Browse Source

save

master
yaoh.wu 7 years ago
parent
commit
3d4f707c56
  1. 45
      designer-base/src/com/fr/design/remote/ui/UserManagerPane.java
  2. 39
      designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java
  3. 63
      designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java
  4. 5
      designer-base/src/com/fr/design/remote/ui/list/AddingMemberListCellRender.java
  5. 55
      designer-base/src/com/fr/design/remote/ui/list/MemberList.java
  6. 7
      designer-base/src/com/fr/design/remote/ui/list/MemberListSelectedChangeListener.java

45
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.RemoteMember;
import com.fr.design.remote.Utils; import com.fr.design.remote.Utils;
import com.fr.design.remote.ui.list.AddedMemberList; import com.fr.design.remote.ui.list.AddedMemberList;
import com.fr.design.remote.ui.list.MemberList; import com.fr.design.remote.ui.list.AddingMemberList;
import com.fr.design.remote.ui.list.MemberListCellRender; import com.fr.design.remote.ui.list.AddingMemberListCellRender;
import com.fr.design.remote.ui.list.MemberListSelectedChangeListener;
import com.fr.general.Inter; import com.fr.general.Inter;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@ -89,7 +90,19 @@ public class UserManagerPane extends BasicPane {
/** /**
* 添加到设计的决策成员计数标签 * 添加到设计的决策成员计数标签
*/ */
private DefaultListModel<Object> addedListModel; private DefaultListModel<RemoteMember> addedListModel;
private MemberListSelectedChangeListener memberListSelectedChangeListener = new MemberListSelectedChangeListener() {
@Override
public void selectedChange() {
resetAddedMembers();
addedMembers.addAll(getNeedAddMember());
addToAddedMemberList();
}
};
private AddedMemberList addedList;
private AddingMemberList list;
public UserManagerPane() { public UserManagerPane() {
@ -134,9 +147,9 @@ public class UserManagerPane extends BasicPane {
// 内容列表 // 内容列表
listModel = new DefaultListModel<>(); listModel = new DefaultListModel<>();
final MemberList list = new MemberList(listModel); list = new AddingMemberList(listModel);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setCellRenderer(new AddingMemberListCellRender());
list.setCellRenderer(new MemberListCellRender()); list.addSelectedChangeListener(memberListSelectedChangeListener);
resetMembers(); resetMembers();
addToMemberList(); addToMemberList();
UIScrollPane listPane = new UIScrollPane(list); UIScrollPane listPane = new UIScrollPane(list);
@ -161,9 +174,9 @@ public class UserManagerPane extends BasicPane {
countLabel.setText(Inter.getLocText("已选择{R1}人", "0")); countLabel.setText(Inter.getLocText("已选择{R1}人", "0"));
addedListModel = new DefaultListModel<>(); addedListModel = new DefaultListModel<>();
final AddedMemberList addedList = new AddedMemberList(listModel); addedList = new AddedMemberList(addedListModel);
addedList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); addedList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
addedList.setCellRenderer(new MemberListCellRender()); addedList.setCellRenderer(new AddingMemberListCellRender());
resetAddedMembers(); resetAddedMembers();
addToAddedMemberList(); addToAddedMemberList();
UIScrollPane listPane = new UIScrollPane(addedList); UIScrollPane listPane = new UIScrollPane(addedList);
@ -181,6 +194,8 @@ public class UserManagerPane extends BasicPane {
for (RemoteMember member : members) { for (RemoteMember member : members) {
listModel.addElement(member); listModel.addElement(member);
} }
list.revalidate();
list.repaint();
} }
private void addToAddedMemberList() { private void addToAddedMemberList() {
@ -188,6 +203,8 @@ public class UserManagerPane extends BasicPane {
for (RemoteMember member : addedMembers) { for (RemoteMember member : addedMembers) {
addedListModel.addElement(member); addedListModel.addElement(member);
} }
addedList.revalidate();
addedList.repaint();
} }
private void resetMembers() { private void resetMembers() {
@ -217,4 +234,16 @@ public class UserManagerPane extends BasicPane {
}; };
getMemberWorker.execute(); getMemberWorker.execute();
} }
private List<RemoteMember> getNeedAddMember() {
List<RemoteMember> res = new ArrayList<>();
RemoteMember[] members = new RemoteMember[listModel.getSize()];
listModel.copyInto(members);
for (RemoteMember member : members) {
if (member.isSelected()) {
res.add(member);
}
}
return res;
}
} }

39
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 com.fr.design.remote.RemoteMember;
import javax.swing.JList;
import javax.swing.ListModel; import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import java.awt.Color; 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; import java.util.Vector;
public class AddedMemberList extends JList<RemoteMember> { public class AddedMemberList extends MemberList {
public AddedMemberList() { public AddedMemberList() {
super(); super();
init(this.getModel().getSize()); init();
} }
public AddedMemberList(ListModel<RemoteMember> dataModel) { public AddedMemberList(ListModel<RemoteMember> dataModel) {
super(dataModel); super(dataModel);
init(dataModel.getSize()); init();
} }
public AddedMemberList(RemoteMember[] listData) { public AddedMemberList(RemoteMember[] listData) {
super(listData); super(listData);
init(listData.length); init();
} }
public AddedMemberList(Vector<? extends RemoteMember> listData) { public AddedMemberList(Vector<? extends RemoteMember> listData) {
super(listData); super(listData);
init(listData.size()); init();
} }
private void init(int size) {
private void init() {
setBackground(new Color(0xF5F5F7)); 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();
}
}
});
} }
} }

63
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<RemoteMember> dataModel) {
super(dataModel);
init();
}
public AddingMemberList(RemoteMember[] listData) {
super(listData);
init();
}
public AddingMemberList(Vector<? extends RemoteMember> 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();
}
}
});
}
}

5
designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java → 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.Component;
import java.awt.FlowLayout; import java.awt.FlowLayout;
public class MemberListCellRender extends JPanel implements ListCellRenderer<RemoteMember> { public class AddingMemberListCellRender extends JPanel implements ListCellRenderer<RemoteMember> {
private UILabel label; private UILabel label;
private UICheckBox check; private UICheckBox check;
public MemberListCellRender() { public AddingMemberListCellRender() {
this.setBorder(BorderFactory.createEmptyBorder()); this.setBorder(BorderFactory.createEmptyBorder());
this.setLayout(new FlowLayout(FlowLayout.LEFT)); this.setLayout(new FlowLayout(FlowLayout.LEFT));
@ -27,6 +27,7 @@ public class MemberListCellRender extends JPanel implements ListCellRenderer<Rem
check = new UICheckBox(); check = new UICheckBox();
check.setSelected(false); check.setSelected(false);
check.setEnabled(true);
this.add(label); this.add(label);
this.add(check); this.add(check);

55
designer-base/src/com/fr/design/remote/ui/list/MemberList.java

@ -4,73 +4,48 @@ import com.fr.design.remote.RemoteMember;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.ListModel; import javax.swing.ListModel;
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; import java.util.Vector;
public class MemberList extends JList<RemoteMember> { public class MemberList extends JList<RemoteMember> {
private boolean[] selects;
public MemberList() {
super();
init(this.getModel().getSize());
}
public MemberList(ListModel<RemoteMember> dataModel) { public MemberList(ListModel<RemoteMember> dataModel) {
super(dataModel); super(dataModel);
init(dataModel.getSize());
} }
public MemberList(RemoteMember[] listData) { public MemberList(RemoteMember[] listData) {
super(listData); super(listData);
init(listData.length);
} }
public MemberList(Vector<? extends RemoteMember> listData) { public MemberList(Vector<? extends RemoteMember> listData) {
super(listData); super(listData);
init(listData.size()); }
public MemberList() {
} }
@Override public void addSelectedChangeListener(MemberListSelectedChangeListener l) {
public void setModel(ListModel<RemoteMember> model) { this.listenerList.add(MemberListSelectedChangeListener.class, l);
super.setModel(model);
selects = new boolean[this.getModel().getSize()];
} }
private void init(int size) { public void removeSelectedChangeListener(MemberListSelectedChangeListener l) {
selects = new boolean[size]; this.listenerList.remove(MemberListSelectedChangeListener.class, l);
setBackground(new Color(0xF5F5F7));
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
displaySelected();
} }
});
this.addKeyListener(new KeyAdapter() { public void fireSelectedChange() {
@Override Object[] listeners = listenerList.getListenerList();
public void keyReleased(KeyEvent e) { for (int i = listeners.length - 2; i >= 0; i -= 2) {
super.keyReleased(e); if (listeners[i] == MemberListSelectedChangeListener.class) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) { ((MemberListSelectedChangeListener) listeners[i + 1]).selectedChange();
displaySelected();
} }
} }
});
} }
private void displaySelected() { protected void displaySelected() {
RemoteMember member = getSelectedValue(); RemoteMember member = getSelectedValue();
member.setSelected(!member.isSelected()); member.setSelected(!member.isSelected());
revalidate(); revalidate();
repaint(); repaint();
fireSelectedChange();
} }
} }

7
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();
}
Loading…
Cancel
Save