Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

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

Prototype

int OK_OPTION

To view the source code for javax.swing JOptionPane OK_OPTION.

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:se.trixon.jota.client.ui.editor.TasksPanel.java

private void removeAllButtonActionPerformed(ActionEvent evt) {
    if (!getModel().isEmpty()) {
        int retval = JOptionPane.showConfirmDialog(getRoot(), mBundle.getString("TasksPanel.message.removeAll"),
                mBundle.getString("TasksPanel.title.removeAll"), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE);

        if (retval == JOptionPane.OK_OPTION) {
            getModel().removeAllElements();
            notifyTaskListenersChanged();
        }//  w  w  w .  j a  va  2  s.  c  o  m
    }
}

From source file:se.trixon.jota.client.ui.editor.TasksPanel.java

private void removeButtonActionPerformed(ActionEvent evt) {
    int[] indices = list.getSelectedIndices();

    if (indices.length > 0) {
        StringBuilder sb = new StringBuilder();
        for (int index : indices) {
            Task task = (Task) getModel().getElementAt(index);
            sb.append(task.getName()).append("\n");
        }/* w  w w. jav  a  2  s  .  c  o m*/

        String message = String.format(mBundle.getString("TasksPanel.message.remove"), sb.toString());
        int retval = JOptionPane.showConfirmDialog(getRoot(), message,
                mBundle.getString("TasksPanel.title.remove"), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE);

        if (retval == JOptionPane.OK_OPTION) {
            for (int i = indices.length - 1; i >= 0; i--) {
                getModel().removeElement(getModel().getElementAt(indices[i]));
            }

            sortModel();
            notifyTaskListenersChanged();
        }
    }
}

From source file:se.trixon.jota.client.ui.MainFrame.java

void showEditor(long jobId, boolean openJob) {
    EditorPanel editorPanel = new EditorPanel(jobId, openJob);
    SwingHelper.makeWindowResizable(editorPanel);

    int retval = JOptionPane.showOptionDialog(this, editorPanel, mBundle.getString("jobEditor"),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);

    if (retval == JOptionPane.OK_OPTION) {
        editorPanel.save();/*  ww w.  ja  v a2 s.c  o  m*/
        try {
            mManager.getServerCommander().saveJota();
        } catch (RemoteException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void showOptions() {
    OptionsPanel optionsPanel = new OptionsPanel();
    SwingHelper.makeWindowResizable(optionsPanel);

    int retval = JOptionPane.showOptionDialog(this, optionsPanel, Dict.OPTIONS.toString(),
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);

    if (retval == JOptionPane.OK_OPTION) {
        optionsPanel.save();/*  ww  w. j  ava2 s.  co  m*/
    }
}

From source file:se.trixon.mapollage.ui.MainFrame.java

private void profileRemove() {
    if (!mProfiles.isEmpty()) {
        String message = String.format(Dict.Dialog.MESSAGE_PROFILE_REMOVE.toString(),
                getSelectedProfile().getName());
        int retval = JOptionPane.showConfirmDialog(this, message, Dict.Dialog.TITLE_PROFILE_REMOVE.toString(),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);

        if (retval == JOptionPane.OK_OPTION) {
            mProfiles.remove(getSelectedProfile());
            populateProfiles(null, 0);//from   w  ww  . j  a va  2s. c om
        }
    }
}

From source file:se.trixon.mapollage.ui.MainFrame.java

private void profileRemoveAll() {
    if (!mProfiles.isEmpty()) {
        String message = String.format(Dict.Dialog.MESSAGE_PROFILE_REMOVE_ALL.toString(),
                getSelectedProfile().getName());
        int retval = JOptionPane.showConfirmDialog(this, message,
                Dict.Dialog.TITLE_PROFILE_REMOVE_ALL.toString(), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE);

        if (retval == JOptionPane.OK_OPTION) {
            mProfiles.clear();//from www. j ava2  s. c  om
            populateProfiles(null, 0);
        }
    }
}

From source file:tvbrowser.core.Settings.java

/**
 * Reads the settings from settings file. If there is no settings file,
 * default settings are used./*from w  w w . j  a va 2  s.  c o  m*/
 */
public static void loadSettings() {
    String oldDirectoryName = System.getProperty("user.home", "") + File.separator + ".tvbrowser";
    String newDirectoryName = getUserSettingsDirName();

    File settingsFile = new File(newDirectoryName, SETTINGS_FILE);
    File firstSettingsBackupFile = new File(getUserSettingsDirName(), SETTINGS_FILE + "_backup1");
    File secondSettingsBackupFile = new File(getUserSettingsDirName(), SETTINGS_FILE + "_backup2");

    if (settingsFile.exists() || firstSettingsBackupFile.exists() || secondSettingsBackupFile.exists()) {
        try {
            mProp.readFromFile(settingsFile);

            if (((mProp.getProperty("subscribedchannels") == null
                    || mProp.getProperty("subscribedchannels").trim().length() < 1)
                    && (mProp.getProperty("channelsWereConfigured") != null
                            && mProp.getProperty("channelsWereConfigured").equals("true")))
                    && (firstSettingsBackupFile.isFile() || secondSettingsBackupFile.isFile())) {
                throw new IOException();
            } else {
                mLog.info("Using settings from file " + settingsFile.getAbsolutePath());
            }
        } catch (IOException evt) {

            if (firstSettingsBackupFile.isFile() || secondSettingsBackupFile.isFile()) {
                Localizer localizer = Localizer.getLocalizerFor(Settings.class);
                if (JOptionPane.showConfirmDialog(null, localizer.msg("settingBroken",
                        "Settings file broken.\nWould you like to load the backup file?\n\n(If you select No, the\ndefault settings are used)"),
                        Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
                    boolean loadSecondBackup = !firstSettingsBackupFile.isFile();

                    if (firstSettingsBackupFile.isFile()) {
                        try {
                            mProp.readFromFile(firstSettingsBackupFile);

                            if ((mProp.getProperty("subscribedchannels") == null
                                    || mProp.getProperty("subscribedchannels").trim().length() < 1)
                                    && secondSettingsBackupFile.isFile()) {
                                loadSecondBackup = true;
                            } else {
                                mLog.info("Using settings from file "
                                        + firstSettingsBackupFile.getAbsolutePath());
                                loadSecondBackup = false;
                            }
                        } catch (Exception e) {
                            loadSecondBackup = true;
                        }
                    }
                    if (loadSecondBackup && secondSettingsBackupFile.isFile()) {
                        try {
                            mProp.readFromFile(secondSettingsBackupFile);
                            mLog.info("Using settings from file " + secondSettingsBackupFile.getAbsolutePath());
                            loadSecondBackup = false;
                        } catch (Exception e) {
                            loadSecondBackup = true;
                        }
                    }

                    if (loadSecondBackup) {
                        mLog.info("Could not read settings - using default user settings");
                    } else {
                        try {
                            loadWindowSettings();
                            storeSettings(true);
                        } catch (Exception e) {
                        }
                    }
                }
            } else {
                mLog.info("Could not read settings - using default user settings");
            }
        }
    }
    /*
     * If the settings file doesn't exist, we try to import the settings created
     * by a previous version of TV-Browser
     */
    else if (!oldDirectoryName.equals(newDirectoryName)) {
        File oldDir = null;
        File testFile = null;

        int countValue = 1;

        String firstDir = System.getProperty("user.home") + "/TV-Browser";

        if (Launch.isOsWindowsNtBranch()) {
            countValue = 3;
        }

        if (OperatingSystem.isWindows()) {
            File test = new File(System.getenv("appdata"), "TV-Browser");

            if (test.isDirectory()) {
                firstDir = test.getAbsolutePath();
            }
        }

        String[] directories = { getUserDirectoryName(), firstDir,
                System.getProperty("user.home") + "/TV-Browser",
                System.getProperty("user.home") + "/Library/Preferences/TV-Browser",
                System.getProperty("user.home") + "/.tvbrowser" };

        for (int j = 0; j < (TVBrowser.isTransportable() ? directories.length : countValue); j++) {
            String[] allVersions = TVBrowser.getAllVersionStrings();
            for (int i = (j == 0 ? 1 : 0); i < allVersions.length; i++) {
                testFile = new File(directories[j] + File.separator + allVersions[i], SETTINGS_FILE);

                if (testFile.isFile()) {
                    oldDir = new File(directories[j], allVersions[i]);
                    break;
                }
            }

            if (oldDir == null) {
                testFile = new File(directories[j], SETTINGS_FILE);

                if (testFile.isFile()) {
                    oldDir = new File(directories[j]);
                } else {
                    testFile = new File(oldDirectoryName, SETTINGS_FILE);

                    if (testFile.isFile()) {
                        oldDir = new File(oldDirectoryName);
                    }
                }
            }

            if (oldDir != null) {
                break;
            }
        }

        if (oldDir != null && oldDir.isDirectory() && oldDir.exists() && TVBrowser.isTransportable()
                && !oldDir.getAbsolutePath().startsWith(new File("settings").getAbsolutePath())) {
            try {
                UIManager.setLookAndFeel(getDefaultLookAndFeelClassName());
            } catch (Exception e) {
                /*ignore*/}

            String[] options = { MainFrame.mLocalizer.msg("import", "Import settings"),
                    MainFrame.mLocalizer.msg("configureNew", "Create new configuration") };
            String title = MainFrame.mLocalizer.msg("importInfoTitle", "Import settings?");
            String msg = MainFrame.mLocalizer.msg("importInfoMsg",
                    "TV-Browser has found settings for import.\nShould the settings be imported now?");

            if (JOptionPane.showOptionDialog(null, msg, title, JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE, null, options, options[0]) == JOptionPane.NO_OPTION) {
                oldDir = null;
            }
        }

        if (oldDir != null && oldDir.isDirectory() && oldDir.exists()) {
            startImportWaitingDlg();
            mLog.info("Try to load settings from a previous version of TV-Browser: " + oldDir);

            final File newDir = new File(getUserSettingsDirName());

            File oldTvDataDir = null;

            final Properties prop = new Properties();

            try {
                StreamUtilities.inputStream(testFile, new InputStreamProcessor() {
                    public void process(InputStream input) throws IOException {
                        prop.load(input);
                    }
                });
            } catch (Exception e) {
            }

            String versionString = prop.getProperty("version", null);
            Version testVersion = null;

            if (versionString != null) {
                try {
                    int asInt = Integer.parseInt(versionString);
                    int major = asInt / 100;
                    int minor = asInt % 100;
                    testVersion = new Version(major, minor);
                } catch (NumberFormatException exc) {
                    // Ignore
                }
            }

            String temp = prop.getProperty("dir.tvdata", null);
            boolean versionTest = !TVBrowser.isTransportable() && Launch.isOsWindowsNtBranch()
                    && testVersion != null && testVersion.compareTo(new Version(3, 0, true)) < 0
                    && (temp == null || temp.replace("/", "\\")
                            .equals(System.getProperty("user.home") + "\\TV-Browser\\tvdata"));

            if ((TVBrowser.isTransportable() || versionTest)
                    && !(new File(getUserDirectoryName(), "tvdata").isDirectory())) {
                try {
                    if (temp != null) {
                        oldTvDataDir = new File(temp);
                    } else if (new File(oldDir, "tvdata").isDirectory()) {
                        oldTvDataDir = new File(oldDir, "tvdata");
                    } else if (new File(oldDir.getParent(), "tvdata").isDirectory()) {
                        oldTvDataDir = new File(oldDir.getParent(), "tvdata");
                    }

                } catch (Exception e) {
                }
            }

            if (newDir.mkdirs()) {
                try {
                    IOUtilities.copy(oldDir.listFiles(new FilenameFilter() {
                        public boolean accept(File dir, String name) {
                            return !name.equalsIgnoreCase("tvdata") && !name.equals(newDir.getName())
                                    && !name.equalsIgnoreCase("backup") && !name.equalsIgnoreCase("lang");
                        }
                    }), newDir);

                    mShowSettingsCopyWaiting = false;

                    mLog.info("settings from previous version copied successfully");
                    File newSettingsFile = new File(newDir, SETTINGS_FILE);
                    mProp.readFromFile(newSettingsFile);
                    mLog.info("settings from previous version read successfully");

                    /*
                     * This is the .tvbrowser dir, if there are settings form version
                     * 1.0 change the name to start with java.
                     */
                    if (oldDirectoryName.equals(oldDir.getAbsolutePath())) {
                        File[] settings = newDir.listFiles(new FilenameFilter() {
                            public boolean accept(File dir, String name) {
                                return (name.toLowerCase().endsWith(".prop")
                                        && name.toLowerCase().indexOf("settings") == -1)
                                        || (name.toLowerCase().endsWith(".dat")
                                                && name.toLowerCase().indexOf("tv-data-inventory") == -1);
                            }
                        });

                        boolean version1 = false;

                        if (settings != null) {
                            for (int i = 0; i < settings.length; i++) {
                                String name = "java." + settings[i].getName();

                                if (!settings[i].getName().toLowerCase().startsWith("java.")) {
                                    version1 = true;
                                    settings[i].renameTo(new File(settings[i].getParent(), name));
                                }
                            }
                        }

                        if (version1 && !(new File(oldDirectoryName, newDir.getName())).isDirectory()) {
                            oldDir.renameTo(new File(
                                    System.getProperty("user.home", "") + File.separator + "tvbrowser_BACKUP"));
                        }
                    }

                    /*
                     * Test if and copy TV data for the portable version.
                     */
                    if (oldTvDataDir != null && oldTvDataDir.isDirectory()) {
                        final File targetDir = new File(getUserDirectoryName(), "tvdata");

                        if (!oldTvDataDir.equals(targetDir)) {
                            targetDir.mkdirs();

                            final CopyWaitingDlg waiting = new CopyWaitingDlg(new JFrame(),
                                    versionTest ? CopyWaitingDlg.APPDATA_MSG : CopyWaitingDlg.IMPORT_MSG);

                            mShowWaiting = true;

                            final File srcDir = oldTvDataDir;

                            Thread copyDataThread = new Thread("Copy TV data directory") {
                                public void run() {
                                    try {
                                        IOUtilities.copy(srcDir.listFiles(), targetDir, true);
                                    } catch (Exception e) {
                                    }

                                    mShowWaiting = false;
                                    waiting.setVisible(false);
                                }
                            };
                            copyDataThread.start();

                            waiting.setVisible(mShowWaiting);
                        }
                    }

                    /*
                     * Test if a settings file exist in the user directory, move the
                     * settings to backup.
                     */
                    if ((new File(getUserDirectoryName(), SETTINGS_FILE)).isFile()) {
                        final File backupDir = new File(getUserDirectoryName(), "BACKUP");
                        if (backupDir.mkdirs()) {
                            mLog.info("moving the settings of old settings dir to backup");
                            File[] files = oldDir.listFiles(new FileFilter() {
                                public boolean accept(File pathname) {
                                    return pathname.compareTo(newDir) != 0
                                            && pathname.getName().compareToIgnoreCase("tvdata") != 0
                                            && pathname.compareTo(backupDir) != 0;
                                }
                            });

                            if (files != null) {
                                for (File file : files) {
                                    file.renameTo(new File(backupDir, file.getName()));
                                }
                            }
                        }
                    }
                } catch (IOException e) {
                    mLog.log(Level.WARNING, "Could not import user settings from '" + oldDir.getAbsolutePath()
                            + "' to '" + newDir.getAbsolutePath() + "'", e);
                }
            } else {
                mLog.info("Could not create directory '" + newDir.getAbsolutePath()
                        + "' - using default user settings");
            }
        } else {
            mLog.info("No previous version of TV-Browser found - using default user settings");
        }
    }
    mShowSettingsCopyWaiting = false;

    File settingsDir = new File(newDirectoryName);

    if (!settingsDir.exists()) {
        mLog.info("Creating " + newDirectoryName);
        settingsDir.mkdir();
    }

    loadWindowSettings();
}

From source file:ua.utility.fkindexgenerator.UIUtils.java

/**
 *
 * @param c/*from  w  ww  .  j av  a2s.  c  o  m*/
 * @param title
 * @param prompt
 * @return
 */
public static boolean promptForCancel(Component c, String title, String prompt) {
    return (JOptionPane.showConfirmDialog(c, prompt, title,
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION);
}

From source file:uk.ac.soton.mib104.t2.activities.json.ui.config.JSONPathConfigurationPanel.java

protected void initGui() {
    this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    this.setLayout(new GridBagLayout());

    jsonPathAsTextField.setMinimumSize(new Dimension(240, jsonPathAsTextField.getMinimumSize().height));
    jsonPathAsTextField.setPreferredSize(jsonPathAsTextField.getMinimumSize());
    jsonPathAsTextField.setText("");

    jsonPathButton.addActionListener(new ActionListener() {

        @Override//w  w  w.  j a  v a2 s. c o m
        public void actionPerformed(final ActionEvent e) {
            final JSONPathInputDialog jsonPathInputDialog = new JSONPathInputDialog(
                    SwingUtilities.getWindowAncestor(JSONPathConfigurationPanel.this));

            final JSONPathInputPanel jsonPathInputPane = jsonPathInputDialog.getJSONPathInputPane();

            jsonPathInputPane.getJSONDocumentEditorPane().setText(jsonPathInputDialog_jsonPathEditorPane_text);

            jsonPathInputPane.getJsonPathEditorPane()
                    .setJSONValue(jsonPathInputDialog_jsonPathEditorPane_value);
            jsonPathInputPane.getJsonPathEditorPane()
                    .setTreeVisible(jsonPathInputDialog_jsonPathEditorPane_treeVisible);
            jsonPathInputPane.getJsonPathEditorPane().setText(jsonPathAsTextField.getText());

            jsonPathInputDialog.setVisible(true);

            switch (jsonPathInputDialog.getOption()) {
            case JOptionPane.OK_OPTION:
                break;
            default:
                return;
            }

            jsonPathInputDialog_jsonPathEditorPane_text = jsonPathInputPane.getJSONDocumentEditorPane()
                    .getText();
            jsonPathInputDialog_jsonPathEditorPane_treeVisible = jsonPathInputPane.getJsonPathEditorPane()
                    .isTreeVisible();
            jsonPathInputDialog_jsonPathEditorPane_value = jsonPathInputPane.getJsonPathEditorPane()
                    .getJSONValue();

            jsonPathAsTextField.setText(jsonPathInputPane.getJsonPathEditorPane().getText());
        }

    });
    jsonPathButton.setFont(jsonPathButton.getFont().deriveFont(11f));
    jsonPathButton.setIcon(JSONPathServiceIcon.getIcon());
    jsonPathButton.setText(jsonPathButtonText);
    jsonPathButton.setToolTipText(jsonPathButtonTip);

    final JLabel portDepthLabel = new JLabel();
    portDepthLabel.setFont(portDepthLabel.getFont().deriveFont(11f));
    portDepthLabel.setHorizontalAlignment(JLabel.LEFT);
    portDepthLabel.setIcon(Silk.getHelpIcon());
    portDepthLabel.setText(portDepthInputPaneText);
    portDepthLabel.setToolTipText(portDepthInputPaneTip);

    final GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 0;

    constraints.anchor = GridBagConstraints.WEST;
    this.add(JSONPathTextField.createLabelForDocument(jsonPathAsTextField.getDocument()), constraints);

    constraints.gridx++;

    constraints.anchor = GridBagConstraints.EAST;
    constraints.weightx = 1d;
    this.add(jsonPathAsTextField, constraints);
    constraints.weightx = 0;

    constraints.gridx++;

    constraints.fill = GridBagConstraints.NONE;
    this.add(jsonPathButton, constraints);

    constraints.gridx--;

    constraints.gridy++;

    constraints.anchor = GridBagConstraints.CENTER;
    this.add(JSONPathTextField.createLabelForDocumentationURI(), constraints);
    constraints.fill = GridBagConstraints.HORIZONTAL;

    constraints.gridx = 0;
    constraints.gridy++;

    constraints.gridwidth = 3;
    this.add(new JSeparator(JSeparator.HORIZONTAL), constraints);
    constraints.gridwidth = 1;

    constraints.gridx = 0;
    constraints.gridy++;

    constraints.anchor = GridBagConstraints.WEST;
    this.add(portDepthLabel, constraints);

    constraints.gridx++;

    constraints.anchor = GridBagConstraints.EAST;
    constraints.gridwidth = 2;
    this.add(portDepthInputPane, constraints);
    constraints.gridwidth = 1;
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.restserver.GiftCloudLoginDialog.java

public PasswordAuthentication getPasswordAuthentication(final String prompt) {
    // Set the default background colour to white
    UIManager UI = new UIManager();
    UI.put("OptionPane.background", Color.white);
    UI.put("Panel.background", Color.white);

    String defaultUserName = "";
    if (giftCloudProperties.getLastUserName().isPresent()) {
        defaultUserName = giftCloudProperties.getLastUserName().get();
    }//from   www . j a  v a2 s.c  o m

    // Create a panel for entering username and password
    final JPanel usernamePasswordPanel = new JPanel(new GridBagLayout());

    final JLabel promptField = new JLabel(prompt, SwingConstants.CENTER);
    final JTextField usernameField = new JTextField(defaultUserName, 16);
    final JPasswordField passwordField = new JPasswordField(16);

    // Add a special listener to get the focus onto the username field when the component is created, or password if the username has already been populated from the default value
    if (StringUtils.isBlank(defaultUserName)) {
        usernameField.addAncestorListener(new RequestFocusListener());
    } else {
        passwordField.addAncestorListener(new RequestFocusListener());
    }

    usernamePasswordPanel.add(promptField, promptConstraint);
    usernamePasswordPanel.add(new JLabel("Username:"), labelConstraint);
    usernamePasswordPanel.add(usernameField, fieldConstraint);
    usernamePasswordPanel.add(new JLabel("Password:"), labelConstraint);
    usernamePasswordPanel.add(passwordField, fieldConstraint);

    // Show the login dialog
    final int returnValue = JOptionPane.showConfirmDialog(new JDialog(getFrame(parent)), usernamePasswordPanel,
            LOGIN_DIALOG_TITLE, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon);

    if (JOptionPane.OK_OPTION == returnValue) {
        giftCloudProperties.setLastUserName(usernameField.getText());
        giftCloudProperties.setLastPassword(passwordField.getPassword());
        giftCloudProperties.save();

        return new PasswordAuthentication(usernameField.getText(), passwordField.getPassword());
    } else {
        return null;
    }
}