Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
vadere
vadere
Commits
7254bec4
Commit
7254bec4
authored
Jul 03, 2018
by
Daniel Lehmberg
Browse files
remove reflection in ReflectionAttriuteModifier; include new ABC for Attributes with shape
parent
571686f9
Pipeline
#59591
passed with stage
in 49 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereGui/src/org/vadere/gui/components/view/ScenarioElementView.java
View file @
7254bec4
...
...
@@ -143,7 +143,7 @@ public class ScenarioElementView extends JPanel implements ISelectScenarioElemen
}
else
{
try
{
Attributes
attributes
=
StateJsonConverter
.
deserializeScenarioElementType
(
json
,
element
.
getType
());
element
.
setAttributes
(
attributes
);
// Replaces previous
Reflection
AttributeModifier.setAttributes (see #91)
element
.
setAttributes
(
attributes
);
// Replaces previous AttributeModifier.setAttributes (see #91)
ScenarioPanel
.
removeJsonParsingErrorMsg
();
ProjectView
.
getMainWindow
().
refreshScenarioNames
();
jsonValidIndicator
.
setValid
();
...
...
VadereGui/src/org/vadere/gui/topographycreator/control/
Reflection
AttributeModifier.java
→
VadereGui/src/org/vadere/gui/topographycreator/control/AttributeModifier.java
View file @
7254bec4
...
...
@@ -5,17 +5,18 @@ import java.lang.reflect.Field;
import
org.vadere.gui.topographycreator.model.AgentWrapper
;
import
org.vadere.simulator.projects.Scenario
;
import
org.vadere.state.attributes.Attributes
;
import
org.vadere.state.attributes.AttributesEmbedShape
;
import
org.vadere.state.scenario.ScenarioElement
;
import
org.vadere.util.geometry.shapes.VPoint
;
import
org.vadere.util.geometry.shapes.VShape
;
/**
* Setter
and getter
implementation to modify Attributes.
This class uses use of reflection.
* Setter implementation to modify
shape of
Attributes.
* Do not use this class outside of the topographycreator package, or even not outside this
* control-package!
*
*
*/
public
class
Reflection
AttributeModifier
{
public
class
AttributeModifier
{
/**
* Sets the shape to the attributes of an topography element. Use this method only in the
* control!
...
...
@@ -25,22 +26,15 @@ public class ReflectionAttributeModifier {
*/
static
void
setShapeToAttributes
(
final
ScenarioElement
element
,
final
VShape
shape
)
{
try
{
Field
field
;
if
(
element
instanceof
AgentWrapper
)
{
double
x
=
shape
.
getBounds2D
().
getCenterX
();
double
y
=
shape
.
getBounds2D
().
getCenterY
();
((
AgentWrapper
)
element
).
getAgentInitialStore
().
setPosition
(
new
VPoint
(
x
,
y
));
}
else
{
Attributes
attributes
=
element
.
getAttributes
();
// replaces Relection code from above
//TODO: issue #91 Cannot easily replace the relection in the following code. Some Attributes classes have a
//TODO: setShape(shape) method such as AttributesStairs, but not all, so there is no guarantee...
//TODO: If there is no field "shape", then only the stacktrace is printed...
field
=
attributes
.
getClass
().
getDeclaredField
(
"shape"
);
field
.
setAccessible
(
true
);
field
.
set
(
attributes
,
shape
);
AttributesEmbedShape
attributes
=
(
AttributesEmbedShape
)
element
.
getAttributes
();
attributes
.
setShape
(
shape
);
}
}
catch
(
NoSuchFieldException
|
SecurityException
|
IllegalArgumentException
|
IllegalAccess
Exception
e
)
{
}
catch
(
ClassCast
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
VadereGui/src/org/vadere/gui/topographycreator/control/EditUpdateElementShape.java
View file @
7254bec4
...
...
@@ -26,14 +26,14 @@ public class EditUpdateElementShape extends AbstractUndoableEdit {
@Override
public
void
undo
()
throws
CannotUndoException
{
Reflection
AttributeModifier
.
setShapeToAttributes
(
element
,
oldShape
);
AttributeModifier
.
setShapeToAttributes
(
element
,
oldShape
);
panelModel
.
setSelectedElement
(
element
);
panelModel
.
notifyObservers
();
}
@Override
public
void
redo
()
throws
CannotRedoException
{
Reflection
AttributeModifier
.
setShapeToAttributes
(
element
,
newShape
);
AttributeModifier
.
setShapeToAttributes
(
element
,
newShape
);
panelModel
.
setSelectedElement
(
element
);
panelModel
.
notifyObservers
();
}
...
...
VadereGui/src/org/vadere/gui/topographycreator/control/SelectElementMode.java
View file @
7254bec4
...
...
@@ -77,7 +77,7 @@ public class SelectElementMode extends DefaultSelectionMode {
VShape
newShape
=
panelModel
.
translate
(
new
Point
(
e
.
getPoint
().
x
-
startPoint
.
x
,
e
.
getPoint
().
y
-
startPoint
.
y
));
Reflection
AttributeModifier
.
setShapeToAttributes
(
element
,
newShape
);
AttributeModifier
.
setShapeToAttributes
(
element
,
newShape
);
// tell the panelModel that the selected element has changed!
panelModel
.
setSelectedElement
(
element
);
...
...
VadereState/src/org/vadere/state/attributes/AttributesEmbedShape.java
0 → 100644
View file @
7254bec4
package
org.vadere.state.attributes
;
import
org.vadere.util.geometry.shapes.VShape
;
/**
* Abstract Base Class for {@link Attributes} that also consist of a {@link VShape}. The shape can be changed and
* 'undo' and 'redo' operations can be carried out in EditUpdateElementShape in package
* org.vadere.gui.topographycreator.control.
*/
public
abstract
class
AttributesEmbedShape
extends
Attributes
{
public
abstract
void
setShape
(
VShape
shape
);
public
abstract
VShape
getShape
();
}
VadereState/src/org/vadere/state/attributes/scenario/AttributesObstacle.java
View file @
7254bec4
package
org.vadere.state.attributes.scenario
;
import
org.vadere.state.attributes.Attributes
;
import
org.vadere.state.attributes.Attributes
EmbedShape
;
import
org.vadere.util.geometry.shapes.VShape
;
public
class
AttributesObstacle
extends
Attributes
{
public
class
AttributesObstacle
extends
Attributes
EmbedShape
{
private
VShape
shape
;
private
int
id
;
...
...
@@ -19,10 +19,12 @@ public class AttributesObstacle extends Attributes {
this
.
shape
=
shape
;
}
@Override
public
void
setShape
(
VShape
shape
)
{
this
.
shape
=
shape
;
}
@Override
public
VShape
getShape
()
{
return
shape
;
}
...
...
VadereState/src/org/vadere/state/attributes/scenario/AttributesSource.java
View file @
7254bec4
...
...
@@ -4,12 +4,12 @@ import java.util.Collections;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.vadere.state.attributes.Attributes
;
import
org.vadere.state.attributes.Attributes
EmbedShape
;
import
org.vadere.state.scenario.ConstantDistribution
;
import
org.vadere.state.types.DynamicElementType
;
import
org.vadere.util.geometry.shapes.VShape
;
public
class
AttributesSource
extends
Attributes
{
public
class
AttributesSource
extends
Attributes
EmbedShape
{
public
static
final
String
CONSTANT_DISTRIBUTION
=
ConstantDistribution
.
class
.
getName
();
public
static
final
int
NO_MAX_SPAWN_NUMBER_TOTAL
=
-
1
;
...
...
@@ -123,10 +123,12 @@ public class AttributesSource extends Attributes {
return
id
;
}
@Override
public
void
setShape
(
VShape
shape
)
{
this
.
shape
=
shape
;
}
@Override
public
VShape
getShape
()
{
return
shape
;
}
...
...
VadereState/src/org/vadere/state/attributes/scenario/AttributesStairs.java
View file @
7254bec4
...
...
@@ -2,6 +2,7 @@ package org.vadere.state.attributes.scenario;
import
org.apache.log4j.Logger
;
import
org.vadere.state.attributes.Attributes
;
import
org.vadere.state.attributes.AttributesEmbedShape
;
import
org.vadere.state.scenario.Stairs
;
import
org.vadere.util.geometry.Vector2D
;
import
org.vadere.util.geometry.shapes.VShape
;
...
...
@@ -16,7 +17,7 @@ import org.vadere.util.geometry.shapes.VShape;
*
*
*/
public
class
AttributesStairs
extends
Attributes
{
public
class
AttributesStairs
extends
Attributes
EmbedShape
{
private
VShape
shape
=
null
;
private
int
id
=
ID_NOT_SET
;
...
...
@@ -42,10 +43,12 @@ public class AttributesStairs extends Attributes {
}
}
@Override
public
void
setShape
(
VShape
shape
)
{
this
.
shape
=
shape
;
}
@Override
public
VShape
getShape
()
{
return
shape
;
}
...
...
VadereState/src/org/vadere/state/attributes/scenario/AttributesTarget.java
View file @
7254bec4
package
org.vadere.state.attributes.scenario
;
import
org.vadere.state.attributes.Attributes
;
import
org.vadere.state.attributes.AttributesEmbedShape
;
import
org.vadere.state.scenario.Pedestrian
;
import
org.vadere.util.geometry.shapes.VShape
;
...
...
@@ -8,7 +9,7 @@ import org.vadere.util.geometry.shapes.VShape;
* Attributes of a target area, used by TargetController in VadereSimulation.
*
*/
public
class
AttributesTarget
extends
Attributes
{
public
class
AttributesTarget
extends
Attributes
EmbedShape
{
private
int
id
=
ID_NOT_SET
;
/**
...
...
@@ -99,10 +100,12 @@ public class AttributesTarget extends Attributes {
return
id
;
}
@Override
public
void
setShape
(
VShape
shape
)
{
this
.
shape
=
shape
;
}
@Override
public
VShape
getShape
()
{
return
shape
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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