Search in sources :

Example 1 with GrafikonException

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();
        }
    }
}
Also used : Set(java.util.Set) TimeInterval(net.parostroj.timetable.model.TimeInterval) GrafikonException(net.parostroj.timetable.model.GrafikonException) HashMap(java.util.HashMap) LineTrack(net.parostroj.timetable.model.LineTrack) NodeTrack(net.parostroj.timetable.model.NodeTrack) Track(net.parostroj.timetable.model.Track)

Example 2 with GrafikonException

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);
    }
}
Also used : Language(net.parostroj.timetable.model.Script.Language) GrafikonException(net.parostroj.timetable.model.GrafikonException)

Example 3 with GrafikonException

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);
    }
}
Also used : Script(net.parostroj.timetable.model.Script) GrafikonException(net.parostroj.timetable.model.GrafikonException)

Example 4 with GrafikonException

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);
    }
}
Also used : GrafikonException(net.parostroj.timetable.model.GrafikonException) TextTemplate(net.parostroj.timetable.model.TextTemplate)

Example 5 with GrafikonException

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);
    }
}
Also used : Language(net.parostroj.timetable.model.TextTemplate.Language) GrafikonException(net.parostroj.timetable.model.GrafikonException)

Aggregations

GrafikonException (net.parostroj.timetable.model.GrafikonException)9 Language (net.parostroj.timetable.model.TextTemplate.Language)2 Color (java.awt.Color)1 Component (java.awt.Component)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ScriptAction (net.parostroj.timetable.actions.scripts.ScriptAction)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 LineTrack (net.parostroj.timetable.model.LineTrack)1 LocalizedString (net.parostroj.timetable.model.LocalizedString)1 NodeTrack (net.parostroj.timetable.model.NodeTrack)1 Script (net.parostroj.timetable.model.Script)1 Language (net.parostroj.timetable.model.Script.Language)1 TextTemplate (net.parostroj.timetable.model.TextTemplate)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 Track (net.parostroj.timetable.model.Track)1 Train (net.parostroj.timetable.model.Train)1 TrainType (net.parostroj.timetable.model.TrainType)1 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)1 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)1