List of usage examples for javafx.scene.control ToggleGroup getSelectedToggle
public final Toggle getSelectedToggle()
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);//w ww. ja va 2s. co 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) { stage.setTitle("Menu Sample"); Scene scene = new Scene(new VBox(), 400, 350); scene.setFill(Color.OLDLACE); name.setFont(new Font("Verdana Bold", 22)); binName.setFont(new Font("Arial Italic", 10)); pic.setFitHeight(150);/*from w w w . ja va 2 s .co m*/ pic.setPreserveRatio(true); description.setWrapText(true); description.setTextAlignment(TextAlignment.JUSTIFY); shuffle(); MenuBar menuBar = new MenuBar(); // --- Graphical elements final VBox vbox = new VBox(); vbox.setAlignment(Pos.CENTER); vbox.setSpacing(10); vbox.setPadding(new Insets(0, 10, 0, 10)); vbox.getChildren().addAll(name, binName, pic, description); // --- Menu File Menu menuFile = new Menu("File"); MenuItem add = new MenuItem("Shuffle", new ImageView(new Image("src/menusample/new.png"))); add.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { shuffle(); vbox.setVisible(true); } }); MenuItem clear = new MenuItem("Clear"); clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X")); clear.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { vbox.setVisible(false); } }); MenuItem exit = new MenuItem("Exit"); exit.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { System.exit(0); } }); menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit); // --- Menu Edit Menu menuEdit = new Menu("Edit"); Menu menuEffect = new Menu("Picture Effect"); final ToggleGroup groupEffect = new ToggleGroup(); for (Entry effect : effects) { RadioMenuItem itemEffect = new RadioMenuItem((String) effect.getKey()); itemEffect.setUserData(effect.getValue()); itemEffect.setToggleGroup(groupEffect); menuEffect.getItems().add(itemEffect); } final MenuItem noEffects = new MenuItem("No Effects"); noEffects.setDisable(true); noEffects.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { pic.setEffect(null); groupEffect.getSelectedToggle().setSelected(false); noEffects.setDisable(true); } }); groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() { public void changed(ObservableValue ov, Toggle old_toggle, Toggle new_toggle) { if (groupEffect.getSelectedToggle() != null) { Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData(); pic.setEffect(effect); noEffects.setDisable(false); } else { noEffects.setDisable(true); } } }); menuEdit.getItems().addAll(menuEffect, noEffects); // --- Menu View Menu menuView = new Menu("View"); CheckMenuItem titleView = createMenuItem("Title", name); CheckMenuItem binNameView = createMenuItem("Binomial name", binName); CheckMenuItem picView = createMenuItem("Picture", pic); CheckMenuItem descriptionView = createMenuItem("Decsription", description); menuView.getItems().addAll(titleView, binNameView, picView, descriptionView); menuBar.getMenus().addAll(menuFile, menuEdit, menuView); // --- Context Menu final ContextMenu cm = new ContextMenu(); MenuItem cmItem1 = new MenuItem("Copy Image"); cmItem1.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putImage(pic.getImage()); clipboard.setContent(content); } }); cm.getItems().add(cmItem1); pic.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { if (e.getButton() == MouseButton.SECONDARY) cm.show(pic, e.getScreenX(), e.getScreenY()); } }); ((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox); stage.setScene(scene); stage.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);//w w w.j ava 2s .co 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:fruitproject.FruitProject.java
public void first(final Stage primaryStage) { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);/*from w ww . ja v a2s. c om*/ 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);//from w w w .j a v a 2 s.c o 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:FeeBooster.java
private GridPane cpfpGrid(Transaction tx) { // Setup Grid GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER);/*from w w w.j a v a 2 s . com*/ 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:editeurpanovisu.EditeurPanovisu.java
/** * * @param iLargeur//from ww w . j a v a 2 s. co 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); } }); }