|
|
@ -1,5 +1,18 @@ |
|
|
|
package com.fr.design.gui.itree.filetree; |
|
|
|
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.stable.ArrayUtils; |
|
|
|
|
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.Icon; |
|
|
|
|
|
|
|
import javax.swing.JTree; |
|
|
|
|
|
|
|
import javax.swing.filechooser.FileSystemView; |
|
|
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode; |
|
|
|
|
|
|
|
import javax.swing.tree.DefaultTreeCellRenderer; |
|
|
|
|
|
|
|
import javax.swing.tree.DefaultTreeModel; |
|
|
|
|
|
|
|
import javax.swing.tree.TreePath; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Component; |
|
|
|
import java.awt.Font; |
|
|
|
import java.awt.Font; |
|
|
@ -11,20 +24,6 @@ import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Stack; |
|
|
|
import java.util.Stack; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.Icon; |
|
|
|
|
|
|
|
import javax.swing.JTree; |
|
|
|
|
|
|
|
import javax.swing.filechooser.FileSystemView; |
|
|
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode; |
|
|
|
|
|
|
|
import javax.swing.tree.DefaultTreeCellRenderer; |
|
|
|
|
|
|
|
import javax.swing.tree.DefaultTreeModel; |
|
|
|
|
|
|
|
import javax.swing.tree.TreePath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* File Tree. |
|
|
|
* File Tree. |
|
|
@ -43,8 +42,8 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
private void init(FileFilter filter) { |
|
|
|
private void init(FileFilter filter) { |
|
|
|
this.fileFilter = filter; |
|
|
|
this.fileFilter = filter; |
|
|
|
|
|
|
|
|
|
|
|
DefaultTreeModel m_model = new DefaultTreeModel(new DefaultMutableTreeNode(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_My_Computer"))); |
|
|
|
DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(Toolkit.i18nText("Fine-Design_Basic_My_Computer"))); |
|
|
|
this.setModel(m_model); |
|
|
|
this.setModel(treeModel); |
|
|
|
|
|
|
|
|
|
|
|
this.putClientProperty("JTree.lineStyle", "Angled"); |
|
|
|
this.putClientProperty("JTree.lineStyle", "Angled"); |
|
|
|
|
|
|
|
|
|
|
@ -65,8 +64,8 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DefaultTreeModel m_model = (DefaultTreeModel) this.getModel(); |
|
|
|
DefaultTreeModel defaultTreeModel = (DefaultTreeModel) this.getModel(); |
|
|
|
DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) m_model.getRoot(); |
|
|
|
DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) defaultTreeModel.getRoot(); |
|
|
|
rootTreeNode.removeAllChildren(); |
|
|
|
rootTreeNode.removeAllChildren(); |
|
|
|
|
|
|
|
|
|
|
|
for (int k = 0; k < rootFiles.length; k++) { |
|
|
|
for (int k = 0; k < rootFiles.length; k++) { |
|
|
@ -78,7 +77,7 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// richer:不是LocalEnv根本就不会运行到这儿
|
|
|
|
// richer:不是LocalEnv根本就不会运行到这儿
|
|
|
|
m_model.reload(rootTreeNode); |
|
|
|
defaultTreeModel.reload(rootTreeNode); |
|
|
|
|
|
|
|
|
|
|
|
if (rootFiles.length == 1) { |
|
|
|
if (rootFiles.length == 1) { |
|
|
|
File expandFile = rootFiles[0]; |
|
|
|
File expandFile = rootFiles[0]; |
|
|
@ -101,12 +100,9 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DefaultMutableTreeNode currentTreeNode = this.getMutableTreeNode(selectedTreePath); |
|
|
|
DefaultMutableTreeNode currentTreeNode = this.getMutableTreeNode(selectedTreePath); |
|
|
|
StringBuffer fBuf = new StringBuffer(); |
|
|
|
StringBuilder fBuf = new StringBuilder(); |
|
|
|
while (true) { |
|
|
|
while (currentTreeNode != null) { |
|
|
|
// 如果已经到了根节点,直接退出.
|
|
|
|
// 如果已经到了根节点,直接退出.
|
|
|
|
if (currentTreeNode == null) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object object = currentTreeNode.getUserObject(); |
|
|
|
Object object = currentTreeNode.getUserObject(); |
|
|
|
if (object instanceof RootFile) { |
|
|
|
if (object instanceof RootFile) { |
|
|
@ -128,6 +124,7 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通过文件夹寻找展开路径 |
|
|
|
* 通过文件夹寻找展开路径 |
|
|
|
|
|
|
|
* |
|
|
|
* @param currentFile 当前文件 |
|
|
|
* @param currentFile 当前文件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void selectFile(File currentFile) { |
|
|
|
public void selectFile(File currentFile) { |
|
|
@ -181,16 +178,15 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 列出当前所有的File |
|
|
|
* 列出当前所有的File |
|
|
|
|
|
|
|
* |
|
|
|
* @param currentTreeNode 当前文件节点 |
|
|
|
* @param currentTreeNode 当前文件节点 |
|
|
|
* @return 当前节点下的所有File |
|
|
|
* @return 当前节点下的所有File |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public FileDirectoryNode[] listFileNodes(DefaultMutableTreeNode currentTreeNode) { |
|
|
|
public FileDirectoryNode[] listFileNodes(DefaultMutableTreeNode currentTreeNode) { |
|
|
|
StringBuffer fBuf = new StringBuffer(); |
|
|
|
StringBuilder fBuf = new StringBuilder(); |
|
|
|
while (true) { |
|
|
|
while (currentTreeNode != null) { |
|
|
|
// 如果已经到了根节点,直接退出.
|
|
|
|
// 如果已经到了根节点,直接退出.
|
|
|
|
if (currentTreeNode == null) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object object = currentTreeNode.getUserObject(); |
|
|
|
Object object = currentTreeNode.getUserObject(); |
|
|
|
if (object instanceof RootFile) { |
|
|
|
if (object instanceof RootFile) { |
|
|
|
RootFile rootFileNode = (RootFile) object; |
|
|
|
RootFile rootFileNode = (RootFile) object; |
|
|
@ -220,7 +216,7 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
FileDirectoryNode[] fileNodes = new FileDirectoryNode[fileNodeList.size()]; |
|
|
|
FileDirectoryNode[] fileNodes = new FileDirectoryNode[fileNodeList.size()]; |
|
|
|
fileNodeList.toArray(fileNodes); |
|
|
|
fileNodeList.toArray(fileNodes); |
|
|
|
// 对文件夹进行排序
|
|
|
|
// 对文件夹进行排序
|
|
|
|
Arrays.sort(fileNodes, new FileNodeComparator()); |
|
|
|
Arrays.sort(fileNodes, new FileDirectoryNodeComparator()); |
|
|
|
return fileNodes; |
|
|
|
return fileNodes; |
|
|
|
} |
|
|
|
} |
|
|
|
// 名字进行逐层反序的回加. 例: Doload ==> C:\java\Doload ,返回到文件夹的path,因为有可能是String. 所以加上instanceof
|
|
|
|
// 名字进行逐层反序的回加. 例: Doload ==> C:\java\Doload ,返回到文件夹的path,因为有可能是String. 所以加上instanceof
|
|
|
@ -240,6 +236,7 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private DefaultTreeCellRenderer fileTreeCellRenderer = new DefaultTreeCellRenderer() { |
|
|
|
private DefaultTreeCellRenderer fileTreeCellRenderer = new DefaultTreeCellRenderer() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Component getTreeCellRendererComponent(JTree tree, Object value, |
|
|
|
public Component getTreeCellRendererComponent(JTree tree, Object value, |
|
|
|
boolean selected, boolean expanded, boolean leaf, int row, |
|
|
|
boolean selected, boolean expanded, boolean leaf, int row, |
|
|
|
boolean hasFocus) { |
|
|
|
boolean hasFocus) { |
|
|
@ -247,11 +244,8 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
leaf, row, hasFocus); |
|
|
|
leaf, row, hasFocus); |
|
|
|
|
|
|
|
|
|
|
|
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value; |
|
|
|
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value; |
|
|
|
StringBuffer fBuf = new StringBuffer(); |
|
|
|
StringBuilder fBuf = new StringBuilder(); |
|
|
|
while(true) { |
|
|
|
while (treeNode != null) { |
|
|
|
if (treeNode == null) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object userObj = treeNode.getUserObject(); |
|
|
|
Object userObj = treeNode.getUserObject(); |
|
|
|
if (userObj instanceof RootFile) { |
|
|
|
if (userObj instanceof RootFile) { |
|
|
|
RootFile rootFileNode = (RootFile) userObj; |
|
|
|
RootFile rootFileNode = (RootFile) userObj; |
|
|
@ -269,9 +263,9 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
Font oldFont = this.getFont(); |
|
|
|
Font oldFont = this.getFont(); |
|
|
|
if (ComparatorUtils.equals(currentFile.getName(), ProjectConstants.WEBINF_NAME)) { |
|
|
|
if (ComparatorUtils.equals(currentFile.getName(), ProjectConstants.WEBINF_NAME)) { |
|
|
|
this.setForeground(Color.blue); |
|
|
|
this.setForeground(Color.blue); |
|
|
|
this.setFont(new Font(oldFont.getName(),1,oldFont.getSize())); |
|
|
|
this.setFont(new Font(oldFont.getName(), Font.BOLD, oldFont.getSize())); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.setFont(new Font(oldFont.getName(),0,oldFont.getSize())); |
|
|
|
this.setFont(new Font(oldFont.getName(), Font.PLAIN, oldFont.getSize())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 名字进行逐层反序的回加. 例: Doload ==> C:\java\Doload
|
|
|
|
// 名字进行逐层反序的回加. 例: Doload ==> C:\java\Doload
|
|
|
@ -289,9 +283,10 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 对文件夹进行排序 先文件夹 然后各种类型文件 |
|
|
|
* 对文件夹进行排序 先文件夹 然后各种类型文件 |
|
|
|
|
|
|
|
* |
|
|
|
* @author kunsnat |
|
|
|
* @author kunsnat |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FileNodeComparator implements Comparator { |
|
|
|
public class FileDirectoryNodeComparator implements Comparator<FileDirectoryNode> { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* This method should return > 0 if v1 is greater than v2, 0 if |
|
|
|
* This method should return > 0 if v1 is greater than v2, 0 if |
|
|
|
* v1 is equal to v2, or < 0 if v1 is less than v2. |
|
|
|
* v1 is equal to v2, or < 0 if v1 is less than v2. |
|
|
@ -302,21 +297,19 @@ public class JFileTree extends AbstractFileTree { |
|
|
|
* @param v2 comparison value.值2 |
|
|
|
* @param v2 comparison value.值2 |
|
|
|
* @return < 0, 0, or > 0 for v1<v2, v1==v2, or v1>v2 .值1大于值2返回大于0,相等返回0,小于和大于相反 |
|
|
|
* @return < 0, 0, or > 0 for v1<v2, v1==v2, or v1>v2 .值1大于值2返回大于0,相等返回0,小于和大于相反 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int compare(Object v1, Object v2) { |
|
|
|
@Override |
|
|
|
FileDirectoryNode nameNode1 = (FileDirectoryNode) v1; |
|
|
|
public int compare(FileDirectoryNode v1, FileDirectoryNode v2) { |
|
|
|
FileDirectoryNode nameNode2 = (FileDirectoryNode) v2; |
|
|
|
if (v1.isDirectory()) { |
|
|
|
|
|
|
|
if (v2.isDirectory()) { |
|
|
|
if (nameNode1.isDirectory()) { |
|
|
|
return v1.getName().toLowerCase().compareTo(v2.getName().toLowerCase()); |
|
|
|
if (nameNode2.isDirectory()) { |
|
|
|
|
|
|
|
return nameNode1.getName().toLowerCase().compareTo(nameNode2.getName().toLowerCase()); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (nameNode2.isDirectory()) { |
|
|
|
if (v2.isDirectory()) { |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return nameNode1.getName().toLowerCase().compareTo(nameNode2.getName().toLowerCase()); |
|
|
|
return v1.getName().toLowerCase().compareTo(v2.getName().toLowerCase()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|