Search in sources :

Example 6 with Pair

use of net.parostroj.timetable.utils.Pair in project grafikon by jub77.

the class LSAttributesItem method extractSimpleValue.

private LSAttributesValue extractSimpleValue(String key, Object value) {
    LSAttributesValue cValue = null;
    if (value instanceof String) {
        cValue = new LSAttributesValue((String) value, "string");
    } else if (value instanceof Boolean) {
        cValue = new LSAttributesValue(value.toString(), "boolean");
    } else if (value instanceof Integer) {
        cValue = new LSAttributesValue(value.toString(), "integer");
    } else if (value instanceof Long) {
        cValue = new LSAttributesValue(value.toString(), "long");
    } else if (value instanceof Float) {
        cValue = new LSAttributesValue(value.toString(), "float");
    } else if (value instanceof Double) {
        cValue = new LSAttributesValue(value.toString(), "double");
    } else if (value instanceof Scale) {
        cValue = new LSAttributesValue(value.toString(), "scale");
    } else if (value instanceof FreightColor) {
        cValue = new LSAttributesValue(((FreightColor) value).getKey(), "freight.color");
    } else if (value instanceof LengthUnit) {
        cValue = new LSAttributesValue(((LengthUnit) value).getKey(), "length.unit");
    } else if (value instanceof WeightUnit) {
        cValue = new LSAttributesValue(((WeightUnit) value).getKey(), "weight.unit");
    } else if (value instanceof Locale) {
        cValue = new LSAttributesValue(((Locale) value).toLanguageTag(), "locale");
    } else if (value instanceof TextTemplate) {
        TextTemplate tt = (TextTemplate) value;
        cValue = new LSAttributesValue(tt.getTemplate(), TEXT_TEMPLATE_KEY_PREFIX + tt.getLanguage().name());
    } else if (value instanceof Script) {
        Script script = (Script) value;
        cValue = new LSAttributesValue(script.getSourceCode(), SCRIPT_KEY_PREFIX + script.getLanguage().name());
    } else if (value instanceof ObjectWithId) {
        Pair<String, String> pair = this.convertToId((ObjectWithId) value);
        cValue = new LSAttributesValue(pair.second, pair.first);
    } else if (value instanceof StringWithLocale) {
        StringWithLocale stringWithLocale = (StringWithLocale) value;
        cValue = new LSAttributesValue(stringWithLocale.getString(), "string." + stringWithLocale.getLocale().toLanguageTag());
    } else {
        log.warn("Cannot convert value to string: {}", key);
    }
    return cValue;
}
Also used : StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) WeightUnit(net.parostroj.timetable.model.units.WeightUnit) LengthUnit(net.parostroj.timetable.model.units.LengthUnit) StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) Pair(net.parostroj.timetable.utils.Pair)

Example 7 with Pair

use of net.parostroj.timetable.utils.Pair in project grafikon by jub77.

the class DefaultTrainTypeListSource method getDefaultTypeList.

public static Pair<TrainsDataDto, List<TrainType>> getDefaultTypeList() throws LSException {
    try {
        LSTrainTypeSerializer serializer = LSTrainTypeSerializer.getLSTrainTypeSerializer(LSSerializer.getLatestVersion());
        LSTrainTypeList lsList = serializer.load(new InputStreamReader(DefaultTrainTypeListSource.getDefaultTypesInputStream(), "utf-8"));
        return new Pair<TrainsDataDto, List<TrainType>>(lsList.getTrainsData(), lsList.getTrainTypeList());
    } catch (UnsupportedEncodingException e) {
        throw new LSException("Cannot load default train type list.", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TrainType(net.parostroj.timetable.model.TrainType) LSException(net.parostroj.timetable.model.ls.LSException) Pair(net.parostroj.timetable.utils.Pair)

Example 8 with Pair

use of net.parostroj.timetable.utils.Pair in project grafikon by jub77.

the class MainFrame method initComponents.

private void initComponents() {
    javax.swing.JTabbedPane tabbedPane = new javax.swing.JTabbedPane();
    trainsPane = new net.parostroj.timetable.gui.panes.TrainsPane();
    engineCyclesPane = new net.parostroj.timetable.gui.panes.TrainsCyclesPane();
    trainUnitCyclesPane = new net.parostroj.timetable.gui.panes.TrainsCyclesPane();
    driverCyclesPane = new net.parostroj.timetable.gui.panes.TrainsCyclesPane();
    netPane = new net.parostroj.timetable.gui.panes.NetPane();
    circulationPane = new net.parostroj.timetable.gui.panes.CirculationPane();
    freightNetPane2 = new net.parostroj.timetable.gui.panes.FreightNetPane2();
    statusBar = new net.parostroj.timetable.gui.StatusBar();
    javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    javax.swing.JMenu languageMenu = new javax.swing.JMenu();
    javax.swing.JMenu lookAndFeelMenu = new javax.swing.JMenu();
    javax.swing.JMenu diagramMenu = new javax.swing.JMenu();
    javax.swing.JMenu actionMenu = new javax.swing.JMenu();
    javax.swing.JMenuItem oLanguageMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenu viewsMenu = new javax.swing.JMenu();
    javax.swing.JMenu specialMenu = new javax.swing.JMenu();
    scriptsMenuModel = new javax.swing.JMenu();
    scriptsMenuGui = new javax.swing.JMenu();
    javax.swing.JMenu settingsMenu = new javax.swing.JMenu();
    javax.swing.JMenu helpMenu = new javax.swing.JMenu();
    floatingDialogsList = FloatingWindowsFactory.createDialogs(this, model.getMediator(), model);
    floatingDialogsList.addToMenuItem(viewsMenu);
    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    setTitle(frameTitle.getTitleString(false));
    setLocationByPlatform(true);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.trains"), trainsPane);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.engine.cycles"), engineCyclesPane);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.trainunit.cycle"), trainUnitCyclesPane);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.driver.cycles"), driverCyclesPane);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.net"), netPane);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.circulations"), circulationPane);
    // NOI18N
    tabbedPane.addTab(ResourceLoader.getString("tab.freight.net"), freightNetPane2);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(tabbedPane, BorderLayout.CENTER);
    getContentPane().add(statusBar, BorderLayout.SOUTH);
    // NOI18N
    tabbedPane.getAccessibleContext().setAccessibleName(ResourceLoader.getString("tab.trains"));
    // NOI18N
    fileMenu.setText(ResourceLoader.getString("menu.file"));
    TemplateLoader<TrainDiagram> loader = TemplateLoader.getDefault(TrainDiagram.class);
    // NOI18N
    this.addMenuItem(fileMenu, "menu.file.new", new NewOpenAction(model, this, loader), "new", false, null);
    try {
        this.addMenuItem(fileMenu, "menu.file.new.default.url", new NewOpenAction(model, this, TemplateLoader.getFromUrl(new URL(model.getTemplatesBaseUrl()), TrainDiagram.class)), "new", false, // NOI18N
        null);
    } catch (MalformedURLException mue) {
        log.warn(mue.getMessage(), mue);
    }
    fileMenu.add(new javax.swing.JSeparator());
    // NOI18N
    this.addMenuItem(fileMenu, "menu.file.open", new NewOpenAction(model, this, null), "open", false, javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
    // NOI18N
    this.addMenuItem(fileMenu, "menu.file.save", new SaveAction(model), "save", true, javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
    // NOI18N
    this.addMenuItem(fileMenu, "menu.file.saveas", new SaveAction(model), "save_as", true, javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
    fileMenu.add(new javax.swing.JSeparator());
    // NOI18N
    javax.swing.JMenu importMenu = new javax.swing.JMenu(ResourceLoader.getString("menu.file.importmenu"));
    fileMenu.add(importMenu);
    // NOI18N
    this.addMenuItem(importMenu, "menu.file.exportimport", new ImportAction(model, this, false, true), null);
    // NOI18N
    this.addMenuItem(importMenu, "menu.file.exportimport.trains", new ImportAction(model, this, true, false), null);
    // NOI18N
    this.addMenuItem(importMenu, "menu.file.outputs.import.replace", new ImportReplaceOutputTemplatesAction(model), null);
    // NOI18N
    this.addMenuItem(importMenu, "menu.file.outputs.import.replace.default.url", new ImportReplaceOutputTemplatesUrlAction(model), null);
    // NOI18N
    this.addMenuItem(fileMenu, "menu.file.library.export", new ExportAction(model, this), null);
    fileMenu.add(new javax.swing.JSeparator());
    // NOI18N
    languageMenu.setText(ResourceLoader.getString("menu.language"));
    fileMenu.add(languageMenu);
    // NOI18N
    lookAndFeelMenu.setText(ResourceLoader.getString("menu.lookandfeel"));
    fileMenu.add(lookAndFeelMenu);
    fileMenu.add(new javax.swing.JSeparator());
    fileMenu.add(new javax.swing.JSeparator());
    // NOI18N
    this.addMenuItem(fileMenu, "menu.file.exit", new ExitAction(model, this), null, false);
    menuBar.add(fileMenu);
    // NOI18N
    diagramMenu.setText(ResourceLoader.getString("menu.diagram"));
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.settings", this::settingsMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.info", this::infoMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.traintypes", this::trainTypesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.lineclasses", this::lineClassesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.weighttables", this::weightTablesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.penaltytable", this::penaltyTableMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.regions", this::regionsMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.companies", this::companiesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "localization.languages", this::languagesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.localization", this::localizationMenuItemActionPerformed, true);
    this.addMenuItem(diagramMenu, "menu.groups", new EditGroupsAction(model), null);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.images", this::imagesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "menu.file.textitems", this::textItemsMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(diagramMenu, "gt.routes.edit", this::editRoutesMenuItemActionPerformed, true);
    menuBar.add(diagramMenu);
    // NOI18N
    actionMenu.setText(ResourceLoader.getString("menu.outputs"));
    // NOI18N
    oLanguageMenuItem.setText(ResourceLoader.getString("menu.language.output") + "...");
    actionMenu.add(oLanguageMenuItem);
    // NOI18N
    this.addMenuItemWithListener(actionMenu, "menu.action.user.output.templates", this::ouputTemplatesMenuItemActionPerformed, true);
    // NOI18N
    this.addMenuItemWithListener(actionMenu, "menu.action.user.outputs", this::ouputMenuItemActionPerformed, true);
    menuBar.add(actionMenu);
    // NOI18N
    viewsMenu.setText(ResourceLoader.getString("menu.views"));
    menuBar.add(viewsMenu);
    // NOI18N
    specialMenu.setText(ResourceLoader.getString("menu.special.scripts"));
    // NOI18N
    this.addMenuItem(specialMenu, "menu.special.execute.script", executeScriptAction, "");
    specialMenu.add(new javax.swing.JSeparator());
    // NOI18N
    scriptsMenuModel.setText(ResourceLoader.getString("menu.special.predefined.scripts.model"));
    specialMenu.add(scriptsMenuModel);
    // NOI18N
    scriptsMenuGui.setText(ResourceLoader.getString("menu.special.predefined.scripts.gui"));
    specialMenu.add(scriptsMenuGui);
    specialMenu.add(new javax.swing.JSeparator());
    // NOI18N
    this.addMenuItem(specialMenu, "menu.special.recalculate", new RecalculateAction(model), null);
    // NOI18N
    this.addMenuItem(specialMenu, "menu.special.recalculate.stops", new RecalculateStopsAction(model), null);
    // NOI18N
    this.addMenuItem(specialMenu, "menu.special.remove.weights", new RemoveWeightsAction(model), null);
    menuBar.add(specialMenu);
    // NOI18N
    settingsMenu.setText(ResourceLoader.getString("menu.settings"));
    // NOI18N
    this.addMenuItemWithListener(settingsMenu, "menu.settings.columns", evt -> trainsPane.editColumns(), false);
    // NOI18N
    this.addMenuItemWithListener(settingsMenu, "menu.settings.sort.columns", evt -> trainsPane.sortColumns(), false);
    // NOI18N
    this.addMenuItemWithListener(settingsMenu, "menu.settings.resize.columns", evt -> trainsPane.resizeColumns(), false);
    // NOI18N
    showGTViewMenuItem = this.addCheckMenuItem(settingsMenu, "menu.settings.show.gtview", this::showGTViewMenuItemActionPerformed, null, true);
    // NOI18N
    this.addMenuItemWithListener(settingsMenu, "menu.program.settings", this::programSettingsMenuItemActionPerformed, false);
    menuBar.add(settingsMenu);
    // NOI18N
    helpMenu.setText(ResourceLoader.getString("menu.help"));
    // NOI18N
    this.addMenuItemWithListener(helpMenu, "menu.help.about", this::aboutMenuItemActionPerformed, false);
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(helpMenu);
    setJMenuBar(menuBar);
    // enabled list
    enabledComponents.add(tabbedPane);
    enabledComponents.add(scriptsMenuModel);
    enabledComponents.add(scriptsMenuGui);
    setMinimumSize(new java.awt.Dimension(800, 600));
    setSize(getMinimumSize());
    trainUnitCyclesPane.setKey("cycles.trainunit");
    driverCyclesPane.setKey("cycles.driver");
    engineCyclesPane.setKey("cycles.engine");
    // add languages to menu
    LanguageMenuBuilder languageMenuBuilder = new LanguageMenuBuilder(model.getLanguageLoader());
    List<Pair<JRadioButtonMenuItem, Locale>> lItems = languageMenuBuilder.createLanguageMenuItems(ResourceLoader.getString("menu.language.system"), LanguagesType.GUI);
    BnButtonGroup<Locale> lBGroup = new BnButtonGroup<>();
    for (Pair<JRadioButtonMenuItem, Locale> item : lItems) {
        languageMenu.add(item.first);
        lBGroup.add(item.first, item.second);
    }
    lBGroup.setModelProvider(provider);
    lBGroup.setPath(new Path("locale"));
    // output language
    oLanguageMenuItem.addActionListener(e -> {
        String system = ResourceLoader.getString("menu.language.system");
        LanguageLoader languageLoader = model.getLanguageLoader();
        List<Wrapper<Locale>> values = languageLoader.createWrappers(languageLoader.getAvailableLocales(), system);
        Collections.sort(values);
        Locale oLocale = model.getOutputSettings().getLocale();
        Wrapper<?> selected = (Wrapper<?>) JOptionPane.showInputDialog(this, null, null, JOptionPane.QUESTION_MESSAGE, null, values.toArray(), oLocale == null ? Wrapper.getEmptyWrapper("") : Wrapper.getWrapper(oLocale));
        if (selected != null) {
            Locale sLocale = (Locale) selected.getElement();
            model.getOutputSettings().setLocale(sLocale);
        }
    });
    // look and feel
    BnButtonGroup<String> lafBGroup = new BnButtonGroup<>();
    for (String key : model.lookAndFeel.getValues()) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(model.lookAndFeel.getOptions().get(key));
        lafBGroup.add(item, key);
        lookAndFeelMenu.add(item);
    }
    lafBGroup.setModelProvider(provider);
    lafBGroup.setPath(new Path("lookAndFeel"));
}
Also used : MalformedURLException(java.net.MalformedURLException) BorderLayout(java.awt.BorderLayout) Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) BnButtonGroup(net.parostroj.timetable.gui.components.BnButtonGroup) URL(java.net.URL) Pair(net.parostroj.timetable.utils.Pair) Path(org.beanfabrics.Path) javax.swing(javax.swing)

Aggregations

Pair (net.parostroj.timetable.utils.Pair)8 TimeInterval (net.parostroj.timetable.model.TimeInterval)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Train (net.parostroj.timetable.model.Train)2 TrainType (net.parostroj.timetable.model.TrainType)2 BorderLayout (java.awt.BorderLayout)1 GridLayout (java.awt.GridLayout)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 javax.swing (javax.swing)1 JCheckBox (javax.swing.JCheckBox)1 ElementSort (net.parostroj.timetable.actions.ElementSort)1 TrainComparator (net.parostroj.timetable.actions.TrainComparator)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1