List of usage examples for javafx.scene.layout Pane getPrefHeight
public final double getPrefHeight()
From source file:cz.lbenda.rcp.DialogHelper.java
public void openWindowInCenterOfStage(Stage parentStage, Pane pane, String title) { Stage stage = new Stage(); stage.setTitle(title);/*from w w w . j a v a 2s .co m*/ stage.setScene(new Scene(pane, pane.getPrefWidth(), pane.getPrefHeight())); stage.getIcons().addAll(parentStage.getIcons()); stage.show(); stage.setX(parentStage.getX() + (parentStage.getWidth() - stage.getWidth()) / 2); stage.setY(parentStage.getY() + (parentStage.getHeight() - stage.getHeight()) / 2); }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param iNumHS/*from w w w. j a va 2 s . c o m*/ * @return */ private static AnchorPane apAfficherListePanosVignettes(int iNumHS) { NavigateurPanoramique navigateurPano2; AnchorPane apVisuPanoHS; iNumeroPanoChoisitHS = -1; if (!getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getStrFichierXML().equals("")) { for (int ii1 = 0; ii1 < getiNombrePanoramiques(); ii1++) { String strFichPano = getPanoramiquesProjet()[ii1].getStrNomFichier(); String strNomXMLFile = strFichPano .substring(strFichPano.lastIndexOf(File.separator) + 1, strFichPano.length()) .split("\\.")[0] + ".xml"; if (strNomXMLFile .equals(getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getStrFichierXML())) { iNumeroPanoChoisitHS = ii1; strNomPanoChoisitHS = getPanoramiquesProjet()[ii1].getStrNomFichier(); } } navigateurPano2 = new NavigateurPanoramique( getPanoramiquesProjet()[iNumeroPanoChoisitHS].getImgVisuPanoramique(), 0, 0, 400, 200, true); if (getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getRegardX() != -1000) { navigateurPano2.setChoixLongitude( getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getRegardX()); } else { navigateurPano2.setChoixLongitude(0); } navigateurPano2.setLongitude(navigateurPano2.getChoixLongitude()); if (getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getRegardY() != -1000) { navigateurPano2.setChoixLatitude( getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getRegardY()); } else { navigateurPano2.setChoixLatitude(0); } navigateurPano2.setLatitude(navigateurPano2.getChoixLatitude()); if (getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getChampVisuel() != 0) { navigateurPano2 .setChoixFov(getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).getChampVisuel()); } else { navigateurPano2.setChoixFov(50); } navigateurPano2.setFov(navigateurPano2.getChoixFov()); apVisuPanoHS = navigateurPano2.affichePano(); apVisuPanoHS.setDisable(false); } else { navigateurPano2 = new NavigateurPanoramique( getPanoramiquesProjet()[getiPanoActuel()].getImgVisuPanoramique(), 0, 0, 400, 200, true); apVisuPanoHS = navigateurPano2.affichePano(); apVisuPanoHS.setDisable(true); } AnchorPane aplistePano = new AnchorPane(); aplistePano.setOpacity(1); Pane paneFond = new Pane(); paneFond.setOnMouseClicked((mouseEvent) -> { mouseEvent.consume(); }); paneFond.setStyle("-fx-background-color : #bbb;"); paneFond.setPrefWidth(540); paneFond.setPrefHeight(((getiNombrePanoramiques() - 2) / 4 + 1) * 65 + 10 + 320); paneFond.setMinWidth(540); paneFond.setMinHeight(70); aplistePano.getChildren().add(paneFond); aplistePano.setStyle("-fx-backgroung-color : #bbb;"); int ij = 0; ImageView[] ivPano; ivPano = new ImageView[getiNombrePanoramiques()]; double xPos; double yPos; int iRow = 0; Button btnValide = new Button("Ok"); btnValide.setPrefWidth(80); btnValide.setLayoutX(paneFond.getPrefWidth() - 100); btnValide.setLayoutY(paneFond.getPrefHeight() - 30); paneFond.getChildren().add(btnValide); btnValide.setOnMouseClicked((mouseEvent) -> { if (iNumeroPanoChoisitHS != -1) { panePanoramique.setCursor(Cursor.CROSSHAIR); panePanoramique.setOnMouseClicked((me1) -> { gereSourisPanoramique(me1); }); setStrPanoListeVignette(strNomPanoChoisitHS); if (getPanoramiquesProjet()[iNumeroPanoChoisitHS].getStrTitrePanoramique() != null) { String strTexteHS = getPanoramiquesProjet()[iNumeroPanoChoisitHS].getStrTitrePanoramique(); TextField tfTxtHS = (TextField) vbOutils.lookup("#txtHS" + iNumHS); tfTxtHS.setText(strTexteHS); } double latitude = Math.round(navigateurPano2.getChoixLatitude() * 10) / 10.d; double longitude = Math.round(navigateurPano2.getChoixLongitude() * 10) / 10.d - 180; double fov = Math.round(navigateurPano2.getChoixFov() * 10) / 10.d; longitude = longitude % 360; longitude = longitude < 0 ? longitude + 360 : longitude; longitude = longitude > 180 ? longitude - 360 : longitude; getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).setNumeroPano(iNumeroPanoChoisitHS); getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).setRegardX(longitude - 180); getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).setRegardY(latitude); getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS).setChampVisuel(fov); getPanoramiquesProjet()[getiPanoActuel()].getHotspot(iNumHS) .setImgVueHs(navigateurPano2.getImgVignetteHS()); ComboBox cbPanos = (ComboBox) vbOutils.lookup("#cbpano" + iNumHS); cbPanos.getSelectionModel().select(iNumeroPanoChoisitHS); aplistePano.setVisible(false); } mouseEvent.consume(); }); for (int i = 0; i < getiNombrePanoramiques(); i++) { int iNumeroPano1 = i; String strNomPano = getPanoramiquesProjet()[i].getStrNomFichier(); ivPano[ij] = new ImageView(getPanoramiquesProjet()[i].getImgVignettePanoramique()); ivPano[ij].setFitWidth(120); ivPano[ij].setFitHeight(60); ivPano[ij].setSmooth(true); int iCol = ij % 4; iRow = ij / 4; xPos = iCol * 130 + 25; yPos = iRow * 65 + 15; ivPano[ij].setLayoutX(xPos); ivPano[ij].setLayoutY(yPos); ivPano[ij].setCursor(Cursor.HAND); ivPano[ij].setStyle("-fx-background-color : #ccc;"); Tooltip tltpPano = new Tooltip( strNomPano.substring(strNomPano.lastIndexOf(File.separator) + 1, strNomPano.lastIndexOf("."))); tltpPano.setStyle(getStrTooltipStyle()); Tooltip.install(ivPano[ij], tltpPano); ivPano[ij].setOnMouseClicked((mouseEvent) -> { iNumeroPanoChoisitHS = iNumeroPano1; strNomPanoChoisitHS = getPanoramiquesProjet()[iNumeroPanoChoisitHS].getStrNomFichier(); navigateurPano2.setImagePanoramique( getPanoramiquesProjet()[iNumeroPanoChoisitHS].getStrNomFichier(), getPanoramiquesProjet()[iNumeroPanoChoisitHS].getImgVisuPanoramique()); navigateurPano2.setLongitude(getPanoramiquesProjet()[iNumeroPanoChoisitHS].getRegardX() - 180); navigateurPano2.setLatitude(getPanoramiquesProjet()[iNumeroPanoChoisitHS].getRegardY()); navigateurPano2.setFov(getPanoramiquesProjet()[iNumeroPanoChoisitHS].getChampVisuel()); navigateurPano2.affiche(); apVisuPanoHS.setDisable(false); }); aplistePano.getChildren().add(ivPano[ij]); ij++; } int iTaille = (iRow + 1) * 65 + 5; apVisuPanoHS.setLayoutY(iTaille + 10); iTaille += 320; apVisuPanoHS.setLayoutX((540 - apVisuPanoHS.getPrefWidth()) / 2.d); aplistePano.setPrefWidth(540); aplistePano.setPrefHeight(iTaille); aplistePano.setMinWidth(540); aplistePano.setMinHeight(iTaille); aplistePano.getChildren().add(apVisuPanoHS); ImageView ivClose = new ImageView( new Image("file:" + getStrRepertAppli() + File.separator + "images/ferme.png", 20, 20, true, true)); ivClose.setLayoutX(2); ivClose.setLayoutY(5); ivClose.setCursor(Cursor.HAND); aplistePano.getChildren().add(ivClose); ivClose.setOnMouseClicked((mouseEvent) -> { panePanoramique.setCursor(Cursor.CROSSHAIR); panePanoramique.setOnMouseClicked((mouseEvent1) -> { gereSourisPanoramique(mouseEvent1); }); setStrPanoListeVignette(""); aplistePano.setVisible(false); mouseEvent.consume(); }); return aplistePano; }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param X/*from w w w.j av a 2s . c o m*/ * @param Y */ private static void panoAjouteHTML(double X, double Y) { if (X > 0 && X < ivImagePanoramique.getFitWidth()) { valideHS(); setbDejaSauve(false); getStPrincipal().setTitle(getStPrincipal().getTitle().replace(" *", "") + " *"); double mouseX = X; double mouseY = Y - panePanoramique.getLayoutY() - 130 - getiDecalageMac(); double longitude, latitude; double largeur = ivImagePanoramique.getFitWidth(); longitude = 360.0f * mouseX / largeur - 180; latitude = 90.0d - 2.0f * mouseY / largeur * 180.0f; Circle circPoint = new Circle(mouseX + ivImagePanoramique.getLayoutX(), mouseY, 5); circPoint.setFill(Color.DARKGREEN); circPoint.setStroke(Color.YELLOWGREEN); circPoint.setId("html" + getiNumHTML()); circPoint.setCursor(Cursor.DEFAULT); panePanoramique.getChildren().add(circPoint); Tooltip tltpImage = new Tooltip("HTML n " + (getiNumHTML() + 1)); tltpImage.setStyle(getStrTooltipStyle()); Tooltip.install(circPoint, tltpImage); EditeurHTML editHTML = new EditeurHTML(); HotspotHTML HS = new HotspotHTML(); editHTML.setHsHTML(HS); HS.setLongitude(longitude); HS.setLatitude(latitude); Rectangle2D tailleEcran = Screen.getPrimary().getBounds(); int iHauteur = (int) tailleEcran.getHeight() - 100; int iLargeur = (int) tailleEcran.getWidth() - 100; editHTML.affiche(iLargeur, iHauteur); editHTML.addPropertyChangeListener("bValide", (e) -> { if (e.getNewValue().toString().equals("true")) { setiNumHTML(getiNumHTML() + 1); getPanoramiquesProjet()[getiPanoActuel()].addHotspotHTML(editHTML.getHsHTML()); retireAffichageHotSpots(); dejaCharge = false; Pane affHS1 = paneAffichageHS(strListePano(), getiPanoActuel()); affHS1.setId("labels"); vbVisuHotspots.getChildren().add(affHS1); spPanneauOutils.setVvalue(spPanneauOutils.getVvalue() + 145); } }); editHTML.addPropertyChangeListener("bAnnule", (e) -> { if (e.getNewValue().toString().equals("true")) { String strPoint = circPoint.getId(); strPoint = strPoint.substring(4, strPoint.length()); Node nodeImage = (Node) panePanoramique.lookup("#html" + strPoint); panePanoramique.getChildren().remove(nodeImage); } }); valideHS(); circPoint.setOnDragDetected((mouseEvent1) -> { circPoint.setFill(Color.YELLOWGREEN); circPoint.setStroke(Color.DARKGREEN); bDragDrop = true; mouseEvent1.consume(); }); circPoint.setOnMouseDragged((mouseEvent1) -> { double XX = mouseEvent1.getX() - ivImagePanoramique.getLayoutX(); if (XX < 0) { XX = 0; } if (XX > ivImagePanoramique.getFitWidth()) { XX = ivImagePanoramique.getFitWidth(); } circPoint.setCenterX(XX + ivImagePanoramique.getLayoutX()); double YY = mouseEvent1.getY(); if (YY < 0) { YY = 0; } if (YY > ivImagePanoramique.getFitHeight()) { YY = ivImagePanoramique.getFitHeight(); } circPoint.setCenterY(YY); afficheLoupe(XX, YY); mouseEvent1.consume(); }); circPoint.setOnMouseReleased((mouseEvent1) -> { setbDejaSauve(false); getStPrincipal().setTitle(getStPrincipal().getTitle().replace(" *", "") + " *"); String strPoint = circPoint.getId(); strPoint = strPoint.substring(4, strPoint.length()); int iNumeroPoint = Integer.parseInt(strPoint); double X1 = mouseEvent1.getSceneX(); double Y1 = mouseEvent1.getSceneY(); double mouseX1 = X1 - ivImagePanoramique.getLayoutX(); if (mouseX1 < 0) { mouseX1 = 0; } if (mouseX1 > ivImagePanoramique.getFitWidth()) { mouseX1 = ivImagePanoramique.getFitWidth(); } double mouseY1 = Y1 - panePanoramique.getLayoutY() - 130 - getiDecalageMac(); if (mouseY1 < 0) { mouseY1 = 0; } if (mouseY1 > ivImagePanoramique.getFitHeight()) { mouseY1 = ivImagePanoramique.getFitHeight(); } double longit, lat; double larg = ivImagePanoramique.getFitWidth(); longit = 360.0f * mouseX1 / larg - 180; lat = 90.0d - 2.0f * mouseY1 / larg * 180.0f; getPanoramiquesProjet()[getiPanoActuel()].getHotspotHTML(iNumeroPoint).setLatitude(lat); getPanoramiquesProjet()[getiPanoActuel()].getHotspotHTML(iNumeroPoint).setLongitude(longit); circPoint.setFill(Color.DARKGREEN); circPoint.setStroke(Color.YELLOWGREEN); mouseEvent1.consume(); }); circPoint.setOnMouseClicked((mouseEvent1) -> { String strPoint = circPoint.getId(); strPoint = strPoint.substring(4, strPoint.length()); int iNum = Integer.parseInt(strPoint); if (mouseEvent1.isControlDown()) { setbDejaSauve(false); getStPrincipal().setTitle(getStPrincipal().getTitle().replace(" *", "") + " *"); Node nodeImage; nodeImage = (Node) panePanoramique.lookup("#html" + strPoint); panePanoramique.getChildren().remove(nodeImage); for (int io = iNum + 1; io < getiNumHTML(); io++) { nodeImage = (Node) panePanoramique.lookup("#html" + Integer.toString(io)); nodeImage.setId("html" + Integer.toString(io - 1)); } /** * on retire les anciennes indication de HS */ retireAffichageHotSpots(); setiNumHTML(getiNumHTML() - 1); getPanoramiquesProjet()[getiPanoActuel()].removeHotspotHTML(iNum); /** * On les cre les nouvelles */ ajouteAffichageHotspots(); } else { if (!bDragDrop) { setbDejaSauve(false); getStPrincipal().setTitle(getStPrincipal().getTitle().replace(" *", "") + " *"); EditeurHTML editHTML1 = new EditeurHTML(); HotspotHTML HS1 = getPanoramiquesProjet()[getiPanoActuel()].getHotspotHTML(iNum); editHTML1.setHsHTML(HS1); Rectangle2D tailleEcran1 = Screen.getPrimary().getBounds(); int iHauteur1 = (int) tailleEcran1.getHeight() - 100; int iLargeur1 = (int) tailleEcran1.getWidth() - 100; editHTML1.affiche(iLargeur1, iHauteur1); editHTML1.addPropertyChangeListener("bValide", (ev) -> { if (ev.getNewValue().toString().equals("true")) { getPanoramiquesProjet()[getiPanoActuel()].setHotspotHTML(editHTML1.getHsHTML(), iNum); retireAffichageHotSpots(); dejaCharge = false; Pane affHS1 = paneAffichageHS(strListePano(), getiPanoActuel()); affHS1.setId("labels"); vbVisuHotspots.getChildren().add(affHS1); apVisuHS.setPrefHeight(affHS1.getPrefHeight()); } }); } else { bDragDrop = false; } mouseEvent1.consume(); } valideHS(); mouseEvent1.consume(); }); } }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param strLstPano/* w ww .j av a 2 s . co m*/ * @param iNumPano * @return */ public static Pane paneAffichageHS(String strLstPano, int iNumPano) { Pane paneHotSpots = new Pane(); paneHotSpots.setTranslateY(10); paneHotSpots.setTranslateX(10); VBox vbHotspots = new VBox(5); paneHotSpots.getChildren().add(vbHotspots); Label lblPoint; int io; for (io = 0; io < getPanoramiquesProjet()[iNumPano].getNombreHotspots(); io++) { Label lblSep = new Label(" "); Label lblSep1 = new Label(" "); VBox vbPanneauHS = new VBox(); double deplacement = 0; vbPanneauHS.setLayoutX(deplacement); Pane paneHsPanoramique = new Pane(vbPanneauHS); paneHsPanoramique.setPrefHeight(300); paneHsPanoramique.setMinHeight(300); paneHsPanoramique.setMaxHeight(300); int iNum1 = io; Timeline timBouge = new Timeline(new KeyFrame(Duration.millis(500), (ActionEvent event) -> { Circle c1 = (Circle) panePanoramique.lookup("#point" + iNum1); if (c1 != null) { if (c1.getFill() == Color.RED) { c1.setFill(Color.YELLOW); c1.setStroke(Color.RED); } else { c1.setFill(Color.RED); c1.setStroke(Color.YELLOW); } } })); timBouge.setCycleCount(Timeline.INDEFINITE); timBouge.pause(); paneHsPanoramique.setOnMouseEntered((e) -> { timBouge.play(); }); paneHsPanoramique.setOnMouseExited((e) -> { timBouge.pause(); Circle c1 = (Circle) panePanoramique.lookup("#point" + iNum1); if (c1 != null) { c1.setFill(Color.YELLOW); c1.setStroke(Color.RED); } }); paneHsPanoramique .setStyle("-fx-border-color : #777777;-fx-border-width : 1px;-fx-border-radius : 3px;"); paneHsPanoramique.setId("HS" + io); lblPoint = new Label("Point #" + (io + 1)); lblPoint.setPadding(new Insets(5, 10, 5, 5)); lblPoint.setTranslateX(-deplacement); lblPoint.getStyleClass().add("titreOutil"); Separator sepHotspots = new Separator(Orientation.HORIZONTAL); sepHotspots.setTranslateX(-deplacement); sepHotspots.setPrefWidth(321); sepHotspots.setTranslateX(2); paneHsPanoramique.setPrefWidth(325); vbPanneauHS.getChildren().addAll(lblPoint, sepHotspots); if (strLstPano != null) { Label lblLien = new Label(rbLocalisation.getString("main.panoramiqueDestination")); lblLien.setTranslateX(10); ComboBox cbDestPano = new ComboBox(); String[] strListe = strLstPano.split(";"); cbDestPano.getItems().addAll(Arrays.asList(strListe)); int iNum11 = getPanoramiquesProjet()[iNumPano].getHotspot(io).getNumeroPano(); cbDestPano.setTranslateX(10); cbDestPano.setId("cbpano" + io); cbDestPano.getSelectionModel().select(iNum11); cbDestPano.getSelectionModel().selectedIndexProperty().addListener((ov, t, t1) -> { valideHS(); if (dejaCharge) { dejaCharge = false; retireAffichageHotSpots(); Pane affHS1 = paneAffichageHS(strListePano(), iNumPano); affHS1.setId("labels"); vbVisuHotspots.getChildren().add(affHS1); } }); if (iNum11 != -1) { int iNumPan = iNum11; ImageView ivAfficheVignettePano = new ImageView( getPanoramiquesProjet()[iNum11].getImgPanoRect()); ivAfficheVignettePano.setPreserveRatio(true); ivAfficheVignettePano.setFitWidth(300); ivAfficheVignettePano.setLayoutY(10); ivAfficheVignettePano.setCursor(Cursor.HAND); ivAfficheVignettePano.setOnMouseClicked((e) -> { affichePanoChoisit(iNumPan); }); AnchorPane apVisuVignettePano = new AnchorPane(ivAfficheVignettePano); apVisuVignettePano.setPrefHeight(170); apVisuVignettePano.setTranslateX(10); vbPanneauHS.getChildren().addAll(lblLien, cbDestPano, apVisuVignettePano, lblSep); } else { vbPanneauHS.getChildren().addAll(lblLien, cbDestPano, lblSep); } } Label lblTexteHS = new Label(rbLocalisation.getString("main.texteHotspot")); lblTexteHS.setTranslateX(10); TextField tfTexteHS = new TextField(); if (getPanoramiquesProjet()[iNumPano].getHotspot(io).getStrInfo() != null) { tfTexteHS.setText(getPanoramiquesProjet()[iNumPano].getHotspot(io).getStrInfo()); } tfTexteHS.textProperty().addListener((final ObservableValue<? extends String> observable, final String oldValue, final String newValue) -> { valideHS(); }); tfTexteHS.setId("txtHS" + io); tfTexteHS.setPrefSize(200, 25); tfTexteHS.setMaxSize(200, 20); tfTexteHS.setTranslateX(60); vbPanneauHS.getChildren().addAll(lblTexteHS, tfTexteHS, lblSep1); vbHotspots.getChildren().addAll(paneHsPanoramique, lblSep); } int iNbHS = io; int iTaillePane = io * 325; for (io = 0; io < getPanoramiquesProjet()[iNumPano].getNombreHotspotImage(); io++) { Label lblSep = new Label(" "); Label lblSep1 = new Label(" "); VBox vbPanneauHsImage = new VBox(); Pane paneHsImage = new Pane(vbPanneauHsImage); int iNum = io; Timeline timBouge = new Timeline(new KeyFrame(Duration.millis(500), (ActionEvent event) -> { Circle c1 = (Circle) panePanoramique.lookup("#img" + iNum); if (c1 != null) { if (c1.getFill() == Color.BLUE) { c1.setFill(Color.YELLOW); c1.setStroke(Color.BLUE); } else { c1.setFill(Color.BLUE); c1.setStroke(Color.YELLOW); } } })); timBouge.setCycleCount(Timeline.INDEFINITE); timBouge.pause(); paneHsImage.setOnMouseEntered((e) -> { timBouge.play(); }); paneHsImage.setOnMouseExited((e) -> { Circle c1 = (Circle) panePanoramique.lookup("#img" + iNum); if (c1 != null) { c1.setFill(Color.BLUE); c1.setStroke(Color.YELLOW); } timBouge.pause(); }); paneHsImage.setStyle("-fx-border-color : #777777;-fx-border-width : 1px;-fx-border-radius : 3px;"); paneHsImage.setId("HSImg" + io); lblPoint = new Label("Image #" + (io + 1)); lblPoint.setPadding(new Insets(5, 10, 5, 5)); lblPoint.getStyleClass().add("titreOutil"); Separator sepHS = new Separator(Orientation.HORIZONTAL); sepHS.setPrefWidth(321); sepHS.setTranslateX(2); paneHsImage.setPrefWidth(325); vbPanneauHsImage.getChildren().addAll(lblPoint, sepHS); Label lblLien = new Label(rbLocalisation.getString("main.imageChoisie")); lblLien.setTranslateX(10); String strF1XML = getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getStrLienImg(); Image imgChoisie = new Image( "file:" + getStrRepertTemp() + File.separator + "images" + File.separator + strF1XML); ImageView ivChoisie = new ImageView(imgChoisie); ivChoisie.setTranslateX(100); ivChoisie.setFitWidth(100); ivChoisie.setFitHeight(imgChoisie.getHeight() / imgChoisie.getWidth() * 100); vbPanneauHsImage.getChildren().addAll(lblLien, ivChoisie, lblSep); Label lblTexteHS = new Label(rbLocalisation.getString("main.texteHotspot")); lblTexteHS.setTranslateX(10); TextField tfTexteHS = new TextField(); if (getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getStrInfo() != null) { tfTexteHS.setText(getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getStrInfo()); } tfTexteHS.textProperty().addListener((final ObservableValue<? extends String> observable, final String oldValue, final String newValue) -> { valideHS(); }); tfTexteHS.setId("txtHSImage" + io); tfTexteHS.setPrefSize(200, 25); tfTexteHS.setMaxSize(200, 20); tfTexteHS.setTranslateX(60); vbPanneauHsImage.getChildren().addAll(lblTexteHS, tfTexteHS, lblSep1); Label lblCoulFond = new Label(rbLocalisation.getString("diapo.couleurFond")); lblCoulFond.setTranslateX(10); Label lblOpacite = new Label(rbLocalisation.getString("diapo.opacite")); lblOpacite.setTranslateX(10); if (getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getStrCouleurFond().equals("")) { getPanoramiquesProjet()[iNumPano].getHotspotImage(io).setStrCouleurFond( "#" + getGestionnaireInterface().getCouleurFondTheme().toString().substring(2, 8)); } ColorPicker cpCouleurFond = new ColorPicker( Color.valueOf(getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getStrCouleurFond())); if (getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getOpacite() == -1) { getPanoramiquesProjet()[iNumPano].getHotspotImage(io) .setOpacite(getGestionnaireInterface().getOpaciteTheme()); } cpCouleurFond.setTranslateX(100); int i = io; cpCouleurFond.valueProperty().addListener((ov, av, nv) -> { if (getiNombrePanoramiques() != 0) { setbDejaSauve(false); getStPrincipal().setTitle(getStPrincipal().getTitle().replace(" *", "") + " *"); } getPanoramiquesProjet()[iNumPano].getHotspotImage(i) .setStrCouleurFond("#" + cpCouleurFond.getValue().toString().substring(2, 8)); }); Slider slOpacite = new Slider(0, 1, getPanoramiquesProjet()[iNumPano].getHotspotImage(io).getOpacite()); slOpacite.valueProperty().addListener((ov, av, nv) -> { if (getiNombrePanoramiques() != 0) { setbDejaSauve(false); getStPrincipal().setTitle(getStPrincipal().getTitle().replace(" *", "") + " *"); } getPanoramiquesProjet()[iNumPano].getHotspotImage(i).setOpacite(slOpacite.getValue()); }); slOpacite.setTranslateX(100); slOpacite.setPrefWidth(130); slOpacite.setMinWidth(130); slOpacite.setMaxWidth(130); vbPanneauHsImage.getChildren().addAll(lblCoulFond, cpCouleurFond, lblOpacite, slOpacite); vbHotspots.getChildren().addAll(paneHsImage, lblSep); iTaillePane += 225 + ivChoisie.getFitHeight(); paneHsImage.setPrefHeight(200 + ivChoisie.getFitHeight()); paneHsImage.setMinHeight(200 + ivChoisie.getFitHeight()); paneHsImage.setMaxHeight(200 + ivChoisie.getFitHeight()); } iNbHS += io; for (io = 0; io < getPanoramiquesProjet()[iNumPano].getNombreHotspotHTML(); io++) { Label lblSep = new Label(" "); int iNum = io; VBox vbPanneauHS = new VBox(); Pane paneHsHtml = new Pane(vbPanneauHS); Timeline timBouge = new Timeline(new KeyFrame(Duration.millis(500), (ActionEvent event) -> { Circle c1 = (Circle) panePanoramique.lookup("#html" + iNum); if (c1 != null) { if (c1.getFill() == Color.DARKGREEN) { c1.setFill(Color.YELLOWGREEN); c1.setStroke(Color.DARKGREEN); } else { c1.setFill(Color.DARKGREEN); c1.setStroke(Color.YELLOWGREEN); } } })); timBouge.setCycleCount(Timeline.INDEFINITE); timBouge.pause(); paneHsHtml.setOnMouseEntered((e) -> { timBouge.play(); }); paneHsHtml.setOnMouseExited((e) -> { timBouge.pause(); Circle c1 = (Circle) panePanoramique.lookup("#html" + iNum); if (c1 != null) { c1.setFill(Color.DARKGREEN); c1.setStroke(Color.YELLOWGREEN); } }); paneHsHtml.setStyle("-fx-border-color : #777777;-fx-border-width : 1px;-fx-border-radius : 3px;"); paneHsHtml.setId("HSHTML" + io); lblPoint = new Label("Hotspot HTML #" + (io + 1)); lblPoint.setPadding(new Insets(5, 10, 5, 5)); lblPoint.getStyleClass().add("titreOutil"); Separator sepHS = new Separator(Orientation.HORIZONTAL); sepHS.setPrefWidth(321); sepHS.setTranslateX(2); paneHsHtml.setPrefWidth(325); Label lblTexteHS = new Label(rbLocalisation.getString("main.texteHotspot")); lblTexteHS.setTranslateX(10); TextField tfTexteHS = new TextField(); if (getPanoramiquesProjet()[iNumPano].getHotspotHTML(io).getStrInfo() != null) { tfTexteHS.setText(getPanoramiquesProjet()[iNumPano].getHotspotHTML(io).getStrInfo()); } tfTexteHS.textProperty().addListener((final ObservableValue<? extends String> observable, final String oldValue, final String newValue) -> { valideHS(); }); tfTexteHS.setId("txtHSHTML" + io); tfTexteHS.setPrefSize(200, 25); tfTexteHS.setMaxSize(200, 20); tfTexteHS.setTranslateX(60); vbPanneauHS.getChildren().addAll(lblPoint, sepHS, lblTexteHS, tfTexteHS); Button btnEditeHSHTML = new Button(rbLocalisation.getString("main.editeHTML")); btnEditeHSHTML.setPrefWidth(80); btnEditeHSHTML.setTranslateX(paneHsHtml.getPrefWidth() - btnEditeHSHTML.getPrefWidth() - 10); vbPanneauHS.getChildren().addAll(btnEditeHSHTML); btnEditeHSHTML.setOnAction((e) -> { EditeurHTML editHTML = new EditeurHTML(); HotspotHTML HS = getPanoramiquesProjet()[iNumPano].getHotspotHTML(iNum); editHTML.setHsHTML(HS); Rectangle2D tailleEcran = Screen.getPrimary().getBounds(); int iHauteur = (int) tailleEcran.getHeight() - 100; int iLargeur = (int) tailleEcran.getWidth() - 100; editHTML.affiche(iLargeur, iHauteur); editHTML.addPropertyChangeListener("bValide", (ev) -> { if (ev.getNewValue().toString().equals("true")) { getPanoramiquesProjet()[iNumPano].setHotspotHTML(editHTML.getHsHTML(), iNum); dejaCharge = false; retireAffichageHotSpots(); Pane affHS1 = paneAffichageHS(strListePano(), iNumPano); affHS1.setId("labels"); vbVisuHotspots.getChildren().add(affHS1); } }); }); vbHotspots.getChildren().addAll(paneHsHtml, lblSep); paneHsHtml.setPrefHeight(120); paneHsHtml.setMinHeight(120); paneHsHtml.setMaxHeight(120); iTaillePane += 145; } iNbHS += io; for (io = 0; io < getPanoramiquesProjet()[iNumPano].getiNombreHotspotDiapo(); io++) { Label lblSep = new Label(" "); int iNum = io; VBox vbPanneauHS = new VBox(); Pane paneHsDiapo = new Pane(vbPanneauHS); Timeline timBouge = new Timeline(new KeyFrame(Duration.millis(500), (ActionEvent event) -> { Circle c1 = (Circle) panePanoramique.lookup("#dia" + iNum); if (c1 != null) { if (c1.getFill() == Color.TURQUOISE) { c1.setFill(Color.ORANGE); c1.setStroke(Color.TURQUOISE); } else { c1.setFill(Color.TURQUOISE); c1.setStroke(Color.ORANGE); } } })); timBouge.setCycleCount(Timeline.INDEFINITE); timBouge.pause(); paneHsDiapo.setOnMouseEntered((e) -> { timBouge.play(); }); paneHsDiapo.setOnMouseExited((e) -> { timBouge.pause(); Circle c1 = (Circle) panePanoramique.lookup("#html" + iNum); if (c1 != null) { c1.setFill(Color.TURQUOISE); c1.setStroke(Color.ORANGE); } }); paneHsDiapo.setStyle("-fx-border-color : #777777;-fx-border-width : 1px;-fx-border-radius : 3px;"); paneHsDiapo.setId("DIAPO" + io); lblPoint = new Label("Hotspot Diaporama #" + (io + 1)); lblPoint.setPadding(new Insets(5, 10, 5, 5)); lblPoint.getStyleClass().add("titreOutil"); Separator sepHS = new Separator(Orientation.HORIZONTAL); sepHS.setPrefWidth(321); sepHS.setTranslateX(2); paneHsDiapo.setPrefWidth(325); Label lblTexteHS = new Label(rbLocalisation.getString("main.texteHotspot")); lblTexteHS.setTranslateX(10); TextField tfTexteHS = new TextField(); if (getPanoramiquesProjet()[iNumPano].getHotspotDiapo(io).getStrInfo() != null) { tfTexteHS.setText(getPanoramiquesProjet()[iNumPano].getHotspotDiapo(io).getStrInfo()); } tfTexteHS.textProperty().addListener((final ObservableValue<? extends String> observable, final String oldValue, final String newValue) -> { valideHS(); }); tfTexteHS.setId("txtDIA" + io); tfTexteHS.setPrefSize(200, 25); tfTexteHS.setMaxSize(200, 20); tfTexteHS.setTranslateX(60); vbPanneauHS.getChildren().addAll(lblPoint, sepHS, lblTexteHS, tfTexteHS); ComboBox cbListeDiapo = new ComboBox(); for (int i = 0; i < getiNombreDiapo(); i++) { cbListeDiapo.getItems().add(diaporamas[i].getStrNomDiaporama()); } cbListeDiapo.getSelectionModel() .select(getPanoramiquesProjet()[iNumPano].getHotspotDiapo(io).getiNumDiapo()); int iii = io; cbListeDiapo.getSelectionModel().selectedIndexProperty().addListener((ov, av, nv) -> { getPanoramiquesProjet()[iNumPano].getHotspotDiapo(iii).setiNumDiapo((int) nv); }); cbListeDiapo.setTranslateX(60); vbPanneauHS.getChildren().addAll(cbListeDiapo); //Ajouter Liste Diaporamas vbHotspots.getChildren().addAll(paneHsDiapo, lblSep); paneHsDiapo.setPrefHeight(120); paneHsDiapo.setMinHeight(120); paneHsDiapo.setMaxHeight(120); iTaillePane += 145; } valideHS(); iNbHS += io; dejaCharge = true; paneHotSpots.setPrefHeight(iTaillePane); paneHotSpots.setMinHeight(iTaillePane); paneHotSpots.setMaxHeight(iTaillePane); paneHotSpots.setId("labels"); apVisuHS.setPrefHeight(paneHotSpots.getPrefHeight()); apVisuHS.setMinHeight(paneHotSpots.getPrefHeight()); apVisuHS.setMaxHeight(paneHotSpots.getPrefHeight()); vbVisuHotspots.setPrefHeight(paneHotSpots.getPrefHeight()); vbVisuHotspots.setMinHeight(paneHotSpots.getPrefHeight()); vbVisuHotspots.setMaxHeight(paneHotSpots.getPrefHeight()); return paneHotSpots; }
From source file:nl.rivm.cib.episim.model.disease.infection.MSEIRSPlot.java
@Override public void start(final Stage stage) { final SIRConfig conf = ConfigFactory.create(SIRConfig.class); final double[] t = conf.t(); final long[] pop = conf.population(); final double n0 = Arrays.stream(pop).sum(); final String[] colors = conf.colors(), colors2 = conf.colors2(); final Pane plot = new Pane(); plot.setPrefSize(400, 300);//from w w w .ja v a 2 s .com plot.setMinSize(50, 50); final NumberAxis xAxis = new NumberAxis(t[0], t[1], (t[1] - t[0]) / 10); final NumberAxis yAxis = new NumberAxis(0, n0, n0 / 10); final Pane axes = new Pane(); axes.prefHeightProperty().bind(plot.heightProperty()); axes.prefWidthProperty().bind(plot.widthProperty()); xAxis.setSide(Side.BOTTOM); xAxis.setMinorTickVisible(false); xAxis.setPrefWidth(axes.getPrefWidth()); xAxis.prefWidthProperty().bind(axes.widthProperty()); xAxis.layoutYProperty().bind(axes.heightProperty()); yAxis.setSide(Side.LEFT); yAxis.setMinorTickVisible(false); yAxis.setPrefHeight(axes.getPrefHeight()); yAxis.prefHeightProperty().bind(axes.heightProperty()); yAxis.layoutXProperty().bind(Bindings.subtract(1, yAxis.widthProperty())); axes.getChildren().setAll(xAxis, yAxis); final Label lbl = new Label(String.format("R0=%.1f, recovery=%.1ft\nSIR(0)=%s", conf.reproduction(), conf.recovery(), Arrays.toString(pop))); lbl.setTextAlignment(TextAlignment.CENTER); lbl.setTextFill(Color.WHITE); final Path[] deterministic = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors[i]); final Path path = deterministic[i]; path.setStroke(color.deriveColor(0, 1, 1, 0.6)); path.setStrokeWidth(2); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); plot.getChildren().setAll(axes); // fill paths with integration estimates final double xl = xAxis.getLowerBound(), sx = plot.getPrefWidth() / (xAxis.getUpperBound() - xl), yh = plot.getPrefHeight(), sy = yh / (yAxis.getUpperBound() - yAxis.getLowerBound()); final TreeMap<Double, Integer> iDeterministic = new TreeMap<>(); MSEIRSTest.deterministic(conf, () -> new DormandPrince853Integrator(1.0E-8, 10, 1.0E-20, 1.0E-20)) .subscribe(yt -> { iDeterministic.put(yt.getKey(), deterministic[0].getElements().size()); final double[] y = yt.getValue(); final double x = (yt.getKey() - xl) * sx; for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final PathElement di = deterministic[i].getElements().isEmpty() ? new MoveTo(x, yi) : new LineTo(x, yi); deterministic[i].getElements().add(di); } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(deterministic)); final Path[] stochasticTau = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors[i]); final Path path = stochasticTau[i]; path.setStroke(color); path.setStrokeWidth(1); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); final TreeMap<Double, Integer> iStochasticTau = new TreeMap<>(); MSEIRSTest.stochasticGillespie(conf).subscribe(yt -> { final double x = (yt.getKey() - xl) * sx; iStochasticTau.put(yt.getKey(), stochasticTau[0].getElements().size()); final long[] y = yt.getValue(); for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final ObservableList<PathElement> path = stochasticTau[i].getElements(); if (path.isEmpty()) { path.add(new MoveTo(x, yi)); // first } else { final PathElement last = path.get(path.size() - 1); final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY(); path.add(new LineTo(x, y_prev)); path.add(new LineTo(x, yi)); } } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticTau)); final Path[] stochasticRes = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors2[i]); final Path path = stochasticRes[i]; path.setStroke(color); path.setStrokeWidth(1); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); final TreeMap<Double, Integer> iStochasticRes = new TreeMap<>(); MSEIRSTest.stochasticSellke(conf).subscribe(yt -> { final double x = (yt.getKey() - xl) * sx; iStochasticRes.put(yt.getKey(), stochasticRes[0].getElements().size()); final long[] y = yt.getValue(); for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final ObservableList<PathElement> path = stochasticRes[i].getElements(); if (path.isEmpty()) { path.add(new MoveTo(x, yi)); // first } else { final PathElement last = path.get(path.size() - 1); final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY(); path.add(new LineTo(x, y_prev)); path.add(new LineTo(x, yi)); } } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticRes)); // auto-scale on stage/plot resize // FIXME scaling around wrong origin, use ScatterChart? // xAxis.widthProperty() // .addListener( (ChangeListener<Number>) ( observable, // oldValue, newValue ) -> // { // final double scale = ((Double) newValue) // / plot.getPrefWidth(); // plot.getChildren().filtered( n -> n instanceof Path ) // .forEach( n -> // { // final Path path = (Path) n; // path.setScaleX( scale ); // path.setTranslateX( (path // .getBoundsInParent().getWidth() // - path.getLayoutBounds().getWidth()) // / 2 ); // } ); // } ); // plot.heightProperty() // .addListener( (ChangeListener<Number>) ( observable, // oldValue, newValue ) -> // { // final double scale = ((Double) newValue) // / plot.getPrefHeight(); // plot.getChildren().filtered( n -> n instanceof Path ) // .forEach( n -> // { // final Path path = (Path) n; // path.setScaleY( scale ); // path.setTranslateY( // (path.getBoundsInParent() // .getHeight() * (scale - 1)) // / 2 ); // } ); // } ); final StackPane layout = new StackPane(lbl, plot); layout.setAlignment(Pos.TOP_CENTER); layout.setPadding(new Insets(50)); layout.setStyle("-fx-background-color: rgb(35, 39, 50);"); final Line vertiCross = new Line(); vertiCross.setStroke(Color.SILVER); vertiCross.setStrokeWidth(1); vertiCross.setVisible(false); axes.getChildren().add(vertiCross); final Tooltip tip = new Tooltip(""); tip.setAutoHide(false); tip.hide(); axes.setOnMouseExited(ev -> tip.hide()); axes.setOnMouseMoved(ev -> { final Double x = (Double) xAxis.getValueForDisplay(ev.getX()); if (x > xAxis.getUpperBound() || x < xAxis.getLowerBound()) { tip.hide(); vertiCross.setVisible(false); return; } final Double y = (Double) yAxis.getValueForDisplay(ev.getY()); if (y > yAxis.getUpperBound() || y < yAxis.getLowerBound()) { tip.hide(); vertiCross.setVisible(false); return; } final double xs = xAxis.getDisplayPosition(x); vertiCross.setStartX(xs); vertiCross.setStartY(yAxis.getDisplayPosition(0)); vertiCross.setEndX(xs); vertiCross.setEndY(yAxis.getDisplayPosition(yAxis.getUpperBound())); vertiCross.setVisible(true); final int i = (iDeterministic.firstKey() > x ? iDeterministic.firstEntry() : iDeterministic.floorEntry(x)).getValue(); final Object[] yi = Arrays.stream(deterministic).mapToDouble(p -> getY(p, i)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 1)).toArray(); final int j = (iStochasticTau.firstKey() > x ? iStochasticTau.firstEntry() : iStochasticTau.floorEntry(x)).getValue(); final Object[] yj = Arrays.stream(stochasticTau).mapToDouble(p -> getY(p, j)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray(); final int k = (iStochasticRes.firstKey() > x ? iStochasticRes.firstEntry() : iStochasticRes.floorEntry(x)).getValue(); final Object[] yk = Arrays.stream(stochasticRes).mapToDouble(p -> getY(p, k)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray(); final String txt = String.format("SIR(t=%.1f)\n" + "~det%s\n" + "~tau%s\n" + "~res%s", x, Arrays.toString(yi), Arrays.toString(yj), Arrays.toString(yk)); tip.setText(txt); tip.show(axes, ev.getScreenX() - ev.getSceneX() + xs, ev.getScreenY() + 15); }); try { stage.getIcons().add(new Image(FileUtil.toInputStream("icon.jpg"))); } catch (final IOException e) { LOG.error("Problem", e); } stage.setTitle("Deterministic vs. Stochastic"); stage.setScene(new Scene(layout, Color.rgb(35, 39, 50))); // stage.setOnHidden( ev -> tip.hide() ); stage.show(); }