List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:com._17od.upm.gui.DatabaseActions.java
/** * This method prompts the user for the name of a file. * If the file exists then it will ask if they want to overwrite (the file isn't overwritten though, * that would be done by the calling method) * @param title The string title to put on the dialog * @return The file to save to or null//from w w w . ja v a2s. c om */ private File getSaveAsFile(String title) { File selectedFile; boolean gotValidFile = false; do { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(title); int returnVal = fc.showSaveDialog(mainWindow); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } selectedFile = fc.getSelectedFile(); //Warn the user if the database file already exists if (selectedFile.exists()) { Object[] options = { "Yes", "No" }; int i = JOptionPane.showOptionDialog(mainWindow, Translator.translate("fileAlreadyExistsWithFileName", selectedFile.getAbsolutePath()) + '\n' + Translator.translate("overwrite"), Translator.translate("fileAlreadyExists"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (i == JOptionPane.YES_OPTION) { gotValidFile = true; } } else { gotValidFile = true; } } while (!gotValidFile); return selectedFile; }
From source file:fll.scheduler.SchedulerUI.java
/** * If there is more than 1 sheet, prompt, otherwise just use the sheet. * //w w w. j av a2 s .com * @return the sheet name or null if the user canceled * @throws IOException * @throws InvalidFormatException */ public static String promptForSheetName(final File selectedFile) throws InvalidFormatException, IOException { final List<String> sheetNames = ExcelCellReader.getAllSheetNames(selectedFile); if (sheetNames.size() == 1) { return sheetNames.get(0); } else { final String[] options = sheetNames.toArray(new String[sheetNames.size()]); final int choosenOption = JOptionPane.showOptionDialog(null, "Choose which sheet to work with", "Choose Sheet", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (JOptionPane.CLOSED_OPTION == choosenOption) { return null; } return options[choosenOption]; } }
From source file:com.atlauncher.data.Settings.java
/** * Load the users Console preference from file */// w w w .ja v a 2 s . co m public void loadStartingProperties() { try { if (!propertiesFile.exists()) { propertiesFile.createNewFile(); } } catch (IOException e) { String[] options = { "OK" }; JOptionPane.showOptionDialog(null, HTMLUtils.centerParagraph("Cannot create the config file" + ".<br/><br/>Make sure you're running the Launcher from somewhere with<br/>write" + " permissions for your user account such as your Home/Users folder or desktop."), "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); System.exit(0); } try { this.properties.load(new FileInputStream(propertiesFile)); this.theme = properties.getProperty("theme", Constants.LAUNCHER_NAME); this.dateFormat = properties.getProperty("dateformat", "dd/M/yyy"); if (!this.dateFormat.equalsIgnoreCase("dd/M/yyy") && !this.dateFormat.equalsIgnoreCase("M/dd/yyy") && !this.dateFormat.equalsIgnoreCase("yyy/M/dd")) { this.dateFormat = "dd/M/yyy"; } this.enablePackTags = Boolean.parseBoolean(properties.getProperty("enablepacktags", "false")); this.enableConsole = Boolean.parseBoolean(properties.getProperty("enableconsole", "true")); this.enableTrayIcon = Boolean.parseBoolean(properties.getProperty("enabletrayicon", "true")); if (!properties.containsKey("usingcustomjavapath")) { this.usingCustomJavaPath = false; this.javaPath = Utils.getJavaHome(); } else { this.usingCustomJavaPath = Boolean .parseBoolean(properties.getProperty("usingcustomjavapath", "false")); if (isUsingCustomJavaPath()) { this.javaPath = properties.getProperty("javapath", Utils.getJavaHome()); } else { this.javaPath = Utils.getJavaHome(); } } this.enableProxy = Boolean.parseBoolean(properties.getProperty("enableproxy", "false")); if (this.enableProxy) { this.proxyHost = properties.getProperty("proxyhost", null); this.proxyPort = Integer.parseInt(properties.getProperty("proxyport", "0")); if (this.proxyPort <= 0 || this.proxyPort > 65535) { this.enableProxy = false; } this.proxyType = properties.getProperty("proxytype", ""); if (!this.proxyType.equals("SOCKS") && !this.proxyType.equals("HTTP") && !this.proxyType.equals("DIRECT")) { this.enableProxy = false; } } else { this.proxyHost = ""; this.proxyPort = 0; this.proxyType = ""; } this.concurrentConnections = Integer.parseInt(properties.getProperty("concurrentconnections", "8")); if (this.concurrentConnections < 1) { this.concurrentConnections = 8; } this.daysOfLogsToKeep = Integer.parseInt(properties.getProperty("daysoflogstokeep", "7")); if (this.daysOfLogsToKeep < 1 || this.daysOfLogsToKeep > 30) { this.daysOfLogsToKeep = 7; } } catch (FileNotFoundException e) { logStackTrace(e); } catch (IOException e) { logStackTrace(e); } }
From source file:edu.ku.brc.specify.tasks.QueryTask.java
/** * @param q//from w w w . j a va 2s. co m * @param session * @return true if q has no associated reports or user confirms delete * @throws Exception */ protected boolean okToDeleteQuery(final SpQuery q, DataProviderSessionIFace session) throws Exception { //assumes q is force-loaded if (q.getReports().size() > 0) { CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(), UIRegistry.getResourceString("REP_CONFIRM_DELETE_TITLE"), true, CustomDialog.OKHELP, new QBReportInfoPanel(q, UIRegistry.getResourceString("QB_UNDELETABLE_REPS"))); cd.setHelpContext("QBUndeletableReps"); UIHelper.centerAndShow(cd); cd.dispose(); return false; } int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(), String.format(UIRegistry.getResourceString("REP_CONFIRM_DELETE"), q.getName()), UIRegistry.getResourceString("REP_CONFIRM_DELETE_TITLE"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); return option == JOptionPane.YES_OPTION; }
From source file:lejos.pc.charting.LogChartFrame.java
/** if file exists, ask user to append or overwrite. sets this.theLogFile. * @return 0 to replace, 1 to append, 2 to cancel */// ww w .ja v a 2s. co m private int getFileAppend() { JFrame frame = new JFrame("DialogDemo"); int n = 0; Object[] options = { "Replace it", "Add to it", "Cancel" }; // if the log file field is empty, the PC logger will handle it. we need to make sure the title is appropo this.theLogFile = new File(FQPathTextArea.getText(), logFileTextField.getText()); if (theLogFile.isFile()) { n = JOptionPane.showOptionDialog(frame, "File \"" + getCanonicalName(theLogFile) + "\" exists.\nWhat do you want to do?", "I have a Question...", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //do not use a custom Icon options, //the titles of buttons options[0]); //default is "Replace it" } frame = null; if (n == JOptionPane.CLOSED_OPTION) n = 2; return n; }
From source file:edu.ku.brc.specify.tasks.RecordSetTask.java
/** * Processes all Commands of type RECORD_SET. * @param cmdAction the command to be processed *//*from w w w .ja v a2s .c om*/ protected void processRecordSetCommands(final CommandAction cmdAction) { if (cmdAction.isAction(SAVE_RECORDSET)) { Object data = cmdAction.getData(); if (data instanceof RecordSetIFace) { // If there is only one item in the RecordSet then the User will most likely want it named the same // as the "identity" of the data object. So this goes and gets the Identity name and // pre-sets the name in the dialog. String intialName = ""; RecordSetIFace recordSet = (RecordSetIFace) cmdAction.getData(); if (recordSet.getNumItems() == 1) { RecordSetItemIFace item = recordSet.getOrderedItems().iterator().next(); DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession(); String sqlStr = DBTableIdMgr.getInstance().getQueryForTable(recordSet.getDbTableId(), item.getRecordId()); if (StringUtils.isNotEmpty(sqlStr)) { Object dataObj = session.getData(sqlStr); if (dataObj != null) { intialName = ((FormDataObjIFace) dataObj).getIdentityTitle(); } } session.close(); } String rsName = getUniqueRecordSetName(intialName); if (isNotEmpty(rsName)) { RecordSet rs = (RecordSet) data; rs.setName(rsName); rs.setModifiedByAgent(Agent.getUserAgent()); saveNewRecordSet(rs); } } } else if (cmdAction.isAction(DELETE_CMD_ACT)) { RecordSetIFace recordSet = null; if (cmdAction.getData() instanceof RecordSetIFace) { recordSet = (RecordSetIFace) cmdAction.getData(); } else if (cmdAction.getData() instanceof RolloverCommand) { RolloverCommand roc = (RolloverCommand) cmdAction.getData(); if (roc.getData() instanceof RecordSetIFace) { recordSet = (RecordSetIFace) roc.getData(); } } if (recordSet != null) { int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(), String.format(UIRegistry.getResourceString("RecordSetTask.CONFIRM_DELETE"), recordSet.getName()), UIRegistry.getResourceString("RecordSetTask.CONFIRM_DELETE_TITLE"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); // I18N if (option == JOptionPane.YES_OPTION) { deleteRecordSet(recordSet); deleteRecordSetFromUI(null, recordSet); } } } else if (cmdAction.isAction("Dropped")) { mergeRecordSets(cmdAction.getSrcObj(), cmdAction.getDstObj()); } else if (cmdAction.isAction("AskForNewRS")) { createRecordSet((RecordSet) cmdAction.getSrcObj()); } else if (cmdAction.isAction("DELETEITEMS")) { processDeleteRSItems(cmdAction); } else if (cmdAction.isAction(ADD_TO_NAV_BOX)) { addToNavBox((RecordSet) cmdAction.getData()); } }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * Checks to see if it is time to do a weekly or monthly backup. Weeks are rolling 7 days and months * are rolling 30 days./*from w w w . java2 s. c o m*/ * @param doSendExit requests to send an application exit command * @param doSkipAsk indicates whether to skip asking the user thus forcing the backup if it is time * @return true if the backup was started, false if it wasn't started. */ private boolean checkForBackUp(final boolean doSendExit, final boolean doSkipAsk) { final long oneDayMilliSecs = 86400000; Calendar calNow = Calendar.getInstance(); Date dateNow = calNow.getTime(); Long timeDays = getLastBackupTime(WEEKLY_PREF); if (timeDays == null) { timeDays = dateNow.getTime(); saveLastBackupTime(WEEKLY_PREF, dateNow.getTime()); } Long timeMons = getLastBackupTime(MONTHLY_PREF); if (timeMons == null) { timeMons = dateNow.getTime(); saveLastBackupTime(MONTHLY_PREF, dateNow.getTime()); } Date lastBackUpDays = new Date(timeDays); Date lastBackUpMons = new Date(timeMons); int diffMons = (int) ((dateNow.getTime() - lastBackUpMons.getTime()) / oneDayMilliSecs); int diffDays = (int) ((dateNow.getTime() - lastBackUpDays.getTime()) / oneDayMilliSecs); int diff = 0; String key = null; boolean isMonthly = false; if (diffMons > 30) { key = "MySQLBackupService.MONTHLY"; diff = diffMons; isMonthly = true; } else if (diffDays > 7) { key = "MySQLBackupService.WEEKLY"; diff = diffDays; } int userChoice = JOptionPane.CANCEL_OPTION; if (key != null && (UIRegistry.isEmbedded() || !doSkipAsk)) { if (UIRegistry.isEmbedded()) { showEZDBBackupMessage(key, diff); } else { Object[] options = { getResourceString("MySQLBackupService.BACKUP_NOW"), //$NON-NLS-1$ getResourceString("MySQLBackupService.BK_SKIP") //$NON-NLS-1$ }; userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), getLocalizedMessage(key, diff), //$NON-NLS-1$ getResourceString("MySQLBackupService.BK_NOW_TITLE"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); } } if (isMonthly) { saveLastBackupTime(MONTHLY_PREF, dateNow.getTime()); if (diffDays > 7) { saveLastBackupTime(WEEKLY_PREF, dateNow.getTime()); } } else { saveLastBackupTime(WEEKLY_PREF, dateNow.getTime()); } if (!UIRegistry.isEmbedded() && (userChoice == JOptionPane.YES_OPTION || doSkipAsk)) { return doBackUp(isMonthly, doSendExit, null); } return false; }
From source file:generadorqr.jifrGestionArticulos.java
private void btnImprimirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnImprimirMouseClicked /*if(jcbBuscarQrCategora.getSelectedIndex() != 0){ Object [] opciones={"ACEPTAR", "CANCELAR"}; int eleccion = JOptionPane.showOptionDialog(this, "Esta seguro de imprimir los QR por categoria", "Imprimir", JOptionPane.YES_NO_OPTION,/*from w w w . j a v a 2 s . c om*/ JOptionPane.QUESTION_MESSAGE, null, opciones, "Aceptar"); if(eleccion==JOptionPane.YES_OPTION){ ItemSeleccionado.accionBoton = "ImprimirXCategoria"; ImprimirQRs iqr = new ImprimirQRs(); iqr.setVisible(true); } }*/ Object[] opciones = { "TODOS LOS QR", "QR UNICO", "POR CATEGOR?A" }; int eleccion = JOptionPane.showOptionDialog(this, "Escoja el modo de impresin", "Imprimir", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, opciones, "Aceptar"); if (eleccion == JOptionPane.YES_OPTION) { ItemSeleccionado.accionBoton = "ImprimirTotal"; ImprimirQRs iqr = new ImprimirQRs(); iqr.setVisible(true); } else if (eleccion == JOptionPane.NO_OPTION) { if (!idA.isEmpty()) { ItemSeleccionado.accionBoton = "ImprimirParcial"; isA.setIdArticulo(idA); ImprimirQRs iqr = new ImprimirQRs(); iqr.setVisible(true); } else JOptionPane.showMessageDialog(this, "Busque y Seleccione un registro para imprimir"); } else { if (jcbBuscarQrCategora.getSelectedIndex() != 0) { ItemSeleccionado.accionBoton = "ImprimirXCategoria"; ImprimirQRs iqr = new ImprimirQRs(); iqr.setVisible(true); } else JOptionPane.showMessageDialog(this, "Seleccione una categora"); } LimpiarTablaEImagenes(); }
From source file:Installer.java
public void run() { JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new String[] { "Install", "Cancel" }); emptyFrame = new Frame("Vivecraft Installer"); emptyFrame.setUndecorated(true);/*from w w w . ja v a2 s . co m*/ emptyFrame.setVisible(true); emptyFrame.setLocationRelativeTo(null); dialog = optionPane.createDialog(emptyFrame, "Vivecraft Installer"); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); String str = ((String) optionPane.getValue()); if (str != null && ((String) optionPane.getValue()).equalsIgnoreCase("Install")) { int option = JOptionPane.showOptionDialog(null, "Please ensure you have closed the Minecraft launcher before proceeding.\n" //"Also, if installing with Forge please ensure you have installed Forge " + FORGE_VERSION + " first.", , "Important!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); if (option == JOptionPane.OK_OPTION) { monitor = new ProgressMonitor(null, "Installing Vivecraft...", "", 0, 100); monitor.setMillisToDecideToPopup(0); monitor.setMillisToPopup(0); task = new InstallTask(); task.addPropertyChangeListener(this); task.execute(); } else { dialog.dispose(); emptyFrame.dispose(); } } else { dialog.dispose(); emptyFrame.dispose(); } }
From source file:com.docdoku.client.data.MainModel.java
private void showContinueOrExitDialog(String pMessage) { Object[] options = { I18N.BUNDLE.getString("Continue_label"), I18N.BUNDLE.getString("Exit_label") }; int selectedOption = JOptionPane.showOptionDialog(null, pMessage, I18N.BUNDLE.getString("Error_title"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (selectedOption == 1) { System.exit(-1);/*from w w w .java2s. com*/ } }