Example usage for javax.swing JOptionPane showInputDialog

List of usage examples for javax.swing JOptionPane showInputDialog

Introduction

In this page you can find the example usage for javax.swing JOptionPane showInputDialog.

Prototype

public static String showInputDialog(Component parentComponent, Object message, String title, int messageType)
        throws HeadlessException 

Source Link

Document

Shows a dialog requesting input from the user parented to parentComponent with the dialog having the title title and message type messageType.

Usage

From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java

private Group createGroupFromPrompter() {
    Object input = JOptionPane.showInputDialog(getPanel(), "Enter a name for the group.",
            "Enter the name of the group.", JOptionPane.INFORMATION_MESSAGE);
    if (input != null && !input.equals("")) {
        return new Group((String) input);
    } else {//  w ww  .j a  v  a  2s  . c o m
        return null;
    }
}

From source file:com.ejie.uda.jsonI18nEditor.Editor.java

public void showFindTranslationDialog() {
    String key = (String) JOptionPane.showInputDialog(this, MessageBundle.get("dialogs.translation.find.text"),
            MessageBundle.get("dialogs.translation.find.title"), JOptionPane.QUESTION_MESSAGE);
    if (key != null) {
        TranslationTreeNode node = translationTree.getNodeByKey(key.trim());
        if (node == null) {
            showWarning(MessageBundle.get("dialogs.translation.find.title"),
                    MessageBundle.get("dialogs.translation.find.error"));
        } else {/*from w w w  .java  2 s .  c  o  m*/
            translationTree.setSelectedNode(node);
        }
    }
}

From source file:net.sf.jabref.sql.exporter.DatabaseExporter.java

private String getDBName(Vector<Vector<String>> matrix, DBStrings databaseStrings, JabRefFrame frame,
        DBImportExportDialog dialogo) throws Exception {
    String dbName = "";
    if (matrix.size() > 1) {
        if (dialogo.hasDBSelected) {
            dbName = dialogo.selectedDB;
            if ((dialogo.selectedInt == 0) && (!dialogo.removeAction)) {
                dbName = JOptionPane.showInputDialog(dialogo.getDiag(),
                        Localization.lang("Please enter the desired name:"), Localization.lang("SQL Export"),
                        JOptionPane.INFORMATION_MESSAGE);
                if (dbName == null) {
                    getDBName(matrix, databaseStrings, frame,
                            new DBImportExportDialog(frame, matrix, DBImportExportDialog.DialogType.EXPORTER));
                } else {
                    while (!isValidDBName(dbNames, dbName)) {
                        dbName = JOptionPane.showInputDialog(dialogo.getDiag(),
                                Localization.lang("You have entered an invalid or already existent DB name.")
                                        + '\n' + Localization.lang("Please enter the desired name:"),
                                Localization.lang("SQL Export"), JOptionPane.ERROR_MESSAGE);
                    }/* w w  w .  j a  v a2 s .  com*/
                }
            }
        }
    } else {
        dbName = JOptionPane.showInputDialog(frame, Localization.lang("Please enter the desired name:"),
                Localization.lang("SQL Export"), JOptionPane.INFORMATION_MESSAGE);
    }
    return dbName;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java

private void newConfigFile() {
    String fileName = JOptionPane.showInputDialog(null, "Please enter a name for the new configuration:",
            "Configuration Name", JOptionPane.QUESTION_MESSAGE);
    if (fileName == null) {
        return;/*from ww  w  .  j  av a 2 s  .c o  m*/
    }

    if (!isExtension(fileName, "xml")) {
        fileName += ".xml";
    }
    checkState(isNotBlank(fileName), "File name must not be empty.");
    checkState(!configFiles.contains(fileName), "The file '" + fileName + "' already exists.");

    configFiles.add(fileName);

    controller.setActiveSettingsFile(fileName);
    cboConfigurationFile.setSelectedItem(fileName);
}

From source file:com.mirth.connect.client.ui.SettingsPanelServer.java

public void doClearAllStats() {
    String result = JOptionPane.showInputDialog(this,
            "<html>This will reset all channel statistics (including lifetime statistics) for<br>all channels (including undeployed channels).<br><font size='1'><br></font>Type CLEAR and click the OK button to continue.</html>",
            "Clear All Statistics", JOptionPane.WARNING_MESSAGE);

    if (result != null) {
        if (!result.equals("CLEAR")) {
            getFrame().alertWarning(SettingsPanelServer.this, "You must type CLEAR to clear all statistics.");
            return;
        }/*from w ww.j  a v  a 2 s. c om*/

        final String workingId = getFrame().startWorking("Clearing all statistics...");

        SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

            private Exception exception = null;

            public Void doInBackground() {
                try {
                    getFrame().mirthClient.clearAllStatistics();
                } catch (ClientException e) {
                    exception = e;
                    getFrame().alertThrowable(SettingsPanelServer.this, e);
                }
                return null;
            }

            public void done() {
                getFrame().stopWorking(workingId);

                if (exception == null) {
                    getFrame().alertInformation(SettingsPanelServer.this,
                            "All current and lifetime statistics have been cleared for all channels.");
                }
            }
        };

        worker.execute();
    }
}

From source file:com.mgmtp.perfload.loadprofiles.ui.dialog.SettingsDialog.java

private void copyConfigFile() {
    if (checkDirty()) {
        String fileName = JOptionPane.showInputDialog(null, "Please enter a name for the copied configuration:",
                "Configuration Name", JOptionPane.QUESTION_MESSAGE);
        if (fileName == null) {
            return;
        }/*from  ww  w.j a v  a  2  s .  c  o  m*/

        if (!isExtension(fileName, "xml")) {
            fileName += ".xml";
        }
        checkState(isNotBlank(fileName), "File name must not be empty.");
        checkState(!configFiles.contains(fileName), "The file '" + fileName + "' already exists.");

        configFiles.add(fileName);
        controller.copyActiveSettingsFile(fileName);
        cboConfigurationFile.setSelectedItem(fileName);
    }
}

From source file:fi.hoski.remote.ui.Admin.java

private JMenuItem menuItemRemoveYear() {
    final String title = TextUtil.getText("REMOVE YEAR");
    JMenuItem removeEntityItem = new JMenuItem(title);
    ActionListener removeEntityAction = new ActionListener() {

        @Override//w  w  w .java 2  s .  c o  m
        public void actionPerformed(ActionEvent e) {
            Object yearString = JOptionPane.showInputDialog(frame, title, "", JOptionPane.OK_CANCEL_OPTION);
            if (yearString != null) {
                String confirm = TextUtil.getText("CONFIRM REMOVE") + " " + yearString;
                if (JOptionPane.showConfirmDialog(frame, confirm, "",
                        JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    long year = Long.parseLong(yearString.toString());
                    Day now = new Day();
                    if (year < now.getYear()) {
                        int count = dss.remove(year);
                        JOptionPane.showMessageDialog(frame, TextUtil.getText("REMOVED") + " " + count);
                    } else {
                        JOptionPane.showMessageDialog(frame, TextUtil.getText("CANNOT REMOVE") + " " + year);
                    }
                }
            }
        }
    };
    removeEntityAction = createActionListener(frame, removeEntityAction);
    removeEntityItem.addActionListener(removeEntityAction);
    return removeEntityItem;
}

From source file:com.sciaps.view.SpectrumShotPanel.java

private void doDeleteScan() {
    boolean allgood = false;

    if (tblShots_.getRowCount() == 0) {
        showErrorDialog("List is Empty. Nothing to delete.");
        return;//from   w  w w .  j ava  2  s .c  om
    }

    while (allgood == false) {

        String retval = JOptionPane.showInputDialog(Constants.MAIN_FRAME, "Enter the scan number to delete:",
                "Delete Scan", JOptionPane.QUESTION_MESSAGE);

        if (retval == null) {
            allgood = true;
        } else {
            try {
                int scanID = Integer.parseInt(retval);

                if (scanID > 0) {
                    allgood = true;
                    shotListTableModel_.deleteScan(scanID);
                }
            } catch (NumberFormatException ex) {
                showErrorDialog("Invalid Scan #: " + retval);
            }
        }
    }
}

From source file:com.pianobakery.complsa.LicenseKeyGUI.java

private void changeProductKeyjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeProductKeyjButtonActionPerformed
    /**/*from   w w w  . jav  a 2  s .co  m*/
     * Basically we show an input dialog to get license key. It will be
     * better to use a JDialog with required license key input fields.
     */
    String key = JOptionPane.showInputDialog(null, "Enter License Key", "License Key",
            JOptionPane.QUESTION_MESSAGE);

    if (key != null) {
        key = key.trim(); // the license key (trim it because user may copy/paste with spaces etc)

        /**
         * First validate license and get a temporary license object to
         * check for validation status later.
         */
        License temporaryLicenseObject = LicenseValidator.validate(key, publicKey, internalString,
                nameforValidation, companyforValidation, hardwareIDMethod);

        /**
         * If given license key is valid, then save it on disk, and update
         * GUI fields.
         */
        if (temporaryLicenseObject.getValidationStatus() == ValidationStatus.LICENSE_VALID) {
            licenseObject = temporaryLicenseObject;

            try {
                /**
                 * We use Apache commons-io (FileUtils class) to easily save
                 * string to file.
                 */
                FileUtils.writeStringToFile(new File(licenseKeyFileOnDisk), key);

                /**
                 * Since license key is changed delete license text file if
                 * exists on disk left from previous license key.
                 */
                FileUtils.deleteQuietly(new File(licenseTextFileOnDisk));
            } catch (IOException ex) {
                Logger.getLogger(LicenseKeyGUI.class.getName()).log(Level.SEVERE, null, ex);
            }

            updateGUIFieldsWithLicenseObject();
        } else {
            /**
             * If given license is not valid, display an error message.
             */
            JOptionPane.showMessageDialog(null,
                    "License error: " + temporaryLicenseObject.getValidationStatus(), "License Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:fi.hoski.remote.ui.Admin.java

private JMenuItem menuItemBackupYear() {
    final String title = TextUtil.getText("BACKUP YEAR");
    JMenuItem backupYearItem = new JMenuItem(title);
    ActionListener backupYearAction = new ActionListener() {

        @Override/*from  www .j  av  a  2s .c  om*/
        public void actionPerformed(ActionEvent e) {
            Object yearString = JOptionPane.showInputDialog(frame, title, "", JOptionPane.OK_CANCEL_OPTION);
            if (yearString != null) {
                long year = Long.parseLong(yearString.toString());
                File file = saveFile(BACKUPDIR, year + ".ser", ".ser", "Backup");
                if (file != null) {
                    int count;
                    try (FileOutputStream fos = new FileOutputStream(file)) {
                        BufferedOutputStream bos = new BufferedOutputStream(fos);
                        ObjectOutputStream oos = new ObjectOutputStream(bos);
                        count = dss.backup(year, oos);
                        JOptionPane.showMessageDialog(frame, TextUtil.getText("STORED") + " " + count);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(frame, ex.getMessage());
                    }
                }
            }
        }
    };
    backupYearAction = createActionListener(frame, backupYearAction);
    backupYearItem.addActionListener(backupYearAction);
    return backupYearItem;
}