|
|
|
@ -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)); |
|
|
|
@ -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 selected 是否选中 |
|
|
|
|
* @param expanded 扩展 |
|
|
|
|
* @param leaf 是否叶子 |
|
|
|
|
* @param row 行 |
|
|
|
|
* @param hasFocus 是否焦点 |
|
|
|
|
* |
|
|
|
|
* @return 返回文本 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |