Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
6ad7eebb
Commit
6ad7eebb
authored
Jun 08, 2018
by
Benedikt Zoennchen
Browse files
issue fix
#73
(internationalization of the data processor tab),
#72
(simple polygon drawing).
parent
46d652c9
Pipeline
#56818
passed with stage
in 45 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereGui/resources/icons/convexHull.png
0 → 100644
View file @
6ad7eebb
556 Bytes
VadereGui/resources/icons/simplePolygon.png
0 → 100644
View file @
6ad7eebb
514 Bytes
VadereGui/resources/messages.properties
View file @
6ad7eebb
...
...
@@ -35,9 +35,29 @@ NewProjectName.title=New Project
NewTestError.text
=
Error while adding a new scenario.
NewTestError.title
=
Error
DataProcessingView.msgInvalidJson
=
Invalid json
DataProcessingView.msgShowError
=
Show error message
DataProcessingView.chbAddTimeStamp
=
Add timestamp to output folder
DataProcessingView.btnAdd
=
Add
DataProcessingView.btnDelete
=
Delete
DataProcessingView.msgFileSelected
=
No output file selected.
DataProcessingView.files.label
=
Files
DataProcessingView.dialogChoseProcessor.label
=
Choose data processor
DataProcessingView.dialogProcessors.label
=
Processors
DataProcessingView.dialogOutputFileSelection.label
=
File name
DataProcessingView.msgFileEmpty
=
File name can't be empty
DataProcessingView.msgFileInUse
=
File name is already in use
DataProcessingView.dialogInvalidFile.label
=
Invalid file name
DataProcessingView.dialogOutputDataKeySelection.label
=
Data Key
DataProcessingView.dialogOutputHeaderSelection.label
=
Header
ProgressPanelDone.text
=
Done
ProgressPanelWorking.text
=
Working...
ProjectView.gui
=
gui
ProjectView.json
=
json
ProjectView.OutputTable.label
=
Output files
ProjectView.JSONSwitch.link
=
<u>switch to <b>{0}</b> mode</u>
ProjectView.JSONDisplay.label
=
Nothing selected
ProjectView.btnAbout.tooltip
=
About
ProjectView.about.title
=
About
ProjectView.title
=
Vadere
...
...
@@ -260,6 +280,11 @@ TopographyCreator.btnInsertTarget.tooltip=Target
TopographyCreator.btnInsertSource.tooltip
=
Source
TopographyCreator.btnInsertStairs.tooltip
=
Stairs
TopographyCreator.btnErase.tooltip
=
Eraser
TopographyCreator.btnConvexHull.label
=
Convex Hull
TopographyCreator.btnSimplePolygon.label
=
Simple Polygon
TopographyCreator.btnCircle.label
=
Circle
TopographyCreator.btnRectangle.label
=
Rectangle
select_shape_tooltip
=
Select Shape
# tab titles Topography creator / postvis
...
...
@@ -273,7 +298,7 @@ Tab.Model.insertModelNameMenu.title=Insert model name
Tab.Model.insertModelNameSubMenu.title
=
Main models
Tab.Pedestrians.title
=
Pedestrians
Tab.Topography.title
=
Topography
Tab.OutputProcessors.title
=
Data processing
Tab.OutputProcessors.title
=
Data processing
GUI
Tab.TopographyCreator.title
=
Topography creator
Tab.PostVisualization.title
=
Post-Visualization
...
...
VadereGui/resources/messages_de_DE.properties
View file @
6ad7eebb
...
...
@@ -35,9 +35,30 @@ NewProjectName.title=Neues Projekt
NewTestError.text
=
Fehler beim erstellen eines neuen Szenarios
NewTestError.title
=
Fehler.
DataProcessingView.msgInvalidJson
=
Fehlerhaftes JSON
DataProcessingView.msgShowError
=
Zeige Fehlermeldung
DataProcessingView.chbAddTimeStamp
=
F
\u
00FCge Zeitstempel zu Ausgabeordner
DataProcessingView.btnAdd
=
Hinzuf
\u
00FCgen
DataProcessingView.btnDelete
=
L
\u
00F6schen
DataProcessingView.msgFileSelected
=
Keine Ausgabedatei ist ausgew
\u
00E4hlt
DataProcessingView.files.label
=
Dateien
DataProcessingView.dialogChoseProcessor.label
=
W
\u
00E4hle Prozessor
DataProcessingView.dialogProcessors.label
=
Prozessoren
DataProcessingView.dialogOutputFileSelection.label
=
Dateiname
DataProcessingView.msgFileEmpty
=
Datei darf nicht leer sein
DataProcessingView.msgFileInUse
=
Dateiname bereits vorhanden
DataProcessingView.dialogInvalidFile.label
=
Ung
\u
00FCltiger Dateiname
DataProcessingView.dialogOutputDataKeySelection.label
=
Rubrik
DataProcessingView.dialogOutputHeaderSelection.label
=
Kopfzeile
ProgressPanelDone.text
=
Fertig
ProgressPanelWorking.text
=
Arbeite...
ProjectView.OutputTable.label
=
Ausgabedateien
ProjectView.gui
=
GUI
ProjectView.json
=
JSON
ProjectView.JSONSwitch.link
=
<u>Wechsle zum <b>{0}</b> Modus</u>
ProjectView.JSONDisplay.label
=
Keine Auswahl
ProjectView.btnAbout.tooltip
=
\u
00dcber
ProjectView.about.title
=
\u
00dcber
ProjectView.title
=
Vadere
...
...
@@ -260,6 +281,10 @@ TopographyCreator.btnInsertSource.tooltip=Quelle
TopographyCreator.btnInsertStairs.tooltip
=
Treppen
TopographyCreator.btnErase.tooltip
=
Radierer
select_shape_tooltip
=
Form ausw
\u
00e4hlen
TopographyCreator.btnConvexHull.label
=
Convexe H
\u
00fclle
TopographyCreator.btnSimplePolygon.label
=
Einfaches Polygon
TopographyCreator.btnCircle.label
=
Kreis
TopographyCreator.btnRectangle.label
=
Rechteck
# tab titles Topography creator / postvis
Tab.Simulation.title
=
Simulation
...
...
VadereGui/src/org/vadere/gui/projectview/model/OutputFileTableModel.java
View file @
6ad7eebb
...
...
@@ -3,6 +3,7 @@ package org.vadere.gui.projectview.model;
import
java.io.File
;
import
java.util.List
;
import
org.vadere.gui.components.utils.Messages
;
import
org.vadere.simulator.projects.VadereProject
;
import
org.vadere.simulator.projects.io.IOOutput
;
...
...
@@ -11,7 +12,7 @@ public class OutputFileTableModel extends VadereTableModelSorted<File> {
private
static
final
long
serialVersionUID
=
134253986682827818L
;
OutputFileTableModel
()
{
super
(
new
String
[]
{
"Output files"
},
0
,
(
f1
,
f2
)
->
f1
.
getName
().
compareTo
(
f2
.
getName
()));
super
(
new
String
[]
{
Messages
.
getString
(
"ProjectView.OutputTable.label"
)
},
0
,
(
f1
,
f2
)
->
f1
.
getName
().
compareTo
(
f2
.
getName
()));
}
@Override
...
...
VadereGui/src/org/vadere/gui/projectview/view/DataProcessingView.java
View file @
6ad7eebb
...
...
@@ -18,6 +18,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashSet
;
...
...
@@ -65,6 +66,7 @@ import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile;
import
org.vadere.simulator.projects.dataprocessing.processor.DataProcessor
;
import
org.vadere.simulator.projects.dataprocessing.store.DataProcessorStore
;
import
org.vadere.simulator.projects.dataprocessing.store.OutputFileStore
;
import
org.vadere.simulator.projects.io.HashGenerator
;
import
org.vadere.state.util.StateJsonConverter
;
import
org.vadere.util.io.IOUtils
;
...
...
@@ -81,8 +83,8 @@ class DataProcessingView extends JPanel implements IJsonView {
private
IJsonView
activeJsonView
;
// gui-mode or expert-mode
private
JLabel
switchJsonViewModeLabel
=
new
JLabel
();
private
JPanel
viewPanel
;
// hosts the gui-panel or the expert-panel
private
static
final
String
guiViewMode
=
"
gui"
;
private
static
final
String
jsonViewMode
=
"
json"
;
private
static
final
String
guiViewMode
=
Messages
.
getString
(
"ProjectView.
gui"
)
;
private
static
final
String
jsonViewMode
=
Messages
.
getString
(
"ProjectView.
json"
)
;
private
boolean
inGuiViewMode
=
true
;
private
Scenario
currentScenario
;
...
...
@@ -113,9 +115,9 @@ class DataProcessingView extends JPanel implements IJsonView {
}
private
void
switchMode
()
{
String
link
=
MessageFormat
.
format
(
Messages
.
getString
(
"ProjectView.JSONSwitch.link"
),
(
inGuiViewMode
?
jsonViewMode
:
guiViewMode
));
switchJsonViewModeLabel
.
setText
(
"<html><span style='font-size:8px'><font color='blue'>"
+
"<u>switch to <b>"
+
(
inGuiViewMode
?
jsonViewMode
:
guiViewMode
)
+
"</b> mode</u></font></span></html>"
);
link
+
"</font></span></html>"
);
Preferences
.
userNodeForPackage
(
DataProcessingView
.
class
).
put
(
"dataProcessingViewMode"
,
inGuiViewMode
?
guiViewMode
:
jsonViewMode
);
viewPanel
.
removeAll
();
...
...
@@ -226,7 +228,7 @@ class DataProcessingView extends JPanel implements IJsonView {
JPanel
filesPanel
=
new
JPanel
();
filesPanel
.
setLayout
(
new
BoxLayout
(
filesPanel
,
BoxLayout
.
PAGE_AXIS
));
isTimestampedCheckBox
=
new
JCheckBox
(
"
Add
t
ime
s
tamp
to output folder
"
);
isTimestampedCheckBox
=
new
JCheckBox
(
Messages
.
getString
(
"DataProcessingView.chb
Add
T
ime
S
tamp"
)
);
isTimestampedCheckBox
.
addActionListener
(
new
AbstractAction
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
...
...
@@ -237,7 +239,7 @@ class DataProcessingView extends JPanel implements IJsonView {
addEditableComponent
(
isTimestampedCheckBox
);
filesPanel
.
add
(
isTimestampedCheckBox
);
JButton
addFileBtn
=
new
JButton
(
new
AbstractAction
(
"
Add"
)
{
JButton
addFileBtn
=
new
JButton
(
new
AbstractAction
(
Messages
.
getString
(
"DataProcessingView.btn
Add"
)
)
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
...
...
@@ -255,11 +257,12 @@ class DataProcessingView extends JPanel implements IJsonView {
refreshGUI
();
}
});
deleteFileBtn
=
new
JButton
(
new
AbstractAction
(
"
Delete"
)
{
deleteFileBtn
=
new
JButton
(
new
AbstractAction
(
Messages
.
getString
(
"DataProcessingView.btn
Delete"
)
)
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
selectedOutputFile
==
null
)
{
JOptionPane
.
showMessageDialog
(
ProjectView
.
getMainWindow
(),
"No output file selected."
);
JOptionPane
.
showMessageDialog
(
ProjectView
.
getMainWindow
(),
Messages
.
getString
(
"DataProcessingView.msgFileSelected"
));
}
else
{
currentScenario
.
getDataProcessingJsonManager
().
getOutputFiles
().
remove
(
selectedOutputFile
);
selectedOutputFile
=
null
;
...
...
@@ -274,18 +277,18 @@ class DataProcessingView extends JPanel implements IJsonView {
setupTables
();
JPanel
filesTable
=
buildPanel
(
"Files"
,
outputFilesTable
,
addFileBtn
,
deleteFileBtn
);
JPanel
filesTable
=
buildPanel
(
Messages
.
getString
(
"DataProcessingView.files.label"
)
,
outputFilesTable
,
addFileBtn
,
deleteFileBtn
);
filesTable
.
setAlignmentX
(
Component
.
LEFT_ALIGNMENT
);
filesPanel
.
add
(
filesTable
);
tableSide
.
add
(
filesPanel
);
JButton
addProcessorBtn
=
new
JButton
(
new
AbstractAction
(
"
Add"
)
{
JButton
addProcessorBtn
=
new
JButton
(
new
AbstractAction
(
Messages
.
getString
(
"DataProcessingView.btn
Add"
)
)
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
Map
<
String
,
Class
>
processorNameToClass
=
ClassFinder
.
getProcessorClassesWithNames
();
JComboBox
processorOptions
=
new
JComboBox
<>(
processorNameToClass
.
keySet
().
toArray
());
if
(
JOptionPane
.
showConfirmDialog
(
ProjectView
.
getMainWindow
(),
processorOptions
,
"Choose data processor"
,
JOptionPane
.
OK_CANCEL_OPTION
)
==
JOptionPane
.
OK_OPTION
)
{
Messages
.
getString
(
"DataProcessingView.dialogChoseProcessor.label"
)
,
JOptionPane
.
OK_CANCEL_OPTION
)
==
JOptionPane
.
OK_OPTION
)
{
try
{
DataProcessor
newDataProcessor
=
(
DataProcessor
)
processorNameToClass
.
get
(
processorOptions
.
getSelectedItem
()).
newInstance
();
newDataProcessor
.
setId
(
currentScenario
.
getDataProcessingJsonManager
().
getMaxProcessorsId
()
+
1
);
...
...
@@ -300,11 +303,11 @@ class DataProcessingView extends JPanel implements IJsonView {
refreshGUI
();
}
});
deleteProcessorBtn
=
new
JButton
(
new
AbstractAction
(
"
Delete"
)
{
deleteProcessorBtn
=
new
JButton
(
new
AbstractAction
(
Messages
.
getString
(
"DataProcessingView.btn
Delete"
)
)
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
selectedDataProcessor
==
null
)
{
JOptionPane
.
showMessageDialog
(
ProjectView
.
getMainWindow
(),
"No d
ata
p
rocess
or s
elected
.
"
);
JOptionPane
.
showMessageDialog
(
ProjectView
.
getMainWindow
(),
Messages
.
getString
(
"D
ata
P
rocess
ingView.msgFileS
elected"
)
);
}
else
{
Integer
id
=
selectedDataProcessor
.
getId
();
currentScenario
.
getDataProcessingJsonManager
().
getDataProcessors
().
remove
(
selectedDataProcessor
);
...
...
@@ -322,7 +325,7 @@ class DataProcessingView extends JPanel implements IJsonView {
}
}
});
tableSide
.
add
(
buildPanel
(
"Processors"
,
dataProcessorsTable
,
addProcessorBtn
,
deleteProcessorBtn
));
tableSide
.
add
(
buildPanel
(
Messages
.
getString
(
"DataProcessingView.dialogProcessors.label"
)
,
dataProcessorsTable
,
addProcessorBtn
,
deleteProcessorBtn
));
// right details side
...
...
@@ -489,7 +492,7 @@ class DataProcessingView extends JPanel implements IJsonView {
c
.
gridx
=
0
;
c
.
gridy
=
0
;
panel
.
add
(
new
JLabel
(
"File name
:"
),
c
);
panel
.
add
(
new
JLabel
(
Messages
.
getString
(
"DataProcessingView.dialogOutputFileSelection.label"
)+
"
:"
),
c
);
c
.
gridx
=
1
;
c
.
gridy
=
0
;
...
...
@@ -500,10 +503,10 @@ class DataProcessingView extends JPanel implements IJsonView {
if
(!
oldName
.
equals
(
newName
))
{
String
msg
=
""
;
if
(
newName
.
isEmpty
())
{
msg
=
"File name can't be e
mpty"
;
msg
=
Messages
.
getString
(
"DataProcessingView.msgFileE
mpty"
)
;
}
if
(
outputFileNameAlreadyExists
(
newName
))
{
msg
=
"File name is already in u
se"
;
msg
=
Messages
.
getString
(
"DataProcessingView.msgFileInU
se"
)
;
}
if
(
msg
.
isEmpty
())
{
outputFile
.
setRelativeFileName
(
newName
);
...
...
@@ -512,7 +515,7 @@ class DataProcessingView extends JPanel implements IJsonView {
}
else
{
nameField
.
setText
(
oldName
);
JOptionPane
.
showMessageDialog
(
ProjectView
.
getMainWindow
(),
msg
,
"
Invalid
f
ile
name"
,
JOptionPane
.
WARNING_MESSAGE
);
Messages
.
getString
(
"DataProcessingView.dialog
Invalid
F
ile
.label"
)
,
JOptionPane
.
WARNING_MESSAGE
);
}
}
passFocusOn
();
...
...
@@ -522,7 +525,7 @@ class DataProcessingView extends JPanel implements IJsonView {
c
.
gridx
=
0
;
c
.
gridy
=
1
;
panel
.
add
(
new
JLabel
(
"Data key:"
),
c
);
panel
.
add
(
new
JLabel
(
Messages
.
getString
(
"DataProcessingView.dialogOutputDataKeySelection.label"
)
),
c
);
c
.
gridx
=
1
;
c
.
gridy
=
1
;
...
...
@@ -549,7 +552,7 @@ class DataProcessingView extends JPanel implements IJsonView {
c
.
gridx
=
0
;
c
.
gridy
=
2
;
panel
.
add
(
new
JLabel
(
"Header
:"
),
c
);
panel
.
add
(
new
JLabel
(
Messages
.
getString
(
"DataProcessingView.dialogOutputHeaderSelection.label"
)+
"
:"
),
c
);
c
.
gridx
=
1
;
c
.
gridy
=
2
;
...
...
@@ -557,7 +560,7 @@ class DataProcessingView extends JPanel implements IJsonView {
c
.
gridx
=
0
;
c
.
gridy
=
3
;
panel
.
add
(
new
JLabel
(
"Processors
:"
),
c
);
panel
.
add
(
new
JLabel
(
Messages
.
getString
(
"DataProcessingView.dialogProcessors.label"
)+
"
:"
),
c
);
c
.
gridx
=
1
;
c
.
gridy
=
3
;
...
...
@@ -602,7 +605,7 @@ class DataProcessingView extends JPanel implements IJsonView {
c
.
gridx
=
0
;
c
.
gridy
=
1
;
panel
.
add
(
new
JLabel
(
"DataKey
:"
),
c
);
panel
.
add
(
new
JLabel
(
Messages
.
getString
(
"DataProcessingView.dialogOutputDataKeySelection.label"
)+
"
:"
),
c
);
c
.
gridx
=
1
;
c
.
gridy
=
1
;
...
...
@@ -611,7 +614,8 @@ class DataProcessingView extends JPanel implements IJsonView {
c
.
gridx
=
2
;
c
.
gridy
=
1
;
c
.
anchor
=
GridBagConstraints
.
EAST
;
JLabel
jsonInvalidLabel
=
new
JLabel
(
"<html><font color='red'>invalid json</font> <font color=gray size=-2><a href=#>show error</a></font></html>"
);
JLabel
jsonInvalidLabel
=
new
JLabel
(
"<html><font color='red'>"
+
Messages
.
getString
(
"DataProcessingView.msgInvalidJson"
)+
"</font> <font color=gray size=-2><a href=#>"
+
Messages
.
getString
(
"DataProcessingView.msgShowError"
)+
"</a></font></html>"
);
jsonInvalidLabel
.
addMouseListener
(
new
MouseAdapter
()
{
@Override
public
void
mouseReleased
(
MouseEvent
e
)
{
...
...
VadereGui/src/org/vadere/gui/projectview/view/ScenarioPanel.java
View file @
6ad7eebb
...
...
@@ -182,7 +182,7 @@ public class ScenarioPanel extends JPanel implements IProjectChangeListener, Pro
topographyFileView
=
new
TextView
(
"/scenarios"
,
"default_directory_scenarios"
,
AttributeType
.
TOPOGRAPHY
);
tabbedPane
.
addTab
(
Messages
.
getString
(
"Tab.Topography.title"
),
topographyFileView
);
dataProcessingGUIview
=
new
DataProcessingView
();
tabbedPane
.
addTab
(
"Data processing GUI"
,
dataProcessingGUIview
);
tabbedPane
.
addTab
(
Messages
.
getString
(
"Tab.OutputProcessors.title"
)
,
dataProcessingGUIview
);
// online visualization card...
JPanel
visualizationCard
=
new
JPanel
();
...
...
VadereGui/src/org/vadere/gui/topographycreator/control/Draw
Polygon
Mode.java
→
VadereGui/src/org/vadere/gui/topographycreator/control/Draw
ConvexHull
Mode.java
View file @
6ad7eebb
...
...
@@ -21,7 +21,7 @@ import org.vadere.util.geometry.shapes.VPolygon;
*
*
*/
public
class
Draw
Polygon
Mode
extends
DefaultSelectionMode
{
public
class
Draw
ConvexHull
Mode
extends
DefaultSelectionMode
{
enum
DrawPathState
{
START
,
ADD
...
...
@@ -35,7 +35,7 @@ public class DrawPolygonMode extends DefaultSelectionMode {
private
final
IDrawPanelModel
panelModel
;
private
final
List
<
VPoint
>
pointList
;
public
Draw
Polygon
Mode
(
final
IDrawPanelModel
panelModel
,
final
UndoableEditSupport
undoSupport
)
{
public
Draw
ConvexHull
Mode
(
final
IDrawPanelModel
panelModel
,
final
UndoableEditSupport
undoSupport
)
{
super
(
panelModel
);
this
.
panelModel
=
panelModel
;
this
.
undoSupport
=
undoSupport
;
...
...
@@ -162,6 +162,6 @@ public class DrawPolygonMode extends DefaultSelectionMode {
@Override
public
IMode
clone
()
{
return
new
Draw
Polygon
Mode
(
panelModel
,
undoSupport
);
return
new
Draw
ConvexHull
Mode
(
panelModel
,
undoSupport
);
}
}
VadereGui/src/org/vadere/gui/topographycreator/control/DrawSimplePolygonMode.java
0 → 100644
View file @
6ad7eebb
package
org.vadere.gui.topographycreator.control
;
import
org.vadere.gui.components.control.DefaultSelectionMode
;
import
org.vadere.gui.components.control.IMode
;
import
org.vadere.gui.topographycreator.model.IDrawPanelModel
;
import
org.vadere.util.geometry.shapes.VLine
;
import
org.vadere.util.geometry.shapes.VPoint
;
import
org.vadere.util.geometry.shapes.VPolygon
;
import
java.awt.event.MouseEvent
;
import
java.awt.geom.Line2D
;
import
java.awt.geom.Path2D
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.swing.*
;
import
javax.swing.undo.UndoableEditSupport
;
/**
* In this mode VPolygons will be generated.
*
*
*/
public
class
DrawSimplePolygonMode
extends
DefaultSelectionMode
{
enum
DrawPathState
{
START
,
ADD
}
private
final
UndoableEditSupport
undoSupport
;
private
Path2D
.
Double
path
;
private
Line2D
.
Double
line
;
private
DrawPathState
state
=
DrawPathState
.
START
;
private
int
lineCount
=
0
;
private
final
IDrawPanelModel
panelModel
;
private
final
List
<
VPoint
>
pointList
;
public
DrawSimplePolygonMode
(
final
IDrawPanelModel
panelModel
,
final
UndoableEditSupport
undoSupport
)
{
super
(
panelModel
);
this
.
panelModel
=
panelModel
;
this
.
undoSupport
=
undoSupport
;
this
.
pointList
=
new
ArrayList
<>();
// panelModel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}
@Override
public
void
mouseDragged
(
MouseEvent
event
)
{
if
(
SwingUtilities
.
isRightMouseButton
(
event
)
&&
state
==
DrawPathState
.
START
)
{
super
.
mouseDragged
(
event
);
}
else
{
mouseMoved
(
event
);
}
}
@Override
public
void
mousePressed
(
final
MouseEvent
event
)
{
if
(
SwingUtilities
.
isRightMouseButton
(
event
)
&&
state
==
DrawPathState
.
START
)
{
super
.
mousePressed
(
event
);
}
}
@Override
public
void
mouseReleased
(
final
MouseEvent
event
)
{
if
(
SwingUtilities
.
isRightMouseButton
(
event
)
&&
state
==
DrawPathState
.
START
)
{
super
.
mouseReleased
(
event
);
}
}
@Override
public
void
mouseClicked
(
final
MouseEvent
event
)
{
if
(!
SwingUtilities
.
isRightMouseButton
(
event
))
{
if
(
SwingUtilities
.
isLeftMouseButton
(
event
))
{
if
(
event
.
getClickCount
()
<=
1
&&
state
==
DrawPathState
.
START
)
{
// add the first point
panelModel
.
setMousePosition
(
event
.
getPoint
());
panelModel
.
setStartSelectionPoint
(
event
.
getPoint
());
path
=
new
Path2D
.
Double
(
Path2D
.
WIND_NON_ZERO
);
path
.
moveTo
(
panelModel
.
getMousePosition
().
x
,
panelModel
.
getMousePosition
().
y
);
path
.
lineTo
(
panelModel
.
getMousePosition
().
x
,
panelModel
.
getMousePosition
().
y
);
line
=
new
VLine
(
panelModel
.
getMousePosition
().
x
,
panelModel
.
getMousePosition
().
y
,
panelModel
.
getMousePosition
().
x
,
panelModel
.
getMousePosition
().
y
);
/*
* panelModel.addShape(ScenarioShapeFactory.getInstance().createScenarioShape(
* panelModel.getCurrentType(), new VPolygon(path)));
*/
panelModel
.
setSelectionShape
(
new
VPolygon
(
path
));
pointList
.
add
(
panelModel
.
getMousePosition
());
state
=
DrawPathState
.
ADD
;
panelModel
.
showSelection
();
}
else
if
(
event
.
getClickCount
()
<=
1
&&
state
==
DrawPathState
.
ADD
)
{
// add a new line
if
(
lineCount
<=
1
||
isValidNextPoint
(
new
VPoint
(
line
.
x2
,
line
.
y2
)))
{
path
.
lineTo
(
line
.
x2
,
line
.
y2
);
pointList
.
add
(
new
VPoint
(
line
.
x2
,
line
.
y2
));
if
(
lineCount
<=
1
)
{
// dirty trick to see the first line!
VPolygon
poly
=
new
VPolygon
(
path
);
poly
.
moveTo
(
line
.
x2
,
line
.
y2
+
0.0001
*
panelModel
.
getScaleFactor
());
panelModel
.
setSelectionShape
(
poly
);
}
else
{
panelModel
.
setSelectionShape
(
new
VPolygon
(
path
));
}
line
=
new
Line2D
.
Double
(
panelModel
.
getMousePosition
().
x
,
panelModel
.
getMousePosition
().
y
,
panelModel
.
getMousePosition
().
x
,
panelModel
.
getMousePosition
().
y
);
panelModel
.
showSelection
();
lineCount
++;
}
}
else
{
// finish the draw
panelModel
.
hideSelection
();
if
(
lineCount
<=
1
)
{
// panelModel.deleteLastShape();
}
else
{
path
.
closePath
();
VPolygon
polygon
=
new
VPolygon
(
path
);
panelModel
.
setSelectionShape
(
polygon
);
if
(
isSimplePolygon
(
pointList
))
{
new
ActionAddElement
(
"add element"
,
panelModel
,
undoSupport
).
actionPerformed
(
null
);
}
panelModel
.
notifyObservers
();
}
state
=
DrawPathState
.
START
;
lineCount
=
0
;
pointList
.
clear
();
}
}
else
{
if
(
state
==
DrawPathState
.
ADD
)
{
panelModel
.
hideSelection
();
state
=
DrawPathState
.
START
;
lineCount
=
0
;
}
}
panelModel
.
notifyObservers
();
}
}
// this can be done more efficiently by: http://geomalgorithms.com/a09-_intersect-3.html#simple_Polygon()
private
boolean
isSimplePolygon
(
final
List
<
VPoint
>
pointList
)
{
for
(
int
i
=
0
;
i
<
pointList
.
size
();
i
++)
{
VPoint
p1
=
pointList
.
get
(
i
%
pointList
.
size
());
VPoint
p2
=
pointList
.
get
((
i
+
1
)
%
pointList
.
size
());
VPoint
pref
=
pointList
.
get
((
i
+
pointList
.
size
()
-
1
)
%
pointList
.
size
());
VPoint
next
=
pointList
.
get
((
i
+
2
)
%
pointList
.
size
());
if
(
pref
.
equals
(
p1
)
||
next
.
equals
(
p2
))
{
return
false
;
}
VLine
line
=
new
VLine
(
p1
,
p2
);
for
(
int
j
=
0
;
j
<
pointList
.
size
()-
3
;
j
++)
{
VPoint
q1
=
pointList
.
get
((
i
+
2
+
j
)
%
pointList
.
size
());
VPoint
q2
=
pointList
.
get
((
i
+
2
+
j
+
1
)
%
pointList
.
size
());
if
(
line
.
intersectsLine
(
new
VLine
(
q1
,
q2
)))
{
return
false
;
}
}
}
return
true
;
}
// this can be done more efficiently by: http://geomalgorithms.com/a09-_intersect-3.html#simple_Polygon()
private
boolean
isValidNextPoint
(
final
VPoint
point
)
{
if
(
pointList
.
size
()
==
1
)
{
return
!
point
.
equals
(
pointList
.
get
(
pointList
.
size
()-
1
));
}
else
if
(
pointList
.
size
()
>=
2
)
{
VLine
line
=
new
VLine
(
pointList
.
get
(
pointList
.
size
()-
1
),
point
);
if
(
point
.
equals
(
pointList
.
get
(
pointList
.
size
()-
1
))
||
point
.
equals
(
pointList
.
get
(
pointList
.
size
()-
2
)))
{
return
false
;
}
for
(
int
i
=
0
;
i
<
pointList
.
size
()-
2
;
i
++)
{
VPoint
p1
=
pointList
.
get
(
i
);
VPoint
p2
=
pointList
.
get
(
i
+
1
);
if
(
line
.
intersectsLine
(
new
VLine
(
p1
,
p2
)))
{
return
false
;
}
}
}
return
true
;
}
@Override
public
void
mouseMoved
(
MouseEvent
e
)
{
super
.
mouseMoved
(
e
);
if
(
state
==
DrawPathState
.
ADD
)
{
VPoint
cursorPosition
=
panelModel
.
getMousePosition
();
line
.
x2
=
cursorPosition
.
x
;
line
.
y2
=
cursorPosition
.
y
;
/*if (pointList.size() >= 2) {
List<VPoint> cloneList = new ArrayList<>(pointList);
cloneList.add(new VPoint(line.x2, line.y2));
GrahamScan scan = new GrahamScan(cloneList);
panelModel.setSelectionShape(scan.getPolytope());
} else {*/
VPolygon
poly
=
new
VPolygon
(
path
);
poly
.
append
(
line
,
false
);
// poly.lineTo(line.x2, line.y2);
panelModel
.
setSelectionShape
(
poly
);
//}
}
}
@Override
public
IMode
clone
()
{
return
new
DrawSimplePolygonMode
(
panelModel
,
undoSupport
);
}
}
VadereGui/src/org/vadere/gui/topographycreator/view/JLabelObserver.java
View file @
6ad7eebb
...
...
@@ -5,12 +5,13 @@ import java.util.Observer;
import
javax.swing.JLabel
;
import
org.vadere.gui.components.utils.Messages
;
import
org.vadere.gui.topographycreator.model.IDrawPanelModel
;
import
org.vadere.state.scenario.ScenarioElement
;
public
class
JLabelObserver
extends
JLabel
implements
Observer
{
public
static
final
String
DEFAULT_TEXT
=
"Nothing selected"
;
public
static
final
String
DEFAULT_TEXT
=
Messages
.
getString
(
"ProjectView.JSONDisplay.label"
)
;
private
static
final
long
serialVersionUID
=
9011952047793438028L
;
private
IDrawPanelModel
panelModel
;
...
...
VadereGui/src/org/vadere/gui/topographycreator/view/TopographyWindow.java
View file @
6ad7eebb
...
...
@@ -32,7 +32,8 @@ import org.vadere.gui.topographycreator.control.ActionUndo;