Java 类javax.swing.text.DefaultFormatterFactory 实例源码

项目:schneckenrennen    文件:WettDialog.java   
/**
    * Creates a new WettDialog and displays the given array of snails.
    * @param parent The Form opening this dialog
    * @param schneggen The array of snails to display
    * @param wettbueroFactor The factor the Wettbuero uses.
    */
   public WettDialog(Frame parent, ArrayList<Rennschnecke> schneggen, double wettbueroFactor) {
       super(parent, true);
       initComponents();
       NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
       NumberFormatter nf = new NumberFormatter(format);
       nf.setMinimum(0.02);
// The maximum bet value is, well, pretty high.
       nf.setMaximum(Double.MAX_VALUE / wettbueroFactor);
       nf.setAllowsInvalid(false);
       nf.setCommitsOnValidEdit(true);
       nf.setOverwriteMode(false);
       einsatzInput.setFormatterFactory(
               new DefaultFormatterFactory(nf)
       );
       result = null;
       snailList.setModel(new DefaultListModel<>());
       snailList.setListData(schneggen.toArray(new Rennschnecke[schneggen.size()]));
   }
项目:gcs    文件:ContainedWeightReductionEditor.java   
@Override
protected void rebuildSelf(FlexGrid grid, FlexRow right) {
    ContainedWeightReduction feature = (ContainedWeightReduction) getFeature();
    FlexRow row = new FlexRow();
    row.add(addChangeBaseTypeCombo());
    EditorField field = new EditorField(new DefaultFormatterFactory(new WeightReductionFormatter()), (event) -> {
        EditorField source = (EditorField) event.getSource();
        if ("value".equals(event.getPropertyName())) { //$NON-NLS-1$
            feature.setValue(source.getValue());
            notifyActionListeners();
        }
    }, SwingConstants.LEFT, feature.getValue(), new WeightValue(999999999, SheetPreferences.getWeightUnits()), WEIGHT_OR_PERCENTAGE);
    UIUtilities.setOnlySize(field, field.getPreferredSize());
    add(field);
    row.add(field);
    row.add(new FlexSpacer(0, 0, true, false));
    grid.add(row, 0, 0);
}
项目:orbit-image-analysis    文件:NumberPropertyEditor.java   
public NumberPropertyEditor(Class type) {
  if (!Number.class.isAssignableFrom(type)) {
    throw new IllegalArgumentException("type must be a subclass of Number");
  }

  editor = new JFormattedTextField();
  this.type = type;
  ((JFormattedTextField)editor).setValue(getDefaultValue());
  ((JFormattedTextField)editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

  // use a custom formatter to have numbers with up to 64 decimals
  NumberFormat format = NumberConverters.getDefaultFormat();

  ((JFormattedTextField) editor).setFormatterFactory(
      new DefaultFormatterFactory(new NumberFormatter(format))
  );
}
项目:DigitalMediaServer    文件:CustomJSpinner.java   
/**
 * Construct a <code>JSpinner</code> editor that supports displaying and
 * editing the value of a <code>SpinnerIntModel</code> with a
 * <code>JFormattedTextField</code>. <code>This</code>
 * <code>IntegerEditor</code> becomes both a <code>ChangeListener</code>
 * on the spinner and a <code>PropertyChangeListener</code> on the new
 * <code>JFormattedTextField</code>.
 *
 * @param spinner the spinner whose model <code>this</code> editor will
 *            monitor
 * @param format the <code>NumberFormat</code> object that's used to
 *            display and parse the value of the text field.
 * @exception IllegalArgumentException if the spinners model is not an
 *                instance of <code>SpinnerIntModel</code>
 *
 * @see #getTextField
 * @see SpinnerIntModel
 * @see java.text.DecimalFormat
 */
private IntegerEditor(JSpinner spinner, NumberFormat format) {
    super(spinner);
    if (!(spinner.getModel() instanceof SpinnerIntModel)) {
        throw new IllegalArgumentException("model not a SpinnerIntModel");
    }

    format.setGroupingUsed(false);
    format.setMaximumFractionDigits(0);
    SpinnerIntModel model = (SpinnerIntModel) spinner.getModel();
    NumberFormatter formatter = new IntegerEditorFormatter(model, format);
    DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
    JFormattedTextField ftf = getTextField();
    ftf.setEditable(true);
    ftf.setFormatterFactory(factory);
    ftf.setHorizontalAlignment(JTextField.RIGHT);

    try {
        String minString = formatter.valueToString(model.getMinimum());
        String maxString = formatter.valueToString(model.getMaximum());
        // Trying to approximate the width difference between "m" and "0" by multiplying with 0.7
        ftf.setColumns((int) Math.round(0.7 * Math.max(maxString.length(), minString.length())));
    } catch (ParseException e) {
        // Nothing to do, the component width will simply be the default
    }
}
项目:PhET    文件:DateEditor.java   
public DateEditor() {
    super( new JFormattedTextField() );
    textField = (JFormattedTextField) getComponent();

    textField.setFormatterFactory( new DefaultFormatterFactory( new DateFormatter( Entry.LOAD_FORMAT ) ) );
    textField.setFocusLostBehavior( JFormattedTextField.PERSIST );

    textField.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "check" );
    textField.getActionMap().put( "check", new AbstractAction() {
        public void actionPerformed( ActionEvent e ) {
            if ( !textField.isEditValid() ) { //The text is invalid.
                if ( userSaysRevert() ) { //reverted
                    textField.postActionEvent(); //inform the editor
                }
            }
            else {
                try {              //The text is valid,
                    textField.commitEdit();     //so use it.
                    textField.postActionEvent(); //stop editing
                }
                catch ( java.text.ParseException exc ) {
                }
            }
        }
    } );
}
项目:alisma    文件:DatePicker.java   
/**
 * Affiche le paneau de selection de la date au clic de souris
 */
private void init() {
    obj = this;
    getEditor().addMouseListener(mouseListener);
    DatePickerFormatter formatter = new DatePickerFormatter(
    // invers sequence for parsing to satisfy the year parsing rules
            new DateFormat[] { shortFormat, longFormat }) {

        @Override
        public String valueToString(Object value) throws ParseException {
            if (value == null)
                return null;
            return getFormats()[1].format(value);
        }
    };
    DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
    getEditor().setFormatterFactory(factory);
    setFormats(formats);
    getEditor().setDisabledTextColor(Color.BLACK);
}
项目:intellij-ce-playground    文件:SingleIntegerFieldOptionsPanel.java   
/**
 * 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
            }
        }
    });
}
项目:l2fprod-properties-editor    文件:NumberPropertyEditor.java   
public NumberPropertyEditor(Class<?> type) {
    if (!Number.class.isAssignableFrom(type)) {
        throw new IllegalArgumentException("type must be a subclass of Number");
    }

    editor = new JFormattedTextField();
    this.type = type;
    ((JFormattedTextField) editor).setValue(getDefaultValue());
    ((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

    // use a custom formatter to have numbers with up to 64 decimals
    NumberFormat format = NumberConverters.DEFAULT_FORMAT;

    ((JFormattedTextField) editor).setFormatterFactory(
            new DefaultFormatterFactory(new NumberFormatter(format))
    );
}
项目:Tracking-AI    文件:RemoteController.java   
private void initFormats() {
    nfInteger = NumberFormat.getIntegerInstance();
    NumberFormatter nf = new NumberFormatter(nfInteger);
    nf.setMaximum(Server.MAX_PORT_INDEX);
    nf.setMinimum(0);

    NumberFormat editFormat = NumberFormat.getIntegerInstance();
    editFormat.setGroupingUsed(false);
    NumberFormatter editFormatter = new NumberFormatter(editFormat);
    editFormatter.setMaximum(Server.MAX_PORT_INDEX);
    editFormatter.setMinimum(0);

    integerFormatter = new DefaultFormatterFactory(nf, nf, editFormatter, nf);
    port.setFormatterFactory(integerFormatter);
    port.setValue(28015);
    refreshFrequency.setFormatterFactory(integerFormatter);
    refreshFrequency.setValue(1);
}
项目:CodenameOne    文件:NumberPropertyEditor.java   
public NumberPropertyEditor(Class type) {
  if (!Number.class.isAssignableFrom(type)) {
    throw new IllegalArgumentException("type must be a subclass of Number");
  }

  editor = new JFormattedTextField();
  this.type = type;
  ((JFormattedTextField)editor).setValue(getDefaultValue());
  ((JFormattedTextField)editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

  // use a custom formatter to have numbers with up to 64 decimals
  NumberFormat format = NumberConverters.getDefaultFormat();

  ((JFormattedTextField) editor).setFormatterFactory(
      new DefaultFormatterFactory(new NumberFormatter(format))
  );
}
项目:hql-builder    文件:PropertyPanel.java   
public BigIntegerEditor() {
    Class t = BigInteger.class;
    if (!Number.class.isAssignableFrom(t)) {
        throw new IllegalArgumentException("type must be a subclass of Number");
    }

    editor = new JFormattedTextField();
    this.type = t;
    ((JFormattedTextField) editor).setValue(getDefaultValue());
    ((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

    // use a custom formatter to have numbers with up to 64 decimals
    format = NumberConverters.getDefaultFormat();

    ((JFormattedTextField) editor).setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(format)));
}
项目:hql-builder    文件:PropertyPanel.java   
public BigDecimalEditor() {
    Class t = BigDecimal.class;
    if (!Number.class.isAssignableFrom(t)) {
        throw new IllegalArgumentException("type must be a subclass of Number");
    }

    editor = new JFormattedTextField();
    this.type = t;
    ((JFormattedTextField) editor).setValue(getDefaultValue());
    ((JFormattedTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

    // use a custom formatter to have numbers with up to 64 decimals
    format = NumberConverters.getDefaultFormat();

    ((JFormattedTextField) editor).setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(format)));
}
项目:hypertalk-java    文件:StackSizeEditor.java   
public static Dimension editStackSize(Dimension currentSize, Component parent) {
    StackSizeEditor dialog = new StackSizeEditor();
    dialog.stackDimension = currentSize;

    NumberFormat format = NumberFormat.getInstance();
    NumberFormatter formatter = new NumberFormatter(format);
    formatter.setValueClass(Integer.class);
    formatter.setMinimum(0);
    formatter.setMaximum(Integer.MAX_VALUE);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);

    dialog.newHeight.setFormatterFactory(new DefaultFormatterFactory(formatter));
    dialog.newWidth.setFormatterFactory(new DefaultFormatterFactory(formatter));

    dialog.currentStackSize.setText("Stack is " + currentSize.width + "px by " + currentSize.height + "px");
    dialog.newWidth.setText(String.valueOf(currentSize.width));
    dialog.newHeight.setText(String.valueOf(currentSize.height));

    dialog.pack();
    dialog.setLocationRelativeTo(parent);
    dialog.setVisible(true);

    return dialog.stackDimension;
}
项目:svarog    文件:SpinnerNumberEditor.java   
/**
 * Constructor.
 * Sets the DefaultFormatterFactory created based on {@link
 * NumberEditorFormatter} in the text field.
 * @param spinner the spinner for which this editor is used
 * @param format the format of the numbers shown in the spinner
 */
public SpinnerNumberEditor(JSpinner spinner, DecimalFormat format) {
    super(spinner);
    if (!(spinner.getModel() instanceof BoundedSpinnerModel)) {
        throw new IllegalArgumentException(
            "model not a BoundedSpinnerModel");
    }

    BoundedSpinnerModel model = (BoundedSpinnerModel) spinner.getModel();
    NumberFormatter formatter = new NumberEditorFormatter(model, format);
    DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);

    JFormattedTextField ftf = getTextField();
    ftf.setEditable(true);
    ftf.setFormatterFactory(factory);
    ftf.setHorizontalAlignment(JTextField.RIGHT);

    try {
        String maxString = formatter.valueToString(model.getMinimum());
        String minString = formatter.valueToString(model.getMaximum());
        ftf.setColumns(Math.max(maxString.length(),minString.length()));
    } catch (ParseException e) {

    }
}
项目:cn1    文件:JFormattedTextFieldTest.java   
public void testCreateFormattersFactory() {
    DefaultFormatterFactory factory;
    tf.setValue(new Integer(34));
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
    //TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
    // or factory.getEditFormatter().
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue(new Date());
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue("sdffsdf");
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
    tf.setFormatterFactory(null);
    tf.setValue(Color.RED);
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
}
项目:cn1    文件:NumberPropertyEditor.java   
public NumberPropertyEditor(Class type) {
  if (!Number.class.isAssignableFrom(type)) {
    throw new IllegalArgumentException("type must be a subclass of Number");
  }

  editor = new JFormattedTextField();
  this.type = type;
  ((JFormattedTextField)editor).setValue(getDefaultValue());
  ((JFormattedTextField)editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);

  // use a custom formatter to have numbers with up to 64 decimals
  NumberFormat format = NumberConverters.getDefaultFormat();

  ((JFormattedTextField) editor).setFormatterFactory(
      new DefaultFormatterFactory(new NumberFormatter(format))
  );
}
项目:tools-idea    文件:SingleIntegerFieldOptionsPanel.java   
/**
 * 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
            }
        }
    });
}
项目:freeVM    文件:JFormattedTextFieldTest.java   
public void testCreateFormattersFactory() {
    DefaultFormatterFactory factory;
    tf.setValue(new Integer(34));
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
    //TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
    // or factory.getEditFormatter().
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue(new Date());
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue("sdffsdf");
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
    tf.setFormatterFactory(null);
    tf.setValue(Color.RED);
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
}
项目:freeVM    文件:JFormattedTextFieldTest.java   
public void testCreateFormattersFactory() {
    DefaultFormatterFactory factory;
    tf.setValue(new Integer(34));
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof NumberFormatter);
    //TODO: check if factory.getDefaultFormatter() should be same to factory.getDisplayFormatter()
    // or factory.getEditFormatter().
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue(new Date());
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    assertTrue(factory.getDefaultFormatter() instanceof DateFormatter);
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertNull(factory.getNullFormatter());
    tf.setFormatterFactory(null);
    tf.setValue("sdffsdf");
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
    tf.setFormatterFactory(null);
    tf.setValue(Color.RED);
    factory = getFactoryIfDefault(tf.getFormatterFactory());
    checkDefaultFormatter(factory);
}
项目:consulo    文件:SingleIntegerFieldOptionsPanel.java   
/**
 * 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
            }
        }
    });
}
项目:fll-sw    文件:ScheduleDurationField.java   
/**
 * @param value the duration to use for the initial value, may not be null
 */
public ScheduleDurationField(final Duration value) {
  setInputVerifier(new TimeVerifier());

  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setDuration(value);
}
项目:fll-sw    文件:FormatterUtils.java   
/**
 * @param min minimum value
 * @param max maximum value
 * @return text field for editing integers
 */
public static JFormattedTextField createIntegerField(final int min,
                                                     final int max) {

  final NumberFormatter def = new NumberFormatter();
  def.setValueClass(Integer.class);
  final NumberFormatter disp = new NumberFormatter((new DecimalFormat("#,###,##0")));
  disp.setValueClass(Integer.class);
  final NumberFormatter ed = new NumberFormatter((new DecimalFormat("#,###,##0")));
  ed.setValueClass(Integer.class);
  final DefaultFormatterFactory factory = new DefaultFormatterFactory(def, disp, ed);

  final JFormattedTextField field = new JFormattedTextField(factory);
  field.setValue(Integer.valueOf(min));
  field.setInputVerifier(new IntegerVerifier(min, max));
  return field;
}
项目:atdl4j    文件:SwingNullableSpinner.java   
private NumberEditorNull(JSpinner spinner, DecimalFormat format) {
    super(spinner);
    if (!(spinner.getModel() instanceof SpinnerNumberModelNull)) {
        return;
    }

    SpinnerNumberModelNull model = (SpinnerNumberModelNull) spinner.getModel();
    NumberFormatter formatter = new NumberEditorFormatterNull(model, format);
    DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
    JFormattedTextField ftf = getTextField();
    ftf.setEditable(true);
    ftf.setFormatterFactory(factory);
    ftf.setHorizontalAlignment(JTextField.RIGHT);

    try {
        String maxString = formatter.valueToString(model.getMinimum());
        String minString = formatter.valueToString(model.getMaximum());
        ftf.setColumns(Math.max(maxString.length(), minString.length()));
    }
    catch (ParseException e) {
        // TBD should throw a chained error here
    }
}
项目:JRLib    文件:MonthDateSpinner.java   
public MonthDateSpinner(MonthDate value, MonthDate min, MonthDate max) {
    super(new SpinnerDateModel(MDF.toDate(value), toDate(min), toDate(max), STEP_UNIT));
    SpinnerDateModel model = (SpinnerDateModel) super.getModel();
    minDate = (Date) model.getStart();
    maxDate = (Date) model.getEnd();

    JFormattedTextField text = ((JSpinner.DateEditor) getEditor()).getTextField();
    DateFormatter df = new DateFormatter(new SimpleDateFormat(PATTERN));
    text.setFormatterFactory(new DefaultFormatterFactory(df));
    text.setColumns(PATTERN.length());
    text.setEditable(false);
    text.setHorizontalAlignment(JTextField.RIGHT);

    revalidate();
    repaint();
}
项目:marathonv5    文件:IntegerEditor.java   
public IntegerEditor(int min, int max) {
    super(new JFormattedTextField());
    ftf = (JFormattedTextField) getComponent();
    minimum = new Integer(min);
    maximum = new Integer(max);

    // Set up the editor for the integer cells.
    integerFormat = NumberFormat.getIntegerInstance();
    NumberFormatter intFormatter = new NumberFormatter(integerFormat);
    intFormatter.setFormat(integerFormat);
    intFormatter.setMinimum(minimum);
    intFormatter.setMaximum(maximum);

    ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
    ftf.setValue(minimum);
    ftf.setHorizontalAlignment(JTextField.TRAILING);
    ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);

    // React when the user presses Enter while the editor is
    // active. (Tab is handled as specified by
    // JFormattedTextField's focusLostBehavior property.)
    ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    ftf.getActionMap().put("check", new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (!ftf.isEditValid()) { // The text is invalid.
                if (userSaysRevert()) { // reverted
                    ftf.postActionEvent(); // inform the editor
                }
            } else
                try { // The text is valid,
                    ftf.commitEdit(); // so use it.
                    ftf.postActionEvent(); // stop editing
                } catch (java.text.ParseException exc) {
                }
        }
    });
}
项目:smile_1.5.0_java7    文件:DateCellEditor.java   
/**
 * Constructor.
 */
public DateCellEditor(DateFormat dateFormat) {
    super(new JFormattedTextField());
    textField = (JFormattedTextField) getComponent();

    this.dateFormat = dateFormat;
    DateFormatter dateFormatter = new DateFormatter(dateFormat);

    textField.setFormatterFactory(new DefaultFormatterFactory(dateFormatter));
    textField.setHorizontalAlignment(JTextField.TRAILING);
    textField.setFocusLostBehavior(JFormattedTextField.PERSIST);

    // React when the user presses Enter while the editor is
    // active.  (Tab is handled as specified by
    // JFormattedTextField's focusLostBehavior property.)
    textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
    textField.getActionMap().put("check", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!textField.isEditValid()) { //The text is invalid.
                Toolkit.getDefaultToolkit().beep();
                textField.selectAll();
            } else {
                try {              //The text is valid,
                    textField.commitEdit();     //so use it.
                    textField.postActionEvent(); //stop editing
                } catch (java.text.ParseException ex) {
                }
            }
        }
    });
}
项目:MapAnalyst    文件:NumberField.java   
/** Creates a new instance of NumberField */
public NumberField() {

    // define a custom input verifier
    this.setInputVerifier(new NumberVerifier());

    // create a formatter for displaying and editing
    DefaultFormatter formatter = new DefaultFormatter();

    // allow the user to completely delete all text
    formatter.setAllowsInvalid(true);

    // typing should insert new characters and not overwrite old ones
    formatter.setOverwriteMode(false);

    // commit on edit, otherwise a property change event is generated
    // when the field loses the focus and the value changed since it gained
    // the focus.
    formatter.setCommitsOnValidEdit(true);

    // getValue should return a Double object
    formatter.setValueClass(java.lang.Double.class);

    // the kind of formatter getFormatter should return
    this.setFormatterFactory(new DefaultFormatterFactory(formatter));

    // default value is 0
    this.setValue(new Double(0));
}
项目:OpenJSharp    文件:ValueFormatter.java   
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
项目:jdk8u-jdk    文件:ValueFormatter.java   
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
项目:openjdk-jdk10    文件:ValueFormatter.java   
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
项目:openjdk9    文件:ValueFormatter.java   
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
项目:gcs    文件:AdvantageEditor.java   
private EditorField createField(String text, String prototype, String tooltip) {
    DefaultFormatter formatter = new DefaultFormatter();
    formatter.setOverwriteMode(false);
    EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, text, prototype, tooltip);
    field.setEnabled(mIsEditable);
    add(field);
    return field;
}
项目:gcs    文件:AdvantageEditor.java   
private EditorField createField(int min, int max, int value, String tooltip) {
    int proto = Math.max(Math.abs(min), Math.abs(max));
    if (min < 0 || max < 0) {
        proto = -proto;
    }
    EditorField field = new EditorField(new DefaultFormatterFactory(new IntegerFormatter(min, max, false)), this, SwingConstants.LEFT, Integer.valueOf(value), Integer.valueOf(proto), tooltip);
    field.setEnabled(mIsEditable);
    add(field);
    return field;
}
项目:gcs    文件:WeaponEditor.java   
/**
 * Creates a new text field.
 *
 * @param parent The parent.
 * @param title The title of the field.
 * @param value The initial value.
 * @return The newly created field.
 */
protected EditorField createTextField(Container parent, String title, Object value) {
    DefaultFormatter formatter = new DefaultFormatter();
    formatter.setOverwriteMode(false);
    EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, value, null);
    parent.add(new LinkedLabel(title, field));
    parent.add(field);
    return field;
}
项目:gcs    文件:EditorPanel.java   
/**
 * @param compare The current string compare object.
 * @return The field that allows a string comparison to be changed.
 */
protected EditorField addStringCompareField(StringCriteria compare) {
    DefaultFormatter formatter = new DefaultFormatter();
    formatter.setOverwriteMode(false);
    EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, compare.getQualifier(), null);
    field.putClientProperty(StringCriteria.class, compare);
    add(field);
    return field;
}
项目:gcs    文件:EditorPanel.java   
/**
 * @param compare The current compare object.
 * @param min The minimum value to allow.
 * @param max The maximum value to allow.
 * @param forceSign Whether to force the sign to be visible.
 * @return The {@link EditorField} that allows an integer comparison to be changed.
 */
protected EditorField addNumericCompareField(IntegerCriteria compare, int min, int max, boolean forceSign) {
    EditorField field = new EditorField(new DefaultFormatterFactory(new IntegerFormatter(min, max, forceSign)), this, SwingConstants.LEFT, Integer.valueOf(compare.getQualifier()), Integer.valueOf(max), null);
    field.putClientProperty(IntegerCriteria.class, compare);
    UIUtilities.setOnlySize(field, field.getPreferredSize());
    add(field);
    return field;
}
项目:gcs    文件:EditorPanel.java   
/**
 * @param compare The current compare object.
 * @param min The minimum value to allow.
 * @param max The maximum value to allow.
 * @param forceSign Whether to force the sign to be visible.
 * @return The {@link EditorField} that allows a double comparison to be changed.
 */
protected EditorField addNumericCompareField(DoubleCriteria compare, double min, double max, boolean forceSign) {
    EditorField field = new EditorField(new DefaultFormatterFactory(new DoubleFormatter(min, max, forceSign)), this, SwingConstants.LEFT, Double.valueOf(compare.getQualifier()), Double.valueOf(max), null);
    field.putClientProperty(DoubleCriteria.class, compare);
    UIUtilities.setOnlySize(field, field.getPreferredSize());
    add(field);
    return field;
}
项目:gcs    文件:EditorPanel.java   
/**
 * @param compare The current compare object.
 * @return The {@link EditorField} that allows a weight comparison to be changed.
 */
protected EditorField addWeightCompareField(WeightCriteria compare) {
    EditorField field = new EditorField(new DefaultFormatterFactory(new WeightFormatter(true)), this, SwingConstants.LEFT, compare.getQualifier(), null, null);
    field.putClientProperty(WeightCriteria.class, compare);
    add(field);
    return field;
}
项目:Java8CN    文件:ValueFormatter.java   
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}
项目:jdk8u_jdk    文件:ValueFormatter.java   
static void init(int length, boolean hex, JFormattedTextField text) {
    ValueFormatter formatter = new ValueFormatter(length, hex);
    text.setColumns(length);
    text.setFormatterFactory(new DefaultFormatterFactory(formatter));
    text.setHorizontalAlignment(SwingConstants.RIGHT);
    text.setMinimumSize(text.getPreferredSize());
    text.addFocusListener(formatter);
}