Example usage for javafx.scene.control Spinner Spinner

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

Introduction

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

Prototype

Spinner(@NamedArg("min") LocalTime min, @NamedArg("max") LocalTime max,
        @NamedArg("initialValue") LocalTime initialValue) 

Source Link

Document

Creates a Spinner instance with the #valueFactoryProperty() value factory set to be an instance of SpinnerValueFactory.LocalTimeSpinnerValueFactory .

Usage

From source file:FeeBooster.java

private GridPane rbfGrid(Transaction tx) {
    // Setup grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from   w  w  w  .j  a va 2s  .  com
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    int inGridHeight = 0;
    int outGridHeight = 0;

    // Add inputs to table
    Label inputHdrLbl = new Label("Inputs");
    grid.add(inputHdrLbl, 0, inGridHeight);
    inGridHeight++;
    for (int i = 0; i < tx.getInputs().size(); i++) {
        // Add input to table
        TxInput in = tx.getInputs().get(i);
        Text inputTxt = new Text("Txid: " + in.getTxid() + "\nIndex: " + in.getVout());
        grid.add(inputTxt, 0, inGridHeight);
        inGridHeight++;
    }

    // Add outputs to table
    Label outputHdrLbl = new Label("Outputs");
    grid.add(outputHdrLbl, 1, outGridHeight);
    outGridHeight++;
    ToggleGroup outputGroup = new ToggleGroup();
    for (int i = 0; i < tx.getOutputs().size(); i++) {
        // Add output to table
        TxOutput out = tx.getOutputs().get(i);
        Text outputTxt = new Text("Amount " + out.getValue() + " Satoshis\nAddress: " + out.getAddress());
        outputTxt.setUserData(i);
        grid.add(outputTxt, 1, outGridHeight);

        // Add radio button to table
        RadioButton radio = new RadioButton();
        radio.setUserData(i);
        radio.setToggleGroup(outputGroup);
        radio.setSelected(true);
        grid.add(radio, 2, outGridHeight);
        outGridHeight++;
    }

    // Set gridheight
    int gridheight = (inGridHeight < outGridHeight) ? outGridHeight : inGridHeight;
    gridheight++;

    // Fee
    Text fee = new Text("Fee Paid: " + tx.getFee() + " Satoshis");
    grid.add(fee, 0, gridheight);

    // Recommended fee from bitcoinfees.21.co
    JSONObject apiResult = Utils.getFromAnAPI("http://bitcoinfees.21.co/api/v1/fees/recommended", "GET");
    int fastestFee = apiResult.getInt("fastestFee");
    long recommendedFee = fastestFee * tx.getSize();
    Text recFeeTxt = new Text("Recommended Fee: " + recommendedFee + " Satoshis");
    grid.add(recFeeTxt, 1, gridheight);
    gridheight += 2;

    // Instructions
    Text instructions = new Text(
            "Choose an output to deduct an additional fee from. Then increase the fee below.");
    grid.add(instructions, 0, gridheight, 3, 1);
    gridheight++;

    // Fee spinner
    Spinner feeSpin = new Spinner((double) tx.getFee(), (double) tx.getTotalAmt(), (double) tx.getFee());
    feeSpin.setEditable(true);
    grid.add(feeSpin, 0, gridheight);
    feeSpin.valueProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            double oldVal = (double) oldValue;
            double newVal = (double) newValue;
            Double step = newVal - oldVal;
            tx.setFee(tx.getFee() + step.longValue());
            fee.setText("Fee Paid: " + tx.getFee() + " Satoshis");
            int output = (int) outputGroup.getSelectedToggle().getUserData();
            TxOutput out = tx.getOutputs().get(output);
            out.decreaseValueBy(step.longValue());
            for (int i = 0; i < grid.getChildren().size(); i++) {
                Node child = grid.getChildren().get(i);
                if (grid.getRowIndex(child) == output + 1 && grid.getColumnIndex(child) == 1) {
                    ((Text) child)
                            .setText("Amount " + out.getValue() + " Satoshis\nAddress: " + out.getAddress());
                }
            }
        }
    });

    // Set to recommended fee button
    Button recFeeBtn = new Button("Set fee to recommended");
    grid.add(recFeeBtn, 1, gridheight);
    gridheight++;
    recFeeBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            long prevFee = tx.getFee();
            long step = recommendedFee - prevFee;
            feeSpin.increment((int) step);
        }
    });

    // Next Button
    Button nextBtn = new Button("Next");
    grid.add(nextBtn, 1, gridheight);
    nextBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            if (sceneCursor == scenes.size() - 1) {
                Scene scene = new Scene(unsignedTxGrid(tx), 900, 500);
                scenes.add(scene);
                sceneCursor++;
                stage.setScene(scene);
            } else {
                sceneCursor++;
                stage.setScene(scenes.get(sceneCursor));
            }
        }
    });
    HBox btnHbox = new HBox(10);

    // Back Button
    Button backBtn = new Button("Back");
    backBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            sceneCursor--;
            stage.setScene(scenes.get(sceneCursor));
        }
    });
    btnHbox.getChildren().add(backBtn);
    btnHbox.getChildren().add(nextBtn);

    // Cancel Button
    Button cancelBtn = new Button("Cancel");
    cancelBtn.setOnAction(cancelEvent);
    btnHbox.getChildren().add(cancelBtn);
    grid.add(btnHbox, 1, gridheight);

    return grid;
}

From source file:de.rkl.tools.tzconv.TimezoneConverter.java

private Spinner<Integer> createHourSpinner() {
    final Spinner<Integer> hourSpinner = new Spinner<>(0, 23, DEFAULT_INITIAL_HOUR);
    hourSpinner.valueProperty().addListener((observable, oldValue, newValue) -> {
        applicationModel.mainDateTime.setValue(applicationModel.mainDateTime.getValue().withHour(newValue));
    });/*from   w  ww .  jav a  2 s. c o m*/
    return hourSpinner;
}

From source file:FeeBooster.java

private GridPane cpfpGrid(Transaction tx) {
    // Setup Grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);/*  w w  w.  j  a  v  a 2 s  .  co m*/
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    int gridheight = 0;

    // Add outputs to table
    Label outputHdrLbl = new Label("Outputs");
    grid.add(outputHdrLbl, 1, gridheight);
    gridheight++;
    ToggleGroup outputGroup = new ToggleGroup();
    for (int i = 0; i < tx.getOutputs().size(); i++) {
        // Add output to table
        TxOutput out = tx.getOutputs().get(i);
        Text outputTxt = new Text("Amount " + out.getValue() + " Satoshis\nAddress: " + out.getAddress());
        outputTxt.setUserData(i);
        grid.add(outputTxt, 0, gridheight);

        // Add radio button to table
        RadioButton radio = new RadioButton();
        radio.setUserData(i);
        radio.setToggleGroup(outputGroup);
        radio.setSelected(true);
        grid.add(radio, 1, gridheight);
        gridheight++;
    }

    // Fee
    Text fee = new Text("Fee to Pay: " + tx.getFee() + " Satoshis");
    grid.add(fee, 0, gridheight);

    // Recommended fee from bitcoinfees.21.co
    JSONObject apiResult = Utils.getFromAnAPI("http://bitcoinfees.21.co/api/v1/fees/recommended", "GET");
    int fastestFee = apiResult.getInt("fastestFee");
    long recommendedFee = fastestFee * tx.getSize() + fastestFee * 300;
    Text recFeeTxt = new Text("Recommended Fee: " + recommendedFee + " Satoshis");
    grid.add(recFeeTxt, 1, gridheight);
    gridheight += 2;

    // Instructions
    Text instructions = new Text("Choose an output to spend from. Set the total transaction fee below.");
    grid.add(instructions, 0, gridheight, 3, 1);
    gridheight++;

    // Fee spinner
    Spinner feeSpin = new Spinner((double) tx.getFee(), (double) tx.getTotalAmt(), (double) tx.getFee());
    feeSpin.setEditable(true);
    grid.add(feeSpin, 0, gridheight);
    feeSpin.valueProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            double oldVal = (double) oldValue;
            double newVal = (double) newValue;
            Double step = newVal - oldVal;
            tx.setFee(tx.getFee() + step.longValue());
            fee.setText("Fee to Pay: " + tx.getFee() + " Satoshis");
        }
    });

    // Set to recommended fee button
    Button recFeeBtn = new Button("Set fee to recommended");
    grid.add(recFeeBtn, 1, gridheight);
    gridheight++;
    recFeeBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            long prevFee = tx.getFee();
            long step = recommendedFee - prevFee;
            feeSpin.increment((int) step);
        }
    });

    // Output address
    Label recvAddr = new Label("Address to pay to");
    grid.add(recvAddr, 0, gridheight);
    TextField outAddr = new TextField();
    grid.add(outAddr, 1, gridheight);
    gridheight++;

    // Next Button
    Button nextBtn = new Button("Next");
    nextBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {

            if (sceneCursor == scenes.size() - 1) {
                // Referenced output
                int output = (int) outputGroup.getSelectedToggle().getUserData();
                TxOutput refout = tx.getOutputs().get(output);

                // Create output for CPFP transaction
                TxOutput out = null;
                long outval = refout.getValue() - ((Double) feeSpin.getValue()).longValue();
                if (Utils.validateAddress(outAddr.getText())) {
                    byte[] decodedAddr = Utils.base58Decode(outAddr.getText());
                    boolean isP2SH = decodedAddr[0] == 0x00;
                    byte[] hash160 = Arrays.copyOfRange(decodedAddr, 1, decodedAddr.length - 4);
                    if (isP2SH) {
                        byte[] script = new byte[hash160.length + 3];
                        script[0] = (byte) 0xa9;
                        script[1] = (byte) 0x14;
                        System.arraycopy(hash160, 0, script, 2, hash160.length);
                        script[script.length - 1] = (byte) 0x87;
                        out = new TxOutput(outval, script);
                    } else {
                        byte[] script = new byte[hash160.length + 5];
                        script[0] = (byte) 0x76;
                        script[1] = (byte) 0xa9;
                        script[2] = (byte) 0x14;
                        System.arraycopy(hash160, 0, script, 3, hash160.length);
                        script[script.length - 2] = (byte) 0x88;
                        script[script.length - 1] = (byte) 0xac;
                        out = new TxOutput(outval, script);
                    }
                } else {
                    Alert alert = new Alert(Alert.AlertType.ERROR, "Invalid Address");
                    alert.showAndWait();
                    return;
                }

                // Create CPFP Transaction
                Transaction cpfpTx = new Transaction();
                TxInput in = new TxInput(tx.getHash(), output, new byte[] { (0x00) }, 0xffffffff);
                cpfpTx.addOutput(out);
                cpfpTx.addInput(in);

                // Create Scene
                Scene scene = new Scene(unsignedTxGrid(cpfpTx), 900, 500);
                scenes.add(scene);
                sceneCursor++;
                stage.setScene(scene);
            } else {
                sceneCursor++;
                stage.setScene(scenes.get(sceneCursor));
            }
        }
    });
    HBox btnHbox = new HBox(10);

    // Back Button
    Button backBtn = new Button("Back");
    backBtn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            sceneCursor--;
            stage.setScene(scenes.get(sceneCursor));
        }
    });
    btnHbox.getChildren().add(backBtn);
    btnHbox.getChildren().add(nextBtn);

    // Cancel Button
    Button cancelBtn = new Button("Cancel");
    cancelBtn.setOnAction(cancelEvent);
    btnHbox.getChildren().add(cancelBtn);
    grid.add(btnHbox, 1, gridheight);

    return grid;
}