From 3d4f707c56e1041a3a21a313c673e77e9c7d6ff8 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Thu, 17 May 2018 14:51:45 +0800 Subject: [PATCH] save --- .../fr/design/remote/ui/UserManagerPane.java | 45 ++++++++++--- .../remote/ui/list/AddedMemberList.java | 39 +++++++++--- .../remote/ui/list/AddingMemberList.java | 63 +++++++++++++++++++ ...r.java => AddingMemberListCellRender.java} | 5 +- .../fr/design/remote/ui/list/MemberList.java | 59 +++++------------ .../MemberListSelectedChangeListener.java | 7 +++ 6 files changed, 159 insertions(+), 59 deletions(-) create mode 100644 designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java rename designer-base/src/com/fr/design/remote/ui/list/{MemberListCellRender.java => AddingMemberListCellRender.java} (87%) create mode 100644 designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java diff --git a/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java b/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java index d5bb9c1e6e..018667d157 100644 --- a/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java +++ b/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java @@ -11,8 +11,9 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.remote.RemoteMember; import com.fr.design.remote.Utils; import com.fr.design.remote.ui.list.AddedMemberList; -import com.fr.design.remote.ui.list.MemberList; -import com.fr.design.remote.ui.list.MemberListCellRender; +import com.fr.design.remote.ui.list.AddingMemberList; +import com.fr.design.remote.ui.list.AddingMemberListCellRender; +import com.fr.design.remote.ui.list.MemberListSelectedChangeListener; import com.fr.general.Inter; import javax.swing.BorderFactory; @@ -89,7 +90,19 @@ public class UserManagerPane extends BasicPane { /** * 添加到设计的决策成员计数标签 */ - private DefaultListModel addedListModel; + private DefaultListModel addedListModel; + + + private MemberListSelectedChangeListener memberListSelectedChangeListener = new MemberListSelectedChangeListener() { + @Override + public void selectedChange() { + resetAddedMembers(); + addedMembers.addAll(getNeedAddMember()); + addToAddedMemberList(); + } + }; + private AddedMemberList addedList; + private AddingMemberList list; public UserManagerPane() { @@ -134,9 +147,9 @@ public class UserManagerPane extends BasicPane { // 内容列表 listModel = new DefaultListModel<>(); - final MemberList list = new MemberList(listModel); - list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - list.setCellRenderer(new MemberListCellRender()); + list = new AddingMemberList(listModel); + list.setCellRenderer(new AddingMemberListCellRender()); + list.addSelectedChangeListener(memberListSelectedChangeListener); resetMembers(); addToMemberList(); UIScrollPane listPane = new UIScrollPane(list); @@ -161,9 +174,9 @@ public class UserManagerPane extends BasicPane { countLabel.setText(Inter.getLocText("已选择{R1}人", "0")); addedListModel = new DefaultListModel<>(); - final AddedMemberList addedList = new AddedMemberList(listModel); + addedList = new AddedMemberList(addedListModel); addedList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - addedList.setCellRenderer(new MemberListCellRender()); + addedList.setCellRenderer(new AddingMemberListCellRender()); resetAddedMembers(); addToAddedMemberList(); UIScrollPane listPane = new UIScrollPane(addedList); @@ -181,6 +194,8 @@ public class UserManagerPane extends BasicPane { for (RemoteMember member : members) { listModel.addElement(member); } + list.revalidate(); + list.repaint(); } private void addToAddedMemberList() { @@ -188,6 +203,8 @@ public class UserManagerPane extends BasicPane { for (RemoteMember member : addedMembers) { addedListModel.addElement(member); } + addedList.revalidate(); + addedList.repaint(); } private void resetMembers() { @@ -217,4 +234,16 @@ public class UserManagerPane extends BasicPane { }; getMemberWorker.execute(); } + + private List getNeedAddMember() { + List res = new ArrayList<>(); + RemoteMember[] members = new RemoteMember[listModel.getSize()]; + listModel.copyInto(members); + for (RemoteMember member : members) { + if (member.isSelected()) { + res.add(member); + } + } + return res; + } } diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java index 40b4bbd942..86f0e1c79f 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java @@ -2,34 +2,59 @@ package com.fr.design.remote.ui.list; import com.fr.design.remote.RemoteMember; -import javax.swing.JList; import javax.swing.ListModel; +import javax.swing.ListSelectionModel; import java.awt.Color; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.Vector; -public class AddedMemberList extends JList { +public class AddedMemberList extends MemberList { public AddedMemberList() { super(); - init(this.getModel().getSize()); + init(); } public AddedMemberList(ListModel dataModel) { super(dataModel); - init(dataModel.getSize()); + init(); } public AddedMemberList(RemoteMember[] listData) { super(listData); - init(listData.length); + init(); } public AddedMemberList(Vector listData) { super(listData); - init(listData.size()); + init(); } - private void init(int size) { + + private void init() { setBackground(new Color(0xF5F5F7)); + + this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + System.out.println(e.getX() + " " + e.getY()); + displaySelected(); + } + }); + this.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + super.keyReleased(e); + if (e.getKeyCode() == KeyEvent.VK_SPACE) { + displaySelected(); + } + } + }); } } diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java new file mode 100644 index 0000000000..4f245daf2a --- /dev/null +++ b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java @@ -0,0 +1,63 @@ +package com.fr.design.remote.ui.list; + +import com.fr.design.remote.RemoteMember; + +import javax.swing.ListModel; +import javax.swing.ListSelectionModel; +import java.awt.Color; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Vector; + +public class AddingMemberList extends MemberList { + + + public AddingMemberList() { + super(); + init(); + } + + public AddingMemberList(ListModel dataModel) { + super(dataModel); + init(); + } + + public AddingMemberList(RemoteMember[] listData) { + super(listData); + init(); + } + + public AddingMemberList(Vector listData) { + super(listData); + init(); + } + + + private void init() { + setBackground(new Color(0xF5F5F7)); + + this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + System.out.println(e.getX() + " " + e.getY()); + displaySelected(); + } + }); + this.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + super.keyReleased(e); + if (e.getKeyCode() == KeyEvent.VK_SPACE) { + displaySelected(); + } + } + }); + } +} + + diff --git a/designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java similarity index 87% rename from designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java rename to designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java index 77ba4941ad..b953a42888 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java +++ b/designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java @@ -12,13 +12,13 @@ import javax.swing.ListCellRenderer; import java.awt.Component; import java.awt.FlowLayout; -public class MemberListCellRender extends JPanel implements ListCellRenderer { +public class AddingMemberListCellRender extends JPanel implements ListCellRenderer { private UILabel label; private UICheckBox check; - public MemberListCellRender() { + public AddingMemberListCellRender() { this.setBorder(BorderFactory.createEmptyBorder()); this.setLayout(new FlowLayout(FlowLayout.LEFT)); @@ -27,6 +27,7 @@ public class MemberListCellRender extends JPanel implements ListCellRenderer { - - private boolean[] selects; - - public MemberList() { - super(); - init(this.getModel().getSize()); - } - public MemberList(ListModel dataModel) { super(dataModel); - init(dataModel.getSize()); } public MemberList(RemoteMember[] listData) { super(listData); - init(listData.length); } public MemberList(Vector listData) { super(listData); - init(listData.size()); + } + + public MemberList() { } - @Override - public void setModel(ListModel model) { - super.setModel(model); - selects = new boolean[this.getModel().getSize()]; + public void addSelectedChangeListener(MemberListSelectedChangeListener l) { + this.listenerList.add(MemberListSelectedChangeListener.class, l); } - private void init(int size) { - selects = new boolean[size]; - setBackground(new Color(0xF5F5F7)); - this.addMouseListener(new MouseAdapter() { - @Override - public void mouseReleased(MouseEvent e) { - super.mouseReleased(e); - displaySelected(); - } - }); - this.addKeyListener(new KeyAdapter() { - @Override - public void keyReleased(KeyEvent e) { - super.keyReleased(e); - if (e.getKeyCode() == KeyEvent.VK_SPACE) { - displaySelected(); - } + public void removeSelectedChangeListener(MemberListSelectedChangeListener l) { + this.listenerList.remove(MemberListSelectedChangeListener.class, l); + } + + public void fireSelectedChange() { + Object[] listeners = listenerList.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == MemberListSelectedChangeListener.class) { + ((MemberListSelectedChangeListener) listeners[i + 1]).selectedChange(); } - }); + } } - private void displaySelected() { + protected void displaySelected() { RemoteMember member = getSelectedValue(); member.setSelected(!member.isSelected()); revalidate(); repaint(); + fireSelectedChange(); } - } - - diff --git a/designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java b/designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java new file mode 100644 index 0000000000..1e00cf7930 --- /dev/null +++ b/designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java @@ -0,0 +1,7 @@ +package com.fr.design.remote.ui.list; + +import java.util.EventListener; + +public interface MemberListSelectedChangeListener extends EventListener { + void selectedChange(); +}