mirror of
https://github.com/badvision/jace.git
synced 2025-02-08 13:30:36 +00:00
Removed hacky class detection in favor of a more stable library (org.reflections).
This commit is contained in:
parent
a52dafa8bb
commit
90e09ba53c
17
pom.xml
17
pom.xml
@ -11,12 +11,11 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mainClass>jace.MainApp</mainClass>
|
||||
<mainClass>jace.JaceApplication</mainClass>
|
||||
</properties>
|
||||
|
||||
<organization>
|
||||
<!-- Used as the 'Vendor' for JNLP generation -->
|
||||
<name>Your Organisation</name>
|
||||
<name>badvision</name>
|
||||
</organization>
|
||||
|
||||
<build>
|
||||
@ -130,13 +129,6 @@
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- <dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>javafx</artifactId>
|
||||
<version>2</version>
|
||||
<systemPath>${java.home}/lib/jfxrt.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>javafx-packager</groupId>
|
||||
<artifactId>javafx-packager</artifactId>
|
||||
@ -144,5 +136,10 @@
|
||||
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.9</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -21,11 +21,11 @@ package jace.config;
|
||||
import jace.core.Utility;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -43,12 +43,12 @@ public class ClassSelection extends DynamicSelection<Class> {
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<Class, String> getSelections() {
|
||||
LinkedHashMap<Class, String> selections = new LinkedHashMap<Class, String>();
|
||||
List<? extends Class> allClasses = (List<? extends Class>) Utility.findAllSubclasses(template);
|
||||
LinkedHashMap<Class, String> selections = new LinkedHashMap<>();
|
||||
Set<? extends Class> allClasses = (Set<? extends Class>) Utility.findAllSubclasses(template);
|
||||
if (!allClasses.contains(null)) {
|
||||
allClasses.add(null);
|
||||
}
|
||||
List<Entry<Class, String>> values = new ArrayList<Map.Entry<Class, String>>();
|
||||
List<Entry<Class, String>> values = new ArrayList<>();
|
||||
if (allowNull()) {
|
||||
values.add(new Entry<Class, String>() {
|
||||
|
||||
@ -71,10 +71,12 @@ public class ClassSelection extends DynamicSelection<Class> {
|
||||
for (final Class c : allClasses) {
|
||||
Entry<Class, String> entry = new Map.Entry<Class, String>() {
|
||||
|
||||
@Override
|
||||
public Class getKey() {
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
if (c == null) {
|
||||
return "**Empty**";
|
||||
@ -85,6 +87,7 @@ public class ClassSelection extends DynamicSelection<Class> {
|
||||
return c.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setValue(String value) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@ -101,8 +104,7 @@ public class ClassSelection extends DynamicSelection<Class> {
|
||||
};
|
||||
values.add(entry);
|
||||
}
|
||||
Collections.sort(values, new Comparator<Map.Entry<? extends Class, String>>() {
|
||||
public int compare(Entry<? extends Class, String> o1, Entry<? extends Class, String> o2) {
|
||||
Collections.sort(values, (Entry<? extends Class, String> o1, Entry<? extends Class, String> o2) -> {
|
||||
if (o1.getKey() == null) {
|
||||
return -1;
|
||||
}
|
||||
@ -111,12 +113,11 @@ public class ClassSelection extends DynamicSelection<Class> {
|
||||
} else {
|
||||
return (o1.getValue().compareTo(o2.getValue()));
|
||||
}
|
||||
}
|
||||
});
|
||||
for (Map.Entry<Class, String> entry : values) {
|
||||
values.stream().forEach((entry) -> {
|
||||
Class key = entry.getKey();
|
||||
selections.put(key, entry.getValue());
|
||||
}
|
||||
});
|
||||
return selections;
|
||||
}
|
||||
|
||||
|
@ -44,4 +44,5 @@ public @interface ConfigurableField {
|
||||
public String defaultValue() default "";
|
||||
public String description() default "";
|
||||
public String category() default "General";
|
||||
public boolean enablesDevice() default false;
|
||||
}
|
@ -39,14 +39,10 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@ -265,10 +261,6 @@ public class Configuration implements Reconfigurable {
|
||||
@ConfigurableField(name = "Autosave Changes", description = "If unchecked, changes are only saved when the Save button is pressed.")
|
||||
public static boolean saveAutomatically = false;
|
||||
|
||||
static {
|
||||
buildTree();
|
||||
}
|
||||
|
||||
public static void buildTree() {
|
||||
BASE = new ConfigNode(new Configuration());
|
||||
buildTree(BASE, new LinkedHashSet());
|
||||
@ -308,7 +300,8 @@ public class Configuration implements Reconfigurable {
|
||||
node.setRawFieldValue(f.getName(), (Serializable) o);
|
||||
}
|
||||
continue;
|
||||
} else if (o == null) {
|
||||
}
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public abstract class DynamicSelection<T> implements ISelection<T> {
|
||||
T currentValue;
|
||||
@Override
|
||||
public T getValue() {
|
||||
if (currentValue != null || !allowNull()) {
|
||||
if (currentValue != null || allowNull()) {
|
||||
return currentValue;
|
||||
} else {
|
||||
Iterator<? extends T> i = getSelections().keySet().iterator();
|
||||
|
@ -27,6 +27,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import org.reflections.Reflections;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
@ -57,12 +58,15 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
|
||||
/**
|
||||
* This is a set of helper functions which do not belong anywhere else. Functions vary from introspection, discovery, and string/pattern matching.
|
||||
* This is a set of helper functions which do not belong anywhere else.
|
||||
* Functions vary from introspection, discovery, and string/pattern matching.
|
||||
*
|
||||
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
||||
*/
|
||||
public class Utility {
|
||||
|
||||
//--------------- Introspection utilities
|
||||
/*
|
||||
private static Set<Class> findClasses(String pckgname, Class clazz) {
|
||||
Set<Class> output = new HashSet<>();
|
||||
// Code from JWhich
|
||||
@ -100,7 +104,6 @@ public class Utility {
|
||||
try {
|
||||
// Try to create an instance of the object
|
||||
String className = pckgname + "." + classname;
|
||||
// System.out.println("Class: " + className);
|
||||
Class c = Class.forName(className);
|
||||
if (clazz.isAssignableFrom(c)) {
|
||||
output.add(c);
|
||||
@ -177,26 +180,36 @@ public class Utility {
|
||||
return output;
|
||||
}
|
||||
private static final Map<Class, Collection<Class>> classCache = new HashMap<>();
|
||||
|
||||
*/
|
||||
static Reflections reflections = new Reflections("jace");
|
||||
public static Set<Class> findAllSubclasses(Class clazz) {
|
||||
return reflections.getSubTypesOf(clazz);
|
||||
}
|
||||
/*
|
||||
public static List<Class> findAllSubclasses(Class clazz) {
|
||||
if (classCache.containsKey(clazz)) {
|
||||
return (List<Class>) classCache.get(clazz);
|
||||
}
|
||||
TreeMap<String, Class> allClasses = new TreeMap<>();
|
||||
List<Class> values = new ArrayList(allClasses.values());
|
||||
classCache.put(clazz, values);
|
||||
for (Package p : Package.getPackages()) {
|
||||
if (p.getName().startsWith("java")
|
||||
|| p.getName().startsWith("com.sun")
|
||||
|| p.getName().startsWith("sun")
|
||||
|| p.getName().startsWith("com.oracle")) {
|
||||
continue;
|
||||
}
|
||||
findClasses(p.getName(), clazz).stream().filter((c) -> !(Modifier.isAbstract(c.getModifiers()))).forEach((c) -> {
|
||||
findClasses(p.getName(), clazz)
|
||||
.stream()
|
||||
.filter((c) -> !(Modifier.isAbstract(c.getModifiers())))
|
||||
.forEach((c) -> {
|
||||
allClasses.put(c.getSimpleName(), c);
|
||||
});
|
||||
}
|
||||
List<Class> values = new ArrayList(allClasses.values());
|
||||
classCache.put(clazz, values);
|
||||
return values;
|
||||
}
|
||||
*/
|
||||
|
||||
//------------------------------ String comparators
|
||||
/**
|
||||
@ -310,7 +323,6 @@ public class Utility {
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
public static void runModalProcess(String title, final Runnable runnable) {
|
||||
// final JDialog frame = new JDialog(Emulator.getFrame());
|
||||
final JProgressBar progressBar = new JProgressBar();
|
||||
|
Loading…
x
Reference in New Issue
Block a user