Example usage for javax.swing JOptionPane INPUT_VALUE_PROPERTY

List of usage examples for javax.swing JOptionPane INPUT_VALUE_PROPERTY

Introduction

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

Prototype

String INPUT_VALUE_PROPERTY

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

Click Source Link

Document

Bound property name for inputValue.

Usage

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;
        }/*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: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);/*from   w ww. ja  v a  2s  . c  om*/
    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/*from   w  ww .j a v  a2 s .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)) {

                        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. ja  v  a2s . co 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)) {

                        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;
        }/*from  w w w.  j  a  va 2  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.
        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;
        }/*from ww w  . java2s .  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;
    }
}