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();
}
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);
}
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);
}
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;
}
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);
}
Aggregations