本文整理汇总了Java中javax.swing.text.InternationalFormatter类的典型用法代码示例。如果您正苦于以下问题:Java InternationalFormatter类的具体用法?Java InternationalFormatter怎么用?Java InternationalFormatter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InternationalFormatter类属于javax.swing.text包,在下文中一共展示了InternationalFormatter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFormat
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
/**
* 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;
}
示例2: getCalendarField
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
/**
* 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;
}
示例3: getCalendarField
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
/**
* 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;
}
示例4: TestFormattedTextField
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
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);
}
示例5: getCalendarField
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
/**
* 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;
}
示例6: getDefaultFormatterFactory
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
/**
* 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());
}
示例7: RangeTableEditor
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
public RangeTableEditor()
{
InternationalFormatter nf = new InternationalFormatter();
nf.setMinimum( 1 );
nf.setAllowsInvalid( true );
mEditor = new JFormattedTextField( nf );
}
示例8: getFormatter
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
@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;
}
示例9: createFormatter
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
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);
}
}
示例10: testJFormattedTextFieldAbstractFormatter
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
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());
}
示例11: testEditorNullValue
import javax.swing.text.InternationalFormatter; //导入依赖的package包/类
/**
* 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());
}