diff --git a/VadereGui/src/org/vadere/gui/components/view/JComboCheckBox.java b/VadereGui/src/org/vadere/gui/components/view/JComboCheckBox.java index d3e16906b7f0061f5b31d788bfdbe914db8fe972..7ad48789391c98218fd07eb0efeb0d39ec292c68 100644 --- a/VadereGui/src/org/vadere/gui/components/view/JComboCheckBox.java +++ b/VadereGui/src/org/vadere/gui/components/view/JComboCheckBox.java @@ -50,17 +50,28 @@ public class JComboCheckBox extends JComboBox { return label; } - JCheckBox cb = new JCheckBox(value.toString()); - cb.setSelected(memory.get(value)); - if (isSelected) { - cb.setBackground(list.getSelectionBackground()); - cb.setForeground(list.getSelectionForeground()); - } else { - cb.setBackground(list.getBackground()); - cb.setForeground(list.getForeground()); + if(value != null) { + JCheckBox cb = new JCheckBox(value == null ? "" : value.toString()); + + if(value != null) { + cb.setSelected(memory.get(value)); + } + + + if (isSelected) { + cb.setBackground(list.getSelectionBackground()); + cb.setForeground(list.getSelectionForeground()); + } else { + cb.setBackground(list.getBackground()); + cb.setForeground(list.getForeground()); + } + + return cb; + } + else { + return this; } - return cb; } }); } diff --git a/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java b/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java index 40a803737c00da3f5a86b45702e600fe3e9878e1..23f99642d53d4d1eef4199e2adf6b9785d0205f3 100644 --- a/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java +++ b/VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java @@ -9,18 +9,12 @@ import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor; import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.models.AttributesOSM; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; public class ClassFinder { @@ -51,14 +45,14 @@ public class ClassFinder { public static Map getDataKeysOutputFileRelation() { try { - return getClasses(DataKey.class.getPackage().getName()) + return getClassesStream(DataKey.class.getPackage().getName()) .stream() .filter(c -> !Modifier.isInterface(c.getModifiers())) .filter(c -> DataKey.class.isAssignableFrom(c)) .map(c -> { // Find corresponding outputfile class try { - List> opClasses = getClasses(OutputFile.class.getPackage().getName()); + List> opClasses = getClassesStream(OutputFile.class.getPackage().getName()); Optional> corrOpClass = opClasses .stream() @@ -112,9 +106,9 @@ public class ClassFinder { private static List> findSubclassesInPackage(String packageName, Class baseClassOrInterface) { try { - return getClasses(packageName).stream() + return getClassesStream(packageName).stream() .filter(c -> !c.isInterface() - && baseClassOrInterface.isAssignableFrom(c) + && baseClassOrInterface.isAssignableFrom(c) && isNotAnInnerClass(c)) .collect(Collectors.toList()); } catch (ClassNotFoundException | IOException e) { @@ -133,17 +127,23 @@ public class ClassFinder { * Scans all classes accessible from the context class loader which belong to the given package * and subpackages. * + * Deprecated since this method does not work inside a jar file! + * * @param packageName The base package * @return The classes * @throws ClassNotFoundException * @throws IOException */ + @Deprecated private static List> getClasses(String packageName) throws ClassNotFoundException, IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - assert classLoader != null; String path = packageName.replace('.', '/'); - Enumeration resources = classLoader.getResources(path); List dirs = new ArrayList<>(); + + assert classLoader != null; + //String path = packageName.replace('.', '/'); + Enumeration resources = classLoader.getResources(path); + while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); @@ -155,6 +155,50 @@ public class ClassFinder { return classes; } + /** + * Scans all classes accessible from the context class loader which belong to the given package + * and subpackages. Works inside a jar file. + * + * + * @param packageName The base package + * @return The classes + * @throws ClassNotFoundException + * @throws IOException + */ + private static List> getClassesStream(String packageName) throws ClassNotFoundException, IOException { + List> classes = new ArrayList<>(); + + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + String path = packageName.replace('.', '/'); + List resources = new ArrayList<>(); + LinkedList dirs = new LinkedList<>(); + + dirs.add(path); + + while(!dirs.isEmpty()) { + String currentDir = dirs.removeFirst(); + String currentPackage = currentDir.replace('/', '.'); + + InputStream in = ClassFinder.class.getResourceAsStream("/" + currentDir); + BufferedReader rdr = new BufferedReader(new InputStreamReader(in)); + + String line; // line is either a .class file or a directory containing .class files or other directories + while ((line = rdr.readLine()) != null) { + + // line is a filenamew + if(line.endsWith(".class")) { + classes.add(ClassFinder.class.forName(currentPackage + '.' + line.substring(0, line.length() - 6))); + } + else { + dirs.add(currentDir+'/'+line); + } + } + rdr.close(); + } + + return classes; + } + /** * Recursive method used to find all classes in a given directory and subdirs. *