Search in sources :

Example 6 with IniConfigSection

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

the class GuiContextImpl method saveToPreferences.

@Override
public IniConfigSection saveToPreferences(IniConfig prefs) {
    IniConfigSection section = prefs.getSection(INI_SECTION);
    dataMap.entrySet().forEach(entry -> section.put(entry.getKey(), this.dataToString(entry.getValue())));
    preferencesMap.entrySet().forEach(entry -> {
        IniConfigSection windowSection = prefs.getSection(entry.getKey());
        if (entry.getValue() == null) {
            windowSection.removeSection();
        } else {
            windowSection.clear();
            windowSection.putAll(entry.getValue());
        }
    });
    return section;
}
Also used : IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 7 with IniConfigSection

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

the class MainFrame method loadFromPreferences.

@Override
public IniConfigSection loadFromPreferences(IniConfig prefs) {
    IniConfigSection section = prefs.getSection("main");
    if (section.get("maximized", Boolean.class, false)) {
        // setting maximized state
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
    } else {
        if (section.containsKey("position")) {
            // set position
            GuiUtils.setPosition(section.get("position"), this);
        }
    }
    // load look and feel
    String laf = section.get("look.and.feel", "system");
    model.lookAndFeel.setValue(laf);
    showGTViewMenuItem.setSelected(prefs.getSection("trains").get("show.gtview", Boolean.class, true));
    // load preferences for last file chooser directories
    FileChooserFactory.getInstance().loadFromPreferences(prefs);
    trainsPane.loadFromPreferences(prefs);
    floatingDialogsList.loadFromPreferences(prefs);
    model.loadFromPreferences(prefs);
    trainUnitCyclesPane.loadFromPreferences(prefs);
    driverCyclesPane.loadFromPreferences(prefs);
    engineCyclesPane.loadFromPreferences(prefs);
    circulationPane.loadFromPreferences(prefs);
    freightNetPane2.loadFromPreferences(prefs);
    return section;
}
Also used : IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 8 with IniConfigSection

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

the class MainFrame method initializeFrame.

/**
 * initializes frame.
 */
private void initializeFrame() {
    provider.setPresentationModel(model);
    lastOpened = new HashMap<>();
    // set local before anything else
    String loadedLocale = null;
    try {
        IniConfigSection section = AppPreferences.getPreferences().getSection("main");
        loadedLocale = section.get("locale.program");
        String templateLocale = section.get("locale.output");
        if (loadedLocale != null) {
            Locale locale = ModelUtils.parseLocale(loadedLocale);
            model.setLocale(locale);
            Locale.setDefault(locale);
        } else {
            model.setLocale(null);
        }
        if (templateLocale != null) {
            model.getOutputSettings().setLocale(ModelUtils.parseLocale(templateLocale));
        }
    } catch (IOException e) {
        log.warn("Cannot load preferences.", e);
    }
    log.debug("Locale: {}", Locale.getDefault());
    executeScriptAction = new ExecuteScriptAction(model);
    initComponents();
    this.addWindowListener(new MainFrameWindowListener(model, this));
    trainsPane.setModel(model);
    engineCyclesPane.setModel(new EngineCycleDelegate(model), interval -> {
        TrainsCycleType type = interval.getTrain().getDiagram().getEngineCycleType();
        if (!interval.getTrain().isCovered(type, interval)) {
            return Color.black;
        } else {
            return Color.gray;
        }
    });
    trainUnitCyclesPane.setModel(new TrainUnitCycleDelegate(model), interval -> {
        TrainsCycleType type = interval.getTrain().getDiagram().getTrainUnitCycleType();
        if (!interval.getTrain().isCovered(type, interval)) {
            return Color.black;
        } else {
            return Color.gray;
        }
    });
    driverCyclesPane.setModel(new DriverCycleDelegate(model), interval -> {
        TrainsCycleType type = interval.getTrain().getDiagram().getDriverCycleType();
        if (!interval.getTrain().isCovered(type, interval)) {
            return Color.black;
        } else {
            return Color.gray;
        }
    });
    circulationPane.setModel(model);
    freightNetPane2.setModel(model);
    model.addListener(this);
    model.addListener(statusBar);
    netPane.setModel(model);
    this.updateView();
    model.setDiagram(null);
    // apply preferences
    try {
        this.loadFromPreferences(AppPreferences.getPreferences());
    } catch (IOException e) {
        log.error("Error loading preferences.", e);
    }
    // add predefined scripts
    for (ScriptAction sd : model.getScriptsLoader().getScriptActions()) {
        addScriptAction(sd, ExecuteScriptAction.MODEL_PREFIX, scriptsMenuModel);
    }
    // add gui scripts
    for (ScriptAction sd : model.getGuiScriptsLoader().getScriptActions()) {
        addScriptAction(sd, ExecuteScriptAction.GUI_PREFIX, scriptsMenuGui);
    }
    statusBar.setModel(model);
}
Also used : EngineCycleDelegate(net.parostroj.timetable.gui.views.EngineCycleDelegate) DriverCycleDelegate(net.parostroj.timetable.gui.views.DriverCycleDelegate) IOException(java.io.IOException) ScriptAction(net.parostroj.timetable.actions.scripts.ScriptAction) IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection) TrainUnitCycleDelegate(net.parostroj.timetable.gui.views.TrainUnitCycleDelegate)

Example 9 with IniConfigSection

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

the class MainFrame method saveToPreferences.

@Override
public IniConfigSection saveToPreferences(IniConfig prefs) {
    boolean maximized = (this.getExtendedState() & JFrame.MAXIMIZED_BOTH) != 0;
    IniConfigSection section = prefs.getSection("main");
    section.put("maximized", maximized);
    if (!maximized) {
        // set position
        String positionStr = GuiUtils.getPosition(this);
        section.put("position", positionStr);
    } else {
        section.remove("position");
    }
    // save to preferences last file chooser directories
    FileChooserFactory.getInstance().saveToPreferences(prefs);
    // save locales
    Locale locale = model.getLocale();
    section.put("locale.program", locale != null ? locale.toLanguageTag() : null);
    section.put("locale.output", model.getOutputSettings().getLocale() != null ? model.getOutputSettings().getLocale().toLanguageTag() : null);
    // save look and feel
    section.put("look.and.feel", model.lookAndFeel.getValue());
    trainsPane.saveToPreferences(prefs);
    floatingDialogsList.saveToPreferences(prefs);
    model.saveToPreferences(prefs);
    trainUnitCyclesPane.saveToPreferences(prefs);
    driverCyclesPane.saveToPreferences(prefs);
    engineCyclesPane.saveToPreferences(prefs);
    circulationPane.saveToPreferences(prefs);
    freightNetPane2.saveToPreferences(prefs);
    return section;
}
Also used : IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection)

Example 10 with IniConfigSection

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

the class ApplicationModel method loadFromPreferences.

@Override
public IniConfigSection loadFromPreferences(IniConfig prefs) {
    guiContext.loadFromPreferences(prefs);
    IniConfigSection section = prefs.getSection("model");
    deserializeOutputTemplates(section.get("output.templates", ""));
    programSettings.setUserName(section.get("user.name"));
    LengthUnit lengthUnit = LengthUnit.getByKey(section.get("unit", "mm"));
    SpeedUnit speedUnit = SpeedUnit.getByKey(section.get("unit.speed", "kmph"));
    programSettings.setLengthUnit(lengthUnit != null ? lengthUnit : LengthUnit.MM);
    programSettings.setSpeedUnit(speedUnit != null ? speedUnit : SpeedUnit.KMPH);
    List<String> filenames = section.getAll("last.opened");
    if (filenames != null) {
        Collections.reverse(filenames);
        for (String filename : filenames) {
            if (filename != null) {
                this.addLastOpenedFile(new File(filename));
            }
        }
    }
    return section;
}
Also used : SpeedUnit(net.parostroj.timetable.model.units.SpeedUnit) IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection) File(java.io.File) LengthUnit(net.parostroj.timetable.model.units.LengthUnit)

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