Example usage for javafx.scene.control Slider setValue

List of usage examples for javafx.scene.control Slider setValue

Introduction

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

Prototype

public final void setValue(double value) 

Source Link

Usage

From source file:AudioPlayer3.java

private Slider createSlider(String id) {
    final Slider slider = new Slider(0.0, 1.0, 0.1);
    slider.setId(id);//from  w  w  w .  j a  va  2  s . com
    slider.setValue(0);
    return slider;
}

From source file:ipat_fx.FXMLDocumentController.java

@FXML
public void resetScores() {

    HashMap<String, Hint> hintMap = controller.hints;
    TabPane tabpane = (TabPane) byProfilePane.getChildren().get(0);
    Tab tab = null;//from  w w  w.j a  va2  s .c o m
    if (tabFlag.equalsIgnoreCase("byProfile")) {
        tab = tabpane.getTabs().get(0);
    } else if (tabFlag.equalsIgnoreCase("byImage")) {
        tab = tabpane.getTabs().get(0);
    } else {
        Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null,
                "Something wrong with tabFlag");
    }
    ScrollPane scrollPane = (ScrollPane) tab.getContent();
    FlowPane flowPane = (FlowPane) scrollPane.getContent();
    Iterator<Node> cellsIterator = flowPane.getChildren().iterator();
    while (cellsIterator.hasNext()) {
        GridPane cell = (GridPane) cellsIterator.next();
        Iterator<Node> cellIterator = cell.getChildren().iterator();
        while (cellIterator.hasNext()) {
            Node cellElement = cellIterator.next();
            if (cellElement instanceof Slider) {
                Set<String> keySet = hintMap.keySet();// get the hints one by one and apply to cell
                int keyCount = 0;
                for (String key : keySet) {
                    Hint h = hintMap.get(key);
                    Slider slider = ((Slider) cellElement);
                    String[] split = slider.getId().split("_");
                    if (split[0].equalsIgnoreCase(h.getHintName())) {
                        slider.setValue(Double.valueOf(h.getDefaultValue()));
                    }
                }
            }
            if (cellElement instanceof CheckBox) {
                ((CheckBox) cellElement).setSelected(false);
            }
        }
    }
}

From source file:boundary.GraphPane.java

private Node addThresholdSlider(float min, float max) {
    HBox hBox = new HBox();

    hBox.setPadding(new Insets(15, 12, 15, 12));
    hBox.setStyle("-fx-background-color: #66FFFF;");

    Label lblThreshold = new Label("Threshold: ");
    lblThreshold.setPrefSize(100, 20);/*from   w  ww.  j  av a 2  s. c  om*/

    Label lblValue = new Label("Value: ");
    lblValue.setPrefSize(50, 20);
    TextField tfValue = new TextField(String.valueOf(min));

    Slider thresholdSlider = new Slider();
    thresholdSlider.setMin(Math.floor(min));
    thresholdSlider.setMax(Math.ceil(max));
    thresholdSlider.setMajorTickUnit(Math.ceil((max - min) / 5));
    thresholdSlider.setMinorTickCount(1);
    thresholdSlider.setBlockIncrement(1);
    thresholdSlider.setSnapToTicks(true);
    thresholdSlider.setShowTickMarks(true);

    thresholdSlider.valueProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {

            edgePredicate.setThreshold(newValue.floatValue());
            vertexPredicate.setThreshold(newValue.floatValue());

            vv.repaint();

            tfValue.setText(String.format(Locale.US, "%.2f", newValue.floatValue()));

        }
    });

    tfValue.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            float value;

            try {
                value = Float.parseFloat(tfValue.getText());
            } catch (Exception ex) {
                value = 0;
            }
            edgePredicate.setThreshold(value);
            vertexPredicate.setThreshold(value);

            vv.repaint();

            thresholdSlider.setValue(value);

        }
    });

    Label lblSearch = new Label("Search: ");
    lblSearch.setPrefSize(70, 20);

    TextField tf = new TextField();

    tf.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            String toFind = tf.getText().toLowerCase();

            for (NodeInfo nodeInfo : nodesHighlighted)
                nodeInfo.setHighlighted(false);

            if (nodesHighlighted.size() > 0) {
                nodesHighlighted.clear();
                vv.repaint();
            }

            if (toFind.length() > 2) {
                for (NodeInfo nodeInfo : nodes.values()) {
                    if (nodeInfo.getUserData().toLowerCase().contains((toFind))) {
                        nodeInfo.setHighlighted(true);
                        nodesHighlighted.add(nodeInfo);
                    }
                }

                if (nodesHighlighted.size() == 1) {
                    Layout<String, String> layout = vv.getGraphLayout();
                    Point2D q = layout.transform(nodesHighlighted.get(0).id);
                    Point2D lvc = vv.getRenderContext().getMultiLayerTransformer()
                            .inverseTransform(vv.getCenter());
                    final double dx = (lvc.getX() - q.getX()) / 10;
                    final double dy = (lvc.getY() - q.getY()) / 10;

                    Runnable animator = new Runnable() {

                        public void run() {
                            for (int i = 0; i < 10; i++) {
                                vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)
                                        .translate(dx, dy);
                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException ex) {
                                }
                            }
                        }
                    };

                    Thread thread = new Thread(animator);
                    thread.start();
                }
                vv.repaint();
            }
        }
    });

    hBox.getChildren().addAll(lblThreshold, thresholdSlider, lblValue, tfValue, lblSearch, tf);

    return hBox;
}

From source file:org.noroomattheinn.visibletesla.NotifierController.java

private void bindBidrectional(final BigDecimalField bdf, final Slider slider) {
    bdf.setFormat(new DecimalFormat("##0.0"));
    bdf.setStepwidth(BigDecimal.valueOf(0.5));
    bdf.setNumber(new BigDecimal(Utils.round(slider.getValue(), 1)));

    slider.valueProperty().addListener(new ChangeListener<Number>() {
        @Override/* w w w.java 2 s . com*/
        public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
            double val = Utils.round(t1.doubleValue(), 1);
            slider.setValue(val);
            bdf.setNumber(new BigDecimal(val));
        }
    });

    bdf.numberProperty().addListener(new ChangeListener<BigDecimal>() {
        @Override
        public void changed(ObservableValue<? extends BigDecimal> ov, BigDecimal t, BigDecimal t1) {
            double val = Utils.round(t1.doubleValue(), 1);
            slider.setValue(val);
            bdf.setNumber(new BigDecimal(val));
        }
    });
}