Example usage for javax.swing JOptionPane UNINITIALIZED_VALUE

List of usage examples for javax.swing JOptionPane UNINITIALIZED_VALUE

Introduction

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

Prototype

Object UNINITIALIZED_VALUE

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

Click Source Link

Document

Indicates that the user has not yet selected a value.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JOptionPane pane = new JOptionPane("your message", JOptionPane.ERROR_MESSAGE, JOptionPane.OK_OPTION);
    JDialog d = pane.createDialog(null, "title");
    d.pack();/*w ww. j av a2  s  . co m*/
    d.setModal(false);
    d.setVisible(true);
    while (pane.getValue() == JOptionPane.UNINITIALIZED_VALUE) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
        }
    }
    System.exit(0);
}

From source file:DualModal.java

public static void main(String args[]) {
    final JFrame frame1 = new JFrame("Left");
    final JFrame frame2 = new JFrame("Right");
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("Left");
    JButton button2 = new JButton("Right");
    frame1.add(button1);/*from w w w.j av a  2s.  c  o  m*/
    frame2.add(button2);
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton source = (JButton) e.getSource();

            JOptionPane pane = new JOptionPane("New label", JOptionPane.QUESTION_MESSAGE);
            pane.setWantsInput(true);
            JDialog dialog = pane.createDialog(frame2, "Enter Text");
            // dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
            dialog.setVisible(true);
            String text = (String) pane.getInputValue();

            if (!JOptionPane.UNINITIALIZED_VALUE.equals(text) && text.trim().length() > 0) {
                source.setText(text);
            }
        }
    };
    button1.addActionListener(listener);
    button2.addActionListener(listener);
    frame1.setBounds(100, 100, 200, 200);
    frame1.setVisible(true);
    frame2.setBounds(400, 100, 200, 200);
    frame2.setVisible(true);
}

From source file:components.CustomDialog.java

/** This method reacts to state changes in the option pane. */
public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible() && (e.getSource() == optionPane)
            && (JOptionPane.VALUE_PROPERTY.equals(prop) || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
        Object value = optionPane.getValue();

        if (value == JOptionPane.UNINITIALIZED_VALUE) {
            //ignore reset
            return;
        }//from w  w w .  jav a  2s  .c  o  m

        //Reset the JOptionPane's value.
        //If you don't do this, then if the user
        //presses the same button next time, no
        //property change event will be fired.
        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

        if (btnString1.equals(value)) {
            typedText = textField.getText();
            String ucText = typedText.toUpperCase();
            if (magicWord.equals(ucText)) {
                //we're done; clear and dismiss the dialog
                clearAndHide();
            } else {
                //text was invalid
                textField.selectAll();
                JOptionPane
                        .showMessageDialog(
                                CustomDialog.this, "Sorry, \"" + typedText + "\" " + "isn't a valid response.\n"
                                        + "Please enter " + magicWord + ".",
                                "Try again", JOptionPane.ERROR_MESSAGE);
                typedText = null;
                textField.requestFocusInWindow();
            }
        } else { //user closed dialog or clicked cancel
            dd.setLabel("It's OK.  " + "We won't force you to type " + magicWord + ".");
            typedText = null;
            clearAndHide();
        }
    }
}

From source file:com.hexidec.ekit.component.PropertiesDialog.java

public PropertiesDialog(Window parent, String[] fields, String[] types, String[] values, String title,
        boolean bModal) {
    super(parent, title);
    setModal(bModal);/*www  .  j  a va2 s .c  o  m*/
    htInputFields = new Hashtable<String, JComponent>();
    final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"),
            Translatrix.getTranslationString("DialogCancel") };
    List<Object> panelContents = new ArrayList<Object>();
    for (int iter = 0; iter < fields.length; iter++) {
        String fieldName = fields[iter];
        String fieldType = types[iter];
        JComponent fieldComponent;
        JComponent panelComponent = null;
        if (fieldType.equals("text") || fieldType.equals("integer")) {
            fieldComponent = new JTextField(3);
            if (values[iter] != null && values[iter].length() > 0) {
                ((JTextField) (fieldComponent)).setText(values[iter]);
            }

            if (fieldType.equals("integer")) {
                ((AbstractDocument) ((JTextField) (fieldComponent)).getDocument())
                        .setDocumentFilter(new DocumentFilter() {

                            @Override
                            public void insertString(FilterBypass fb, int offset, String text,
                                    AttributeSet attrs) throws BadLocationException {
                                replace(fb, offset, 0, text, attrs);
                            }

                            @Override
                            public void replace(FilterBypass fb, int offset, int length, String text,
                                    AttributeSet attrs) throws BadLocationException {

                                if (StringUtils.isNumeric(text)) {
                                    super.replace(fb, offset, length, text, attrs);
                                }

                            }

                        });
            }
        } else if (fieldType.equals("bool")) {
            fieldComponent = new JCheckBox(fieldName);
            if (values[iter] != null) {
                ((JCheckBox) (fieldComponent)).setSelected(values[iter] == "true");
            }
            panelComponent = fieldComponent;
        } else if (fieldType.equals("combo")) {
            fieldComponent = new JComboBox();
            if (values[iter] != null) {
                StringTokenizer stParse = new StringTokenizer(values[iter], ",", false);
                while (stParse.hasMoreTokens()) {
                    ((JComboBox) (fieldComponent)).addItem(stParse.nextToken());
                }
            }
        } else {
            fieldComponent = new JTextField(3);
        }
        htInputFields.put(fieldName, fieldComponent);
        if (panelComponent == null) {
            panelContents.add(fieldName);
            panelContents.add(fieldComponent);
        } else {
            panelContents.add(panelComponent);
        }
    }
    jOptionPane = new JOptionPane(panelContents.toArray(), JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]);

    setContentPane(jOptionPane);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    jOptionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (isVisible() && (e.getSource() == jOptionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY)
                    || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                Object value = jOptionPane.getValue();
                if (value == JOptionPane.UNINITIALIZED_VALUE) {
                    return;
                }
                if (value.equals(buttonLabels[0])) {
                    setVisible(false);
                } else {
                    setVisible(false);
                }
            }
        }
    });
    this.pack();
    setLocation(SwingUtilities.getPointForCentering(this, parent));
}

From source file:gda.gui.mca.McaGUI.java

private void makeTcaControlDialog() {
    if (tcaControlPanel == null) {
        tcaControlPanel = new TcaPanel();
        tcaDialog = new JDialog();
        Object[] options = { "OK" };
        Object[] array = { tcaControlPanel };

        // Create the JOptionPane.
        final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION,
                null, options, options[0]);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override//ww  w.  j av  a2  s  . c  o m
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop)
                        || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if ("OK".equals(value)) {

                        tcaDialog.setVisible(false);
                    }
                }

            }

        });
        tcaDialog.setContentPane(optionPane);
        tcaDialog.pack();
        tcaDialog.setTitle("TCA Controls");
        tcaDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    }

}

From source file:gda.gui.mca.McaGUI.java

private void makeAdcControlDialog() {
    if (adcControlPanel == null) {
        adcControlPanel = new AdcPanel();
        adcDialog = new JDialog();
        Object[] options = { "OK" };
        Object[] array = { adcControlPanel };

        // Create the JOptionPane.
        final JOptionPane optionPane = new JOptionPane(array, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_OPTION,
                null, options, options[0]);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override//  w w  w.  j  av a 2s  .  c om
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();

                if (isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop)
                        || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if ("OK".equals(value)) {

                        adcDialog.setVisible(false);
                    }
                }

            }

        });
        adcDialog.setContentPane(optionPane);
        adcDialog.pack();
        adcDialog.setTitle("ADC Controls");
        adcDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    }

}

From source file:DialogDemo.java

/** This method reacts to state changes in the option pane. */
public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible() && (e.getSource() == optionPane)
            && (JOptionPane.VALUE_PROPERTY.equals(prop) || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
        Object value = optionPane.getValue();

        if (value == JOptionPane.UNINITIALIZED_VALUE) {
            // ignore reset
            return;
        }//  ww w .  j a  v  a  2s . c  o  m

        // Reset the JOptionPane's value.
        // If you don't do this, then if the user
        // presses the same button next time, no
        // property change event will be fired.
        optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

        if (btnString1.equals(value)) {
            typedText = textField.getText();
            String ucText = typedText.toUpperCase();
            if (magicWord.equals(ucText)) {
                // we're done; clear and dismiss the dialog
                clearAndHide();
            } else {
                // text was invalid
                textField.selectAll();
                JOptionPane
                        .showMessageDialog(
                                CustomDialog.this, "Sorry, \"" + typedText + "\" " + "isn't a valid response.\n"
                                        + "Please enter " + magicWord + ".",
                                "Try again", JOptionPane.ERROR_MESSAGE);
                typedText = null;
                textField.requestFocusInWindow();
            }
        } else { // user closed dialog or clicked cancel
            dd.setLabel("It's OK.  " + "We won't force you to type " + magicWord + ".");
            typedText = null;
            clearAndHide();
        }
    }
}

From source file:org.docx4all.swing.ExternalHyperlinkDialog.java

/** This method reacts to state changes in the option pane. */
public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible() && (e.getSource() == this.optionPane)
            && (JOptionPane.VALUE_PROPERTY.equals(prop) || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
        Object userAnswer = this.optionPane.getValue();

        if (userAnswer == JOptionPane.UNINITIALIZED_VALUE) {
            //ignore reset
            return;
        }/* w w  w.j a  v  a2  s  .  co m*/

        //Reset the JOptionPane's value.
        //If you don't do this, then if the user
        //presses the same button next time, no
        //property change event will be fired.
        this.optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

        setVisible(false);

        if (OK_BUTTON_TEXT.equals(userAnswer)) {
            this.value = OK_BUTTON_TEXT;

            StringBuilder target = new StringBuilder();
            if (isSourceFileDirectory(this.directoryUrlPath)) {
                target.append(this.documentNameField.getText());
            } else {
                target.append(VFSUtils.getFriendlyName(this.directoryUrlPath, false));
                target.append("/");
                target.append(this.documentNameField.getText());
            }
            if (!target.toString().endsWith(".docx")) {
                target.append(".docx");
            }

            if (this.hyperlinkML.canSetTarget()) {
                this.hyperlinkML.setTarget(target.toString());
            } else {
                this.hyperlinkML.setDummyTarget(target.toString());
            }

            if (this.displayTextField.getText().length() == 0) {
                this.hyperlinkML.setDisplayText(target.toString());
            } else {
                this.hyperlinkML.setDisplayText(this.displayTextField.getText());
            }
            this.hyperlinkML.setTooltip(this.tooltipField.getText());

        } else {
            //User closed dialog or clicked cancel
            this.value = CANCEL_BUTTON_TEXT;
        }

        //do not keep a reference to the edited hyperlinkML
        //so that this dialog can be disposed of.
        this.hyperlinkML = null;
    }
}