1 7 8 package org.gjt.jclasslib.browser.config; 9 10 import org.gjt.jclasslib.browser.config.classpath.*; 11 import org.gjt.jclasslib.mdi.MDIConfig; 12 13 import javax.swing.tree.DefaultTreeModel ; 14 import java.io.File ; 15 import java.util.*; 16 import java.util.regex.Matcher ; 17 import java.util.regex.Pattern ; 18 19 20 26 public class BrowserConfig implements ClasspathComponent { 27 28 private MDIConfig mdiConfig; 29 private List classpath = new ArrayList(); 30 private Set mergedEntries = new HashSet(); 31 private Set changeListeners = new HashSet(); 32 33 37 public MDIConfig getMDIConfig() { 38 return mdiConfig; 39 } 40 41 45 public void setMDIConfig(MDIConfig mdiConfig) { 46 this.mdiConfig = mdiConfig; 47 } 48 49 53 public List getClasspath() { 54 return classpath; 55 } 56 57 61 public void setClasspath(List classpath) { 62 this.classpath = classpath; 63 } 64 65 public void addClasspathChangeListener(ClasspathChangeListener listener) { 66 changeListeners.add(listener); 67 } 68 69 public void removeClasspathChangeListener(ClasspathChangeListener listener) { 70 changeListeners.remove(listener); 71 } 72 73 78 public void addClasspathDirectory(String directoryName) { 79 ClasspathDirectoryEntry entry = new ClasspathDirectoryEntry(); 80 entry.setFileName(directoryName); 81 if (classpath.indexOf(entry) < 0) { 82 classpath.add(entry); 83 fireClasspathChanged(false); 84 } 85 } 86 87 92 public void addClasspathArchive(String archiveName) { 93 ClasspathArchiveEntry entry = new ClasspathArchiveEntry(); 94 entry.setFileName(archiveName); 95 if (classpath.indexOf(entry) < 0) { 96 classpath.add(entry); 97 fireClasspathChanged(false); 98 } 99 } 100 101 106 public void addClasspathEntry(ClasspathEntry entry) { 107 if (classpath.indexOf(entry) < 0) { 108 classpath.add(entry); 109 fireClasspathChanged(false); 110 } 111 } 112 113 117 public void removeClasspathEntry(ClasspathEntry entry) { 118 if (classpath.remove(entry)) { 119 fireClasspathChanged(true); 120 } 121 } 122 123 126 public void addRuntimeLib() { 127 128 String fileName = String .class.getResource("String.class").toExternalForm(); 129 Matcher matcher = Pattern.compile("jar:file:/(.*)!.*").matcher(fileName); 130 if (matcher.matches()) { 131 String path = matcher.group(1); 132 if (path.indexOf(':') == -1) { 133 path = "/" + path; 134 } 135 addClasspathArchive(new File (path).getPath()); 136 fireClasspathChanged(false); 137 } 138 } 139 140 public FindResult findClass(String className) { 141 142 Iterator it = classpath.iterator(); 143 while (it.hasNext()) { 144 ClasspathEntry entry = (ClasspathEntry)it.next(); 145 FindResult findResult = entry.findClass(className); 146 if (findResult != null) { 147 return findResult; 148 } 149 } 150 return null; 151 } 152 153 public void mergeClassesIntoTree(DefaultTreeModel model, boolean reset) { 154 155 Iterator it = classpath.iterator(); 156 while (it.hasNext()) { 157 ClasspathEntry entry = (ClasspathEntry)it.next(); 158 if (reset || !mergedEntries.contains(entry)) { 159 entry.mergeClassesIntoTree(model, reset); 160 mergedEntries.add(entry); 161 } 162 } 163 } 164 165 private void fireClasspathChanged(boolean removal) { 166 Iterator it = changeListeners.iterator(); 167 ClasspathChangeEvent event = new ClasspathChangeEvent(this, removal); 168 while (it.hasNext()) { 169 ClasspathChangeListener listener = (ClasspathChangeListener)it.next(); 170 listener.classpathChanged(event); 171 } 172 } 173 174 } 175 | Popular Tags |