Search in sources :

Example 46 with DefaultComboBoxModel

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

the class MissingValuePanel method getFixTextField.

/*
     * Helper in constructor, generates the text field to enter the replacement
     * value.
     */
private static JComponent getFixTextField(final ColSetting setting, final DataColumnSpec spec) {
    JComponent fixText;
    // FIX text field
    DataCell fixCell = setting.getFixCell();
    switch(setting.getType()) {
        case ColSetting.TYPE_DOUBLE:
            fixText = new JFormattedTextField();
            ((JFormattedTextField) fixText).setColumns(8);
            Double doubel;
            if (fixCell == null) {
                doubel = new Double(0.0);
            } else {
                double d = ((DoubleValue) fixCell).getDoubleValue();
                doubel = new Double(d);
            }
            ((JFormattedTextField) fixText).setValue(doubel);
            break;
        case ColSetting.TYPE_INT:
            fixText = new JFormattedTextField();
            ((JFormattedTextField) fixText).setColumns(8);
            Integer integer;
            if (fixCell == null) {
                integer = new Integer(0);
            } else {
                int i = ((IntValue) fixCell).getIntValue();
                integer = new Integer(i);
            }
            ((JFormattedTextField) fixText).setValue(integer);
            break;
        case ColSetting.TYPE_STRING:
            DataCell[] vals;
            if (spec != null && spec.getDomain().hasValues()) {
                vals = spec.getDomain().getValues().toArray(new DataCell[0]);
            } else {
                vals = new DataCell[0];
            }
            DefaultComboBoxModel model = new DefaultComboBoxModel(vals);
            fixText = new JComboBox(model);
            ((JComboBox) fixText).setPrototypeDisplayValue("#########");
            ((JComboBox) fixText).setEditable(true);
            ((JComboBox) fixText).setRenderer(new DefaultListCellRenderer() {

                /**
                 * Overridden to set tooltip text properly.
                 * @see DefaultListCellRenderer#getListCellRendererComponent(
                 * JList, Object, int, boolean, boolean)
                 */
                @Override
                public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
                    Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if (c instanceof JComponent) {
                        ((JComponent) c).setToolTipText(value.toString());
                    }
                    return c;
                }
            });
            String string;
            if (fixCell == null) {
                string = "";
            } else {
                string = ((StringValue) fixCell).getStringValue();
            }
            model.setSelectedItem(string);
            break;
        default:
            throw new InternalError("No such type");
    }
    return fixText;
}
Also used : JComboBox(javax.swing.JComboBox) JComponent(javax.swing.JComponent) JFormattedTextField(javax.swing.JFormattedTextField) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DoubleValue(org.knime.core.data.DoubleValue) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) DataCell(org.knime.core.data.DataCell) JComponent(javax.swing.JComponent) Component(java.awt.Component) IntValue(org.knime.core.data.IntValue) JList(javax.swing.JList)

Example 47 with DefaultComboBoxModel

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

the class ScatterProps method setSelectables.

/**
 * @param tSpec the data table spec
 * @param filterClass allowed classes
 */
public void setSelectables(final DataTableSpec tSpec, final Class<? extends DataValue>... filterClass) {
    List<Class<? extends DataValue>> filters = Arrays.asList(filterClass);
    // do nothing if the table spec has been already before
    if (m_tableSpec == tSpec) {
        return;
    }
    // else set the given table spec as the current
    m_tableSpec = tSpec;
    m_xCol.setEnabled(true);
    m_yCol.setEnabled(true);
    m_xAvailCol.clear();
    if (tSpec != null) {
        // put all column names of type double in the drop box
        List<DataColumnSpec> compatibleSpecs = new ArrayList<DataColumnSpec>();
        for (int i = 0; i < tSpec.getNumColumns(); i++) {
            // if we can get a number from that column: add it to the vector
            // check which columns are displayable
            DataType type = tSpec.getColumnSpec(i).getType();
            for (Class<? extends DataValue> cl : filters) {
                if (type.isCompatible(cl)) {
                    compatibleSpecs.add(tSpec.getColumnSpec(i));
                }
            }
        }
        for (DataColumnSpec compSpec : compatibleSpecs) {
            // check which columns are displayable
            if (Coordinate.createCoordinate(compSpec) != null) {
                m_xAvailCol.add(compSpec);
            }
        }
    }
    // store the old selection - in case it's still good
    DataColumnSpec xColSel = (DataColumnSpec) m_xCol.getSelectedItem();
    DataColumnSpec yColSel = (DataColumnSpec) m_yCol.getSelectedItem();
    // now set the (possibly empty) list
    m_xCol.setModel(new DefaultComboBoxModel(m_xAvailCol));
    m_yCol.setModel(new DefaultComboBoxModel(m_xAvailCol));
    // check if we can reuse the old selection
    if (xColSel != null && yColSel != null) {
        m_xCol.setSelectedItem(xColSel);
        m_yCol.setSelectedItem(yColSel);
    } else {
        // set default values if we dont have any selected values
        if ((xColSel == null) && (m_xAvailCol.size() > 0)) {
            m_xCol.setSelectedItem(m_xAvailCol.get(0));
        }
        if (yColSel == null) {
            if (m_xAvailCol.size() > 1) {
                m_yCol.setSelectedItem(m_xAvailCol.get(1));
            } else if (m_xAvailCol.size() > 0) {
                m_yCol.setSelectedItem(m_xAvailCol.get(0));
            }
        }
    }
    selectedXColChanged((DataColumnSpec) m_xCol.getSelectedItem());
    selectedYColChanged((DataColumnSpec) m_yCol.getSelectedItem());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataValue(org.knime.core.data.DataValue) ArrayList(java.util.ArrayList) DataType(org.knime.core.data.DataType) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 48 with DefaultComboBoxModel

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

the class ScatterProps method fixXColTo.

/**
 * Attempts to set the argument as selected x column and disables the combo
 * box if there is only one available.
 *
 * @param xColName Name of the fixed x columns.
 */
public void fixXColTo(final String... xColName) {
    DataColumnSpec oldSelected = (DataColumnSpec) m_xCol.getSelectedItem();
    HashSet<String> hash = new HashSet<String>(Arrays.asList(xColName));
    Vector<DataColumnSpec> survivers = new Vector<DataColumnSpec>();
    for (DataColumnSpec s : m_xAvailCol) {
        if (hash.contains(s.getName())) {
            survivers.add(s);
        }
    }
    m_xCol.setModel(new DefaultComboBoxModel(survivers));
    if (survivers.contains(oldSelected)) {
        m_xCol.setSelectedItem(oldSelected);
    } else {
        // may be -1 ... but that is ok
        m_xCol.setSelectedIndex(survivers.size() - 1);
    }
    m_xCol.setEnabled(survivers.size() > 1);
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Vector(java.util.Vector) HashSet(java.util.HashSet)

Example 49 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project vcell by virtualcell.

the class MIRIAMAnnotationEditor method getJComboBoxURI.

/**
 * This method initializes jComboBoxURI
 *
 * @return javax.swing.JComboBox
 */
private JComboBox getJComboBoxURI() {
    if (jComboBoxURI == null) {
        jComboBoxURI = new JComboBox();
        DefaultComboBoxModel defaultComboBoxModel = new DefaultComboBoxModel();
        for (DataType dataType : vcMetaData.getMiriamManager().getAllDataTypes().values()) {
            defaultComboBoxModel.addElement(dataType);
        }
        jComboBoxURI.setModel(defaultComboBoxModel);
        jComboBoxURI.setRenderer(new DefaultListCellRenderer() {

            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                return super.getListCellRendererComponent(list, ((DataType) value).getDataTypeName(), index, isSelected, cellHasFocus);
            }
        });
    }
    return jComboBoxURI;
}
Also used : JComboBox(javax.swing.JComboBox) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) DataType(cbit.vcell.biomodel.meta.MiriamManager.DataType) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Component(java.awt.Component) JList(javax.swing.JList)

Example 50 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project vcell by virtualcell.

the class MIRIAMAnnotationEditor method getQualifierComboBoxModel.

private DefaultComboBoxModel getQualifierComboBoxModel() {
    if (qualifierComboBoxModel == null) {
        qualifierComboBoxModel = new DefaultComboBoxModel();
        Set<MIRIAMQualifier> allQualifiers = AnnotationQualifiers.MIRIAM_all;
        for (MIRIAMQualifier qualifier : allQualifiers) {
            qualifierComboBoxModel.addElement(qualifier);
        }
    }
    return qualifierComboBoxModel;
}
Also used : DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) MIRIAMQualifier(org.vcell.sybil.models.miriam.MIRIAMQualifier)

Aggregations

DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)119 JComboBox (javax.swing.JComboBox)22 JPanel (javax.swing.JPanel)21 JLabel (javax.swing.JLabel)17 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 JButton (javax.swing.JButton)15 Insets (java.awt.Insets)14 GridBagConstraints (java.awt.GridBagConstraints)13 GridBagLayout (java.awt.GridBagLayout)12 Dimension (java.awt.Dimension)11 JTextField (javax.swing.JTextField)11 JCheckBox (javax.swing.JCheckBox)10 JScrollPane (javax.swing.JScrollPane)10 ArrayList (java.util.ArrayList)9 Vector (java.util.Vector)9 JList (javax.swing.JList)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 BorderLayout (java.awt.BorderLayout)8 ItemEvent (java.awt.event.ItemEvent)8