Search in sources :

Example 1 with BnButtonGroup

use of net.parostroj.timetable.gui.components.BnButtonGroup 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

BorderLayout (java.awt.BorderLayout)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 javax.swing (javax.swing)1 BnButtonGroup (net.parostroj.timetable.gui.components.BnButtonGroup)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 Pair (net.parostroj.timetable.utils.Pair)1 Path (org.beanfabrics.Path)1