Browse Source

REPORT-55188 【组件背景分离】组件复用-设计器右侧组件目录树选中组件应也触发绝对布局下组件的工具栏 update

persist/11.0
hades 3 years ago
parent
commit
2428f72694
  1. 58
      designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java

58
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.Rectangle;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.util.Stack; import java.util.Stack;
import java.util.function.Consumer;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.DropMode; import javax.swing.DropMode;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -350,6 +351,7 @@ public class ComponentTree extends JTree {
private final class ComponetTreeMouseListener extends MouseAdapter { private final class ComponetTreeMouseListener extends MouseAdapter {
private final JTree tree; private final JTree tree;
private XCreator selectedCreator;
private ComponetTreeMouseListener(JTree tree) { private ComponetTreeMouseListener(JTree tree) {
this.tree = tree; this.tree = tree;
@ -379,6 +381,49 @@ public class ComponentTree extends JTree {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
onMouseEvent(e, new Consumer<XCreator>() {
@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<XCreator>() {
@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<XCreator> consumer) {
Point p = e.getPoint(); Point p = e.getPoint();
// 解析组件树路径 获取选中的组件 // 解析组件树路径 获取选中的组件
int selRow = tree.getRowForLocation(p.x, p.y); int selRow = tree.getRowForLocation(p.x, p.y);
@ -388,21 +433,10 @@ public class ComponentTree extends JTree {
Point point = bounds.getLocation(); Point point = bounds.getLocation();
SwingUtilities.convertPointToScreen(point, tree); SwingUtilities.convertPointToScreen(point, tree);
XCreator comp = (XCreator) path.getLastPathComponent(); XCreator comp = (XCreator) path.getLastPathComponent();
// 鼠标左键 双击 consumer.accept(comp);
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1 && !designer.isFormParaDesigner()) {
startEditing(comp, e);
} else if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) {
showSelectedPopup(comp);
}
} }
} }
private void showSelectedPopup(XCreator comp) {
Rectangle rectangle = getRelativeBounds(comp);
comp.showSelectedPopup(designer, rectangle, comp.acceptType(XWTitleLayout.class));
comp.setSelected(true);
}
/** /**
* 组件进入编辑状态 * 组件进入编辑状态
* *

Loading…
Cancel
Save