Browse Source

update

master
yaoh.wu 7 years ago
parent
commit
ca778b2b15
  1. 95
      designer-base/src/com/fr/design/remote/ui/UserManagerPane.java
  2. 48
      designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java
  3. 1
      designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java
  4. 48
      designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java
  5. 52
      designer-base/src/com/fr/design/remote/ui/list/MemberList.java

95
designer-base/src/com/fr/design/remote/ui/UserManagerPane.java

@ -11,10 +11,12 @@ 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.AddedMemberListCellRender;
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 com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
@ -31,6 +33,7 @@ import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -42,7 +45,7 @@ public class UserManagerPane extends BasicPane {
/**
* 获取的决策平台成员
*/
private List<RemoteMember> members = new ArrayList<>();
private List<RemoteMember> addingMembers = new ArrayList<>();
/**
* 添加到设计的决策平台成员
*/
@ -51,7 +54,7 @@ public class UserManagerPane extends BasicPane {
/**
* 决策平台成员列表model
*/
private DefaultListModel<RemoteMember> listModel = new DefaultListModel<>();
private DefaultListModel<RemoteMember> addingListModel = new DefaultListModel<>();
/**
* 搜索输入框
*/
@ -67,7 +70,7 @@ public class UserManagerPane extends BasicPane {
private ActionListener keyButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
searchMembers(keyField.getText());
searchAddingMembers(keyField.getText());
}
};
@ -77,9 +80,10 @@ public class UserManagerPane extends BasicPane {
private KeyAdapter keyFieldKeyListener = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
//判断按下的键是否是回车键
// 判断按下的键是否是回车键
// todo 对话款回车键绑定的是对话框的确定按钮
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
searchMembers(keyField.getText());
searchAddingMembers(keyField.getText());
}
}
};
@ -93,16 +97,28 @@ public class UserManagerPane extends BasicPane {
private DefaultListModel<RemoteMember> addedListModel;
private MemberListSelectedChangeListener memberListSelectedChangeListener = new MemberListSelectedChangeListener() {
private MemberListSelectedChangeListener addingListChangeListener = new MemberListSelectedChangeListener() {
@Override
public void selectedChange() {
resetAddedMembers();
addedMembers.addAll(getNeedAddMember());
sync2AddedMembersFromAdding();
addToAddedMemberList();
}
};
private MemberListSelectedChangeListener addedListChangeListener = new MemberListSelectedChangeListener() {
@Override
public void selectedChange() {
addingList.revalidate();
addingList.repaint();
resetAddedMembers();
sync2AddedMembersFormAdded();
// 不需要重复更新右侧列表显示
}
};
private AddedMemberList addedList;
private AddingMemberList list;
private AddingMemberList addingList;
public UserManagerPane() {
@ -146,13 +162,14 @@ public class UserManagerPane extends BasicPane {
searchPanel.add(keyButton);
// 内容列表
listModel = new DefaultListModel<>();
list = new AddingMemberList(listModel);
list.setCellRenderer(new AddingMemberListCellRender());
list.addSelectedChangeListener(memberListSelectedChangeListener);
addingListModel = new DefaultListModel<>();
addingList = new AddingMemberList(addingListModel);
addingList.setCellRenderer(new AddingMemberListCellRender());
addingList.addSelectedChangeListener(addingListChangeListener);
resetMembers();
addToMemberList();
UIScrollPane listPane = new UIScrollPane(list);
searchAddingMembers(StringUtils.EMPTY);
UIScrollPane listPane = new UIScrollPane(addingList);
listPane.setBorder(BorderFactory.createEmptyBorder());
content.add(searchPanel, BorderLayout.NORTH);
@ -171,12 +188,13 @@ public class UserManagerPane extends BasicPane {
);
// 计数
countLabel.setText(Inter.getLocText("已选择{R1}人", "0"));
countLabel.setText(Inter.getLocText("已选择{R1}人", String.valueOf(addedMembers.size())));
addedListModel = new DefaultListModel<>();
addedList = new AddedMemberList(addedListModel);
addedList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
addedList.setCellRenderer(new AddingMemberListCellRender());
addedList.setCellRenderer(new AddedMemberListCellRender());
addedList.addSelectedChangeListener(addedListChangeListener);
resetAddedMembers();
addToAddedMemberList();
UIScrollPane listPane = new UIScrollPane(addedList);
@ -190,12 +208,12 @@ public class UserManagerPane extends BasicPane {
private void addToMemberList() {
listModel.clear();
for (RemoteMember member : members) {
listModel.addElement(member);
addingListModel.clear();
for (RemoteMember member : addingMembers) {
addingListModel.addElement(member);
}
list.revalidate();
list.repaint();
addingList.revalidate();
addingList.repaint();
}
private void addToAddedMemberList() {
@ -205,11 +223,12 @@ public class UserManagerPane extends BasicPane {
}
addedList.revalidate();
addedList.repaint();
countLabel.setText(Inter.getLocText("已选择{R1}人", String.valueOf(addedMembers.size())));
}
private void resetMembers() {
members.clear();
members.add(RemoteMember.DEFAULT_MEMBER);
addingMembers.clear();
addingMembers.add(RemoteMember.DEFAULT_MEMBER);
}
private void resetAddedMembers() {
@ -217,14 +236,19 @@ public class UserManagerPane extends BasicPane {
}
private void searchMembers(final String keyword) {
private void searchAddingMembers(final String keyword) {
final SwingWorker getMemberWorker = new SwingWorker<List<RemoteMember>, Void>() {
@Override
protected List<RemoteMember> doInBackground() {
members.clear();
members.addAll(Utils.getRemoteMember(keyword));
return members;
addingMembers.clear();
addingMembers.addAll(Utils.getRemoteMember(keyword));
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
return addingMembers;
}
@Override
@ -235,15 +259,22 @@ 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);
private void sync2AddedMembersFromAdding() {
RemoteMember[] members = new RemoteMember[addingListModel.getSize()];
// shallow copy
addingListModel.copyInto(members);
for (RemoteMember member : members) {
if (member.isSelected()) {
res.add(member);
addedMembers.add(member);
}
}
return res;
}
private void sync2AddedMembersFormAdded() {
RemoteMember[] members = new RemoteMember[addedListModel.getSize()];
// shallow copy
addedListModel.copyInto(members);
addedMembers.addAll(Arrays.asList(members));
}
}

48
designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java

@ -2,12 +2,7 @@ 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 javax.swing.DefaultListModel;
import java.awt.event.MouseEvent;
import java.util.Vector;
@ -15,46 +10,33 @@ public class AddedMemberList extends MemberList {
public AddedMemberList() {
super();
init();
}
public AddedMemberList(ListModel<RemoteMember> dataModel) {
public AddedMemberList(DefaultListModel<RemoteMember> dataModel) {
super(dataModel);
init();
}
public AddedMemberList(RemoteMember[] listData) {
super(listData);
init();
}
public AddedMemberList(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();
}
}
});
@Override
protected boolean shouldDisplaySelected(MouseEvent e) {
return true;
}
@Override
protected void displaySelected() {
RemoteMember member = getSelectedValue();
member.setSelected(!member.isSelected());
((DefaultListModel<RemoteMember>) getModel()).removeElement(member);
revalidate();
repaint();
fireSelectedChange();
}
}

1
designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java

@ -26,6 +26,7 @@ public class AddedMemberListCellRender extends JPanel implements ListCellRendere
label = new UILabel();
label.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png"));
uiButton = new UIButton();
uiButton.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Remove_x.png"));
this.add(label);

48
designer-base/src/com/fr/design/remote/ui/list/AddingMemberList.java

@ -2,12 +2,7 @@ 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 javax.swing.DefaultListModel;
import java.awt.event.MouseEvent;
import java.util.Vector;
@ -16,47 +11,34 @@ public class AddingMemberList extends MemberList {
public AddingMemberList() {
super();
init();
}
public AddingMemberList(ListModel<RemoteMember> dataModel) {
public AddingMemberList(DefaultListModel<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();
}
}
});
@Override
protected void displaySelected() {
RemoteMember member = getSelectedValue();
member.setSelected(!member.isSelected());
revalidate();
repaint();
fireSelectedChange();
}
@Override
protected boolean shouldDisplaySelected(MouseEvent e) {
return true;
}
}

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

@ -2,25 +2,36 @@ package com.fr.design.remote.ui.list;
import com.fr.design.remote.RemoteMember;
import javax.swing.DefaultListModel;
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 MemberList extends JList<RemoteMember> {
public abstract class MemberList extends JList<RemoteMember> {
public MemberList(ListModel<RemoteMember> dataModel) {
public MemberList(DefaultListModel<RemoteMember> dataModel) {
super(dataModel);
init();
}
public MemberList(RemoteMember[] listData) {
super(listData);
init();
}
public MemberList(Vector<? extends RemoteMember> listData) {
super(listData);
init();
}
public MemberList() {
super();
init();
}
@ -41,11 +52,34 @@ public class MemberList extends JList<RemoteMember> {
}
}
protected void displaySelected() {
RemoteMember member = getSelectedValue();
member.setSelected(!member.isSelected());
revalidate();
repaint();
fireSelectedChange();
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("click location: x:" + e.getX() + " y:" + e.getY());
if (shouldDisplaySelected(e)) {
displaySelected();
}
}
});
this.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
super.keyReleased(e);
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
displaySelected();
}
}
});
}
abstract protected void displaySelected();
abstract protected boolean shouldDisplaySelected(MouseEvent e);
}

Loading…
Cancel
Save