use of javax.swing.text.NumberFormatter in project pcgen by PCGen.
the class Initiative method bDuplicateCombatantActionPerformed.
/**
* @param evt
*/
private void bDuplicateCombatantActionPerformed(ActionEvent evt) {
//TODO: This only works for saved pcgen files and xml combatants.
//For pcgen files, it reloads the file, since there's no good way
//curently to clone a PlayerCharacter.
DefaultFormatter formatter = new NumberFormatter();
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
formatter.setValueClass(Integer.class);
JFormattedTextField field = new JFormattedTextField(formatter);
field.setValue(1);
int choice = JOptionPane.showConfirmDialog(GMGenSystem.inst, field, "How many copies?", JOptionPane.OK_CANCEL_OPTION);
if (choice == JOptionPane.CANCEL_OPTION) {
return;
}
int count = ((Number) field.getValue()).intValue();
for (InitHolder holderToCopy : getSelected()) {
if ((holderToCopy instanceof XMLCombatant) || (holderToCopy instanceof PcgCombatant)) {
if (holderToCopy instanceof PcgCombatant) {
if ((((PcgCombatant) holderToCopy).getPC().getFileName() != null) && (!((PcgCombatant) holderToCopy).getPC().getFileName().isEmpty())) {
pasteNew(holderToCopy, count);
} else {
JOptionPane.showMessageDialog(GMGenSystem.inst, "Combatant " + holderToCopy.getName() + " cannot be duplicated because it has not been saved to a valid .pcg file.", "Cannot Duplicate", JOptionPane.WARNING_MESSAGE);
}
} else {
pasteNew(holderToCopy, count);
}
} else {
JOptionPane.showMessageDialog(GMGenSystem.inst, "Combatant " + holderToCopy.getName() + " cannot be duplicated because it is not a PCGen or XML combatant.", "Cannot Duplicate", JOptionPane.WARNING_MESSAGE);
}
}
}
use of javax.swing.text.NumberFormatter in project pcgen by PCGen.
the class Utils method buildFloatField.
/**
* <p>Builds a formatted text field with specified min and max</p>
*
* @param min minimum value
* @param max maximum value
* @return JFormattedTextField
*/
public static JFormattedTextField buildFloatField(float min, float max) {
java.text.NumberFormat numberFormat = java.text.NumberFormat.getNumberInstance();
// numberFormat.setParseIntegerOnly(false);
NumberFormatter formatter = new NumberFormatter(numberFormat);
//formatter.getCommitsOnValidEdit();
formatter.setMinimum(min);
formatter.setMaximum(max);
final JFormattedTextField returnValue = new JFormattedTextField(formatter);
returnValue.setColumns(4);
returnValue.addPropertyChangeListener(new PropertyChangeListener() {
Border m_originalBorder = returnValue.getBorder();
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName() != null && evt.getPropertyName().equals("editValid")) {
if (evt.getNewValue() != null && evt.getNewValue() instanceof Boolean) {
if (((Boolean) evt.getNewValue()).booleanValue()) {
returnValue.setBorder(m_originalBorder);
} else {
returnValue.setBorder(BorderFactory.createLineBorder(Color.red));
}
}
}
}
});
return returnValue;
}
use of javax.swing.text.NumberFormatter in project jdk8u_jdk by JetBrains.
the class Test6462562 method create.
TestFormattedTextField create(NumberFormat format) {
format.setMaximumFractionDigits(0);
NumberFormatter fmt = new NumberFormatter(format);
return new TestFormattedTextField(fmt);
}
use of javax.swing.text.NumberFormatter in project intellij-community by JetBrains.
the class SingleIntegerFieldOptionsPanel method setupIntegerFieldTrackingValue.
/**
* Sets integer number format to JFormattedTextField instance,
* sets value of JFormattedTextField instance to object's field value,
* synchronizes object's field value with the value of JFormattedTextField instance.
*
* @param textField JFormattedTextField instance
* @param owner an object whose field is synchronized with {@code textField}
* @param property object's field name for synchronization
*/
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField, final InspectionProfileEntry owner, final String property) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
textField.setValue(getPropertyValue(owner, property));
final Document document = textField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
textField.commitEdit();
setPropertyValue(owner, property, ((Number) textField.getValue()).intValue());
} catch (ParseException e1) {
// No luck this time
}
}
});
}
use of javax.swing.text.NumberFormatter in project jgnash by ccavanaugh.
the class CheckDesignDialog method getFloatField.
private static JFormattedTextField getFloatField() {
NumberFormatter df = new NumberFormatter(new DecimalFormat("#.##"));
NumberFormatter ef = new NumberFormatter(new DecimalFormat("#.##"));
return new JFormattedTextField(new DefaultFormatterFactory(df, df, ef));
}
Aggregations