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. 59
      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.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<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() {
@ -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<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 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<RemoteMember> {
public class AddedMemberList extends MemberList {
public AddedMemberList() {
super();
init(this.getModel().getSize());
init();
}
public AddedMemberList(ListModel<RemoteMember> dataModel) {
super(dataModel);
init(dataModel.getSize());
init();
}
public AddedMemberList(RemoteMember[] listData) {
super(listData);
init(listData.length);
init();
}
public AddedMemberList(Vector<? extends RemoteMember> 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();
}
}
});
}
}

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.FlowLayout;
public class MemberListCellRender extends JPanel implements ListCellRenderer<RemoteMember> {
public class AddingMemberListCellRender extends JPanel implements ListCellRenderer<RemoteMember> {
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<Rem
check = new UICheckBox();
check.setSelected(false);
check.setEnabled(true);
this.add(label);
this.add(check);

59
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.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;
public class MemberList extends JList<RemoteMember> {
private boolean[] selects;
public MemberList() {
super();
init(this.getModel().getSize());
}
public MemberList(ListModel<RemoteMember> dataModel) {
super(dataModel);
init(dataModel.getSize());
}
public MemberList(RemoteMember[] listData) {
super(listData);
init(listData.length);
}
public MemberList(Vector<? extends RemoteMember> listData) {
super(listData);
init(listData.size());
}
public MemberList() {
}
@Override
public void setModel(ListModel<RemoteMember> 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();
}
}

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