Example usage for javafx.scene.control RadioButton RadioButton

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

Introduction

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

Prototype

public RadioButton() 

Source Link

Document

Creates a radio button with an empty string for its label.

Usage

From source file:fruitproject.FruitProject.java

public void first(final Stage primaryStage) {
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);/* www  . j  a  v  a2 s  .c  o  m*/
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    rows = 0;
    addPairs.clear();

    Text lb = new Text();
    lb.setText("J-Fruit");
    //lb.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(lb, 1, 0);

    final ToggleGroup grp = new ToggleGroup();
    RadioButton rb1 = new RadioButton();
    rb1.setText("Add Fruit file");
    rb1.setUserData("add");
    rb1.setToggleGroup(grp);
    rb1.setSelected(true);
    grid.add(rb1, 1, 1);

    RadioButton rb2 = new RadioButton();
    rb2.setText("Load Fruit file");
    rb2.setUserData("load");
    rb2.setToggleGroup(grp);
    grid.add(rb2, 1, 2);

    Label label1 = new Label("Enter File Name:");
    final TextField tfFilename = new TextField();
    final HBox hb = new HBox();
    hb.getChildren().addAll(label1, tfFilename);
    hb.setSpacing(10);
    hb.setVisible(false);
    tfFilename.setText("");
    grid.add(hb, 1, 3);

    grp.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (grp.getSelectedToggle() != null) {
                // System.out.println(grp.getSelectedToggle().getUserData().toString());
                if (grp.getSelectedToggle().getUserData().toString() == "load")
                    hb.setVisible(true);
                else {
                    hb.setVisible(false);
                    tfFilename.setText("");
                }
            }
        }
    });

    if (rb2.isSelected() == true) {
        hb.setVisible(true);
    }

    Button btn = new Button();
    btn.setText("GO");
    grid.add(btn, 1, 4);
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");
            if (tfFilename.getText() == "")
                second("");
            else
                second(tfFilename.getText());
            primaryStage.close();
        }
    });

    //StackPane root = new StackPane();
    //root.getChildren().add(lb);
    //root.getChildren().add(rb1);
    //root.getChildren().add(rb2);
    //root.getChildren().add(btn);

    Scene scene = new Scene(grid, 400, 450);
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();

}

From source file:FeeBooster.java

private GridPane rbfGrid(Transaction tx) {
    // Setup grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//w ww  . j  a  v a2  s .  co m
    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:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java

@Override
public Region getContent() {
    if (hBox == null) {
        VBox statedInferredToggleGroupVBox = new VBox();
        statedInferredToggleGroupVBox.setSpacing(4.0);

        //Instantiate Everything
        pathComboBox = new ComboBox<>(); //Path
        statedInferredToggleGroup = new ToggleGroup(); //Stated / Inferred
        List<RadioButton> statedInferredOptionButtons = new ArrayList<>();
        datePicker = new DatePicker(); //Date
        timeSelectCombo = new ComboBox<Long>(); //Time

        //Radio buttons
        for (StatedInferredOptions option : StatedInferredOptions.values()) {
            RadioButton optionButton = new RadioButton();
            if (option == StatedInferredOptions.STATED) {
                optionButton.setText("Stated");
            } else if (option == StatedInferredOptions.INFERRED_THEN_STATED) {
                optionButton.setText("Inferred Then Stated");
            } else if (option == StatedInferredOptions.INFERRED) {
                optionButton.setText("Inferred");
            } else {
                throw new RuntimeException("oops");
            }//from w  ww  .j  a  v a 2  s .c  o  m
            optionButton.setUserData(option);
            optionButton.setTooltip(
                    new Tooltip("Default StatedInferredOption is " + getDefaultStatedInferredOption()));
            statedInferredToggleGroup.getToggles().add(optionButton);
            statedInferredToggleGroupVBox.getChildren().add(optionButton);
            statedInferredOptionButtons.add(optionButton);
        }
        statedInferredToggleGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
            @Override
            public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue,
                    Toggle newValue) {
                currentStatedInferredOptionProperty.set((StatedInferredOptions) newValue.getUserData());
            }
        });

        //Path Combo Box
        pathComboBox.setCellFactory(new Callback<ListView<UUID>, ListCell<UUID>>() {
            @Override
            public ListCell<UUID> call(ListView<UUID> param) {
                final ListCell<UUID> cell = new ListCell<UUID>() {
                    @Override
                    protected void updateItem(UUID c, boolean emptyRow) {
                        super.updateItem(c, emptyRow);
                        if (c == null) {
                            setText(null);
                        } else {
                            String desc = OTFUtility.getDescription(c);
                            setText(desc);
                        }
                    }
                };
                return cell;
            }
        });

        pathComboBox.setButtonCell(new ListCell<UUID>() { // Don't know why this should be necessary, but without this the UUID itself is displayed
            @Override
            protected void updateItem(UUID c, boolean emptyRow) {
                super.updateItem(c, emptyRow);
                if (emptyRow) {
                    setText("");
                } else {
                    String desc = OTFUtility.getDescription(c);
                    setText(desc);
                }
            }
        });
        pathComboBox.setOnAction((event) -> {
            if (!pathComboFirstRun) {
                UUID selectedPath = pathComboBox.getSelectionModel().getSelectedItem();
                if (selectedPath != null) {
                    int path = OTFUtility.getConceptVersion(selectedPath).getPathNid();

                    StampBdb stampDb = Bdb.getStampDb();
                    NidSet nidSet = new NidSet();
                    nidSet.add(path);
                    //TODO: Make this multi-threaded and possibly implement setTimeOptions() here also
                    NidSetBI stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE);

                    pathDatesList.clear();
                    //                  disableTimeCombo(true);
                    timeSelectCombo.setValue(Long.MAX_VALUE);

                    for (Integer thisStamp : stamps.getAsSet()) {
                        try {
                            Position stampPosition = stampDb.getPosition(thisStamp);
                            this.stampDate = new Date(stampPosition.getTime());
                            stampDateInstant = stampDate.toInstant().atZone(ZoneId.systemDefault())
                                    .toLocalDate();
                            this.pathDatesList.add(stampDateInstant); //Build DatePicker
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    datePicker.setValue(LocalDate.now());
                }
            } else {
                pathComboFirstRun = false;
            }
        });

        pathComboBox.setTooltip(
                new Tooltip("Default path is \"" + OTFUtility.getDescription(getDefaultPath()) + "\""));

        //Calendar Date Picker
        final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
            @Override
            public DateCell call(final DatePicker datePicker) {
                return new DateCell() {
                    @Override
                    public void updateItem(LocalDate thisDate, boolean empty) {
                        super.updateItem(thisDate, empty);
                        if (pathDatesList != null) {
                            if (pathDatesList.contains(thisDate)) {
                                setDisable(false);
                            } else {
                                setDisable(true);
                            }
                        }
                    }
                };
            }
        };
        datePicker.setDayCellFactory(dayCellFactory);
        datePicker.setOnAction((event) -> {
            if (!datePickerFirstRun) {
                UUID selectedPath = pathComboBox.getSelectionModel().getSelectedItem();

                Instant instant = Instant.from(datePicker.getValue().atStartOfDay(ZoneId.systemDefault()));
                Long dateSelected = Date.from(instant).getTime();

                if (selectedPath != null && dateSelected != 0) {

                    int path = OTFUtility.getConceptVersion(selectedPath).getPathNid();
                    setTimeOptions(path, dateSelected);
                    try {
                        timeSelectCombo.setValue(times.first()); //Default Dropdown Value
                    } catch (Exception e) {
                        // Eat it.. like a sandwich! TODO: Create Read Only Property Conditional for checking if Time Combo is disabled
                        // Right now, Sometimes Time Combo is disabled, so we catch this and eat it
                        // Otherwise make a conditional from the Read Only Boolean Property to check first
                    }
                } else {
                    disableTimeCombo(false);
                    logger.debug("The path isn't set or the date isn't set. Both are needed right now");
                }
            } else {
                datePickerFirstRun = false;
            }
        });

        //Commit-Time ComboBox
        timeSelectCombo.setMinWidth(200);
        timeSelectCombo.setCellFactory(new Callback<ListView<Long>, ListCell<Long>>() {
            @Override
            public ListCell<Long> call(ListView<Long> param) {
                final ListCell<Long> cell = new ListCell<Long>() {
                    @Override
                    protected void updateItem(Long item, boolean emptyRow) {
                        super.updateItem(item, emptyRow);
                        if (item == null) {
                            setText("");
                        } else {
                            if (item == Long.MAX_VALUE) {
                                setText("LATEST TIME");
                            } else {
                                setText(timeFormatter.format(new Date(item)));
                            }
                        }
                    }
                };
                return cell;
            }
        });
        timeSelectCombo.setButtonCell(new ListCell<Long>() {
            @Override
            protected void updateItem(Long item, boolean emptyRow) {
                super.updateItem(item, emptyRow);
                if (item == null) {
                    setText("");
                } else {
                    if (item == Long.MAX_VALUE) {
                        setText("LATEST TIME");
                    } else {
                        setText(timeFormatter.format(new Date(item)));
                    }
                }
            }
        });

        try {
            currentPathProperty.bind(pathComboBox.getSelectionModel().selectedItemProperty()); //Set Path Property
            currentTimeProperty.bind(timeSelectCombo.getSelectionModel().selectedItemProperty());
        } catch (Exception e) {
            e.printStackTrace();
        }

        // DEFAULT VALUES
        UserProfile loggedIn = ExtendedAppContext.getCurrentlyLoggedInUserProfile();
        storedTimePref = loggedIn.getViewCoordinateTime();
        storedPathPref = loggedIn.getViewCoordinatePath();

        if (storedPathPref != null) {
            pathComboBox.getItems().clear(); //Set the path Dates by default
            pathComboBox.getItems().addAll(getPathOptions());
            final UUID storedPath = getStoredPath();
            if (storedPath != null) {
                pathComboBox.getSelectionModel().select(storedPath);
            }

            if (storedTimePref != null) {
                final Long storedTime = loggedIn.getViewCoordinateTime();
                Calendar cal = Calendar.getInstance();
                cal.setTime(new Date(storedTime));
                cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds
                Long storedTruncTime = cal.getTimeInMillis();

                if (!storedTime.equals(Long.MAX_VALUE)) { //***** FIX THIS, not checking default vc time value
                    int path = OTFUtility.getConceptVersion(storedPathPref).getPathNid();
                    setTimeOptions(path, storedTimePref);
                    timeSelectCombo.setValue(storedTruncTime);
                    //                  timeSelectCombo.getItems().addAll(getTimeOptions()); //The correct way, but doesen't work

                    Date storedDate = new Date(storedTime);
                    datePicker.setValue(storedDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
                } else {
                    datePicker.setValue(LocalDate.now());
                    timeSelectCombo.getItems().addAll(Long.MAX_VALUE); //The correct way, but doesen't work
                    timeSelectCombo.setValue(Long.MAX_VALUE);
                    //                  disableTimeCombo(false);
                }
            } else { //Stored Time Pref == null
                logger.error("ERROR: Stored Time Preference = null");
            }
        } else { //Stored Path Pref == null
            logger.error("We could not load a stored path, ISAAC cannot run");
            throw new Error("No stored PATH could be found. ISAAC can't run without a path");
        }

        GridPane gridPane = new GridPane();
        gridPane.setHgap(10);
        gridPane.setVgap(10);

        Label pathLabel = new Label("View Coordinate Path");
        gridPane.add(pathLabel, 0, 0); //Path Label - Row 0
        GridPane.setHalignment(pathLabel, HPos.LEFT);
        gridPane.add(statedInferredToggleGroupVBox, 1, 0, 1, 2); //--Row 0, span 2

        gridPane.add(pathComboBox, 0, 1); //Path Combo box - Row 2
        GridPane.setValignment(pathComboBox, VPos.TOP);

        Label datePickerLabel = new Label("View Coordinate Dates");
        gridPane.add(datePickerLabel, 0, 2); //Row 3
        GridPane.setHalignment(datePickerLabel, HPos.LEFT);
        gridPane.add(datePicker, 0, 3); //Row 4

        Label timeSelectLabel = new Label("View Coordinate Times");
        gridPane.add(timeSelectLabel, 1, 2); //Row 3
        GridPane.setHalignment(timeSelectLabel, HPos.LEFT);
        gridPane.add(timeSelectCombo, 1, 3); //Row 4

        // FOR DEBUGGING CURRENTLY SELECTED PATH, TIME AND POLICY
        /*         
                 UserProfile userProfile = ExtendedAppContext.getCurrentlyLoggedInUserProfile();
                 StatedInferredOptions chosenPolicy = userProfile.getStatedInferredPolicy();
                 UUID chosenPathUuid = userProfile.getViewCoordinatePath();
                 Long chosenTime = userProfile.getViewCoordinateTime();
                         
                 Label printSelectedPathLabel = new Label("Path: " + OTFUtility.getDescription(chosenPathUuid));
                 gridPane.add(printSelectedPathLabel, 0, 4);
                 GridPane.setHalignment(printSelectedPathLabel, HPos.LEFT);
                 Label printSelectedTimeLabel = null;
                 if(chosenTime != getDefaultTime()) {
                    printSelectedTimeLabel = new Label("Time: " + dateFormat.format(new Date(chosenTime)));
                 } else {
                    printSelectedTimeLabel = new Label("Time: LONG MAX VALUE");
                 }
                 gridPane.add(printSelectedTimeLabel, 1, 4);
                 GridPane.setHalignment(printSelectedTimeLabel, HPos.LEFT);
                 Label printSelectedPolicyLabel = new Label("Policy: " + chosenPolicy);
                 gridPane.add(printSelectedPolicyLabel, 2, 4);
                 GridPane.setHalignment(printSelectedPolicyLabel, HPos.LEFT);
                 */
        hBox = new HBox();
        hBox.getChildren().addAll(gridPane);

        allValid_ = new ValidBooleanBinding() {
            {
                bind(currentStatedInferredOptionProperty, currentPathProperty, currentTimeProperty);
                setComputeOnInvalidate(true);
            }

            @Override
            protected boolean computeValue() {
                if (currentStatedInferredOptionProperty.get() == null) {
                    this.setInvalidReason("Null/unset/unselected StatedInferredOption");
                    for (RadioButton button : statedInferredOptionButtons) {
                        TextErrorColorHelper.setTextErrorColor(button);
                    }
                    return false;
                } else {
                    for (RadioButton button : statedInferredOptionButtons) {
                        TextErrorColorHelper.clearTextErrorColor(button);
                    }
                }
                if (currentPathProperty.get() == null) {
                    this.setInvalidReason("Null/unset/unselected path");
                    TextErrorColorHelper.setTextErrorColor(pathComboBox);

                    return false;
                } else {
                    TextErrorColorHelper.clearTextErrorColor(pathComboBox);
                }
                if (OTFUtility.getConceptVersion(currentPathProperty.get()) == null) {
                    this.setInvalidReason("Invalid path");
                    TextErrorColorHelper.setTextErrorColor(pathComboBox);

                    return false;
                } else {
                    TextErrorColorHelper.clearTextErrorColor(pathComboBox);
                }
                //               if(currentTimeProperty.get() == null && currentTimeProperty.get() != Long.MAX_VALUE)
                //               {
                //                  this.setInvalidReason("View Coordinate Time is unselected");
                //                  TextErrorColorHelper.setTextErrorColor(timeSelectCombo);
                //                  return false;
                //               }
                this.clearInvalidReason();
                return true;
            }
        };
    }
    //      createButton.disableProperty().bind(saveButtonValid.not()));

    // Reload persisted values every time
    final StatedInferredOptions storedStatedInferredOption = getStoredStatedInferredOption();
    for (Toggle toggle : statedInferredToggleGroup.getToggles()) {
        if (toggle.getUserData() == storedStatedInferredOption) {
            toggle.setSelected(true);
        }
    }

    //      pathComboBox.setButtonCell(new ListCell<UUID>() {
    //         @Override
    //         protected void updateItem(UUID c, boolean emptyRow) {
    //            super.updateItem(c, emptyRow); 
    //            if (emptyRow) {
    //               setText("");
    //            } else {
    //               String desc = OTFUtility.getDescription(c);
    //               setText(desc);
    //            }
    //         }
    //      });
    //      timeSelectCombo.setButtonCell(new ListCell<Long>() {
    //         @Override
    //         protected void updateItem(Long item, boolean emptyRow) {
    //            super.updateItem(item, emptyRow); 
    //            if (emptyRow) {
    //               setText("");
    //            } else {
    //               setText(timeFormatter.format(new Date(item)));
    //            }
    //         }
    //      });

    //      datePickerFirstRun = false;
    //      pathComboFirstRun = false;

    return hBox;
}

From source file:dpfmanager.shell.interfaces.gui.component.dessign.DessignView.java

public void addConfigFile(String text, String description, boolean selected) {
    RadioButton radio = new RadioButton();
    radio.setId("radioConfig" + vBoxConfig.getChildren().size());
    radio.setText(text);//ww  w. j a  v a 2  s .c o  m
    radio.setToggleGroup(group);
    radio.setSelected(selected);
    if (description != null && !description.isEmpty()) {
        radio.setTooltip(new Tooltip(description));
    }
    radio.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            selectedButton = radio;
        }
    });
    vBoxConfig.getChildren().add(radio);
    if (selected) {
        selectedButton = radio;
    }
}

From source file:FeeBooster.java

private GridPane cpfpGrid(Transaction tx) {
    // Setup Grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from  w  ww . ja  va2  s  .c om
    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;
}

From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java

private void initializeStatusesToggleGroup() {
    statusesToggleGroup = new ToggleGroup();
    Tooltip statusButtonsTooltip = new Tooltip("Default Status(es) is " + getDefaultStatuses());
    activeStatusButton = new RadioButton();
    activeStatusButton.setText("Active");
    activeStatusButton.setTooltip(statusButtonsTooltip);
    statusesToggleGroup.getToggles().add(activeStatusButton);
    activeStatusButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            currentStatusesProperty.get().clear();
            currentStatusesProperty.add(Status.ACTIVE);
        }//from   w  w w.  j a  v a 2  s  .c  o  m
    });
    statusesToggleGroupVBox.getChildren().add(activeStatusButton);

    inactiveStatusButton = new RadioButton();
    inactiveStatusButton.setText("Inactive");
    inactiveStatusButton.setTooltip(statusButtonsTooltip);
    statusesToggleGroup.getToggles().add(inactiveStatusButton);
    inactiveStatusButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            currentStatusesProperty.get().clear();
            currentStatusesProperty.add(Status.INACTIVE);
        }
    });
    statusesToggleGroupVBox.getChildren().add(inactiveStatusButton);

    activeAndInactiveStatusButton = new RadioButton();
    activeAndInactiveStatusButton.setText("All");
    activeAndInactiveStatusButton.setTooltip(statusButtonsTooltip);
    statusesToggleGroup.getToggles().add(activeAndInactiveStatusButton);
    activeAndInactiveStatusButton.selectedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            currentStatusesProperty.get().clear();
            currentStatusesProperty.add(Status.ACTIVE);
            currentStatusesProperty.add(Status.INACTIVE);
        }
    });
    statusesToggleGroupVBox.getChildren().add(activeAndInactiveStatusButton);
}

From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java

private void initializeStatedInferredToggleGroup() {
    statedInferredToggleGroup = new ToggleGroup(); //Stated / Inferred

    for (StatedInferredOptions option : StatedInferredOptions.values()) {
        RadioButton optionButton = new RadioButton();
        if (option == StatedInferredOptions.STATED) {
            optionButton.setText("Stated");
        } else if (option == StatedInferredOptions.INFERRED) {
            optionButton.setText("Inferred");
        } else {/*from w w w.ja  v  a  2 s.c om*/
            throw new RuntimeException("oops");
        }
        optionButton.setUserData(option);
        optionButton
                .setTooltip(new Tooltip("Default StatedInferredOption is " + getDefaultStatedInferredOption()));
        statedInferredToggleGroup.getToggles().add(optionButton);
        statedInferredToggleGroupVBox.getChildren().add(optionButton);
        statedInferredOptionButtons.add(optionButton);
    }
    statedInferredToggleGroup.selectedToggleProperty()
            .addListener((observable, oldValue,
                    newValue) -> runLaterIfNotFXApplicationThread(() -> currentStatedInferredOptionProperty
                            .set((StatedInferredOptions) newValue.getUserData())));
}