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
15cc6e4a
Commit
15cc6e4a
authored
Oct 10, 2019
by
Benedikt Zoennchen
Browse files
Merge branch 'master' of
https://gitlab.lrz.de/vadere/vadere
parents
ce962337
696a81f4
Changes
259
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 259+
files are displayed.
Plain diff
Email patch
VadereGui/resources/messages.properties
View file @
15cc6e4a
...
...
@@ -215,7 +215,8 @@ ProjectView.OpenInExplorer.text=Open in Explorer
ProjectView.mntmCopyOutputDir.text
=
Copy output path to clipboard
SettingsDialog.chbShowPedestrianIds.text
=
Show PedestrianIds
PostVis.chShowEvacTimeColor.text
=
Color Pedestrians regarding to Evacuation Times
PostVis.chShowEvacTimeColor.text
=
Coloring by Evacuation Times
PostVis.chShowCriteriaColor.text
=
Coloring by Predicate
PostVis.additional.border.text
=
PostVis
PostVis.btnPlay.tooltip
=
Play (Space)
...
...
@@ -228,12 +229,13 @@ PostVis.title=Vadere Post-Visualization
PostVis.version
=
Version {0}
PostVis.license.text
=
This product is licensed under the {0}
PostVis.chbHidePedAtTarget.text
=
Hide Pedestrians
at Target
PostVis.chbHideTrajAtTarget.text
=
Hide Trajectories
at Target
PostVis.chbHidePedAtTarget.text
=
Hide
disappeared
Pedestrians
PostVis.chbHideTrajAtTarget.text
=
Hide Trajectories
of disappeared Pedestrians
PostVis.chShowAllTrajOnSnapshot.text
=
Show all Trajectories on Snapshot
PostVis.chbCleanSnapshot.text
=
Hide Trajectories on Snapshots
SettingsDialog.chbUseRandomColors.text
=
Random Coloring
SettingsDialog.chbGroupColors.text
=
Coloring by Group
SettingsDialog.chbHideVoronoiDiagram.text
=
Hide VoronoiDiagram
SettingsDialog.chbShowObstacles.text
=
Show Obstacles
SettingsDialog.chbShowTargets.text
=
Show Targets
...
...
@@ -269,7 +271,8 @@ LoadingDialog.title=Loading...
FileDialog.filenamePrefix
=
vadere_
SettingsDialog.title
=
Settings
SettingsDialog.colors.border.text
=
Colors
SettingsDialog.colors.border.text
=
Element coloring
SettingsDialog.pedcolors.border.text
=
Pedestrian coloring
SettingsDialog.additional.border.text
=
Additional
SettingsDialog.lblTarget.text
=
Target
#SettingsDialog.lblPedestrian.text=Pedestrian
...
...
@@ -284,7 +287,8 @@ SettingsDialog.btnClose.text=Close
SettingsDialog.lblDensityColor.text
=
Density
SettingsDialog.lblAbsorbingAreaColor.text
=
Absorbing Area
SettingsDialog.lblStair.text
=
Stair
SettingsDialog.lblPedestrianNoTarget.text
=
Without Target (-1)
SettingsDialog.lblPedestrianNoTarget.text
=
Without Target
SettingsDialog.lblTargetColoring.text
=
Coloring by Target
ProjectView.menuOpenFloorFieldFile.title
=
Add Floor Field File...
ProjectView.btnDrawVoronoiDiagram.tooltip
=
Draw and display a Voronoi Diagram
...
...
VadereGui/resources/messages_de_DE.properties
View file @
15cc6e4a
...
...
@@ -218,18 +218,20 @@ ProjectView.mntmCopyOutputDir.text=Kopiere Output Pfad in Zwischenablage
SettingsDialog.chbShowPedestrianIds.text
=
Fu
\u
00dfg
\u
00E4nger-Ids anzeigen
PostVis.additional.border.text
=
PostVis
PostVis.chShowEvacTimeColor.text
=
F
\u
00e4rbe Fu
\u
00dfg
\u
00E4nger nach ihrer Evakuierungszeit
PostVis.chShowEvacTimeColor.text
=
F
\u
00e4rbe nach Evakuierungszeit
PostVis.chShowCriteriaColor.text
=
F
\u
00e4rbung nach Bedingung
PostVis.btnPlay.tooltip
=
Start (Leertaste)
PostVis.btnPause.tooltip
=
Pause (Leertaste)
PostVis.btnStop.tooltip
=
Stopp (Backspace-Taste)
PostVis.btnRecord.tooltip
=
Starte Aufnahme
PostVis.chbHidePedAtTarget.text
=
Fu
\u
00dfg
\u
00E4nger im Ziel nicht anzeigen
PostVis.chbHideTrajAtTarget.text
=
Trajektorien am Ziel nicht anzeigen
PostVis.chbHidePedAtTarget.text
=
Verschwundene
Fu
\u
00dfg
\u
00E4nger im Ziel nicht anzeigen
PostVis.chbHideTrajAtTarget.text
=
Verschwundene
Trajektorien am Ziel nicht anzeigen
PostVis.chbCleanSnapshot.text
=
Trajektorien auf Snapshots nicht anzeigen
PostVis.chShowAllTrajOnSnapshot.text
=
Alle Trajektorien auf Snapshot anzeigen
SettingsDialog.chbUseRandomColors.text
=
Zuf
\u
00E4llige Farben
SettingsDialog.chbGroupColors.text
=
F
\u
00E4rbung nach Gruppe
SettingsDialog.chbHideVoronoiDiagram.text
=
Voronoi-Diagramm nicht anzeigen
SettingsDialog.chbShowObstacles.text
=
Hindernisse anzeigen
SettingsDialog.chbShowTargets.text
=
Ziele anzeigen
...
...
@@ -264,7 +266,8 @@ LoadingDialog.title=Lade...
FileDialog.filenamePrefix
=
vadere_
SettingsDialog.title
=
Einstellungen
SettingsDialog.colors.border.text
=
Farben
SettingsDialog.colors.border.text
=
Elementfarben
SettingsDialog.pedcolors.border.text
=
Fu
\u
00dfg
\u
00e4ngerfarben
SettingsDialog.additional.border.text
=
Extras
SettingsDialog.lblTarget.text
=
Ziel
SettingsDialog.lblPedestrian.text
=
Pedestrian
...
...
@@ -279,7 +282,8 @@ SettingsDialog.btnClose.text=Schlie\u00dfen
SettingsDialog.lblDensityColor.text
=
Dichte
SettingsDialog.lblAbsorbingAreaColor.text
=
Absorbierender Bereich
SettingsDialog.lblStair.text
=
Treppe
SettingsDialog.lblPedestrianNoTarget.text
=
Ohne Ziel (-1)
SettingsDialog.lblPedestrianNoTarget.text
=
Ohne Ziel
SettingsDialog.lblTargetColoring.text
=
F
\u
00e4rbung nach Ziel
SettingsDialog.menuOpenFloorFieldFile.title
=
Floor Field-Datei hinzuf
\u
00fcgen...
SettingsDialog.btnDrawVoronoiDiagram.tooltip
=
Voronoi-Diagramm zeichnen und anzeigen
SettingsDialog.chbLogo.text
=
VADERE-Logo anzeigen
...
...
VadereGui/src/org/vadere/gui/components/control/simulation/ActionSetColor.java
View file @
15cc6e4a
...
...
@@ -19,7 +19,7 @@ public abstract class ActionSetColor extends ActionVisualization {
@Override
public
void
actionPerformed
(
final
ActionEvent
event
)
{
Color
color
=
JColorChooser
.
showDialog
(
null
,
"Choose Color"
,
coloredPanel
.
getBackground
());
Color
color
=
JColorChooser
.
showDialog
(
coloredPanel
.
getParent
()
,
"Choose Color"
,
coloredPanel
.
getBackground
());
if
(
color
!=
null
)
{
coloredPanel
.
setBackground
(
color
);
saveColor
(
color
);
...
...
VadereGui/src/org/vadere/gui/components/control/simulation/ActionSetSnapshotDirectory.java
View file @
15cc6e4a
...
...
@@ -13,18 +13,20 @@ public class ActionSetSnapshotDirectory extends ActionVisualization {
private
static
final
Configuration
CONFIG
=
VadereConfig
.
getConfig
();
private
final
JTextField
textField
;
private
final
JDialog
parent
;
public
ActionSetSnapshotDirectory
(
final
String
name
,
final
SimulationModel
<?
extends
DefaultSimulationConfig
>
model
,
final
JTextField
textField
)
{
final
JTextField
textField
,
final
JDialog
parent
)
{
super
(
name
,
model
);
this
.
textField
=
textField
;
this
.
parent
=
parent
;
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
final
JFileChooser
fc
=
new
JFileChooser
(
CONFIG
.
getString
(
"SettingsDialog.snapshotDirectory.path"
));
fc
.
setFileSelectionMode
(
JFileChooser
.
DIRECTORIES_ONLY
);
int
returnVal
=
fc
.
showOpenDialog
(
null
);
int
returnVal
=
fc
.
showOpenDialog
(
parent
);
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
fc
.
getSelectedFile
();
...
...
VadereGui/src/org/vadere/gui/components/model/AgentColoring.java
0 → 100644
View file @
15cc6e4a
package
org.vadere.gui.components.model
;
public
enum
AgentColoring
{
TARGET
,
RANDOM
,
GROUP
,
EVACUATION_TIMES
,
PREDICATE
;
}
VadereGui/src/org/vadere/gui/components/model/DefaultModel.java
View file @
15cc6e4a
...
...
@@ -174,36 +174,36 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
return
hasChanged
;
}
protected
void
notifyViewportListeners
(
final
ViewportChangeEvent
event
)
{
protected
synchronized
void
notifyViewportListeners
(
final
ViewportChangeEvent
event
)
{
for
(
IViewportChangeListener
listener
:
viewportChangeListeners
)
{
listener
.
viewportChange
(
event
);
}
}
@Override
public
void
notifyScaleListeners
()
{
public
synchronized
void
notifyScaleListeners
()
{
for
(
IScaleChangeListener
listener
:
scaleChangeListeners
)
{
listener
.
scaleChange
(
getScaleFactor
());
}
}
@Override
public
void
addViewportChangeListener
(
final
IViewportChangeListener
listener
)
{
public
synchronized
void
addViewportChangeListener
(
final
IViewportChangeListener
listener
)
{
viewportChangeListeners
.
add
(
listener
);
}
@Override
public
void
removeViewportChangeListener
(
final
IViewportChangeListener
listener
)
{
public
synchronized
void
removeViewportChangeListener
(
final
IViewportChangeListener
listener
)
{
viewportChangeListeners
.
remove
(
listener
);
}
@Override
public
void
addScaleChangeListener
(
final
IScaleChangeListener
listener
)
{
public
synchronized
void
addScaleChangeListener
(
final
IScaleChangeListener
listener
)
{
this
.
scaleChangeListeners
.
add
(
listener
);
}
@Override
public
void
removeScaleChangeListener
(
final
IScaleChangeListener
listener
)
{
public
synchronized
void
removeScaleChangeListener
(
final
IScaleChangeListener
listener
)
{
this
.
scaleChangeListeners
.
remove
(
listener
);
}
...
...
@@ -236,7 +236,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
*/
@Override
public
void
setMousePosition
(
final
Point
mousePosition
)
{
public
synchronized
void
setMousePosition
(
final
Point
mousePosition
)
{
// this is needed cause of the mirrowing!
VPoint
mouseWorldPosition
=
pixelToWorld
(
new
VPoint
(
mousePosition
.
x
,
mousePosition
.
y
));
double
factor
=
Math
.
max
(
10
,
1
/
getGridResolution
());
...
...
@@ -246,7 +246,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
}
@Override
public
void
setStartSelectionPoint
(
final
Point
startSelectionPoint
)
{
public
synchronized
void
setStartSelectionPoint
(
final
Point
startSelectionPoint
)
{
VPoint
worldPosition
=
pixelToWorld
(
new
VPoint
(
startSelectionPoint
.
x
,
startSelectionPoint
.
y
));
double
factor
=
Math
.
max
(
10
,
1
/
getGridResolution
());
this
.
startSelectionPoint
=
new
VPoint
((
Math
.
round
(
worldPosition
.
x
*
factor
))
/
factor
,
...
...
@@ -255,13 +255,13 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
}
@Override
public
void
setSelectionShape
(
final
VShape
shape
)
{
public
synchronized
void
setSelectionShape
(
final
VShape
shape
)
{
selectionShape
=
shape
;
setChanged
();
}
@Override
public
void
fireChangeViewportEvent
(
final
Rectangle2D
.
Double
viewportBound
)
{
public
synchronized
void
fireChangeViewportEvent
(
final
Rectangle2D
.
Double
viewportBound
)
{
notifyViewportListeners
(
new
ViewportChangeEvent
(
viewportBound
));
}
...
...
@@ -343,7 +343,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
}
@Override
public
void
setVoronoiDiagram
(
final
VoronoiDiagram
voronoiDiagram
)
{
public
synchronized
void
setVoronoiDiagram
(
final
VoronoiDiagram
voronoiDiagram
)
{
this
.
voronoiDiagram
=
voronoiDiagram
;
}
...
...
@@ -382,7 +382,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
}
@Override
public
void
setWindowBound
(
final
Rectangle2D
.
Double
windowBound
)
{
public
synchronized
void
setWindowBound
(
final
Rectangle2D
.
Double
windowBound
)
{
this
.
windowBound
=
windowBound
;
setChanged
();
}
...
...
@@ -393,18 +393,18 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
return
selectedElement
;
}
private
Optional
<
ScenarioElement
>
getElementsByPosition
(
final
VPoint
position
)
{
private
synchronized
Optional
<
ScenarioElement
>
getElementsByPosition
(
final
VPoint
position
)
{
return
getElements
(
e
->
e
.
getShape
().
intersects
(
new
Rectangle2D
.
Double
(
position
.
x
-
0.1
,
position
.
y
-
0.1
,
0.2
,
0.2
))).
findFirst
();
}
protected
ScenarioElement
getClickedElement
(
final
VPoint
position
)
{
protected
synchronized
ScenarioElement
getClickedElement
(
final
VPoint
position
)
{
Optional
<
ScenarioElement
>
optional
=
getElementsByPosition
(
position
);
if
(
optional
.
isPresent
())
return
optional
.
get
();
return
null
;
}
protected
Stream
<
ScenarioElement
>
getElements
(
final
Predicate
<
ScenarioElement
>
predicate
)
{
protected
synchronized
Stream
<
ScenarioElement
>
getElements
(
final
Predicate
<
ScenarioElement
>
predicate
)
{
return
StreamSupport
.
stream
(
this
.
spliterator
(),
false
).
filter
(
predicate
);
}
...
...
@@ -430,12 +430,12 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
}
@Override
public
void
addSelectScenarioElementListener
(
final
ISelectScenarioElementListener
listener
)
{
public
synchronized
void
addSelectScenarioElementListener
(
final
ISelectScenarioElementListener
listener
)
{
this
.
selectScenarioElementListener
.
add
(
listener
);
}
@Override
public
void
removeSelectScenarioElementListener
(
final
ISelectScenarioElementListener
listener
)
{
public
synchronized
void
removeSelectScenarioElementListener
(
final
ISelectScenarioElementListener
listener
)
{
this
.
selectScenarioElementListener
.
remove
(
listener
);
}
...
...
@@ -454,13 +454,13 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
setChanged
();
}
protected
void
notifySelectSecenarioElementListener
(
final
ScenarioElement
scenarioElement
)
{
protected
synchronized
void
notifySelectSecenarioElementListener
(
final
ScenarioElement
scenarioElement
)
{
for
(
ISelectScenarioElementListener
listener
:
selectScenarioElementListener
)
{
listener
.
selectionChange
(
scenarioElement
);
}
}
protected
void
calculateScaleFactor
()
{
protected
synchronized
void
calculateScaleFactor
()
{
scaleFactor
=
Math
.
min
(
getWindowBound
().
getWidth
()
/
getViewportBound
().
getWidth
(),
getWindowBound
().
getHeight
()
/
getViewportBound
().
getHeight
());
}
...
...
@@ -470,7 +470,7 @@ public abstract class DefaultModel<T extends DefaultConfig> extends Observable i
* @param pInPixel the mouse position of the mouse event
* @return
*/
protected
VPoint
pixelToWorld
(
final
VPoint
pInPixel
)
{
protected
synchronized
VPoint
pixelToWorld
(
final
VPoint
pInPixel
)
{
if
(
pInPixel
!=
null
)
{
return
new
VPoint
(
pInPixel
.
getX
()
/
scaleFactor
+
getTopographyBound
().
getMinX
(),
getTopographyBound
().
getMinY
()
+
(
getTopographyBound
().
getHeight
()
*
scaleFactor
-
pInPixel
.
getY
())
/
scaleFactor
);
...
...
VadereGui/src/org/vadere/gui/components/model/DefaultSimulationConfig.java
View file @
15cc6e4a
...
...
@@ -20,7 +20,6 @@ public class DefaultSimulationConfig extends DefaultConfig {
private
double
densityStandardDerivation
=
CONFIG
.
getDouble
(
"Density.standardDeviation"
);
private
double
pedestrianTorso
=
CONFIG
.
getDouble
(
"Pedestrian.radius"
)
*
2
;
private
boolean
useRandomPedestrianColors
=
false
;
private
boolean
showPedestrianIds
=
false
;
private
boolean
showTargets
=
true
;
private
boolean
showAbsorbingAreas
=
true
;
...
...
@@ -43,6 +42,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private
double
gridWidth
=
CONFIG
.
getDouble
(
"ProjectView.cellWidth"
);
private
final
double
MIN_CELL_WIDTH
=
CONFIG
.
getDouble
(
"ProjectView.minCellWidth"
);
private
final
double
MAX_CELL_WIDTH
=
CONFIG
.
getDouble
(
"ProjectView.maxCellWidth"
);
private
AgentColoring
agentColoring
=
AgentColoring
.
TARGET
;
public
DefaultSimulationConfig
()
{
super
();
...
...
@@ -71,6 +71,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
this
.
showGroups
=
config
.
showGroups
;
this
.
showPotentialField
=
config
.
showPotentialField
;
this
.
showTargetPotentielFieldMesh
=
config
.
showTargetPotentielFieldMesh
;
this
.
agentColoring
=
config
.
agentColoring
;
}
public
boolean
isShowGroups
()
{
...
...
@@ -262,6 +263,17 @@ public class DefaultSimulationConfig extends DefaultConfig {
}
}
public
void
setAgentColoring
(
final
AgentColoring
agentColoring
)
{
if
(
agentColoring
!=
this
.
agentColoring
)
{
this
.
agentColoring
=
agentColoring
;
setChanged
();
}
}
public
AgentColoring
getAgentColoring
()
{
return
agentColoring
;
}
public
void
clearRandomColors
()
{
randomColors
.
clear
();
}
...
...
@@ -273,14 +285,6 @@ public class DefaultSimulationConfig extends DefaultConfig {
return
randomColors
.
get
(
pedId
);
}
public
void
setUseRandomPedestrianColors
(
final
boolean
useRandomPedestrianColors
)
{
this
.
useRandomPedestrianColors
=
useRandomPedestrianColors
;
}
public
boolean
isUseRandomPedestrianColors
()
{
return
useRandomPedestrianColors
;
}
public
void
setGridWidth
(
double
gridWidth
)
{
this
.
gridWidth
=
gridWidth
;
}
...
...
@@ -305,4 +309,8 @@ public class DefaultSimulationConfig extends DefaultConfig {
this
.
showPedestrianIds
=
showPedestrianIds
;
}
public
boolean
isShowFaydedPedestrians
()
{
return
false
;
}
}
VadereGui/src/org/vadere/gui/components/model/SimulationModel.java
View file @
15cc6e4a
package
org.vadere.gui.components.model
;
import
java.awt.*
;
import
java.util.Collection
;
import
java.util.Random
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.function.Function
;
import
org.jetbrains.annotations.NotNull
;
import
org.vadere.meshing.mesh.gen.PMesh
;
import
org.vadere.meshing.mesh.inter.IMesh
;
import
org.vadere.state.scenario.Agent
;
import
org.vadere.state.scenario.Pedestrian
;
import
org.vadere.util.geometry.shapes.IPoint
;
import
org.vadere.util.geometry.shapes.VRectangle
;
public
abstract
class
SimulationModel
<
T
extends
DefaultSimulationConfig
>
extends
DefaultModel
{
public
final
T
config
;
private
ConcurrentHashMap
<
Integer
,
Color
>
colorMap
;
private
Random
random
;
@SuppressWarnings
(
"unchecked"
)
public
SimulationModel
(
final
T
config
)
{
super
(
config
);
this
.
config
=
config
;
this
.
colorMap
=
new
ConcurrentHashMap
<>();
this
.
colorMap
.
put
(-
1
,
config
.
getPedestrianDefaultColor
());
this
.
random
=
new
Random
();
}
public
abstract
Collection
<
Agent
>
getAgents
();
...
...
@@ -43,6 +53,8 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
return
new
PMesh
();
}
public
abstract
void
setAgentColoring
(
@NotNull
final
AgentColoring
agentColoring
);
/*public double getPotential(final int x, final int y) {
double result = 0.0;
...
...
@@ -83,13 +95,29 @@ public abstract class SimulationModel<T extends DefaultSimulationConfig> extends
return result;
}*/
public
abstract
boolean
isAlive
(
int
pedId
);
public
Color
getGroupColor
(
@NotNull
final
Pedestrian
ped
)
{
if
(
ped
.
getGroupIds
().
isEmpty
()
||
(!
ped
.
getGroupSizes
().
isEmpty
()
&&
ped
.
getGroupSizes
().
getFirst
()
==
1
))
{
return
config
.
getPedestrianDefaultColor
();
}
int
groupId
=
ped
.
getGroupIds
().
getFirst
();
Color
c
=
colorMap
.
get
(
groupId
);
if
(
c
==
null
)
{
c
=
new
Color
(
Color
.
HSBtoRGB
(
random
.
nextFloat
(),
1
f
,
0.75f
));
colorMap
.
put
(
groupId
,
c
);
}
return
c
;
}
@Override
public
synchronized
void
notifyObservers
()
{
// synchronized (config) {
if
(
config
.
hasChanged
())
{
setChanged
();
config
.
clearChange
();
if
(
!
config
.
isUseRandomPedestrianColors
()
)
{
if
(
config
.
getAgentColoring
()
!=
AgentColoring
.
RANDOM
)
{
config
.
clearRandomColors
();
}
}
...
...
VadereGui/src/org/vadere/gui/components/view/SettingsDialog.java
View file @
15cc6e4a
...
...
@@ -5,6 +5,7 @@ import com.jgoodies.forms.layout.CellConstraints;
import
com.jgoodies.forms.layout.FormLayout
;
import
org.jetbrains.annotations.NotNull
;
import
org.vadere.gui.components.control.simulation.*
;
import
org.vadere.gui.components.model.AgentColoring
;
import
org.vadere.gui.components.model.DefaultSimulationConfig
;
import
org.vadere.gui.components.model.SimulationModel
;
import
org.vadere.gui.components.utils.Messages
;
...
...
@@ -21,428 +22,476 @@ import java.util.Optional;
public
class
SettingsDialog
extends
JDialog
{
/**
* The content is usually placed in every second cell (row/column).
* Therefore, increment by two to jump to the next content cell.
*/
public
final
int
NEXT_CELL
=
2
;
private
DefaultSimulationConfig
config
;
private
final
SimulationModel
<?
extends
DefaultSimulationConfig
>
model
;
private
JLayeredPane
colorSettingsPane
;
private
JLayeredPane
otherSettingsPane
;
private
JComboBox
<
Integer
>
jComboTargetIds
;
public
SettingsDialog
(
final
SimulationModel
<?
extends
DefaultSimulationConfig
>
model
)
{
this
.
config
=
model
.
config
;
this
.
model
=
model
;
}
public
JLayeredPane
getColorSettingsPane
()
{
return
colorSettingsPane
;
}
/**
* The settings dialogs consists of several rows:
* 1. Color settings for scenario elements like targets and pedestrians
* 2. Other settings consisting of
* * Visibility checkboxes to control whether scenario elements should be visible
* * Snapshot options (for PNG, SVG and TikZ export)
* 3. Post-visualization options (also called additional options)
* 4. A row containing a close button
*/
public
void
initComponents
()
{
this
.
setTitle
(
Messages
.
getString
(
"SettingsDialog.title"
));
this
.
setDefaultCloseOperation
(
DISPOSE_ON_CLOSE
);
this
.
addWindowListener
(
new
WindowAdapter
()
{
@Override
public
void
windowClosing
(
WindowEvent
e
)
{
new
ActionCloseSettingDialog
(
SettingsDialog
.
this
).
actionPerformed
(
null
);
}
});
JPanel
mainPanel
=
createMainPanel
();
JScrollPane
scrollPane
=
createScrollPane
(
mainPanel
);
colorSettingsPane
=
new
JLayeredPane
();
otherSettingsPane
=
new
JLayeredPane
();
JPanel
closePane
=
createClosePane
();
initColorSettingsPane
(
colorSettingsPane
);
initOtherSettingsPane
(
otherSettingsPane
);
// Note:
// - Form layout indices start from 1 (and not 0)!
// - First cell is a separator.
// - Every second row/column is a cell representing a separator.
// - The first statement increments "row" directly to get to the 2nd content row.
int
row
=
0
;
int
column
=
2
;
CellConstraints
cc
=
new
CellConstraints
();
mainPanel
.
add
(
colorSettingsPane
,
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
mainPanel
.
add
(
otherSettingsPane
,
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
mainPanel
.
add
(
getAdditionalOptionPanel
(),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
mainPanel
.
add
(
closePane
,
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
scrollPane
.
setPreferredSize
(
new
Dimension
(
mainPanel
.
getPreferredSize
().
width
+
10
,
Math
.
min
(
mainPanel
.
getPreferredSize
().
height
,
Toolkit
.
getDefaultToolkit
().
getScreenSize
().
height
-
50
)));
pack
();
setResizable
(
true
);
SwingUtils
.
centerComponent
(
this
);
setVisible
(
true
);
}
@NotNull
private
JPanel
createMainPanel
()
{
JPanel
mainPanel
=
new
JPanel
();
FormLayout
mainLayout
=
new
FormLayout
(
"5dlu, [300dlu,pref,600dlu], 5dlu"
,
// cols
createCellsWithSeparators
(
4
));
// rows
mainPanel
.
setLayout
(
mainLayout
);
return
mainPanel
;
}
@NotNull
private
JScrollPane
createScrollPane
(
JPanel
mainPanel
)
{
JScrollPane
scrollPane
=
new
JScrollPane
(
mainPanel
);
scrollPane
.
setHorizontalScrollBarPolicy
(
JScrollPane
.
HORIZONTAL_SCROLLBAR_NEVER
);
scrollPane
.
setVerticalScrollBarPolicy
(
JScrollPane
.
VERTICAL_SCROLLBAR_AS_NEEDED
);
getContentPane
().
add
(
scrollPane
);
return
scrollPane
;
}
private
JPanel
createClosePane
()
{
JPanel
closePane
=
new
JPanel
();
closePane
.
setLayout
(
new
FlowLayout
(
FlowLayout
.
RIGHT
));
JButton
closeButton
=
new
JButton
(
Messages
.
getString
(
"SettingsDialog.btnClose.text"
));
closeButton
.
addActionListener
(
new
ActionCloseSettingDialog
(
this
));
closePane
.
add
(
closeButton
);
return
closePane
;
}
private
void
initColorSettingsPane
(
JLayeredPane
colorSettingsPane
){
colorSettingsPane
.
setBorder
(
BorderFactory
.
createTitledBorder
(
Messages
.
getString
(
"SettingsDialog.colors.border.text"
)));
FormLayout
colorSettingsLayout
=
new
FormLayout
(
"5dlu, pref, 2dlu, pref:grow, 2dlu, pref, 2dlu, pref, 5dlu"
,
// col
createCellsWithSeparators
(
18
));
// rows
colorSettingsPane
.
setLayout
(
colorSettingsLayout
);
// For each scenario element, add a color preview canvas and a button to change the color.
int
row
=
0
;
int
column
=
2
;
CellConstraints
cc
=
new
CellConstraints
();
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblObstacle.text"
)
+
":"
),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblTarget.text"
)
+
":"
),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblSource.text"
)
+
":"
),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblStair.text"
)
+
":"
),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblDensityColor.text"
)
+
":"
),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblAbsorbingAreaColor.text"
)
+
":"
),
cc
.
xy
(
column
,
row
+=
NEXT_CELL
));
createColorCanvasesAndChangeButtonsOnPane
(
colorSettingsPane
);
// Add options to colorize pedestrians based on different strategies (by target, evacuation time, randomly, ...=
// By target id:
colorSettingsPane
.
add
(
new
JSeparator
(),
cc
.
xyw
(
1
,
row
+=
NEXT_CELL
,
9
));
colorSettingsPane
.
add
(
new
JLabel
(
Messages
.
getString
(
"SettingsDialog.lblPedTrajColor.text"
)
+
":"
),
cc
.
xyw
(
column
,
row
+=
NEXT_CELL
,
5
));
jComboTargetIds
=
createTargetIdsComboBoxAndAddIds
();
jComboTargetIds
.
setSelectedIndex
(
0
);
final
JButton
bChange
=
new
JButton
(
Messages
.
getString
(
"SettingsDialog.btnEditColor.text"
));
final
JPanel
pPedestrian
=
new
JPanel
();
Integer
selectedTargetIdOuter
=
jComboTargetIds
.
getItemAt
(
jComboTargetIds
.
getSelectedIndex
());
if
(
selectedTargetIdOuter
==
null
)
{
selectedTargetIdOuter
=
1
;
}
Optional
<
Color
>
colorByTargetId
=
model
.
config
.
getColorByTargetId
(
selectedTargetIdOuter
);
pPedestrian
.
setBackground
(
colorByTargetId
.
orElseGet
(()
->
model
.
config
.
getPedestrianDefaultColor
()));
pPedestrian
.
setPreferredSize
(
new
Dimension
(
130
,
20
));
// When user changes a color, save it in the model.
bChange
.
addActionListener
(
new
ActionSetPedestrianColor
(
"Set Pedestrian Color"
,
model
,
pPedestrian
,
jComboTargetIds
));