Search in sources :

Example 96 with DefaultComboBoxModel

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

the class KymographPanel method updateTheVariable.

private void updateTheVariable(DataIdentifier override) {
    try {
        // (DataIdentifier)ivjVarNamesJComboBox.getSelectedItem();
        DataIdentifier selected = (override != null ? override : (DataIdentifier) ivjVarNamesJComboBox.getSelectedItem());
        ivjVarNamesJComboBox.removeActionListener(ivjEventHandler);
        DataIdentifier[] newData = multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers();
        // setListData(newData);
        ((DefaultComboBoxModel<DataIdentifier>) ivjVarNamesJComboBox.getModel()).removeAllElements();
        for (int i = 0; i < newData.length; i++) {
            ((DefaultComboBoxModel<DataIdentifier>) ivjVarNamesJComboBox.getModel()).addElement(newData[i]);
        }
        initVariableListSelected(ivjVarNamesJComboBox, selected);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        ivjVarNamesJComboBox.addActionListener(ivjEventHandler);
    }
    initDataManagerVariable();
}
Also used : DataIdentifier(cbit.vcell.simdata.DataIdentifier) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Point(java.awt.Point) DataAccessException(org.vcell.util.DataAccessException)

Example 97 with DefaultComboBoxModel

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

the class ChomboSimpleDataViewer method retrieveVariablesAndTimes.

private void retrieveVariablesAndTimes() {
    AsynchClientTask task0 = new AsynchClientTask("clear", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            DefaultComboBoxModel dcm = new DefaultComboBoxModel();
            timeComboBox.setModel(dcm);
            DefaultListModel dlm = new DefaultListModel();
            varList.setModel(dlm);
            solTableModel.clear();
            meshMetricsTableModel.clear();
            meanTextField.setText(null);
            maxErrorTextField.setText(null);
            sumVolFracTextField.setText(null);
            l2ErrorTextField.setText(null);
        }
    };
    AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            String simId = simIdField.getText().trim();
            if (simId == null || simId.length() == 0) {
                throw new RuntimeException("Please provide a simulation id.");
            }
            String username = userNameTextField.getText().trim();
            if (username == null || username.length() == 0) {
                throw new RuntimeException("Please provide a user name.");
            }
            VCSimulationDataIdentifier vcDataId = new VCSimulationDataIdentifier(new VCSimulationIdentifier(new KeyValue(simId), new User(username, null)), 0);
            SimDataInfoHolder simDataInfoHolder = null;
            String datadir = dataDirTextField.getText();
            if (datadir == null || datadir.length() == 0) {
                simDataInfoHolder = createSimulationDataFromRemote(username, vcDataId);
                datadir = simDataInfoHolder.userDir.getParent();
                dataDirTextField.setText(datadir);
            } else {
                simDataInfoHolder = createSimulationDataFromDir(new File(datadir), username, vcDataId);
            }
            simData = simDataInfoHolder.simData;
            simData.readVarAndFunctionDataIdentifiers();
            usernames.add(username);
            userNameTextField.setAutoCompletionWords(usernames);
            datadirs.add(datadir);
            dataDirTextField.setAutoCompletionWords(datadirs);
            simIds.add(simId);
            simIdField.setAutoCompletionWords(simIds);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            double[] times = simData.getDataTimes();
            DefaultComboBoxModel dcm = new DefaultComboBoxModel();
            for (double t : times) {
                dcm.addElement(t);
            }
            timeComboBox.setModel(dcm);
            meshMetricsTableModel.setData(simData.getChomboMesh().getMetricsColumnNames(), simData.getChomboMesh().getMetricsNumbers());
            List<DataSetIdentifier> dsiList = simData.getDataSetIdentifiers();
            DefaultListModel dlm = new DefaultListModel();
            for (DataSetIdentifier dsi : dsiList) {
                dlm.addElement(dsi);
            }
            varList.setModel(dlm);
            if (times.length > 0) {
                timeComboBox.setSelectedIndex(0);
            }
            if (dsiList.size() > 0) {
                varList.setSelectedIndex(0);
            }
            meshMetricsTableModel.refreshTable();
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task0, task1, task2 }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Hashtable(java.util.Hashtable) DataSetIdentifier(cbit.vcell.simdata.DataSetIdentifier) DefaultListModel(javax.swing.DefaultListModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) File(java.io.File)

Example 98 with DefaultComboBoxModel

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

the class CSVFilesHistoryPanel method updateHistory.

/**
 * Updates the elements in the combo box, reads the file history.
 */
public void updateHistory() {
    StringHistory history = StringHistory.getInstance(CSVWriterNodeModel.FILE_HISTORY_ID);
    String[] allVals = history.getHistory();
    LinkedHashSet<String> list = new LinkedHashSet<String>();
    for (String s : allVals) {
        list.add(s);
    }
    DefaultComboBoxModel<String> comboModel = (DefaultComboBoxModel<String>) m_textBox.getModel();
    comboModel.removeAllElements();
    for (String s : list) {
        comboModel.addElement(s);
    }
    // changing the model will also change the minimum size to be
    // quite big. We have a tooltip, we don't need that
    Dimension newMin = new Dimension(0, getPreferredSize().height);
    setMinimumSize(newMin);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StringHistory(org.knime.core.node.util.StringHistory) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Dimension(java.awt.Dimension)

Example 99 with DefaultComboBoxModel

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

the class MissingValueHandling2Panel method getFixTextField.

/*
     * Helper in constructor, generates the text field to enter the replacement
     * value.
     */
private static JComponent getFixTextField(final MissingValueHandling2ColSetting setting, final DataColumnSpec... specs) {
    JComponent fixText;
    // FIX text field
    DataCell fixCell = setting.getFixCell();
    switch(setting.getType()) {
        case MissingValueHandling2ColSetting.TYPE_DOUBLE:
            fixText = new JFormattedTextField();
            ((JFormattedTextField) fixText).setColumns(11);
            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 MissingValueHandling2ColSetting.TYPE_INT:
            fixText = new JFormattedTextField();
            ((JFormattedTextField) fixText).setColumns(11);
            Integer integer;
            if (fixCell == null) {
                integer = 0;
            } else {
                integer = ((IntValue) fixCell).getIntValue();
            }
            ((JFormattedTextField) fixText).setValue(integer);
            break;
        case MissingValueHandling2ColSetting.TYPE_STRING:
            final ArrayList<DataCell> vals = new ArrayList<DataCell>();
            if (specs != null) {
                for (DataColumnSpec spec : specs) {
                    if (spec != null && spec.getDomain().hasValues()) {
                        vals.addAll(spec.getDomain().getValues());
                    }
                }
            }
            DefaultComboBoxModel model = new DefaultComboBoxModel(vals.toArray(new DataCell[0]));
            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) ArrayList(java.util.ArrayList) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleValue(org.knime.core.data.DoubleValue) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) DataCell(org.knime.core.data.DataCell) JComponent(javax.swing.JComponent) Component(java.awt.Component) JList(javax.swing.JList)

Example 100 with DefaultComboBoxModel

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

the class ColumnSelectionPanel method fixSelectablesTo.

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

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