javafx.util.converter.IntegerStringConverter Java Examples

The following examples show how to use javafx.util.converter.IntegerStringConverter. 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: GuiControllerWorld.java    From BlockMap with MIT License 5 votes vote down vote up
@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 #2
Source File: GuiControllerWorld.java    From BlockMap with MIT License 5 votes vote down vote up
public void reload() {
	if (worldPath == null) {
		folder.set(null);
		return;
	}
	try {
		settings = new RenderSettings(
				Integer.MIN_VALUE,
				Integer.MAX_VALUE,
				new IntegerStringConverter().fromString(minHeight.getText()),
				new IntegerStringConverter().fromString(maxHeight.getText()),
				Integer.MIN_VALUE,
				Integer.MAX_VALUE,
				InternalColorMap.values()[colorBox.getSelectionModel().getSelectedIndex()].getColorMap(),
				BiomeColorMap.loadDefault(),
				RegionShader.DEFAULT_SHADERS[shadingBox.getSelectionModel().getSelectedIndex()]);
		RegionRenderer renderer = new RegionRenderer(settings);
		folder.set(new Pair<>(
				Integer.toHexString(Objects.hash(worldPath.toAbsolutePath().toString(), settings, dimensionBox.getValue())),
				WorldRegionFolder.load(worldPath,
						dimensionBox.getValue(), renderer, true)));
	} catch (RuntimeException | IOException e) {
		folder.set(null);
		log.warn("Could not load world " + worldPath, e);
		ExceptionDialog d = new ExceptionDialog(e);
		d.setTitle("Could not load world");
		d.showAndWait();
	}
}
 
Example #3
Source File: SimpleIntegerControl.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
@Override
public String toString(Integer object) {
  try {
    return new IntegerStringConverter().toString(object);
  } catch (NumberFormatException ex) {
    return "0";
  }
}
 
Example #4
Source File: SimpleIntegerControl.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
@Override
public Integer fromString(String string) {
  try {
    return new IntegerStringConverter().fromString(string);
  } catch (NumberFormatException ex) {
    return 0;
  }
}
 
Example #5
Source File: DateTimeRangeInputPane.java    From constellation with Apache License 2.0 4 votes vote down vote up
/**
 * 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 #6
Source File: TitleDetailDelayTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
public DelayTableCell()
{
    super(new IntegerStringConverter());
}