use of javax.swing.text.NumberFormatter in project jgnash by ccavanaugh.
the class CheckDesignDialog method getIntegerField.
private static JFormattedTextField getIntegerField() {
NumberFormatter df = new NumberFormatter(new DecimalFormat("#"));
NumberFormatter ef = new NumberFormatter(new DecimalFormat("#"));
return new JFormattedTextField(new DefaultFormatterFactory(df, df, ef));
}
use of javax.swing.text.NumberFormatter in project sic by belluccifranco.
the class RenderTabla method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
this.setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : null);
this.setBackground(isSelected ? UIManager.getColor("Table.selectionBackground") : UIManager.getColor("Table.background"));
this.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(new DecimalFormat("##,##0.00"))));
this.setHorizontalAlignment(SwingConstants.RIGHT);
Double valor = null;
if (value instanceof Double) {
valor = (Double) value;
}
this.setValue(valor);
return this;
}
use of javax.swing.text.NumberFormatter in project JMRI by JMRI.
the class OptionsMenu method optionWindowRequested.
private void optionWindowRequested(ActionEvent e) {
if (optionsFrame == null) {
optionsFrame = new JmriJFrame(Bundle.getMessage("MenuOptions"), false, true);
optionsFrame.addHelpMenu("package.jmri.jmrit.dispatcher.Options", true);
optionsPane = optionsFrame.getContentPane();
optionsPane.setLayout(new BoxLayout(optionsFrame.getContentPane(), BoxLayout.Y_AXIS));
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(useConnectivityCheckBox);
useConnectivityCheckBox.setToolTipText(Bundle.getMessage("UseConnectivityHint"));
p1.add(layoutEditorBox);
layoutEditorBox.setToolTipText(Bundle.getMessage("LayoutEditorHint"));
signalTypeBox = new JComboBox<String>(signalTypes);
p1.add(signalTypeBox);
signalTypeBox.setToolTipText(Bundle.getMessage("SignalTypeHint"));
optionsPane.add(p1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
ButtonGroup trainsGroup = new ButtonGroup();
p2.add(trainsFromRoster);
trainsFromRoster.setToolTipText(Bundle.getMessage("TrainsFromRosterHint"));
trainsGroup.add(trainsFromRoster);
ActionListener useRosterEntryListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (trainsFromRoster.isSelected()) {
rosterInBlockCheckBox.setEnabled(true);
if (nameInBlockCheckBox.isSelected() && e.getSource() == nameInBlockCheckBox) {
rosterInBlockCheckBox.setSelected(false);
} else if (rosterInBlockCheckBox.isSelected() && e.getSource() == rosterInBlockCheckBox) {
nameInBlockCheckBox.setSelected(false);
}
} else {
rosterInBlockCheckBox.setEnabled(false);
}
}
};
trainsFromRoster.addActionListener(useRosterEntryListener);
p2.add(new JLabel(" "));
p2.add(trainsFromTrains);
trainsFromTrains.setToolTipText(Bundle.getMessage("TrainsFromTrainsHint"));
trainsFromTrains.addActionListener(useRosterEntryListener);
trainsGroup.add(trainsFromTrains);
p2.add(new JLabel(" "));
p2.add(trainsFromUser);
trainsFromUser.setToolTipText(Bundle.getMessage("TrainsFromUserHint"));
trainsFromUser.addActionListener(useRosterEntryListener);
trainsGroup.add(trainsFromUser);
optionsPane.add(p2);
JPanel p3 = new JPanel();
p3.setLayout(new FlowLayout());
p3.add(detectionCheckBox);
detectionCheckBox.setToolTipText(Bundle.getMessage("DetectionBoxHint"));
optionsPane.add(p3);
JPanel p4 = new JPanel();
p4.setLayout(new FlowLayout());
p4.add(autoAllocateCheckBox);
autoAllocateCheckBox.setToolTipText(Bundle.getMessage("AutoAllocateBoxHint"));
optionsPane.add(p4);
JPanel p5 = new JPanel();
p5.setLayout(new FlowLayout());
p5.add(autoTurnoutsCheckBox);
autoTurnoutsCheckBox.setToolTipText(Bundle.getMessage("AutoTurnoutsBoxHint"));
optionsPane.add(p5);
JPanel p16 = new JPanel();
p16.setLayout(new FlowLayout());
p16.add(trustKnownTurnoutsCheckBox);
trustKnownTurnoutsCheckBox.setToolTipText(Bundle.getMessage("trustKnownTurnoutsHint"));
optionsPane.add(p16);
JPanel p6 = new JPanel();
p6.setLayout(new FlowLayout());
p6.add(shortNameCheckBox);
shortNameCheckBox.setToolTipText(Bundle.getMessage("ShortNameBoxHint"));
optionsPane.add(p6);
JPanel p7 = new JPanel();
p7.setLayout(new FlowLayout());
p7.add(nameInBlockCheckBox);
nameInBlockCheckBox.setToolTipText(Bundle.getMessage("NameInBlockBoxHint"));
nameInBlockCheckBox.addActionListener(useRosterEntryListener);
optionsPane.add(p7);
JPanel p7b = new JPanel();
p7b.setLayout(new FlowLayout());
p7b.add(rosterInBlockCheckBox);
rosterInBlockCheckBox.setToolTipText(Bundle.getMessage("RosterInBlockBoxHint"));
rosterInBlockCheckBox.addActionListener(useRosterEntryListener);
optionsPane.add(p7b);
JPanel p10 = new JPanel();
p10.setLayout(new FlowLayout());
p10.add(extraColorForAllocatedCheckBox);
extraColorForAllocatedCheckBox.setToolTipText(Bundle.getMessage("ExtraColorForAllocatedBoxHint"));
optionsPane.add(p10);
JPanel p11 = new JPanel();
p11.setLayout(new FlowLayout());
p11.add(nameInAllocatedBlockCheckBox);
nameInAllocatedBlockCheckBox.setToolTipText(Bundle.getMessage("NameInAllocatedBlockBoxHint"));
optionsPane.add(p11);
JPanel p13 = new JPanel();
p13.setLayout(new FlowLayout());
p13.add(supportVSDecoderCheckBox);
supportVSDecoderCheckBox.setToolTipText(Bundle.getMessage("SupportVSDecoderBoxHint"));
optionsPane.add(p13);
JPanel p8 = new JPanel();
initializeScaleCombo();
p8.add(new JLabel(Bundle.getMessage("LayoutScale") + ":"));
p8.add(layoutScaleBox);
layoutScaleBox.setToolTipText(Bundle.getMessage("ScaleBoxHint"));
optionsPane.add(p8);
JPanel p12 = new JPanel();
p12.setLayout(new FlowLayout());
p12.add(new JLabel(Bundle.getMessage("Units") + " "));
ButtonGroup scaleGroup = new ButtonGroup();
p12.add(scaleFeet);
scaleFeet.setToolTipText(Bundle.getMessage("ScaleFeetHint"));
scaleGroup.add(scaleFeet);
p12.add(new JLabel(" "));
p12.add(scaleMeters);
scaleMeters.setToolTipText(Bundle.getMessage("ScaleMetersHint"));
scaleGroup.add(scaleMeters);
optionsPane.add(p12);
JPanel p15 = new JPanel();
p15.setLayout(new FlowLayout());
p15.add(new JLabel(Bundle.getMessage("minThrottleInterval") + " :"));
NumberFormatter numberFormatter = new NumberFormatter(NumberFormat.getIntegerInstance());
numberFormatter.setValueClass(Integer.class);
numberFormatter.setMinimum(20);
numberFormatter.setMaximum(1000);
minThrottleIntervalTextField = new JFormattedTextField(numberFormatter);
minThrottleIntervalTextField.setColumns(4);
minThrottleIntervalTextField.setValue(250);
minThrottleIntervalTextField.setToolTipText(Bundle.getMessage("minThrottleIntervalHint"));
p15.add(minThrottleIntervalTextField);
p15.add(new JLabel(Bundle.getMessage("ms")));
optionsPane.add(p15);
JPanel p17 = new JPanel();
p17.setLayout(new FlowLayout());
p17.add(new JLabel(Bundle.getMessage("fullRampTime") + " :"));
numberFormatter = new NumberFormatter(NumberFormat.getIntegerInstance());
numberFormatter.setValueClass(Integer.class);
numberFormatter.setMinimum(1000);
numberFormatter.setMaximum(20000);
fullRampTimeTextField = new JFormattedTextField(numberFormatter);
fullRampTimeTextField.setColumns(4);
fullRampTimeTextField.setValue(5000);
fullRampTimeTextField.setToolTipText(Bundle.getMessage("fullRampTimeHint"));
p17.add(fullRampTimeTextField);
p17.add(new JLabel(Bundle.getMessage("ms")));
optionsPane.add(p17);
JPanel p14 = new JPanel();
p14.setLayout(new FlowLayout());
p14.add(openDispatcherWithPanel);
openDispatcherWithPanel.setToolTipText(Bundle.getMessage("OpenDispatcherWithPanelBoxHint"));
optionsPane.add(p14);
optionsPane.add(new JSeparator());
JPanel p9 = new JPanel();
p9.setLayout(new FlowLayout());
JButton cancelButton = null;
p9.add(cancelButton = new JButton(Bundle.getMessage("ButtonCancel")));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancelOptions(e);
}
});
cancelButton.setToolTipText(Bundle.getMessage("CancelButtonHint2"));
p9.add(new JLabel(" "));
JButton applyButton = null;
p9.add(applyButton = new JButton(Bundle.getMessage("ButtonApply")));
applyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
applyOptions(e);
}
});
applyButton.setToolTipText(Bundle.getMessage("ApplyButtonHint"));
optionsPane.add(p9);
}
if (initializeLayoutEditorCombo()) {
useConnectivityCheckBox.setVisible(true);
layoutEditorBox.setVisible(true);
} else {
useConnectivityCheckBox.setVisible(false);
layoutEditorBox.setVisible(false);
}
useConnectivityCheckBox.setSelected(dispatcher.getUseConnectivity());
signalTypeBox.setSelectedIndex(dispatcher.getSignalType());
trainsFromRoster.setSelected(dispatcher.getTrainsFromRoster());
trainsFromTrains.setSelected(dispatcher.getTrainsFromTrains());
trainsFromUser.setSelected(dispatcher.getTrainsFromUser());
detectionCheckBox.setSelected(dispatcher.getHasOccupancyDetection());
autoAllocateCheckBox.setSelected(dispatcher.getAutoAllocate());
autoTurnoutsCheckBox.setSelected(dispatcher.getAutoTurnouts());
trustKnownTurnoutsCheckBox.setSelected(dispatcher.getTrustKnownTurnouts());
shortNameCheckBox.setSelected(dispatcher.getShortActiveTrainNames());
nameInBlockCheckBox.setSelected(dispatcher.getShortNameInBlock());
rosterInBlockCheckBox.setSelected(dispatcher.getRosterEntryInBlock());
extraColorForAllocatedCheckBox.setSelected(dispatcher.getExtraColorForAllocated());
nameInAllocatedBlockCheckBox.setSelected(dispatcher.getNameInAllocatedBlock());
supportVSDecoderCheckBox.setSelected(dispatcher.getSupportVSDecoder());
scaleMeters.setSelected(dispatcher.getUseScaleMeters());
scaleFeet.setSelected(!dispatcher.getUseScaleMeters());
minThrottleIntervalTextField.setValue(dispatcher.getMinThrottleInterval());
fullRampTimeTextField.setValue(dispatcher.getFullRampTime());
if (dispatcher.getLayoutEditor() != null) {
openDispatcherWithPanel.setSelected(dispatcher.getLayoutEditor().getOpenDispatcherOnLoad());
}
optionsFrame.pack();
optionsFrame.setVisible(true);
}
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