1 7 8 package org.gjt.jclasslib.browser.config.classpath; 9 10 import javax.swing.tree.DefaultTreeModel ; 11 import java.io.File ; 12 import java.io.IOException ; 13 14 20 public abstract class ClasspathEntry implements ClasspathComponent { 21 22 23 protected static final String CLASSFILE_SUFFIX = ".class"; 24 25 private String fileName; 26 private File file; 27 28 32 public String getFileName() { 33 return fileName; 34 } 35 36 40 public void setFileName(String fileName) { 41 42 this.fileName = fileName; 43 file = new File (fileName); 44 try { 45 file = file.getCanonicalFile(); 46 } catch (IOException e) { 47 file = null; 48 } 49 } 50 51 public boolean equals(Object other) { 52 53 if (this == other) { 54 return true; 55 } 56 if (other.getClass() != getClass()) { 57 return false; 58 } 59 60 return fileName.equals(((ClasspathEntry)other).fileName); 61 } 62 63 public int hashCode() { 64 return fileName.hashCode(); 65 } 66 67 public void addClasspathChangeListener(ClasspathChangeListener listener) { 69 } 70 71 public void removeClasspathChangeListener(ClasspathChangeListener listener) { 72 } 73 74 78 protected File getFile() { 79 return file; 80 } 81 82 92 protected ClassTreeNode addOrFindNode(String newNodeName, 93 ClassTreeNode parentNode, 94 boolean packageNode, 95 DefaultTreeModel model, 96 boolean reset) 97 { 98 int childCount = parentNode.getChildCount(); 99 100 ClassTreeNode newNode = new ClassTreeNode(newNodeName, packageNode); 101 for (int i = 0; i < childCount; i++) { 102 ClassTreeNode childNode = (ClassTreeNode)parentNode.getChildAt(i); 103 String childNodeName = childNode.toString(); 104 if (childNode.getChildCount() > 0 && !packageNode) { 105 continue; 106 } else if (childNode.getChildCount() == 0 && packageNode) { 107 insertNode(newNode, parentNode, i, model, reset); 108 return newNode; 109 } else if (newNodeName.equals(childNodeName)) { 110 return childNode; 111 } else if (newNodeName.compareTo(childNodeName) < 0) { 112 insertNode(newNode, parentNode, i, model, reset); 113 return newNode; 114 } 115 } 116 insertNode(newNode, parentNode, childCount, model, reset); 117 118 return newNode; 119 } 120 121 126 protected String stripClassSuffix(String name) { 127 return name.substring(0, name.length() - CLASSFILE_SUFFIX.length()); 128 } 129 130 private void insertNode(ClassTreeNode newNode, 131 ClassTreeNode parentNode, 132 int insertionIndex, 133 DefaultTreeModel model, 134 boolean reset) 135 { 136 parentNode.insert(newNode, insertionIndex); 137 if (!reset) { 138 model.nodesWereInserted(parentNode, new int[] {insertionIndex}); 139 } 140 } 141 142 } 143 | Popular Tags |