Search in sources :

Example 1 with NumberFormatter

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);
        }
    }
}
Also used : PcgCombatant(gmgen.plugin.PcgCombatant) JFormattedTextField(javax.swing.JFormattedTextField) DefaultFormatter(javax.swing.text.DefaultFormatter) InitHolder(gmgen.plugin.InitHolder) XMLCombatant(plugin.initiative.XMLCombatant) NumberFormatter(javax.swing.text.NumberFormatter)

Example 2 with NumberFormatter

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;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JFormattedTextField(javax.swing.JFormattedTextField) Border(javax.swing.border.Border) NumberFormatter(javax.swing.text.NumberFormatter)

Example 3 with NumberFormatter

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);
}
Also used : NumberFormatter(javax.swing.text.NumberFormatter)

Example 4 with NumberFormatter

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
            }
        }
    });
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) ParseException(java.text.ParseException) Document(javax.swing.text.Document) DocumentEvent(javax.swing.event.DocumentEvent) NumberFormat(java.text.NumberFormat) NumberFormatter(javax.swing.text.NumberFormatter)

Example 5 with NumberFormatter

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));
}
Also used : DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter)

Aggregations

NumberFormatter (javax.swing.text.NumberFormatter)23 JFormattedTextField (javax.swing.JFormattedTextField)9 NumberFormat (java.text.NumberFormat)8 DecimalFormat (java.text.DecimalFormat)7 DefaultFormatterFactory (javax.swing.text.DefaultFormatterFactory)7 JLabel (javax.swing.JLabel)4 ParseException (java.text.ParseException)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 JButton (javax.swing.JButton)2 JPanel (javax.swing.JPanel)2 Border (javax.swing.border.Border)2 ExtrapolationMethod (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.ExtrapolationMethod)1 RedistributionMode (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionMode)1 RedistributionVersion (cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 ColoredListCellRenderer (com.intellij.ui.ColoredListCellRenderer)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1