Search in sources :

Example 16 with IniConfigSection

use of net.parostroj.timetable.gui.ini.IniConfigSection in project grafikon by jub77.

the class FloatingWindowsFactory method createCirculationViewDialog.

private static FloatingWindow createCirculationViewDialog(Frame frame, Mediator mediator, ApplicationModel model) {
    final CirculationViewPanel panel = new CirculationViewPanel();
    mediator.addColleague(new ApplicationGTEventColleague() {

        @Override
        public void processApplicationEvent(ApplicationModelEvent event) {
            if (event.getType() == ApplicationModelEventType.SET_DIAGRAM_CHANGED)
                panel.setDiagram(event.getModel().getDiagram());
        }

        @Override
        public void processTrainDiagramEvent(Event event) {
            switch(event.getType()) {
                case ADDED:
                    if (event.getObject() instanceof TrainsCycle) {
                        panel.circulationAdded((TrainsCycle) event.getObject());
                    } else if (event.getObject() instanceof TrainsCycleType) {
                        panel.typeAdded((TrainsCycleType) event.getObject());
                    }
                    break;
                case REMOVED:
                    if (event.getObject() instanceof TrainsCycle) {
                        panel.circulationRemoved((TrainsCycle) event.getObject());
                    } else if (event.getObject() instanceof TrainsCycleType) {
                        panel.typeRemoved((TrainsCycleType) event.getObject());
                    }
                    break;
                case ATTRIBUTE:
                    if (event.getAttributeChange().getName().equals(TrainDiagram.ATTR_FROM_TIME) || event.getAttributeChange().getName().equals(TrainDiagram.ATTR_TO_TIME)) {
                        panel.timeLimitsUpdated();
                    }
                    break;
                default:
                    break;
            }
        }

        @Override
        public void processTrainsCycleEvent(Event event) {
            panel.circulationUpdated((TrainsCycle) event.getSource());
        }
    });
    FloatingWindow dialog = new FloatingDialog(frame, panel, "dialog.circulationview.title", "circulations.view") {

        private static final long serialVersionUID = 1L;

        @Override
        public IniConfigSection saveToPreferences(IniConfig prefs) {
            IniConfigSection section = super.saveToPreferences(prefs);
            section.put("size", panel.getSizeSlider());
            section.put("zoom", panel.getZoomSlider());
            section.put("type", panel.getDrawType());
            return section;
        }

        @Override
        public IniConfigSection loadFromPreferences(IniConfig prefs) {
            IniConfigSection section = super.loadFromPreferences(prefs);
            panel.setSizeSlider(section.get("size", Integer.class, panel.getSizeSlider()));
            panel.setZoomSlider(section.get("zoom", Integer.class, panel.getZoomSlider()));
            panel.setDrawType(section.get("type", String.class, panel.getDrawType()));
            return section;
        }
    };
    return dialog;
}
Also used : IniConfig(net.parostroj.timetable.gui.ini.IniConfig) ListSelectionEvent(javax.swing.event.ListSelectionEvent) IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 17 with IniConfigSection

use of net.parostroj.timetable.gui.ini.IniConfigSection in project grafikon by jub77.

the class FloatingWindowsFactory method createEventsViewerDialog.

private static FloatingWindow createEventsViewerDialog(final Frame frame, final Mediator mediator, final ApplicationModel model) {
    final EventsViewerPanel panel = new EventsViewerPanel();
    panel.addConverter(new GTEventTypeConverter());
    panel.addConverter(new ApplicationEventTypeConverter());
    final FloatingDialog dialog = new FloatingDialog(frame, panel, "dialog.eventsviewer.title", "events.viewer") {

        private static final long serialVersionUID = 1L;

        @Override
        public IniConfigSection saveToPreferences(IniConfig prefs) {
            IniConfigSection section = super.saveToPreferences(prefs);
            section.put("divider", panel.getDividerLocation());
            section.put("limit", panel.getLimit());
            section.put("show.time", panel.isShowTime());
            section.put("write.to.log", panel.isWriteToLog());
            return section;
        }

        @Override
        public IniConfigSection loadFromPreferences(IniConfig prefs) {
            IniConfigSection section = super.loadFromPreferences(prefs);
            int divider = section.get("divider", Integer.class, panel.getDividerLocation());
            panel.setDividerLocation(divider);
            int limit = section.get("limit", Integer.class, panel.getLimit());
            panel.setLimit(limit);
            panel.setShowTime(section.get("show.time", Boolean.class, false));
            panel.setWriteToLog(section.get("write.to.log", Boolean.class, false));
            return section;
        }
    };
    mediator.addColleague(new AbstractColleague() {

        @Override
        public void receiveMessage(Object message) {
            // do not process messages when the dialog is not visible ...
            if (!dialog.isVisible())
                return;
            panel.addEvent(message);
        }
    });
    return dialog;
}
Also used : IniConfig(net.parostroj.timetable.gui.ini.IniConfig) AbstractColleague(net.parostroj.timetable.mediator.AbstractColleague) IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 18 with IniConfigSection

use of net.parostroj.timetable.gui.ini.IniConfigSection in project grafikon by jub77.

the class FloatingWindowsFactory method createGTViewDialog.

private static FloatingWindow createGTViewDialog(Frame frame, Mediator mediator, ApplicationModel model) {
    final GraphicalTimetableView gtView = new GraphicalTimetableView();
    final GTLayeredPane2 scrollPane = new GTLayeredPane2(gtView);
    NormalHTS hts = new NormalHTS(model, Color.GREEN, gtView);
    gtView.setParameter(GTDraw.HIGHLIGHTED_TRAINS, hts);
    gtView.setRegionSelector(hts, TimeInterval.class);
    FloatingFrame dialog = new FloatingFrame(frame, scrollPane, "dialog.gtview.title", "gt.view") {

        private static final long serialVersionUID = 1L;

        @Override
        public IniConfigSection saveToPreferences(IniConfig prefs) {
            IniConfigSection section = super.saveToPreferences(prefs);
            section.put("gtv", gtView.getSettings().getStorageString());
            return section;
        }

        @Override
        public IniConfigSection loadFromPreferences(IniConfig prefs) {
            IniConfigSection section = super.loadFromPreferences(prefs);
            try {
                GTViewSettings gtvs = GTViewSettings.parseStorageString(section.get("gtv"));
                gtView.setSettings(gtView.getSettings().merge(gtvs));
            } catch (Exception e) {
                log.warn("Wrong GTView settings - using default values.");
            }
            return section;
        }
    };
    return dialog;
}
Also used : IniConfig(net.parostroj.timetable.gui.ini.IniConfig) NormalHTS(net.parostroj.timetable.gui.utils.NormalHTS) IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 19 with IniConfigSection

use of net.parostroj.timetable.gui.ini.IniConfigSection in project grafikon by jub77.

the class GuiContextImpl method loadFromPreferences.

@Override
public IniConfigSection loadFromPreferences(IniConfig prefs) {
    IniConfigSection section = prefs.getSection(INI_SECTION);
    section.entrySet().stream().forEach(entry -> dataMap.put(entry.getKey(), this.dataFromString(entry.getValue())));
    this.preferences = prefs;
    return section;
}
Also used : IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 20 with IniConfigSection

use of net.parostroj.timetable.gui.ini.IniConfigSection in project grafikon by jub77.

the class ApplicationModel method saveToPreferences.

@Override
public IniConfigSection saveToPreferences(IniConfig prefs) {
    IniConfigSection section = prefs.getSection("model");
    section.put("output.templates", getSerializedOutputTemplates());
    section.put("user.name", programSettings.getUserName());
    section.put("unit", programSettings.getLengthUnit() != null ? programSettings.getLengthUnit().getKey() : null);
    section.put("unit.speed", programSettings.getSpeedUnit() != null ? programSettings.getSpeedUnit().getKey() : null);
    section.remove("last.opened");
    for (File file : this.lastOpenedFiles) {
        section.add("last.opened", file.getAbsolutePath());
    }
    guiContext.saveToPreferences(prefs);
    return section;
}
Also used : IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection) File(java.io.File)

Aggregations

IniConfigSection (net.parostroj.timetable.gui.ini.IniConfigSection)24 IniConfig (net.parostroj.timetable.gui.ini.IniConfig)4 File (java.io.File)3 GTViewSettings (net.parostroj.timetable.gui.components.GTViewSettings)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ScriptAction (net.parostroj.timetable.actions.scripts.ScriptAction)1 NormalHTS (net.parostroj.timetable.gui.utils.NormalHTS)1 DriverCycleDelegate (net.parostroj.timetable.gui.views.DriverCycleDelegate)1 EngineCycleDelegate (net.parostroj.timetable.gui.views.EngineCycleDelegate)1 TreeType (net.parostroj.timetable.gui.views.TrainListView.TreeType)1 TrainUnitCycleDelegate (net.parostroj.timetable.gui.views.TrainUnitCycleDelegate)1 AbstractColleague (net.parostroj.timetable.mediator.AbstractColleague)1 LengthUnit (net.parostroj.timetable.model.units.LengthUnit)1 SpeedUnit (net.parostroj.timetable.model.units.SpeedUnit)1