diff --git a/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java b/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java index d96162559..37094494b 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java @@ -17,6 +17,7 @@ import com.fr.stable.StringUtils; import java.awt.Rectangle; import java.awt.event.MouseListener; import java.util.Stack; +import java.util.function.Consumer; import javax.swing.BorderFactory; import javax.swing.DropMode; import javax.swing.JPanel; @@ -350,6 +351,7 @@ public class ComponentTree extends JTree { private final class ComponetTreeMouseListener extends MouseAdapter { private final JTree tree; + private XCreator selectedCreator; private ComponetTreeMouseListener(JTree tree) { this.tree = tree; @@ -379,6 +381,49 @@ public class ComponentTree extends JTree { @Override public void mouseClicked(MouseEvent e) { + onMouseEvent(e, new Consumer() { + @Override + public void accept(XCreator creator) { + if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1 && !designer.isFormParaDesigner()) { + startEditing(creator, e); + } + } + }); + + } + + @Override + public void mousePressed(MouseEvent e) { + onMouseEvent(e, new Consumer() { + @Override + public void accept(XCreator creator) { + if (e.getButton() == MouseEvent.BUTTON1) { + selectedCreator = creator; + } + } + }); + } + + @Override + public void mouseReleased(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON1 && selectedCreator != null) { + showSelectedPopup(selectedCreator); + } + } + + private void showSelectedPopup(XCreator comp) { + Rectangle rectangle = getRelativeBounds(comp); + comp.showSelectedPopup(designer, rectangle, comp.acceptType(XWTitleLayout.class)); + comp.setSelected(true); + } + + /** + * 响应鼠标事件并解析选中的组件 + * + * @param e + * @param consumer + */ + private void onMouseEvent(final MouseEvent e, Consumer consumer) { Point p = e.getPoint(); // 解析组件树路径 获取选中的组件 int selRow = tree.getRowForLocation(p.x, p.y); @@ -388,21 +433,10 @@ public class ComponentTree extends JTree { Point point = bounds.getLocation(); SwingUtilities.convertPointToScreen(point, tree); XCreator comp = (XCreator) path.getLastPathComponent(); - // 鼠标左键 双击 - if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1 && !designer.isFormParaDesigner()) { - startEditing(comp, e); - } else if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) { - showSelectedPopup(comp); - } + consumer.accept(comp); } } - private void showSelectedPopup(XCreator comp) { - Rectangle rectangle = getRelativeBounds(comp); - comp.showSelectedPopup(designer, rectangle, comp.acceptType(XWTitleLayout.class)); - comp.setSelected(true); - } - /** * 组件进入编辑状态 *