當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractFormatter類代碼示例

本文整理匯總了Java中javax.swing.JFormattedTextField.AbstractFormatter的典型用法代碼示例。如果您正苦於以下問題:Java AbstractFormatter類的具體用法?Java AbstractFormatter怎麽用?Java AbstractFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractFormatter類屬於javax.swing.JFormattedTextField包,在下文中一共展示了AbstractFormatter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFormatter

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Returns the appropriate formatter based on the state of
 * <code>tf</code>. If <code>tf<code> is null we return null, otherwise
 * we return one of the following:
 * 1. Returns <code>nullFormatter</code> if <code>tf.getValue()</code> is
 * null and <code>nullFormatter</code> is not.
 * 2. Returns <code>editFormatter</code> if <code>tf.hasFocus()</code> is
 * true and <code>editFormatter</code> is not null.
 * 3. Returns <code>displayFormatter</code> if <code>tf.hasFocus()</code> is
 * false and <code>displayFormatter</code> is not null.
 * 4. Otherwise returns <code>defaultFormatter</code>.
 */
public AbstractFormatter getFormatter(JFormattedTextField tf)
{
  if (tf == null)
    return null;

  if (tf.getValue() == null && nullFormatter != null)
    return nullFormatter;

  if (tf.hasFocus() && editFormatter != null)
    return editFormatter;

  if (!tf.hasFocus() && displayFormatter != null)
    return displayFormatter;

  return defaultFormatter;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:29,代碼來源:DefaultFormatterFactory.java

示例2: getFormatter

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Returns the appropriate formatter based on the state of 
 * <code>tf</code>. If <code>tf<code> is null we return null, otherwise
 * we return one of the following:
 * 1. Returns <code>nullFormatter</code> if <code>tf.getValue()</code> is 
 * null and <code>nullFormatter</code> is not.  
 * 2. Returns <code>editFormatter</code> if <code>tf.hasFocus()</code> is
 * true and <code>editFormatter</code> is not null.
 * 3. Returns <code>displayFormatter</code> if <code>tf.hasFocus()</code> is
 * false and <code>displayFormatter</code> is not null.
 * 4. Otherwise returns <code>defaultFormatter</code>.
 */
public AbstractFormatter getFormatter(JFormattedTextField tf)
{
  if (tf == null)
    return null;
  
  if (tf.getValue() == null && nullFormatter != null)
    return nullFormatter;

  if (tf.hasFocus() && editFormatter != null)
    return editFormatter;

  if (!tf.hasFocus() && displayFormatter != null)
    return displayFormatter;

  return defaultFormatter;
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:29,代碼來源:DefaultFormatterFactory.java

示例3: getCustomFormats

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
     * Checks and returns custom formats on the editor, if any.
     * 
     * @param editor the editor to check
     * @return the custom formats uses in the editor or null if it had
     *   used defaults as defined in the datepicker properties
     */
    private DateFormat[] getCustomFormats(JFormattedTextField editor) {
        DateFormat[] formats = null;
        if (editor != null) {
            AbstractFormatterFactory factory = editor.getFormatterFactory();
            if (factory != null) {
                AbstractFormatter formatter = factory.getFormatter(editor);
                // fix for #1144: classCastException for custom formatters
                // PENDING JW: revisit for #1138
                if ((formatter instanceof DatePickerFormatter) && !(formatter instanceof UIResource)) {
//                if (!(formatter instanceof DatePickerFormatterUIResource))  {
                    formats = ((DatePickerFormatter) formatter).getFormats();
                }
            }

        }
        return formats;
    }
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:25,代碼來源:BasicDatePickerUI.java

示例4: setCommitOnValidEdit

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
@Override
public void setCommitOnValidEdit(final boolean commit)
{
	if (textComponent instanceof JFormattedTextField)
	{
		final JFormattedTextField formattedTextField = (JFormattedTextField)textComponent;
		final AbstractFormatter formatter = formattedTextField.getFormatter();
		if (formatter instanceof DefaultFormatter)
		{
			final DefaultFormatter defaultFormatter = (DefaultFormatter)formatter;
			defaultFormatter.setCommitsOnValidEdit(commit);
			return;
		}
	}
	else if (textComponent instanceof JTextArea)
	{
		// ignore it for now
	}
	else
	{
		throw new UnsupportedOperationException("setCommitOnValidValue not supported for " + this);
	}
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:24,代碼來源:SwingTerminalTextField.java

示例5: init

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
private void init() {
	JFormattedTextField ftf = (JFormattedTextField)((JSpinner.DefaultEditor)this.getEditor()).getTextField(); // ! depends on swing implementation to actually use FormattedTextField
	ftf.setColumns(((TickSpinnerModel)getModel()).format.textFieldSize);
	ftf.setFormatterFactory(new JFormattedTextField.AbstractFormatterFactory() {
		@Override
		public AbstractFormatter getFormatter(JFormattedTextField tf) {
			return new JFormattedTextField.AbstractFormatter() {
				@Override
				public Object stringToValue(String text) throws ParseException {
					return ((TickSpinnerModel)getModel()).stringToTicks(text);
				}
				@Override
				public String valueToString(Object value) throws ParseException {
					return ((TickSpinnerModel)getModel()).ticksToString((Long)value);
				}
			};
		}
	});
	ftf.addCaretListener(this);
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:21,代碼來源:TickSpinner.java

示例6: verify

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Verify the input text.  An empty text string is allowed for an optional field.
 * The text is not valid if the formatter throws a parse exception.
 *
 * @param       input       Input component
 * @return                  TRUE if the input text is valid
 */
@Override
public boolean verify(JComponent input) {
    boolean allow = true;
    if (input instanceof JFormattedTextField) {
        JFormattedTextField textField = (JFormattedTextField)input;
        AbstractFormatter formatter = textField.getFormatter();
        if (formatter != null) {
            String value = textField.getText();
            if (value.length() != 0) {
                try {
                    formatter.stringToValue(value);
                } catch (ParseException exc) {
                    allow = false;
                }
            } else if (!optionalField) {
                allow = false;
            }
        }
    }

    return allow;
}
 
開發者ID:ScripterRon,項目名稱:BitcoinWallet,代碼行數:30,代碼來源:EditInputVerifier.java

示例7: verify

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Verify the input text.  An empty text string is allowed for an optional field.
 * The text is not valid if the formatter throws a parse exception.
 *
 * @param       input       Input component
 * @return                  TRUE if the input text is valid
 */
public boolean verify(JComponent input) {
    boolean allow = true;
    if (input instanceof JFormattedTextField) {
        JFormattedTextField textField = (JFormattedTextField)input;
        AbstractFormatter formatter = textField.getFormatter();
        if (formatter != null) {
            String value = textField.getText();
            if (value.length() != 0) {
                try {
                    formatter.stringToValue(value);
                } catch (ParseException exc) {
                    allow = false;
                }
            } else if (!optionalField) {
                allow = false;
            }
        }
    }

    return allow;
}
 
開發者ID:ScripterRon,項目名稱:MyMoney,代碼行數:29,代碼來源:EditInputVerifier.java

示例8: setFormat

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Sets the format used to display the value of this spinner.
 */
public void setFormat(Format format)
{
	JComponent editor = getEditor();
	if (editor instanceof JSpinner.DefaultEditor)
	{
		JFormattedTextField textField = ((JSpinner.DefaultEditor) editor).getTextField();
		AbstractFormatter formatter = textField.getFormatter();
		if (formatter instanceof NumberFormatter)
		{
			((NumberFormatter) formatter).setFormat(format);
			fireStateChanged();
		}
	}
}
 
開發者ID:valsr,項目名稱:SweetHome3D,代碼行數:18,代碼來源:AutoCommitSpinner.java

示例9: getFormats

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Returns an array of the formats used by the installed formatter
 * if it is a subclass of <code>JXDatePickerFormatter<code>.
 * <code>javax.swing.JFormattedTextField.AbstractFormatter</code>
 * and <code>javax.swing.text.DefaultFormatter</code> do not have
 * support for accessing the formats used.
 *
 * @return array of formats guaranteed to be not null, but might be empty.
 */
public DateFormat[] getFormats() {
    // Dig this out from the factory, if possible, otherwise return null.
    AbstractFormatterFactory factory = _dateField.getFormatterFactory();
    if (factory != null) {
        AbstractFormatter formatter = factory.getFormatter(_dateField);
        if (formatter instanceof DatePickerFormatter) {
            return ((DatePickerFormatter) formatter).getFormats();
        }
    }
    return EMPTY_DATE_FORMATS;
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:21,代碼來源:JXDatePicker.java

示例10: SizeSpinner

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * @param model
 */
public SizeSpinner(final SpinnerNumberModel model) {
    super(model);

    // this.addFocusListener(this);
    this.nm = (SpinnerNumberModel) super.getModel();

    final DefaultFormatterFactory factory = new DefaultFormatterFactory(new AbstractFormatter() {

        private static final long serialVersionUID = 7808117078307243989L;

        @Override
        public Object stringToValue(final String text) throws ParseException {
            return SizeSpinner.this.textToObject(text);
        }

        @Override
        public String valueToString(final Object value) throws ParseException {

            return SizeSpinner.this.longToText(((Number) value).longValue());
        }

    });
    ((JSpinner.DefaultEditor) this.getEditor()).getTextField().setFormatterFactory(factory);
    ((JSpinner.DefaultEditor) this.getEditor()).getTextField().addFocusListener(this);
    ((JSpinner.DefaultEditor) this.getEditor()).getTextField().addActionListener(this);
}
 
開發者ID:friedlwo,項目名稱:AppWoksUtils,代碼行數:30,代碼來源:SizeSpinner.java

示例11: getFormatter

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的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;
        }
 
開發者ID:Jayden159,項目名稱:ConverterApp,代碼行數:14,代碼來源:ConverterView.java

示例12: getCustomFormats

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Checks and returns custom formats on the editor, if any.
 * 
 * @param editor the editor to check
 * @return the custom formats uses in the editor or null if it had
 *   used defaults as defined in the datepicker properties
 */
private DateFormat[] getCustomFormats(JFormattedTextField editor) {
    DateFormat[] formats = null;
    if (editor != null) {
        AbstractFormatterFactory factory = editor.getFormatterFactory();
        if (factory != null) {
            AbstractFormatter formatter = factory.getFormatter(editor);
            if (!(formatter instanceof DatePickerFormatterUIResource))  {
                formats = ((DatePickerFormatter) formatter).getFormats();
            }
        }

    }
    return formats;
}
 
開發者ID:sing-group,項目名稱:aibench-project,代碼行數:22,代碼來源:BasicDatePickerUI.java

示例13: getFormats

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
/**
 * Returns an array of the formats used by the installed formatter
 * if it is a subclass of <code>JXDatePickerFormatter<code>.
 * <code>javax.swing.JFormattedTextField.AbstractFormatter</code>
 * and <code>javax.swing.text.DefaultFormatter</code> do not have
 * support for accessing the formats used.
 *
 * @return array of formats or null if unavailable.
 */
public DateFormat[] getFormats() {
    // Dig this out from the factory, if possible, otherwise return null.
    AbstractFormatterFactory factory = _dateField.getFormatterFactory();
    if (factory != null) {
        AbstractFormatter formatter = factory.getFormatter(_dateField);
        if (formatter instanceof JXDatePickerFormatter) {
            return ((JXDatePickerFormatter)formatter).getFormats();
        }
    }
    return null;
}
 
開發者ID:JockiHendry,項目名稱:ireport-fork,代碼行數:21,代碼來源:DateRangeDatePicker.java

示例14: testListEditor_formatter

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
public void testListEditor_formatter() throws Exception {
    JComponent comp = new JButton();
    Object[] values = { "arrline1", "arrline2", "text", new Integer(33), comp };
    spinner.setModel(new SpinnerListModel(values));
    ListEditor listEditor = new ListEditor(spinner);
    spinner.setEditor(listEditor);
    AbstractFormatter formatter = ((ListEditor) spinner.getEditor()).getTextField()
            .getFormatter();
    assertEquals(formatter.valueToString(null), "");
    assertEquals(formatter.valueToString(new Integer(33)), "33");
    assertEquals(formatter.stringToValue("text"), "text");
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:13,代碼來源:JSpinnerTest.java

示例15: getFormatter

import javax.swing.JFormattedTextField.AbstractFormatter; //導入依賴的package包/類
public AbstractFormatter getFormatter(JFormattedTextField tf) {
    return new AbstractFormatter() {

        public Object stringToValue(String text) throws ParseException {
            if (text != null && !text.equals(text.toLowerCase())) {
                throw new ParseException(text, 0);
            }
            return text;
        }

        public String valueToString(Object value) throws ParseException {
            return (String) value;
        }
    };
}
 
開發者ID:shevek,項目名稱:spring-rich-client,代碼行數:16,代碼來源:FormattedTextFieldAdapterTests.java


注:本文中的javax.swing.JFormattedTextField.AbstractFormatter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。