|
|
@ -4,11 +4,9 @@ import com.fr.design.constants.UIConstants; |
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
import com.fr.design.designer.creator.XCreatorUtils; |
|
|
|
import com.fr.design.designer.creator.XCreatorUtils; |
|
|
|
import com.fr.design.designer.creator.XLayoutContainer; |
|
|
|
import com.fr.design.designer.creator.XLayoutContainer; |
|
|
|
import com.fr.design.designer.creator.XWAbsoluteBodyLayout; |
|
|
|
|
|
|
|
import com.fr.design.designer.creator.XWFitLayout; |
|
|
|
|
|
|
|
import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; |
|
|
|
|
|
|
|
import com.fr.design.designer.treeview.ComponentTreeCellRenderer; |
|
|
|
import com.fr.design.designer.treeview.ComponentTreeCellRenderer; |
|
|
|
import com.fr.design.designer.treeview.ComponentTreeModel; |
|
|
|
import com.fr.design.designer.treeview.ComponentTreeModel; |
|
|
|
|
|
|
|
import com.fr.design.file.HistoryTemplateListCache; |
|
|
|
import com.fr.design.gui.itree.UITreeUI; |
|
|
|
import com.fr.design.gui.itree.UITreeUI; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
@ -19,9 +17,7 @@ import javax.swing.JPanel; |
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
import javax.swing.JPopupMenu; |
|
|
|
import javax.swing.JTree; |
|
|
|
import javax.swing.JTree; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.tree.DefaultMutableTreeNode; |
|
|
|
|
|
|
|
import javax.swing.tree.TreeCellRenderer; |
|
|
|
import javax.swing.tree.TreeCellRenderer; |
|
|
|
import javax.swing.tree.TreeNode; |
|
|
|
|
|
|
|
import javax.swing.tree.TreePath; |
|
|
|
import javax.swing.tree.TreePath; |
|
|
|
import javax.swing.tree.TreeSelectionModel; |
|
|
|
import javax.swing.tree.TreeSelectionModel; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.BorderLayout; |
|
|
@ -37,8 +33,9 @@ import java.awt.image.BufferedImage; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Enumeration; |
|
|
|
import java.util.Enumeration; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Vector; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
public class ComponentTree extends JTree { |
|
|
|
public class ComponentTree extends JTree { |
|
|
|
|
|
|
|
|
|
|
@ -46,6 +43,8 @@ public class ComponentTree extends JTree { |
|
|
|
private ComponentTreeModel model; |
|
|
|
private ComponentTreeModel model; |
|
|
|
private UITreeUI uiTreeUI = new UITreeUI(); |
|
|
|
private UITreeUI uiTreeUI = new UITreeUI(); |
|
|
|
private PopupPreviewPane previewPane; |
|
|
|
private PopupPreviewPane previewPane; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<String, List<TreePath>> treePathCache = new HashMap<>(); |
|
|
|
private static final int PADDING_LEFT = 5; |
|
|
|
private static final int PADDING_LEFT = 5; |
|
|
|
private static final int PADDING_TOP = 5; |
|
|
|
private static final int PADDING_TOP = 5; |
|
|
|
|
|
|
|
|
|
|
@ -85,6 +84,7 @@ public class ComponentTree extends JTree { |
|
|
|
public ComponentTree(FormDesigner designer, ComponentTreeModel model) { |
|
|
|
public ComponentTree(FormDesigner designer, ComponentTreeModel model) { |
|
|
|
this(designer); |
|
|
|
this(designer); |
|
|
|
this.setModel(model); |
|
|
|
this.setModel(model); |
|
|
|
|
|
|
|
expandTree(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setSelectionPath(TreePath path) { |
|
|
|
public void setSelectionPath(TreePath path) { |
|
|
@ -138,7 +138,6 @@ public class ComponentTree extends JTree { |
|
|
|
setSelectionPaths(treepath); |
|
|
|
setSelectionPaths(treepath); |
|
|
|
if (treepath.length > 0) { |
|
|
|
if (treepath.length > 0) { |
|
|
|
scrollPathToVisible(treepath[0]); |
|
|
|
scrollPathToVisible(treepath[0]); |
|
|
|
//expandPath(treepath[0]);
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -193,6 +192,20 @@ public class ComponentTree extends JTree { |
|
|
|
return paths; |
|
|
|
return paths; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void setExpandedState(TreePath path, boolean state) { |
|
|
|
|
|
|
|
super.setExpandedState(path, state); |
|
|
|
|
|
|
|
saveTreePath(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 删除key对应的缓存展开路径 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void removeTreePath(String key) { |
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(key)) { |
|
|
|
|
|
|
|
treePathCache.remove(key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setSelectionPath() { |
|
|
|
private void setSelectionPath() { |
|
|
|
|
|
|
|
|
|
|
@ -232,6 +245,7 @@ public class ComponentTree extends JTree { |
|
|
|
public void refreshTreeRoot() { |
|
|
|
public void refreshTreeRoot() { |
|
|
|
model = new ComponentTreeModel(designer, designer.getTopContainer()); |
|
|
|
model = new ComponentTreeModel(designer, designer.getTopContainer()); |
|
|
|
setModel(model); |
|
|
|
setModel(model); |
|
|
|
|
|
|
|
expandTree(); |
|
|
|
setDragEnabled(false); |
|
|
|
setDragEnabled(false); |
|
|
|
setDropMode(DropMode.ON_OR_INSERT); |
|
|
|
setDropMode(DropMode.ON_OR_INSERT); |
|
|
|
setTransferHandler(new TreeTransferHandler()); |
|
|
|
setTransferHandler(new TreeTransferHandler()); |
|
|
@ -239,49 +253,56 @@ public class ComponentTree extends JTree { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获得树的展开路径 |
|
|
|
* 从缓存中获取展开路径并进行展开 |
|
|
|
* */ |
|
|
|
*/ |
|
|
|
public void getExpandNodes(List<TreePath> searchList) { |
|
|
|
public void expandTree() { |
|
|
|
getExpandNodes((XLayoutContainer)designer.getTopContainer(),searchList); |
|
|
|
expandTree(loadTreePath()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void getExpandNodes(XLayoutContainer container, List<TreePath> searchList) { |
|
|
|
/** |
|
|
|
TreePath treePath = buildTreePath(container); |
|
|
|
* 按照传入参数展开组件树 |
|
|
|
if (isExpanded(treePath)) { |
|
|
|
*/ |
|
|
|
searchList.add(treePath); |
|
|
|
private void expandTree(List<TreePath> list) { |
|
|
|
for (int i = 0, size = container.getXCreatorCount(); i < size; i++) { |
|
|
|
if (list == null) { |
|
|
|
XCreator creator = container.getXCreator(i); |
|
|
|
return; |
|
|
|
if (creator.acceptType(XLayoutContainer.class) || creator.acceptType(XCardSwitchButton.class)) { |
|
|
|
|
|
|
|
getExpandNodes((XLayoutContainer) creator.getXCreator(), searchList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (TreePath treePath : list) { |
|
|
|
|
|
|
|
expandPath(treePath); |
|
|
|
} |
|
|
|
} |
|
|
|
//对绝对布局做特殊处理
|
|
|
|
|
|
|
|
if (container.acceptType(XWFitLayout.class)) { |
|
|
|
|
|
|
|
XWFitLayout bodyFitLayout = (XWFitLayout) container; |
|
|
|
|
|
|
|
for (int j = 0; j < bodyFitLayout.getXCreatorCount(); j++) { |
|
|
|
|
|
|
|
//类型是绝对布局并且还是body
|
|
|
|
|
|
|
|
if (bodyFitLayout.getXCreator(j).acceptType(XWAbsoluteBodyLayout.class)) { |
|
|
|
|
|
|
|
container = (XLayoutContainer) bodyFitLayout.getXCreator(j); |
|
|
|
|
|
|
|
getExpandNodes(container, searchList); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获得树的展开路径 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private List<TreePath> getExpandTreePaths() { |
|
|
|
|
|
|
|
List<TreePath> result = new ArrayList<>(); |
|
|
|
|
|
|
|
TreePath rootTreePath = buildTreePath(designer.getTopContainer()); |
|
|
|
|
|
|
|
Enumeration<TreePath> enumeration = getExpandedDescendants(rootTreePath); |
|
|
|
|
|
|
|
if (enumeration != null) { |
|
|
|
|
|
|
|
while (enumeration.hasMoreElements()) { |
|
|
|
|
|
|
|
result.add(enumeration.nextElement()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
private void saveTreePath() { |
|
|
|
* 将树按照展开路径进行展开 |
|
|
|
String templateID = designer.getTarget().getTemplateID(); |
|
|
|
* */ |
|
|
|
JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
public void expandNodes(List<TreePath> list){ |
|
|
|
if (templateID != null && jt != null && StringUtils.equals(templateID, jt.getTarget().getTemplateID())) { |
|
|
|
for(TreePath treePath:list) { |
|
|
|
String key = jt.getEditingFILE().getPath() + templateID; |
|
|
|
if (treePath.getLastPathComponent() instanceof XLayoutContainer) { |
|
|
|
treePathCache.put(key, getExpandTreePaths()); |
|
|
|
XLayoutContainer creator= (XLayoutContainer) treePath.getLastPathComponent(); |
|
|
|
|
|
|
|
if (XCreatorUtils.getParentXLayoutContainer(creator) == null) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
expandPath(treePath); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<TreePath> loadTreePath() { |
|
|
|
|
|
|
|
JTemplate<?, ?> jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
|
|
|
if (jt == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String key = jt.getEditingFILE().getPath() + designer.getTarget().getTemplateID(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return treePathCache.get(key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private TreePath buildTreePath(Component comp) { |
|
|
|
private TreePath buildTreePath(Component comp) { |
|
|
|