Search in sources :

Example 91 with JComponent

use of javax.swing.JComponent in project knime-core by knime.

the class DatabasePortObjectSpec method getViews.

/**
 * {@inheritDoc}
 */
@Override
public JComponent[] getViews() {
    JComponent[] views = super.getViews();
    views = Arrays.copyOf(views, views.length + 1);
    views[views.length - 1] = new DataTableSpecView(m_spec);
    return views;
}
Also used : DataTableSpecView(org.knime.core.node.workflow.DataTableSpecView) JComponent(javax.swing.JComponent)

Example 92 with JComponent

use of javax.swing.JComponent 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 93 with JComponent

use of javax.swing.JComponent 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 94 with JComponent

use of javax.swing.JComponent in project knime-core by knime.

the class FilterDefinitionHandlerPortObject method getViews.

/**
 * {@inheritDoc}
 */
@Override
public JComponent[] getViews() {
    ModelContent model = new ModelContent("FilterDefinition");
    Config columnConfig = model.addConfig("Column");
    getSpec().forEach(col -> col.getFilterHandler().ifPresent(handler -> handler.save(columnConfig.addConfig(col.getName()))));
    return new JComponent[] { new ModelContentOutPortView(model) };
}
Also used : JComponent(javax.swing.JComponent) PortTypeRegistry(org.knime.core.node.port.PortTypeRegistry) ModelContent(org.knime.core.node.ModelContent) ModelContentOutPortView(org.knime.core.node.workflow.ModelContentOutPortView) DataTableSpec(org.knime.core.data.DataTableSpec) Config(org.knime.core.node.config.Config) PortType(org.knime.core.node.port.PortType) ModelContent(org.knime.core.node.ModelContent) Config(org.knime.core.node.config.Config) JComponent(javax.swing.JComponent) ModelContentOutPortView(org.knime.core.node.workflow.ModelContentOutPortView)

Example 95 with JComponent

use of javax.swing.JComponent in project knime-core by knime.

the class SizeHandlerPortObject method getViews.

/**
 * {@inheritDoc}
 */
@Override
public JComponent[] getViews() {
    ModelContent model = new ModelContent("Size");
    getSpec().getColumnSpec(0).getSizeHandler().save(model);
    return new JComponent[] { new ModelContentOutPortView(model) };
}
Also used : ModelContent(org.knime.core.node.ModelContent) JComponent(javax.swing.JComponent) ModelContentOutPortView(org.knime.core.node.workflow.ModelContentOutPortView)

Aggregations

JComponent (javax.swing.JComponent)225 Component (java.awt.Component)44 JPanel (javax.swing.JPanel)37 JLabel (javax.swing.JLabel)34 JButton (javax.swing.JButton)28 BorderLayout (java.awt.BorderLayout)27 Dimension (java.awt.Dimension)23 Insets (java.awt.Insets)20 ActionEvent (java.awt.event.ActionEvent)16 ArrayList (java.util.ArrayList)16 ActionListener (java.awt.event.ActionListener)15 Color (java.awt.Color)13 GridBagConstraints (java.awt.GridBagConstraints)13 Point (java.awt.Point)13 GridBagLayout (java.awt.GridBagLayout)12 JScrollPane (javax.swing.JScrollPane)12 JTextField (javax.swing.JTextField)12 JFrame (javax.swing.JFrame)11 Container (java.awt.Container)8 FlowLayout (java.awt.FlowLayout)8