List of usage examples for javafx.beans.property DoubleProperty addListener
void addListener(ChangeListener<? super T> listener);
From source file:Main.java
@Override public void start(Stage stage) throws Exception { ImageView imageView = new ImageView(); ScrollPane scrollPane = new ScrollPane(); DoubleProperty zoomProperty = new SimpleDoubleProperty(200); zoomProperty.addListener(new InvalidationListener() { @Override//from ww w .ja v a 2 s.c o m public void invalidated(Observable arg0) { imageView.setFitWidth(zoomProperty.get() * 2); imageView.setFitHeight(zoomProperty.get() * 3); } }); scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (event.getDeltaY() > 0) { zoomProperty.set(zoomProperty.get() * 1.2); } else if (event.getDeltaY() < 0) { zoomProperty.set(zoomProperty.get() / 1.1); } } }); imageView.setImage(new Image("http://yourImageURL")); imageView.preserveRatioProperty().set(true); scrollPane.setContent(imageView); stage.setScene(new Scene(scrollPane, 400, 300)); stage.show(); }
From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java
private void showImage(File file) { try {/*from w ww. j a va2s .co m*/ ImageView iv = new ImageView(new Image(file.toURI().toURL().toString())); iv.setPreserveRatio(true); Stage stage = new Stage(); final DoubleProperty zoomProperty = new SimpleDoubleProperty(200); zoomProperty.addListener(new InvalidationListener() { @Override public void invalidated(javafx.beans.Observable observable) { iv.setFitWidth(zoomProperty.get() * 4); iv.setFitHeight(zoomProperty.get() * 3); } }); ScrollPane sp = new ScrollPane(iv); stage.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() { @Override public void handle(ScrollEvent event) { if (event.getDeltaY() > 0) { zoomProperty.set(zoomProperty.get() * 1.1); } else if (event.getDeltaY() < 0) { zoomProperty.set(zoomProperty.get() / 1.1); } } }); stage.setScene(new Scene(new Group(sp))); stage.sizeToScene(); stage.show(); } catch (IOException ex) { showErrorDialog(ex); } }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param iNumZone numro de la zone//from ww w .j a v a 2 s . c om * @param points liste de points du polygone * @return ancres du polygone */ private static ObservableList<AncreForme> olCreeAncresPourPolygone(int iNumZone, final ObservableList<Double> points) { ObservableList<AncreForme> olAnchors = FXCollections.observableArrayList(); for (int i = 0; i < points.size(); i += 2) { final int idx = i; DoubleProperty xProperty = new SimpleDoubleProperty(points.get(i)); DoubleProperty yProperty = new SimpleDoubleProperty(points.get(i + 1)); xProperty.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> { points.set(idx, (double) x); String chaine = ""; chaine = points.stream().map((point) -> point.toString() + ",").reduce(chaine, String::concat); chaine = chaine.substring(0, chaine.length() - 1); zones[iNumZone].setStrCoordonneesZone(chaine); }); yProperty.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> { points.set(idx + 1, (double) y); String chaine = ""; chaine = points.stream().map((point) -> point.toString() + ",").reduce(chaine, String::concat); chaine = chaine.substring(0, chaine.length() - 1); zones[iNumZone].setStrCoordonneesZone(chaine); }); olAnchors.add(new AncreForme(Color.GOLD, xProperty, yProperty)); } return olAnchors; }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param iNumZone numero de la zone// w w w .j a v a2 s. co m * @param rect rectangle concern * @return ancres rectangle */ private static ObservableList<AncreForme> olCreeAncresPourRectangle(int iNumZone, Rectangle rect) { ObservableList<AncreForme> olAnchors = FXCollections.observableArrayList(); DoubleProperty xProperty1 = new SimpleDoubleProperty(rect.getX()); DoubleProperty yProperty1 = new SimpleDoubleProperty(rect.getY()); DoubleProperty xProperty2 = new SimpleDoubleProperty(rect.getWidth() + rect.getX()); DoubleProperty yProperty2 = new SimpleDoubleProperty(rect.getHeight() + rect.getY()); olAnchors.add(new AncreForme(Color.GOLD, xProperty1, yProperty1)); AncreForme ancrePoint2 = new AncreForme(Color.BLUEVIOLET, xProperty2, yProperty2); olAnchors.add(ancrePoint2); xProperty1.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> { double dX = -rect.getX() + (double) x; rect.setX((double) x); ancrePoint2.setCenterX(ancrePoint2.getCenterX() + dX); String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + "," + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + "," + Math.round((rect.getY() + rect.getHeight()) * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); yProperty1.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> { double dY = -rect.getY() + (double) y; rect.setY((double) y); ancrePoint2.setCenterY(ancrePoint2.getCenterY() + dY); String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + "," + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + "," + Math.round((rect.getY() + rect.getHeight()) * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); xProperty2.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> { rect.setWidth((double) x - rect.getX()); String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + "," + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + "," + Math.round((rect.getY() + rect.getHeight()) * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); yProperty2.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> { rect.setHeight((double) y - rect.getY()); String chaine = Math.round(rect.getX() * 10) / 10 + "," + Math.round(rect.getY() * 10) / 10 + "," + Math.round((rect.getX() + rect.getWidth()) * 10) / 10 + "," + Math.round((rect.getY() + rect.getHeight()) * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); return olAnchors; }
From source file:editeurpanovisu.EditeurPanovisu.java
/** * * @param iNumZone numro de la zone/*from w ww . j a v a 2 s. c om*/ * @param cercle cercle concern * @return ancres cercles */ private static ObservableList<AncreForme> olCreeAncresPourCercle(int iNumZone, Circle cercle) { ObservableList<AncreForme> olAnchors = FXCollections.observableArrayList(); DoubleProperty xProperty1 = new SimpleDoubleProperty(cercle.getCenterX()); DoubleProperty yProperty1 = new SimpleDoubleProperty(cercle.getCenterY()); olAnchors.add(new AncreForme(Color.GOLD, xProperty1, yProperty1)); DoubleProperty xProperty2 = new SimpleDoubleProperty(cercle.getCenterX() + cercle.getRadius()); DoubleProperty yProperty2 = new SimpleDoubleProperty(cercle.getCenterY()); final AncreForme ancRayon = new AncreForme(Color.BLUEVIOLET, xProperty2, yProperty2); olAnchors.add(ancRayon); xProperty1.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> { double dX = (double) x - cercle.getCenterX(); double rayon = Math.sqrt(Math.pow(cercle.getCenterX() - xProperty2.get(), 2.d) + Math.pow(cercle.getCenterY() - yProperty2.get(), 2.d)); cercle.setCenterX((double) x); ancRayon.setCenterX(ancRayon.getCenterX() + dX); String chaine = Math.round(cercle.getCenterX() * 10) / 10 + "," + Math.round(cercle.getCenterY() * 10) / 10 + "," + Math.round(rayon * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); yProperty1.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> { double dY = -cercle.getCenterY() + (double) y; double rayon = Math.sqrt(Math.pow(cercle.getCenterX() - xProperty2.get(), 2.d) + Math.pow(cercle.getCenterY() - yProperty2.get(), 2.d)); cercle.setCenterY((double) y); ancRayon.setCenterY(ancRayon.getCenterY() + dY); String chaine = Math.round(cercle.getCenterX() * 10) / 10 + "," + Math.round(cercle.getCenterY() * 10) / 10 + "," + Math.round(rayon * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); xProperty2.addListener((ObservableValue<? extends Number> ov, Number oldX, Number x) -> { double rayon = Math.sqrt(Math.pow(cercle.getCenterX() - (double) x, 2.d) + Math.pow(cercle.getCenterY() - yProperty2.get(), 2.d)); cercle.setRadius(rayon); String chaine = Math.round(cercle.getCenterX() * 10) / 10 + "," + Math.round(cercle.getCenterY() * 10) / 10 + "," + Math.round(rayon * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); yProperty2.addListener((ObservableValue<? extends Number> ov, Number oldY, Number y) -> { double rayon = Math.sqrt(Math.pow(cercle.getCenterX() - xProperty2.get(), 2.d) + Math.pow(cercle.getCenterY() - (double) y, 2.d)); cercle.setRadius(rayon); String chaine = Math.round(cercle.getCenterX() * 10) / 10 + "," + Math.round(cercle.getCenterY() * 10) / 10 + "," + Math.round(rayon * 10) / 10; zones[iNumZone].setStrCoordonneesZone(chaine); }); return olAnchors; }