Search in sources :

Example 1 with CloseCancelledException

use of com.mucommander.viewer.CloseCancelledException in project mucommander by mucommander.

the class BinaryEditor method close.

@Override
public void close() throws CloseCancelledException {
    if (!canClose()) {
        throw new CloseCancelledException();
    }
    PagedData data = Objects.requireNonNull((PagedData) binaryComponent.getCodeArea().getContentData());
    data.dispose();
}
Also used : CloseCancelledException(com.mucommander.viewer.CloseCancelledException) PagedData(org.exbin.auxiliary.paged_data.PagedData)

Example 2 with CloseCancelledException

use of com.mucommander.viewer.CloseCancelledException in project mucommander by mucommander.

the class FileEditorPresenter method addEditorService.

public void addEditorService(FileEditorService service) throws UserCancelledException {
    services.add(service);
    JRadioButtonMenuItem editorMenuItem = new JRadioButtonMenuItem(service.getName());
    final int serviceIndex = editorsCount;
    editorMenuItem.addActionListener((e) -> {
        try {
            switchFileEditor(serviceIndex);
        } catch (IOException ex) {
            Logger.getLogger(FileViewerPresenter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CloseCancelledException ex) {
            editorMenu.getItem(activeEditor).setSelected(true);
        }
    });
    editorsButtonGroup.add(editorMenuItem);
    editorMenu.add(editorMenuItem);
    if (editorsCount == 0) {
        editorMenuItem.setSelected(true);
    }
    editorsCount++;
}
Also used : JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) CloseCancelledException(com.mucommander.viewer.CloseCancelledException) IOException(java.io.IOException)

Example 3 with CloseCancelledException

use of com.mucommander.viewer.CloseCancelledException 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

CloseCancelledException (com.mucommander.viewer.CloseCancelledException)3 IOException (java.io.IOException)2 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)2 AbstractFile (com.mucommander.commons.file.AbstractFile)1 MenuToolkit (com.mucommander.commons.util.ui.helper.MenuToolkit)1 MnemonicHelper (com.mucommander.commons.util.ui.helper.MnemonicHelper)1 Translator (com.mucommander.text.Translator)1 EditorPresenter (com.mucommander.viewer.EditorPresenter)1 FileEditor (com.mucommander.viewer.FileEditor)1 FileEditorService (com.mucommander.viewer.FileEditorService)1 Cursor (java.awt.Cursor)1 KeyEvent (java.awt.event.KeyEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 ButtonGroup (javax.swing.ButtonGroup)1 JComponent (javax.swing.JComponent)1