Example usage for javafx.scene.control RadioButton setUserData

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

Introduction

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

Prototype

public void setUserData(Object value) 

Source Link

Document

Convenience method for setting a single Object property that can be retrieved at a later date.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(250);//  ww  w .  j a va  2 s  . c o  m
    stage.setHeight(150);

    final ToggleGroup group = new ToggleGroup();

    RadioButton rb1 = new RadioButton("A");
    rb1.setToggleGroup(group);
    rb1.setUserData("A");

    RadioButton rb2 = new RadioButton("B");
    rb2.setToggleGroup(group);
    rb2.setUserData("B");

    RadioButton rb3 = new RadioButton("C");
    rb3.setToggleGroup(group);
    rb3.setUserData("C");

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (group.getSelectedToggle() != null) {
                System.out.println(group.getSelectedToggle().getUserData().toString());
            }
        }
    });

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    vbox.getChildren().add(rb1);
    vbox.getChildren().add(rb2);
    vbox.getChildren().add(rb3);
    vbox.setSpacing(10);

    hbox.getChildren().add(vbox);
    hbox.setSpacing(50);
    hbox.setPadding(new Insets(20, 10, 10, 20));

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Radio Button Sample");
    stage.setWidth(250);//from ww  w  . ja v  a2s.c o  m
    stage.setHeight(150);

    final ToggleGroup group = new ToggleGroup();

    RadioButton rb1 = new RadioButton("A");
    rb1.setToggleGroup(group);
    rb1.setUserData("A");

    RadioButton rb2 = new RadioButton("B");
    rb2.setToggleGroup(group);
    rb2.setUserData("B");

    RadioButton rb3 = new RadioButton("C");
    rb3.setToggleGroup(group);
    rb3.setUserData("C");

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
            if (group.getSelectedToggle() != null) {
                System.out.println(group.getSelectedToggle().getUserData().toString());
            }
        }
    });

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    vbox.getChildren().add(rb1);
    vbox.getChildren().add(rb2);
    vbox.getChildren().add(rb3);
    vbox.setSpacing(10);

    hbox.getChildren().add(vbox);
    hbox.setSpacing(50);
    hbox.setPadding(new Insets(20, 10, 10, 20));

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

From source file:fruitproject.FruitProject.java

public void first(final Stage primaryStage) {
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);/*  w ww  .  j  ava 2  s . co  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:boundary.GraphPane.java

private HBox addTransformingModeOptions() {
    HBox hBox = new HBox();

    hBox.setPadding(new Insets(15, 12, 15, 12));
    hBox.setSpacing(10);//from   www. j a  v a2  s.  c  o m
    hBox.setStyle("-fx-background-color: #66FFFF;");

    final ToggleGroup optionGroup = new ToggleGroup();

    Label lblMouseMode = new Label("Mouse Mode: ");
    lblMouseMode.setPrefSize(100, 20);

    RadioButton rbTransform = new RadioButton("Pan & Zoom");
    rbTransform.setPrefSize(100, 20);
    rbTransform.setToggleGroup(optionGroup);
    rbTransform.setUserData("T");
    rbTransform.setSelected(true);

    RadioButton rbPick = new RadioButton("Picking");
    rbPick.setPrefSize(100, 20);
    rbPick.setUserData("P");
    rbPick.setToggleGroup(optionGroup);

    optionGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {

        @Override
        public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
            if (optionGroup.getSelectedToggle() != null) {
                DefaultModalGraphMouse dmg = (DefaultModalGraphMouse) vv.getGraphMouse();

                if (optionGroup.getSelectedToggle().getUserData().equals("T")) {
                    dmg.setMode(Mode.TRANSFORMING);
                } else if (optionGroup.getSelectedToggle().getUserData().equals("P")) {
                    dmg.setMode(Mode.PICKING);
                }
            }

        }
    });

    hBox.getChildren().addAll(lblMouseMode, rbTransform, rbPick);

    return hBox;

}

From source file:FeeBooster.java

private GridPane rbfGrid(Transaction tx) {
    // Setup grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from www  . jav  a 2  s  .  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:FeeBooster.java

private GridPane cpfpGrid(Transaction tx) {
    // Setup Grid
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);/*from  w  ww . j a v  a 2  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:de.dkfz.roddy.client.fxuiclient.RoddyUIController.java

/**
 * Called when the selected project is changed.
 *//*w w w. j av a2  s  . c  o  m*/
private void changeSelectedProject(final FXICCWrapper pWrapper) {
    projectDatasetAccordion.setExpandedPane(tpDatasets);

    RoddyUITask.runTask(new RoddyUITask<Void>(UIConstants.UITASK_CHANGE_PROJECT) {
        List<String> analysesList = null;

        @Override
        public Void _call() throws Exception {
            long t1 = ExecutionService.measureStart();
            currentProjectWrapper = pWrapper;
            currentProject = pWrapper.getID();
            long t2 = ExecutionService.measureStart();

            ExecutionService.measureStop(t2, UIConstants.UITASK_MP_LOADCONFIGURATION);

            analysesList = currentProjectWrapper.getICC().getListOfAnalyses();

            cleanRMIPool();

            ExecutionService.measureStop(t2, UIConstants.UITASK_MP_LOAD_ANALYSIS_LIST);
            return null;
        }

        @Override
        public void _succeeded() {

            vboxAvailableAnalyses.getChildren().clear();
            ToggleGroup tgAnalyses = new ToggleGroup();

            for (String analysis : analysesList) {
                List fullAnalysisID = ProjectFactory.dissectFullAnalysisID(analysis);
                String id = analysis.split("[:][:]")[0];
                String plugin = fullAnalysisID.size() > 0 ? "\n - " + fullAnalysisID.get(0).toString() : "";

                RadioButton rb = new RadioButton(id + plugin);
                rb.setUserData(analysis);
                rb.setToggleGroup(tgAnalyses);
                vboxAvailableAnalyses.getChildren().add(rb);
            }
            tgAnalyses.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
                @Override
                public void changed(ObservableValue<? extends Toggle> observableValue, Toggle toggle,
                        Toggle toggle2) {
                    changeSelectedAnalysis((String) toggle2.getUserData());
                }
            });

            if (analysesList.size() == 1) {
                tgAnalyses.getToggles().get(0).setSelected(true);
            }
        }
    });
}

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 {/*  w  w  w.j ava2 s. c  o  m*/
            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())));
}

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");
            }/*  w  w w . ja  v  a  2s .  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:editeurpanovisu.EditeurPanovisu.java

/**
 *
 * @param iLargeur/*from   w w  w .j  av  a 2 s  .  c o m*/
 * @param iHauteur
 * @param bMasqueZones
 */
private static void ajouterZone(int iLargeur, int iHauteur, boolean bMasqueZones) {
    if (iNombreZones == -1) {
        iNombreZones = 0;
    }
    final ZoneTelecommande zone = new ZoneTelecommande();
    strTypeZone = "poly";
    zone.setStrTypeZone(strTypeZone);
    iNombrePointsZone = 0;
    bRecommenceZone = false;
    apZoneBarrePersonnalisee.getChildren().clear();
    Button btnAnnuler = new Button(rbLocalisation.getString("main.annuler"),
            new ImageView(new Image("file:" + getStrRepertAppli() + "/images/annule.png")));
    Button btnValider = new Button(rbLocalisation.getString("main.valider"),
            new ImageView(new Image("file:" + getStrRepertAppli() + "/images/valide.png")));
    btnValider.setLayoutX(180);
    btnValider.setLayoutY(170);
    btnAnnuler.setLayoutX(80);
    btnAnnuler.setLayoutY(170);
    ToggleGroup tgTypeZone = new ToggleGroup();
    Label lblTypeZone = new Label(rbLocalisation.getString("main.typeZone"));
    lblTypeZone.setLayoutX(20);
    lblTypeZone.setLayoutY(10);

    RadioButton rbCercleZone = new RadioButton(rbLocalisation.getString("main.cercle"));
    rbCercleZone.setLayoutX(20);
    rbCercleZone.setLayoutY(40);
    rbCercleZone.setUserData("circle");
    rbCercleZone.setToggleGroup(tgTypeZone);
    RadioButton rbRectZone = new RadioButton(rbLocalisation.getString("main.rectangle"));
    rbRectZone.setLayoutX(120);
    rbRectZone.setLayoutY(40);
    rbRectZone.setUserData("rect");
    rbRectZone.setToggleGroup(tgTypeZone);
    RadioButton rbPolyZone = new RadioButton(rbLocalisation.getString("main.polygone"));
    rbPolyZone.setLayoutX(220);
    rbPolyZone.setLayoutY(40);
    rbPolyZone.setUserData("poly");
    rbPolyZone.setToggleGroup(tgTypeZone);
    rbPolyZone.setSelected(true);
    ComboBox cbTouchesBarre = new ComboBox();
    cbTouchesBarre.getItems().clear();
    for (int i = 0; i < strTouchesBarre.length; i++) {
        cbTouchesBarre.getItems().add(i, strTouchesBarre[i]);
    }
    cbTouchesBarre.setLayoutX(50);
    cbTouchesBarre.setLayoutY(110);

    afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
    AnchorPane apCreeZone = new AnchorPane();
    apCreeZone.setStyle("-fx-background-color : rgba(0,0,0,0.1)");
    apCreeZone.setPrefWidth(imgBarrePersonnalisee.getWidth());
    apCreeZone.setPrefHeight(imgBarrePersonnalisee.getHeight());
    apCreeZone.setCursor(Cursor.CROSSHAIR);
    apImgBarrePersonnalisee.getChildren().add(apCreeZone);
    apZoneBarrePersonnalisee.getChildren().addAll(lblTypeZone, rbCercleZone, rbRectZone, rbPolyZone,
            cbTouchesBarre, btnAnnuler, btnValider);
    apCreeZone.setOnMouseClicked((t) -> {
        rbCercleZone.setDisable(true);
        rbRectZone.setDisable(true);
        rbPolyZone.setDisable(true);
        iNombrePointsZone++;
        switch (strTypeZone) {
        case "rect":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                x1Zone = t.getX();
                y1Zone = t.getY();
                Circle cercle = new Circle(t.getX(), t.getY(), 4);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
            }
            if (iNombrePointsZone == 2) {
                apCreeZone.getChildren().clear();
                Rectangle rect = new Rectangle(x1Zone, y1Zone, t.getX() - x1Zone, t.getY() - y1Zone);
                rect.setFill(Color.rgb(255, 0, 0, 0.5));
                rect.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(rect);
                String chaine = Math.round(x1Zone * 10) / 10 + "," + Math.round(y1Zone * 10) / 10 + ","
                        + Math.round(t.getX() * 10) / 10 + "," + Math.round(t.getY() * 10) / 10;
                zone.setStrCoordonneesZone(chaine);
                iNombrePointsZone = 0;
            }
            break;
        case "circle":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                x1Zone = t.getX();
                y1Zone = t.getY();
                Circle cercle = new Circle(t.getX(), t.getY(), 4);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
            }
            if (iNombrePointsZone == 2) {
                apCreeZone.getChildren().clear();
                double rayon = Math.sqrt(Math.pow(x1Zone - t.getX(), 2.d) + Math.pow(y1Zone - t.getY(), 2.d));
                Circle cercle = new Circle(x1Zone, y1Zone, rayon);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
                String chaine = Math.round(x1Zone * 10) / 10 + "," + Math.round(y1Zone * 10) / 10 + ","
                        + Math.round(rayon * 10) / 10;
                zone.setStrCoordonneesZone(chaine);
                iNombrePointsZone = 0;
            }
            break;
        case "poly":
            if (bRecommenceZone) {
                bRecommenceZone = false;
                iNombrePointsZone = 1;
            }
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                x1Zone = t.getX();
                y1Zone = t.getY();
                Circle cercle = new Circle(t.getX(), t.getY(), 4);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
                pointsPolyZone[(iNombrePointsZone - 1) * 2] = t.getX();
                pointsPolyZone[(iNombrePointsZone - 1) * 2 + 1] = t.getY();
            }
            if (iNombrePointsZone == 2) {
                apCreeZone.getChildren().clear();
                Line ligne = new Line(x1Zone, y1Zone, t.getX(), t.getY());
                ligne.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(ligne);
                pointsPolyZone[(iNombrePointsZone - 1) * 2] = t.getX();
                pointsPolyZone[(iNombrePointsZone - 1) * 2 + 1] = t.getY();
            }
            if (iNombrePointsZone > 2) {
                pointsPolyZone[(iNombrePointsZone - 1) * 2] = t.getX();
                pointsPolyZone[(iNombrePointsZone - 1) * 2 + 1] = t.getY();
                apCreeZone.getChildren().clear();
                Polygon poly = new Polygon();
                for (int i = 0; i < iNombrePointsZone; i++) {
                    poly.getPoints().addAll(pointsPolyZone[i * 2], pointsPolyZone[i * 2 + 1]);
                }
                poly.setFill(Color.rgb(255, 0, 0, 0.5));
                poly.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(poly);
            }
            if (t.getClickCount() == 2) {
                String chaine = "";
                for (int i = 0; i < iNombrePointsZone; i++) {
                    if (i != 0) {
                        chaine += ",";
                    }
                    chaine += Math.round(pointsPolyZone[i * 2] * 10) / 10 + ","
                            + Math.round(pointsPolyZone[i * 2 + 1] * 10) / 10;
                }
                zone.setStrCoordonneesZone(chaine);
                bRecommenceZone = true;
            }
            break;
        }
    });

    apCreeZone.setOnMouseMoved((t) -> {
        switch (strTypeZone) {
        case "rect":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                Rectangle rect = new Rectangle(x1Zone, y1Zone, t.getX() - x1Zone, t.getY() - y1Zone);
                rect.setFill(Color.rgb(255, 0, 0, 0.5));
                rect.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(rect);
            }
            break;
        case "circle":
            if (iNombrePointsZone == 1) {
                apCreeZone.getChildren().clear();
                double rayon = Math.sqrt(Math.pow(x1Zone - t.getX(), 2.d) + Math.pow(y1Zone - t.getY(), 2.d));
                Circle cercle = new Circle(x1Zone, y1Zone, rayon);
                cercle.setFill(Color.rgb(255, 0, 0, 0.5));
                cercle.setStroke(Color.YELLOW);
                apCreeZone.getChildren().add(cercle);
            }
            break;
        case "poly":
            if (!bRecommenceZone) {
                if (iNombrePointsZone == 1) {
                    apCreeZone.getChildren().clear();
                    Line ligne = new Line(x1Zone, y1Zone, t.getX(), t.getY());
                    ligne.setStroke(Color.YELLOW);
                    apCreeZone.getChildren().add(ligne);
                }
                if (iNombrePointsZone > 1) {
                    apCreeZone.getChildren().clear();
                    Polygon poly = new Polygon();
                    for (int i = 0; i < iNombrePointsZone; i++) {
                        poly.getPoints().addAll(pointsPolyZone[i * 2], pointsPolyZone[i * 2 + 1]);
                    }
                    poly.getPoints().addAll(t.getX(), t.getY());
                    poly.setFill(Color.rgb(255, 0, 0, 0.5));
                    poly.setStroke(Color.YELLOW);
                    apCreeZone.getChildren().add(poly);
                }
            }
            break;
        }
    });

    btnValider.setOnMouseClicked((t) -> {
        if (strTypeZone.equals("poly")) {
            String strChaine = "";
            for (int i = 0; i < iNombrePointsZone; i++) {
                if (i != 0) {
                    strChaine += ",";
                }
                strChaine += Math.round(pointsPolyZone[i * 2] * 10) / 10 + ","
                        + Math.round(pointsPolyZone[i * 2 + 1] * 10) / 10;
            }
            zone.setStrCoordonneesZone(strChaine);

        }
        zones[iNombreZones] = zone;
        iNombreZones++;
        afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
        btnAjouteZone.setDisable(false);
    });

    btnAnnuler.setOnMouseClicked((t) -> {
        afficheBarrePersonnalisee(iLargeur, iHauteur, bMasqueZones);
        btnAjouteZone.setDisable(false);
    });

    cbTouchesBarre.valueProperty().addListener((ov, strAncienneValeur, strNouvelleValeur) -> {
        if (strNouvelleValeur != null) {
            String strId = strCodeBarre[cbTouchesBarre.getSelectionModel().getSelectedIndex()];
            zone.setStrIdZone(strId);
        }
    });

    tgTypeZone.selectedToggleProperty()
            .addListener((ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) -> {
                if (tgTypeZone.getSelectedToggle() != null) {
                    strTypeZone = tgTypeZone.getSelectedToggle().getUserData().toString();
                    zone.setStrTypeZone(strTypeZone);
                }
            });

}