private void setFormConstraints(Node field) { if (field instanceof ISetConstraints) { ((ISetConstraints) field).setFormConstraints(this); } else if (field instanceof Button) { _setFormConstraints((Button) field); } else if (field instanceof TextField) { _setFormConstraints((TextField) field); } else if (field instanceof TextArea) { _setFormConstraints((TextArea) field); } else if (field instanceof ComboBox<?>) { _setFormConstraints((ComboBox<?>) field); } else if (field instanceof ChoiceBox<?>) { _setFormConstraints((ChoiceBox<?>) field); } else if (field instanceof CheckBox) { _setFormConstraints((CheckBox) field); } else if (field instanceof Spinner<?>) { _setFormConstraints((Spinner<?>) field); } else if (field instanceof VBox) { _setFormConstraints((VBox) field); } else if (field instanceof Label) { _setFormConstraints((Label) field); } else { LOGGER.info("FormPane.setFormConstraints(): unknown field type: " + field.getClass().getName()); } }
@SuppressWarnings("unchecked") @Override public boolean marathon_select(String value) { Spinner<?> spinner = (Spinner<?>) getComponent(); if (!spinner.isEditable()) { @SuppressWarnings("rawtypes") SpinnerValueFactory factory = ((Spinner<?>) getComponent()).getValueFactory(); Object convertedValue = factory.getConverter().fromString(value); factory.setValue(convertedValue); return true; } TextField spinnerEditor = spinner.getEditor(); if (spinnerEditor == null) { throw new JavaAgentException("Null value returned by getEditor() on spinner", null); } IJavaFXElement ele = JavaFXElementFactory.createElement(spinnerEditor, driver, window); spinnerEditor.getProperties().put("marathon.celleditor", true); ele.marathon_select(value); return true; }
private Spinner<Object> createListSpinner() { Spinner<Object> spinner = new Spinner<>(); spinner.setId("list-spinner"); List<Object> names = new ArrayList<Object>(); names.add("January"); names.add("February"); names.add("March"); names.add("April"); names.add("May"); names.add("June"); names.add("July"); names.add("August"); names.add("September"); names.add("October"); names.add("November"); names.add("December"); spinner.setValueFactory(new SpinnerValueFactory.ListSpinnerValueFactory<Object>(FXCollections.observableArrayList(names))); return spinner; }
@Test public void getText() { Spinner<?> spinner = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup(".spinner"); LoggingRecorder lr = new LoggingRecorder(); List<String> text = new ArrayList<>(); Platform.runLater(() -> { RFXSpinner rfxSpinner = new RFXSpinner(spinner, null, null, lr); spinner.getEditor().setText("March"); rfxSpinner.focusLost(null); text.add(rfxSpinner.getAttribute("text")); }); new Wait("Waiting for spinner text.") { @Override public boolean until() { return text.size() > 0; } }; AssertJUnit.assertEquals("March", text.get(0)); }
public static void initializeSpinner(final Spinner<Integer> spinner, final int minValue, final int maxValue, final int initialValue) { spinner.getEditor().setOnKeyPressed(event -> { switch (event.getCode()) { case UP: spinner.increment(1); break; case DOWN: spinner.decrement(1); break; } }); spinner.setOnScroll(e -> { spinner.increment((int) (e.getDeltaY() / e.getMultiplierY())); }); SpinnerValueFactory<Integer> factory = new SpinnerValueFactory.IntegerSpinnerValueFactory(minValue, maxValue, initialValue); spinner.setValueFactory(factory); spinner.setEditable(true); TextFormatter<Integer> formatter = new TextFormatter<>(factory.getConverter(), factory.getValue()); spinner.getEditor().setTextFormatter(formatter); factory.valueProperty().bindBidirectional(formatter.valueProperty()); }
private void commitEditorText(Spinner<T> spinner) { if (!spinner.isEditable()) return; try { String text = spinner.getEditor().getText(); SpinnerValueFactory<T> valueFactory = spinner.getValueFactory(); if (valueFactory != null) { StringConverter<T> converter = valueFactory.getConverter(); if (converter != null) { T value = converter.fromString(text); if (value == null) return; valueFactory.setValue(value); } } } catch (NumberFormatException e) { // Ignore text input. return; } }
private Spinner<Integer> createZoomSpinner(ToggleButton btnZoom, String ip) { Spinner<Integer> spinnerZoom = new Spinner<>(googleMinZoomLevel, googleMaxZoomLevel, googleDefaultZoomLevel, googleZoomLevelStep); spinnerZoom.setPrefWidth(55); spinnerZoom.setPrefHeight(btnZoom.getHeight()); spinnerZoom.valueProperty().addListener((ChangeListener<Integer>) (observable, oldValue, newValue) -> { imgService.setCenterOnIP(ip, newValue); labelUnderMap.setVisible(true); generateAndShowImage(); }); Tooltip spinnerTooltip = new Tooltip("Set zoom level (1-20)"); ToolTipUtilities.setTooltipProperties(spinnerTooltip, true, GUIController.defaultTooltipMaxWidth, GUIController.defaultFontSize, null); spinnerZoom.setTooltip(spinnerTooltip); spinnerZoom.getEditor().setTooltip(spinnerTooltip); spinnerZoom.setEditable(false); spinnerZoom.setDisable(true); return spinnerZoom; }
public SpinnerTableCell(TableColumn<T, Integer> column, int min, int max) { spinner = new Spinner<>(min, max, 1); spinner.editableProperty().bind(column.editableProperty()); spinner.disableProperty().bind(column.editableProperty().not()); tableRowProperty().addListener(e -> { TableRow<?> row = getTableRow(); if (row == null) return; MsSpectrumDataSet dataSet = (MsSpectrumDataSet) row.getItem(); if (dataSet == null) return; spinner.getValueFactory().valueProperty().bindBidirectional(dataSet.lineThicknessProperty()); disableProperty().bind(dataSet.renderingTypeProperty().isEqualTo(MsSpectrumType.CENTROIDED)); }); }
public SpinnerTableCell(TableColumn<T, Integer> column, int min, int max) { spinner = new Spinner<>(min, max, 1); spinner.editableProperty().bind(column.editableProperty()); spinner.disableProperty().bind(column.editableProperty().not()); tableRowProperty().addListener(e -> { TableRow<?> row = getTableRow(); if (row == null) return; ChromatogramPlotDataSet dataSet = (ChromatogramPlotDataSet) row.getItem(); if (dataSet == null) return; spinner.getValueFactory().valueProperty().bindBidirectional(dataSet.lineThicknessProperty()); }); }
@FXML @Override public void initialize() { super.initialize(); final Spinner<List> spinner = new Spinner<>(this.valueFactory); spinner.setEditable(true); spinner.disableProperty().bind(this.getHandle().connectedProperty()); spinner.focusedProperty().addListener((s, ov, nv) -> { // Code found at http://stackoverflow.com/questions/32340476/manually-typing-in-text-in-javafx-spinner-is-not-updating-the-value-unless-user if (nv) { return; } commitEditorText(spinner); }); this.setContent(spinner); }
public static void reset() { add(Node.class, JavaFXElement.class); add(TextInputControl.class, JavaFXTextInputControlElement.class); add(HTMLEditor.class, JavaFXHTMLEditor.class); add(CheckBox.class, JavaFXCheckBoxElement.class); add(ToggleButton.class, JavaFXToggleButtonElement.class); add(Slider.class, JavaFXSliderElement.class); add(Spinner.class, JavaFXSpinnerElement.class); add(SplitPane.class, JavaFXSplitPaneElement.class); add(ProgressBar.class, JavaFXProgressBarElement.class); add(ChoiceBox.class, JavaFXChoiceBoxElement.class); add(ColorPicker.class, JavaFXColorPickerElement.class); add(ComboBox.class, JavaFXComboBoxElement.class); add(DatePicker.class, JavaFXDatePickerElement.class); add(TabPane.class, JavaFXTabPaneElement.class); add(ListView.class, JavaFXListViewElement.class); add(TreeView.class, JavaFXTreeViewElement.class); add(TableView.class, JavaFXTableViewElement.class); add(TreeTableView.class, JavaFXTreeTableViewElement.class); add(CheckBoxListCell.class, JavaFXCheckBoxListCellElement.class); add(ChoiceBoxListCell.class, JavaFXChoiceBoxListCellElement.class); add(ComboBoxListCell.class, JavaFXComboBoxListCellElemnt.class); add(CheckBoxTreeCell.class, JavaFXCheckBoxTreeCellElement.class); add(ChoiceBoxTreeCell.class, JavaFXChoiceBoxTreeCellElement.class); add(ComboBoxTreeCell.class, JavaFXComboBoxTreeCellElement.class); add(TableCell.class, JavaFXTableViewCellElement.class); add(CheckBoxTableCell.class, JavaFXCheckBoxTableCellElement.class); add(ChoiceBoxTableCell.class, JavaFXChoiceBoxTableCellElement.class); add(ComboBoxTableCell.class, JavaFXComboBoxTableCellElemnt.class); add(TreeTableCell.class, JavaFXTreeTableCellElement.class); add(CheckBoxTreeTableCell.class, JavaFXCheckBoxTreeTableCell.class); add(ChoiceBoxTreeTableCell.class, JavaFXChoiceBoxTreeTableCell.class); add(ComboBoxTreeTableCell.class, JavaFXComboBoxTreeTableCell.class); }
@Test public void selectListSpinner() { IJavaFXElement spinner = driver.findElementByName("list-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#list-spinner"); Platform.runLater(() -> { spinner.marathon_select("June"); }); new Wait("Waiting for spinner to set value") { @Override public boolean until() { Object value = spinnerNode.getValue(); return value.toString().equals("June"); } }; }
@Test public void selectEditableListSpinner() { IJavaFXElement spinner = driver.findElementByName("list-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#list-spinner"); Platform.runLater(() -> { spinnerNode.setEditable(true); spinner.marathon_select("December"); }); new Wait("Waiting for spinner to set value") { @Override public boolean until() { Object value = spinnerNode.getValue(); return value.toString().equals("December"); } }; }
@Test public void listSpinnerWithInvalidValue() { IJavaFXElement spinner = driver.findElementByName("list-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#list-spinner"); Platform.runLater(() -> { spinnerNode.setEditable(true); spinner.marathon_select("Decem"); }); new Wait("Spinner was not reset.") { @Override public boolean until() { Object value = spinnerNode.getValue(); return value.toString().equals("January"); } }; }
@Test public void selectIntegerSpinner() { IJavaFXElement spinner = driver.findElementByName("integer-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#integer-spinner"); Platform.runLater(() -> { spinner.marathon_select("35"); }); new Wait("Waiting for spinner to set value") { @Override public boolean until() { Integer value = (Integer) spinnerNode.getValue(); return value == 35; } }; }
@Test public void selectEditableIntegerSpinner() { IJavaFXElement spinner = driver.findElementByName("integer-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#integer-spinner"); Platform.runLater(() -> { spinner.marathon_select("45"); }); new Wait("Waiting for spinner to set value") { @Override public boolean until() { Integer value = (Integer) spinnerNode.getValue(); return value == 45; } }; }
@Test public void selectDoubleSpinner() { IJavaFXElement spinner = driver.findElementByName("double-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#double-spinner"); Platform.runLater(() -> { spinnerNode.setEditable(false); spinner.marathon_select("38.9"); }); new Wait("Waiting for spinner to set value") { @Override public boolean until() { Double value = (Double) spinnerNode.getValue(); return value == 38.9; } }; }
@Test public void selectEditableDoubleSpinner() { IJavaFXElement spinner = driver.findElementByName("double-spinner"); Spinner<?> spinnerNode = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#double-spinner"); Platform.runLater(() -> { spinner.marathon_select("49.0"); }); new Wait("Waiting for spinner to set value") { @Override public boolean until() { Double value = (Double) spinnerNode.getValue(); return value == 49.0; } }; }
public SpinnerSample() { Spinner<Object> listSpinner = createListSpinner(); Spinner<Integer> integerSpinner = createIntegerSpinner(); Spinner<Double> doubleSpinner = createDoubleSpinner(); HBox hBox = new HBox(); hBox.setSpacing(20.0); hBox.getChildren().addAll(listSpinner, integerSpinner, doubleSpinner); getChildren().add(hBox); }
private Spinner<Double> createDoubleSpinner() { Spinner<Double> spinner = new Spinner<Double>(); spinner.setId("double-spinner"); spinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(25.50, 50.50)); spinner.setEditable(true); return spinner; }
@Override public void focusLost(RFXComponent next) { Spinner<?> spinner = (Spinner<?>) node; String currentValue = getSpinnerText(spinner); if (!currentValue.equals(oldValue)) { recorder.recordSelect(this, currentValue); } }
@Test public void selectListSpinner() { Spinner<?> spinner = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup(".spinner"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXSpinner rfxSpinner = new RFXSpinner(spinner, null, null, lr); spinner.getEditor().setText("March"); rfxSpinner.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("March", recording.getParameters()[0]); }
@Test public void selectListEditableSpinner() { Spinner<?> spinner = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup(".spinner"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { spinner.setEditable(true); RFXSpinner rfxSpinner = new RFXSpinner(spinner, null, null, lr); spinner.getEditor().setText("April"); rfxSpinner.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("April", recording.getParameters()[0]); }
@Test public void selectIntegerSpinner() { Spinner<?> spinner = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#integer-spinner"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXSpinner rfxSpinner = new RFXSpinner(spinner, null, null, lr); spinner.getEditor().setText("25"); rfxSpinner.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("25", recording.getParameters()[0]); }
@Test public void selectDoubleSpinner() { Spinner<?> spinner = (Spinner<?>) getPrimaryStage().getScene().getRoot().lookup("#double-spinner"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { RFXSpinner rfxSpinner = new RFXSpinner(spinner, null, null, lr); spinner.getEditor().setText("35.5"); rfxSpinner.focusLost(null); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("35.5", recording.getParameters()[0]); }
public OverclockingPaneTemplate(boolean showReset) { super(); super.getStyleClass().add("hbox"); //super.setPadding(new Insets(10,10,10,10)); super.setPadding(new Insets(10,10,0,10)); super.setVgap(5); super.setHgap(30); currentValueLabel = new Label(); minValueLabel = new Label(); maxValueLabel = new Label(); currentValueSpinner = new Spinner<>(); currentMinValue = new Label(); currentMaxValue = new Label(); apply = new Button("Apply"); apply.setPrefWidth(100); if(showReset) { reset = new Button("Reset"); reset.setPrefWidth(100); } currentValueSpinner.setPrefWidth(85); super.add(currentValueLabel, 0, 0); super.add(minValueLabel, 1, 0); super.add(maxValueLabel, 2, 0); super.add(apply, 3, 0); super.add(currentValueSpinner, 0, 1); super.add(currentMinValue, 1, 1); super.add(currentMaxValue, 2, 1); if(showReset) super.add(reset, 3, 1); }
public static void fixIntegerSpinner(Spinner<Integer> spinner) { spinner.getEditor().textProperty().addListener((_ob, _old, _new) -> { try { int value = Integer.parseInt(_new); spinner.getValueFactory().setValue(value); } catch (NumberFormatException e) { // nothing } }); }
public void setSpinnerValueFactory(final Spinner _spinner, final String _newValue) { ObservableList<String> items = FXCollections.observableArrayList("Jonathan", "Julia", "Henry"); switch (_newValue) { case "Integer": { _spinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(5, 10)); break; } case "List<String>": { _spinner.setValueFactory(new SpinnerValueFactory.ListSpinnerValueFactory<>(items)); break; } /* postponed. see https://javafx-jira.kenai.com/browse/RT-37968 case "Calendar": { _spinner.setValueFactory(new SpinnerValueFactory.LocalDateSpinnerValueFactory()); break; } */ case "Double": { _spinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 1.0, 0.5, 0.05)); break; } default: { _spinner.setValueFactory(null); break; } } }
public static void retrieveSpinnerValues(final Wrap<? extends Spinner> _spinner) { new GetAction() { @Override public void run(Object... os) throws Exception { final Spinner spinner = (Spinner)_spinner.getControl(); spinnerPropertyValue = spinner.getValue().toString(); spinnerEditorValue = spinner.getEditor().textProperty().get(); System.out.println("retrieved values:" + spinnerPropertyValue + " / " + spinnerEditorValue); } }.dispatch(Root.ROOT.getEnvironment()); }
public DoubleControl(Options o, DoubleSetting setting) { setSpacing(3); // Option Name Label title = new Label(setting.getHumanName()); title.setFont(new Font(20)); title.getStyleClass().add("title"); getChildren().add(title); // Option Desc if (!setting.getDescription().equals("")) { Label desc = new Label(setting.getDescription()); desc.getStyleClass().add("description"); desc.setFont(new Font(14)); desc.setWrapText(true); getChildren().add(desc); } // Option Value Spinner<Double> value = new Spinner<>(); DoubleSpinnerValueFactory factory = new DoubleSpinnerValueFactory(0, 0); factory.setMax(setting.getHighBound()); factory.setMin(setting.getLowBound()); factory.setValue(setting.getValue()); double step = (setting.getHighBound() - setting.getLowBound()) / 1000; factory.setAmountToStepBy(step <= 20 ? step : 20); value.setValueFactory(factory); value.setEditable(true); value.getStyleClass().add("value"); value.setPrefWidth(Double.MAX_VALUE); value.valueProperty().addListener(e -> { if (setting.isValid(value.getValue())) { o.madeChanges(); setting.setValue(value.getValue()); } else value.getValueFactory().setValue(setting.getValue()); }); getChildren().add(value); }
private void setUpSpinnerInt(Spinner<Integer> spinner, int pos, int min, int max, int increment, int savedSet ){ IntegerSpinnerValueFactory oswFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(min, max, savedSet, increment); spinner.setValueFactory(oswFactory); spinner.valueProperty().addListener((obs, oldValue, newValue) -> { System.out.println("New value: "+newValue); // hier könnte es rundungsfehler von double auf Number geben setValueSettings(pos, newValue); }); }
private void setUpSpinnerDouble(Spinner<Double> spinner, int pos, double min, double max, double increment, double savedSet){ DoubleSpinnerValueFactory oswFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(min, max, savedSet, increment); spinner.setValueFactory(oswFactory); spinner.valueProperty().addListener((obs, oldValue, newValue) -> { System.out.println("New value: "+newValue); // hier könnte es rundungsfehler von double auf Number geben setValueSettings(pos, newValue); }); }
protected Spinner<Integer> createSpinner(final String label, final int min, final int max, final int init) { final Spinner<Integer> sp = new Spinner<>(min, max, init); sp.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); GridPane.setFillWidth(sp, true); controls.add(new Text(label + ":"), 0, nRows); controls.add(sp, 1, nRows); nRows++; return sp; }
/** * Create a grid of sliders and spinners not unlike the aspectSelector * @param parameterSetter The function to execute when the parameters change * @return the full formatted Region */ @SuppressWarnings("unchecked") protected Region buildParameterSelector(Procedure parameterSetter) { currentParams = new double[4]; paramLabels = new Label[4]; paramSliders = new Slider[4]; // I don't think any projection has more than four parameters final Spinner<Double> spin0 = new Spinner<Double>(0.,0.,0.); //yes, this is awkward. Java gets weird about arrays with generic types paramSpinners = (Spinner<Double>[])Array.newInstance(spin0.getClass(), 4); paramSpinners[0] = spin0; for (int i = 0; i < 4; i ++) { paramLabels[i] = new Label(); paramSliders[i] = new Slider(); if (i != 0) paramSpinners[i] = new Spinner<Double>(0.,0.,0.); link(paramSliders[i], paramSpinners[i], i, currentParams, (d)->d, parameterSetter, isChanging, suppressListeners); } for (int i = 0; i < 4; i ++) { GridPane.setHgrow(paramSliders[i], Priority.ALWAYS); paramSpinners[i].setEditable(true); } paramGrid = new GridPane(); paramGrid.setVgap(V_SPACE); paramGrid.setHgap(H_SPACE); paramGrid.getColumnConstraints().addAll( new ColumnConstraints(SPINNER_WIDTH,Control.USE_COMPUTED_SIZE,Control.USE_COMPUTED_SIZE), new ColumnConstraints(), new ColumnConstraints(SPINNER_WIDTH)); return paramGrid; }
/** * Create a block of niche options - specifically International Dateline cropping and whether * there should be a graticule * @param cropAtIDL The mutable boolean value to which to bind the "Crop at Dateline" CheckBox * @param graticule The mutable double value to which to bind the "Graticule" Spinner * @return the full formatted Region */ protected Region buildOptionPane(Flag cropAtIDL, MutableDouble graticule) { final CheckBox cropBox = new CheckBox("Crop at International Dateline"); //the CheckBox for whether there should be shown imagery outside the International Dateline cropBox.setSelected(cropAtIDL.isSet()); cropBox.setTooltip(new Tooltip("Show every point exactly once.")); cropBox.selectedProperty().addListener((observable, old, now) -> { cropAtIDL.set(now); }); final ObservableList<Double> factorsOf90 = FXCollections.observableArrayList(); for (double f = 1; f <= 90; f += 0.5) if (90%f == 0) factorsOf90.add((double)f); final Spinner<Double> gratSpinner = new Spinner<Double>(factorsOf90); //spinner for the graticule value gratSpinner.getValueFactory().setConverter(new DoubleStringConverter()); gratSpinner.getValueFactory().setValue(graticule.get()); gratSpinner.setDisable(graticule.isZero()); gratSpinner.setEditable(true); gratSpinner.setTooltip(new Tooltip("The spacing in degrees between shown parallels and meridians.")); gratSpinner.setPrefWidth(SPINNER_WIDTH); gratSpinner.valueProperty().addListener((observable, old, now) -> { graticule.set(now); //which is tied to the mutable graticule spacing variable }); final CheckBox gratBox = new CheckBox("Graticule: "); //the CheckBox for whether there should be a graticule gratBox.setSelected(!graticule.isZero()); gratBox.setTooltip(new Tooltip("Overlay a mesh of parallels and meridians.")); gratBox.selectedProperty().addListener((observable, old, now) -> { if (now) graticule.set(gratSpinner.getValue()); //set the value of graticule appropriately when checked else graticule.set(0); //when not checked, represent "no graticule" as a spacing of 0 gratSpinner.setDisable(!now); //disable the graticule Spinner when appropriate }); final HBox gratRow = new HBox(H_SPACE, gratBox, gratSpinner); gratRow.setAlignment(Pos.CENTER_LEFT); return new VBox(V_SPACE, cropBox, gratRow); }
private void setAspectByPreset(String presetName, Slider[] sliders, Spinner<Double>[] spinners) { this.suppressListeners.set(); if (presetName.equals("Antipode")) { sliders[0].setValue(-sliders[0].getValue()); sliders[1].setValue((sliders[1].getValue()+360)%360-180); sliders[2].setValue(-sliders[2].getValue()); } else if (presetName.equals("Random")) { sliders[0].setValue(Math.toDegrees(Math.asin(Math.random()*2-1))); sliders[1].setValue(Math.random()*360-180); sliders[2].setValue(Math.random()*360-180); } else { for (int i = 0; i < ASPECT_NAMES.length; i ++) { if (ASPECT_NAMES[i].equals(presetName)) { for (int j = 0; j < 3; j ++) sliders[j].setValue(ASPECT_VALS[j][i]); break; } } } for (int i = 0; i < 3; i ++) spinners[i].getEditor().textProperty().set( Double.toString(sliders[i].getValue())); this.suppressListeners.clear(); }
private static void link(Slider sld, Spinner<Double> spn, int i, double[] doubles, DoubleUnaryOperator converter, Procedure callback, Flag isChanging, Flag suppressListeners) { sld.valueChangingProperty().addListener((observable, prev, now) -> { //link spinner to slider isChanging.set(now); if (!now) { if (spn.getValue() != sld.getValue()) spn.getValueFactory().setValue(sld.getValue()); doubles[i] = converter.applyAsDouble(Math2.round(sld.getValue(),3)); if (!suppressListeners.isSet()) callback.execute(); } }); sld.valueProperty().addListener((observable, prev, now) -> { if (spn.getValue() != sld.getValue()) spn.getValueFactory().setValue(sld.getValue()); doubles[i] = converter.applyAsDouble(Math2.round(now.doubleValue(),3)); if (!suppressListeners.isSet()) callback.execute(); }); spn.valueProperty().addListener((observable, prev, now) -> { //link slider to spinner if (spn.getValue() != sld.getValue()) sld.setValue(spn.getValue()); }); spn.focusedProperty().addListener((observable, prev, now) -> { //make spinner act rationally if (!now) spn.increment(0); }); }
@Override public void updateItem(String item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) { setGraphic(null); setText(null); } else { String ip = item; HBox zoomControls = mapIPToZoomControls.get(ip); //"cache" is required so we won't lose the zoomControl's state when tableTrace.refresh() is called (while dragging splitter) if (zoomControls == null) { ToggleButton btnZoom = createZoomButton(ip); Spinner<Integer> spinnerZoom = createZoomSpinner(btnZoom, ip); zoomControls = new HBox(btnZoom, spinnerZoom); zoomControls.setStyle("-fx-alignment: center;"); mapIPToZoomControls.put(ip, zoomControls); } setGraphic(zoomControls); setText(null); } }
/** * Creates a new instance of {@link FXSpinnerBehaviorRT40623}. * * @param pSpinner the spinner. */ public FXSpinnerBehaviorRT40623(Spinner<T> pSpinner) { super(pSpinner); keyPressedHandler = this::onKeyPressed; scrollHandler = this::onScroll; pSpinner.addEventFilter(KeyEvent.KEY_PRESSED, keyPressedHandler); pSpinner.addEventFilter(ScrollEvent.SCROLL, scrollHandler); }
/** * Creates the {@link ComboBox} used for selection a year. * * @return the {@link ComboBox} for selecting a year. */ private Spinner<Integer> createYearSelector() { Spinner<Integer> yearSpinner = new FXSpinnerRT40623<>(new IntegerSpinnerValueFactory(Integer.MIN_VALUE, Integer.MAX_VALUE)); yearSpinner.getStyleClass().add("year-selector"); yearSpinner.setEditable(true); yearSpinner.valueProperty().addListener(this::onSelectedYearChanged); return yearSpinner; }