From 8a81a5d5336a6e152f47c01881b49afc3c8c5d51 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Wed, 16 May 2018 17:53:09 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-6700=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/remote/RemoteMember.java | 12 ++ .../src/com/fr/design/remote/Utils.java | 49 ++++++ .../fr/design/remote/images/icon_Remove_x.png | Bin 0 -> 238 bytes .../remote/ui/AuthorityListControlPane.java | 4 +- .../fr/design/remote/ui/UserManagerPane.java | 144 ++++++++++++++++-- .../remote/ui/list/AddedMemberList.java | 35 +++++ .../ui/list/AddedMemberListCellRender.java | 44 ++++++ .../fr/design/remote/ui/list/MemberList.java | 47 +++++- .../remote/ui/list/MemberListCellRender.java | 13 +- 9 files changed, 324 insertions(+), 24 deletions(-) create mode 100644 designer-base/src/com/fr/design/remote/Utils.java create mode 100644 designer-base/src/com/fr/design/remote/images/icon_Remove_x.png create mode 100644 designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java create mode 100644 designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java diff --git a/designer-base/src/com/fr/design/remote/RemoteMember.java b/designer-base/src/com/fr/design/remote/RemoteMember.java index aa25da3686..019159b30a 100644 --- a/designer-base/src/com/fr/design/remote/RemoteMember.java +++ b/designer-base/src/com/fr/design/remote/RemoteMember.java @@ -4,8 +4,11 @@ public class RemoteMember { public static final RemoteMember DEFAULT_MEMBER = new RemoteMember("查询中..."); + private String name; + private boolean selected; + public RemoteMember(String name) { this.name = name; } @@ -17,4 +20,13 @@ public class RemoteMember { public void setName(String name) { this.name = name; } + + + public boolean isSelected() { + return selected; + } + + public void setSelected(boolean selected) { + this.selected = selected; + } } diff --git a/designer-base/src/com/fr/design/remote/Utils.java b/designer-base/src/com/fr/design/remote/Utils.java new file mode 100644 index 0000000000..1e2e12ebaf --- /dev/null +++ b/designer-base/src/com/fr/design/remote/Utils.java @@ -0,0 +1,49 @@ +package com.fr.design.remote; + +import com.fr.stable.StringUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; + +public class Utils { + + private static final String SOURCES = + "._-~`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; + + private Utils() { + + } + + public static Collection getRemoteMember(String keyword) { + // todo 使用决策平台api获取决策平台用户 + List res = new ArrayList<>(); + for (int i = 0; i < 30; i++) { + RemoteMember remoteMember = new RemoteMember(generate()); + if (StringUtils.isEmpty(keyword)) { + res.add(remoteMember); + continue; + } + if (remoteMember.getName().contains(keyword)) { + res.add(remoteMember); + } + } + return res; + } + + + /** + * Generate a random string. + * + * @return String string + */ + private static String generate() { + Random random = new Random(); + char[] text = new char[6]; + for (int i = 0; i < 6; i++) { + text[i] = Utils.SOURCES.charAt(random.nextInt(Utils.SOURCES.length())); + } + return new String(text); + } +} diff --git a/designer-base/src/com/fr/design/remote/images/icon_Remove_x.png b/designer-base/src/com/fr/design/remote/images/icon_Remove_x.png new file mode 100644 index 0000000000000000000000000000000000000000..5a9a05e8add66e9c7b76e4fefb3144d48242618a GIT binary patch literal 238 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP*AeO zHKHUqKdq!Zu_%?nF(p4KRlzeiF+DXXH8G{K@MNkDP*Js~i(^Q|t>hp7|JyUGO8AI~ zi*qwKiP>fr?}99cEZGUX0S=Q6WO2-T#&2-_QE-Ao zkBnk8&xg!o1`OSb^A}1izy5($%t!f*0`r`U9-+({pO{=5JpxUF=1f>Ib&B+dOgG~t djLMpmyBQ-_wE3U$kpuaR!PC{xWt~$(699PDNCW@? literal 0 HcmV?d00001 diff --git a/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java b/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java index c228e58899..8fc3e120d8 100644 --- a/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java +++ b/designer-base/src/com/fr/design/remote/ui/AuthorityListControlPane.java @@ -217,7 +217,7 @@ public class AuthorityListControlPane extends BasicPane { * 获取选中的名字 */ public String getSelectedName() { - RemoteDesignAuthority authority = (RemoteDesignAuthority) this.authorityList.getSelectedValue(); + RemoteDesignAuthority authority = this.authorityList.getSelectedValue(); return authority == null ? null : authority.getName(); } @@ -412,7 +412,7 @@ public class AuthorityListControlPane extends BasicPane { } public void populate() { - authority = (RemoteDesignAuthority) AuthorityListControlPane.this.authorityList.getSelectedValue(); + authority = AuthorityListControlPane.this.authorityList.getSelectedValue(); if (authority == null) { return; 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 08014ad882..d5bb9c1e6e 100644 --- a/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java +++ b/designer-base/src/com/fr/design/remote/ui/UserManagerPane.java @@ -4,10 +4,13 @@ import com.fr.design.border.UITitledBorder; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; +import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.TableLayout; 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.general.Inter; @@ -15,10 +18,17 @@ import com.fr.general.Inter; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; import javax.swing.JPanel; +import javax.swing.ListSelectionModel; +import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; import java.awt.BorderLayout; import java.awt.Component; +import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.List; @@ -28,9 +38,58 @@ import java.util.List; */ public class UserManagerPane extends BasicPane { + /** + * 获取的决策平台成员 + */ private List members = new ArrayList<>(); - - DefaultListModel listModel = new DefaultListModel<>(); + /** + * 添加到设计的决策平台成员 + */ + private List addedMembers = new ArrayList<>(); + + /** + * 决策平台成员列表model + */ + private DefaultListModel listModel = new DefaultListModel<>(); + /** + * 搜索输入框 + */ + private UITextField keyField = new UITextField(); + /** + * 搜索按钮 + */ + private UIButton keyButton = new UIButton(); + + /** + * 搜索按钮绑定事件 + */ + private ActionListener keyButtonActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + searchMembers(keyField.getText()); + } + }; + + /** + * 输入框绑定事件 + */ + private KeyAdapter keyFieldKeyListener = new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + //判断按下的键是否是回车键 + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + searchMembers(keyField.getText()); + } + } + }; + /** + * 添加到设计的决策成员计数标签 + */ + private UILabel countLabel = new UILabel(); + /** + * 添加到设计的决策成员计数标签 + */ + private DefaultListModel addedListModel; public UserManagerPane() { @@ -39,7 +98,7 @@ public class UserManagerPane extends BasicPane { this.add( TableLayoutHelper.createTableLayoutPane( new Component[][]{ - new Component[]{createLeftPanel(), new JPanel()} + new Component[]{createLeftPanel(), createRightPanel()} }, new double[]{TableLayout.FILL}, new double[]{TableLayout.FILL, TableLayout.FILL} @@ -63,18 +122,23 @@ public class UserManagerPane extends BasicPane { ); // 搜索 - UITextField searchKeyInput = new UITextField(); - UIButton searchButton = new UIButton("搜索"); JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); searchPanel.setBorder(BorderFactory.createEmptyBorder()); - searchPanel.add(searchKeyInput); - searchPanel.add(searchButton); + keyField.setPreferredSize(new Dimension(200, 20)); + keyField.requestFocus(); + keyField.addKeyListener(keyFieldKeyListener); + keyButton.setText("搜索"); + keyButton.addActionListener(keyButtonActionListener); + searchPanel.add(keyField); + searchPanel.add(keyButton); + // 内容列表 listModel = new DefaultListModel<>(); - MemberList list = new MemberList(listModel); + final MemberList list = new MemberList(listModel); + list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setCellRenderer(new MemberListCellRender()); resetMembers(); - addContentToList(); + addToMemberList(); UIScrollPane listPane = new UIScrollPane(list); listPane.setBorder(BorderFactory.createEmptyBorder()); @@ -84,15 +148,73 @@ public class UserManagerPane extends BasicPane { } - private void addContentToList() { - listModel.removeAllElements(); + private JPanel createRightPanel() { + JPanel content = new JPanel(new BorderLayout()); + + content.setBorder( + BorderFactory.createCompoundBorder( + new EmptyBorder(6, 0, 0, 0), + UITitledBorder.createBorderWithTitle(Inter.getLocText("已选择的设计成员"))) + ); + + // 计数 + countLabel.setText(Inter.getLocText("已选择{R1}人", "0")); + + addedListModel = new DefaultListModel<>(); + final AddedMemberList addedList = new AddedMemberList(listModel); + addedList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + addedList.setCellRenderer(new MemberListCellRender()); + resetAddedMembers(); + addToAddedMemberList(); + UIScrollPane listPane = new UIScrollPane(addedList); + listPane.setBorder(BorderFactory.createEmptyBorder()); + + content.add(countLabel, BorderLayout.NORTH); + content.add(listPane, BorderLayout.CENTER); + return content; + + } + + + private void addToMemberList() { + listModel.clear(); for (RemoteMember member : members) { listModel.addElement(member); } } + private void addToAddedMemberList() { + addedListModel.clear(); + for (RemoteMember member : addedMembers) { + addedListModel.addElement(member); + } + } + private void resetMembers() { members.clear(); members.add(RemoteMember.DEFAULT_MEMBER); } + + private void resetAddedMembers() { + addedMembers.clear(); + } + + + private void searchMembers(final String keyword) { + + final SwingWorker getMemberWorker = new SwingWorker, Void>() { + @Override + protected List doInBackground() { + members.clear(); + members.addAll(Utils.getRemoteMember(keyword)); + return members; + } + + @Override + protected void done() { + addToMemberList(); + } + }; + getMemberWorker.execute(); + } } 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 new file mode 100644 index 0000000000..40b4bbd942 --- /dev/null +++ b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberList.java @@ -0,0 +1,35 @@ +package com.fr.design.remote.ui.list; + +import com.fr.design.remote.RemoteMember; + +import javax.swing.JList; +import javax.swing.ListModel; +import java.awt.Color; +import java.util.Vector; + +public class AddedMemberList extends JList { + + public AddedMemberList() { + super(); + init(this.getModel().getSize()); + } + + public AddedMemberList(ListModel dataModel) { + super(dataModel); + init(dataModel.getSize()); + } + + public AddedMemberList(RemoteMember[] listData) { + super(listData); + init(listData.length); + } + + public AddedMemberList(Vector listData) { + super(listData); + init(listData.size()); + } + + private void init(int size) { + setBackground(new Color(0xF5F5F7)); + } +} diff --git a/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java new file mode 100644 index 0000000000..8af7713bea --- /dev/null +++ b/designer-base/src/com/fr/design/remote/ui/list/AddedMemberListCellRender.java @@ -0,0 +1,44 @@ +package com.fr.design.remote.ui.list; + +import com.fr.base.BaseUtils; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.remote.RemoteMember; + +import javax.swing.BorderFactory; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.ListCellRenderer; +import java.awt.Component; +import java.awt.FlowLayout; + +public class AddedMemberListCellRender extends JPanel implements ListCellRenderer { + + + private UILabel label; + + private UIButton uiButton; + + public AddedMemberListCellRender() { + this.setBorder(BorderFactory.createEmptyBorder()); + this.setLayout(new FlowLayout(FlowLayout.LEFT)); + + label = new UILabel(); + label.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Member_normal@1x.png")); + + uiButton.setIcon(BaseUtils.readIcon("com/fr/design/remote/images/icon_Remove_x.png")); + + this.add(label); + this.add(uiButton); + } + + @Override + public Component getListCellRendererComponent(JList list, RemoteMember member, int index, boolean isSelected, boolean cellHasFocus) { + this.setLabelText(member.getName()); + return this; + } + + private void setLabelText(String name) { + label.setText(name); + } +} diff --git a/designer-base/src/com/fr/design/remote/ui/list/MemberList.java b/designer-base/src/com/fr/design/remote/ui/list/MemberList.java index df1bc866a6..71cad5e6df 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/MemberList.java +++ b/designer-base/src/com/fr/design/remote/ui/list/MemberList.java @@ -5,33 +5,70 @@ 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 { + private boolean[] selects; + public MemberList() { super(); - init(); + init(this.getModel().getSize()); } public MemberList(ListModel dataModel) { super(dataModel); - init(); + init(dataModel.getSize()); } public MemberList(RemoteMember[] listData) { super(listData); - init(); + init(listData.length); } public MemberList(Vector listData) { super(listData); - init(); + init(listData.size()); + } + + + @Override + public void setModel(ListModel model) { + super.setModel(model); + selects = new boolean[this.getModel().getSize()]; } - private void init() { + 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(); + } + } + }); + } + + private void displaySelected() { + RemoteMember member = getSelectedValue(); + member.setSelected(!member.isSelected()); + revalidate(); + repaint(); } } diff --git a/designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java b/designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java index 2d7f886fec..77ba4941ad 100644 --- a/designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java +++ b/designer-base/src/com/fr/design/remote/ui/list/MemberListCellRender.java @@ -21,10 +21,13 @@ public class MemberListCellRender extends JPanel implements ListCellRenderer