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
28c0fe3a
Commit
28c0fe3a
authored
Mar 26, 2019
by
Stefan Schuhbaeck
Browse files
fix
#225
. Keep dialog open after csv export.
parent
1a26f9ef
Pipeline
#100634
passed with stages
in 135 minutes and 32 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereGui/src/org/vadere/gui/projectview/view/ProjectRunResultDialog.java
View file @
28c0fe3a
...
...
@@ -10,7 +10,6 @@ import org.vadere.util.logging.Logger;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
...
...
@@ -22,130 +21,123 @@ import java.util.LinkedList;
import
javax.swing.*
;
public
class
ProjectRunResultDialog
implements
ProjectFinishedListener
{
private
static
Logger
logger
=
Logger
.
getLogger
(
ProjectRunResultDialog
.
class
);
private
final
ProjectView
projectView
;
private
final
ProjectViewModel
projectViewModel
;
private
static
Logger
logger
=
Logger
.
getLogger
(
ProjectRunResultDialog
.
class
);
private
final
ProjectView
projectView
;
private
final
ProjectViewModel
projectViewModel
;
ProjectRunResultDialog
(
ProjectView
projectView
,
ProjectViewModel
projectViewModel
)
{
this
.
projectView
=
projectView
;
this
.
projectViewModel
=
projectViewModel
;
}
public
ProjectRunResultDialog
(
ProjectView
projectView
,
ProjectViewModel
projectViewModel
)
{
this
.
projectView
=
projectView
;
this
.
projectViewModel
=
projectViewModel
;
}
@Override
public
void
preProjectRun
(
VadereProject
project
)
{
}
@Override
public
void
postProjectRun
(
VadereProject
project
)
{
LinkedList
<
SimulationResult
>
simulationResultList
=
project
.
getSimulationResults
();
StringBuilder
sb
=
new
StringBuilder
();
for
(
SimulationResult
res
:
simulationResultList
)
{
String
[]
headers
=
res
.
getHeaders
();
String
[]
values
=
res
.
getAsTableRow
();
for
(
int
i
=
0
;
i
<
headers
.
length
;
i
++)
{
sb
.
append
(
" "
+
headers
[
i
]
+
": "
).
append
(
values
[
i
]).
append
(
"\n"
);
}
}
if
(
projectViewModel
.
isShowSimulationResultDialog
())
{
SwingUtilities
.
invokeLater
(()
->
{
JDialog
dialog
=
new
ResultDialog
(
projectView
,
simulationResultList
);
dialog
.
setVisible
(
true
);
});
}
else
{
logger
.
info
(
sb
.
toString
());
}
}
class
ResultDialog
extends
JDialog
{
Button
btnOk
,
btnCsv
;
private
JTable
table
;
JPanel
main
;
JScrollPane
scrollPane
;
JPanel
btnPane
;
LinkedList
<
SimulationResult
>
data
;
public
ResultDialog
(
ProjectView
projectView
,
LinkedList
<
SimulationResult
>
data
)
{
super
(
projectView
);
this
.
data
=
data
;
main
=
new
JPanel
();
main
.
setLayout
(
new
BoxLayout
(
main
,
BoxLayout
.
PAGE_AXIS
));
table
=
new
JTable
(
getData
(
data
),
data
.
getFirst
().
getHeaders
());
table
.
setFillsViewportHeight
(
true
);
table
.
doLayout
();
scrollPane
=
new
JScrollPane
(
table
);
main
.
add
(
scrollPane
);
btnOk
=
new
Button
(
Messages
.
getString
(
"SettingsDialog.btnClose.text"
));
btnOk
.
addActionListener
(
this
::
btnOKListener
);
btnCsv
=
new
Button
(
Messages
.
getString
(
"ProjectView.btnExpertCSV"
));
btnPane
=
new
JPanel
();
btnCsv
.
addActionListener
(
this
::
btnCsvListener
);
btnPane
.
setLayout
(
new
BoxLayout
(
btnPane
,
BoxLayout
.
LINE_AXIS
));
btnPane
.
add
(
Box
.
createHorizontalGlue
());
btnPane
.
add
(
btnOk
);
btnPane
.
add
(
Box
.
createRigidArea
(
new
Dimension
(
10
,
0
)));
btnPane
.
add
(
btnCsv
);
Container
c
=
getContentPane
();
c
.
add
(
main
,
BorderLayout
.
CENTER
);
c
.
add
(
btnPane
,
BorderLayout
.
PAGE_END
);
setTitle
(
Messages
.
getString
(
"ProjectView.label.simResults"
));
setSize
(
600
,
200
);
}
public
Object
[][]
getData
(
LinkedList
<
SimulationResult
>
data
)
{
Object
[][]
res
=
new
Object
[
data
.
size
()][
5
];
int
rowIdx
=
0
;
for
(
SimulationResult
d
:
data
)
{
res
[
rowIdx
]
=
d
.
getAsTableRow
();
rowIdx
++;
}
return
res
;
}
private
void
btnOKListener
(
ActionEvent
actionEvent
)
{
setVisible
(
false
);
}
private
void
btnCsvListener
(
ActionEvent
actionEvent
)
{
StringBuilder
sj
=
new
StringBuilder
();
SimulationResult
.
addCsvHeader
(
data
.
getFirst
(),
sj
,
';'
);
data
.
forEach
(
simulationResult
->
simulationResult
.
addCsvRow
(
sj
,
';'
));
FileDialog
fd
=
new
FileDialog
(
this
,
Messages
.
getString
(
"ProjectView.chooseFile"
),
FileDialog
.
SAVE
);
fd
.
setVisible
(
true
);
Path
p
=
(
Paths
.
get
(
fd
.
getDirectory
()).
resolve
(
fd
.
getFile
()));
fd
.
setVisible
(
false
);
try
(
OutputStreamWriter
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
p
.
toString
(),
false
),
StandardCharsets
.
UTF_8
))
{
writer
.
write
(
sj
.
toString
());
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
setVisible
(
false
);
}
}
@Override
public
void
preProjectRun
(
VadereProject
project
)
{
}
@Override
public
void
postProjectRun
(
VadereProject
project
)
{
LinkedList
<
SimulationResult
>
simulationResultList
=
project
.
getSimulationResults
();
StringBuilder
sb
=
new
StringBuilder
();
for
(
SimulationResult
res
:
simulationResultList
)
{
String
[]
headers
=
res
.
getHeaders
();
String
[]
values
=
res
.
getAsTableRow
();
for
(
int
i
=
0
;
i
<
headers
.
length
;
i
++)
{
sb
.
append
(
" "
).
append
(
headers
[
i
]).
append
(
": "
).
append
(
values
[
i
]).
append
(
"\n"
);
}
}
if
(
projectViewModel
.
isShowSimulationResultDialog
())
{
SwingUtilities
.
invokeLater
(()
->
{
JDialog
dialog
=
new
ResultDialog
(
projectView
,
simulationResultList
);
dialog
.
setVisible
(
true
);
});
}
else
{
logger
.
info
(
sb
.
toString
());
}
}
class
ResultDialog
extends
JDialog
{
Button
btnOk
,
btnCsv
;
private
JTable
table
;
JPanel
main
;
JScrollPane
scrollPane
;
JPanel
btnPane
;
LinkedList
<
SimulationResult
>
data
;
ResultDialog
(
ProjectView
projectView
,
LinkedList
<
SimulationResult
>
data
)
{
super
(
projectView
);
this
.
data
=
data
;
main
=
new
JPanel
();
main
.
setLayout
(
new
BoxLayout
(
main
,
BoxLayout
.
PAGE_AXIS
));
table
=
new
JTable
(
getData
(
data
),
data
.
getFirst
().
getHeaders
());
table
.
setFillsViewportHeight
(
true
);
table
.
doLayout
();
scrollPane
=
new
JScrollPane
(
table
);
main
.
add
(
scrollPane
);
btnOk
=
new
Button
(
Messages
.
getString
(
"SettingsDialog.btnClose.text"
));
btnOk
.
addActionListener
(
this
::
btnOKListener
);
btnCsv
=
new
Button
(
Messages
.
getString
(
"ProjectView.btnExpertCSV"
));
btnPane
=
new
JPanel
();
btnCsv
.
addActionListener
(
this
::
btnCsvListener
);
btnPane
.
setLayout
(
new
BoxLayout
(
btnPane
,
BoxLayout
.
LINE_AXIS
));
btnPane
.
add
(
Box
.
createHorizontalGlue
());
btnPane
.
add
(
btnOk
);
btnPane
.
add
(
Box
.
createRigidArea
(
new
Dimension
(
10
,
0
)));
btnPane
.
add
(
btnCsv
);
Container
c
=
getContentPane
();
c
.
add
(
main
,
BorderLayout
.
CENTER
);
c
.
add
(
btnPane
,
BorderLayout
.
PAGE_END
);
setTitle
(
Messages
.
getString
(
"ProjectView.label.simResults"
));
setSize
(
600
,
200
);
}
Object
[][]
getData
(
LinkedList
<
SimulationResult
>
data
)
{
Object
[][]
res
=
new
Object
[
data
.
size
()][
5
];
int
rowIdx
=
0
;
for
(
SimulationResult
d
:
data
)
{
res
[
rowIdx
]
=
d
.
getAsTableRow
();
rowIdx
++;
}
return
res
;
}
private
void
btnOKListener
(
ActionEvent
actionEvent
)
{
setVisible
(
false
);
}
private
void
btnCsvListener
(
ActionEvent
actionEvent
)
{
StringBuilder
sj
=
new
StringBuilder
();
SimulationResult
.
addCsvHeader
(
data
.
getFirst
(),
sj
,
';'
);
data
.
forEach
(
simulationResult
->
simulationResult
.
addCsvRow
(
sj
,
';'
));
FileDialog
fd
=
new
FileDialog
(
this
,
Messages
.
getString
(
"ProjectView.chooseFile"
),
FileDialog
.
SAVE
);
fd
.
setVisible
(
true
);
Path
p
=
(
Paths
.
get
(
fd
.
getDirectory
()).
resolve
(
fd
.
getFile
()));
fd
.
setVisible
(
false
);
try
(
OutputStreamWriter
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
p
.
toString
(),
false
),
StandardCharsets
.
UTF_8
))
{
writer
.
write
(
sj
.
toString
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
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