List of usage examples for javax.swing JOptionPane CANCEL_OPTION
int CANCEL_OPTION
To view the source code for javax.swing JOptionPane CANCEL_OPTION.
Click Source Link
From source file:org.docx4all.ui.main.WordMLEditor.java
public void closeAllInternalFrames() { List<JInternalFrame> list = getAllInternalFrames(); //Start from current editor's frame JInternalFrame currentFrame = getCurrentInternalFrame(); list.remove(currentFrame);//from w ww .j a v a 2 s. com list.add(0, currentFrame); for (final JInternalFrame iframe : list) { final Runnable disposeRunnable = new Runnable() { public void run() { iframe.dispose(); } }; if (getToolbarStates().isDocumentDirty(iframe)) { try { iframe.setSelected(true); iframe.setIcon(false); } catch (PropertyVetoException exc) { ;//ignore } int answer = showConfirmClosingInternalFrame(iframe, "internalframe.close"); if (answer == JOptionPane.CANCEL_OPTION) { break; } } SwingUtilities.invokeLater(disposeRunnable); } }
From source file:org.docx4all.ui.main.WordMLEditor.java
public void closeInternalFrame(JInternalFrame iframe) { boolean canClose = true; if (getToolbarStates().isDocumentDirty(iframe)) { try {/*from w w w.j a va 2 s .c o m*/ iframe.setSelected(true); iframe.setIcon(false); } catch (PropertyVetoException exc) { ;//ignore } int answer = showConfirmClosingInternalFrame(iframe, "internalframe.close"); canClose = (answer != JOptionPane.CANCEL_OPTION); } if (canClose) { WordMLTextPane editor = SwingUtil.getWordMLTextPane(iframe); if (editor != null) { editor.removeCaretListener(getToolbarStates()); editor.removeFocusListener(getToolbarStates()); editor.setTransferHandler(null); editor.getDocument().removeDocumentListener(getToolbarStates()); WordMLEditorKit editorKit = (WordMLEditorKit) editor.getEditorKit(); editorKit.removeInputAttributeListener(getToolbarStates()); editor.getWordMLEditorKit().deinstall(editor); } iframe.dispose(); } }
From source file:org.docx4all.ui.main.WordMLEditor.java
private int showConfirmClosingInternalFrame(JInternalFrame iframe, String resourceKeyPrefix) { int answer = JOptionPane.CANCEL_OPTION; String filePath = (String) iframe.getClientProperty(WordMLDocument.FILE_PATH_PROPERTY); ResourceMap rm = getContext().getResourceMap(); String title = rm.getString(resourceKeyPrefix + ".dialog.title") + " " + filePath.substring(filePath.lastIndexOf(File.separator) + 1); String message = filePath + "\n" + rm.getString(resourceKeyPrefix + ".confirmMessage"); Object[] options = { rm.getString(resourceKeyPrefix + ".confirm.saveNow"), rm.getString(resourceKeyPrefix + ".confirm.dontSave"), rm.getString(resourceKeyPrefix + ".confirm.cancel") }; answer = showConfirmDialog(title, message, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, options, options[0]);/*from ww w .jav a 2s .co m*/ if (answer == JOptionPane.CANCEL_OPTION) { ; } else if (answer == JOptionPane.YES_OPTION) { boolean success = FileMenu.getInstance().save(iframe, null, FileMenu.SAVE_FILE_ACTION_NAME); if (success) { getToolbarStates().setDocumentDirty(iframe, false); getToolbarStates().setLocalEditsEnabled(iframe, false); } else { answer = JOptionPane.CANCEL_OPTION; } } else { //getToolbarStates().setDocumentDirty(iframe, false); } return answer; }
From source file:org.executequery.components.FileChooserDialog.java
public int showSaveDialog(Component parent) throws HeadlessException { int result = super.showSaveDialog(parent); File file = getSelectedFile(); if (file == null || result == CANCEL_OPTION) { return CANCEL_OPTION; }//from ww w. j a va 2 s. com if (file.exists()) { int _result = GUIUtilities.displayConfirmCancelDialog("Overwrite existing file?"); if (_result == JOptionPane.CANCEL_OPTION) { return CANCEL_OPTION; } else if (_result == JOptionPane.NO_OPTION) { return showSaveDialog(parent); } } return result; }
From source file:org.executequery.gui.ExportResultSetPanel.java
public void browse() { FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle("Select Export File Path"); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select"); if (result == JFileChooser.CANCEL_OPTION) { return;//from ww w .ja v a 2s . c o m } File file = fileChooser.getSelectedFile(); if (file.exists()) { result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?"); if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) { browse(); return; } } fileNameField.setText(file.getAbsolutePath()); }
From source file:org.executequery.gui.ReadOnlyTextPanePopUpMenu.java
public void saveToFile(ActionEvent e) { FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle("Select Output File Path"); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Select"); if (result == JFileChooser.CANCEL_OPTION) { return;//w w w . j a va 2 s .c om } File file = fileChooser.getSelectedFile(); if (file.exists()) { result = GUIUtilities.displayConfirmCancelDialog("The selected file exists.\nOverwrite existing file?"); if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.NO_OPTION) { saveToFile(e); return; } } try { FileUtils.writeFile(file.getAbsolutePath(), readOnlyTextArea.getText()); } catch (IOException e1) { GUIUtilities.displayErrorMessage("Error writing output pane contents to file.\n" + e1.getMessage()); } }
From source file:org.freeplane.core.ui.components.OptionalDontShowMeAgainDialog.java
private OptionalDontShowMeAgainDialog show() { final String property = getProperty(); if (StringUtils.equals(property, "true")) { mResult = JOptionPane.OK_OPTION; return this; }/* ww w .j a v a2 s .c om*/ if (mMessageType == BOTH_OK_AND_CANCEL_OPTIONS_ARE_STORED && StringUtils.equals(property, "false")) { mResult = JOptionPane.CANCEL_OPTION; return this; } mDialog = null; mDialog = new JDialog(mParent, TextUtils.getText(mTitleId)); mDialog.setModal(true); mDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); final AbstractAction cancelAction = new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent pE) { close(JOptionPane.CANCEL_OPTION); } }; final AbstractAction okAction = new AbstractAction() { /** * */ private static final long serialVersionUID = 1L; public void actionPerformed(final ActionEvent pE) { close(JOptionPane.OK_OPTION); } }; UITools.addEscapeActionToDialog(mDialog, cancelAction); mDialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent pE) { close(JOptionPane.CANCEL_OPTION); } }); mDialog.getContentPane().setLayout(new GridBagLayout()); mDialog.getContentPane().add(new JLabel(TextUtils.getText(mMessageId)), new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); final ImageIcon questionMark; if (mMessageType == ONLY_OK_SELECTION_IS_SHOWN) { questionMark = new ImageIcon( ResourceController.getResourceController().getResource("/images/icons/messagebox_warning.png")); } else { questionMark = new ImageIcon( ResourceController.getResourceController().getResource("/images/icons/help.png")); } mDialog.getContentPane().add(new JLabel(questionMark), new GridBagConstraints(0, 0, 1, 2, 1.0, 2.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); String boxString; if (mMessageType != OptionalDontShowMeAgainDialog.BOTH_OK_AND_CANCEL_OPTIONS_ARE_STORED) { boxString = "OptionalDontShowMeAgainDialog.dontShowAgain"; } else { boxString = "OptionalDontShowMeAgainDialog.rememberMyDescision"; } mDontShowAgainBox = new JCheckBox(TextUtils.getRawText(boxString)); MenuBuilder.setLabelAndMnemonic(mDontShowAgainBox, null); mDialog.getContentPane().add(mDontShowAgainBox, new GridBagConstraints(0, 2, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); final String okText; if (mMessageType == ONLY_OK_SELECTION_IS_SHOWN) { okText = TextUtils.getRawText("ok"); } else { okText = TextUtils.getRawText("OptionalDontShowMeAgainDialog.ok"); } final JButton okButton = new JButton(okText); MenuBuilder.setLabelAndMnemonic(okButton, null); okButton.addActionListener(okAction); mDialog.getContentPane().add(okButton, new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); if (mMessageType != ONLY_OK_SELECTION_IS_SHOWN) { final JButton cancelButton = new JButton(TextUtils.getRawText("OptionalDontShowMeAgainDialog.cancel")); MenuBuilder.setLabelAndMnemonic(cancelButton, null); cancelButton.addActionListener(cancelAction); mDialog.getContentPane().add(cancelButton, new GridBagConstraints(3, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 0, 0), 0, 0)); } mDialog.getRootPane().setDefaultButton(okButton); mDialog.pack(); if (mNode != null) { UITools.setDialogLocationRelativeTo(mDialog, mNode); } else { mDialog.setLocationRelativeTo(null); } mDialog.setVisible(true); return this; }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerSaveAsLayerToSLDAction.java
@Override public void actionPerformed(ActionEvent e) { boolean backup = false; File startWithFile = new File(System.getProperty("user.home"), styledLayer.getTitle().toString() + ".sld"); if (styledLayer.getSldFile() != null) startWithFile = styledLayer.getSldFile(); File exportFile = AsSwingUtil.chooseFileSave(owner, startWithFile, ASUtil.R("StyledLayerSLD.ChooseFileLocationDialog.Title"), new FileExtensionFilter(ASUtil.FILTER_SLD)); if (exportFile == null) return;// w w w . jav a2s .c o m if (!(exportFile.getName().toLowerCase().endsWith(".sld") || exportFile.getName().toLowerCase().endsWith(".xml"))) { exportFile = new File(exportFile.getParentFile(), exportFile.getName() + ".sld"); } styledLayer.setSldFile(exportFile); if (styledLayer.getSldFile().exists()) { try { FileUtils.copyFile(styledLayer.getSldFile(), IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak")); backup = true; } catch (IOException e1) { LOGGER.warn("could not create a backup of the existing .sld", e1); return; } } try { StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile()); StylingUtil.saveStyleToSld(styledLayer.getStyle(), ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true, getOptimizedTitle(styledLayer)); Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"), ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") }; int dialogValue = 0; if (backup) { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } else { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } if (dialogValue == JOptionPane.NO_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(styledLayer.getSldFile()); } if (dialogValue == JOptionPane.CANCEL_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile())); } List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile())); if (es.size() > 0) { ExceptionDialog.show(owner, new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid", IOUtil.escapePath(styledLayer.getSldFile())), es.get(0))); } } catch (Exception e1) { LOGGER.error("saveStyleToSLD", e1); ExceptionDialog.show(owner, e1); return; } }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerSaveLayerToSLDAction.java
@Override public void actionPerformed(ActionEvent e) { boolean backup = false; if (styledLayer.getSldFile().exists()) { // if (StylingUtil.isStyleDifferent(styledLayer.getStyle(), // styledLayer.getSldFile())){ // return; // }// w w w .ja v a2s .c o m try { FileUtils.copyFile(styledLayer.getSldFile(), IOUtil.changeFileExt(styledLayer.getSldFile(), "sld.bak")); backup = true; } catch (IOException e1) { LOGGER.warn("could not create a backup of the existing .sld", e1); return; } } try { StylingUtil.saveStyleToSld(styledLayer.getStyle(), styledLayer.getSldFile()); StylingUtil.saveStyleToSld(styledLayer.getStyle(), ASUtil.changeToOptimizedFilename(styledLayer.getSldFile()), true, "AtlasStyler " + ReleaseUtil.getVersionInfo(AtlasStyler.class) + ", Layer:" + styledLayer.getTitle() + ", Export-Mode: PRODUCTION"); Object[] options = { "OK", ASUtil.R("AtlasStylerSaveLayerToSLD.OpenFile"), ASUtil.R("AtlasStylerSaveLayerToSLD.OpenProductive") }; int dialogValue = 0; if (backup) { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccessAndBackedUp", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } else { dialogValue = JOptionPane.showOptionDialog(owner, ASUtil.R("AtlasStylerGUI.saveToSLDFileSuccess", IOUtil.escapePath(styledLayer.getSldFile())), "", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); } if (dialogValue == JOptionPane.NO_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(styledLayer.getSldFile()); } if (dialogValue == JOptionPane.CANCEL_OPTION) { Desktop desktop = Desktop.getDesktop(); desktop.open(ASUtil.changeToOptimizedFilename(styledLayer.getSldFile())); } List<Exception> es = StylingUtil.validateSld(new FileInputStream(styledLayer.getSldFile())); if (es.size() > 0) { ExceptionDialog.show(owner, new IllegalStateException(ASUtil.R("AtlasStylerExport.WarningSLDNotValid", IOUtil.escapePath(styledLayer.getSldFile())), es.get(0))); } } catch (Exception e1) { LOGGER.error("saveStyleToSLD", e1); ExceptionDialog.show(owner, e1); return; } }
From source file:org.giswater.controller.MenuController.java
public void exit(Boolean askQuestion) { if (askQuestion) { String msg = Utils.getBundleString("MenuController.save_project_preferences"); //$NON-NLS-1$ int answer = Utils.showYesNoCancelDialog(mainFrame, msg); if (answer == JOptionPane.CANCEL_OPTION) return; if (answer == JOptionPane.YES_OPTION) { Utils.getLogger().info("Project preferences saved"); gswSave();//from w w w . j a va 2s. co m } } else { gswSave(); } Utils.getLogger().info("Application closed"); System.exit(0); }