javax.swing.JFormattedTextField.AbstractFormatter Java Examples
The following examples show how to use
javax.swing.JFormattedTextField.AbstractFormatter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoubleRangeConstraintEditor.java From ghidra with Apache License 2.0 | 6 votes |
private boolean hasValidValue(JSpinner spinner) { NumberEditor numEditor = (NumberEditor) spinner.getEditor(); JFormattedTextField textField = numEditor.getTextField(); AbstractFormatter formatter = textField.getFormatter(); String text = textField.getText(); try { String roundTrip = formatter.valueToString(formatter.stringToValue(text)); Double textDouble = Double.valueOf(text); Double roundTripDouble = Double.valueOf(roundTrip); return Double.compare(textDouble, roundTripDouble) == 0; } catch (ParseException e) { return false; } catch (NumberFormatException nfe) { return false; } }
Example #2
Source File: IntegerInputVerifier.java From ghidra with Apache License 2.0 | 6 votes |
@Override public boolean verify( JComponent input ) { if ( !(input instanceof JFormattedTextField) ) { return true; } JFormattedTextField ftf = (JFormattedTextField)input; AbstractFormatter formatter = ftf.getFormatter(); if ( formatter == null ) { return true; } String text = ftf.getText(); try { Integer intValue = ((Number) formatter.stringToValue(text)).intValue(); if ( intValue.compareTo( 0 ) < 0 ) { // no negatives or values over 1 return false; } return true; } catch ( ParseException e ) { return false; } }
Example #3
Source File: FeatureEditor.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * @param amt The current {@link LeveledAmount}. * @param min The minimum value to allow. * @param max The maximum value to allow. * @return The {@link EditorField} that allows a {@link LeveledAmount} to be changed. */ protected EditorField addLeveledAmountField(LeveledAmount amt, int min, int max) { AbstractFormatter formatter; Object value; Object prototype; if (amt.isIntegerOnly()) { formatter = new IntegerFormatter(min, max, true); value = Integer.valueOf(amt.getIntegerAmount()); prototype = Integer.valueOf(max); } else { formatter = new DoubleFormatter(min, max, true); value = Double.valueOf(amt.getAmount()); prototype = Double.valueOf(max + 0.25); } EditorField field = new EditorField(new DefaultFormatterFactory(formatter), this, SwingConstants.LEFT, value, prototype, null); field.putClientProperty(LeveledAmount.class, amt); UIUtilities.setToPreferredSizeOnly(field); add(field); return field; }
Example #4
Source File: DoubleValueConstraintEditor.java From ghidra with Apache License 2.0 | 5 votes |
private boolean checkEditorValue() { NumberEditor numEditor = (NumberEditor) spinner.getEditor(); JFormattedTextField textField = numEditor.getTextField(); AbstractFormatter formatter = textField.getFormatter(); // to test if the textfield has a valid value, we try and parse it. There are two ways // in which it is invalid - it can't be parsed or when parsed it doesn't match the spinner // value. String text = textField.getText(); try { Double valueFromTextField = (Double) formatter.stringToValue(text); Double spinnerValue = (Double) spinner.getValue(); // to compare the two values, convert them back to formatted strings to avoid rounding issues String valueFromField = formatter.valueToString(valueFromTextField); String valueFromSpinner = formatter.valueToString(spinnerValue); if (valueFromField.equals(valueFromSpinner)) { errorMessage = ""; return true; } } catch (ParseException e) { // Do nothing } errorMessage = "Invalid Value!"; return false; }
Example #5
Source File: BoundedRangeDecimalFormatterFactory.java From ghidra with Apache License 2.0 | 4 votes |
@Override public AbstractFormatter getFormatter(JFormattedTextField tf) { return decimalFormatter; }
Example #6
Source File: DecimalFormatterFactory.java From ghidra with Apache License 2.0 | 4 votes |
@Override public AbstractFormatter getFormatter(JFormattedTextField tf) { return numberFormatter; }
Example #7
Source File: IntegerFormatterFactory.java From ghidra with Apache License 2.0 | 4 votes |
@Override public AbstractFormatter getFormatter(JFormattedTextField tf) { return formatter; }
Example #8
Source File: BoundedRangeInputVerifier.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean verify( JComponent input ) { if ( !(input instanceof JFormattedTextField) ) { return true; } JFormattedTextField ftf = (JFormattedTextField)input; AbstractFormatter formatter = ftf.getFormatter(); if ( formatter == null ) { return true; } String text = ftf.getText(); try { // // First, make sure we are within bounds // Number number = (Number) formatter.stringToValue(text); if ( compareNumbers( number, upperRangeValue ) > 0 || compareNumbers( number, lowerRangeValue ) < 0 ) { // no values above or below our max return false; } // // Second, don't let any value through that crosses our other field's range // boolean result = false; Number otherNumber = (Number) otherField.getValue(); if ( isOtherFieldUpperRange ) { // make sure our value is below the upper range value result = compareNumbers( number, otherNumber ) <= 0; } // make sure our value is above the lower range value else { result = compareNumbers( number, otherNumber ) >= 0; } return result; } catch (ParseException pe) { return false; } }
Example #9
Source File: Fields.java From arcusplatform with Apache License 2.0 | 4 votes |
public static FormattedTextFieldBuilder<Object> formattedTextFieldBuilder(AbstractFormatter formatter) { return new FormattedTextFieldBuilder<Object>(formatter); }
Example #10
Source File: Fields.java From arcusplatform with Apache License 2.0 | 4 votes |
public FormattedTextFieldBuilder(AbstractFormatter passedFormat) { super(new JFormattedTextField(passedFormat)); withGetter((field) -> (V) field.getValue()); withSetter((field, value) -> field.setValue((V) value)); }
Example #11
Source File: SplashUISupport.java From netbeans with Apache License 2.0 | 4 votes |
FontFormatter(AbstractFormatter deleg) { setOverwriteMode(false); this.deleg = deleg; }
Example #12
Source File: CellTypeTextFieldDefaultImpl.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
/** * Creates a {@link JFormattedTextField} for the specified cell. If a formatter is given, will * apply it to the field. Does not validate the model, so make sure this call works! * * @param model * @param rowIndex * @param columnIndex * @param cellClass * @param formatter * the formatter or <code>null</code> if none is required * @param hideUnavailableContentAssist * @return */ public CellTypeTextFieldDefaultImpl(final TablePanelModel model, final int rowIndex, final int columnIndex, final Class<? extends CellType> cellClass, AbstractFormatter formatter, boolean hideUnavailableContentAssist) { super(); final JFormattedTextField field = CellTypeImplHelper.createFormattedTextField(model, rowIndex, columnIndex); setLayout(new BorderLayout()); add(field, BorderLayout.CENTER); // otherwise 'null' would be restored Object value = model.getValueAt(rowIndex, columnIndex); String text = value != null ? String.valueOf(value) : ""; // specical handling when formatter is given if (formatter != null) { field.setFormatterFactory(new DefaultFormatterFactory(formatter)); } field.setText(text); // set syntax assist if available String syntaxHelp = model.getSyntaxHelpAt(rowIndex, columnIndex); if (syntaxHelp != null && !"".equals(syntaxHelp.trim())) { SwingTools.setPrompt(syntaxHelp, field); } // see if content assist is possible for this field, if so add it ImageIcon icon = SwingTools.createIcon("16/" + I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist.icon")); JButton contentAssistButton = new JButton(); contentAssistButton.setIcon(icon); if (field.isEnabled() && model.isContentAssistPossibleForCell(rowIndex, columnIndex)) { contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist_enabled.tip")); CellTypeImplHelper.addContentAssist(model, rowIndex, columnIndex, field, contentAssistButton, cellClass); } else { contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist_disabled.tip")); contentAssistButton.setEnabled(false); } if (contentAssistButton.isEnabled() || (!contentAssistButton.isEnabled() && !hideUnavailableContentAssist)) { add(contentAssistButton, BorderLayout.EAST); } // set size so panels don't grow larger when they get the chance setPreferredSize(new Dimension(300, 20)); setMinimumSize(new Dimension(100, 15)); setMaximumSize(new Dimension(1600, 30)); }