Search in sources :

Example 1 with SwingShutDownTask

use of jmri.implementation.swing.SwingShutDownTask in project JMRI by JMRI.

the class ImageIndexEditor method indexChanged.

public static final synchronized void indexChanged(boolean changed) {
    _indexChanged = changed;
    if (jmri.InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
        if (changed) {
            if (_shutDownTask == null) {
                _shutDownTask = new SwingShutDownTask("PanelPro Save default icon check", Bundle.getMessage("IndexChanged"), Bundle.getMessage("SaveAndQuit"), null) {

                    @Override
                    public boolean checkPromptNeeded() {
                        return !_indexChanged;
                    }

                    @Override
                    public boolean doPrompt() {
                        storeImageIndex();
                        return true;
                    }
                };
                jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(_shutDownTask);
            }
        } else {
            if (_shutDownTask != null) {
                jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).deregister(_shutDownTask);
                _shutDownTask = null;
            }
        }
    }
}
Also used : SwingShutDownTask(jmri.implementation.swing.SwingShutDownTask)

Example 2 with SwingShutDownTask

use of jmri.implementation.swing.SwingShutDownTask in project JMRI by JMRI.

the class PaneProgFrame method installComponents.

protected void installComponents() {
    // create ShutDownTasks
    if (jmri.InstanceManager.getNullableDefault(jmri.ShutDownManager.class) != null) {
        if (decoderDirtyTask == null) {
            decoderDirtyTask = new SwingShutDownTask("DecoderPro Decoder Window Check", Bundle.getMessage("PromptQuitWindowNotWrittenDecoder"), (String) null, this) {

                @Override
                public boolean checkPromptNeeded() {
                    return !checkDirtyDecoder();
                }
            };
        }
        jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(decoderDirtyTask);
        if (fileDirtyTask == null) {
            fileDirtyTask = new SwingShutDownTask("DecoderPro Decoder Window Check", Bundle.getMessage("PromptQuitWindowNotWrittenConfig"), Bundle.getMessage("PromptSaveQuit"), this) {

                @Override
                public boolean checkPromptNeeded() {
                    return !checkDirtyFile();
                }

                @Override
                public boolean doPrompt() {
                    // storeFile false if failed, abort shutdown
                    boolean result = storeFile();
                    return result;
                }
            };
        }
        jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(fileDirtyTask);
    }
    // Create a menu bar
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    // add a "File" menu
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    menuBar.add(fileMenu);
    // add a "Factory Reset" menu
    resetMenu = new JMenu(Bundle.getMessage("MenuReset"));
    menuBar.add(resetMenu);
    resetMenu.add(new FactoryResetAction(Bundle.getMessage("MenuFactoryReset"), resetModel, this));
    resetMenu.setEnabled(false);
    // Add a save item
    fileMenu.add(new AbstractAction(Bundle.getMessage("MenuSave")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            storeFile();
        }
    });
    JMenu printSubMenu = new JMenu(Bundle.getMessage("MenuPrint"));
    printSubMenu.add(new PrintAction(Bundle.getMessage("MenuPrintAll"), this, false));
    printSubMenu.add(new PrintCvAction(Bundle.getMessage("MenuPrintCVs"), cvModel, this, false, _rosterEntry));
    fileMenu.add(printSubMenu);
    JMenu printPreviewSubMenu = new JMenu(Bundle.getMessage("MenuPrintPreview"));
    printPreviewSubMenu.add(new PrintAction(Bundle.getMessage("MenuPrintPreviewAll"), this, true));
    printPreviewSubMenu.add(new PrintCvAction(Bundle.getMessage("MenuPrintPreviewCVs"), cvModel, this, true, _rosterEntry));
    fileMenu.add(printPreviewSubMenu);
    // add "Import" submenu; this is heirarchical because
    // some of the names are so long, and we expect more formats
    JMenu importSubMenu = new JMenu(Bundle.getMessage("MenuImport"));
    fileMenu.add(importSubMenu);
    importSubMenu.add(new CsvImportAction(Bundle.getMessage("MenuImportCSV"), cvModel, this, progStatus));
    importSubMenu.add(new Pr1ImportAction(Bundle.getMessage("MenuImportPr1"), cvModel, this, progStatus));
    importSubMenu.add(new LokProgImportAction(Bundle.getMessage("MenuImportLokProg"), cvModel, this, progStatus));
    importSubMenu.add(new QuantumCvMgrImportAction(Bundle.getMessage("MenuImportQuantumCvMgr"), cvModel, this, progStatus));
    // add "Export" submenu; this is heirarchical because
    // some of the names are so long, and we expect more formats
    JMenu exportSubMenu = new JMenu(Bundle.getMessage("MenuExport"));
    fileMenu.add(exportSubMenu);
    exportSubMenu.add(new CsvExportAction(Bundle.getMessage("MenuExportCSV"), cvModel, this));
    exportSubMenu.add(new Pr1ExportAction(Bundle.getMessage("MenuExportPr1DOS"), cvModel, this));
    exportSubMenu.add(new Pr1WinExportAction(Bundle.getMessage("MenuExportPr1WIN"), cvModel, this));
    // to control size, we need to insert a single
    // JPanel, then have it laid out with BoxLayout
    JPanel pane = new JPanel();
    tempPane = pane;
    // general GUI config
    pane.setLayout(new BorderLayout());
    // configure GUI elements
    // set read buttons enabled state, tooltips
    enableReadButtons();
    readChangesButton.addItemListener(l1 = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                prepGlassPane(readChangesButton);
                readChangesButton.setText(Bundle.getMessage("ButtonStopReadChangesAll"));
                readChanges();
            } else {
                if (_programmingPane != null) {
                    _programmingPane.stopProgramming();
                }
                paneListIndex = paneList.size();
                readChangesButton.setText(Bundle.getMessage("ButtonReadChangesAllSheets"));
            }
        }
    });
    readAllButton.addItemListener(l3 = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                prepGlassPane(readAllButton);
                readAllButton.setText(Bundle.getMessage("ButtonStopReadAll"));
                readAll();
            } else {
                if (_programmingPane != null) {
                    _programmingPane.stopProgramming();
                }
                paneListIndex = paneList.size();
                readAllButton.setText(Bundle.getMessage("ButtonReadAllSheets"));
            }
        }
    });
    writeChangesButton.setToolTipText(Bundle.getMessage("TipWriteHighlightedValues"));
    writeChangesButton.addItemListener(l2 = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                prepGlassPane(writeChangesButton);
                writeChangesButton.setText(Bundle.getMessage("ButtonStopWriteChangesAll"));
                writeChanges();
            } else {
                if (_programmingPane != null) {
                    _programmingPane.stopProgramming();
                }
                paneListIndex = paneList.size();
                writeChangesButton.setText(Bundle.getMessage("ButtonWriteChangesAllSheets"));
            }
        }
    });
    writeAllButton.setToolTipText(Bundle.getMessage("TipWriteAllValues"));
    writeAllButton.addItemListener(l4 = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                prepGlassPane(writeAllButton);
                writeAllButton.setText(Bundle.getMessage("ButtonStopWriteAll"));
                writeAll();
            } else {
                if (_programmingPane != null) {
                    _programmingPane.stopProgramming();
                }
                paneListIndex = paneList.size();
                writeAllButton.setText(Bundle.getMessage("ButtonWriteAllSheets"));
            }
        }
    });
    // most of the GUI is done from XML in readConfig() function
    // which configures the tabPane
    pane.add(tabPane, BorderLayout.CENTER);
    // and put that pane into the JFrame
    getContentPane().add(pane);
    // add help
    addHelp();
}
Also used : Pr1ExportAction(jmri.jmrit.symbolicprog.Pr1ExportAction) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) PrintAction(jmri.jmrit.symbolicprog.PrintAction) ActionEvent(java.awt.event.ActionEvent) Pr1ImportAction(jmri.jmrit.symbolicprog.Pr1ImportAction) QuantumCvMgrImportAction(jmri.jmrit.symbolicprog.QuantumCvMgrImportAction) CsvExportAction(jmri.jmrit.symbolicprog.CsvExportAction) BorderLayout(java.awt.BorderLayout) CsvImportAction(jmri.jmrit.symbolicprog.CsvImportAction) PrintCvAction(jmri.jmrit.symbolicprog.PrintCvAction) LokProgImportAction(jmri.jmrit.symbolicprog.LokProgImportAction) ItemListener(java.awt.event.ItemListener) SwingShutDownTask(jmri.implementation.swing.SwingShutDownTask) Pr1WinExportAction(jmri.jmrit.symbolicprog.Pr1WinExportAction) FactoryResetAction(jmri.jmrit.symbolicprog.FactoryResetAction) AbstractAction(javax.swing.AbstractAction) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 3 with SwingShutDownTask

use of jmri.implementation.swing.SwingShutDownTask in project JMRI by JMRI.

the class WarrantTableAction method makeLogMenu.

protected static JMenuItem makeLogMenu() {
    JMenuItem mi;
    if (!_logging) {
        mi = new JMenuItem(Bundle.getMessage("startLog"));
        mi.addActionListener((ActionEvent e) -> {
            if (!OpSessionLog.makeLogFile(WarrantTableFrame.getDefault())) {
                return;
            }
            _logging = true;
            _shutDownTask = new SwingShutDownTask("PanelPro Save default icon check", null, null, null) {

                @Override
                public boolean checkPromptNeeded() {
                    OpSessionLog.close();
                    _logging = false;
                    return true;
                }
            };
            jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).register(_shutDownTask);
            updateWarrantMenu();
        });
    } else {
        mi = new JMenuItem(Bundle.getMessage("stopLog"));
        mi.addActionListener((ActionEvent e) -> {
            OpSessionLog.close();
            jmri.InstanceManager.getDefault(jmri.ShutDownManager.class).deregister(_shutDownTask);
            _shutDownTask = null;
            _logging = false;
            updateWarrantMenu();
        });
    }
    return mi;
}
Also used : ActionEvent(java.awt.event.ActionEvent) SwingShutDownTask(jmri.implementation.swing.SwingShutDownTask) JMenuItem(javax.swing.JMenuItem)

Aggregations

SwingShutDownTask (jmri.implementation.swing.SwingShutDownTask)3 ActionEvent (java.awt.event.ActionEvent)2 BorderLayout (java.awt.BorderLayout)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 AbstractAction (javax.swing.AbstractAction)1 JMenu (javax.swing.JMenu)1 JMenuBar (javax.swing.JMenuBar)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 CsvExportAction (jmri.jmrit.symbolicprog.CsvExportAction)1 CsvImportAction (jmri.jmrit.symbolicprog.CsvImportAction)1 FactoryResetAction (jmri.jmrit.symbolicprog.FactoryResetAction)1 LokProgImportAction (jmri.jmrit.symbolicprog.LokProgImportAction)1 Pr1ExportAction (jmri.jmrit.symbolicprog.Pr1ExportAction)1 Pr1ImportAction (jmri.jmrit.symbolicprog.Pr1ImportAction)1 Pr1WinExportAction (jmri.jmrit.symbolicprog.Pr1WinExportAction)1 PrintAction (jmri.jmrit.symbolicprog.PrintAction)1 PrintCvAction (jmri.jmrit.symbolicprog.PrintCvAction)1 QuantumCvMgrImportAction (jmri.jmrit.symbolicprog.QuantumCvMgrImportAction)1