Browse Source

Pull request #2409: REPORT-38376 & REPORT-39308 设计器目录树等树控件JDK11下显示不全

Merge in DESIGN/design from ~VITO/c-design:release/10.0 to release/10.0

* commit '9af539cbbd2bd7b73258fe12489325991b09079a':
  REPORT-39308 参数输入面板参数名显示不完整
  REPORT-38376 设计器目录树等树控件JDK11下显示不全
feature/big-screen
vito 4 years ago
parent
commit
8b5af0141b
  1. 21
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java
  2. 12
      designer-base/src/main/java/com/fr/design/gui/itree/filetree/EnvFileTree.java
  3. 232
      designer-base/src/main/java/com/fr/design/parameter/ParameterInputPane.java
  4. 48
      designer-chart/src/main/java/com/fr/van/chart/drillmap/designer/data/comp/MapDataTree.java
  5. 87
      designer-form/src/main/java/com/fr/design/designer/treeview/ComponentTreeCellRenderer.java

21
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTree.java

@ -1,21 +1,22 @@
package com.fr.design.data.datapane; package com.fr.design.data.datapane;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.general.NameObject;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; 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.ExpandMutableTreeNode;
import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree; import com.fr.design.gui.itree.refreshabletree.UserObjectRefreshJTree;
import com.fr.design.icon.IconPathConstants; import com.fr.design.icon.IconPathConstants;
import com.fr.general.ComparatorUtils; 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.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.*; import java.awt.Color;
import java.awt.Component;
/** /**
* TableData Tree * TableData Tree
@ -31,6 +32,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> {
this.setCellRenderer(tableDataTreeCellRenderer); this.setCellRenderer(tableDataTreeCellRenderer);
this.setEditable(false); this.setEditable(false);
} }
// CellRenderer // CellRenderer
private DefaultTreeCellRenderer tableDataTreeCellRenderer = new DefaultTreeCellRenderer() { private DefaultTreeCellRenderer tableDataTreeCellRenderer = new DefaultTreeCellRenderer() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -66,14 +68,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> {
this.setIcon(null); this.setIcon(null);
this.setText(PENDING.toString()); this.setText(PENDING.toString());
} }
// 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..." this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
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); this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND);
this.setTextSelectionColor(Color.WHITE); this.setTextSelectionColor(Color.WHITE);
this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE);
@ -152,7 +147,7 @@ public class TableDataTree extends UserObjectRefreshJTree<TableDataSourceOP> {
/* /*
* p:获得选中的NameObject = name + tabledata. * p:获得选中的NameObject = name + tabledata.
*/ */
public NameObject getSelectedNameObject() { public NameObject getSelectedNameObject() {
TreePath selectedTreePath = this.getSelectionPath(); TreePath selectedTreePath = this.getSelectionPath();
if (selectedTreePath == null) { if (selectedTreePath == null) {

12
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.base.FRContext;
import com.fr.design.constants.UIConstants; 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.ExpandMutableTreeNode;
import com.fr.design.gui.itree.refreshabletree.RefreshableJTree; import com.fr.design.gui.itree.refreshabletree.RefreshableJTree;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
@ -14,13 +13,13 @@ import com.fr.stable.CoreConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.BorderFactory;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -79,14 +78,7 @@ public class EnvFileTree extends RefreshableJTree {
this.setIcon(null); this.setIcon(null);
this.setText(PENDING.toString()); this.setText(PENDING.toString());
} }
// 这里新建一个Label作为render是因为JTree在动态刷新的时候,节点上render画布的的宽度不会变,会使得一部分比较长的数据显示为"..." this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
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.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND);
this.setTextSelectionColor(Color.WHITE); this.setTextSelectionColor(Color.WHITE);
this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE);

232
designer-base/src/main/java/com/fr/design/parameter/ParameterInputPane.java

@ -20,14 +20,18 @@ import com.fr.design.editor.editor.TextEditor;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.stable.ParameterProvider; import com.fr.stable.ParameterProvider;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
@ -37,31 +41,34 @@ import java.util.Map.Entry;
/** /**
* The dialog used to input parameter. * The dialog used to input parameter.
*
* @editor zhou * @editor zhou
* @since 2012-3-26上午11:09:45 * @since 2012-3-26上午11:09:45
*/ */
public class ParameterInputPane extends BasicPane { public class ParameterInputPane extends BasicPane {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// alex:保存编辑器对应的参数的名字
private java.util.Map<ValueEditorPane, String> editorNameMap; // Map<Editor, Name>
// alex:保存编辑器对应的参数的名字 private boolean allowBlank = true;
private java.util.Map<ValueEditorPane,String> editorNameMap; // Map<Editor, Name>
private boolean allowBlank = true; private FlowTableLayoutHelper flowTableLayoutHelper;
/** /**
* Constructor. * Constructor.
*/ */
public ParameterInputPane(ParameterProvider[] parameters) { public ParameterInputPane(ParameterProvider[] parameters) {
this.initComponents(parameters); this.initComponents(parameters);
} }
public ParameterInputPane(ParameterProvider[] parameters, boolean allowBlank) { public ParameterInputPane(ParameterProvider[] parameters, boolean allowBlank) {
this.allowBlank = allowBlank; this.allowBlank = allowBlank;
this.initComponents(parameters); this.initComponents(parameters);
} }
private void initComponents(ParameterProvider[] parameters) { private void initComponents(ParameterProvider[] parameters) {
this.setLayout(new BorderLayout(0, 4)); this.setLayout(new BorderLayout(0, 4));
@ -71,9 +78,9 @@ public class ParameterInputPane extends BasicPane {
this.add(new JScrollPane(contentPane), BorderLayout.CENTER); this.add(new JScrollPane(contentPane), BorderLayout.CENTER);
contentPane.setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameters") + ":")); contentPane.setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameters") + ":"));
FlowTableLayoutHelper flowTableLayoutHelper = new FlowTableLayoutHelper(); flowTableLayoutHelper = new FlowTableLayoutHelper();
editorNameMap = new java.util.HashMap<ValueEditorPane,String>(); editorNameMap = new java.util.HashMap<ValueEditorPane, String>();
//Parameter list. //Parameter list.
java.util.List<String> nameAddedList = new java.util.ArrayList<String>(); // alex:已经加到界面中去的参数名 java.util.List<String> nameAddedList = new java.util.ArrayList<String>(); // alex:已经加到界面中去的参数名
@ -83,12 +90,12 @@ public class ParameterInputPane extends BasicPane {
// alex:已经在界面中的参数,不加了 // alex:已经在界面中的参数,不加了
if (nameAddedList.contains(parameter.getName())) { if (nameAddedList.contains(parameter.getName())) {
continue; continue;
} }
if(parameter instanceof StoreProcedureParameter if (parameter instanceof StoreProcedureParameter
&& ((StoreProcedureParameter) parameter).getSchema() == StoreProcedureConstants.OUT) { && ((StoreProcedureParameter) parameter).getSchema() == StoreProcedureConstants.OUT) {
continue; continue;
} }
final Object pv = parameter.getValue(); final Object pv = parameter.getValue();
Editor[] editors = makeEditorByValue(pv); Editor[] editors = makeEditorByValue(pv);
@ -100,135 +107,140 @@ public class ParameterInputPane extends BasicPane {
editPane.setPreferredSize(new Dimension(180, editPane.getPreferredSize().height)); editPane.setPreferredSize(new Dimension(180, editPane.getPreferredSize().height));
String parameterDisplayName = parameter.getName(); String parameterDisplayName = parameter.getName();
if(StringUtils.isNotBlank(parameter.getName())) { if (StringUtils.isNotBlank(parameter.getName())) {
parameterDisplayName = parameter.getName(); parameterDisplayName = parameter.getName();
} }
contentPane.add(flowTableLayoutHelper.createLabelFlowPane(parameterDisplayName + ":", editPane)); contentPane.add(flowTableLayoutHelper.createLabelFlowPane(parameterDisplayName + ":", editPane));
//add editor to parameter hashtable. //add editor to parameter hashtable.
initTextListener(textF); initTextListener(textF);
this.editorNameMap.put(textF, parameter.getName()); this.editorNameMap.put(textF, parameter.getName());
nameAddedList.add(parameter.getName()); nameAddedList.add(parameter.getName());
} }
} }
}
@Override
public void addNotify() {
super.addNotify();
// windows 高DPI下,使用getPreferredSize必须在添加到容器之后,否则得到的数值不准确,因此先放到这调整大小
flowTableLayoutHelper.adjustLabelWidth(); flowTableLayoutHelper.adjustLabelWidth();
} }
protected void initTextListener(ValueEditorPane textF) { protected void initTextListener(ValueEditorPane textF) {
textF.getCurrentEditor().addChangeListener(new ChangeListener() { textF.getCurrentEditor().addChangeListener(new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified(); HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified();
} }
}); });
} }
private Editor[] makeEditorByValue(Object pv) { private Editor[] makeEditorByValue(Object pv) {
Editor[] editors = {null}; Editor[] editors = {null};
if (pv instanceof Integer) { if (pv instanceof Integer) {
editors[0] = new IntegerEditor(); editors[0] = new IntegerEditor();
} else if (pv instanceof Double || pv instanceof Float) { } else if (pv instanceof Double || pv instanceof Float) {
editors[0] = new DoubleEditor(); editors[0] = new DoubleEditor();
} else if (pv instanceof Float) { } else if (pv instanceof Float) {
editors[0] = new FloatEditor(); editors[0] = new FloatEditor();
} else if (pv instanceof Date) { } else if (pv instanceof Date) {
editors[0] = new DateEditor(true, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Date")); editors[0] = new DateEditor(true, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Date"));
} else if (pv instanceof Boolean) { } else if (pv instanceof Boolean) {
editors[0] = new BooleanEditor(); editors[0] = new BooleanEditor();
} else if (pv instanceof BaseFormula) { } else if (pv instanceof BaseFormula) {
editors = ValueEditorPaneFactory.basicEditors(); editors = ValueEditorPaneFactory.basicEditors();
} else { } else {
editors[0] = new TextEditor(); editors[0] = new TextEditor();
} }
return editors; return editors;
} }
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameters"); return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Parameters");
} }
/** /**
* Update * Update
*/ */
public Map<String,Object> update() { public Map<String, Object> update() {
java.util.Map<String,Object> nameValueMap = new java.util.HashMap<String,Object>(); java.util.Map<String, Object> nameValueMap = new java.util.HashMap<String, Object>();
Iterator<Entry<ValueEditorPane, String>> entryIt = this.editorNameMap.entrySet().iterator(); Iterator<Entry<ValueEditorPane, String>> entryIt = this.editorNameMap.entrySet().iterator();
while(entryIt.hasNext()) { while (entryIt.hasNext()) {
java.util.Map.Entry<ValueEditorPane, String> entry = entryIt.next(); java.util.Map.Entry<ValueEditorPane, String> entry = entryIt.next();
ValueEditorPane editor = entry.getKey(); ValueEditorPane editor = entry.getKey();
String parameterName = entry.getValue(); String parameterName = entry.getValue();
Object editorStringValue = editor.update(); Object editorStringValue = editor.update();
nameValueMap.put(parameterName, editorStringValue); nameValueMap.put(parameterName, editorStringValue);
} }
return nameValueMap; return nameValueMap;
} }
public void checkValid() throws Exception { public void checkValid() throws Exception {
if (!allowBlank) { if (!allowBlank) {
boolean valid = true; boolean valid = true;
String error = ""; String error = "";
Iterator<Entry<ValueEditorPane, String>> entryIt = this.editorNameMap.entrySet().iterator(); Iterator<Entry<ValueEditorPane, String>> entryIt = this.editorNameMap.entrySet().iterator();
while (entryIt.hasNext()) { while (entryIt.hasNext()) {
java.util.Map.Entry<ValueEditorPane, String> entry = entryIt.next(); java.util.Map.Entry<ValueEditorPane, String> entry = entryIt.next();
ValueEditorPane editor = entry.getKey(); ValueEditorPane editor = entry.getKey();
String parameterName = entry.getValue(); String parameterName = entry.getValue();
Object editorStringValue = editor.update(); Object editorStringValue = editor.update();
if (editorStringValue == null || StringUtils.isEmpty(Utils.objectToString(editorStringValue))) { if (editorStringValue == null || StringUtils.isEmpty(Utils.objectToString(editorStringValue))) {
valid = false; valid = false;
error += parameterName + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Not_Null_Des") + "\n"; error += parameterName + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Not_Null_Des") + "\n";
} }
} }
if (!valid) { if (!valid) {
throw new Exception(error); throw new Exception(error);
} }
} }
} }
/** /**
* The class help to flowlayout components * The class help to flowlayout components
*/ */
private static class FlowTableLayoutHelper { private static class FlowTableLayoutHelper {
private List<UILabel> labelList = new ArrayList<UILabel>(); private List<UILabel> labelList = new ArrayList<UILabel>();
public FlowTableLayoutHelper() { public FlowTableLayoutHelper() {
} }
public JPanel createLabelFlowPane(String text, JComponent comp) { public JPanel createLabelFlowPane(String text, JComponent comp) {
JPanel centerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); JPanel centerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
UILabel textLabel = new UILabel(text); UILabel textLabel = new UILabel(text);
centerPane.add(textLabel); centerPane.add(textLabel);
textLabel.setHorizontalAlignment(SwingConstants.LEFT); textLabel.setHorizontalAlignment(SwingConstants.LEFT);
this.labelList.add(textLabel); this.labelList.add(textLabel);
centerPane.add(comp); centerPane.add(comp);
return centerPane; return centerPane;
} }
public void adjustLabelWidth() { public void adjustLabelWidth() {
int maxWidth = 0; int maxWidth = 0;
for (int i = 0; i < labelList.size(); i++) { for (int i = 0; i < labelList.size(); i++) {
maxWidth = Math.max(maxWidth, labelList.get(i).getPreferredSize().width); maxWidth = Math.max(maxWidth, labelList.get(i).getPreferredSize().width);
} }
for (int i = 0; i < labelList.size(); i++) { for (int i = 0; i < labelList.size(); i++) {
UILabel label = labelList.get(i); UILabel label = labelList.get(i);
Dimension labelDim = new Dimension(maxWidth, label.getPreferredSize().height); Dimension labelDim = new Dimension(maxWidth, label.getPreferredSize().height);
label.setPreferredSize(labelDim); label.setPreferredSize(labelDim);
label.setSize(labelDim); label.setSize(labelDim);
label.setMinimumSize(labelDim); label.setMinimumSize(labelDim);
} }
} }
} }
} }

48
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; package com.fr.van.chart.drillmap.designer.data.comp;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.plugin.chart.map.designer.type.GEOJSONTreeHelper; import com.fr.plugin.chart.map.designer.type.GEOJSONTreeHelper;
import com.fr.plugin.chart.map.server.ChartGEOJSONHelper; import com.fr.plugin.chart.map.server.ChartGEOJSONHelper;
import com.fr.plugin.chart.map.server.CompatibleGEOJSONHelper; import com.fr.plugin.chart.map.server.CompatibleGEOJSONHelper;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
@ -15,7 +15,6 @@ import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode; import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension;
import java.util.Enumeration; import java.util.Enumeration;
/** /**
@ -23,7 +22,7 @@ import java.util.Enumeration;
*/ */
public class MapDataTree extends JTree { public class MapDataTree extends JTree {
public MapDataTree(TreeNode root){ public MapDataTree(TreeNode root) {
super(); super();
this.setModel(model); this.setModel(model);
model.setRoot(root); model.setRoot(root);
@ -49,54 +48,54 @@ public class MapDataTree extends JTree {
if (children.hasMoreElements()) { if (children.hasMoreElements()) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
if(GEOJSONTreeHelper.getInstance().isSelectableTreeNode(child)){ if (GEOJSONTreeHelper.isSelectableTreeNode(child)) {
selectTreeNode(child, m_model); selectTreeNode(child, m_model);
}else{ } else {
setFirstChildTreeNode(child, m_model); setFirstChildTreeNode(child, m_model);
} }
} }
} }
private void setFirstChildTreeNode(DefaultMutableTreeNode parent, DefaultTreeModel m_model){ private void setFirstChildTreeNode(DefaultMutableTreeNode parent, DefaultTreeModel m_model) {
Enumeration<TreeNode> children = parent.children(); Enumeration<TreeNode> children = parent.children();
if (children.hasMoreElements()){ if (children.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
selectTreeNode(node, m_model); selectTreeNode(node, m_model);
} }
} }
public void changeRootNode(TreeNode node){ public void changeRootNode(TreeNode node) {
DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); DefaultTreeModel m_model = (DefaultTreeModel) this.getModel();
m_model.setRoot(node); m_model.setRoot(node);
} }
public String getSelectNodeJSONPath() { public String getSelectNodeJSONPath() {
if(this.getLastSelectedPathComponent() == null){ if (this.getLastSelectedPathComponent() == null) {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
DefaultMutableTreeNode currentSel = (DefaultMutableTreeNode)this.getLastSelectedPathComponent(); DefaultMutableTreeNode currentSel = (DefaultMutableTreeNode) this.getLastSelectedPathComponent();
return CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(currentSel.getUserObject().toString()); return CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(currentSel.getUserObject().toString());
} }
//根据路径精确查找 //根据路径精确查找
public DefaultMutableTreeNode setSelectNodePath(String jsonUrl) { public DefaultMutableTreeNode setSelectNodePath(String jsonUrl) {
if(StringUtils.isEmpty(jsonUrl) || CompatibleGEOJSONHelper.isDeprecated(jsonUrl)){ if (StringUtils.isEmpty(jsonUrl) || CompatibleGEOJSONHelper.isDeprecated(jsonUrl)) {
return null; return null;
} }
DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); DefaultTreeModel m_model = (DefaultTreeModel) this.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) m_model.getRoot(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) m_model.getRoot();
Enumeration<TreeNode> els = root.postorderEnumeration(); Enumeration<TreeNode> els = root.postorderEnumeration();
while(els.hasMoreElements()){ while (els.hasMoreElements()) {
DefaultMutableTreeNode el = (DefaultMutableTreeNode) els.nextElement(); DefaultMutableTreeNode el = (DefaultMutableTreeNode) els.nextElement();
if(el == null || el.getUserObject() == null){ if (el == null || el.getUserObject() == null) {
return null; return null;
} }
String dirPath = el.getUserObject().toString(); String dirPath = el.getUserObject().toString();
String url = CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(dirPath); String url = CompatibleGEOJSONHelper.getJsonUrlByPathIncludeParam(dirPath);
//先equals再valid原因:valid 远程下实时去服务器看有没有json文件 //先equals再valid原因:valid 远程下实时去服务器看有没有json文件
if (ComparatorUtils.equals(jsonUrl, url) && GEOJSONTreeHelper.isValidDirPath(dirPath)) { if (ComparatorUtils.equals(jsonUrl, url) && GEOJSONTreeHelper.isValidDirPath(dirPath)) {
selectTreeNode(el, m_model); selectTreeNode(el, m_model);
@ -115,14 +114,7 @@ public class MapDataTree extends JTree {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value; DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
String name = getPresentName(treeNode); String name = getPresentName(treeNode);
this.setText(name); this.setText(name);
this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
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.setBackgroundNonSelectionColor(UIConstants.NORMAL_BACKGROUND); this.setBackgroundNonSelectionColor(UIConstants.NORMAL_BACKGROUND);
this.setForeground(UIConstants.FONT_COLOR); this.setForeground(UIConstants.FONT_COLOR);
this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE); this.setBackgroundSelectionColor(UIConstants.FLESH_BLUE);
@ -131,25 +123,25 @@ public class MapDataTree extends JTree {
}; };
protected String getPresentName(DefaultMutableTreeNode treeNode) { protected String getPresentName(DefaultMutableTreeNode treeNode) {
if(treeNode == null || treeNode.getUserObject() == null){ if (treeNode == null || treeNode.getUserObject() == null) {
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
return ChartGEOJSONHelper.getPresentNameWithPath(treeNode.getUserObject().toString()); return ChartGEOJSONHelper.getPresentNameWithPath(treeNode.getUserObject().toString());
} }
//模糊搜索 深度优先. //模糊搜索 深度优先.
public void search(String text){ public void search(String text) {
if(StringUtils.isEmpty(text)){ if (StringUtils.isEmpty(text)) {
return; return;
} }
DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); DefaultTreeModel m_model = (DefaultTreeModel) this.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) m_model.getRoot(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) m_model.getRoot();
Enumeration<TreeNode> els = root.postorderEnumeration(); Enumeration<TreeNode> els = root.postorderEnumeration();
while(els.hasMoreElements()){ while (els.hasMoreElements()) {
DefaultMutableTreeNode el = (DefaultMutableTreeNode) els.nextElement(); DefaultMutableTreeNode el = (DefaultMutableTreeNode) els.nextElement();
String path = el.getUserObject().toString(); String path = el.getUserObject().toString();
String fileName = ChartGEOJSONHelper.getPresentNameWithPath(path); String fileName = ChartGEOJSONHelper.getPresentNameWithPath(path);
if (StringUtils.contains(fileName, text) && GEOJSONTreeHelper.isValidDirPath(path)) { if (StringUtils.contains(fileName, text) && GEOJSONTreeHelper.isValidDirPath(path)) {
selectTreeNode(el, m_model); 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); TreeNode[] nodes = m_model.getPathToRoot(node);
TreePath treePath = new TreePath(nodes); TreePath treePath = new TreePath(nodes);
setSelectionPath(treePath); setSelectionPath(treePath);

87
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.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.gui.ilable.UILabel;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JTree; import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension;
public class ComponentTreeCellRenderer extends DefaultTreeCellRenderer { public class ComponentTreeCellRenderer extends DefaultTreeCellRenderer {
public ComponentTreeCellRenderer() { public ComponentTreeCellRenderer() {
} }
@Override @Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) { boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (value instanceof XCreator) { if (value instanceof XCreator) {
String name = ((XCreator) value).toData().getWidgetName(); String name = ((XCreator) value).toData().getWidgetName();
setText(name); setText(name);
Icon icon = null; Icon icon = null;
try { try {
icon = XCreatorUtils.getCreatorIcon((XCreator) value); icon = XCreatorUtils.getCreatorIcon((XCreator) value);
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().info("{} has not icon or has been deleted", name); FineLoggerFactory.getLogger().info("{} has not icon or has been deleted", name);
} }
if (icon != null) { if (icon != null) {
setIcon(icon); setIcon(icon);
} }
} }
UILabel label = new UILabel(); this.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
label.setText(getText()); this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND);
label.setIcon(getIcon()); return this;
Dimension dim = label.getPreferredSize(); }
dim.height += 2;
this.setSize(dim); @Override
this.setPreferredSize(dim); public Icon getClosedIcon() {
this.setBackgroundNonSelectionColor(UIConstants.TREE_BACKGROUND); return getIcon();
return this; }
}
@Override
@Override public Icon getLeafIcon() {
public Icon getClosedIcon() { return getIcon();
return getIcon(); }
}
@Override
@Override public Icon getOpenIcon() {
public Icon getLeafIcon() { return getIcon();
return getIcon(); }
}
@Override
public Icon getOpenIcon() {
return getIcon();
}
} }
Loading…
Cancel
Save