use of javax.swing.text.NumberFormatter in project chordatlas by twak.
the class AlignTool method getUI.
@Override
public void getUI(JPanel p) {
p.setLayout(new ListDownLayout());
JButton w = new JButton("save alignment");
w.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toAlign.save();
}
});
JButton swap = new JButton("swap");
swap.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Vector3f tmp = alignMarkers[0];
alignMarkers[0] = alignMarkers[1];
alignMarkers[1] = tmp;
tweed.enqueue(new Runnable() {
@Override
public void run() {
doAlign();
}
});
}
});
JFormattedTextField tf = new JFormattedTextField(new NumberFormatter());
tf.setValue(vOffset);
tf.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
vOffset = ((Number) tf.getValue()).doubleValue();
doAlign();
}
});
p.add(w);
p.add(swap);
p.add(new JLabel("height offset:"));
p.add(tf);
}
use of javax.swing.text.NumberFormatter in project java-swing-tips by aterai.
the class MainPanel method makeFFactory.
private static DefaultFormatterFactory makeFFactory(DecimalFormatSymbols dfs) {
DecimalFormat format = new DecimalFormat("0.00", dfs);
NumberFormatter displayFormatter = new NumberFormatter(format);
displayFormatter.setValueClass(Double.class);
NumberFormatter editFormatter = new NumberFormatter(format);
editFormatter.setValueClass(Double.class);
return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
}
use of javax.swing.text.NumberFormatter in project java-swing-tips by aterai.
the class WarningSpinner method makeFFactory.
private static DefaultFormatterFactory makeFFactory(SpinnerNumberModel m) {
// , dfs);
NumberFormat format = new DecimalFormat("####0");
NumberFormatter editFormatter = new NumberFormatter(format) {
// @Override protected DocumentFilter getDocumentFilter() {
// return new IntegerDocumentFilter();
// }
@Override
public Object stringToValue(String text) throws ParseException {
try {
Long.parseLong(text);
} catch (NumberFormatException ex) {
throw (ParseException) new ParseException(ex.getMessage(), 0).initCause(ex);
}
Object o = format.parse(text);
if (o instanceof Long) {
Long val = (Long) format.parse(text);
Long max = (Long) m.getMaximum();
Long min = (Long) m.getMinimum();
if (max.compareTo(val) < 0 || min.compareTo(val) > 0) {
throw new ParseException("out of bounds", 0);
}
return val;
}
throw new ParseException("not Long", 0);
}
};
// editFormatter.setAllowsInvalid(false);
// editFormatter.setCommitsOnValidEdit(true);
editFormatter.setValueClass(Long.class);
NumberFormatter displayFormatter = new NumberFormatter(format);
return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
}
use of javax.swing.text.NumberFormatter in project scylla by bptlab.
the class NumberField method getFormatter.
/**
* @return The formatter that is used for my component.
* Can be overridden to change/add properties.
*/
protected NumberFormatter getFormatter() {
formatter = new NumberFormatter(getFormat());
formatter.setValueClass(getDataTypeClass());
return formatter;
}
use of javax.swing.text.NumberFormatter in project vcell by virtualcell.
the class MovingBoundarySolverOptionsPanel method getFrontTrackingPanel.
private JPanel getFrontTrackingPanel() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createTitledBorder(GuiConstants.TAB_PANEL_BORDER, "Front Tracking"));
int gridy = 0;
GridBagConstraints gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
gbc.anchor = GridBagConstraints.LINE_END;
panel.add(new JLabel("Front To Volume Nodes Ratio"), gbc);
textFieldFrontToNodeRatio = new JFormattedTextField(DecimalFormat.getInstance());
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
panel.add(textFieldFrontToNodeRatio, gbc);
++gridy;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
gbc.anchor = GridBagConstraints.LINE_END;
panel.add(new JLabel("Front Redistribution Method"), gbc);
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
panel.add(comboBoxRedistMode, gbc);
++gridy;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
gbc.anchor = GridBagConstraints.LINE_END;
panel.add(new JLabel("Full Redistribution Mode"), gbc);
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
panel.add(comboBoxRedistVersion, gbc);
++gridy;
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
gbc.anchor = GridBagConstraints.LINE_END;
panel.add(new JLabel("Redistribution Frequency"), gbc);
NumberFormatter integerFormatter = new NumberFormatter(NumberFormat.getInstance());
integerFormatter.setValueClass(Integer.class);
integerFormatter.setMinimum(1);
integerFormatter.setMaximum(Integer.MAX_VALUE);
textFieldRedistributionFrequency = new JFormattedTextField(integerFormatter);
gbc = new java.awt.GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;
gbc.insets = new java.awt.Insets(4, 4, 4, 4);
textFieldRedistributionFrequency.setToolTipText("integer only");
panel.add(textFieldRedistributionFrequency, gbc);
comboBoxRedistMode.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// TODO Auto-generated method stub
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel lbl = (JLabel) c;
lbl.setText(((RedistributionMode) value).getLabel());
}
return c;
}
});
comboBoxRedistVersion.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// TODO Auto-generated method stub
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel lbl = (JLabel) c;
lbl.setText(((RedistributionVersion) value).getLabel());
}
return c;
}
});
comboBoxExtrapolationMethod.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// TODO Auto-generated method stub
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel) {
JLabel lbl = (JLabel) c;
lbl.setText(((ExtrapolationMethod) value).getLabel());
}
return c;
}
});
return panel;
}
Aggregations