1 package org.matsim.run.gui;
3 import java.awt.HeadlessException;
6 import javax.swing.GroupLayout;
7 import javax.swing.JButton;
8 import javax.swing.JDialog;
9 import javax.swing.JFileChooser;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JScrollPane;
13 import javax.swing.JTable;
14 import javax.swing.JTextField;
15 import javax.swing.SwingUtilities;
16 import javax.swing.table.DefaultTableModel;
42 setTitle(
"Transit Schedule Validator");
45 JLabel lblSchedule =
new JLabel(
"Transit Schedule:");
46 JLabel lblNetwork =
new JLabel(
"Network (optional):");
47 JLabel lblOutput =
new JLabel(
"Output");
49 this.txtScheduleFilename =
new JTextField(
"", 20);
50 this.txtNetworkFilename =
new JTextField(
"", 20);
52 JButton btnChooseSchedule =
new JButton(
"Choose");
53 JButton btnChooseNetwork =
new JButton(
"Choose");
55 this.btnValidate =
new JButton(
"Validate");
57 this.resultTableModel =
new DefaultTableModel(0, 2) {
59 public String getColumnName(
int column) {
60 return new String[] {
"Type",
"Message" }[column];
64 public boolean isCellEditable(
int row,
int column) {
68 this.resultTable =
new JTable(this.resultTableModel);
69 this.resultTable.getColumnModel().getColumn(0).setWidth(150);
70 this.resultTable.getColumnModel().getColumn(0).setMaxWidth(250);
71 JScrollPane outputPane =
new JScrollPane(this.resultTable);
75 this.lastUsedDirectory =
new File(
".");
77 btnChooseSchedule.addActionListener(e -> {
78 JFileChooser chooser =
new JFileChooser();
79 chooser.setCurrentDirectory(this.lastUsedDirectory);
80 int result = chooser.showOpenDialog(null);
81 if (result == JFileChooser.APPROVE_OPTION) {
82 File f = chooser.getSelectedFile();
83 this.lastUsedDirectory = f.getParentFile();
84 this.txtScheduleFilename.setText(f.getAbsolutePath());
88 btnChooseNetwork.addActionListener(e -> {
89 JFileChooser chooser =
new JFileChooser();
90 chooser.setCurrentDirectory(this.lastUsedDirectory);
91 int result = chooser.showOpenDialog(null);
92 if (result == JFileChooser.APPROVE_OPTION) {
93 File f = chooser.getSelectedFile();
94 this.lastUsedDirectory = f.getParentFile();
95 this.txtNetworkFilename.setText(f.getAbsolutePath());
99 this.btnValidate.addActionListener(e ->
run());
103 GroupLayout groupLayout =
new GroupLayout(getContentPane());
104 groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
106 .addGroup(groupLayout.createParallelGroup()
107 .addGroup(groupLayout.createSequentialGroup()
108 .addGroup(groupLayout.createParallelGroup()
109 .addComponent(lblSchedule)
110 .addComponent(lblNetwork)
111 .addComponent(this.btnValidate)
112 .addComponent(lblOutput))
113 .addGroup(groupLayout.createParallelGroup()
114 .addComponent(this.txtScheduleFilename)
115 .addComponent(this.txtNetworkFilename))
116 .addGroup(groupLayout.createParallelGroup()
117 .addComponent(btnChooseSchedule)
118 .addComponent(btnChooseNetwork)))
119 .addComponent(outputPane, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE, Short.MAX_VALUE))
122 groupLayout.setVerticalGroup(groupLayout.createSequentialGroup()
124 .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
125 .addComponent(lblSchedule)
126 .addComponent(this.txtScheduleFilename)
127 .addComponent(btnChooseSchedule))
128 .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
129 .addComponent(lblNetwork)
130 .addComponent(this.txtNetworkFilename)
131 .addComponent(btnChooseNetwork))
133 groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.btnValidate))
134 .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(lblOutput))
135 .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
136 .addComponent(outputPane, 200, Short.MAX_VALUE, Short.MAX_VALUE))
139 getContentPane().setLayout(groupLayout);
142 this.setSize(800, 600);
147 if (scheduleFilename != null) {
148 this.txtScheduleFilename.setText(
new File(configDirectory, scheduleFilename).getAbsolutePath());
151 if (networkFilename != null) {
152 this.txtNetworkFilename.setText(
new File(configDirectory, networkFilename).getAbsolutePath());
157 this.btnValidate.setEnabled(
false);
158 this.resultTableModel.setRowCount(0);
159 this.resultTableModel.addRow(
new Object[] {
"",
"Validating transit schedule..." });
162 String scheduleFilename = this.txtScheduleFilename.getText();
163 String networkFilename = this.txtNetworkFilename.getText();
169 if (networkFilename != null) {
173 if (scheduleFilename != null) {
179 SwingUtilities.invokeLater(() -> {
180 this.resultTableModel.setRowCount(0);
181 if (result.isValid()) {
182 this.resultTableModel.addRow(
new Object[] {
"SUCCESS",
"The schedule appears valid" });
184 for (String message : result.getWarnings()) {
185 this.resultTableModel.addRow(
new Object[] {
"WARNING", message });
187 for (String message : result.getErrors()) {
188 this.resultTableModel.addRow(
new Object[] {
"ERROR", message });
190 this.btnValidate.setEnabled(
true);
196 public static void main(String[] args) {
void readFile(final String filename)
static void main(String[] args)
final NetworkConfigGroup network()
void loadFromConfig(Config config, File configDirectory)
final JTextField txtScheduleFilename
final DefaultTableModel resultTableModel
final JButton btnValidate
TransitConfigGroup transit()
static ValidationResult validateAll(final TransitSchedule schedule, final Network network)
String getTransitScheduleFile()
ScheduleValidatorWindow(JFrame parent)
final void readFile(final String filename)
TransitSchedule getTransitSchedule()
static Scenario createScenario(final Config config)
final JTextField txtNetworkFilename
static Config createConfig(final String context)