Java Code Examples for javax.swing.JOptionPane.CANCEL_OPTION

The following are Jave code examples for showing how to use CANCEL_OPTION of the javax.swing.JOptionPane class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: geomapapp   File: ImageComponent.java   View Source Code Vote up 7 votes
public void save() throws IOException {
	initChooser();
	int ok = JOptionPane.NO_OPTION;
	if( file!=null ) {
		ok = JOptionPane.showConfirmDialog(
			(JFrame)getTopLevelAncestor(),
			"overwrite "+file.getName()+"?",
			"overwrite?",
			JOptionPane.YES_NO_CANCEL_OPTION);
		if( ok==JOptionPane.CANCEL_OPTION) return;
		chooser.setSelectedFile( file);
	}
	if( ok==JOptionPane.NO_OPTION) {
		ok = chooser.showSaveDialog((JFrame)getTopLevelAncestor());
		if( ok==chooser.CANCEL_OPTION) return;
		file = chooser.getSelectedFile();
	}
	apply();
	String type = file.getName().substring(
		file.getName().indexOf(".")+1).toLowerCase();
	if( !type.equals("jpg") && !type.equals("png") && !type.equals("tif")) type="jpg";
	ImageIO.write( image, type, file);
}
 
Example 2
Project: openjdk-jdk10   File: J2DBench.java   View Source Code Vote up 6 votes
public static boolean saveOrDiscardLastResults() {
    if (lastResults != null) {
        int ret = JOptionPane.showConfirmDialog
            (guiFrame,
             "The results of the last test will be "+
             "discarded if you continue!  Do you want "+
             "to save them?",
             "Discard last results?",
             JOptionPane.YES_NO_CANCEL_OPTION);
        if (ret == JOptionPane.CANCEL_OPTION) {
            return false;
        } else if (ret == JOptionPane.YES_OPTION) {
            if (saveResults()) {
                lastResults = null;
            } else {
                return false;
            }
        }
    }
    return true;
}
 
Example 3
Project: Equella   File: TermTree.java   View Source Code Vote up 6 votes
@Override
protected String promptForName()
{
	final JValidatingTextField field = new JValidatingTextField(new JValidatingTextField.MaxLength(
		Term.MAX_TERM_VALUE_LENGTH), new JValidatingTextField.DisallowStr(TaxonomyConstants.TERM_SEPARATOR));
	String name = null;
	do
	{
		final int result = JOptionPane.showOptionDialog(this, field,
			CurrentLocale.get("com.tle.admin.gui.common.tree.editor.entername"), JOptionPane.OK_CANCEL_OPTION,
			JOptionPane.PLAIN_MESSAGE, null, null, null);
		if( result == JOptionPane.CANCEL_OPTION )
		{
			return null;
		}
		name = field.getText();
	}
	while( Check.isEmpty(name) || !isProposedNewNameValid(name) );

	return name.trim();
}
 
Example 4
Project: jdk8u-jdk   File: J2DBench.java   View Source Code Vote up 6 votes
public static boolean saveOrDiscardLastResults() {
    if (lastResults != null) {
        int ret = JOptionPane.showConfirmDialog
            (guiFrame,
             "The results of the last test will be "+
             "discarded if you continue!  Do you want "+
             "to save them?",
             "Discard last results?",
             JOptionPane.YES_NO_CANCEL_OPTION);
        if (ret == JOptionPane.CANCEL_OPTION) {
            return false;
        } else if (ret == JOptionPane.YES_OPTION) {
            if (saveResults()) {
                lastResults = null;
            } else {
                return false;
            }
        }
    }
    return true;
}
 
Example 5
Project: jmt   File: JabaWizard.java   View Source Code Vote up 6 votes
/**
 * Shows a confirmation dialog to save before new model or exit operations
 * 
 * @param msg
 *            The message to display.
 * @return <code>true</code> - if the user select cancel button.
 */
public boolean checkForSave(String msg) {
	// Checks if there's an old graph to save
	if (data != null && data.isChanged()) {
		int resultValue = JOptionPane.showConfirmDialog(this, msg,
				"JABA - Warning", JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.WARNING_MESSAGE);
		if (resultValue == JOptionPane.YES_OPTION) {
			save();
			return true;
		}
		if (resultValue == JOptionPane.CANCEL_OPTION) {
			return true;
		}
	}
	return false;
}
 
Example 6
Project: QN-ACTR-Release   File: Mediator.java   View Source Code Vote up 6 votes
/**
 * Checks if there's an old graph to save. This methods is called when creates/closes/opens a graph.
 * @param msg The message to display.
 * @return <code>true</code> - whether the user accepts to save the graph, or he cancels the current action.
 */
public boolean checkForSave(String msg) {
	// Checks if there's an old graph to save
	if (model != null && model.toBeSaved()) {
		int resultValue = JOptionPane.showConfirmDialog(mainWindow, msg, "JMODEL - Warning", JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.WARNING_MESSAGE);
		if (resultValue == JOptionPane.YES_OPTION) {
			saveModel();
			return true;
		}
		if (resultValue == JOptionPane.CANCEL_OPTION) {
			return true;
		}
	}
	return false;
}
 
Example 7
Project: jmt   File: Mediator.java   View Source Code Vote up 6 votes
/**
 * Checks if there's an old graph to save. This methods is called when creates/closes/opens a graph.
 * @param msg The message to display.
 * @return <code>true</code> - whether the user accepts to save the graph, or he cancels the current action.
 */
public boolean checkForSave(String msg) {
	// Checks if there's an old graph to save
	if (model != null && model.toBeSaved()) {
		int resultValue = JOptionPane.showConfirmDialog(mainWindow, msg, "JSIMgraph - Warning", JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.WARNING_MESSAGE);
		if (resultValue == JOptionPane.YES_OPTION) {
			saveModel();
			return true;
		}
		if (resultValue == JOptionPane.CANCEL_OPTION) {
			return true;
		}
	}
	return false;
}
 
Example 8
Project: Equella   File: SecurityTree.java   View Source Code Vote up 6 votes
protected void attemptToCloseWindow()
{
	boolean close = trySave(new GlassSwingWorker<Object>()
	{
		@Override
		public Object construct() throws Exception
		{
			tabManager.saveTabs();
			return null;
		}
	}) != JOptionPane.CANCEL_OPTION;

	if( close )
	{
		dialog.setVisible(false);
		dialog.dispose();
	}
}
 
Example 9
Project: JavaGraph   File: ResourceTab.java   View Source Code Vote up 6 votes
/**
 * Creates and shows a confirmation dialog for abandoning the currently
 * edited graph.
 * @return {@code true} if the user did not cancel the action
 */
public boolean confirmCancel() {
    boolean result = true;
    if (isDirty()) {
        int answer = JOptionPane.showConfirmDialog(getDisplay(),
            String.format("%s '%s' has been modified. Save changes?",
                getResourceKind().getName(),
                getName()),
            null,
            JOptionPane.YES_NO_CANCEL_OPTION);
        if (answer == JOptionPane.YES_OPTION) {
            saveResource();
        }
        result = answer != JOptionPane.CANCEL_OPTION;
    }
    return result;
}
 
Example 10
Project: alevin-svn2   File: MyEditingPopupGraphMousePlugin.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
private void addLink(int layer, V src, V dest) {
	boolean addConstraint = true;
	E edge = edgeFactory.create();
	while (addConstraint) {
		new AddConstraintDialog((NetworkEntity<AbstractConstraint>) edge, layer, GUI.getInstance(),
				new Dimension(300, 150));
		// if a resource/demand has been added
		if (edge.get().size() > 0) {
			addConstraint = false;
			@SuppressWarnings("rawtypes")
			Network net = scenario.getNetworkStack()
					.getLayer(layer);
			if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net)
					.addEdge((SubstrateLink) edge, (SubstrateNode) src,
							(SubstrateNode) dest))
					|| (net instanceof VirtualNetwork && ((VirtualNetwork) net)
							.addEdge((VirtualLink) edge, (VirtualNode) src,
									(VirtualNode) dest))) {
				vv.updateUI();
			} else {
				throw new AssertionError("Adding link failed.");
			}
		} else {
			int option = JOptionPane.showConfirmDialog(GUI.getInstance(),
					"A " + (layer == 0 ? "Resource" : "Demand")
							+ " must be added for the link to be created!",
					"Create Node", JOptionPane.OK_CANCEL_OPTION);
			if (option == JOptionPane.CANCEL_OPTION
					|| option == JOptionPane.CLOSED_OPTION) {
				addConstraint = false;
			}
		}
	}
}
 
Example 11
Project: cuttlefish   File: CxfNetwork.java   View Source Code Vote up 5 votes
protected boolean confirmFileFormatWarning(String warning,
		String dialogTitle) {
	System.out.println(warning);

	int answer = JOptionPane.showConfirmDialog(null, warning, dialogTitle,
			2, JOptionPane.WARNING_MESSAGE);

	if (answer == JOptionPane.CANCEL_OPTION) {
		clearGraph();
		return false;
	}
	return true;
}
 
Example 12
Project: geomapapp   File: Janus.java   View Source Code Vote up 5 votes
public static String showOpenDialog(java.awt.Component comp) {
	if( jdial==null )jdial = new JanusDialog();
	int ok = jdial.showDialog(comp);
	if( ok==JOptionPane.CANCEL_OPTION )return null;
	Janus j = new Janus(jdial.getDataID(), jdial.getLeg(), jdial.getSite(), jdial.getHole());
	return j.urlString();
}
 
Example 13
Project: java-course   File: TabButtonAction.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public void actionPerformed(ActionEvent e) {
    JTabbedPane pane = observer.getTabs();
    int i = pane.indexOfTabComponent(tab);
    JNotepadPPDocument editor = observer.getEditors().get(i);

    List<JNotepadPPDocument> editors = observer.getEditors();

    if (pane.getComponentCount() == 4) {
        return;
    }
    if (editor.isChanged()) {
        int answer = JOptionPane.showConfirmDialog(observer,
                lp.getString("saveMessage"), lp.getString("saveDialog"),
                JOptionPane.YES_NO_CANCEL_OPTION);

        if (answer == JOptionPane.YES_OPTION) {
            editor.saveDocument(false);
        } else if (answer == JOptionPane.CANCEL_OPTION) {
            return;
        }
    }

    pane.remove(i);
    editors.remove(i);
    int size = editors.size();

    if (i >= size) {
        observer.setActiveEditor(editors.get(size - 1));
        pane.setSelectedIndex(size - 1);
    } else {
        observer.setActiveEditor(editors.get(i));
        pane.setSelectedIndex(i);
    }
    observer.getActiveEditor().updateStatusBar();
}
 
Example 14
Project: VASSAL-src   File: TranslateWindow.java   View Source Code Vote up 5 votes
protected boolean querySave() throws IOException {
  switch (JOptionPane.showConfirmDialog(this, "Do you want to save these changes now?",
      "Unsaved Changes", JOptionPane.YES_NO_CANCEL_OPTION)) {
  case JOptionPane.YES_OPTION:
    saveTranslation();
    return true;
  case JOptionPane.NO_OPTION:
    reloadTranslation();
    return true;
  case JOptionPane.CANCEL_OPTION:
    return false;
  }
  return true;
}
 
Example 15
Project: AgentWorkbench   File: BasicGraphGuiProperties.java   View Source Code Vote up 4 votes
/**
 * Does the close action.
 */
private void doClose() {
	
	if (this.hasChanged()==true) {
		// --- Data model has changed ! ---------------------------
		String diaTitle = Language.translate("Close Properties", Language.EN);
		String diaQuestion = null;
		if (this.graphController.getProject()!=null) {
			// --- Setup case -------------
			diaQuestion = Language.translate("Save changes to network model?", Language.EN);
		} else {
			// --- Execution case ---------
			diaQuestion = Language.translate("Save and send data model changes to agent(s)?", Language.EN);
		}

		// --- User request ---------------------------------------
		int diaAnswer = JOptionPane.showInternalConfirmDialog(this, diaQuestion, diaTitle, JOptionPane.YES_NO_CANCEL_OPTION);
		if (diaAnswer==JOptionPane.YES_OPTION) {
			if (this.graphController.getProject()!=null) {
				// --- Setup case -------------
				this.save();	
			} else {
				// --- Execution case ---------
				this.save(true);
			}
			this.setVisible(false);
			this.dispose();
			
		} else if (diaAnswer==JOptionPane.NO_OPTION){
			this.setVisible(false);
			this.dispose();
			
		} else if (diaAnswer==JOptionPane.CANCEL_OPTION){
			// --- Do nothing ---- 
		}
		
	} else {
		// --- Data model has NOT changed ! ---
		this.setVisible(false);
		this.dispose();
	}
}
 
Example 16
Project: KernelHive   File: MainFrameController.java   View Source Code Vote up 4 votes
/**
 * closes the selected tab
 *
 * @param tab {@link JTabPanel}
 */
public void closeTab(final JTabPanel tab) {
	JTabContent content;
	int index = -1;
	if (tab != null) {
		content = tab.getTabContent();
		for (int i = 0; i < frame.getWorkspacePane().getTabCount(); i++) {
			final Component c = frame.getWorkspacePane().getTabComponentAt(
					i);
			if (c.equals(tab)) {
				index = i;
				break;
			}
		}
	} else {
		index = frame.getWorkspacePane().getSelectedIndex();
		if (index != -1) {
			content = (JTabContent) frame.getWorkspacePane()
					.getComponentAt(index);
		} else {
			return;
		}
	}

	if (content != null) {
		content.onClose();
	}

	// TODO i18n
	if (content.isDirty()) {
		final int result = JOptionPane.showConfirmDialog(
				frame.getContentPane(),
				"The selected file has been modified. "
				+ "Do you wanto to save it?", "Save file?",
				JOptionPane.YES_NO_CANCEL_OPTION);
		if (result == JOptionPane.YES_OPTION) {
			final File f = content.getFile();
			if (f != null && f.exists()) {
				content.saveContent(f);
			} else {
				saveTabAs(tab);
			}
			frame.getWorkspacePane().removeTabAt(index);
		} else if (result == JOptionPane.NO_OPTION) {
			frame.getWorkspacePane().removeTabAt(index);
		} else if (result == JOptionPane.CANCEL_OPTION) {
		}
	} else {
		frame.getWorkspacePane().removeTabAt(index);
	}
}
 
Example 17
Project: OpenJSharp   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 18
Project: geomapapp   File: UnknownDataSet.java   View Source Code Vote up 4 votes
public void exportExcelXLSX(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;

	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	String defaultName = desc.name.replace(":", "") + ".xlsx";

	if(defaultName.contains("Data Table ")){
		defaultName = defaultName.replace("Data Table ", "");
	}

	File f=new File(defaultName);
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION)break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		if (!f.getName().endsWith(".xlsx")){
			System.out.println(f.getName());
			JOptionPane.showMessageDialog(null, "Save did not complete. Must end in .xlsx. Try again.");
		}else{
			XSSFWorkbook xlsxWB = new XSSFWorkbook();
			CreationHelper createHelper = xlsxWB.getCreationHelper();
			XSSFSheet xlsxSheet1 = xlsxWB.createSheet("First Sheet");
			Row row = null;
			
			int[] ind;
			if (saveOption.equals("selection")) {
				ind = dataT.getSelectedRows();
			} else if (saveOption.equals("plottable")) {
				ind = getPlottableRows();
			} else {
				ind = new int[dataT.getRowCount()];
				for (int i=0; i<dataT.getRowCount(); i++) ind[i] = i;
			}
			int xlsxCol = dataT.getColumnCount();
			row = xlsxSheet1.createRow((0));
			//don't include Plot column
			for (int c=1; c<xlsxCol; c++){
				String columnName = dataT.getColumnName(c);
				row.createCell(c-1).setCellValue(columnName);
			}

			for (int r=1; r<=ind.length; r++){
				row = xlsxSheet1.createRow((r));
				for (int c=1; c<xlsxCol; c++){
					Object o = dataT.getValueAt(ind[r-1], c);
					String input1 = null;
					if(o instanceof String && ((String)o).equals("NaN")){
						o = "";
						input1 = o.toString();
						row.createCell(c-1).setCellValue(input1);
					}else if(o instanceof String){
						row.createCell(c-1).setCellValue((String)o);
					}
				}
			}
			FileOutputStream xlsxOut = new FileOutputStream(f);
			xlsxWB.write(xlsxOut);
			xlsxOut.close();
		}
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
Example 19
Project: geomapapp   File: Digitizer.java   View Source Code Vote up 4 votes
void saveTable() {
		try {
			LineSegmentsObject obj = (LineSegmentsObject) table.getModel();
			String dataType = obj.grid.getDataType();
			String units = obj.grid.getUnits();
			JFileChooser chooser = MapApp.getFileChooser();
			String defaultFileName = list.getSelectedValue().toString().replace(" ", "_") + ".xyz";
			chooser.setSelectedFile(new File(defaultFileName));
			int ok = chooser.showSaveDialog(map.getTopLevelAncestor());
			if( ok==JFileChooser.CANCEL_OPTION ) return;
			File file = chooser.getSelectedFile();
			if( file.exists() ) {
				ok = askOverWrite();
				if( ok==JOptionPane.CANCEL_OPTION ) return;
			}
			
			PrintStream out = new PrintStream(
					new FileOutputStream( file ));
			out.println ( "Longitude\tLatitude\t" + dataType + 
					      " (" + units + ")"); //\tDistance between points (km)\tCumulative distance (km)");

			//first print the digitized points 
			out.println("Digitized points");
			for (int row = 0; row < obj.points.size(); row ++) {
				out.println(obj.getValueAt(row, 0, 0) +"\t" +
							obj.getValueAt(row, 1, 0) +"\t" +
							obj.getValueAt(row, 2, 0));
//							obj.getValueAt(row, 2, 0) +"\t" +
//							obj.getValueAt(row, 3, 0) +"\t" +
//							obj.getValueAt(row, 4, 0));
			}
			
			//then print the interpolated points
			out.println("Interpolated points");
			for (int row = 0; row < obj.profile.size(); row ++) {
				out.println(obj.getValueAt(row, 0, 1) +"\t" +
							obj.getValueAt(row, 1, 1) +"\t" +
							obj.getValueAt(row, 2, 1));
//							obj.getValueAt(row, 2, 1) +"\t" +
//							obj.getValueAt(row, 3, 1) +"\t" +
//							obj.getValueAt(row, 4, 1));
			}
			out.close();
		} catch(IOException ex) {
			JOptionPane.showMessageDialog( map.getTopLevelAncestor(),
					"\"save\" failed\n   "+ ex.getMessage() );
		}
	}
 
Example 20
Project: Equella   File: AbstractTreeEditor.java   View Source Code Vote up 4 votes
public void saveChanges(final Runnable actionAfterSave)
{
	if( currentEditor == null || !currentEditor.hasChanges() )
	{
		actionAfterSave.run();
		return;
	}

	String message = CurrentLocale.get("com.tle.admin.gui.common.tree.nodeeditor.saveconfirm");
	String[] buttons = {CurrentLocale.get("com.dytech.edge.admin.gui.save"),
			CurrentLocale.get("com.dytech.edge.admin.gui.dontsave"),
			CurrentLocale.get("com.dytech.edge.admin.gui.cancel")};
	final int confirm = JOptionPane.showOptionDialog(this, message,
		CurrentLocale.get("com.dytech.edge.admin.gui.savechanges"), JOptionPane.YES_NO_CANCEL_OPTION,
		JOptionPane.WARNING_MESSAGE, null, buttons, buttons[0]);

	if( confirm == JOptionPane.CANCEL_OPTION )
	{
		return;
	}
	else if( confirm == JOptionPane.NO_OPTION )
	{
		actionAfterSave.run();
		return;
	}

	// We must save then run the runnable
	GlassSwingWorker<?> worker = new GlassSwingWorker<Object>()
	{
		@Override
		public Object construct()
		{
			currentEditor.doSave();
			return null;
		}

		@Override
		public void finished()
		{
			actionAfterSave.run();
		}

		@Override
		public void exception()
		{
			JOptionPane.showMessageDialog(getComponent(),
				CurrentLocale.get("com.tle.admin.gui.common.tree.nodeeditor.saveerror"));
			getException().printStackTrace();
		}
	};
	worker.setComponent(this);
	worker.start();
}