Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
vadere
vadere
Commits
e1432189
Commit
e1432189
authored
Oct 10, 2017
by
Benedikt Zoennchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixing, loading .class files
parent
600f40d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
23 deletions
+78
-23
VadereGui/src/org/vadere/gui/components/view/JComboCheckBox.java
...ui/src/org/vadere/gui/components/view/JComboCheckBox.java
+20
-9
VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java
...Gui/src/org/vadere/gui/projectview/utils/ClassFinder.java
+58
-14
No files found.
VadereGui/src/org/vadere/gui/components/view/JComboCheckBox.java
View file @
e1432189
...
...
@@ -50,17 +50,28 @@ public class JComboCheckBox<E> 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
;
}
});
}
...
...
VadereGui/src/org/vadere/gui/projectview/utils/ClassFinder.java
View file @
e1432189
...
...
@@ -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
<
String
,
Class
>
getDataKeysOutputFileRelation
()
{
try
{
return
getClasses
(
DataKey
.
class
.
getPackage
().
getName
())
return
getClasses
Stream
(
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
<
Class
<?>>
opClasses
=
getClasses
(
OutputFile
.
class
.
getPackage
().
getName
());
List
<
Class
<?>>
opClasses
=
getClasses
Stream
(
OutputFile
.
class
.
getPackage
().
getName
());
Optional
<
Class
<?>>
corrOpClass
=
opClasses
.
stream
()
...
...
@@ -112,9 +106,9 @@ public class ClassFinder {
private
static
List
<
Class
<?>>
findSubclassesInPackage
(
String
packageName
,
Class
<?>
baseClassOrInterface
)
{
try
{
return
getClasses
(
packageName
).
stream
()
return
getClasses
Stream
(
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
<
Class
<?>>
getClasses
(
String
packageName
)
throws
ClassNotFoundException
,
IOException
{
ClassLoader
classLoader
=
Thread
.
currentThread
().
getContextClassLoader
();
assert
classLoader
!=
null
;
String
path
=
packageName
.
replace
(
'.'
,
'/'
);
Enumeration
<
URL
>
resources
=
classLoader
.
getResources
(
path
);
List
<
File
>
dirs
=
new
ArrayList
<>();
assert
classLoader
!=
null
;
//String path = packageName.replace('.', '/');
Enumeration
<
URL
>
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
<
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.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment