Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Compare Revisions
bcd2a94a6bb57f118cfc5a92547c743803f5d8da...6f1d69a4b3c32959497c85aa3d91c88b8649344d
Commits (3)
add action listeners
· f54669d1
Ermek Kuban
authored
Jan 16, 2023
implement buttons and fuctions
f54669d1
draft for exporter runner with parameters
· e6134bdf
Ermek Kuban
authored
Jan 16, 2023
e6134bdf
set config file selected
· 6f1d69a4
Ermek Kuban
authored
Jan 16, 2023
6f1d69a4
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/util/guirunner/ExporterGUI.java
View file @
6f1d69a4
package
de.tud.kom.p2psim.impl.util.guirunner
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.EventQueue
;
import
javax.swing.JFrame
;
import
javax.swing.JPanel
;
import
javax.swing.border.EmptyBorder
;
import
javax.swing.JLabel
;
import
java.awt.Font
;
import
javax.swing.JRadioButton
;
import
javax.swing.JSeparator
;
import
java.awt.SystemColor
;
import
javax.swing.JFileChooser
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.FocusAdapter
;
import
java.awt.event.FocusEvent
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.awt.Color
;
import
javax.swing.ButtonGroup
;
import
javax.swing.JTextField
;
import
javax.swing.JButton
;
import
java.awt.event.ActionListener
;
import
java.io.File
;
import
java.awt.event.ActionEvent
;
import
javax.swing.JFileChooser
;
import
javax.swing.JFrame
;
import
javax.swing.JLabel
;
import
javax.swing.JPanel
;
import
javax.swing.JRadioButton
;
import
javax.swing.JSeparator
;
import
javax.swing.JSlider
;
import
javax.swing.JTextField
;
import
javax.swing.SwingConstants
;
import
javax.swing.WindowConstants
;
import
javax.swing.border.BevelBorder
;
import
javax.swing.
event.ChangeListen
er
;
import
javax.swing.
border.EmptyBord
er
;
import
javax.swing.event.ChangeEvent
;
import
javax.swing.
SwingConstants
;
import
java
.awt.Dimension
;
import
java.awt.event.FocusAdapter
;
import
java.awt.event.FocusEvent
;
import
javax.swing.
event.ChangeListener
;
import
java
x.swing.filechooser.FileNameExtensionFilter
;
import
de.tud.kom.p2psim.impl.util.guirunner.impl.ConfigFile
;
public
class
ExporterGUI
extends
JFrame
implements
ChangeListener
,
ActionListener
{
public
class
ExporterGUI
extends
JFrame
implements
ChangeListener
,
ActionListener
{
private
JPanel
contentPane
;
private
final
ButtonGroup
OutputFormats
=
new
ButtonGroup
();
private
ButtonGroup
OutputFormats
=
new
ButtonGroup
();
private
ButtonGroup
Seeds
=
new
ButtonGroup
();
private
JTextField
textConfigPath
;
private
JTextField
textSeedsPath
;
private
final
ButtonGroup
Seeds
=
new
ButtonGroup
();
private
JTextField
textPathOutput
;
static
JSlider
sliderRuns
;
private
JTextField
textRuns
;
private
JTextField
textSeedsFrom
;
private
JTextField
textSeedsTo
;
private
int
[]
seedRange
=
new
int
[
2
];
private
JButton
btnClose
;
private
JButton
btnStart
;
private
ConfigFile
configFile
;
static
JSlider
sliderRuns
;
private
boolean
resizable
=
false
;
private
int
numberOfRuns
=
1
;
private
File
seedFile
;
private
String
outputPath
;
private
boolean
randomizeSeeds
;
private
String
format
;
/**
* Launch the application.
*/
public
static
void
main
(
String
[]
args
)
{
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
try
{
...
...
@@ -64,9 +99,10 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
* Create the frame.
*/
public
ExporterGUI
()
{
setResizable
(
resizable
);
setSize
(
new
Dimension
(
600
,
500
));
setTitle
(
"Simonstrator - Automated Trace File Generation"
);
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
setDefaultCloseOperation
(
WindowConstants
.
EXIT_ON_CLOSE
);
setBounds
(
100
,
100
,
600
,
500
);
contentPane
=
new
JPanel
();
contentPane
.
setBackground
(
SystemColor
.
controlHighlight
);
...
...
@@ -74,51 +110,87 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
setContentPane
(
contentPane
);
contentPane
.
setLayout
(
null
);
JLabel
lblSelFormat
=
new
JLabel
(
"Select simulation framework output format"
);
JLabel
lblSelFormat
=
new
JLabel
(
"Select simulation framework output format"
);
lblSelFormat
.
setLabelFor
(
lblSelFormat
);
lblSelFormat
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
14
));
lblSelFormat
.
setBounds
(
10
,
0
,
339
,
39
);
contentPane
.
add
(
lblSelFormat
);
JRadioButton
rdbtnMatlab
=
new
JRadioButton
(
"MatLab Simulink"
);
OutputFormats
.
add
(
rdbtnMatlab
);
rdbtnMatlab
.
setBackground
(
SystemColor
.
controlHighlight
);
rdbtnMatlab
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
12
));
rdbtnMatlab
.
setBounds
(
153
,
42
,
133
,
25
);
contentPane
.
add
(
rdbtnMatlab
);
rdbtnMatlab
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
setFormat
(
"matlab"
);
}
});
JRadioButton
rdbtnNS3
=
new
JRadioButton
(
"NS3"
);
OutputFormats
.
add
(
rdbtnNS3
);
rdbtnNS3
.
setBackground
(
SystemColor
.
controlHighlight
);
rdbtnNS3
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
12
));
rdbtnNS3
.
setBounds
(
10
,
42
,
133
,
25
);
contentPane
.
add
(
rdbtnNS3
);
rdbtnNS3
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
setFormat
(
"ns3"
);
}
});
JRadioButton
rdbtnBonmo
=
new
JRadioButton
(
"BonMotion"
);
OutputFormats
.
add
(
rdbtnBonmo
);
rdbtnBonmo
.
setBackground
(
SystemColor
.
controlHighlight
);
rdbtnBonmo
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
12
));
rdbtnBonmo
.
setBounds
(
10
,
70
,
133
,
25
);
contentPane
.
add
(
rdbtnBonmo
);
rdbtnBonmo
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
setFormat
(
"bm"
);
}
});
JRadioButton
rdbtnTheone
=
new
JRadioButton
(
"The ONE"
);
OutputFormats
.
add
(
rdbtnTheone
);
rdbtnTheone
.
setBackground
(
SystemColor
.
controlHighlight
);
rdbtnTheone
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
12
));
rdbtnTheone
.
setBounds
(
153
,
70
,
133
,
25
);
contentPane
.
add
(
rdbtnTheone
);
rdbtnTheone
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
setFormat
(
"one"
);
}
});
JSeparator
separator
=
new
JSeparator
();
separator
.
setBounds
(
0
,
111
,
582
,
10
);
contentPane
.
add
(
separator
);
JLabel
lblSelConfig
=
new
JLabel
(
"Configuration"
);
lblSelConfig
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
14
));
lblSelConfig
.
setBounds
(
10
,
121
,
95
,
39
);
contentPane
.
add
(
lblSelConfig
);
textConfigPath
=
new
JTextField
();
textConfigPath
.
setText
(
"Please select a file"
);
textConfigPath
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
ITALIC
,
11
));
...
...
@@ -126,7 +198,7 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
textConfigPath
.
setBounds
(
119
,
132
,
346
,
20
);
contentPane
.
add
(
textConfigPath
);
textConfigPath
.
setColumns
(
10
);
JButton
btnOpenConfig
=
new
JButton
(
"Open..."
);
btnOpenConfig
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
11
));
btnOpenConfig
.
addActionListener
(
new
ActionListener
()
{
...
...
@@ -136,26 +208,25 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
});
btnOpenConfig
.
setBounds
(
475
,
130
,
89
,
23
);
contentPane
.
add
(
btnOpenConfig
);
JSeparator
separator_1
=
new
JSeparator
();
separator_1
.
setBounds
(
0
,
171
,
582
,
10
);
contentPane
.
add
(
separator_1
);
JRadioButton
rdbtnRandomSeeds
=
new
JRadioButton
(
"Random seeds"
);
Seeds
.
add
(
rdbtnRandomSeeds
);
rdbtnRandomSeeds
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
12
));
rdbtnRandomSeeds
.
setBackground
(
SystemColor
.
controlHighlight
);
rdbtnRandomSeeds
.
setBounds
(
10
,
227
,
103
,
25
);
contentPane
.
add
(
rdbtnRandomSeeds
);
JRadioButton
rdbtnUseCustomSeeds
=
new
JRadioButton
(
"Custom seeds"
);
Seeds
.
add
(
rdbtnUseCustomSeeds
);
rdbtnUseCustomSeeds
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
12
));
rdbtnUseCustomSeeds
.
setBackground
(
SystemColor
.
controlHighlight
);
rdbtnUseCustomSeeds
.
setBounds
(
10
,
188
,
103
,
25
);
contentPane
.
add
(
rdbtnUseCustomSeeds
);
textSeedsPath
=
new
JTextField
();
textSeedsPath
.
setText
(
"Please select a file"
);
textSeedsPath
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
ITALIC
,
11
));
...
...
@@ -163,7 +234,6 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
textSeedsPath
.
setColumns
(
10
);
textSeedsPath
.
setBounds
(
119
,
189
,
346
,
20
);
contentPane
.
add
(
textSeedsPath
);
textSeedsFrom
=
new
JTextField
();
textSeedsFrom
.
setEnabled
(
false
);
...
...
@@ -173,37 +243,39 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
textSeedsFrom
.
setBounds
(
200
,
230
,
110
,
20
);
contentPane
.
add
(
textSeedsFrom
);
textSeedsFrom
.
setColumns
(
10
);
textSeedsFrom
.
addFocusListener
(
new
FocusAdapter
()
{
@Override
public
void
focusGained
(
FocusEvent
e
)
{
if
(
rdbtnRandomSeeds
.
isSelected
()
&&
!
isNumeric
(
textSeedsFrom
.
getText
()))
{
if
(
rdbtnRandomSeeds
.
isSelected
()
&&
!
isNumeric
(
textSeedsFrom
.
getText
()))
{
textSeedsFrom
.
setText
(
""
);
textSeedsFrom
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
11
));
}};
}
}
@Override
public
void
focusLost
(
FocusEvent
e
)
{
if
(
textSeedsFrom
.
getText
().
isEmpty
()
||
!
isNumeric
(
textSeedsFrom
.
getText
()))
{
if
(
textSeedsFrom
.
getText
().
isEmpty
()
||
!
isNumeric
(
textSeedsFrom
.
getText
()))
{
textSeedsFrom
.
setText
(
"select range"
);
}
};
setSeedRange
(
0
,
Integer
.
parseInt
(
textSeedsFrom
.
getText
()));
}
});
JLabel
lblSeedsFrom
=
new
JLabel
(
"from"
);
lblSeedsFrom
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
11
));
lblSeedsFrom
.
setBounds
(
161
,
232
,
29
,
14
);
contentPane
.
add
(
lblSeedsFrom
);
JLabel
lblSeedsTo
=
new
JLabel
(
"to"
);
lblSeedsTo
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
11
));
lblSeedsTo
.
setBounds
(
320
,
232
,
16
,
14
);
contentPane
.
add
(
lblSeedsTo
);
textSeedsTo
=
new
JTextField
();
textSeedsTo
.
setEnabled
(
false
);
textSeedsTo
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
ITALIC
,
11
));
...
...
@@ -212,28 +284,29 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
textSeedsTo
.
setColumns
(
10
);
textSeedsTo
.
setBounds
(
346
,
230
,
110
,
20
);
contentPane
.
add
(
textSeedsTo
);
textSeedsTo
.
addFocusListener
(
new
FocusAdapter
()
{
@Override
public
void
focusGained
(
FocusEvent
e
)
{
if
(
rdbtnRandomSeeds
.
isSelected
()
&&
!
isNumeric
(
textSeedsTo
.
getText
()))
{
if
(
rdbtnRandomSeeds
.
isSelected
()
&&
!
isNumeric
(
textSeedsTo
.
getText
()))
{
textSeedsTo
.
setText
(
""
);
textSeedsTo
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
11
));
}};
}
}
@Override
public
void
focusLost
(
FocusEvent
e
)
{
if
(
textSeedsTo
.
getText
().
isEmpty
()
||
!
isNumeric
(
textSeedsTo
.
getText
()))
{
if
(
textSeedsTo
.
getText
().
isEmpty
()
||
!
isNumeric
(
textSeedsTo
.
getText
()))
{
textSeedsTo
.
setText
(
"select range"
);
}
else
{
setSeedRange
(
1
,
Integer
.
parseInt
(
textSeedsTo
.
getText
()));
}
};
}
});
JButton
btnOpenSeeds
=
new
JButton
(
"Open..."
);
btnOpenSeeds
.
setEnabled
(
false
);
contentPane
.
add
(
btnOpenSeeds
);
...
...
@@ -242,68 +315,70 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
btnOpenSeeds
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
openSeeds
();
}
});
rdbtnRandomSeeds
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
btnOpenSeeds
.
setEnabled
(
false
);
textSeedsTo
.
setEnabled
(
true
);
textSeedsFrom
.
setEnabled
(
true
);
setSeedsOption
(
true
);
}
});
rdbtnUseCustomSeeds
.
addActionListener
(
new
ActionListener
()
{
rdbtnUseCustomSeeds
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
btnOpenSeeds
.
setEnabled
(
true
);
textSeedsTo
.
setEnabled
(
false
);
textSeedsFrom
.
setEnabled
(
false
);
setSeedsOption
(
false
);
}
});
JSeparator
separator_1_1
=
new
JSeparator
();
separator_1_1
.
setBounds
(
0
,
265
,
582
,
10
);
contentPane
.
add
(
separator_1_1
);
JLabel
lblSimulationruns
=
new
JLabel
(
"Simulation runs"
);
lblSimulationruns
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
14
));
lblSimulationruns
.
setBounds
(
10
,
280
,
95
,
39
);
contentPane
.
add
(
lblSimulationruns
);
sliderRuns
=
new
JSlider
();
sliderRuns
.
setValue
(
12
);
sliderRuns
.
setPaintTicks
(
true
);
sliderRuns
.
setPaintLabels
(
true
);
sliderRuns
.
setMajorTickSpacing
(
10
);
sliderRuns
.
setBorder
(
new
BevelBorder
(
BevelBorder
.
LOWERED
,
null
,
null
,
null
,
null
));
sliderRuns
.
setBorder
(
new
BevelBorder
(
BevelBorder
.
LOWERED
,
null
,
null
,
null
,
null
));
sliderRuns
.
setBounds
(
119
,
276
,
346
,
55
);
contentPane
.
add
(
sliderRuns
);
textRuns
=
new
JTextField
();
textRuns
.
addFocusListener
(
new
FocusAdapter
()
{
@Override
public
void
focusGained
(
FocusEvent
e
)
{
textRuns
.
setText
(
""
);
}
@Override
public
void
focusLost
(
FocusEvent
e
)
{
if
(!
isNumeric
(
textRuns
.
getText
())
||
Integer
.
parseInt
(
textRuns
.
getText
())
<
0
||
Integer
.
parseInt
(
textRuns
.
getText
())
>
100
)
{
textRuns
.
setText
(
""
+
sliderRuns
.
getValue
());
}}
if
(!
isNumeric
(
textRuns
.
getText
())
||
Integer
.
parseInt
(
textRuns
.
getText
())
<
0
||
Integer
.
parseInt
(
textRuns
.
getText
())
>
100
)
{
textRuns
.
setText
(
""
+
sliderRuns
.
getValue
());
}
}
});
textRuns
.
setHorizontalAlignment
(
SwingConstants
.
CENTER
);
textRuns
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
15
));
...
...
@@ -312,19 +387,18 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
contentPane
.
add
(
textRuns
);
textRuns
.
setColumns
(
10
);
textRuns
.
addActionListener
(
this
);
sliderRuns
.
addChangeListener
(
this
);
JSeparator
separator_1_1_1
=
new
JSeparator
();
separator_1_1_1
.
setBounds
(
10
,
342
,
582
,
10
);
contentPane
.
add
(
separator_1_1_1
);
JLabel
lblOutputFolder
=
new
JLabel
(
"Output folder"
);
lblOutputFolder
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
14
));
lblOutputFolder
.
setBounds
(
10
,
357
,
95
,
31
);
contentPane
.
add
(
lblOutputFolder
);
textPathOutput
=
new
JTextField
();
textPathOutput
.
setText
(
"Please select output folder"
);
textPathOutput
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
ITALIC
,
11
));
...
...
@@ -332,84 +406,176 @@ public class ExporterGUI extends JFrame implements ChangeListener, ActionListene
textPathOutput
.
setColumns
(
10
);
textPathOutput
.
setBounds
(
119
,
363
,
346
,
20
);
contentPane
.
add
(
textPathOutput
);
JButton
btnOpenoutput
=
new
JButton
(
"Open..."
);
btnOpenoutput
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
openOutput
();
}
openOutput
();
}
});
btnOpenoutput
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
PLAIN
,
11
));
btnOpenoutput
.
setBounds
(
475
,
363
,
89
,
23
);
contentPane
.
add
(
btnOpenoutput
);
JButton
btnClose
=
new
JButton
(
"Close"
);
btnClose
=
new
JButton
(
"Close"
);
btnClose
.
setForeground
(
Color
.
RED
);
btnClose
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
BOLD
,
13
));
btnClose
.
setBounds
(
372
,
429
,
89
,
31
);
contentPane
.
add
(
btnClose
);
JButton
btnStart
=
new
JButton
(
"Start"
);
this
.
add
(
btnClose
);
btnStart
=
new
JButton
(
"Start"
);
btnStart
.
setForeground
(
new
Color
(
0
,
128
,
0
));
btnStart
.
setFont
(
new
Font
(
"Segoe UI"
,
Font
.
BOLD
,
18
));
btnStart
.
setBounds
(
471
,
413
,
111
,
48
);
contentPane
.
add
(
btnStart
);
this
.
add
(
btnStart
);
btnStart
.
addActionListener
(
this
);
btnClose
.
addActionListener
(
this
);
}
public
void
stateChanged
(
ChangeEvent
e
)
{
if
(
e
.
getSource
()
==
sliderRuns
)
{
textRuns
.
setText
(
""
+
sliderRuns
.
getValue
());
if
(
e
.
getSource
()
==
sliderRuns
)
{
textRuns
.
setText
(
""
+
sliderRuns
.
getValue
());
}
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
if
(
isNumeric
(
textRuns
.
getText
()))
{
if
(
isNumeric
(
textRuns
.
getText
()))
{
int
value
=
Integer
.
parseInt
(
textRuns
.
getText
());
if
(!(
value
<
0
||
value
>
100
))
{
sliderRuns
.
setValue
(
Integer
.
parseInt
(
textRuns
.
getText
()));
if
(!(
value
<
0
||
value
>
100
))
{
sliderRuns
.
setValue
(
Integer
.
parseInt
(
textRuns
.
getText
()));
}
else
{
textRuns
.
setText
(
""
+
sliderRuns
.
getValue
());
textRuns
.
setText
(
""
+
sliderRuns
.
getValue
());
}
this
.
numberOfRuns
=
sliderRuns
.
getValue
();
}
if
(
e
.
getSource
()
==
btnClose
)
{
closeExporter
();
}
if
(
e
.
getSource
()
==
btnStart
)
{
try
{
startExporter
();
}
catch
(
FileNotFoundException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
}
}
}
private
void
setFormat
(
String
format
)
{
this
.
format
=
format
;
}
private
String
getFormat
()
{
// TODO Auto-generated method stub
return
this
.
format
;
}
public
void
setSeedsOption
(
boolean
b
)
{
// TODO Auto-generated method stub
this
.
randomizeSeeds
=
b
;
}
public
boolean
getSeedsOption
()
{
// TODO Auto-generated method stub
return
this
.
randomizeSeeds
;
}
private
void
startExporter
()
throws
FileNotFoundException
{
// TODO Auto-generated method stub
this
.
setVisible
(
false
);
new
ExporterRunner
(
configFile
,
randomizeSeeds
,
seedFile
,
seedRange
,
numberOfRuns
,
outputPath
,
format
);
}
public
void
openConfig
()
{
JFileChooser
config
=
new
JFileChooser
();
config
.
setFileSelectionMode
(
JFileChooser
.
FILES_ONLY
);
config
.
setAcceptAllFileFilterUsed
(
false
);
config
.
setFileFilter
(
new
FileNameExtensionFilter
(
"*.xml"
,
"xml"
));
int
returnVal
=
config
.
showOpenDialog
(
this
);
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
config
.
getSelectedFile
();
textConfigPath
.
setText
(
""
+
file
.
getPath
());
}
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
config
.
getSelectedFile
();
setConfigFile
((
ConfigFile
)
file
);
textConfigPath
.
setText
(
""
+
file
.
getPath
());
}
}
public
void
openSeeds
()
{
JFileChooser
seed
=
new
JFileChooser
();
seed
.
setFileSelectionMode
(
JFileChooser
.
FILES_ONLY
);
int
returnVal
=
seed
.
showOpenDialog
(
this
);
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
seed
.
getSelectedFile
();
textSeedsPath
.
setText
(
""
+
file
.
getPath
());
}
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
seed
.
getSelectedFile
();
textSeedsPath
.
setText
(
""
+
file
.
getPath
());
this
.
seedFile
=
file
;
this
.
randomizeSeeds
=
false
;
}
}
public
void
openOutput
()
{
JFileChooser
output
=
new
JFileChooser
();
output
.
setFileSelectionMode
(
JFileChooser
.
DIRECTORIES_ONLY
);
int
returnVal
=
output
.
showOpenDialog
(
this
);
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
output
.
getSelectedFile
();
textPathOutput
.
setText
(
""
+
file
.
getPath
());
}
if
(
returnVal
==
JFileChooser
.
APPROVE_OPTION
)
{
File
file
=
output
.
getSelectedFile
();
textPathOutput
.
setText
(
""
+
file
.
getPath
());
this
.
outputPath
=
file
.
getPath
();
}
}
public
static
boolean
isNumeric
(
String
str
)
{
return
str
.
matches
(
"-?\\d+(\\.\\d+)?"
);
//match a number with optional '-' and decimal.
return
str
.
matches
(
"-?\\d+(\\.\\d+)?"
);
// match a number with optional
// '-' and decimal.
}
public
void
setConfigFile
(
ConfigFile
config
)
{
this
.
configFile
=
config
;
textConfigPath
.
setText
(
""
+
config
.
getFile
().
getPath
());
}
ConfigFile
getConfigFile
()
{
return
this
.
configFile
;
}
public
int
getRunNumbers
()
{
return
this
.
numberOfRuns
;
}
private
void
setSeedRange
(
int
index
,
int
range
)
{
this
.
seedRange
[
index
]
=
range
;
}
public
int
[]
getSeedRange
()
{
return
this
.
seedRange
;
}
public
void
closeExporter
()
{
this
.
dispose
();
System
.
exit
(
0
);
}
public
String
getOutputPath
()
{
return
this
.
outputPath
;
}
public
File
getSeed
()
{
return
this
.
seedFile
;
}
public
void
setSeedFile
(
File
seeds
)
{
this
.
seedFile
=
seeds
;
}
}
src/de/tud/kom/p2psim/impl/util/guirunner/ExporterRunner.java
0 → 100644
View file @
6f1d69a4
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.util.guirunner
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.Random
;
import
com.mysql.cj.exceptions.DataReadException
;
import
de.tud.kom.p2psim.impl.util.guirunner.impl.ConfigFile
;
public
class
ExporterRunner
{
private
ConfigFile
configFile
;
private
boolean
resizable
=
false
;
private
int
numberOfRuns
=
1
;
private
File
seedFile
=
null
;
private
String
outputPath
=
null
;
private
boolean
randomizeSeeds
;
private
static
ExporterGUI
gui
;
private
int
seed
;
private
int
seeds
[];
private
String
format
;
private
String
samplingInterval
;
public
ExporterRunner
(
ConfigFile
config
,
boolean
randomSeeds
,
File
seedFile
,
int
[]
seedRange
,
int
runs
,
String
output
,
String
format
)
throws
FileNotFoundException
{
this
.
configFile
=
config
;
this
.
randomizeSeeds
=
randomSeeds
;
this
.
outputPath
=
output
;
this
.
numberOfRuns
=
runs
;
this
.
format
=
format
;
this
.
seeds
=
seedRange
;
if
(
randomizeSeeds
)
{
if
(
seeds
==
null
)
{
seed
=
new
Random
().
nextInt
();
/// randomize yourself
}
else
{
seed
=
new
Random
().
nextInt
(
seedRange
[
0
],
seedRange
[
1
]);
}
}
else
{
this
.
seedFile
=
seedFile
;
if
(
seedFile
.
isFile
()
&&
seedFile
.
exists
())
{
if
(
seedFile
.
length
()
==
0
)
{
throw
new
DataReadException
(
"File is empty"
);
}
else
{
parseSeeds
(
seedFile
);
}
}
else
{
throw
new
FileNotFoundException
(
"File does not exist or it is not a file"
);
}
}
run
();
}
public
void
run
()
{
System
.
out
.
println
(
"Congrats, you've reached me!! \n"
);
}
public
void
runGui
()
{
this
.
gui
.
setVisible
(
true
);
}
public
void
setValues
()
{
}
// parse file with custom seeds
private
void
parseSeeds
(
File
seedFile
)
{
// TODO Auto-generated method stub
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
seedFile
));
// index to access array
int
i
=
0
;
String
line
;
// initialize seeds array with the size of run numebers
this
.
seeds
=
new
int
[
this
.
numberOfRuns
];
// parse line by line
while
((
line
=
reader
.
readLine
())
!=
null
&&
i
<
seeds
.
length
)
{
try
{
this
.
seeds
[
i
]
=
Integer
.
parseInt
(
line
);
// read next line
i
++;
}
catch
(
NumberFormatException
e
)
{
// TODO: handle exception
throw
new
NumberFormatException
(
"File contains not integer characters"
);
}
}
// add random seeds if file contains less seeds than number of runs
if
(
i
<
this
.
numberOfRuns
)
{
for
(
int
j
=
i
;
j
<
seeds
.
length
;
j
++)
{
seeds
[
j
]
=
new
Random
().
nextInt
();
}
}
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
setConfigFile
(
ConfigFile
config
)
{
this
.
configFile
=
config
;
}
}
src/de/tud/kom/p2psim/impl/util/guirunner/impl/DirView.java
View file @
6f1d69a4
...
...
@@ -18,125 +18,145 @@
*
*/
package
de.tud.kom.p2psim.impl.util.guirunner.impl
;
package
de.tud.kom.p2psim.impl.util.guirunner.impl
;
import
java.awt.event.MouseEvent
;
import
java.awt.event.MouseListener
;
import
javax.swing.JOptionPane
;
import
javax.swing.JTree
;
import
javax.swing.event.TreeSelectionEvent
;
import
javax.swing.event.TreeSelectionListener
;
import
javax.swing.tree.DefaultTreeModel
;
import
javax.swing.tree.TreeSelectionModel
;
/**
* A tree view that shows available and recently opened configuration files.
*
* @author Leo Nobach
* @version 3.0, 25.11.2008
*
*/
public
class
DirView
extends
JTree
implements
TreeSelectionListener
,
MouseListener
{
private
RunnerController
ctrl
;
import
de.tud.kom.p2psim.impl.util.guirunner.ExporterGUI
;
/**
* A tree view that shows available and recently opened configuration files.
*
* @author Leo Nobach
* @version 3.0, 25.11.2008
*
*/
public
class
DirView
extends
JTree
implements
TreeSelectionListener
,
MouseListener
{
private
RunnerController
ctrl
;
private
ExporterGUI
expo
=
new
ExporterGUI
();
private
ConfigTreeNode
selectedConfigNode
=
null
;
private
FilterTreeModel
treeModel
;
public
DirView
(
RunnerController
ctrl
,
LastOpened
lastOpened
)
{
super
();
this
.
ctrl
=
ctrl
;
NodeModel
mdl
=
new
NodeModel
(
lastOpened
);
private
FilterTreeModel
treeModel
;
public
DirView
(
RunnerController
ctrl
,
LastOpened
lastOpened
)
{
super
();
this
.
ctrl
=
ctrl
;
NodeModel
mdl
=
new
NodeModel
(
lastOpened
);
treeModel
=
new
FilterTreeModel
(
new
DefaultTreeModel
(
mdl
.
getRoot
()));
this
.
setModel
(
treeModel
);
this
.
getSelectionModel
()
.
setSelectionMode
(
TreeSelectionModel
.
SINGLE_TREE_SELECTION
);
this
.
addTreeSelectionListener
(
this
);
this
.
expandAll
(
this
);
this
.
addMouseListener
(
this
);
this
.
setCellRenderer
(
new
NodeRenderer
());
initialSelect
();
this
.
setModel
(
treeModel
);
this
.
getSelectionModel
()
.
setSelectionMode
(
TreeSelectionModel
.
SINGLE_TREE_SELECTION
);
this
.
addTreeSelectionListener
(
this
);
this
.
expandAll
(
this
);
this
.
addMouseListener
(
this
);
this
.
setCellRenderer
(
new
NodeRenderer
());
initialSelect
();
}
public
void
filter
(
String
text
)
{
treeModel
.
setFilter
(
text
);
}
/**
* Selects the row that should be selected on startup.
*/
private
void
initialSelect
()
{
this
.
setSelectionRow
(
2
);
}
/**
* Expands all entries in the tree view.
*
* @param tree
*/
public
void
expandAll
(
JTree
tree
)
{
int
row
=
0
;
while
(
row
<
tree
.
getRowCount
())
{
tree
.
expandRow
(
row
);
row
++;
}
}
@Override
public
void
valueChanged
(
TreeSelectionEvent
e
)
{
Object
selectedNode
=
this
.
getLastSelectedPathComponent
();
if
(
selectedNode
instanceof
ConfigTreeNode
)
{
selectedConfigNode
=
(
ConfigTreeNode
)
selectedNode
;
}
else
{
selectedConfigNode
=
null
;
}
ctrl
.
selectFile
(
selectedConfigNode
==
null
?
null
:
selectedConfigNode
.
getConfigFile
());
// System.out.println("Ausgewählte ConfigNode: " + selectedConfigNode);
}
@Override
public
void
mouseClicked
(
MouseEvent
arg0
)
{
if
(
arg0
.
getClickCount
()
==
2
&&
selectedConfigNode
!=
null
)
ctrl
.
invokeRunSimulator
();
}
@Override
public
void
mouseEntered
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mouseExited
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mousePressed
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mouseReleased
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
}
}
/**
* Selects the row that should be selected on startup.
*/
private
void
initialSelect
()
{
this
.
setSelectionRow
(
2
);
}
/**
* Expands all entries in the tree view.
*
* @param tree
*/
public
void
expandAll
(
JTree
tree
)
{
int
row
=
0
;
while
(
row
<
tree
.
getRowCount
())
{
tree
.
expandRow
(
row
);
row
++;
}
}
@Override
public
void
valueChanged
(
TreeSelectionEvent
e
)
{
Object
selectedNode
=
this
.
getLastSelectedPathComponent
();
if
(
selectedNode
instanceof
ConfigTreeNode
)
{
selectedConfigNode
=
(
ConfigTreeNode
)
selectedNode
;
}
else
{
selectedConfigNode
=
null
;
}
ctrl
.
selectFile
(
selectedConfigNode
==
null
?
null
:
selectedConfigNode
.
getConfigFile
());
// System.out.println("Ausgewählte ConfigNode: " + selectedConfigNode);
}
@Override
public
void
mouseClicked
(
MouseEvent
arg0
)
{
JOptionPane
optionConfigStart
=
new
JOptionPane
();
int
selectedOption
=
0
;
if
(
arg0
.
getClickCount
()
==
2
&&
selectedConfigNode
!=
null
)
{
selectedOption
=
optionConfigStart
.
showOptionDialog
(
null
,
"Use this configuration file to start"
,
"Choose option"
,
JOptionPane
.
YES_NO_OPTION
,
JOptionPane
.
QUESTION_MESSAGE
,
null
,
new
String
[]
{
"Simulation"
,
"Trace Exporter"
},
""
);
if
(
selectedOption
==
0
)
{
ctrl
.
invokeRunSimulator
();
}
else
{
expo
.
setConfigFile
(
selectedConfigNode
.
getConfigFile
());
expo
.
setVisible
(
true
);
}
}
}
@Override
public
void
mouseEntered
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mouseExited
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mousePressed
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
mouseReleased
(
MouseEvent
arg0
)
{
// TODO Auto-generated method stub
}
}