javafx.scene.control.TextFormatter Java Examples
The following examples show how to use
javafx.scene.control.TextFormatter.
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: ValidatorUtils.java From kafka-message-tool with MIT License | 7 votes |
public static void configureTextFieldToAcceptOnlyDecimalValues(TextField textField) { DecimalFormat format = new DecimalFormat("#"); final TextFormatter<Object> decimalTextFormatter = new TextFormatter<>(change -> { if (change.getControlNewText().isEmpty()) { return change; } ParsePosition parsePosition = new ParsePosition(0); Object object = format.parse(change.getControlNewText(), parsePosition); if (object == null || parsePosition.getIndex() < change.getControlNewText().length()) { return null; } else { return change; } }); textField.setTextFormatter(decimalTextFormatter); }
Example #2
Source File: ReadViewPresenter.java From mokka7 with Eclipse Public License 1.0 | 6 votes |
private static void addNumericValidation(TextField field) { field.getProperties().put("vkType", "numeric"); field.setTextFormatter(new TextFormatter<>(c -> { if (c.isContentChange()) { if (c.getControlNewText().length() == 0) { return c; } try { Integer.parseInt(c.getControlNewText()); return c; } catch (NumberFormatException e) { } return null; } return c; })); }
Example #3
Source File: ChartViewPresenter.java From mokka7 with Eclipse Public License 1.0 | 6 votes |
private static void addNumericValidation(TextField field) { field.getProperties().put("vkType", "numeric"); field.setTextFormatter(new TextFormatter<>(c -> { if (c.isContentChange()) { if (c.getControlNewText().length() == 0) { return c; } try { Integer.parseInt(c.getControlNewText()); return c; } catch (NumberFormatException e) { } return null; } return c; })); }
Example #4
Source File: Formatters.java From pikatimer with GNU General Public License v3.0 | 5 votes |
public static TextFormatter<Integer> integerFormatter(Boolean negOK) { UnaryOperator<TextFormatter.Change> filter = c -> { String newText = c.getControlNewText() ; if (newText.isEmpty()) { // always allow deleting all characters return c ; } else if (negOK && ! newText.matches("-?\\d*")) { return null; } else if (! newText.matches("\\d+")) {// otherwise, must have all digits: return null ; } return c; }; // Custom string converter to deal with blanks and such StringConverter<Integer> sc = new StringConverter<Integer>() { @Override public String toString(Integer i) { if (i == null) return ""; return i.toString() ; } @Override public Integer fromString(String s) { if (s != null && s.matches("-?\\d+")) { return Integer.valueOf(s); } else { // fall back to what the value used to be // (in case they blanked it out) return 0 ; } } }; return new TextFormatter<>(sc, 0, filter) ; }
Example #5
Source File: MacProtocolView.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Add Mac input field validations */ @Override protected void addInputValidation() { final UnaryOperator<TextFormatter.Change> ipAddressFilter = Util.getTextChangeFormatter(validateAddressRegex()); srcAddress.setTextFormatter(new TextFormatter<>(ipAddressFilter)); dstAddress.setTextFormatter(new TextFormatter<>(ipAddressFilter)); // add format for step and count srcCount.setTextFormatter(Util.getNumberFilter(4)); dstCount.setTextFormatter(Util.getNumberFilter(4)); srcStep.setTextFormatter(Util.getNumberFilter(3)); dstStep.setTextFormatter(Util.getNumberFilter(3)); }
Example #6
Source File: ImportedPacketPropertiesView.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Add input formatter instructions */ private void addInputValidation() { UnaryOperator<TextFormatter.Change> unitFormatter = Util.getTextChangeFormatter(Util.getUnitRegex(false)); srcCountTF.setTextFormatter(new TextFormatter<>(unitFormatter)); dstCountTF.setTextFormatter(new TextFormatter<>(unitFormatter)); countTF.setTextFormatter(Util.getNumberFilter(5)); UnaryOperator<TextFormatter.Change> digitsFormatter = Util.getTextChangeFormatter(digitsRegex()); speedupTF.setTextFormatter(new TextFormatter<>(digitsFormatter)); ipgTF.setTextFormatter(new TextFormatter<>(digitsFormatter)); }
Example #7
Source File: NumberField.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
public void setAllowUnits(final boolean isAllowUnits) { if (isAllowUnits) { setTextFormatter(new TextFormatter<>(new NumberWithUnitsFormatter())); } else { setTextFormatter(new TextFormatter<>(new NumberFormatter())); } }
Example #8
Source File: Util.java From trex-stateless-gui with Apache License 2.0 | 5 votes |
/** * Return textChange formatter * * @param regex * @return */ public static UnaryOperator<TextFormatter.Change> getTextChangeFormatter(String regex) { return c -> { String text = c.getControlNewText(); if (text.matches(regex)) { return c; } else { return null; } }; }
Example #9
Source File: TextManagedMenuItem.java From tcMenu with Apache License 2.0 | 5 votes |
public static void applyIpFormatting(TextField field) { field.setTextFormatter( new TextFormatter<>(c -> { if (c.getControlNewText().isEmpty()) { return c; } return (IPADDRESS.matcher(c.getControlNewText()).matches()) ? c : null; })); }
Example #10
Source File: TextFormatterUtils.java From tcMenu with Apache License 2.0 | 5 votes |
public static void applyIntegerFormatToField(TextField field) { field.setTextFormatter( new TextFormatter<>(c -> { if (c.getControlNewText().isEmpty()) { return c; } return (INTEGER_MATCH.matcher(c.getControlNewText()).matches()) ? c : null; })); }
Example #11
Source File: GuiControllerWorld.java From BlockMap with MIT License | 5 votes |
@Override public void initialize(URL location, ResourceBundle resources) { minHeight.setTextFormatter(new TextFormatter<>(new IntegerStringConverter(), 0)); maxHeight.setTextFormatter(new TextFormatter<>(new IntegerStringConverter(), 255)); EventHandler<ActionEvent> onHeightChange = e -> { if (minHeight.getText().isEmpty()) minHeight.setText("0"); if (maxHeight.getText().isEmpty()) maxHeight.setText("255"); if (new IntegerStringConverter().fromString(minHeight.getText()) > new IntegerStringConverter().fromString(maxHeight.getText())) { String tmp = minHeight.getText(); minHeight.setText(maxHeight.getText()); maxHeight.setText(tmp); } reload(); }; minHeight.setOnAction(onHeightChange); maxHeight.setOnAction(onHeightChange); colorBox.valueProperty().addListener(reloadListener); shadingBox.valueProperty().addListener(reloadListener); dimensionBox.setConverter(new StringConverter<MinecraftDimension>() { @Override public String toString(MinecraftDimension object) { return object.displayName; } @Override public MinecraftDimension fromString(String string) { return null; } }); }
Example #12
Source File: DoubleComponent.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
public DoubleComponent(int inputsize, Double minimum, Double maximum, NumberFormat format) { this.minimum = minimum; this.maximum = maximum; textField = new TextField(); textField.setTextFormatter(new TextFormatter<>(new NumberStringConverter(format))); textField.setPrefWidth(inputsize); // Add an input verifier if any bounds are specified. if (minimum != null || maximum != null) { // textField.setInputVerifier(new MinMaxVerifier()); } getChildren().add(textField); }
Example #13
Source File: SepaForm.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
@Override public void addFormForAddAccount() { gridRowFrom = gridRow + 1; InputTextField holderNameInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.account.owner")); holderNameInputTextField.setValidator(inputValidator); holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { sepaAccount.setHolderName(newValue); updateFromInputs(); }); ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN); ibanInputTextField.setTextFormatter(new TextFormatter<>(new IBANNormalizer())); ibanInputTextField.setValidator(ibanValidator); ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { sepaAccount.setIban(newValue); updateFromInputs(); }); InputTextField bicInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, BIC); bicInputTextField.setValidator(bicValidator); bicInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { sepaAccount.setBic(newValue); updateFromInputs(); }); ComboBox<Country> countryComboBox = addCountrySelection(); setCountryComboBoxAction(countryComboBox, sepaAccount); addEuroCountriesGrid(); addNonEuroCountriesGrid(); addLimitations(false); addAccountNameTextFieldWithAutoFillToggleButton(); countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllSepaCountries())); Country country = CountryUtil.getDefaultCountry(); if (CountryUtil.getAllSepaCountries().contains(country)) { countryComboBox.getSelectionModel().select(country); sepaAccount.setCountry(country); } updateFromInputs(); }
Example #14
Source File: Formatters.java From pikatimer with GNU General Public License v3.0 | 4 votes |
public static TextFormatter<Integer> integerFormatter() { return integerFormatter(false); }
Example #15
Source File: ManualZoomDialog.java From old-mzmine3 with GNU General Public License v2.0 | 4 votes |
@FXML public void initialize() { NumberFormat xAxisFormatter; 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()); }
Example #16
Source File: IntegerEditingCell.java From pikatimer with GNU General Public License v3.0 | 4 votes |
public IntegerEditingCell() { UnaryOperator<TextFormatter.Change> filter = c -> { String newText = c.getControlNewText() ; if (newText.isEmpty()) { // always allow deleting all characters return c ; } else if (negOK && ! newText.matches("-?\\d*")) { return null; } else if (! newText.matches("\\d+")) {// otherwise, must have all digits: return null ; } return c; }; // Custom string converter to deal with blanks and such StringConverter<Integer> sc = new StringConverter<Integer>() { @Override public String toString(Integer i) { if (i == null) return ""; return i.toString() ; } @Override public Integer fromString(String s) { if (s != null && s.matches("-?\\d+")) { return Integer.valueOf(s); } else { // fall back to what the value used to be // (in case they blanked it out) return getItem() ; } } }; textFormatter = new TextFormatter<>(sc, 0, filter) ; textField.setTextFormatter(textFormatter); textField.addEventFilter(KeyEvent.KEY_RELEASED, e -> { if (e.getCode() == KeyCode.ESCAPE) { cancelEdit(); } }); textField.setOnAction(e -> commitEdit(sc.fromString(textField.getText()))); // This may work. I hope... textField.focusedProperty().addListener((e, o, n) -> {if (!n) commitEdit(sc.fromString(textField.getText()));}); textProperty().bind(Bindings .when(emptyProperty()) .then("") .otherwise(itemProperty().asString())); setGraphic(textField); setContentDisplay(ContentDisplay.TEXT_ONLY); }
Example #17
Source File: Controller.java From molecular-music-generator with MIT License | 4 votes |
public void setup(Stage stage) { directoryChooser = new DirectoryChooser(); this.stage = stage; props = new Properties(); TextField[] integerInputs = new TextField[] { timeSigUpper, timeSigLower, octaveLower, octaveUpper, patternLength, patternAmount }; for (TextField integerInput : integerInputs ) { integerInput.setTextFormatter(new TextFormatter<>(integerInputValidator)); } TextField[] floatInputs = new TextField[] { tempoInput, firstNoteLength, secondNoteLength }; for (TextField floatInput : floatInputs ) { floatInput.setTextFormatter(new TextFormatter<>(floatInputValidator)); } scaleInput.setTextFormatter(new TextFormatter<>(noteInputValidator)); tempoSlider.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) { tempoInput.setText(doubleToFixedPrecisionString(newValue.doubleValue())); } }); attachTooltip(tempoInput, "The song tempo in BPM"); attachTooltip(timeSigUpper, "The upper numeral of a time signature (e.g. the \"3\" in \"3/4\")"); attachTooltip(timeSigLower, "The lower numeral of a time signature (e.g. the \"4\" in \"3/4\")"); attachTooltip(firstNoteLength, "The duration (in quarter notes) of the first note"); attachTooltip(secondNoteLength, "The duration (in quarter notes) of the second note"); attachTooltip(scaleInput, "Comma separated list of all notes to use for the patterns. This can be\n" + "changed to any sequence (or length!) of notes you like, meaning you can\n" + "use exotic scales, or dictate the movement by creating a sequence in thirds,\n" + "re-introduce a previously defined note, etc. etc.\n" + "The scale will be repeated over the determined octave range. You can create sharps\n" + "and flats too, e.g.: \"Eb\", \"F#\", etc. are all valid input." ); attachTooltip(octaveLower, "The lowest octave in the note range"); attachTooltip(octaveUpper, "The highest octave in the note range"); attachTooltip(patternLength, "The length of each generated pattern (in measures)"); attachTooltip(patternAmount, "The amount of patterns to generate"); attachTooltip(trackPerPattern, "Whether to separate each pattern into a unique MIDI track.\n" + "When the amount of patterns is high enough for the algorithm\n" + "to go back down the scale, it is best to have this set active\n" + "to avoid conflicts in MIDI notes." ); }
Example #18
Source File: SepaInstantForm.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
@Override public void addFormForAddAccount() { gridRowFrom = gridRow + 1; InputTextField holderNameInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.account.owner")); holderNameInputTextField.setValidator(inputValidator); holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { sepaInstantAccount.setHolderName(newValue); updateFromInputs(); }); ibanInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, IBAN); ibanInputTextField.setTextFormatter(new TextFormatter<>(new IBANNormalizer())); ibanInputTextField.setValidator(ibanValidator); ibanInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { sepaInstantAccount.setIban(newValue); updateFromInputs(); }); InputTextField bicInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, BIC); bicInputTextField.setValidator(bicValidator); bicInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { sepaInstantAccount.setBic(newValue); updateFromInputs(); }); ComboBox<Country> countryComboBox = addCountrySelection(); setCountryComboBoxAction(countryComboBox, sepaInstantAccount); addEuroCountriesGrid(); addNonEuroCountriesGrid(); addLimitations(false); addAccountNameTextFieldWithAutoFillToggleButton(); countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllSepaInstantCountries())); Country country = CountryUtil.getDefaultCountry(); if (CountryUtil.getAllSepaInstantCountries().contains(country)) { countryComboBox.getSelectionModel().select(country); sepaInstantAccount.setCountry(country); } updateFromInputs(); }
Example #19
Source File: DateTimeRangeInputPane.java From constellation with Apache License 2.0 | 4 votes |
/** * Build the hour/minute/second part of the datetime picker. * * @param label * @param min * @param max * @param value * @param changed * @return */ private Pane createSpinner(final String label, final int min, final int max, final ChangeListener<String> changed) { final int NUMBER_SPINNER_WIDTH = 55; final String small = "-fx-font-size: 75%;"; final Spinner<Integer> spinner = new Spinner<>(min, max, 1); spinner.setPrefWidth(NUMBER_SPINNER_WIDTH); // Create a filter to limit text entry to just numerical digits final NumberFormat format = NumberFormat.getIntegerInstance(); final UnaryOperator<TextFormatter.Change> filter = c -> { if (c.isContentChange()) { final ParsePosition parsePosition = new ParsePosition(0); // NumberFormat evaluates the beginning of the text format.parse(c.getControlNewText(), parsePosition); if (parsePosition.getIndex() == 0 || c.getControlNewText().length() > 2 || parsePosition.getIndex() < c.getControlNewText().length()) { // reject parsing the complete text failed return null; } } return c; }; // Ensure spinner is set to editable, meaning user can directly edit text, then hook in // a text formatter which in turn will trigger flitering of input text. spinner.setEditable(true); final TextFormatter<Integer> timeFormatter = new TextFormatter<>(new IntegerStringConverter(), 0, filter); spinner.getEditor().setTextFormatter(timeFormatter); final Label spinnerLabel = new Label(label); spinnerLabel.setLabelFor(spinner); spinnerLabel.setStyle(small); final VBox vbox = new VBox(); vbox.getChildren().addAll(spinnerLabel, spinner); spinner.valueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> { changed.changed(null, null, null); }); timeSpinners.add(spinner); return vbox; }
Example #20
Source File: EthernetProtocolView.java From trex-stateless-gui with Apache License 2.0 | 4 votes |
/** * Add input validation */ @Override protected void addInputValidation() { typeField.setTextFormatter(new TextFormatter<>(Util.getTextChangeFormatter(getHexRegex()))); }
Example #21
Source File: PayloadView.java From trex-stateless-gui with Apache License 2.0 | 4 votes |
/** * Add input validation for pattern */ @Override protected void addInputValidation() { final UnaryOperator<TextFormatter.Change> filter = Util.getTextChangeFormatter(validatePayloadPattern()); pattern.setTextFormatter(new TextFormatter<>(filter)); }
Example #22
Source File: TextFieldValidator.java From AudioBookConverter with GNU General Public License v2.0 | 4 votes |
private TextFormatter.Change validateChange(TextFormatter.Change c) { if (validate(c.getControlNewText())) { return c; } return null; }
Example #23
Source File: TextFieldValidator.java From AudioBookConverter with GNU General Public License v2.0 | 4 votes |
public TextFormatter<Object> getFormatter() { return new TextFormatter<>(this::validateChange); }
Example #24
Source File: AddWaypointDialogController.java From Motion_Profile_Generator with MIT License | 4 votes |
@FXML private void initialize() { txtWX.setTextFormatter( new TextFormatter<>( new DoubleStringConverter() ) ); txtWY.setTextFormatter( new TextFormatter<>( new DoubleStringConverter() ) ); txtWA.setTextFormatter( new TextFormatter<>( new DoubleStringConverter() ) ); }
Example #25
Source File: TextAreaLimited.java From marathonv5 with Apache License 2.0 | 4 votes |
public TextAreaLimited() { setStyle(DEFAULT_STYLE + System.getProperty(Constants.OUTPUT_STYLE, "")); setTextFormatter(new TextFormatter<String>(change -> !change.isContentChange() || internalMod ? change : null)); }
Example #26
Source File: SpatialInformation.java From paintera with GNU General Public License v2.0 | 4 votes |
public SpatialInformation( final double textFieldWidth, final String promptTextX, final String promptTextY, final String promptTextZ, final DoublePredicate checkValues, final Submit checkContents, final Submit... moreCheckContents) { textX.setPrefWidth(textFieldWidth); textY.setPrefWidth(textFieldWidth); textZ.setPrefWidth(textFieldWidth); textX.setPromptText(promptTextX); textY.setPromptText(promptTextY); textZ.setPromptText(promptTextZ); textX.setText(Double.toString(x.doubleValue())); textY.setText(Double.toString(y.doubleValue())); textZ.setText(Double.toString(z.doubleValue())); x.addListener((obs, oldv, newv) -> {if (!checkValues.test(newv.doubleValue())) x.set(oldv.doubleValue());}); y.addListener((obs, oldv, newv) -> {if (!checkValues.test(newv.doubleValue())) y.set(oldv.doubleValue());}); z.addListener((obs, oldv, newv) -> {if (!checkValues.test(newv.doubleValue())) z.set(oldv.doubleValue());}); final Set<Submit> checkSet = new HashSet<>(Arrays.asList(moreCheckContents)); checkSet.add(checkContents); for (Submit check : checkSet) { switch (check) { case WHILE_TYPING: textX.setTextFormatter(new TextFormatter<>(new DoubleFilter())); textY.setTextFormatter(new TextFormatter<>(new DoubleFilter())); textZ.setTextFormatter(new TextFormatter<>(new DoubleFilter())); textX.textProperty().bindBidirectional(x, new Converter()); textY.textProperty().bindBidirectional(y, new Converter()); textZ.textProperty().bindBidirectional(z, new Converter()); break; case ON_ENTER: textX.addEventFilter(KeyEvent.KEY_PRESSED, event -> submitOnKeyPressed(textX.textProperty(), x, event, KeyCode.ENTER)); textY.addEventFilter(KeyEvent.KEY_PRESSED, event -> submitOnKeyPressed(textY.textProperty(), y, event, KeyCode.ENTER)); textZ.addEventFilter(KeyEvent.KEY_PRESSED, event -> submitOnKeyPressed(textZ.textProperty(), z, event, KeyCode.ENTER)); x.addListener((obs, oldv, newv) -> textX.setText(Double.toString(newv.doubleValue()))); y.addListener((obs, oldv, newv) -> textY.setText(Double.toString(newv.doubleValue()))); z.addListener((obs, oldv, newv) -> textZ.setText(Double.toString(newv.doubleValue()))); break; case ON_FOCUS_LOST: textX.focusedProperty().addListener((obs, oldv, newv) -> submitOnFocusLost(textX.textProperty(), x, newv)); textY.focusedProperty().addListener((obs, oldv, newv) -> submitOnFocusLost(textY.textProperty(), y, newv)); textZ.focusedProperty().addListener((obs, oldv, newv) -> submitOnFocusLost(textZ.textProperty(), z, newv)); x.addListener((obs, oldv, newv) -> textX.setText(Double.toString(newv.doubleValue()))); y.addListener((obs, oldv, newv) -> textY.setText(Double.toString(newv.doubleValue()))); z.addListener((obs, oldv, newv) -> textZ.setText(Double.toString(newv.doubleValue()))); } } }
Example #27
Source File: NetProtocolSettingFrame.java From oim-fx with MIT License | 4 votes |
private void initComponent() { this.setWidth(520); this.setHeight(120); this.setResizable(false); this.setTitlePaneStyle(2); this.setRadius(5); this.setCenter(rootPane); this.setTitle("服务器地址设置"); titleLabel.setText("服务器地址设置"); titleLabel.setFont(Font.font("微软雅黑", 14)); titleLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1)"); topBox.setStyle("-fx-background-color:#2cb1e0"); topBox.setPrefHeight(35); topBox.setPadding(new Insets(5, 10, 5, 10)); topBox.setSpacing(10); topBox.getChildren().add(titleLabel); Label addressLabel = new Label("服务器地址:"); addressField.setPromptText("服务器地址"); addressLabel.setPrefSize(75, 25); addressLabel.setLayoutX(10); addressLabel.setLayoutY(5); addressField.setPrefSize(250, 25); addressField.setLayoutX(addressLabel.getLayoutX() + addressLabel.getPrefWidth() + 10); addressField.setLayoutY(addressLabel.getLayoutY()); portField.setPromptText("端口"); Label partLabel = new Label("端口:"); partLabel.setPrefSize(40, 25); partLabel.setLayoutX(355); partLabel.setLayoutY(5); portField.setPrefSize(80, 25); portField.setLayoutX(partLabel.getLayoutX() + partLabel.getPrefWidth() + 10); portField.setLayoutY(partLabel.getLayoutY()); AnchorPane infoPane = new AnchorPane(); infoPane.setStyle("-fx-background-color:#ffffff"); infoPane.getChildren().add(addressLabel); infoPane.getChildren().add(addressField); infoPane.getChildren().add(partLabel); infoPane.getChildren().add(portField); cancelButton.setText("取消"); cancelButton.setPrefWidth(80); button.setText("确定"); button.setPrefWidth(80); bottomBox.setStyle("-fx-background-color:#c9e1e9"); bottomBox.setAlignment(Pos.BASELINE_RIGHT); bottomBox.setPadding(new Insets(5, 10, 5, 10)); bottomBox.setSpacing(10); bottomBox.getChildren().add(button); bottomBox.getChildren().add(cancelButton); rootPane.setTop(topBox); rootPane.setCenter(infoPane); rootPane.setBottom(bottomBox); Pattern pattern = Pattern.compile("0|(-?([1-9]\\d*)?)"); ; TextFormatter<Integer> formatter = new TextFormatter<Integer>(new StringConverter<Integer>() { @Override public String toString(Integer value) { return null != value ? value.toString() : "0"; } @Override public Integer fromString(String text) { int i = 0; if (null != text) { Matcher matcher = pattern.matcher(text); if (matcher.matches()) { i = Integer.parseInt(text); } } return i; } }); portField.setTextFormatter(formatter); }
Example #28
Source File: ProductIonFilterSetHighlightDialog.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
public ProductIonFilterSetHighlightDialog(@Nonnull Stage parent, ProductIonFilterPlot plot, String command) { this.desktop = MZmineCore.getDesktop(); this.plot = plot; this.rangeType = command; mainPane = new DialogPane(); mainScene = new Scene(mainPane); mainScene.getStylesheets() .addAll(MZmineCore.getDesktop().getMainWindow().getScene().getStylesheets()); setScene(mainScene); initOwner(parent); String title = "Highlight "; if (command.equals("HIGHLIGHT_PRECURSOR")) { title += "precursor m/z range"; axis = plot.getXYPlot().getDomainAxis(); } else if (command.equals("HIGHLIGHT_NEUTRALLOSS")) { title += "neutral loss m/z range"; axis = plot.getXYPlot().getRangeAxis(); } setTitle(title); Label lblMinMZ = new Label("Minimum m/z"); Label lblMaxMZ = new Label("Maximum m/z"); NumberStringConverter converter = new NumberStringConverter(); fieldMinMZ = new TextField(); fieldMinMZ.setTextFormatter(new TextFormatter<>(converter)); fieldMaxMZ = new TextField(); fieldMaxMZ.setTextFormatter(new TextFormatter<>(converter)); pnlLabelsAndFields = new GridPane(); pnlLabelsAndFields.setHgap(5); pnlLabelsAndFields.setVgap(10); int row = 0; pnlLabelsAndFields.add(lblMinMZ, 0, row); pnlLabelsAndFields.add(fieldMinMZ, 1, row); row++; pnlLabelsAndFields.add(lblMaxMZ, 0, row); pnlLabelsAndFields.add(fieldMaxMZ, 1, row); // Create buttons mainPane.getButtonTypes().add(ButtonType.OK); mainPane.getButtonTypes().add(ButtonType.CANCEL); btnOK = (Button) mainPane.lookupButton(ButtonType.OK); btnOK.setOnAction(e -> { if (highlightDataPoints()) { hide(); } }); btnCancel = (Button) mainPane.lookupButton(ButtonType.CANCEL); btnCancel.setOnAction(e -> hide()); mainPane.setContent(pnlLabelsAndFields); sizeToScene(); centerOnScreen(); setResizable(false); }
Example #29
Source File: CombinedModuleSetHighlightDialog.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
public CombinedModuleSetHighlightDialog(@Nonnull Stage parent, @Nonnull CombinedModulePlot plot, @Nonnull String command) { desktop = MZmineCore.getDesktop(); this.plot = plot; rangeType = command; mainPane = new DialogPane(); mainScene = new Scene(mainPane); // Use main CSS mainScene.getStylesheets() .addAll(MZmineCore.getDesktop().getMainWindow().getScene().getStylesheets()); setScene(mainScene); initOwner(parent); String title = "Highlight "; if (command.equals("HIGHLIGHT_PRECURSOR")) { title += "precursor m/z range"; axis = plot.getXYPlot().getDomainAxis(); } else if (command.equals("HIGHLIGHT_NEUTRALLOSS")) { title += "neutral loss m/z range"; axis = plot.getXYPlot().getRangeAxis(); } setTitle(title); Label lblMinMZ = new Label("Minimum m/z"); Label lblMaxMZ = new Label("Maximum m/z"); NumberStringConverter converter = new NumberStringConverter(); fieldMinMZ = new TextField(); fieldMinMZ.setTextFormatter(new TextFormatter<>(converter)); fieldMaxMZ = new TextField(); fieldMaxMZ.setTextFormatter(new TextFormatter<>(converter)); pnlLabelsAndFields = new GridPane(); pnlLabelsAndFields.setHgap(5); pnlLabelsAndFields.setVgap(10); int row = 0; pnlLabelsAndFields.add(lblMinMZ, 0, row); pnlLabelsAndFields.add(fieldMinMZ, 1, row); row++; pnlLabelsAndFields.add(lblMaxMZ, 0, row); pnlLabelsAndFields.add(fieldMaxMZ, 1, row); // Create buttons mainPane.getButtonTypes().add(ButtonType.OK); mainPane.getButtonTypes().add(ButtonType.CANCEL); btnOK = (Button) mainPane.lookupButton(ButtonType.OK); btnOK.setOnAction(e -> { if (highlightDataPoints()) { hide(); } }); btnCancel = (Button) mainPane.lookupButton(ButtonType.CANCEL); btnCancel.setOnAction(e -> hide()); mainPane.setContent(pnlLabelsAndFields); sizeToScene(); centerOnScreen(); setResizable(false); }
Example #30
Source File: DoubleRangeComponent.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
public void setNumberFormat(NumberFormat format) { this.format = format; this.formatConverter = new NumberStringConverter(format); minTxtField.setTextFormatter(new TextFormatter<Number>(formatConverter)); maxTxtField.setTextFormatter(new TextFormatter<Number>(formatConverter)); }