Search in sources :

Example 1 with DefaultEditor

use of javax.swing.JSpinner.DefaultEditor in project jdk8u_jdk by JetBrains.

the class ColorPanel method buildPanel.

void buildPanel() {
    int count = this.model.getCount();
    this.spinners[4].setVisible(count > 4);
    for (int i = 0; i < count; i++) {
        String text = this.model.getLabel(this, i);
        Object object = this.spinners[i].getLabel();
        if (object instanceof JRadioButton) {
            JRadioButton button = (JRadioButton) object;
            button.setText(text);
            button.getAccessibleContext().setAccessibleDescription(text);
        } else if (object instanceof JLabel) {
            JLabel label = (JLabel) object;
            label.setText(text);
        }
        this.spinners[i].setRange(this.model.getMinimum(i), this.model.getMaximum(i));
        this.spinners[i].setValue(this.values[i]);
        this.spinners[i].getSlider().getAccessibleContext().setAccessibleName(text);
        this.spinners[i].getSpinner().getAccessibleContext().setAccessibleName(text);
        DefaultEditor editor = (DefaultEditor) this.spinners[i].getSpinner().getEditor();
        editor.getTextField().getAccessibleContext().setAccessibleName(text);
        this.spinners[i].getSlider().getAccessibleContext().setAccessibleDescription(text);
        this.spinners[i].getSpinner().getAccessibleContext().setAccessibleDescription(text);
        editor.getTextField().getAccessibleContext().setAccessibleDescription(text);
    }
}
Also used : JRadioButton(javax.swing.JRadioButton) JLabel(javax.swing.JLabel) DefaultEditor(javax.swing.JSpinner.DefaultEditor)

Example 2 with DefaultEditor

use of javax.swing.JSpinner.DefaultEditor in project knime-core by knime.

the class DialogComponentDoubleRange method validateSettingsBeforeSave.

/**
 * {@inheritDoc}
 */
@Override
protected void validateSettingsBeforeSave() throws InvalidSettingsException {
    final SettingsModelDoubleRange model = (SettingsModelDoubleRange) getModel();
    double newMin;
    double newMax;
    // try to commit Minimum
    try {
        m_spinnerMin.commitEdit();
        newMin = ((Double) m_spinnerMin.getValue()).doubleValue();
    } catch (final ParseException e) {
        final JComponent editor = m_spinnerMin.getEditor();
        if (editor instanceof DefaultEditor) {
            showError(((DefaultEditor) editor).getTextField());
        }
        String errMsg = "Invalid number format. ";
        errMsg += "Please enter a valid minimum.";
        throw new InvalidSettingsException(errMsg);
    }
    // try to commit Maximum
    try {
        m_spinnerMax.commitEdit();
        newMax = ((Double) m_spinnerMax.getValue()).doubleValue();
    } catch (final ParseException e) {
        final JComponent editor = m_spinnerMax.getEditor();
        if (editor instanceof DefaultEditor) {
            showError(((DefaultEditor) editor).getTextField());
        }
        String errMsg = "Invalid number format. ";
        errMsg += "Please enter a valid maximum.";
        throw new InvalidSettingsException(errMsg);
    }
    try {
        new SettingsModelDoubleRange(model.getConfigName(), newMin, newMax);
    } catch (final IllegalArgumentException iae) {
        JComponent editor = m_spinnerMax.getEditor();
        if (editor instanceof DefaultEditor) {
            showError(((DefaultEditor) editor).getTextField());
        }
        editor = m_spinnerMin.getEditor();
        if (editor instanceof DefaultEditor) {
            showError(((DefaultEditor) editor).getTextField());
        }
        throw new InvalidSettingsException(iae.getMessage());
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) JComponent(javax.swing.JComponent) ParseException(java.text.ParseException) DefaultEditor(javax.swing.JSpinner.DefaultEditor)

Example 3 with DefaultEditor

use of javax.swing.JSpinner.DefaultEditor in project knime-core by knime.

the class DialogComponentNumber method updateComponent.

/**
 * {@inheritDoc}
 */
@Override
protected void updateComponent() {
    final JComponent editor = m_spinner.getEditor();
    if (editor instanceof DefaultEditor) {
        clearError(((DefaultEditor) editor).getTextField());
    }
    // model
    try {
        m_spinner.commitEdit();
        if (getModel() instanceof SettingsModelDouble) {
            final SettingsModelDouble model = (SettingsModelDouble) getModel();
            final double val = ((Double) m_spinner.getValue()).doubleValue();
            if (val != model.getDoubleValue()) {
                m_spinner.setValue(new Double(model.getDoubleValue()));
            }
        } else if (getModel() instanceof SettingsModelInteger) {
            final SettingsModelInteger model = (SettingsModelInteger) getModel();
            final int val = ((Integer) m_spinner.getValue()).intValue();
            if (val != model.getIntValue()) {
                m_spinner.setValue(Integer.valueOf(model.getIntValue()));
            }
        } else {
            final SettingsModelLong model = (SettingsModelLong) getModel();
            final long val = ((Long) m_spinner.getValue()).longValue();
            if (val != model.getLongValue()) {
                m_spinner.setValue(Long.valueOf(model.getLongValue()));
            }
        }
    } catch (final ParseException e) {
        // spinner contains invalid value - update component!
        if (getModel() instanceof SettingsModelDouble) {
            final SettingsModelDouble model = (SettingsModelDouble) getModel();
            m_spinner.setValue(new Double(model.getDoubleValue()));
        } else if (getModel() instanceof SettingsModelInteger) {
            final SettingsModelInteger model = (SettingsModelInteger) getModel();
            m_spinner.setValue(Integer.valueOf(model.getIntValue()));
        } else {
            final SettingsModelLong model = (SettingsModelLong) getModel();
            m_spinner.setValue(Long.valueOf(model.getLongValue()));
        }
    }
    // also update the enable status of all components...
    setEnabledComponents(getModel().isEnabled());
}
Also used : JComponent(javax.swing.JComponent) ParseException(java.text.ParseException) DefaultEditor(javax.swing.JSpinner.DefaultEditor)

Example 4 with DefaultEditor

use of javax.swing.JSpinner.DefaultEditor in project knime-core by knime.

the class DialogComponentDoubleRange method updateComponent.

/**
 * {@inheritDoc}
 */
@Override
protected void updateComponent() {
    // clear any possible error indication
    JComponent editor = m_spinnerMin.getEditor();
    if (editor instanceof DefaultEditor) {
        clearError(((DefaultEditor) editor).getTextField());
    }
    editor = m_spinnerMax.getEditor();
    if (editor instanceof DefaultEditor) {
        clearError(((DefaultEditor) editor).getTextField());
    }
    // update the spinners
    final SettingsModelDoubleRange model = (SettingsModelDoubleRange) getModel();
    final double valMin = ((Double) m_spinnerMin.getValue()).doubleValue();
    if (valMin != model.getMinRange()) {
        m_spinnerMin.setValue(new Double(model.getMinRange()));
    }
    final double valMax = ((Double) m_spinnerMax.getValue()).doubleValue();
    if (valMax != model.getMaxRange()) {
        m_spinnerMax.setValue(new Double(model.getMaxRange()));
    }
    // update enable status
    setEnabledComponents(model.isEnabled());
}
Also used : JComponent(javax.swing.JComponent) DefaultEditor(javax.swing.JSpinner.DefaultEditor)

Example 5 with DefaultEditor

use of javax.swing.JSpinner.DefaultEditor in project knime-core by knime.

the class DialogComponentNumber method updateModel.

/**
 * Transfers the value from the spinner into the model. Colors the spinner
 * red, if the number is not accepted by the settings model. And throws an
 * exception then.
 *
 * @throws InvalidSettingsException if the number was not accepted by the
 *             model (reason could be an out of range, or just an invalid
 *             input).
 */
private void updateModel() throws InvalidSettingsException {
    try {
        m_spinner.commitEdit();
        if (getModel() instanceof SettingsModelDouble) {
            final SettingsModelDouble model = (SettingsModelDouble) getModel();
            model.setDoubleValue(((Double) m_spinner.getValue()).doubleValue());
        } else if (getModel() instanceof SettingsModelLong) {
            final SettingsModelLong model = (SettingsModelLong) getModel();
            model.setLongValue(((Long) m_spinner.getValue()).longValue());
        } else {
            final SettingsModelInteger model = (SettingsModelInteger) getModel();
            model.setIntValue(((Integer) m_spinner.getValue()).intValue());
        }
    } catch (final ParseException e) {
        final JComponent editor = m_spinner.getEditor();
        if (editor instanceof DefaultEditor) {
            showError(((DefaultEditor) editor).getTextField());
        }
        String errMsg = "Invalid number format. ";
        if (getModel() instanceof SettingsModelDouble) {
            errMsg += "Please enter a valid floating point number.";
        }
        if (getModel() instanceof SettingsModelInteger) {
            errMsg += "Please enter a valid integer number.";
        }
        if (getModel() instanceof SettingsModelLong) {
            errMsg += "Please enter a valid long number.";
        }
        throw new InvalidSettingsException(errMsg);
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) JComponent(javax.swing.JComponent) ParseException(java.text.ParseException) DefaultEditor(javax.swing.JSpinner.DefaultEditor)

Aggregations

DefaultEditor (javax.swing.JSpinner.DefaultEditor)5 JComponent (javax.swing.JComponent)4 ParseException (java.text.ParseException)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 JLabel (javax.swing.JLabel)1 JRadioButton (javax.swing.JRadioButton)1