Browse Source

REPORT-4634 组件叠加体验优化=>4缩略图=>缩略图框架

master
plough 7 years ago
parent
commit
2edcd45da6
  1. 118
      designer_form/src/com/fr/design/mainframe/ComponentTree.java

118
designer_form/src/com/fr/design/mainframe/ComponentTree.java

@ -1,9 +1,12 @@
package com.fr.design.mainframe;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
@ -12,6 +15,7 @@ import com.fr.design.designer.creator.*;
import com.fr.design.designer.treeview.ComponentTreeCellRenderer;
import com.fr.design.designer.treeview.ComponentTreeModel;
import com.fr.design.gui.itree.UITreeUI;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.StringUtils;
public class ComponentTree extends JTree {
@ -19,6 +23,7 @@ public class ComponentTree extends JTree {
private FormDesigner designer;
private ComponentTreeModel model;
private UITreeUI uiTreeUI = new UITreeUI();
private PopupPreviewPane previewPane;
private static final int PADDING_LEFT = 10;
private static final int PADDING_TOP = 8;
@ -33,6 +38,7 @@ public class ComponentTree extends JTree {
this.setTransferHandler(new TreeTransferHandler());
this.refreshTreeRoot();
addTreeSelectionListener(designer);
addMouseMotionListener(new ComponetTreeMouseListener(this));
setEditable(true);
setUI(uiTreeUI);
setBorder(BorderFactory.createEmptyBorder(PADDING_TOP, PADDING_LEFT, 0, 0));
@ -46,9 +52,9 @@ public class ComponentTree extends JTree {
* 构造函数
*
* @param designer 设计界面组件
* @param model 构造JTree的model
* @param model 构造JTree的model
*/
public ComponentTree(FormDesigner designer,ComponentTreeModel model) {
public ComponentTree(FormDesigner designer, ComponentTreeModel model) {
this(designer);
this.setModel(model);
}
@ -63,6 +69,7 @@ public class ComponentTree extends JTree {
/**
* 是否可编辑
*
* @param path 树路径
* @return 是则返回true
*/
@ -73,13 +80,13 @@ public class ComponentTree extends JTree {
/**
* 将值转换为文本
* @param value
*
* @param value
* @param selected 是否选中
* @param expanded 扩展
* @param leaf 是否叶子
* @param row
* @param leaf 是否叶子
* @param row
* @param hasFocus 是否焦点
*
* @return 返回文本
*/
@Override
@ -117,7 +124,7 @@ public class ComponentTree extends JTree {
/**
*搜索指定名称的路径
* 搜索指定名称的路径
*
* @param text 名称
* @return 树路径
@ -134,7 +141,7 @@ public class ComponentTree extends JTree {
for (int i = 0; i < paths.length; i++) {
paths[i] = buildTreePath(searchList.get(i));
}
if(paths.length > 0) {
if (paths.length > 0) {
setAndScrollSelectionPath(paths);
} else {
setSelectionPath();
@ -143,7 +150,7 @@ public class ComponentTree extends JTree {
}
private void setSelectionPath(){
private void setSelectionPath() {
/**
* 不让传null参数所以只有自己定义
@ -194,13 +201,13 @@ public class ComponentTree extends JTree {
while (parent != null) {
XCreator creator = (XCreator) parent;
path.add(0, parent);
if (creator != comp ) {
if (creator != comp) {
creator.notShowInComponentTree(path);
}
//绝对布局作为body的时候不显示自适应布局父层
if (((XCreator) parent).acceptType(XWAbsoluteBodyLayout.class)) {
if ((parent.getParent() != null)
&& ((XCreator)parent.getParent()).acceptType(XWFitLayout.class)){
&& ((XCreator) parent.getParent()).acceptType(XWFitLayout.class)) {
parent = parent.getParent().getParent();
continue;
}
@ -212,4 +219,93 @@ public class ComponentTree extends JTree {
return new TreePath(components);
}
private void popupPreviewPane(int popupPosYOnScreen) {
if (previewPane == null) {
previewPane = new PopupPreviewPane();
}
if (previewPane.isVisible() && previewPane.getLocationOnScreen().y != popupPosYOnScreen) {
previewPane.setVisible(false);
}
if (!previewPane.isVisible()) {
int popupPosY = popupPosYOnScreen - FormHierarchyTreePane.getInstance().getLocationOnScreen().y;
GUICoreUtils.showPopupMenu(previewPane, FormHierarchyTreePane.getInstance(), -previewPane.getPreferredSize().width, popupPosY);
}
}
private void hidePreviewPane() {
if (previewPane != null && previewPane.isVisible()) {
previewPane.setVisible(false);
}
}
private final class ComponetTreeMouseListener extends MouseAdapter {
private final JTree tree;
private ComponetTreeMouseListener(JTree tree) {
this.tree = tree;
}
@Override
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int selRow = tree.getRowForLocation(p.x, p.y);
TreeCellRenderer r = tree.getCellRenderer();
if (selRow != -1 && r != null) {
TreePath path = tree.getPathForRow(selRow);
Point point = tree.getPathBounds(path).getLocation();
SwingUtilities.convertPointToScreen(point, tree);
popupPreviewPane(point.y);
} else {
hidePreviewPane();
}
}
}
private class PopupPreviewPane extends JPopupMenu {
private Container contentPane;
PopupPreviewPane() {
contentPane = new JPanel();
contentPane.setBackground(Color.blue);
this.setLayout(new BorderLayout());
// this.add(new PopupToolPane(propertyItem), BorderLayout.NORTH);
this.add(contentPane, BorderLayout.CENTER);
this.setOpaque(false);
// setPreferredSize(new Dimension(CONTAINER_WIDTH - TAB_WIDTH, POPUP_DEFAULT_HEIGHT));
setPreferredSize(new Dimension(200, 200));
setBorder(BorderFactory.createLineBorder(UIConstants.LINE_COLOR));
}
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
// if (visible == true) {
// replaceContentPane(propertyItem.getContentArea());
// } else {
// propertyItem.reAddContentArea();
// }
}
public void menuSelectionChanged(boolean isIncluded) {
}
public Container getContentPane() {
return contentPane;
}
public void replaceContentPane(Container pane) {
this.remove(this.contentPane);
this.add(this.contentPane = pane);
refreshContainer();
}
private void refreshContainer() {
validate();
repaint();
revalidate();
}
}
}
Loading…
Cancel
Save