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();
}
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++;
}
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);
}
}
}
Aggregations