Example usage for javafx.scene.control TextFormatter TextFormatter

List of usage examples for javafx.scene.control TextFormatter TextFormatter

Introduction

In this page you can find the example usage for javafx.scene.control TextFormatter TextFormatter.

Prototype

public TextFormatter(@NamedArg("valueConverter") StringConverter<V> valueConverter) 

Source Link

Document

Creates a new Formatter with the provided value converter.

Usage

From source file:ninja.javafx.smartcsv.fx.preferences.PreferencesController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    quoteMode.getItems().addAll("normal", "always", "column");

    UnaryOperator<TextFormatter.Change> allowOnlyOneCharacter = change -> {
        if (change.isContentChange()) {
            if (change.getControlNewText().length() > 1) {
                return null;
            }//from w  w  w  . j  a  va2  s. c  om
        }
        return change;
    };
    quoteChar.setTextFormatter(new TextFormatter(allowOnlyOneCharacter));
    quoteChar.textProperty().addListener(observable -> {
        revalidate();
    });

    delimiterChar.setTextFormatter(new TextFormatter(allowOnlyOneCharacter));
    delimiterChar.textProperty().addListener(observable -> {
        revalidate();
    });
}

From source file:io.github.mzmine.util.jfreechart.ManualZoomDialog.java

@FXML
public void initialize() {

    NumberFormat xAxisFormatter;//  www  .  j  av a 2 s  . c om
    if (xAxis instanceof NumberAxis)
        xAxisFormatter = ((NumberAxis) xAxis).getNumberFormatOverride();
    else
        xAxisFormatter = NumberFormat.getNumberInstance();

    NumberFormat yAxisFormatter;
    if (yAxis instanceof NumberAxis)
        yAxisFormatter = ((NumberAxis) yAxis).getNumberFormatOverride();
    else
        yAxisFormatter = NumberFormat.getNumberInstance();

    xAxisLabel.setText(xAxis.getLabel());
    yAxisLabel.setText(yAxis.getLabel());

    xAxisRangeMin.setTextFormatter(new TextFormatter<>(new NumberStringConverter(xAxisFormatter)));
    xAxisRangeMin.disableProperty().bind(xAxisAutoRange.selectedProperty());
    xAxisRangeMin.setText(String.valueOf(xAxis.getLowerBound()));
    xAxisRangeMax.setTextFormatter(new TextFormatter<>(new NumberStringConverter(xAxisFormatter)));
    xAxisRangeMax.disableProperty().bind(xAxisAutoRange.selectedProperty());
    xAxisRangeMax.setText(String.valueOf(xAxis.getUpperBound()));
    xAxisAutoRange.setSelected(xAxis.isAutoRange());

    yAxisRangeMin.setTextFormatter(new TextFormatter<>(new NumberStringConverter(yAxisFormatter)));
    yAxisRangeMin.setText(String.valueOf(yAxis.getLowerBound()));
    yAxisRangeMin.disableProperty().bind(yAxisAutoRange.selectedProperty());
    yAxisRangeMax.setTextFormatter(new TextFormatter<>(new NumberStringConverter(yAxisFormatter)));
    yAxisRangeMax.setText(String.valueOf(yAxis.getUpperBound()));
    yAxisRangeMax.disableProperty().bind(yAxisAutoRange.selectedProperty());
    yAxisAutoRange.setSelected(yAxis.isAutoRange());

    xAxisTickSize.disableProperty().bind(xAxisAutoTickSize.selectedProperty());
    xAxisTickSize.setText(String.valueOf(xAxis.getTickUnit().getSize()));
    xAxisAutoTickSize.setSelected(xAxis.isAutoTickUnitSelection());

    yAxisTickSize.setTextFormatter(new TextFormatter<>(new NumberStringConverter(yAxisFormatter)));
    yAxisTickSize.setText(String.valueOf(yAxis.getTickUnit().getSize()));
    yAxisTickSize.disableProperty().bind(yAxisAutoTickSize.selectedProperty());
    yAxisAutoTickSize.setSelected(yAxis.isAutoTickUnitSelection());

}

From source file:com.gitlab.anlar.lunatic.gui.MainWindowController.java

private void initElements(Config config) {
    portField.setTextFormatter(new TextFormatter<>(change -> {
        change.setText(change.getText().replaceAll("[^0-9.,]", ""));
        return change;
    }));// w  ww . jav a  2s . c o  m

    if (SystemUtils.IS_OS_UNIX) {
        // change web-cache dir
        // from: $HOME/.com.gitlab.anlar.lunatic.gui.LunaticApplication/webview
        // to:   $HOME/.cache/lunatic-smtp/webview/
        this.emailText.getEngine()
                .setUserDataDirectory(new File(
                        SystemUtils.USER_HOME + File.separator + ".cache" + File.separator + "lunatic-smtp",
                        "webview"));
    }

    portField.setText(String.valueOf(config.getPort()));
    messagesField.setText("0");
    setStartButtonText(false);

    dirField.setText(config.getDirectory());
    saveDirCheck.setSelected(config.isWrite());
}

From source file:net.rptools.tokentool.controller.TokenTool_Controller.java

@FXML
void initialize() {
    // Note: A Pane is added to the compositeTokenPane so the ScrollPane doesn't consume the mouse events
    assert fileManageOverlaysMenu != null : "fx:id=\"fileManageOverlaysMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert fileSaveAsMenu != null : "fx:id=\"fileSaveAsMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert fileExitMenu != null : "fx:id=\"fileExitMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert editCaptureScreenMenu != null : "fx:id=\"editCaptureScreenMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert editCopyImageMenu != null : "fx:id=\"editCopyImageMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert editPasteImageMenu != null : "fx:id=\"editPasteImageMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert helpAboutMenu != null : "fx:id=\"helpAboutMenu\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert saveOptionsPane != null : "fx:id=\"saveOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert overlayOptionsPane != null : "fx:id=\"overlayOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert backgroundOptionsPane != null : "fx:id=\"backgroundOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert zoomOptionsPane != null : "fx:id=\"zoomOptionsPane\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert compositeTokenPane != null : "fx:id=\"compositeTokenPane\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert tokenPreviewPane != null : "fx:id=\"tokenPreviewPane\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert portraitScrollPane != null : "fx:id=\"portraitScrollPane\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert compositeGroup != null : "fx:id=\"compositeGroup\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert overlayTreeView != null : "fx:id=\"overlayTreeview\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert portraitImageView != null : "fx:id=\"portraitImageView\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert maskImageView != null : "fx:id=\"maskImageView\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert overlayImageView != null : "fx:id=\"overlayImageView\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert tokenImageView != null : "fx:id=\"tokenImageView\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert useFileNumberingCheckbox != null : "fx:id=\"useFileNumberingCheckbox\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert overlayUseAsBaseCheckbox != null : "fx:id=\"overlayUseAsBaseCheckbox\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert clipPortraitCheckbox != null : "fx:id=\"clipPortraitCheckbox\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert fileNameTextField != null : "fx:id=\"fileNameTextField\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert fileNameSuffixLabel != null : "fx:id=\"fileNameSuffixLabel\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert fileNameSuffixTextField != null : "fx:id=\"fileNameSuffixTextField\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert overlayNameLabel != null : "fx:id=\"overlayNameLabel\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert backgroundColorPicker != null : "fx:id=\"backgroundColorPicker\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert overlayAspectToggleButton != null : "fx:id=\"overlayAspectToggleButton\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert portraitTransparencySlider != null : "fx:id=\"portraitTransparencySlider\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert portraitBlurSlider != null : "fx:id=\"portraitBlurSlider\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert portraitGlowSlider != null : "fx:id=\"portraitGlowSlider\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert overlayTransparencySlider != null : "fx:id=\"overlayTransparencySlider\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert overlayWidthSpinner != null : "fx:id=\"overlayWidthSpinner\" was not injected: check your FXML file 'TokenTool.fxml'.";
    assert overlayHeightSpinner != null : "fx:id=\"overlayHeightSpinner\" was not injected: check your FXML file 'TokenTool.fxml'.";

    assert overlayTreeProgressBar != null : "fx:id=\"overlayTreeProgressIndicator\" was not injected: check your FXML file 'ManageOverlays.fxml'.";

    executorService = Executors.newCachedThreadPool(runable -> {
        loadOverlaysThread = Executors.defaultThreadFactory().newThread(runable);
        loadOverlaysThread.setDaemon(true);
        return loadOverlaysThread;
    });//  ww w .j  a  v  a 2s. c o  m

    overlayTreeView.setShowRoot(false);
    overlayTreeView.getSelectionModel().selectedItemProperty().addListener(
            (observable, oldValue, newValue) -> updateCompositImageView((TreeItem<Path>) newValue));

    addPseudoClassToLeafs(overlayTreeView);

    // Bind color picker to compositeTokenPane background fill
    backgroundColorPicker.setValue(Color.TRANSPARENT);
    ObjectProperty<Background> background = compositeTokenPane.backgroundProperty();
    background.bind(Bindings.createObjectBinding(() -> {
        BackgroundFill fill = new BackgroundFill(backgroundColorPicker.getValue(), CornerRadii.EMPTY,
                Insets.EMPTY);
        return new Background(fill);
    }, backgroundColorPicker.valueProperty()));

    // Bind transparency slider to portraitImageView opacity
    portraitTransparencySlider.valueProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
            portraitImageView.setOpacity(new_val.doubleValue());
            updateTokenPreviewImageView();
        }
    });

    // // Restrict text field to valid filename characters
    // Pattern validDoubleText = Pattern.compile("[^a-zA-Z0-9\\\\._ \\\\/`~!@#$%\\\\^&\\\\(\\\\)\\\\-\\\\=\\\\+\\\\[\\\\]\\\\{\\\\}',\\\\\\\\:]");
    // Pattern validText = Pattern.compile("[^a-zA-Z0-9 ]");
    // TextFormatter<> textFormatter = new TextFormatter<>(
    // change -> {
    // String newText = change.getControlNewText();
    // if (validText.matcher(newText).matches()) {
    // return change;
    // } else
    // return null;
    // });

    // UnaryOperator<TextFormatter.Change> filter = new UnaryOperator<TextFormatter.Change>() {
    // @Override
    // public TextFormatter.Change apply(TextFormatter.Change t) {
    // String validText = "[^a-zA-Z0-9]";
    //
    // if (t.isReplaced())
    // if (t.getText().matches(validText))
    // t.setText(t.getControlText().substring(t.getRangeStart(), t.getRangeEnd()));
    //
    // if (t.isAdded()) {
    // if (t.getText().matches(validText)) {
    // return null;
    // }
    // }
    //
    // return t;
    // }
    // };

    UnaryOperator<Change> filter = change -> {
        String text = change.getText();

        if (text.matches(AppConstants.VALID_FILE_NAME_PATTERN)) {
            return change;
        } else {
            change.setText(FileSaveUtil.cleanFileName(text));
            ;
            return change;
        }
        //
        // return null;
    };
    TextFormatter<String> textFormatter = new TextFormatter<>(filter);
    fileNameTextField.setTextFormatter(textFormatter);

    // Effects
    GaussianBlur gaussianBlur = new GaussianBlur(0);
    Glow glow = new Glow(0);
    gaussianBlur.setInput(glow);

    // Bind blur slider to portraitImageView opacity
    portraitBlurSlider.valueProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
            gaussianBlur.setRadius(new_val.doubleValue());
            portraitImageView.setEffect(gaussianBlur);
            updateTokenPreviewImageView();
        }
    });

    // Bind glow slider to portraitImageView opacity
    portraitGlowSlider.valueProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
            glow.setLevel(new_val.doubleValue());
            portraitImageView.setEffect(gaussianBlur);
            updateTokenPreviewImageView();
        }
    });

    // Bind transparency slider to overlayImageView opacity
    overlayTransparencySlider.valueProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
            overlayImageView.setOpacity(new_val.doubleValue());
            updateTokenPreviewImageView();
        }
    });

    // Bind width/height spinners to overlay width/height
    overlayWidthSpinner.getValueFactory().valueProperty()
            .bindBidirectional(overlayHeightSpinner.getValueFactory().valueProperty());
    overlayWidthSpinner.valueProperty().addListener(
            (observable, oldValue, newValue) -> overlayWidthSpinner_onTextChanged(oldValue, newValue));
    overlayHeightSpinner.valueProperty().addListener(
            (observable, oldValue, newValue) -> overlayHeightSpinner_onTextChanged(oldValue, newValue));
}

From source file:com.exalttech.trex.util.Util.java

/**
 * Return hex filter// w  w  w  . j  ava  2 s  .com
 *
 * @param numOfChar
 * @return
 */
public static TextFormatter getHexFilter(int numOfChar) {
    UnaryOperator<TextFormatter.Change> filter = Util.getTextChangeFormatter(hexRegex(numOfChar));
    return new TextFormatter<>(filter);
}

From source file:com.exalttech.trex.util.Util.java

/**
 * Return hex filter//w w  w . j a v  a2s .  c o m
 *
 * @param numOfChar
 * @return
 */
public static TextFormatter getNumberFilter(int numOfChar) {
    UnaryOperator<TextFormatter.Change> filter = Util.getTextChangeFormatter(numberRegex(numOfChar));
    return new TextFormatter<>(filter);
}

From source file:ua.com.ecotep.debtprevention.VnaklController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");

    dateFieldFormatter = new TextFormatter(new LocalDateStringConverter(dateTimeFormatter, null));
    dateField.setTextFormatter(dateFieldFormatter);

    dateMaxFieldFormatter = new TextFormatter(new LocalDateStringConverter(dateTimeFormatter, null));
    dateMaxField.setTextFormatter(dateMaxFieldFormatter);

    TableColumn numCol = new TableColumn(".");
    numCol.setPrefWidth(100);/*ww  w .j  av  a 2 s .  c  om*/
    numCol.setCellValueFactory(new PropertyValueFactory<DebPrevDetailBean, String>("num"));
    invTable.getColumns().add(numCol);

    TableColumn dateCol = new TableColumn("");
    dateCol.setPrefWidth(90);
    dateCol.setCellValueFactory(new PropertyValueFactory<DebPrevDetailBean, String>("date"));
    dateCol.setCellFactory(CellDateBox.forTableColumn(dateCol, CellDateBox.DATE_NORMAL_VIEW));
    invTable.getColumns().add(dateCol);

    TableColumn sumCol = new TableColumn("");
    sumCol.setPrefWidth(90);
    sumCol.setCellValueFactory(new PropertyValueFactory<DebPrevDetailBean, String>("sum"));
    sumCol.setCellFactory(CellMoneyBox.forTableColumn(sumCol, " ", 2));
    invTable.getColumns().add(sumCol);
    invTable.autosize();

    invTable.getItems().addListener(new ListChangeListener<DebPrevDetailBean>() {
        @Override
        public void onChanged(ListChangeListener.Change<? extends DebPrevDetailBean> c) {
            double sumDpm = 0;
            for (DebPrevDetailBean bean : c.getList()) {
                sumDpm += bean.getSum();
            }
            sumField.setText(String.format("%.2f ", sumDpm));
            if (sumDpm > 0) {
                saveButon.setDisable(false);
            } else {
                saveButon.setDisable(true);
            }
        }
    });

    TableColumn numVCol = new TableColumn(".");
    numVCol.setPrefWidth(100);
    numVCol.setCellValueFactory(new PropertyValueFactory<DebPrevDetailBean, String>("num"));
    vnaklTable.getColumns().add(numVCol);

    TableColumn dateVCol = new TableColumn("");
    dateVCol.setPrefWidth(90);
    dateVCol.setCellValueFactory(new PropertyValueFactory<DebPrevDetailBean, String>("date"));
    dateVCol.setCellFactory(CellDateBox.forTableColumn(dateVCol, CellDateBox.DATE_NORMAL_VIEW));
    vnaklTable.getColumns().add(dateVCol);

    TableColumn sumVCol = new TableColumn("");
    sumVCol.setPrefWidth(90);
    sumVCol.setCellValueFactory(new PropertyValueFactory<DebPrevDetailBean, String>("sum"));
    sumVCol.setCellFactory(CellMoneyBox.forTableColumn(sumVCol, " ", 2));
    vnaklTable.getColumns().add(sumVCol);
    vnaklTable.autosize();

    TextMaxLengthFieldInstaller mlControl = new TextMaxLengthFieldInstaller();
    mlControl.install(clientField, 150);

    try {

        dateFieldFormatter.setValue(currentDate);
        dateMaxFieldFormatter.setValue(currentDate);
    } catch (Exception ex) {
        Logger.getLogger(FilterController.class.getName()).log(Level.SEVERE, null, ex);
        AlertDialog.showSimpleMessage(" ?    !",
                AlertDialog.ICON_ERROR, parentInterface.getCurrentWindow());
    }

}