Commit bcd2a94a authored by Ermek Kuban's avatar Ermek Kuban
Browse files

gui for the trace file exporter

adjust guirunner for exportergui
parent 4e93e08f
package de.tud.kom.p2psim.impl.util.guirunner;
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.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.JSlider;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.SwingConstants;
import java.awt.Dimension;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
public class ExporterGUI extends JFrame implements ChangeListener, ActionListener {
private JPanel contentPane;
private final ButtonGroup OutputFormats = 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;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ExporterGUI frame = new ExporterGUI();
frame.setVisible(true);
frame.setResizable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ExporterGUI() {
setSize(new Dimension(600, 500));
setTitle("Simonstrator - Automated Trace File Generation");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 500);
contentPane = new JPanel();
contentPane.setBackground(SystemColor.controlHighlight);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
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);
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);
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);
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);
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));
textConfigPath.setEditable(false);
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() {
public void actionPerformed(ActionEvent e) {
openConfig();
}
});
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));
textSeedsPath.setEditable(false);
textSeedsPath.setColumns(10);
textSeedsPath.setBounds(119, 189, 346, 20);
contentPane.add(textSeedsPath);
textSeedsFrom = new JTextField();
textSeedsFrom.setEnabled(false);
textSeedsFrom.setFont(new Font("Segoe UI", Font.ITALIC, 11));
textSeedsFrom.setHorizontalAlignment(SwingConstants.CENTER);
textSeedsFrom.setText("select range");
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())) {
textSeedsFrom.setText("");
textSeedsFrom.setFont(new Font("Segoe UI", Font.PLAIN, 11));
}};
@Override
public void focusLost(FocusEvent e) {
if(textSeedsFrom.getText().isEmpty() || !isNumeric(textSeedsFrom.getText())) {
textSeedsFrom.setText("select range");
}
};
});
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));
textSeedsTo.setText("select range");
textSeedsTo.setHorizontalAlignment(SwingConstants.CENTER);
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())) {
textSeedsTo.setText("");
textSeedsTo.setFont(new Font("Segoe UI", Font.PLAIN, 11));
}};
@Override
public void focusLost(FocusEvent e) {
if(textSeedsTo.getText().isEmpty() || !isNumeric(textSeedsTo.getText())) {
textSeedsTo.setText("select range");
}
};
});
JButton btnOpenSeeds = new JButton("Open...");
btnOpenSeeds.setEnabled(false);
contentPane.add(btnOpenSeeds);
btnOpenSeeds.setFont(new Font("Segoe UI", Font.PLAIN, 11));
btnOpenSeeds.setBounds(475, 189, 89, 23);
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);
}
});
rdbtnUseCustomSeeds.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
btnOpenSeeds.setEnabled(true);
textSeedsTo.setEnabled(false);
textSeedsFrom.setEnabled(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.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());
}}
});
textRuns.setHorizontalAlignment(SwingConstants.CENTER);
textRuns.setFont(new Font("Segoe UI", Font.PLAIN, 15));
textRuns.setBounds(490, 286, 35, 33);
textRuns.setText("100");
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));
textPathOutput.setEditable(false);
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();
}
});
btnOpenoutput.setFont(new Font("Segoe UI", Font.PLAIN, 11));
btnOpenoutput.setBounds(475, 363, 89, 23);
contentPane.add(btnOpenoutput);
JButton 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");
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);
}
public void stateChanged(ChangeEvent e) {
if(e.getSource() == sliderRuns) {
textRuns.setText(""+sliderRuns.getValue());
}
}
public void actionPerformed(ActionEvent e) {
if(isNumeric(textRuns.getText())) {
int value = Integer.parseInt(textRuns.getText());
if(!(value<0 || value > 100)) {
sliderRuns.setValue(Integer.parseInt(textRuns.getText()));
} else {
textRuns.setText(""+sliderRuns.getValue());
}
}
}
public void openConfig() {
JFileChooser config = new JFileChooser();
config.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = config.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = config.getSelectedFile();
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());
}
}
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());
}
}
public static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
}
}
......@@ -190,25 +190,34 @@ public class GUIRunner extends JFrame implements WindowListener, KeyListener {
*/
private static final long serialVersionUID = -7482502225920138689L;
private JButton cancelBtn;
private JButton cancelBtn;
private JButton launchExporter;
public ButtonBar() {
this.setLayout(new FlowLayout());
JButton launchBtn = new JButton("Start Simulation");
ctrl.setLaunchButton(launchBtn);
this.add(launchBtn);
cancelBtn = new JButton("Cancel");
this.add(cancelBtn);
public ButtonBar() {
this.setLayout(new FlowLayout());
JButton launchBtn = new JButton("Start Simulation");
ctrl.setLaunchButton(launchBtn);
this.add(launchBtn);
cancelBtn = new JButton("Cancel");
this.add(cancelBtn);
launchExporter = new JButton("Start Trace Exporter");
this.add(launchExporter);
launchExporter.addActionListener(this);
cancelBtn.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cancelBtn)
closeRunner();
closeRunner();
if (e.getSource() == launchExporter)
startExporter();
}
}
......@@ -217,6 +226,14 @@ public class GUIRunner extends JFrame implements WindowListener, KeyListener {
disposeRunner();
System.exit(0);
}
public void startExporter() {
disposeRunner();
ExporterGUI expo = new ExporterGUI();
expo.setVisible(true);
}
public void disposeRunner() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment