From 84dae4884f1fcdefce4351a9b19530e2c237a478 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Fri, 19 Jul 2019 13:49:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0=E4=BB=BB=E5=8A=A1=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=96=B0=E5=BB=BA=E6=9C=AC=E5=9C=B0=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84npe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/itree/filetree/JFileTree.java | 25 +++++++++++-------- .../main/java/com/fr/env/LocalEnvPane.java | 17 ++++++++----- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java index 69875a97fb..3b37f4358b 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java @@ -1,10 +1,11 @@ package com.fr.design.gui.itree.filetree; -import com.fr.base.BaseUtils; import com.fr.design.i18n.Toolkit; import com.fr.general.ComparatorUtils; +import com.fr.general.IOUtils; import com.fr.stable.ArrayUtils; import com.fr.stable.project.ProjectConstants; +import org.jetbrains.annotations.Nullable; import javax.swing.Icon; import javax.swing.JTree; @@ -29,7 +30,8 @@ import java.util.Stack; * File Tree. */ public class JFileTree extends AbstractFileTree { - protected FileFilter fileFilter; + + private FileFilter fileFilter; public JFileTree() { this(null); @@ -68,11 +70,11 @@ public class JFileTree extends AbstractFileTree { DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) defaultTreeModel.getRoot(); rootTreeNode.removeAllChildren(); - for (int k = 0; k < rootFiles.length; k++) { - DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RootFile(rootFiles[k])); + for (File rootFile : rootFiles) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RootFile(rootFile)); rootTreeNode.add(node); - if (rootFiles[k].isDirectory()) { + if (rootFile.isDirectory()) { node.add(new DefaultMutableTreeNode(Boolean.TRUE)); } } @@ -93,6 +95,7 @@ public class JFileTree extends AbstractFileTree { this.fileFilter = fileFilter; } + @Nullable public File getSelectedFile() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { @@ -140,7 +143,7 @@ public class JFileTree extends AbstractFileTree { File rootFile = rootLocalFile.getFile(); // 是父子关系,开始找孩子. if (AbstractFileTree.isParentFile(rootFile, currentFile)) { - Stack nameStack = new Stack(); // 将所有的名字加入Stack. + Stack nameStack = new Stack<>(); // 将所有的名字加入Stack. while (true) { if (ComparatorUtils.equals(rootFile, currentFile)) { break; @@ -153,7 +156,7 @@ public class JFileTree extends AbstractFileTree { } DefaultMutableTreeNode curChildTreeNode = rootChildTreeNode; while (!nameStack.isEmpty()) { - String name = (String) nameStack.pop(); + String name = nameStack.pop(); this.expandTreeNode(curChildTreeNode); for (int j = 0; j < curChildTreeNode.getChildCount(); j++) { DefaultMutableTreeNode tmpChildTreeNode = @@ -198,9 +201,8 @@ public class JFileTree extends AbstractFileTree { if (files == null) { return new FileDirectoryNode[0]; } - List fileNodeList = new ArrayList(); - for (int k = 0; k < files.length; k++) { - File tmpFile = files[k]; + List fileNodeList = new ArrayList<>(); + for (File tmpFile : files) { // 文件属性为隐藏的话 不放入列表 if (tmpFile.isHidden()) { continue; @@ -256,7 +258,7 @@ public class JFileTree extends AbstractFileTree { // 得到本地tree图标 Icon tmpIcon = view.getSystemIcon(currentFile); if (currentFile.isDirectory() && fBuf.length() > 0) { - tmpIcon = BaseUtils.readIcon("/com/fr/design/images/gui/folder.png"); + tmpIcon = IOUtils.readIcon("/com/fr/design/images/gui/folder.png"); } this.setIcon(tmpIcon); this.setName(null); @@ -299,6 +301,7 @@ public class JFileTree extends AbstractFileTree { */ @Override public int compare(FileDirectoryNode v1, FileDirectoryNode v2) { + //noinspection Duplicates if (v1.isDirectory()) { if (v2.isDirectory()) { return v1.getName().toLowerCase().compareTo(v2.getName().toLowerCase()); diff --git a/designer-base/src/main/java/com/fr/env/LocalEnvPane.java b/designer-base/src/main/java/com/fr/env/LocalEnvPane.java index eaabd0a9a4..6f191dd1ec 100644 --- a/designer-base/src/main/java/com/fr/env/LocalEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/LocalEnvPane.java @@ -6,9 +6,9 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itree.filetree.JFileTree; +import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.file.filter.OnlyShowDirectoryFileFilter; - import com.fr.stable.StringUtils; import javax.swing.JPanel; @@ -33,8 +33,9 @@ public class LocalEnvPane extends BasicBeanPane { JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); this.add(northPane, BorderLayout.NORTH); - northPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Location") + ":"), BorderLayout.WEST); - northPane.add(pathTextField = new UITextField(), BorderLayout.CENTER); + northPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Location") + ":"), BorderLayout.WEST); + pathTextField = new UITextField(); + northPane.add(pathTextField, BorderLayout.CENTER); // 删除选择文件按钮 添加JFileTree @@ -54,19 +55,23 @@ public class LocalEnvPane extends BasicBeanPane { @Override public void valueChanged(TreeSelectionEvent e) { - pathTextField.setText(localEnvTree.getSelectedFile().getPath()); + File selectFile = localEnvTree.getSelectedFile(); + if (selectFile == null) { + return; + } + pathTextField.setText(selectFile.getPath()); } }); UITextArea description = new UITextArea(); centerPane.add(description, BorderLayout.SOUTH); - description.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Env_Des1")); + description.setText(Toolkit.i18nText("Fine-Design_Basic_Env_Des1")); description.setEditable(false); } @Override protected String title4PopupWindow() { - return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Location"); + return Toolkit.i18nText("Fine-Design_Basic_Location"); } @Override