From 57cf66276b3e69fbc6fe684ea065a60964f729b2 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 11 Oct 2016 20:44:15 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=99=A8=E9=83=A8=E5=88=86=EF=BC=8C=E5=87=A0?= =?UTF-8?q?=E4=B8=AA=E7=94=A8=E5=88=B0=E7=9A=84=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/ShareWidgetButton.java | 192 +++++++++++ .../fr/design/mainframe/ShareWidgetPane.java | 29 ++ .../mainframe/widget/UITreeComboBox.java | 312 ++++++++++++++++++ 3 files changed, 533 insertions(+) create mode 100644 designer_form/src/com/fr/design/mainframe/ShareWidgetButton.java create mode 100644 designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java create mode 100644 designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java diff --git a/designer_form/src/com/fr/design/mainframe/ShareWidgetButton.java b/designer_form/src/com/fr/design/mainframe/ShareWidgetButton.java new file mode 100644 index 0000000000..3054bea328 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/ShareWidgetButton.java @@ -0,0 +1,192 @@ +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.form.share.ShareLoader; +import com.fr.form.ui.ElCaseBindInfo; +import com.fr.form.ui.Widget; +import com.fr.general.ComparatorUtils; +import com.fr.stable.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.dnd.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.Serializable; + +/** + * Coder: zack + * Date: 2016/10/9 + * Time: 16:14 + */ +public class ShareWidgetButton extends JPanel implements MouseListener, MouseMotionListener, Serializable { + private ElCaseBindInfo bindInfo; + private MouseEvent lastPressEvent; + + public ShareWidgetButton(ElCaseBindInfo bindInfo) { + this.bindInfo = bindInfo; + initUI(); + this.setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); + this.addMouseListener(this); + this.addMouseMotionListener(this); + new DragAndDropDragGestureListener(this, DnDConstants.ACTION_COPY_OR_MOVE); + } + + + private void initUI() { + this.setBackground(Color.WHITE); + this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + setPreferredSize(new Dimension(110, 70)); + setLayout(FRGUIPaneFactory.createBorderLayout()); + ImagePanel imagePanel = new ImagePanel((BufferedImage) bindInfo.getCover()); + + this.add(imagePanel, BorderLayout.NORTH); + JPanel panel = new JPanel(); + UILabel label = new UILabel(bindInfo.getName(), SwingConstants.HORIZONTAL); + panel.setBackground(new Color(184, 220, 242)); + panel.add(label); + this.add(panel, BorderLayout.SOUTH); + } + + private class ImagePanel extends JPanel { + + private BufferedImage image; + + public ImagePanel(BufferedImage image) { + this.image = image; + this.setPreferredSize(new Dimension(110, 50)); + } + + @Override + public void paintComponent(Graphics g) { + g.drawImage(image, 0, 0, 110, 70, null); + } + + } + + public ElCaseBindInfo getBindInfo() { + return bindInfo; + } + + public void setBindInfo(ElCaseBindInfo bindInfo) { + this.bindInfo = bindInfo; + } + + @Override + public void mouseClicked(MouseEvent e) { + + } + + @Override + public void mousePressed(MouseEvent e) { + lastPressEvent = e; + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + + @Override + public void mouseDragged(MouseEvent e) { + if (BaseUtils.isAuthorityEditing()) { + return; + } + if (lastPressEvent == null) { + return; + } + Object source = e.getSource(); + Widget creatorSource = null; + String shareId = StringUtils.EMPTY; + if (source instanceof ShareWidgetButton) { + ShareWidgetButton no = (ShareWidgetButton) e.getSource(); + if (no == null) { + return; + } + shareId = no.getBindInfo().getId(); + creatorSource = ShareLoader.getLoader().getElCaseEditorById(shareId); + } + if (creatorSource != null) { + XCreator xCreator = XCreatorUtils.createXCreator(creatorSource); + xCreator.setShareId(shareId); + WidgetToolBarPane.getTarget().startDraggingBean(xCreator); + lastPressEvent = null; + this.setBorder(null); + } + } + + @Override + public void mouseMoved(MouseEvent e) { + + } + + public class DragAndDropDragGestureListener extends DragSourceAdapter implements DragGestureListener { + private DragSource source; + + public DragAndDropDragGestureListener(ShareWidgetButton tt, int actions) { + source = new DragSource(); + source.createDefaultDragGestureRecognizer(tt, actions, this); + } + + public void dragGestureRecognized(DragGestureEvent dge) { + ShareWidgetButton shareWidgetButton = (ShareWidgetButton) dge.getComponent(); + if (shareWidgetButton != null) { + Widget widget = ShareLoader.getLoader().getElCaseEditorById(shareWidgetButton.getBindInfo().getId()); + DragAndDropTransferable dragAndDropTransferable = new DragAndDropTransferable(widget); + dge.startDrag(DragSource.DefaultCopyDrop, dragAndDropTransferable, this); + } + } + + @Override + public void dragEnter(DragSourceDragEvent dragSourceDragEvent) { + + } + } + + public class DragAndDropTransferable implements Transferable { + private Widget widget; + + public DragAndDropTransferable(Widget widget) { + this.widget = widget; + } + + DataFlavor[] flavors = {new DataFlavor(Widget.class, "Widget")}; + + public DataFlavor[] getTransferDataFlavors() { + return flavors; + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + for (DataFlavor df : flavors) { + if (ComparatorUtils.equals(df, flavor)) { + return true; + } + } + return false; + } + + public Object getTransferData(DataFlavor df) throws UnsupportedFlavorException, IOException { + return widget; + } + } +} diff --git a/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java b/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java new file mode 100644 index 0000000000..7abfb6900a --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java @@ -0,0 +1,29 @@ +package com.fr.design.mainframe; + + +import com.fr.form.ui.ElCaseBindInfo; + + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; + + +/** + * Created by xiaxiang on 2016/10/10. + */ +public class ShareWidgetPane extends JPanel { + public ShareWidgetPane(ArrayList elCaseBindInfos) { + this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));// 设置面板的边框 ,距离上、左、下、右 的距离 + int rowCount = (elCaseBindInfos.size() + 1)/2; + this.setLayout(new GridLayout(rowCount, 2, 10, 10)); + for (ElCaseBindInfo rbModuleInfo : elCaseBindInfos) { + ShareWidgetButton widgetButton = new ShareWidgetButton(rbModuleInfo); + this.add(widgetButton); + } + if (elCaseBindInfos.size() == 1) { + this.add(new JPanel()); + } + + } +} diff --git a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java new file mode 100644 index 0000000000..4d92ccc264 --- /dev/null +++ b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java @@ -0,0 +1,312 @@ +package com.fr.design.mainframe.widget; + +/** + * Created by xiaxiang on 2016/9/30. + */ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.plaf.*; +import javax.swing.plaf.basic.*; +import javax.swing.plaf.metal.*; +import javax.swing.tree.*; + +import com.fr.design.designer.beans.*; +import com.fr.design.designer.beans.events.DesignerEditListener; +import com.fr.design.designer.beans.events.DesignerEvent; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.mainframe.ComponentTree; +import com.sun.java.swing.plaf.motif.*; +import com.sun.java.swing.plaf.windows.*; + +/** + * 控件树下拉列表框 + */ +public class UITreeComboBox extends JComboBox{ + /** + * 显示用的树 + */ + private ComponentTree tree; + + public UITreeComboBox(ComponentTree componentTree){ + this.setTree(componentTree); + tree.getDesigner().addDesignerEditListener(new TreeComboBoxDesignerEditAdapter()); + for(int i=0; iTitle: UITreeComboBoxRenderer

+ *

Description: 树形结构而来的DefaultListCellRenderer

+ */ + class UITreeComboBoxRenderer extends DefaultListCellRenderer { + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus){ + if(value != null){ + TreePath path = (TreePath)value; + Object node = path.getLastPathComponent(); + value = node; + TreeCellRenderer r = tree.getCellRenderer(); + JLabel lb = (JLabel)r.getTreeCellRendererComponent( + tree, value, isSelected, false, false, index, + cellHasFocus); + return lb; + } + return super.getListCellRendererComponent(list, value, index, + isSelected, cellHasFocus); + } + } + + + public TreePath[] getSelectedTreePath() { + XCreator[] creators = tree.getDesigner().getSelectionModel().getSelection().getSelectedCreators(); + TreePath[] paths = new TreePath[creators.length]; + + for (int i = 0; i < paths.length; i++) { + paths[i] = tree.buildTreePath(creators[i]); + } + return paths; + } + + private class TreeComboBoxDesignerEditAdapter implements DesignerEditListener { + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { + TreePath[] paths = getSelectedTreePath(); + + if (paths.length == 1) { + tree.setAndScrollSelectionPath(paths[0]); + } else { + tree.setSelectionPaths(paths); + } + setSelectedItem(paths[0]); + MenuSelectionManager.defaultManager().clearSelectedPath(); + } else if(evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) { + TreePath[] paths = getSelectedTreePath(); + if (paths.length == 1) { + tree.setAndScrollSelectionPath(paths[0]); + } else { + tree.setSelectionPaths(paths); + } + setSelectedItem(paths[0]); + MenuSelectionManager.defaultManager().clearSelectedPath(); + + } else { + return; + } + + } + + @Override + public boolean equals(Object o) { + return o.getClass() == this.getClass(); + } + } + + /** + * 测试 + */ +// public static void main(String args[]){ +// JFrame frame = new JFrame("UITreeComboBox"); +// final UITreeComboBox box = new UITreeComboBox(new ComponentTree(new FormDesigner())); +// box.setPreferredSize(new Dimension(300, 28)); +// frame.getContentPane().add(box); +// frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); +// frame.pack(); +// frame.setVisible(true); +// } +} + +/** + *

Title: UITreeComboBox

+ *

Description: TreePopup

+ */ +class TreePopup extends JPopupMenu implements ComboPopup{ + protected UITreeComboBox comboBox; + protected JScrollPane scrollPane; + + protected MouseMotionListener mouseMotionListener; + protected MouseListener mouseListener; + private MouseListener treeSelectListener = new MouseAdapter(){ + public void mouseClicked (MouseEvent e){ + if (e.isMetaDown()) { + popupMenu(e); + } else { + return; + } + } + }; + + public void popupMenu(MouseEvent e) { + TreePath path = comboBox.getTree().getSelectionPath(); + if (path == null) { + return; + } + Component component = (Component) path.getLastPathComponent(); + if (!(component instanceof XCreator)) { + return; + } + com.fr.design.designer.beans.ComponentAdapter adapter = AdapterBus.getComponentAdapter(comboBox.getTree().getDesigner(), (XCreator) component); + JPopupMenu menu = adapter.getContextPopupMenu(e); + menu.show(comboBox, e.getX(), e.getY()); + } + + public TreePopup(JComboBox comboBox){ + this.comboBox = (UITreeComboBox)comboBox; + setBorder(BorderFactory.createLineBorder(Color.black)); + setLayout(new BorderLayout()); + setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled()); + JTree tree = this.comboBox.getTree(); + if(tree != null){ + scrollPane = new JScrollPane(tree); + scrollPane.setBorder(null); + add(scrollPane, BorderLayout.CENTER); + this.comboBox.addMouseListener(treeSelectListener); + } + } + + public void show(){ + updatePopup(); + show(comboBox, 0, comboBox.getHeight()); + comboBox.getTree().requestFocus(); + } + + public void hide(){ + setVisible(false); + comboBox.firePropertyChange("popupVisible", true, false); + } + + protected JList list = new JList(); + public JList getList(){ + return list; + } + + public MouseMotionListener getMouseMotionListener(){ + if(mouseMotionListener == null){ + mouseMotionListener = new MouseMotionAdapter(){}; + } + return mouseMotionListener; + } + + public KeyListener getKeyListener(){ + return null; + } + + public void uninstallingUI(){} + + /** + * Implementation of ComboPopup.getMouseListener(). + * + * @return a MouseListener or null + * @see ComboPopup#getMouseListener + */ + public MouseListener getMouseListener(){ + if(mouseListener == null){ + mouseListener = new InvocationMouseHandler(); + } + return mouseListener; + } + + protected void togglePopup(){ + if(isVisible()){ + hide(); + } else{ + show(); + } + } + protected void updatePopup(){ + setPreferredSize(new Dimension(comboBox.getSize().width, 200)); + Object selectedObj = comboBox.getSelectedItem(); + if(selectedObj != null){ + TreePath tp = (TreePath)selectedObj; + ((UITreeComboBox)comboBox).getTree().setSelectionPath(tp); + } + } + + protected class InvocationMouseHandler extends MouseAdapter{ + public void mousePressed(MouseEvent e){ + if(!SwingUtilities.isLeftMouseButton(e) || !comboBox.isEnabled()){ + return; + } + if(comboBox.isEditable()){ + Component comp = comboBox.getEditor().getEditorComponent(); + if((!(comp instanceof JComponent)) || + ((JComponent)comp).isRequestFocusEnabled()){ + comp.requestFocus(); + } + } else if(comboBox.isRequestFocusEnabled()){ + comboBox.requestFocus(); + } + togglePopup(); + } + } + + + +} From 2325ca73fd6a3a175d4ec0148ef944af38e4096b Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 12 Oct 2016 00:17:50 +0800 Subject: [PATCH 2/7] rt --- .../src/com/fr/design/mainframe/ShareWidgetPane.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java b/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java index 7abfb6900a..79f15b3646 100644 --- a/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java +++ b/designer_form/src/com/fr/design/mainframe/ShareWidgetPane.java @@ -13,15 +13,15 @@ import java.util.ArrayList; * Created by xiaxiang on 2016/10/10. */ public class ShareWidgetPane extends JPanel { - public ShareWidgetPane(ArrayList elCaseBindInfos) { + public ShareWidgetPane(ArrayList elCaseBindInfoList) { this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));// 设置面板的边框 ,距离上、左、下、右 的距离 - int rowCount = (elCaseBindInfos.size() + 1)/2; + int rowCount = (elCaseBindInfoList.size() + 1)/2; this.setLayout(new GridLayout(rowCount, 2, 10, 10)); - for (ElCaseBindInfo rbModuleInfo : elCaseBindInfos) { + for (ElCaseBindInfo rbModuleInfo : elCaseBindInfoList) { ShareWidgetButton widgetButton = new ShareWidgetButton(rbModuleInfo); this.add(widgetButton); } - if (elCaseBindInfos.size() == 1) { + if (elCaseBindInfoList.size() == 1) { this.add(new JPanel()); } From 760aff6304c5c5ccbcf44f0974eb2f45a9dd2ccd Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 12 Oct 2016 02:02:18 +0800 Subject: [PATCH 3/7] rt --- .../com/fr/design/mainframe/widget/UITreeComboBox.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java index 4d92ccc264..dd2c8fa897 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java +++ b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java @@ -31,11 +31,11 @@ public class UITreeComboBox extends JComboBox{ public UITreeComboBox(ComponentTree componentTree){ this.setTree(componentTree); tree.getDesigner().addDesignerEditListener(new TreeComboBoxDesignerEditAdapter()); - for(int i=0; i Date: Wed, 12 Oct 2016 02:02:51 +0800 Subject: [PATCH 4/7] rt --- .../src/com/fr/design/mainframe/widget/UITreeComboBox.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java index dd2c8fa897..8bb921df4b 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java +++ b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java @@ -31,10 +31,6 @@ public class UITreeComboBox extends JComboBox{ public UITreeComboBox(ComponentTree componentTree){ this.setTree(componentTree); tree.getDesigner().addDesignerEditListener(new TreeComboBoxDesignerEditAdapter()); -// for(int i=0; i Date: Wed, 12 Oct 2016 09:20:56 +0800 Subject: [PATCH 5/7] rt --- .../mainframe/widget/UITreeComboBox.java | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java index 8bb921df4b..81afb7cc8d 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java +++ b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java @@ -31,6 +31,10 @@ public class UITreeComboBox extends JComboBox{ public UITreeComboBox(ComponentTree componentTree){ this.setTree(componentTree); tree.getDesigner().addDesignerEditListener(new TreeComboBoxDesignerEditAdapter()); +// for(int i=0; i Date: Wed, 12 Oct 2016 09:31:06 +0800 Subject: [PATCH 6/7] rt --- .../fr/design/mainframe/widget/UITreeComboBox.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java index 81afb7cc8d..7f55ddeafe 100644 --- a/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java +++ b/designer_form/src/com/fr/design/mainframe/widget/UITreeComboBox.java @@ -123,22 +123,12 @@ public class UITreeComboBox extends JComboBox{ } - public TreePath[] getSelectedTreePath() { - XCreator[] creators = tree.getDesigner().getSelectionModel().getSelection().getSelectedCreators(); - TreePath[] paths = new TreePath[creators.length]; - - for (int i = 0; i < paths.length; i++) { - paths[i] = tree.buildTreePath(creators[i]); - } - return paths; - } - private class TreeComboBoxDesignerEditAdapter implements DesignerEditListener { @Override public void fireCreatorModified(DesignerEvent evt) { if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED || evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) { - TreePath[] paths = getSelectedTreePath(); + TreePath[] paths = tree.getSelectedTreePath(); if (paths.length == 1) { tree.setAndScrollSelectionPath(paths[0]); From 0efb563d4ce847285c6c7fff0fa2fa897888f146 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 12 Oct 2016 09:31:48 +0800 Subject: [PATCH 7/7] =?UTF-8?q?componenttree=E5=90=8E=E9=9D=A2=E8=BF=98?= =?UTF-8?q?=E8=A6=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/ComponentTree.java | 182 +++++++++--------- 1 file changed, 93 insertions(+), 89 deletions(-) diff --git a/designer_form/src/com/fr/design/mainframe/ComponentTree.java b/designer_form/src/com/fr/design/mainframe/ComponentTree.java index fb0586a693..0a268610ec 100644 --- a/designer_form/src/com/fr/design/mainframe/ComponentTree.java +++ b/designer_form/src/com/fr/design/mainframe/ComponentTree.java @@ -40,7 +40,7 @@ public class ComponentTree extends JTree { TreePath[] paths = getSelectedTreePath(); addTreeSelectionListener(designer); setSelectionPaths(paths); - + designer.addDesignerEditListener(new TreeDesignerEditAdapter()); this.addMouseListener(new MouseAdapter() { @@ -68,15 +68,19 @@ public class ComponentTree extends JTree { setEditable(true); } + public FormDesigner getDesigner() { + return designer; + } + /** * 构造函数 - * + * * @param designer 设计界面组件 * @param model 构造JTree的model */ public ComponentTree(FormDesigner designer,ComponentTreeModel model) { - this(designer); - this.setModel(model); + this(designer); + this.setModel(model); } @@ -96,17 +100,17 @@ public class ComponentTree extends JTree { return super.isPathEditable(path); } - /** - * 将值转换为文本 - * @param value 值 - * @param selected 是否选中 - * @param expanded 扩展 - * @param leaf 是否叶子 - * @param row 行 - * @param hasFocus 是否焦点 - * - * @return 返回文本 - */ + /** + * 将值转换为文本 + * @param value 值 + * @param selected 是否选中 + * @param expanded 扩展 + * @param leaf 是否叶子 + * @param row 行 + * @param hasFocus 是否焦点 + * + * @return 返回文本 + */ @Override public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value != null && value instanceof XCreator) { @@ -115,25 +119,25 @@ public class ComponentTree extends JTree { return super.convertValueToText(value, selected, expanded, leaf, row, hasFocus); } } - + public void setAndScrollSelectionPath(TreePath treepath) { - setSelectionPath(treepath); - scrollPathToVisible(treepath); + setSelectionPath(treepath); + scrollPathToVisible(treepath); + } + + private void popupMenu(MouseEvent e) { + TreePath path = this.getSelectionPath(); + if (path == null) { + return; + } + Component component = (Component) path.getLastPathComponent(); + if (!(component instanceof XCreator)) { + return; + } + ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, (XCreator) component); + JPopupMenu menu = adapter.getContextPopupMenu(e); + menu.show(this, e.getX(), e.getY()); } - - private void popupMenu(MouseEvent e) { - TreePath path = this.getSelectionPath(); - if (path == null) { - return; - } - Component component = (Component) path.getLastPathComponent(); - if (!(component instanceof XCreator)) { - return; - } - ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, (XCreator) component); - JPopupMenu menu = adapter.getContextPopupMenu(e); - menu.show(this, e.getX(), e.getY()); - } /** * 刷新 @@ -145,51 +149,51 @@ public class ComponentTree extends JTree { - - public TreePath[] getSelectedTreePath() { - XCreator[] creators = designer.getSelectionModel().getSelection().getSelectedCreators(); - TreePath[] paths = new TreePath[creators.length]; - - for (int i = 0; i < paths.length; i++) { - paths[i] = buildTreePath(creators[i]); - } - return paths; - } - - private class TreeDesignerEditAdapter implements DesignerEditListener { - - @Override - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { - TreePath[] paths = getSelectedTreePath(); - - if (paths.length == 1) { - setAndScrollSelectionPath(paths[0]); - } else { - setSelectionPaths(paths); - } - } else if(evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) { - ComponentTree.this.refreshUI(); - TreePath[] paths = getSelectedTreePath(); - - if (paths.length == 1) { - setAndScrollSelectionPath(paths[0]); - } else { - setSelectionPaths(paths); - } - ComponentTree.this.repaint(); - - } else { - ComponentTree.this.refreshUI(); - ComponentTree.this.repaint(); - } - } - - @Override - public boolean equals(Object o) { - return o.getClass() == this.getClass(); - } - } + + public TreePath[] getSelectedTreePath() { + XCreator[] creators = designer.getSelectionModel().getSelection().getSelectedCreators(); + TreePath[] paths = new TreePath[creators.length]; + + for (int i = 0; i < paths.length; i++) { + paths[i] = buildTreePath(creators[i]); + } + return paths; + } + + private class TreeDesignerEditAdapter implements DesignerEditListener { + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) { + TreePath[] paths = getSelectedTreePath(); + + if (paths.length == 1) { + setAndScrollSelectionPath(paths[0]); + } else { + setSelectionPaths(paths); + } + } else if(evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED) { + ComponentTree.this.refreshUI(); + TreePath[] paths = getSelectedTreePath(); + + if (paths.length == 1) { + setAndScrollSelectionPath(paths[0]); + } else { + setSelectionPaths(paths); + } + ComponentTree.this.repaint(); + + } else { + ComponentTree.this.refreshUI(); + ComponentTree.this.repaint(); + } + } + + @Override + public boolean equals(Object o) { + return o.getClass() == this.getClass(); + } + } /** @@ -211,11 +215,11 @@ public class ComponentTree extends JTree { paths[i] = buildTreePath(searchList.get(i)); } if(paths.length > 0) { - setAndScrollSelectionPath(paths[0]); + setAndScrollSelectionPath(paths[0]); } else { - setSelectionPath(); + setSelectionPath(); } - return paths; + return paths; } @@ -248,7 +252,7 @@ public class ComponentTree extends JTree { * 触发 */ public void fireTreeChanged() { - designer.refreshDesignerUI(); + designer.refreshDesignerUI(); } /** @@ -267,14 +271,14 @@ public class ComponentTree extends JTree { ArrayList path = new ArrayList(); Component parent = comp; - while (parent != null) { - XCreator creator = (XCreator) parent; - path.add(0, parent); - if (creator != comp ) { - creator.notShowInComponentTree(path); - } - parent = parent.getParent(); - } + while (parent != null) { + XCreator creator = (XCreator) parent; + path.add(0, parent); + if (creator != comp ) { + creator.notShowInComponentTree(path); + } + parent = parent.getParent(); + } Object[] components = path.toArray(); return new TreePath(components); }