📄 foldernode.java
字号:
/* * FolderNode.java * * Created on 2007年11月23日, 下午4:18 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package TreeList;import javax.swing.filechooser.FileSystemView;import javax.swing.*;import java.io.*;import java.util.*;/** * A data model for a JTree. This model explorer windows file system directly. * @author Liuyuyang */class FolderNode { final public static char DIRECTORY = 'D'; final public static char FILE = 'F'; final public static char ALL = 'A'; private static FileSystemView fsView; private static boolean isHiden = true; private File theFile; private Vector<File> all = new Vector<File>(); private Vector<File> folder = new Vector<File>(); private Vector<File> file = new Vector<File>(); /** * set that whether apply hiden file. * * @param ifshow */ public void setIsHiden(boolean ifshow) { isHiden = ifshow; } public Icon getIcon() { return fsView.getSystemIcon(theFile); } @Override public String toString() { return fsView.getSystemDisplayName(theFile); } /** * create a root node. by default, it should be the DeskTop in window file * system. */ public FolderNode() { fsView = FileSystemView.getFileSystemView(); theFile = new File("D:\\project"); prepareChildren(); } /** * create a root node. by default, it should be the DeskTop in window file * system. @param filePath This param is used to get a file. e.g."D:\\project" */ public FolderNode(String filePath) { fsView = FileSystemView.getFileSystemView(); theFile = new File(filePath); prepareChildren(); } public String getNodePath() { return theFile.getPath(); } private void prepareChildren() { File[] files = fsView.getFiles(theFile, isHiden); for (int i = 0; i < files.length; i++) { //this part is for test // System.out.println("path: "+files[i].getPath().toString()); // System.out.println("name: "+files[i].getName().toString()); //test end all.add(files[i]); if (!files[i].toString().toLowerCase().endsWith(".lnk")) { folder.add(files[i]); } } } private FolderNode(File file) { theFile = file; prepareChildren(); } public FolderNode getChild(char fileType, int index) { if (FolderNode.DIRECTORY == fileType) { return new FolderNode(folder.get(index)); } else if (FolderNode.ALL == fileType) { return new FolderNode(all.get(index)); } else if (FolderNode.FILE == fileType) { return new FolderNode(file.get(index)); } else { return null; } } public int getChildCount(char fileType) { if (FolderNode.DIRECTORY == fileType) { return folder.size(); } else if (FolderNode.ALL == fileType) { return all.size(); } else if (FolderNode.FILE == fileType) { return file.size(); } else { return -1; } } public boolean isLeaf(char fileType) { if (FolderNode.DIRECTORY == fileType) { return folder.size() == 0; } else if (FolderNode.ALL == fileType) { return all.size() == 0; } else if (FolderNode.FILE == fileType) { return true; } else { return true; } } public int getIndexOfChild(char fileType, Object child) { if (child instanceof FolderNode) { if (FolderNode.DIRECTORY == fileType) { return folder.indexOf(((FolderNode) child).theFile); } else if (FolderNode.ALL == fileType) { return all.indexOf(((FolderNode) child).theFile); } else if (FolderNode.FILE == fileType) { return file.indexOf(((FolderNode) child).theFile); } else { return -1; } } else { return -1; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -