Example usage for javax.swing JOptionPane createDialog

List of usage examples for javax.swing JOptionPane createDialog

Introduction

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

Prototype

public JDialog createDialog(Component parentComponent, String title) throws HeadlessException 

Source Link

Document

Creates and returns a new JDialog wrapping this centered on the parentComponent in the parentComponent's frame.

Usage

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * Prompt the user to enter a password//w  w  w  . j av  a 2  s. c o m
 * @return The password entered by the user or null of this hit escape/cancel
 */
private char[] askUserForPassword(String message) {
    char[] password = null;

    final JPasswordField masterPassword = new JPasswordField("");
    JOptionPane pane = new JOptionPane(new Object[] { message, masterPassword }, JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword"));
    dialog.addWindowFocusListener(new WindowAdapter() {
        public void windowGainedFocus(WindowEvent e) {
            masterPassword.requestFocusInWindow();
        }
    });
    dialog.show();

    if (pane.getValue() != null && pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) {
        password = masterPassword.getPassword();
    }

    return password;
}

From source file:com.floreantpos.config.ui.TerminalConfigurationView.java

public void restartPOS() {
    JOptionPane optionPane = new JOptionPane(Messages.getString("TerminalConfigurationView.26"), //$NON-NLS-1$
            JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, Application.getApplicationIcon(),
            new String[] { /*Messages.getString("TerminalConfigurationView.28"),*/Messages
                    .getString("TerminalConfigurationView.30") }); //$NON-NLS-1$ //$NON-NLS-2$

    Object[] optionValues = optionPane.getComponents();
    for (Object object : optionValues) {
        if (object instanceof JPanel) {
            JPanel panel = (JPanel) object;
            Component[] components = panel.getComponents();

            for (Component component : components) {
                if (component instanceof JButton) {
                    component.setPreferredSize(new Dimension(100, 80));
                    JButton button = (JButton) component;
                    button.setPreferredSize(PosUIManager.getSize(100, 50));
                }//  w  w w . j av  a 2  s  .  c om
            }
        }
    }
    JDialog dialog = optionPane.createDialog(Application.getPosWindow(),
            Messages.getString("TerminalConfigurationView.31")); //$NON-NLS-1$
    dialog.setIconImage(Application.getApplicationIcon().getImage());
    dialog.setLocationRelativeTo(Application.getPosWindow());
    dialog.setVisible(true);
    Object selectedValue = (String) optionPane.getValue();
    if (selectedValue != null) {

        if (selectedValue.equals(Messages.getString("TerminalConfigurationView.28"))) { //$NON-NLS-1$
            try {
                Main.restart();
            } catch (IOException | InterruptedException | URISyntaxException e) {
            }
        } else {
        }
    }

}

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * This method asks the user for the name of a new database and then creates
 * it. If the file already exists then the user is asked if they'd like to
 * overwrite it./*from   ww  w  . j a  v a 2  s . c o  m*/
 * @throws CryptoException 
 * @throws IOException 
 */
public void newDatabase() throws IOException, CryptoException {

    File newDatabaseFile = getSaveAsFile(Translator.translate("newPasswordDatabase"));
    if (newDatabaseFile == null) {
        return;
    }

    final JPasswordField masterPassword = new JPasswordField("");
    boolean passwordsMatch = false;
    do {

        //Get a new master password for this database from the user
        JPasswordField confirmedMasterPassword = new JPasswordField("");
        JOptionPane pane = new JOptionPane(
                new Object[] { Translator.translate("enterMasterPassword"), masterPassword,
                        Translator.translate("confirmation"), confirmedMasterPassword },
                JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
        JDialog dialog = pane.createDialog(mainWindow, Translator.translate("masterPassword"));
        dialog.addWindowFocusListener(new WindowAdapter() {
            public void windowGainedFocus(WindowEvent e) {
                masterPassword.requestFocusInWindow();
            }
        });
        dialog.show();

        if (pane.getValue().equals(new Integer(JOptionPane.OK_OPTION))) {
            if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) {
                JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch"));
            } else {
                passwordsMatch = true;
            }
        } else {
            return;
        }

    } while (passwordsMatch == false);

    if (newDatabaseFile.exists()) {
        newDatabaseFile.delete();
    }

    database = new PasswordDatabase(newDatabaseFile);
    dbPers = new PasswordDatabasePersistence(masterPassword.getPassword());
    saveDatabase();
    accountNames = new ArrayList();
    doOpenDatabaseActions();

    // If a "Database to Load on Startup" hasn't been set yet then ask the
    // user if they'd like to open this database on startup.
    if (Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP) == null
            || Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP).equals("")) {
        int option = JOptionPane.showConfirmDialog(mainWindow,
                Translator.translate("setNewLoadOnStartupDatabase"),
                Translator.translate("newPasswordDatabase"), JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            Preferences.set(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP,
                    newDatabaseFile.getAbsolutePath());
            Preferences.save();
        }
    }
}

From source file:com._17od.upm.gui.DatabaseActions.java

public void changeMasterPassword() throws IOException, ProblemReadingDatabaseFile, CryptoException,
        PasswordDatabaseException, TransportException {

    if (getLatestVersionOfDatabase()) {
        //The first task is to get the current master password
        boolean passwordCorrect = false;
        boolean okClicked = true;
        do {//from  w ww  . j  a v  a2 s. c  o  m
            char[] password = askUserForPassword(Translator.translate("enterDatabasePassword"));
            if (password == null) {
                okClicked = false;
            } else {
                try {
                    dbPers.load(database.getDatabaseFile(), password);
                    passwordCorrect = true;
                } catch (InvalidPasswordException e) {
                    JOptionPane.showMessageDialog(mainWindow, Translator.translate("incorrectPassword"));
                }
            }
        } while (!passwordCorrect && okClicked);

        //If the master password was entered correctly then the next step is to get the new master password
        if (passwordCorrect == true) {

            final JPasswordField masterPassword = new JPasswordField("");
            boolean passwordsMatch = false;
            Object buttonClicked;

            //Ask the user for the new master password
            //This loop will continue until the two passwords entered match or until the user hits the cancel button
            do {

                JPasswordField confirmedMasterPassword = new JPasswordField("");
                JOptionPane pane = new JOptionPane(
                        new Object[] { Translator.translate("enterNewMasterPassword"), masterPassword,
                                Translator.translate("confirmation"), confirmedMasterPassword },
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
                JDialog dialog = pane.createDialog(mainWindow, Translator.translate("changeMasterPassword"));
                dialog.addWindowFocusListener(new WindowAdapter() {
                    public void windowGainedFocus(WindowEvent e) {
                        masterPassword.requestFocusInWindow();
                    }
                });
                dialog.show();

                buttonClicked = pane.getValue();
                if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION))) {
                    if (!Arrays.equals(masterPassword.getPassword(), confirmedMasterPassword.getPassword())) {
                        JOptionPane.showMessageDialog(mainWindow, Translator.translate("passwordsDontMatch"));
                    } else {
                        passwordsMatch = true;
                    }
                }

            } while (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && !passwordsMatch);

            //If the user clicked OK and the passwords match then change the database password
            if (buttonClicked.equals(new Integer(JOptionPane.OK_OPTION)) && passwordsMatch) {
                this.dbPers.getEncryptionService().initCipher(masterPassword.getPassword());
                saveDatabase();
            }

        }
    }

}

From source file:net.rptools.maptool.client.functions.InputFunction.java

@Override
public Object childEvaluate(Parser parser, String functionName, List<Object> parameters)
        throws EvaluationException, ParserException {
    // Extract the list of specifier strings from the parameters
    // "name | value | prompt | inputType | options"
    List<String> varStrings = new ArrayList<String>();
    for (Object param : parameters) {
        String paramStr = (String) param;
        if (StringUtils.isEmpty(paramStr)) {
            continue;
        }/*from w w  w . j  ava  2s  . com*/
        // Multiple vars can be packed into a string, separated by "##"
        List<String> substrings = new ArrayList<String>();
        StrListFunctions.parse(paramStr, substrings, "##");
        for (String varString : substrings) {
            if (StringUtils.isEmpty(paramStr)) {
                continue;
            }
            varStrings.add(varString);
        }
    }

    // Create VarSpec objects from each variable's specifier string
    List<VarSpec> varSpecs = new ArrayList<VarSpec>();
    for (String specifier : varStrings) {
        VarSpec vs;
        try {
            vs = new VarSpec(specifier);
        } catch (VarSpec.SpecifierException se) {
            throw new ParameterException(se.msg);
        } catch (InputType.OptionException oe) {
            throw new ParameterException(I18N.getText("macro.function.input.invalidOptionType", oe.key,
                    oe.value, oe.type, specifier));
        }
        varSpecs.add(vs);
    }

    // Check if any variables were defined
    if (varSpecs.isEmpty())
        return BigDecimal.ONE; // No work to do, so treat it as a successful invocation.

    // UI step 1 - First, see if a token is in context.
    VariableResolver varRes = parser.getVariableResolver();
    Token tokenInContext = null;
    if (varRes instanceof MapToolVariableResolver) {
        tokenInContext = ((MapToolVariableResolver) varRes).getTokenInContext();
    }
    String dialogTitle = "Input Values";
    if (tokenInContext != null) {
        String name = tokenInContext.getName(), gm_name = tokenInContext.getGMName();
        boolean isGM = MapTool.getPlayer().isGM();
        String extra = "";

        if (isGM && gm_name != null && gm_name.compareTo("") != 0)
            extra = " for " + gm_name;
        else if (name != null && name.compareTo("") != 0)
            extra = " for " + name;

        dialogTitle = dialogTitle + extra;
    }

    // UI step 2 - build the panel with the input fields
    InputPanel ip = new InputPanel(varSpecs);

    // Calculate the height
    // TODO: remove this workaround
    int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    int maxHeight = screenHeight * 3 / 4;
    Dimension ipPreferredDim = ip.getPreferredSize();
    if (maxHeight < ipPreferredDim.height) {
        ip.modifyMaxHeightBy(maxHeight - ipPreferredDim.height);
    }

    // UI step 3 - show the dialog
    JOptionPane jop = new JOptionPane(ip, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog dlg = jop.createDialog(MapTool.getFrame(), dialogTitle);

    // Set up callbacks needed for desired runtime behavior
    dlg.addComponentListener(new FixupComponentAdapter(ip));

    dlg.setVisible(true);
    int dlgResult = JOptionPane.CLOSED_OPTION;
    try {
        dlgResult = (Integer) jop.getValue();
    } catch (NullPointerException npe) {
    }
    dlg.dispose();

    if (dlgResult == JOptionPane.CANCEL_OPTION || dlgResult == JOptionPane.CLOSED_OPTION)
        return BigDecimal.ZERO;

    // Finally, assign values from the dialog box to the variables
    for (ColumnPanel cp : ip.columnPanels) {
        List<VarSpec> panelVars = cp.varSpecs;
        List<JComponent> panelControls = cp.inputFields;
        int numPanelVars = panelVars.size();
        StringBuilder allAssignments = new StringBuilder(); // holds all values assigned in this tab

        for (int varCount = 0; varCount < numPanelVars; varCount++) {
            VarSpec vs = panelVars.get(varCount);
            JComponent comp = panelControls.get(varCount);
            String newValue = null;
            switch (vs.inputType) {
            case TEXT: {
                newValue = ((JTextField) comp).getText();
                break;
            }
            case LIST: {
                Integer index = ((JComboBox) comp).getSelectedIndex();
                if (vs.optionValues.optionEquals("VALUE", "STRING")) {
                    newValue = vs.valueList.get(index);
                } else { // default is "NUMBER"
                    newValue = index.toString();
                }
                break;
            }
            case CHECK: {
                Integer value = ((JCheckBox) comp).isSelected() ? 1 : 0;
                newValue = value.toString();
                break;
            }
            case RADIO: {
                // This code assumes that the Box container returns components
                // in the same order that they were added.
                Component[] comps = ((Box) comp).getComponents();
                int componentCount = 0;
                Integer index = 0;
                for (Component c : comps) {
                    if (c instanceof JRadioButton) {
                        JRadioButton radio = (JRadioButton) c;
                        if (radio.isSelected())
                            index = componentCount;
                    }
                    componentCount++;
                }
                if (vs.optionValues.optionEquals("VALUE", "STRING")) {
                    newValue = vs.valueList.get(index);
                } else { // default is "NUMBER"
                    newValue = index.toString();
                }
                break;
            }
            case LABEL: {
                newValue = null;
                // The variable name is ignored and not set.
                break;
            }
            case PROPS: {
                // Read out and assign all the subvariables.
                // The overall return value is a property string (as in StrPropFunctions.java) with all the new settings.
                Component[] comps = ((JPanel) comp).getComponents();
                StringBuilder sb = new StringBuilder();
                int setVars = 0; // "NONE", no assignments made
                if (vs.optionValues.optionEquals("SETVARS", "SUFFIXED"))
                    setVars = 1;
                if (vs.optionValues.optionEquals("SETVARS", "UNSUFFIXED"))
                    setVars = 2;
                if (vs.optionValues.optionEquals("SETVARS", "TRUE"))
                    setVars = 2; // for backward compatibility
                for (int compCount = 0; compCount < comps.length; compCount += 2) {
                    String key = ((JLabel) comps[compCount]).getText().split("\\:")[0]; // strip trailing colon
                    String value = ((JTextField) comps[compCount + 1]).getText();
                    sb.append(key);
                    sb.append("=");
                    sb.append(value);
                    sb.append(" ; ");
                    switch (setVars) {
                    case 0:
                        // Do nothing
                        break;
                    case 1:
                        parser.setVariable(key + "_", value);
                        break;
                    case 2:
                        parser.setVariable(key, value);
                        break;
                    }
                }
                newValue = sb.toString();
                break;
            }
            default:
                // should never happen
                newValue = null;
                break;
            }
            // Set the variable to the value we got from the dialog box.
            if (newValue != null) {
                parser.setVariable(vs.name, newValue.trim());
                allAssignments.append(vs.name + "=" + newValue.trim() + " ## ");
            }
        }
        if (cp.tabVarSpec != null) {
            parser.setVariable(cp.tabVarSpec.name, allAssignments.toString());
        }
    }

    return BigDecimal.ONE; // success

    // for debugging:
    //return debugOutput(varSpecs);
}

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  ww  . ja  v  a 2s .com*/
    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:org.nuclos.client.ui.collect.Chart.java

private void actionCommandShow() {
    final JOptionPane optpn = new JOptionPane(subform, JOptionPane.PLAIN_MESSAGE, JOptionPane.CLOSED_OPTION);

    // perform the dialog:
    final JDialog dlg = optpn.createDialog(panel, "Chart-Daten anzeigen");
    dlg.setModal(true);//  w  w  w.  j  av a 2s . com
    dlg.setResizable(true);
    dlg.pack();
    dlg.setLocationRelativeTo(panel);
    dlg.setVisible(true);
}

From source file:atlas.kingj.roi.FrmMain.java

private void OpenAll() {
    ResetStatusLabel();//  w w  w . ja v  a2 s.c om

    formReady = false;
    jobFormReady = false;

    fc = new OpenSaveFileChooser();
    fc.setFileFilter(new OBJfilter(3));
    fc.type = 1;

    JOptionPane pane = new JOptionPane(
            "Opening a previous configuration will erase all current settings.\nAre you sure you want to proceed?");
    Object[] options = new String[] { "Yes", "No" };
    pane.setOptions(options);
    JDialog dialog = pane.createDialog(new JFrame(), "Confirm");
    dialog.setVisible(true);
    Object obj = pane.getValue();
    if (obj != null && obj.equals(options[0])) {

        int returnVal = fc.showOpenDialog(frmTitanRoiCalculator);
        if (returnVal == JFileChooser.APPROVE_OPTION) {

            SaveFile save;

            File file = fc.getSelectedFile();

            try {
                FileInputStream fin = new FileInputStream(file);
                ObjectInputStream ois = new ObjectInputStream(fin);
                save = (SaveFile) ois.readObject();
                ois.close();

                // Don't want to change the save settings in any way
                boolean temp1 = environment.SaveOnClose;
                String temp2 = environment.SaveFileName;
                environment = save.getEnvironment();
                environment.SaveOnClose = temp1;
                environment.SaveFileName = temp2;

                listModel = (DefaultListModel) save.getMachineList();
                RoiData.setSize(listModel.getSize());
                listMachines.setModel(listModel);
                jobModel = (DefaultListModel) save.getJobList();
                listJobs.setModel(jobModel);
                listJobsAvail.setModel(jobModel);
                listCompare.setModel(listModel);
                listCompareRoi.setModel(listModel);
                listCompare.setSelectedIndices(save.getSelection());
                machNames = save.getMachNames();
                jobNames = save.getJobNames();
                RoiData = (ROIData) save.getRoiData().clone();
                if (metric != environment.getUnits()) {
                    ChangeUnits();
                    rdbtnmntmImperial.setSelected(true);
                }

                chckbxSimulateScheduleStart.setSelected(!environment.StartStopTimes);

                scheduleModel.clear();
                environment.Unlocked = false;
                if (environment.getSchedule() == null)
                    environment.setSchedule(new JobSchedule());
                else {
                    int size = environment.getSchedule().getSize();
                    for (int i = 0; i < size; ++i) {
                        scheduleModel.addElement(environment.getSchedule().getJob(i));
                    }
                    btnRemoveJob.setEnabled(true);
                    btnUpSchedule.setEnabled(true);
                    btnViewSchedule.setEnabled(true);
                    btnClearSchedule.setEnabled(true);
                    if (size > 0)
                        listSchedule.setSelectedIndex(0);
                }

                formReady = false;
                UpdateForm();

                if (listModel.size() > 0) {
                    listMachines.setSelectedIndex(0);
                    formReady = true;
                }
                if (jobModel.size() > 0) {
                    listJobs.setSelectedIndex(0);
                    jobFormReady = true;
                }

                UpdateJobForm();

                // Update environment
                initialising = true;
                chckbxSimulateScheduleStart.setSelected(!environment.StartStopTimes);
                txtShiftLength.setText(Double.toString(roundTwoDecimals(environment.HrsPerShift)));
                txtShiftCount.setText(
                        Double.toString(roundTwoDecimals(environment.HrsPerDay / environment.HrsPerShift)));
                txtDaysYear.setText(
                        Double.toString(roundTwoDecimals(environment.HrsPerYear / environment.HrsPerDay)));
                initialising = false;
                UpdateShifts();

                // Update ROI form
                txtsellingprice.setText(Double.toString(roundTwoDecimals(
                        (metric ? save.RoiData.sellingprice : Core.TonToTonne(save.RoiData.sellingprice)))));
                txtcontribution.setText(Double.toString(roundTwoDecimals(save.RoiData.contribution * 100)));
                lblvalueadded.setText(
                        "" + formatDecimal((metric ? save.RoiData.value : Core.TonToTonne(save.RoiData.value)))
                                + (metric ? " / tonne" : " / ton"));
                txtenergycost.setText(Double.toString(roundTwoDecimals(save.RoiData.energycost)));
                txtwastesavedflags.setText(Double.toString(roundTwoDecimals(
                        (metric ? save.RoiData.wastesavedflag : Core.MToFt(save.RoiData.wastesavedflag)))));
                txtwastesavedguide.setText(Double.toString(roundTwoDecimals(
                        (metric ? save.RoiData.wastesavedguide : Core.MToFt(save.RoiData.wastesavedguide)))));

                UpdateAnalysis();
                UpdateROI();

                ShowMessageSuccess("File loaded successfully.");

            } catch (ClassCastException e1) {
                ShowMessage("Save-all file required, not found.");
            } catch (ClassNotFoundException e1) {
                ShowMessage("File load error.");
            } catch (FileNotFoundException e1) {
                ShowMessage("File not found.");
            } catch (Exception e1) {
                ShowMessage("File load error.");
            } finally {
                if (!(listModel.getSize() == 0))
                    formReady = true;
                if (!(jobModel.getSize() == 0))
                    jobFormReady = true;
            }

        }

    }

}

From source file:org.broad.igv.track.TrackMenuUtils.java

public static JMenuItem getRemoveMenuItem(final Collection<Track> selectedTracks) {

    boolean multiple = selectedTracks.size() > 1;

    JMenuItem item = new JMenuItem("Remove Track" + (multiple ? "s" : ""));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (selectedTracks.isEmpty()) {
                return;
            }//from  ww  w.j  a v  a 2s.  c  om

            StringBuffer buffer = new StringBuffer();
            for (Track track : selectedTracks) {
                buffer.append("\n\t");
                buffer.append(track.getName());
            }
            String deleteItems = buffer.toString();

            JTextArea textArea = new JTextArea();
            textArea.setEditable(false);
            JScrollPane scrollPane = new JScrollPane(textArea);
            textArea.setText(deleteItems);

            JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.YES_NO_OPTION);
            optionPane.setPreferredSize(new Dimension(550, 500));
            JDialog dialog = optionPane.createDialog(IGV.getMainFrame(), "Remove The Following Tracks");
            dialog.setVisible(true);

            Object choice = optionPane.getValue();
            if ((choice == null) || (JOptionPane.YES_OPTION != ((Integer) choice).intValue())) {
                return;
            }

            IGV.getInstance().removeTracks(selectedTracks);
            IGV.getInstance().doRefresh();
        }
    });
    return item;
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

private void removalConfirmation(final FieldTypes whatIsBeingRemoved) {
    // delete reference to protocol in subform

    // add one to take into account the model and the initial column which contains fields names.
    final int selectedItem = scrollTable.getSelectedColumn() + 1;

    // check to ensure the value isn't 0, if it is, nothing is selected in the table since -1 (value returned by model if
    // no column is selected + 1 = 0!)
    if ((selectedItem != 0) && (dataEntryForm != null)) {
        String displayText;/*w  w w . jav  a  2 s.  co  m*/
        if ((whatIsBeingRemoved == FieldTypes.FACTOR) || (whatIsBeingRemoved == FieldTypes.PROTOCOL)) {
            displayText = "<html>" + "<b>Confirm deletion of " + fieldType + "</b>" + "<p>Deleting this "
                    + fieldType + " will result in all " + fieldType + "s of this type in subsequent assays</p>"
                    + "<p>being deleted too! Do you wish to continue?</p>" + "</html>";
        } else {
            displayText = "<html>" + "<b>Confirm deletion of " + fieldType + "</b>" + "<p>Deleting this "
                    + fieldType + " will result in its complete removal from this experiment annotation!</p>"
                    + "<p>Do you wish to continue?</p>" + "</html>";
        }

        JOptionPane optionPane = new JOptionPane(displayText, JOptionPane.INFORMATION_MESSAGE,
                JOptionPane.YES_NO_OPTION);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                    int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString());

                    if (lastOptionAnswer == JOptionPane.YES_OPTION) {
                        removeItem(selectedItem);
                        ApplicationManager.getCurrentApplicationInstance().hideSheet();
                    } else {
                        // just hide the sheet and cancel further actions!
                        ApplicationManager.getCurrentApplicationInstance().hideSheet();
                    }
                }
            }
        });
        optionPane.setIcon(confirmRemoveColumn);
        UIHelper.applyOptionPaneBackground(optionPane, UIHelper.BG_COLOR);
        ApplicationManager.getCurrentApplicationInstance()
                .showJDialogAsSheet(optionPane.createDialog(this, "Confirm Delete"));
    } else {
        removeColumn(selectedItem);
    }
}