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);
}
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));
}
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);
}
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);
}
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());
}
Aggregations