1 7 8 package org.gjt.jclasslib.browser.config.classpath; 9 10 import javax.swing.tree.DefaultTreeModel ; 11 import java.io.File ; 12 13 19 public class ClasspathDirectoryEntry extends ClasspathEntry { 20 21 public FindResult findClass(String className) { 22 23 File file = getFile(); 24 if (file == null) { 25 return null; 26 } 27 File classFile = new File (file, className.replace('.', '/') + ".class"); 28 if (classFile.exists() && classFile.canRead()) { 29 FindResult findResult = new FindResult(this, classFile.getPath()); 30 return findResult; 31 } 32 33 return null; 34 } 35 36 public void mergeClassesIntoTree(DefaultTreeModel model, boolean reset) { 37 38 File directory = getFile(); 39 if (directory == null) { 40 return; 41 } 42 43 ClassTreeNode rootNode = (ClassTreeNode)model.getRoot(); 44 mergeDirectory(directory, rootNode, model, reset); 45 46 } 47 48 private void mergeDirectory(File directory, ClassTreeNode parentNode, DefaultTreeModel model, boolean reset) { 49 50 File [] files = directory.listFiles(); 51 if (files == null) { 52 return; 53 } 54 for (int i = 0; i < files.length; i++) { 55 File file = files[i]; 56 if (file.isDirectory()) { 57 ClassTreeNode directoryNode = addOrFindNode(file.getName(), parentNode, true, model, reset); 58 mergeDirectory(file, directoryNode, model, reset); 59 if ((directoryNode.getChildCount() == 0)) { 60 int deletionIndex = parentNode.getIndex(directoryNode); 61 parentNode.remove(directoryNode); 62 if (!reset) { 63 model.nodesWereRemoved(parentNode, new int[] {deletionIndex}, new Object [] {directoryNode}); 64 } 65 } 66 } else if (file.getName().toLowerCase().endsWith(CLASSFILE_SUFFIX)) { 67 addOrFindNode(stripClassSuffix(file.getName()), parentNode, false, model, reset); 68 } 69 } 70 71 } 72 73 } 74 | Popular Tags |