All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jidefx.scene.control.field.FormattedTextField Maven / Gradle / Ivy

The newest version!
/*
 * @(#)FormattedTextField.java 5/19/2013
 *
 * Copyright 2002 - 2013 JIDE Software Inc. All rights reserved.
 */

package jidefx.scene.control.field;

import com.sun.javafx.scene.control.skin.TextFieldSkin;
import com.sun.javafx.scene.text.HitInfo;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import javafx.css.PseudoClass;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Cell;
import javafx.scene.control.IndexRange;
import javafx.scene.control.TextField;
import javafx.scene.input.*;
import javafx.scene.shape.Shape;
import javafx.util.Callback;
import javafx.util.StringConverter;
import jidefx.scene.control.decoration.DecorationPane;
import jidefx.scene.control.decoration.DecorationUtils;
import jidefx.scene.control.decoration.Decorator;
import jidefx.scene.control.decoration.PredefinedDecorators;
import jidefx.scene.control.editor.Editor;
import jidefx.scene.control.field.verifier.IntegerRangePatternVerifier;
import jidefx.scene.control.field.verifier.PatternVerifier;
import jidefx.utils.AutoRepeatButtonUtils;
import jidefx.utils.CommonUtils;
import jidefx.utils.PredefinedShapes;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * {@code FormattedTextField} is a {@code TextField} that can restrict the user input by applying a pattern to separate
 * the input string into groups, then define PatternVerifiers to verify/restrict the input for each group.
 * 

* Let's start by looking an example for an IPv4 address field. *

{@code
 * FormattedTextField<String> field = new FormattedTextField<>();
 * field.setPattern("h.h.h.h");
 * field.getPatternVerifiers().put('h', new IntegerRangeGroupVerifier(0, 255));
 * }
*

* The pattern is "h.h.h.h", it means there are four groups, separated by dots. It doesn?t really matter which letter or * letters you use here because it is just a name for the group. In this case, four groups have the same name "h". Then * in the PatternVerifiers map, we added a verifier for the group named "h". The verifier will enforce the input string * for the group is a number and it must be between 0 and 255. * * @param the data type of the value in the {@code FormattedTextField} */ @SuppressWarnings({"Convert2Lambda", "SpellCheckingInspection", "UnusedDeclaration"}) public class FormattedTextField extends TextField /*implements DecorationSupport */ implements Editor { private static final String STYLE_CLASS_DEFAULT = "formatted-text-field"; //NON-NLS private static final String STYLE_CLASS_NO_BACKGROUND_BUTTON = "no-background-button"; //NON-NLS private static final String STYLE_CLASS_INCREASE_BUTTON_ = "increase-button"; //NON-NLS private static final String STYLE_CLASS_DECREASE_BUTTON = "decrease-button"; //NON-NLS private static final String PROPERTY_FORMATTED_TEXT_FIELD_ADJUSTMENT_MOUSE_HANDLER = "FormattedTextField.AdjustmentMouseHandler"; //NON-NLS private StringProperty _patternProperty; private StringProperty _regularExpressionProperty; private BooleanProperty _autoAdvanceProperty; private BooleanProperty _autoReformatProperty; private BooleanProperty _autoSelectAllProperty; private boolean _internalAutoSelectAll = true; private ObjectProperty _valueProperty; private ObjectProperty _defaultValueProperty; private ObjectProperty> _stringConverterProperty; private BooleanProperty _clearbuttonVisibleProperty; private Decorator





© 2015 - 2025 Weber Informatics LLC | Privacy Policy