From 76ac6b7edbf7de2c29ed998b39ba78813470414d Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 24 Sep 2020 09:41:40 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-38376=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=A0=91=E7=AD=89=E6=A0=91=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?JDK11=E4=B8=8B=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/data/datapane/TableDataTree.java | 21 ++--- .../gui/itree/filetree/EnvFileTree.java | 12 +-- .../designer/data/comp/MapDataTree.java | 48 +++++----- .../treeview/ComponentTreeCellRenderer.java | 89 +++++++++---------- 4 files changed, 71 insertions(+), 99 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java index 8f49b6e504..94efc5faa8 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java @@ -1,21 +1,22 @@ package com.fr.design.data.datapane; import com.fr.base.BaseUtils; -import com.fr.general.NameObject; import com.fr.design.constants.UIConstants; import com.fr.design.data.tabledata.wrapper.TableDataWrapper; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree; import com.fr.design.icon.IconPathConstants; import com.fr.general.ComparatorUtils; +import com.fr.general.NameObject; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; /** * TableData Tree @@ -31,6 +32,7 @@ public class TableDataTree extends UserObjectRefreshJTree { this.setCellRenderer(tableDataTreeCellRenderer); this.setEditable(false); } + // CellRenderer private DefaultTreeCellRenderer tableDataTreeCellRenderer = new DefaultTreeCellRenderer() { private static final long serialVersionUID = 1L; @@ -66,14 +68,7 @@ public class TableDataTree extends UserObjectRefreshJTree { this.setIcon(null); this.setText(PENDING.toString()); } - // 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..." - UILabel label = new UILabel(); - label.setText(getText()); - label.setIcon(getIcon()); - Dimension dim = label.getPreferredSize(); - dim.height += 2; - this.setSize(dim); - this.setPreferredSize(dim); + this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); this.setTextSelectionColor(Color.WHITE); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); @@ -152,7 +147,7 @@ public class TableDataTree extends UserObjectRefreshJTree { /* * p:获得选中的NameObject = name + tabledata. - */ + */ public NameObject getSelectedNameObject() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java index d5a9044d5e..435d5a465a 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java @@ -2,7 +2,6 @@ package com.fr.design.gui.itree.filetree; import com.fr.base.FRContext; import com.fr.design.constants.UIConstants; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.gui.itree.refreshabletree.RefreshableJTree; import com.fr.design.i18n.Toolkit; @@ -14,13 +13,13 @@ import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.workspace.WorkContext; +import javax.swing.BorderFactory; import javax.swing.JTree; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.Color; import java.awt.Component; -import java.awt.Dimension; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -79,14 +78,7 @@ public class EnvFileTree extends RefreshableJTree { this.setIcon(null); this.setText(PENDING.toString()); } - // 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..." - UILabel label = new UILabel(); - label.setText(getText()); - label.setIcon(getIcon()); - this.setSize(label.getPreferredSize()); - Dimension dim = label.getPreferredSize(); - dim.height += 2; - this.setPreferredSize(dim); + this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); this.setTextSelectionColor(Color.WHITE); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); diff --git a/designer-chart/src/main/java/com/fr/van/chart/drillmap/designer/data/comp/MapDataTree.java b/designer-chart/src/main/java/com/fr/van/chart/drillmap/designer/data/comp/MapDataTree.java index 5a223cbf0c..034c621d57 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/drillmap/designer/data/comp/MapDataTree.java +++ b/designer-chart/src/main/java/com/fr/van/chart/drillmap/designer/data/comp/MapDataTree.java @@ -1,13 +1,13 @@ package com.fr.van.chart.drillmap.designer.data.comp; import com.fr.design.constants.UIConstants; -import com.fr.design.gui.ilable.UILabel; import com.fr.general.ComparatorUtils; import com.fr.plugin.chart.map.designer.type.GEOJSONTreeHelper; import com.fr.plugin.chart.map.server.ChartGEOJSONHelper; import com.fr.plugin.chart.map.server.CompatibleGEOJSONHelper; import com.fr.stable.StringUtils; +import javax.swing.BorderFactory; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; @@ -15,7 +15,6 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.Component; -import java.awt.Dimension; import java.util.Enumeration; /** @@ -23,7 +22,7 @@ import java.util.Enumeration; */ public class MapDataTree extends JTree { - public MapDataTree(TreeNode root){ + public MapDataTree(TreeNode root) { super(); this.setModel(model); model.setRoot(root); @@ -49,54 +48,54 @@ public class MapDataTree extends JTree { if (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); - if(GEOJSONTreeHelper.getInstance().isSelectableTreeNode(child)){ + if (GEOJSONTreeHelper.isSelectableTreeNode(child)) { selectTreeNode(child, m_model); - }else{ + } else { setFirstChildTreeNode(child, m_model); } } } - private void setFirstChildTreeNode(DefaultMutableTreeNode parent, DefaultTreeModel m_model){ + private void setFirstChildTreeNode(DefaultMutableTreeNode parent, DefaultTreeModel m_model) { Enumeration children = parent.children(); - if (children.hasMoreElements()){ + if (children.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); selectTreeNode(node, m_model); } } - public void changeRootNode(TreeNode node){ + public void changeRootNode(TreeNode node) { DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); m_model.setRoot(node); } public String getSelectNodeJSONPath() { - if(this.getLastSelectedPathComponent() == null){ + if (this.getLastSelectedPathComponent() == null) { return StringUtils.EMPTY; } - DefaultMutableTreeNode currentSel = (DefaultMutableTreeNode)this.getLastSelectedPathComponent(); + DefaultMutableTreeNode currentSel = (DefaultMutableTreeNode) this.getLastSelectedPathComponent(); return CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(currentSel.getUserObject().toString()); } //根据路径精确查找 public DefaultMutableTreeNode setSelectNodePath(String jsonUrl) { - if(StringUtils.isEmpty(jsonUrl) || CompatibleGEOJSONHelper.isDeprecated(jsonUrl)){ + if (StringUtils.isEmpty(jsonUrl) || CompatibleGEOJSONHelper.isDeprecated(jsonUrl)) { return null; } DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) m_model.getRoot(); Enumeration els = root.postorderEnumeration(); - while(els.hasMoreElements()){ + while (els.hasMoreElements()) { DefaultMutableTreeNode el = (DefaultMutableTreeNode) els.nextElement(); - if(el == null || el.getUserObject() == null){ + if (el == null || el.getUserObject() == null) { return null; } String dirPath = el.getUserObject().toString(); - String url = CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(dirPath); + String url = CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(dirPath); //先equals再valid原因:valid 远程下实时去服务器看有没有json文件 if (ComparatorUtils.equals(jsonUrl, url) && GEOJSONTreeHelper.isValidDirPath(dirPath)) { selectTreeNode(el, m_model); @@ -115,14 +114,7 @@ public class MapDataTree extends JTree { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value; String name = getPresentName(treeNode); this.setText(name); - - UILabel label = new UILabel(); - label.setText(getText()); - label.setIcon(getIcon()); - this.setSize(label.getPreferredSize()); - Dimension dim = label.getPreferredSize(); - dim.height += 2; - this.setPreferredSize(dim); + this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); this.setBackgroundNonSelectionColor(UIConstants.NORMAL_BACKGROUND); this.setForeground(UIConstants.FONT_COLOR); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); @@ -131,25 +123,25 @@ public class MapDataTree extends JTree { }; protected String getPresentName(DefaultMutableTreeNode treeNode) { - if(treeNode == null || treeNode.getUserObject() == null){ + if (treeNode == null || treeNode.getUserObject() == null) { return StringUtils.EMPTY; } return ChartGEOJSONHelper.getPresentNameWithPath(treeNode.getUserObject().toString()); } //模糊搜索 深度优先. - public void search(String text){ - if(StringUtils.isEmpty(text)){ + public void search(String text) { + if (StringUtils.isEmpty(text)) { return; } DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) m_model.getRoot(); Enumeration els = root.postorderEnumeration(); - while(els.hasMoreElements()){ + while (els.hasMoreElements()) { DefaultMutableTreeNode el = (DefaultMutableTreeNode) els.nextElement(); - String path = el.getUserObject().toString(); + String path = el.getUserObject().toString(); String fileName = ChartGEOJSONHelper.getPresentNameWithPath(path); if (StringUtils.contains(fileName, text) && GEOJSONTreeHelper.isValidDirPath(path)) { selectTreeNode(el, m_model); @@ -158,7 +150,7 @@ public class MapDataTree extends JTree { } } - public void selectTreeNode(DefaultMutableTreeNode node, DefaultTreeModel m_model){ + public void selectTreeNode(DefaultMutableTreeNode node, DefaultTreeModel m_model) { TreeNode[] nodes = m_model.getPathToRoot(node); TreePath treePath = new TreePath(nodes); setSelectionPath(treePath); diff --git a/designer-form/src/main/java/com/fr/design/designer/treeview/ComponentTreeCellRenderer.java b/designer-form/src/main/java/com/fr/design/designer/treeview/ComponentTreeCellRenderer.java index 78b606a7fc..48938dceee 100644 --- a/designer-form/src/main/java/com/fr/design/designer/treeview/ComponentTreeCellRenderer.java +++ b/designer-form/src/main/java/com/fr/design/designer/treeview/ComponentTreeCellRenderer.java @@ -3,60 +3,53 @@ package com.fr.design.designer.treeview; import com.fr.design.constants.UIConstants; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreatorUtils; -import com.fr.design.gui.ilable.UILabel; import com.fr.log.FineLoggerFactory; +import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JTree; import javax.swing.tree.DefaultTreeCellRenderer; import java.awt.Component; -import java.awt.Dimension; public class ComponentTreeCellRenderer extends DefaultTreeCellRenderer { - public ComponentTreeCellRenderer() { - } - - @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, - boolean leaf, int row, boolean hasFocus) { - super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); - if (value instanceof XCreator) { - String name = ((XCreator) value).toData().getWidgetName(); - setText(name); - Icon icon = null; - try { - icon = XCreatorUtils.getCreatorIcon((XCreator) value); - } catch (Exception e) { - FineLoggerFactory.getLogger().info("{} has not icon or has been deleted", name); - } - if (icon != null) { - setIcon(icon); - } - } - UILabel label = new UILabel(); - label.setText(getText()); - label.setIcon(getIcon()); - Dimension dim = label.getPreferredSize(); - dim.height += 2; - this.setSize(dim); - this.setPreferredSize(dim); - this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); - return this; - } - - @Override - public Icon getClosedIcon() { - return getIcon(); - } - - @Override - public Icon getLeafIcon() { - return getIcon(); - } - - @Override - public Icon getOpenIcon() { - return getIcon(); - } -} \ No newline at end of file + public ComponentTreeCellRenderer() { + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row, boolean hasFocus) { + super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); + if (value instanceof XCreator) { + String name = ((XCreator) value).toData().getWidgetName(); + setText(name); + Icon icon = null; + try { + icon = XCreatorUtils.getCreatorIcon((XCreator) value); + } catch (Exception e) { + FineLoggerFactory.getLogger().info("{} has not icon or has been deleted", name); + } + if (icon != null) { + setIcon(icon); + } + } + this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); + this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); + return this; + } + + @Override + public Icon getClosedIcon() { + return getIcon(); + } + + @Override + public Icon getLeafIcon() { + return getIcon(); + } + + @Override + public Icon getOpenIcon() { + return getIcon(); + } +}