11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit e1432189 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

bug fixing, loading .class files

parent 600f40d1
...@@ -50,17 +50,28 @@ public class JComboCheckBox<E> extends JComboBox { ...@@ -50,17 +50,28 @@ public class JComboCheckBox<E> extends JComboBox {
return label; return label;
} }
JCheckBox cb = new JCheckBox(value.toString()); if(value != null) {
cb.setSelected(memory.get(value)); JCheckBox cb = new JCheckBox(value == null ? "" : value.toString());
if (isSelected) {
cb.setBackground(list.getSelectionBackground()); if(value != null) {
cb.setForeground(list.getSelectionForeground()); cb.setSelected(memory.get(value));
} else { }
cb.setBackground(list.getBackground());
cb.setForeground(list.getForeground());
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;
} }
}); });
} }
......
...@@ -9,18 +9,12 @@ import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor; ...@@ -9,18 +9,12 @@ import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor;
import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesOSM; import org.vadere.state.attributes.models.AttributesOSM;
import java.io.File; import java.io.*;
import java.io.IOException;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ClassFinder { public class ClassFinder {
...@@ -51,14 +45,14 @@ public class ClassFinder { ...@@ -51,14 +45,14 @@ public class ClassFinder {
public static Map<String, Class> getDataKeysOutputFileRelation() { public static Map<String, Class> getDataKeysOutputFileRelation() {
try { try {
return getClasses(DataKey.class.getPackage().getName()) return getClassesStream(DataKey.class.getPackage().getName())
.stream() .stream()
.filter(c -> !Modifier.isInterface(c.getModifiers())) .filter(c -> !Modifier.isInterface(c.getModifiers()))
.filter(c -> DataKey.class.isAssignableFrom(c)) .filter(c -> DataKey.class.isAssignableFrom(c))
.map(c -> { .map(c -> {
// Find corresponding outputfile class // Find corresponding outputfile class
try { try {
List<Class<?>> opClasses = getClasses(OutputFile.class.getPackage().getName()); List<Class<?>> opClasses = getClassesStream(OutputFile.class.getPackage().getName());
Optional<Class<?>> corrOpClass = opClasses Optional<Class<?>> corrOpClass = opClasses
.stream() .stream()
...@@ -112,9 +106,9 @@ public class ClassFinder { ...@@ -112,9 +106,9 @@ public class ClassFinder {
private static List<Class<?>> findSubclassesInPackage(String packageName, Class<?> baseClassOrInterface) { private static List<Class<?>> findSubclassesInPackage(String packageName, Class<?> baseClassOrInterface) {
try { try {
return getClasses(packageName).stream() return getClassesStream(packageName).stream()
.filter(c -> !c.isInterface() .filter(c -> !c.isInterface()
&& baseClassOrInterface.isAssignableFrom(c) && baseClassOrInterface.isAssignableFrom(c)
&& isNotAnInnerClass(c)) && isNotAnInnerClass(c))
.collect(Collectors.toList()); .collect(Collectors.toList());
} catch (ClassNotFoundException | IOException e) { } catch (ClassNotFoundException | IOException e) {
...@@ -133,17 +127,23 @@ public class ClassFinder { ...@@ -133,17 +127,23 @@ public class ClassFinder {
* Scans all classes accessible from the context class loader which belong to the given package * Scans all classes accessible from the context class loader which belong to the given package
* and subpackages. * and subpackages.
* *
* Deprecated since this method does not work inside a jar file!
*
* @param packageName The base package * @param packageName The base package
* @return The classes * @return The classes
* @throws ClassNotFoundException * @throws ClassNotFoundException
* @throws IOException * @throws IOException
*/ */
@Deprecated
private static List<Class<?>> getClasses(String packageName) throws ClassNotFoundException, IOException { private static List<Class<?>> getClasses(String packageName) throws ClassNotFoundException, IOException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
assert classLoader != null;
String path = packageName.replace('.', '/'); String path = packageName.replace('.', '/');
Enumeration<URL> resources = classLoader.getResources(path);
List<File> dirs = new ArrayList<>(); List<File> dirs = new ArrayList<>();
assert classLoader != null;
//String path = packageName.replace('.', '/');
Enumeration<URL> resources = classLoader.getResources(path);
while (resources.hasMoreElements()) { while (resources.hasMoreElements()) {
URL resource = resources.nextElement(); URL resource = resources.nextElement();
dirs.add(new File(resource.getFile())); dirs.add(new File(resource.getFile()));
...@@ -155,6 +155,50 @@ public class ClassFinder { ...@@ -155,6 +155,50 @@ public class ClassFinder {
return classes; 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<Class<?>> getClassesStream(String packageName) throws ClassNotFoundException, IOException {
List<Class<?>> classes = new ArrayList<>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
String path = packageName.replace('.', '/');
List<String> resources = new ArrayList<>();
LinkedList<String> 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. * Recursive method used to find all classes in a given directory and subdirs.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment