Search in sources :

Example 11 with MnemonicHelper

use of com.mucommander.commons.util.ui.helper.MnemonicHelper in project mucommander by mucommander.

the class FileEditorPresenter method show.

@Override
protected void show(AbstractFile file) throws IOException {
    setCurrentFile(file);
    if (fileEditor == null) {
        getFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        getFrame().addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                if (fileEditor != null) {
                    try {
                        fileEditor.close();
                    } catch (CloseCancelledException ex) {
                        return;
                    }
                }
                getFrame().dispose();
            }
        });
        MnemonicHelper menuItemMnemonicHelper = new MnemonicHelper();
        editorMenu.addSeparator();
        closeMenuItem = MenuToolkit.addMenuItem(editorMenu, Translator.get("file_editor.close"), menuItemMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), (e) -> {
            try {
                fileEditor.close();
                getFrame().dispose();
            } catch (CloseCancelledException ex) {
            // cancelled
            }
        });
        editorMenu.add(closeMenuItem);
        try {
            switchFileEditor(0);
        } catch (CloseCancelledException ex) {
            Logger.getLogger(FileViewerPresenter.class.getName()).log(Level.SEVERE, "Unexpected cancellation", ex);
        }
    }
}
Also used : Cursor(java.awt.Cursor) MenuToolkit(com.mucommander.commons.util.ui.helper.MenuToolkit) EditorPresenter(com.mucommander.viewer.EditorPresenter) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) JMenuItem(javax.swing.JMenuItem) MnemonicHelper(com.mucommander.commons.util.ui.helper.MnemonicHelper) FileEditorService(com.mucommander.viewer.FileEditorService) JFrame(javax.swing.JFrame) Translator(com.mucommander.text.Translator) CloseCancelledException(com.mucommander.viewer.CloseCancelledException) FileEditor(com.mucommander.viewer.FileEditor) JComponent(javax.swing.JComponent) JMenuBar(javax.swing.JMenuBar) KeyStroke(javax.swing.KeyStroke) ButtonGroup(javax.swing.ButtonGroup) JMenu(javax.swing.JMenu) IOException(java.io.IOException) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Logger(java.util.logging.Logger) WindowEvent(java.awt.event.WindowEvent) List(java.util.List) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) AbstractFile(com.mucommander.commons.file.AbstractFile) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) CloseCancelledException(com.mucommander.viewer.CloseCancelledException) MnemonicHelper(com.mucommander.commons.util.ui.helper.MnemonicHelper)

Aggregations

MnemonicHelper (com.mucommander.commons.util.ui.helper.MnemonicHelper)11 JMenuItem (javax.swing.JMenuItem)6 MenuToolkit (com.mucommander.commons.util.ui.helper.MenuToolkit)5 Translator (com.mucommander.text.Translator)5 KeyEvent (java.awt.event.KeyEvent)5 JMenu (javax.swing.JMenu)5 KeyStroke (javax.swing.KeyStroke)5 AbstractFile (com.mucommander.commons.file.AbstractFile)4 JComponent (javax.swing.JComponent)4 JMenuBar (javax.swing.JMenuBar)4 ArrayList (java.util.ArrayList)3 Nonnull (javax.annotation.Nonnull)3 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)3 JButton (javax.swing.JButton)3 ButtonChoicePanel (com.mucommander.commons.util.ui.button.ButtonChoicePanel)2 DialogOwner (com.mucommander.commons.util.ui.dialog.DialogOwner)2 EncodingMenu (com.mucommander.ui.encoding.EncodingMenu)2 CloseCancelledException (com.mucommander.viewer.CloseCancelledException)2 EditorPresenter (com.mucommander.viewer.EditorPresenter)2 FileEditor (com.mucommander.viewer.FileEditor)2