use of net.parostroj.timetable.model.GrafikonException in project grafikon by jub77.
the class TrainRouteSelection method changeTrack.
/**
* Changes track - in case of different track route (change the whole chain).
*
* @param train train
* @param interval interval
* @param newTrack requested track
*/
public void changeTrack(Train train, TimeInterval interval, Track newTrack) {
if (interval.getOwner() != newTrack.getOwner()) {
throw new IllegalArgumentException("Invalid track owner");
}
if (isTrackValid(interval, newTrack)) {
// change directly
interval.setTrack(newTrack);
} else {
// check alternative routes
Map<TimeInterval, Set<Track>> map = new HashMap<>();
if (!interval.isFirst()) {
// first part
TimeInterval firstInterval = train.getFirstInterval();
List<TimeInterval> intervals = train.getIntervals(firstInterval, interval);
Map<TimeInterval, Set<Track>> trackMap = tracksComputation.getAvailableTracksForIntervals(intervals, firstInterval.getOwnerAsNode().getTracks(), Collections.singletonList(newTrack));
map.putAll(trackMap);
}
if (!interval.isLast()) {
// second part
TimeInterval lastInterval = train.getLastInterval();
List<TimeInterval> intervals = train.getIntervals(interval, lastInterval);
Map<TimeInterval, Set<Track>> trackMap = tracksComputation.getAvailableTracksForIntervals(intervals, Collections.singletonList(newTrack), lastInterval.getOwnerAsNode().getTracks());
map.putAll(trackMap);
}
if (map.isEmpty()) {
throw new GrafikonException("No route");
}
Track fromTrack = null;
for (TimeInterval checkedInterval : train.getTimeIntervalList()) {
checkedInterval.setTrack(trackSelection.selectTrack(checkedInterval, checkedInterval.getTrack(), fromTrack, map.get(checkedInterval)));
fromTrack = checkedInterval.getTrack();
}
}
}
use of net.parostroj.timetable.model.GrafikonException in project grafikon by jub77.
the class ExecuteScriptAction method loadScriptFromPreferences.
private void loadScriptFromPreferences() {
String scriptStr = null;
try {
scriptStr = AppPreferences.getPreferences().getSection("scripts").get("last.script");
scriptStr = scriptStr != null ? EscapeTool.getInstance().unescape(scriptStr) : null;
} catch (IOException ex) {
log.error("Error reading script from preferences.", ex);
}
if (scriptStr == null) {
// default script
scriptStr = "GROOVY:for (train in diagram.trains) {}";
}
int location = scriptStr.indexOf(':');
Language lang = Language.valueOf(scriptStr.substring(0, location));
String scriptSource = scriptStr.substring(location + 1);
try {
lastScript = Script.createScript(scriptSource, lang);
} catch (GrafikonException e) {
log.error("Error converting script.", e);
}
}
use of net.parostroj.timetable.model.GrafikonException in project grafikon by jub77.
the class ScriptDialog method executeButtonActionPerformed.
private void executeButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
statusBar.setText("");
counter++;
Script script = this.getScript();
if (executor != null) {
long time = System.currentTimeMillis();
Object result = executor.apply(script, this);
statusBar.setText(String.format(ResourceLoader.getString("script.message"), counter, System.currentTimeMillis() - time, result));
}
} catch (GrafikonException e) {
log.error("Error creating script.", e);
String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
GuiComponentUtils.showError(message, this);
}
}
use of net.parostroj.timetable.model.GrafikonException in project grafikon by jub77.
the class TextItemDialog method okButtonActionPerformed.
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
TextTemplate template = this.convertToTemplate();
this.resultItemModel = new TextItemModel(template, trainTimetableInfoCheckBox.isSelected());
this.setVisible(false);
} catch (GrafikonException e) {
log.error(e.getMessage(), e);
GuiComponentUtils.showError(e.getMessage(), this);
}
}
use of net.parostroj.timetable.model.GrafikonException in project grafikon by jub77.
the class TextTemplateEditBox method getTemplateEmpty.
public TextTemplate getTemplateEmpty() throws GrafikonException {
String str = ObjectsUtil.checkAndTrim(templateTextField.getText());
Language lang = (Language) languageComboBox.getSelectedItem();
if (lang == null)
throw new GrafikonException("No language selected.");
if (str == null) {
return null;
} else {
return TextTemplate.createTextTemplate(str, lang);
}
}
Aggregations