use of net.parostroj.timetable.gui.commands.CreateTrainCommand in project grafikon by jub77.
the class CreateTrainView method okButtonActionPerformed.
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
// test needed values
Integer speed = null;
try {
String speedText = ObjectsUtil.checkAndTrim(speedTextField.getText());
if (speedText != null) {
speed = Integer.valueOf(speedText);
if (speed < 1) {
throw new NumberFormatException();
}
}
} catch (NumberFormatException e) {
GuiComponentUtils.showError(ResourceLoader.getString("create.train.trainspeedmissing"), this.getParent());
return;
}
if (nameTextField.getText() == null || nameTextField.getText().trim().equals("")) {
GuiComponentUtils.showError(ResourceLoader.getString("create.train.trainnamemissing"), this.getParent());
return;
}
if (fromComboBox.getSelectedItem() == null || toComboBox.getSelectedItem() == null) {
GuiComponentUtils.showError("", this.getParent());
return;
}
RouteBuilder routeBuilder = new RouteBuilder();
Route route = null;
if (throughNodes == null)
route = routeBuilder.createRoute(null, diagram.getNet(), (Node) fromComboBox.getSelectedItem(), (Node) toComboBox.getSelectedItem());
else {
List<Node> r = new ArrayList<>();
r.add((Node) fromComboBox.getSelectedItem());
r.addAll(throughNodes);
r.add((Node) toComboBox.getSelectedItem());
route = routeBuilder.createRoute(null, diagram.getNet(), r);
}
if (route == null) {
GuiComponentUtils.showError(ResourceLoader.getString("create.train.createtrainerror"), this.getParent());
return;
}
// get start time
int start = diagram.getTimeConverter().convertTextToInt(startTimeTextField.getText());
if (start == -1)
// midnight if cannot be parsed
start = 0;
Group group = groupComboBox.getGroupSelection().getGroup();
// create command ...
TrainType tType = (TrainType) typeComboBox.getSelectedItem();
CreateTrainCommand createCommand = new CreateTrainCommand(ObjectsUtil.checkAndTrim(nameTextField.getText()), tType != NO_TYPE ? tType : null, speed, route, start, (stopTextField.getText().equals("") ? 0 : Integer.valueOf(stopTextField.getText()) * 60), ObjectsUtil.checkAndTrim(commentTextField.getText()), dieselCheckBox.isSelected(), electricCheckBox.isSelected(), true, group, managedFreightCheckBox.isSelected());
this.createTrainCommand = createCommand;
// hide dialog
this.closeDialog();
}
Aggregations