Java Code Examples for javax.swing.JOptionPane.showConfirmDialog()

The following are Jave code examples for showing how to use showConfirmDialog() 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: OpenJSharp   File: J2DBench.java   View Source Code Vote up 7 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 2
Project: black-scholes-java   File: GBSEngine.java   View Source Code Vote up 6 votes
public void actionPerformed(ActionEvent e){
	Object eventSource = e.getSource(); 
	if (eventSource == parent.yieldType){
		parent.set_yield_type();
		parent.compute();
	}
	if (eventSource == parent.impliedButton){
		parent.toggle_implied();
		parent.compute();
	}
	if (eventSource == parent.closeButton){
		JOptionPane.showConfirmDialog(null, 
			"The Black Scholes Calculator was written by Prof. Jayanth R. Varma (http://www.iima.ac.in/~jrvarma/)\n" +
	        "and is released under the GNU General Public Licence. \n\n" +
	        "The implied volatility is calculated using the UnivariateRealSolver from the Apache Commons \n" +
	        "Mathematics Library (http://commons.apache.org/math/) which is released under the Apache Licence\n" +
	        "by the Apache Software Foundation.", 
	        "Black Scholes Calculator Exiting...", 
	        JOptionPane.PLAIN_MESSAGE);
		System.exit(0);
	}
	if (eventSource == parent.rateType){
    	parent.compute();
	}
}
 
Example 3
Project: dracoon-dropzone   File: Dropzone.java   View Source Code Vote up 6 votes
/**
 * Show master password dialog if enabled
 */
private void showMasterPasswordEntry() {
	ConfigIO cfg = ConfigIO.getInstance();
	if (cfg.isMasterPwdEnabled()) {
		JPanel panel = new JPanel(new BorderLayout());
		JPasswordField pf = new JPasswordField();
		panel.setBorder(new EmptyBorder(0, 10, 0, 10));
		panel.add(pf, BorderLayout.NORTH);
		JFrame frame = new JFrame();
		frame.setAlwaysOnTop(true);

		int option = JOptionPane.showConfirmDialog(frame, panel, I18n.get("main.start.requestmasterpwd"),
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
		frame.dispose();
		if (option == JOptionPane.OK_OPTION) {
			cfg.setMasterPassword(new String(pf.getPassword()));
		} else {
			// TODO show config dialog
		}
	}
}
 
Example 4
Project: Equella   File: PowerSearchList.java   View Source Code Vote up 6 votes
@Override
public void actionPerformed(ActionEvent e)
{
	Control c = getSelectedControl();
	if( c != null )
	{
		int confirm = JOptionPane.showConfirmDialog(PowerSearchList.this,
			CurrentLocale.get("com.dytech.edge.admin.wizard.powersearchlist.confirm"), CurrentLocale //$NON-NLS-1$
				.get("com.dytech.edge.admin.wizard.powersearchlist.remove"), //$NON-NLS-1$
			JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

		if( confirm == JOptionPane.YES_OPTION )
		{
			table.clearSelection();
			model.removeControl(c);
		}
	}
}
 
Example 5
Project: defense-solutions-proofs-of-concept   File: AppConfigDialog.java   View Source Code Vote up 6 votes
private void jButton_resetAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_resetAllActionPerformed
    if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
            this,
            "Are you sure you want to reset all settings?",
            "Reset All Settings",
            JOptionPane.YES_NO_OPTION)) {
        try {
            appConfigController.resetFromAppConfigFile(true);
            copySettingsToUI();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(
                    this,
                    "Could not reset settings: " + e.getMessage(),
                    "Could Not Reset Settings",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}
 
Example 6
Project: Cognizant-Intelligent-Test-Scripter   File: TestDataComponent.java   View Source Code Vote up 6 votes
private void deleteTestData(Object source) {
    JTabbedPane tab = (JTabbedPane) source;
    TestDataTablePanel panel = getSelectedData();
    if (!panel.isGlobalData) {
        int index = tab.getSelectedIndex();
        String name = tab.getTitleAt(index);
        int option = JOptionPane.showConfirmDialog(null, "Are you sure want to delete the TestData [" + name + "]", "Delete TestData", JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            Boolean flag = testDesign.getProject().getTestData()
                    .getTestDataFor(envTab.getTitleAt(envTab.getSelectedIndex()))
                    .deleteTestData(name);
            if (flag) {
                tab.setSelectedIndex(index - 1);
                tab.removeTabAt(index);
            } else {
                Notification.show("Couldn't Delete Testdata - '" + name + "'");
            }
        }
    }
}
 
Example 7
Project: LOSY   File: Fine.java   View Source Code Vote up 6 votes
private void jTableEquipmentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableEquipmentMouseClicked

        tablaequipment = (DefaultTableModel) jTableEquipment.getModel();
        String numero=String.valueOf(tablaequipment.getValueAt(jTableEquipment.getSelectedRow(), 0));
        String prestamo=String.valueOf(tablaequipment.getValueAt(jTableEquipment.getSelectedRow(), 3));
        int opcion = JOptionPane.showConfirmDialog(this, "Va a pagar la multa", TOOL_TIP_TEXT_KEY, WIDTH);
        if(opcion==0){
            if(loanDao.check_prestamo(Integer.parseInt(prestamo))){
               fineDao.deleteFine(numero); 
               fineDao.updateFine(numero);
            }else{
              JOptionPane.showMessageDialog(null,"Por favor hacer devolucion del equipo primero");
            } 
            
        }
        int row = jTableEquipment.rowAtPoint(evt.getPoint());

    }
 
Example 8
Project: QN-ACTR-Release   File: TextualPanel.java   View Source Code Vote up 5 votes
/**
 * Overrides default method to provide a warning if saving over an existing file
 */
@Override
public void approveSelection() {
	// Gets the choosed file name
	String name = getSelectedFile().getName();
	String parent = getSelectedFile().getParent();
	if (getDialogType() == OPEN_DIALOG) {
		super.approveSelection();
	}
	if (getDialogType() == SAVE_DIALOG) {
		try {
			FileFilter used = ((FileFilter) this.getFileFilter());

			if (!name.toLowerCase().endsWith(used.getExtension())) {
				name = name + used.getExtension();
				setSelectedFile(new File(parent, name));
			}
			if (getSelectedFile().exists()) {
				int resultValue = JOptionPane.showConfirmDialog(this, "<html>File <font color=#0000ff>" + name
						+ "</font> already exists in this folder.<br>Do you want to replace it?</html>", "JMT - Warning",
						JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
				if (resultValue == JOptionPane.OK_OPTION) {
					getSelectedFile().delete();
					super.approveSelection();
				}
			} else {
				super.approveSelection();
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, "Select a type for the output file", "Select a type for the output file",
					JOptionPane.ERROR_MESSAGE);
		}
	}
}
 
Example 9
Project: QN-ACTR-Release   File: KMeanScatter.java   View Source Code Vote up 5 votes
/**
 * Overrides default method to provide a warning if saving over an existing file
 */
@Override
public void approveSelection() {
	// Gets the choosed file name
	String name = getSelectedFile().getName();
	String parent = getSelectedFile().getParent();
	if (getDialogType() == OPEN_DIALOG) {
		super.approveSelection();
	}
	if (getDialogType() == SAVE_DIALOG) {
		PlotImagesFileFilter used = ((PlotImagesFileFilter) this.getFileFilter());
		if (!name.toLowerCase().endsWith(used.getExtension())) {
			name = name + used.getExtension();
			setSelectedFile(new File(parent, name));
		}
		if (getSelectedFile().exists()) {
			int resultValue = JOptionPane.showConfirmDialog(this, "<html>File <font color=#0000ff>" + name
					+ "</font> already exists in this folder.<br>Do you want to replace it?</html>", "JMT - Warning",
					JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
			if (resultValue == JOptionPane.OK_OPTION) {
				getSelectedFile().delete();
				super.approveSelection();
			}
		} else {
			super.approveSelection();
		}
	}
}
 
Example 10
Project: QN-ACTR-Release   File: WhatIfPlot.java   View Source Code Vote up 5 votes
/**
 * Overrides default method to provide a warning if saving over an existing file
 */
@Override
public void approveSelection() {
	// Gets the choosed file name
	String name = getSelectedFile().getName();
	String parent = getSelectedFile().getParent();
	if (getDialogType() == OPEN_DIALOG) {
		super.approveSelection();
	}
	if (getDialogType() == SAVE_DIALOG) {
		PlotImagesFileFilter used = ((PlotImagesFileFilter) this.getFileFilter());
		if (!name.toLowerCase().endsWith(used.getExtension())) {
			name = name + used.getExtension();
			setSelectedFile(new File(parent, name));
		}
		if (getSelectedFile().exists()) {
			int resultValue = JOptionPane.showConfirmDialog(this, "<html>File <font color=#0000ff>" + name
					+ "</font> already exists in this folder.<br>Do you want to replace it?</html>", "File save - Warning",
					JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
			if (resultValue == JOptionPane.OK_OPTION) {
				getSelectedFile().delete();
				super.approveSelection();
			}
		} else {
			super.approveSelection();
		}
	}
}
 
Example 11
Project: Equella   File: DialogUtils.java   View Source Code Vote up 5 votes
/**
 * Does standard 'ok' clicked checking, and confirms overwrite before
 * executing saver if applicable
 * 
 * @param parent
 * @param title
 * @param filter
 * @param defaultFileName
 * @param saver
 */
public static void doSaveDialog(Component parent, String title, FileFilter filter, String defaultFileName,
	FileWorker saver)
{
	final DialogResult result = doDialog(parent, false, title, filter, true, new File(defaultFileName));
	if( result.isOkayed() )
	{
		boolean writeFile = true;
		final File file = result.getFile();
		if( file.exists() )
		{
			final int result2 = JOptionPane.showConfirmDialog(parent,
				CurrentLocale.get("com.tle.common.gui.confirmoverwrite"), //$NON-NLS-1$
				CurrentLocale.get("com.tle.common.gui.overwrite"), //$NON-NLS-1$
				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

			if( result2 != JOptionPane.YES_OPTION )
			{
				writeFile = false;
			}
		}

		if( writeFile )
		{
			saver.setFile(file);
			saver.setComponent(parent);
			saver.start();
		}
	}
}
 
Example 12
Project: JavaGraph   File: PropertiesTable.java   View Source Code Vote up 5 votes
/**
 * Creates and shows a confirmation dialog for continuing the current
 * edit.
 */
private boolean showContinueDialog(String value) {
    int response = JOptionPane.showConfirmDialog(PropertiesTable.this,
        getContinueQuestion(value),
        null,
        JOptionPane.YES_NO_OPTION);
    return response == JOptionPane.YES_OPTION;
}
 
Example 13
Project: geomapapp   File: GMAProfile.java   View Source Code Vote up 5 votes
int askOverWrite() {
	JFileChooser chooser = MapApp.getFileChooser();
	int ok = JOptionPane.NO_OPTION;
	while( true ) {
		ok = JOptionPane.showConfirmDialog(dialog,
			"File exists. Overwrite?",
			"Overwrite?",
			JOptionPane.YES_NO_CANCEL_OPTION);
		if( ok!=JOptionPane.NO_OPTION) return ok;
		ok = chooser.showSaveDialog(dialog);
		if( ok==JFileChooser.CANCEL_OPTION ) return JOptionPane.CANCEL_OPTION;
		if( !chooser.getSelectedFile().exists() ) return JOptionPane.YES_OPTION;
	}
}
 
Example 14
Project: tcc-rpg   File: PainelDeControle.java   View Source Code Vote up 4 votes
private void botaoLimparChatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoLimparChatActionPerformed
    int sair = JOptionPane.showConfirmDialog(null, "Deseja limpar o chat?", "Limpar chat", JOptionPane.YES_NO_OPTION);
    if (sair == JOptionPane.YES_OPTION) {
        dao.limparChat();
    }
}
 
Example 15
Project: geomapapp   File: DSDPDemo.java   View Source Code Vote up 4 votes
public void exportSelectExcel(){
	if (table.getSelectedRowCount() == 0) {
		JOptionPane.showMessageDialog(null, "No data selected for export", "No Selection", JOptionPane.ERROR_MESSAGE);
		return;
	}

	JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	File f=new File("dsdpTableSelection.xls");
	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 {
		WritableWorkbook wb = Workbook.createWorkbook(f);
		WritableSheet sheet = wb.createSheet("First Sheet", 0);
		for (int i=0;i<table.getColumnCount();i++)
			sheet.addCell( new Label(i,0,table.getColumnName(i)) );
		int sel[] = table.getSelectedRows();
		for (int i=0;i<sel.length;i++) {
			for (int j=0; j<table.getColumnCount();j++) {
				Object o = table.getValueAt(sel[i], j);
				if (o == null || ( o instanceof String && ((String)o).equals("NaN") ) ) o = "";
				sheet.addCell( new Label(j,i+1,o.toString()) );
			}
		}
		wb.write();
		wb.close();
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
Example 16
Project: ObsidianSuite   File: TimelineController.java   View Source Code Vote up 4 votes
public boolean checkSaved() {
	return !unsaved || JOptionPane.showConfirmDialog(timelineFrame, "You have unsaved changes.\n Continue?", "Unsaved Changes", JOptionPane.YES_NO_OPTION) == 0;
}
 
Example 17
Project: incubator-netbeans   File: UiUtils.java   View Source Code Vote up 4 votes
/**
 * @param title The title of the dialog
 * @param message The message of the dialog
 * @param silentDefault The dafault return value if installer is running silently
 * @return true if user click YES option. In silent mode return <code>silentDefault</code>
 */
public static int showYesNoCancelDialog(
        final String title,
        final String message,
        final int silentDefault) {
    initLAF();
    switch (UiMode.getCurrentUiMode()) {
        case SWING:
            LogManager.logIndent("... show Yes/No/Cancel dialog");
            LogManager.log("title: " + title);
            LogManager.log("message: " + message);
            int result = JOptionPane.showConfirmDialog(
                    null,
                    message,
                    title,
                    YES_NO_CANCEL_OPTION);
            LogManager.logUnindent("... dialog closed, choice : " + (result == YES_OPTION ? "yes" : (result == NO_OPTION ? "no" : (result==CANCEL_OPTION ? "cancel" : "closed"))));
            return result;
            
        case SILENT:
            LogManager.log(message);               
            String resource;
            switch(silentDefault) {
                case YES_OPTION : 
                    resource = RESOURCE_SILENT_DEFAULT_YES; 
                    break;
                case NO_OPTION : 
                    resource = RESOURCE_SILENT_DEFAULT_NO; 
                    break;
                case CANCEL_OPTION : 
                    resource = RESOURCE_SILENT_DEFAULT_CANCEL; 
                    break;
                default:
                    resource = StringUtils.EMPTY_STRING;
                    break;
            }
                    
            final String option = StringUtils.format(
                    ResourceUtils.getString(UiUtils.class,resource));
            System.err.println(message);
            System.err.println(option);
            LogManager.log(message);
            LogManager.log(option);
            return silentDefault;
    }
    //never get this line...
    return silentDefault;
}
 
Example 18
Project: QN-ACTR-Release   File: TestWizardPanel.java   View Source Code Vote up 4 votes
@Override
public boolean canGoForward() {
	System.out.println(name + ".canGoForward()");
	return JOptionPane.showConfirmDialog(this, "Can " + name + " go forward?", "", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION;
}
 
Example 19
Project: jmt   File: StatsPanel.java   View Source Code Vote up 4 votes
public void actionPerformed(ActionEvent e) {
	if (session.getListOfClustering().size() > 0) {
		if (JOptionPane.showConfirmDialog(StatsPanel.this,
				"If you apply this sampling all clustering will be deleted. Do you want to continue?", "Warning", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
			session.removeAllClustering();
		} else {
			return;
		}
	}
	int varSel = varsList.getSelectedIndex();
	int sampSel = samplingList.getSelectedIndex();
	switch (sampSel) {
	/** TRIMMING **/
	case 0:
		isSampled = true;
		int percentile = ((Integer) quantile.getValue()).intValue();
		if (!between.isSelected()) {
			model.doSamplingOnVariable(varSel, new TrimmingFilter(
					model.getMatrix().getVariables()[varSel].getUniStats().getQuantili()[percentile - 1], up.isSelected()));
		} else {
			model.doSamplingOnVariable(varSel,
					new TrimmingBetweenFilter(model.getMatrix().getVariables()[varSel].getUniStats().getQuantili()[percentile - 1],
							model.getMatrix().getVariables()[varSel].getUniStats().getQuantili()[((Integer) quantileB.getValue())
							                                                                     .intValue() - 1]));
		}
		undoSam.setEnabled(true);
		break;
	case 1:
		isSampled = true;
		int nObs = ((Integer) random.getValue()).intValue();
		model.doSamplingOnVariable(0, new RandomFilter(model.getMatrix().getVariables()[0].Size(), nObs));
		undoSam.setEnabled(true);
		break;
	case 2:
		isSampled = true;
		int min = ((Integer) fromO.getValue()).intValue();
		int max = ((Integer) toO.getValue()).intValue();
		model.doSamplingOnVariable(0, new IntervalFilter(min, max));
		undoSam.setEnabled(true);
		break;
	case 3:
		isSampled = true;
		switch (model.getMatrix().getVariables()[varsList.getSelectedIndex()].getType()) {
		case STRING:
			model.doSamplingOnVariable(varsList.getSelectedIndex(), new FilterOnString(varsList.getSelectedIndex(),
					((VariableString) model.getMatrix().getVariables()[varsList.getSelectedIndex()])
					.getListOfMatching(subs.getText())));
			undoSam.setEnabled(true);
			break;
		case NUMERIC:
			model.doSamplingOnVariable(varsList.getSelectedIndex(), new FilterOnNumeric(((Double) minN.getValue()).doubleValue(),
					((Double) maxN.getValue()).doubleValue(), varsList.getSelectedIndex()));
			undoSam.setEnabled(true);
			break;
		case DATE:
			model.doSamplingOnVariable(varsList.getSelectedIndex(), new FilterOnData(((Date) fromD.getValue()), ((Date) toD
					.getValue()), varsList.getSelectedIndex()));
			undoSam.setEnabled(true);
			break;
		}
		break;
	}
}
 
Example 20
Project: PekaED   File: PekaEDGUI.java   View Source Code Vote up 4 votes
public void newLevel() {
	Data.fileChanged = false;
	
	PK2Sprite psprite = new PK2Sprite("rooster.spr");
	Data.map = new PK2Map();
	Data.map.addSprite(psprite, psprite.filename);
	Data.map.levelNumber = Data.episodeFiles.size() + 1;
	sp.setList();
	
	Data.currentFile = null;
	
	Data.selectedTile = 0;
	
	msp.setMap();
	sp.setMap();
	
	tp.setTileset(Data.map.getTileset());
	lp.setMap();
	
	lp.repaint();
	mmp.repaint();
	
	if (Data.currentEpisodeFile != null) {
		int res = JOptionPane.showConfirmDialog(frame, "Do you want to add this file to the episode '" + Data.currentEpisodeName + "'?", "Add file to episode?", JOptionPane.YES_NO_OPTION);
		
		if (res == JOptionPane.YES_OPTION) {
			if (showAddToEpisodeSave()) {
				Data.map.saveFile();
				ep.importLevel(Data.currentFile);
				ep.setSelectedLevel(Data.episodeFiles.size() - 1);
				Data.currentFile = new File(Data.episodeFiles.get(Data.episodeFiles.size() - 1).getAbsolutePath());
				
				setFrameTitle();
			} else {
				setFrameTitle();
			}
		}
	}
	
	
}