use of javax.swing.JFormattedTextField in project knime-core by knime.
the class MissingValueHandling2Panel method getSettings.
/**
* Get the settings currently entered in the dialog.
*
* @return the current settings
*/
public MissingValueHandling2ColSetting getSettings() {
int method;
if (m_nothingButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
} else if (m_removeButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_IGNORE_ROWS;
} else if (m_fixButton != null && m_fixButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_FIX_VAL;
DataCell cell;
switch(m_setting.getType()) {
case MissingValueHandling2ColSetting.TYPE_INT:
Object value = ((JFormattedTextField) m_fixText).getValue();
cell = new IntCell(((Number) value).intValue());
break;
case MissingValueHandling2ColSetting.TYPE_DOUBLE:
value = ((JFormattedTextField) m_fixText).getValue();
cell = new DoubleCell(((Number) value).doubleValue());
break;
case MissingValueHandling2ColSetting.TYPE_STRING:
value = ((JComboBox) m_fixText).getEditor().getItem();
cell = new StringCell(value.toString());
break;
default:
throw new RuntimeException("You shouldn't have come here.");
}
m_setting.setFixCell(cell);
} else if (m_maxButton != null && m_maxButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MAX;
} else if (m_minButton != null && m_minButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MIN;
} else if (m_meanButton != null && m_meanButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MEAN;
} else if (m_mostFrequentButton != null && m_mostFrequentButton.isSelected()) {
method = MissingValueHandling2ColSetting.METHOD_MOST_FREQUENT;
} else {
assert false : "One button must be selected.";
method = MissingValueHandling2ColSetting.METHOD_NO_HANDLING;
}
m_setting.setMethod(method);
return m_setting;
}
use of javax.swing.JFormattedTextField 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.JFormattedTextField in project knime-core by knime.
the class DomainDialog method createNumericDomainPanel.
private JPanel createNumericDomainPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Domain values"));
// Integer column domain panel
Box nomBox = Box.createHorizontalBox();
JPanel up = new JPanel();
up.setLayout(new BoxLayout(up, BoxLayout.X_AXIS));
JLabel upperBoundLabel = new JLabel("Upper Bound: ");
up.add(upperBoundLabel);
m_upperBoundField = new JFormattedTextField(new AbstractFormatter() {
/**
* {@inheritDoc}
*/
@Override
public Object stringToValue(final String text) throws ParseException {
try {
if (m_colProp.getColumnSpec().getType().equals(DoubleCell.TYPE)) {
return Double.parseDouble(text);
}
if (m_colProp.getColumnSpec().getType().equals(IntCell.TYPE)) {
return Integer.parseInt(text);
}
// should not happen
throw new NumberFormatException("Impossible column type.");
} catch (NumberFormatException nfe) {
throw new ParseException("Contains non-numeric chars", 0);
}
}
/**
* {@inheritDoc}
*/
@Override
public String valueToString(final Object value) throws ParseException {
return value == null ? null : value.toString();
}
});
m_upperBoundField.setColumns(8);
up.add(m_upperBoundField);
JPanel low = new JPanel();
low.setLayout(new BoxLayout(low, BoxLayout.X_AXIS));
JLabel lowerBoundLabel = new JLabel("Lower Bound: ");
low.add(lowerBoundLabel);
m_lowerBoundField = new JFormattedTextField(new AbstractFormatter() {
/**
* {@inheritDoc}
*/
@Override
public Object stringToValue(final String text) throws ParseException {
try {
if (m_colProp.getColumnSpec().getType().equals(DoubleCell.TYPE)) {
return Double.parseDouble(text);
}
if (m_colProp.getColumnSpec().getType().equals(IntCell.TYPE)) {
return Integer.parseInt(text);
}
// should not happen
throw new NumberFormatException("Impossible column type.");
} catch (NumberFormatException nfe) {
throw new ParseException("Contains non-numeric chars", 0);
}
}
/**
* {@inheritDoc}
*/
@Override
public String valueToString(final Object value) throws ParseException {
return value == null ? null : value.toString();
}
});
m_lowerBoundField.setColumns(8);
low.add(m_lowerBoundField);
if (m_colProp.getColumnSpec().getDomain().getUpperBound() != null) {
if (m_colProp.getColumnSpec().getType().equals(IntCell.TYPE)) {
m_upperBoundField.setValue(((IntValue) m_colProp.getColumnSpec().getDomain().getUpperBound()).getIntValue());
m_lowerBoundField.setValue(((IntValue) m_colProp.getColumnSpec().getDomain().getLowerBound()).getIntValue());
}
}
if (m_colProp.getColumnSpec().getDomain().getLowerBound() != null) {
if (m_colProp.getColumnSpec().getType().equals(DoubleCell.TYPE)) {
m_upperBoundField.setValue(((DoubleValue) m_colProp.getColumnSpec().getDomain().getUpperBound()).getDoubleValue());
m_lowerBoundField.setValue(((DoubleValue) m_colProp.getColumnSpec().getDomain().getLowerBound()).getDoubleValue());
}
}
panel.add(low);
panel.add(up);
panel.add(nomBox);
return panel;
}
use of javax.swing.JFormattedTextField in project knime-core by knime.
the class SorterNodeDialogPanel2 method update.
/**
* Updates this panel based on the DataTableSpec, the list of columns to
* include and the corresponding sorting order.
*
* @param spec the DataTableSpec
* @param incl the list to include
* @param sortOrder the sorting order
* @param nrsortitems the inital number of sortitems to be shown
* @param sortInMemory whether to perform the sorting in memory or not
* @param missingToEnd Whether to move missings to the end
*/
void update(final DataTableSpec spec, final List<String> incl, final boolean[] sortOrder, final int nrsortitems, final boolean sortInMemory, final boolean missingToEnd) {
m_spec = spec;
m_memory = sortInMemory;
super.removeAll();
m_components.removeAllElements();
int interncounter = 0;
if (spec != null) {
Vector<DataColumnSpec> values = new Vector<DataColumnSpec>();
values.add(NOSORT);
values.add(ROWKEY);
for (int j = 0; j < spec.getNumColumns(); j++) {
values.add(spec.getColumnSpec(j));
}
if ((incl == null) || (sortOrder == null)) {
for (int i = 0; i < nrsortitems && i < spec.getNumColumns(); i++) {
DataColumnSpec selected = (i == 0) ? values.get(i + 1) : values.get(0);
SortItem temp = new SortItem(i, values, selected, true);
super.add(temp);
m_components.add(temp);
}
} else {
for (int i = 0; i < incl.size(); i++) {
String includeString = incl.get(i);
int columnIndex = spec.findColumnIndex(includeString);
if (columnIndex != -1) {
DataColumnSpec colspec = spec.getColumnSpec(columnIndex);
SortItem temp = new SortItem(interncounter, values, colspec, sortOrder[interncounter]);
super.add(temp);
m_components.add(temp);
interncounter++;
} else if (includeString.equals(NOSORT.getName())) {
SortItem temp = new SortItem(interncounter, values, NOSORT, sortOrder[interncounter]);
super.add(temp);
m_components.add(temp);
interncounter++;
} else if (includeString.equals(ROWKEY.getName())) {
SortItem temp = new SortItem(interncounter, values, ROWKEY, sortOrder[interncounter]);
super.add(temp);
m_components.add(temp);
interncounter++;
} else if (columnIndex == -1) {
SortItem temp = new SortItem(interncounter, values, includeString, sortOrder[interncounter]);
super.add(temp);
m_components.add(temp);
interncounter++;
}
}
}
Box buttonbox = Box.createHorizontalBox();
Border addColumnBorder = BorderFactory.createTitledBorder("Add columns");
buttonbox.setBorder(addColumnBorder);
int maxCols = m_spec.getNumColumns() - m_components.size() + 1;
JButton addSortItemButton = new JButton("new columns");
final JSpinner spinner = new JSpinner();
SpinnerNumberModel snm;
if (maxCols == 0) {
snm = new SpinnerNumberModel(0, 0, maxCols, 1);
spinner.setEnabled(false);
addSortItemButton.setEnabled(false);
} else {
snm = new SpinnerNumberModel(1, 1, maxCols, 1);
}
spinner.setModel(snm);
spinner.setMaximumSize(new Dimension(50, 25));
spinner.setPreferredSize(new Dimension(50, 25));
NumberEditor ne = (NumberEditor) spinner.getEditor();
final JFormattedTextField spinnertextfield = ne.getTextField();
// workaround to ensure same background color
Color backColor = spinnertextfield.getBackground();
// when spinner's text field is editable false
spinnertextfield.setEditable(false);
spinnertextfield.setBackground(backColor);
addSortItemButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ae) {
ArrayList<String> newlist = new ArrayList<String>();
for (int i = 0; i < m_components.size(); i++) {
SortItem temp = m_components.get(i);
newlist.add(temp.getColumnText());
}
int oldsize = m_components.size();
String temp = spinner.getValue().toString();
int newsize = Integer.parseInt(temp);
for (int n = oldsize; n < oldsize + newsize; n++) {
newlist.add(NOSORT.getName());
}
boolean[] oldbool = new boolean[oldsize];
boolean[] newbool = new boolean[oldsize + newsize];
// copy old values
for (int i = 0; i < m_components.size(); i++) {
SortItem temp2 = m_components.get(i);
newbool[i] = temp2.getSortOrder();
}
// create new values
for (int i = oldbool.length; i < newbool.length; i++) {
newbool[i] = true;
}
boolean misToEnd = m_sortMissingToEndChecker.isSelected();
update(m_spec, newlist, newbool, (oldsize + newsize), m_memory, misToEnd);
}
});
buttonbox.add(spinner);
buttonbox.add(Box.createHorizontalStrut(10));
buttonbox.add(addSortItemButton);
super.add(buttonbox);
Box memorybox = Box.createHorizontalBox();
m_memorycheckb = new JCheckBox("Sort in memory", m_memory);
m_memorycheckb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent ae) {
if (m_memorycheckb.isSelected()) {
m_memory = true;
} else {
m_memory = false;
}
}
});
memorybox.add(m_memorycheckb);
super.add(memorybox);
Box missingToEndBox = Box.createHorizontalBox();
m_sortMissingToEndChecker.setSelected(missingToEnd);
missingToEndBox.add(m_sortMissingToEndChecker);
super.add(missingToEndBox);
revalidate();
}
}
use of javax.swing.JFormattedTextField in project scylla by bptlab.
the class DateField method createComponent.
@Override
protected JFormattedTextField createComponent() {
JFormattedTextField field = new JFormattedTextField(DATEFORMAT);
field.setValue(defaultValue());
return field;
}
Aggregations