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

项目:incubator-netbeans    文件:FormatSelector.java   
/**
 * Returns format's pattern. 
 * 
 * @return format's pattern.
 */
public String getFormat() {
    if (format != null) return format;
    String fmt = null;
    if (formatter instanceof MaskFormatter) {
        fmt = ((MaskFormatter)formatter).getMask();
    } else if (formatter instanceof InternationalFormatter) {
        Format f = ((InternationalFormatter)formatter).getFormat();
        if (f instanceof DecimalFormat) {
            fmt = ((DecimalFormat)f).toPattern();
        } else if (f instanceof SimpleDateFormat) {
            fmt = ((SimpleDateFormat)f).toPattern();
        }
    }
    return fmt;
}
项目:Equella    文件:FlatterSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or -1 if
 * there is no valid calendar field under the selection (or the spinner
 * isn't editing dates.
 */
private int getCalendarField(JSpinner spinner)
{
    JComponent editor = spinner.getEditor();

    if( editor instanceof JSpinner.DateEditor )
    {
        JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
        JFormattedTextField ftf = dateEditor.getTextField();
        int start = ftf.getSelectionStart();
        JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();

        if( formatter instanceof InternationalFormatter )
        {
            Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);

            for( int counter = 0; counter < fields.length; counter++ )
            {
                if( fields[counter] instanceof DateFormat.Field )
                {
                    int calendarField;

                    if( fields[counter] == DateFormat.Field.HOUR1 )
                    {
                        calendarField = Calendar.HOUR;
                    }
                    else
                    {
                        calendarField = ((DateFormat.Field) fields[counter]).getCalendarField();
                    }
                    if( calendarField != -1 )
                    {
                        return calendarField;
                    }
                }
            }
        }
    }
    return -1;
}
项目:OpenJSharp    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:jdk8u-jdk    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:jdk8u-jdk    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:openjdk-jdk10    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or -1 if
 * there is no valid calendar field under the selection (or the spinner
 * isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) {
        return -1;
    }

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) {
        return -1;
    }

    final Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) {
            continue;
        }
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field) element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:openjdk-jdk10    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:openjdk9    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or -1 if
 * there is no valid calendar field under the selection (or the spinner
 * isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) {
        return -1;
    }

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) {
        return -1;
    }

    final Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) {
            continue;
        }
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field) element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:openjdk9    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:jdk8u_jdk    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:jdk8u_jdk    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:lookaside_java-1.8.0-openjdk    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:lookaside_java-1.8.0-openjdk    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:j2se_for_android    文件:JFormattedTextField.java   
/**
 * Returns an AbstractFormatterFactory suitable for the passed in Object
 * type.
 */
private AbstractFormatterFactory getDefaultFormatterFactory(Object type) {
    if (type instanceof DateFormat) {
        return new DefaultFormatterFactory(new DateFormatter(
                (DateFormat) type));
    }
    if (type instanceof NumberFormat) {
        return new DefaultFormatterFactory(new NumberFormatter(
                (NumberFormat) type));
    }
    if (type instanceof Format) {
        return new DefaultFormatterFactory(new InternationalFormatter(
                (Format) type));
    }
    if (type instanceof Date) {
        return new DefaultFormatterFactory(new DateFormatter());
    }
    if (type instanceof Number) {
        AbstractFormatter displayFormatter = new NumberFormatter();
        ((NumberFormatter) displayFormatter).setValueClass(type.getClass());
        AbstractFormatter editFormatter = new NumberFormatter(
                new DecimalFormat("#.#"));
        ((NumberFormatter) editFormatter).setValueClass(type.getClass());

        return new DefaultFormatterFactory(displayFormatter,
                displayFormatter, editFormatter);
    }
    return new DefaultFormatterFactory(new DefaultFormatter());
}
项目:sdrtrunk    文件:ChannelMapEditor.java   
public RangeTableEditor()
{
    InternationalFormatter nf = new InternationalFormatter();
    nf.setMinimum( 1 );
    nf.setAllowsInvalid( true );

    mEditor = new JFormattedTextField( nf );
}
项目:ConverterApp    文件:ConverterView.java   
@Override
        public AbstractFormatter getFormatter(JFormattedTextField tf) {
            NumberFormat format = DecimalFormat.getInstance();
//            format.setMinimumIntegerDigits(0);
            format.setMinimumFractionDigits(1); //set minimum decimal place
            format.setMaximumFractionDigits(maximumFractionDigits); //set maximum decimal place
            format.setRoundingMode(RoundingMode.HALF_UP); //set rounding decimal method

            InternationalFormatter formatter = new InternationalFormatter(format);
            formatter.setAllowsInvalid(false);

            return formatter;
        }
项目:infobip-open-jdk-8    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:infobip-open-jdk-8    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:jdk8u-dev-jdk    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:jdk8u-dev-jdk    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:jdk7-jdk    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:openjdk-source-code-learn    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:OLD-OpenJDK8    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:OLD-OpenJDK8    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:cn1    文件:JFormattedTextField.java   
private AbstractFormatter createFormatter(final Format format) {
    if (format instanceof DateFormat) {
        return new DateFormatter((DateFormat) format);
    } else if (format instanceof NumberFormat) {
        return new NumberFormatter((NumberFormat) format);
    } else {
        return new InternationalFormatter(format);
    }
}
项目:cn1    文件:JFormattedTextFieldTest.java   
public void testJFormattedTextFieldAbstractFormatter() {
    InternationalFormatter formatter = new InternationalFormatter();
    JFormattedTextField tf1 = new JFormattedTextField(formatter);
    assertNull(tf1.getValue());
    assertEquals(JFormattedTextField.COMMIT_OR_REVERT, tf1.getFocusLostBehavior());
    assertEquals(formatter, tf1.getFormatter());
    assertTrue(tf1.getFormatterFactory() instanceof DefaultFormatterFactory);
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf1.getFormatterFactory();
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertEquals(formatter, factory.getDefaultFormatter());
    assertNull(factory.getNullFormatter());
}
项目:JAVA_UNIT    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:openjdk-jdk7u-jdk    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:openjdk-jdk7u-jdk    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:freeVM    文件:JFormattedTextField.java   
private AbstractFormatter createFormatter(final Format format) {
    if (format instanceof DateFormat) {
        return new DateFormatter((DateFormat) format);
    } else if (format instanceof NumberFormat) {
        return new NumberFormatter((NumberFormat) format);
    } else {
        return new InternationalFormatter(format);
    }
}
项目:freeVM    文件:JFormattedTextFieldTest.java   
public void testJFormattedTextFieldAbstractFormatter() {
    InternationalFormatter formatter = new InternationalFormatter();
    JFormattedTextField tf1 = new JFormattedTextField(formatter);
    assertNull(tf1.getValue());
    assertEquals(JFormattedTextField.COMMIT_OR_REVERT, tf1.getFocusLostBehavior());
    assertEquals(formatter, tf1.getFormatter());
    assertTrue(tf1.getFormatterFactory() instanceof DefaultFormatterFactory);
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf1.getFormatterFactory();
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertEquals(formatter, factory.getDefaultFormatter());
    assertNull(factory.getNullFormatter());
}
项目:freeVM    文件:JFormattedTextField.java   
private AbstractFormatter createFormatter(final Format format) {
    if (format instanceof DateFormat) {
        return new DateFormatter((DateFormat) format);
    } else if (format instanceof NumberFormat) {
        return new NumberFormatter((NumberFormat) format);
    } else {
        return new InternationalFormatter(format);
    }
}
项目:freeVM    文件:JFormattedTextFieldTest.java   
public void testJFormattedTextFieldAbstractFormatter() {
    InternationalFormatter formatter = new InternationalFormatter();
    JFormattedTextField tf1 = new JFormattedTextField(formatter);
    assertNull(tf1.getValue());
    assertEquals(JFormattedTextField.COMMIT_OR_REVERT, tf1.getFocusLostBehavior());
    assertEquals(formatter, tf1.getFormatter());
    assertTrue(tf1.getFormatterFactory() instanceof DefaultFormatterFactory);
    DefaultFormatterFactory factory = (DefaultFormatterFactory) tf1.getFormatterFactory();
    assertNull(factory.getDisplayFormatter());
    assertNull(factory.getEditFormatter());
    assertEquals(formatter, factory.getDefaultFormatter());
    assertNull(factory.getNullFormatter());
}
项目:openjdk-icedtea7    文件:AquaSpinnerUI.java   
/**
 * Returns the calendarField under the start of the selection, or
 * -1 if there is no valid calendar field under the selection (or
 * the spinner isn't editing dates.
 */
private int getCalendarField(final JSpinner spinnerComponent) {
    final JComponent editor = spinnerComponent.getEditor();
    if (!(editor instanceof JSpinner.DateEditor)) return -1;

    final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor)editor;
    final JFormattedTextField ftf = dateEditor.getTextField();
    final int start = ftf.getSelectionStart();
    final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
    if (!(formatter instanceof InternationalFormatter)) return -1;

    final Format.Field[] fields = ((InternationalFormatter)formatter).getFields(start);
    for (final Field element : fields) {
        if (!(element instanceof DateFormat.Field)) continue;
        int calendarField;

        if (element == DateFormat.Field.HOUR1) {
            calendarField = Calendar.HOUR;
        } else {
            calendarField = ((DateFormat.Field)element).getCalendarField();
        }

        if (calendarField != -1) {
            return calendarField;
        }
    }
    return -1;
}
项目:openjdk-icedtea7    文件:Test6462562.java   
public TestFormattedTextField(InternationalFormatter fmt) {
    super(fmt);
    fmt.setAllowsInvalid(false);
    fmt.setOverwriteMode(true);

    backspace = getActionMap().get(DefaultEditorKit.deletePrevCharAction);
    delete = getActionMap().get(DefaultEditorKit.deleteNextCharAction);
    insert = getActionMap().get(DefaultEditorKit.insertContentAction);
    dummyEvent = new ActionEvent(this, 0, null);
}
项目:swingx    文件:NumberEditorExtIssues.java   
/**
 * Issue ??-swingx: editor with strict number formatter throws on 
 *    committing null value.
 *   
 *  happens only if active editor in table. Use non-strict for comparison.
 *  InternationalFormatter with bounds throws as well. But not using
 *  strict catches this in isValid, that is stopCellEditing returns false.
 */
@Test
public void testEditorNullValue() {
    table.getColumn(INTEGER_COLUMN).setCellEditor(cellEditor);
    ((InternationalFormatter) cellEditor.getComponent().getFormatter()).setMinimum(0);
    table.editCellAt(0, INTEGER_COLUMN);
    assertTrue(cellEditor.stopCellEditing());
}