Search in sources :

Example 6 with DefaultFormatterFactory

use of javax.swing.text.DefaultFormatterFactory in project intellij-idea-plugin-connector-for-aws-lambda by satr.

the class ConnectorViewFactory method getIntegerFormatterFactoryFor.

@NotNull
private DefaultFormatterFactory getIntegerFormatterFactoryFor(int minValue, int maxValue) {
    NumberFormatter integerFormat = new NumberFormatter(NumberFormat.getIntegerInstance());
    integerFormat.setMinimum(new Integer(minValue));
    integerFormat.setMaximum(new Integer(maxValue));
    return new DefaultFormatterFactory(integerFormat, integerFormat, integerFormat);
}
Also used : DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DefaultFormatterFactory

use of javax.swing.text.DefaultFormatterFactory in project intellij-idea-plugin-connector-for-aws-lambda by satr.

the class ConnectorViewFactory method getRegexFormatterFactory.

private JFormattedTextField.AbstractFormatterFactory getRegexFormatterFactory(String pattern) {
    RegExFormatter formatter = new RegExFormatter();
    formatter.setAllowsInvalid(false);
    return new DefaultFormatterFactory(new RegexFormatter(pattern));
}
Also used : RegExFormatter(com.intellij.codeInspection.ui.RegExFormatter) RegexFormatter(io.github.satr.idea.plugin.connector.la.ui.components.RegexFormatter) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory)

Example 8 with DefaultFormatterFactory

use of javax.swing.text.DefaultFormatterFactory in project java-swing-tips by aterai.

the class MainPanel method makeFFactory.

private static DefaultFormatterFactory makeFFactory(DecimalFormatSymbols dfs) {
    DecimalFormat format = new DecimalFormat("0.00", dfs);
    NumberFormatter displayFormatter = new NumberFormatter(format);
    displayFormatter.setValueClass(Double.class);
    NumberFormatter editFormatter = new NumberFormatter(format);
    editFormatter.setValueClass(Double.class);
    return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
}
Also used : DecimalFormat(java.text.DecimalFormat) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormatter(javax.swing.text.NumberFormatter)

Example 9 with DefaultFormatterFactory

use of javax.swing.text.DefaultFormatterFactory in project java-swing-tips by aterai.

the class WarningSpinner method makeFFactory.

private static DefaultFormatterFactory makeFFactory(SpinnerNumberModel m) {
    // , dfs);
    NumberFormat format = new DecimalFormat("####0");
    NumberFormatter editFormatter = new NumberFormatter(format) {

        // @Override protected DocumentFilter getDocumentFilter() {
        // return new IntegerDocumentFilter();
        // }
        @Override
        public Object stringToValue(String text) throws ParseException {
            try {
                Long.parseLong(text);
            } catch (NumberFormatException ex) {
                throw (ParseException) new ParseException(ex.getMessage(), 0).initCause(ex);
            }
            Object o = format.parse(text);
            if (o instanceof Long) {
                Long val = (Long) format.parse(text);
                Long max = (Long) m.getMaximum();
                Long min = (Long) m.getMinimum();
                if (max.compareTo(val) < 0 || min.compareTo(val) > 0) {
                    throw new ParseException("out of bounds", 0);
                }
                return val;
            }
            throw new ParseException("not Long", 0);
        }
    };
    // editFormatter.setAllowsInvalid(false);
    // editFormatter.setCommitsOnValidEdit(true);
    editFormatter.setValueClass(Long.class);
    NumberFormatter displayFormatter = new NumberFormatter(format);
    return new DefaultFormatterFactory(displayFormatter, displayFormatter, editFormatter);
}
Also used : DecimalFormat(java.text.DecimalFormat) ParseException(java.text.ParseException) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory) NumberFormat(java.text.NumberFormat) NumberFormatter(javax.swing.text.NumberFormatter)

Example 10 with DefaultFormatterFactory

use of javax.swing.text.DefaultFormatterFactory in project cuba by cuba-platform.

the class DatePicker method setFormats.

@Override
public void setFormats(DateFormat... formats) {
    if (formats != null) {
        Contract.asNotNull(formats, "the array of formats " + "must not contain null elements");
    }
    DateFormat[] old = getFormats();
    for (DateFormat format : formats) {
        format.setLenient(false);
    }
    getEditor().setFormatterFactory(new DefaultFormatterFactory(new DatePicker.CustomDatePickerFormatter(formats, getLocale())));
    firePropertyChange("formats", old, getFormats());
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DefaultFormatterFactory(javax.swing.text.DefaultFormatterFactory)

Aggregations

DefaultFormatterFactory (javax.swing.text.DefaultFormatterFactory)13 NumberFormatter (javax.swing.text.NumberFormatter)9 DecimalFormat (java.text.DecimalFormat)5 NumberFormat (java.text.NumberFormat)3 ParseException (java.text.ParseException)3 JFormattedTextField (javax.swing.JFormattedTextField)2 RegExFormatter (com.intellij.codeInspection.ui.RegExFormatter)1 DocumentAdapter (com.intellij.ui.DocumentAdapter)1 RegexFormatter (io.github.satr.idea.plugin.connector.la.ui.components.RegexFormatter)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DefaultFormatter (javax.swing.text.DefaultFormatter)1 Document (javax.swing.text.Document)1 SearchDefinition (net.sf.mzmine.util.SearchDefinition)1 SearchDefinitionType (net.sf.mzmine.util.SearchDefinitionType)1 NotNull (org.jetbrains.annotations.NotNull)1