public void addImageTab(Path imagePath) { TabPane previewTabPane = controller.getPreviewTabPane(); ImageTab tab = new ImageTab(); tab.setPath(imagePath); tab.setText(imagePath.getFileName().toString()); if (previewTabPane.getTabs().contains(tab)) { previewTabPane.getSelectionModel().select(tab); return; } Image image = new Image(IOHelper.pathToUrl(imagePath)); ImageView imageView = new ImageView(image); imageView.setPreserveRatio(true); imageView.setFitWidth(previewTabPane.getWidth()); previewTabPane .widthProperty() .addListener( (observable, oldValue, newValue) -> { imageView.setFitWidth(previewTabPane.getWidth()); }); Tooltip tip = new Tooltip(imagePath.toString()); Tooltip.install(tab.getGraphic(), tip); ScrollPane scrollPane = new ScrollPane(); scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); scrollPane.setContent(imageView); scrollPane.addEventFilter( ScrollEvent.SCROLL, e -> { if (e.isControlDown() && e.getDeltaY() > 0) { // zoom in imageView.setFitWidth(imageView.getFitWidth() + 16.0); } else if (e.isControlDown() && e.getDeltaY() < 0) { // zoom out imageView.setFitWidth(imageView.getFitWidth() - 16.0); } }); tab.setContent(scrollPane); TabPane tabPane = previewTabPane; tabPane.getTabs().add(tab); tabPane.getSelectionModel().select(tab); }
private void redraw() { params.setViewport(new Rectangle2D(0, 0, imageView.getFitWidth(), imageView.getFitHeight())); if (image == null || image.getWidth() != imageView.getFitWidth() || image.getHeight() != imageView.getFitHeight()) { image = worldToView.snapshot(params, null); } else { worldToView.snapshot(params, image); } // set a clip to apply rounded border to the original image. Rectangle clip = new Rectangle(imageView.getFitWidth(), imageView.getFitHeight()); clip.setArcWidth(20); clip.setArcHeight(20); imageView.setClip(clip); imageView.setImage(image); }
@Override public boolean update() { int speed = 1; if (myImageView.getFitWidth() <= 300) { myImageView.setVisible(true); myImageView.setFitHeight(myImageView.getFitHeight() + speed); myImageView.relocate( myWidth / 2 - myImageView.getFitWidth() / 2, myHeight / 2 - myImageView.getFitHeight() / 2); myImageView.setFitWidth(myImageView.getFitWidth() + speed); myImageView.setRotate(myImageView.getRotate() + speed); } else if (myImageView.getRotate() <= 360) { myImageView.setRotate(myImageView.getRotate() + speed); } return (myImageView.getFitHeight() <= 300 || myImageView.getRotate() <= 300); }
private void stackProducts(Rectangle rectangle, ImageView box, Pane layout) { Rectangle rect = null; // if(rectangle.getClass() == Rectangle.class) { rect = new Rectangle(); rect.setWidth(rectangle.getWidth()); rect.setHeight(rectangle.getHeight()); rect.setFill(rectangle.getFill()); // } if (products.isEmpty()) { rect.setX(box.getX() + box.getFitWidth() - 20); rect.setY(box.getY() - rect.getHeight()); } else if (products.peek().getX() < box.getX() + 20) { rect.setY(products.peek().getY() - rect.getHeight() - 2); rect.setX(box.getX() + box.getFitWidth() - 20); } else { rect.setX(products.peek().getX() - rect.getWidth() - 2); rect.setY(products.peek().getY()); } products.add(rect); layout.getChildren().add(rect); }
@Override public void resizeNode(double width, double height) { MN90.getLogger().debug(this, "Changement de taille : " + width + " - " + height); double widthForFit = width > height ? width : height; for (int i = 0; i < this.getColumnConstraints().size(); i++) { double value = 5; if (i == 1) { value = 10; } this.getColumnConstraints().get(i).setPercentWidth(value); } for (int i = 0; i < this.getRowConstraints().size(); i++) { double value = 5; if (i == 0) { value = 5; } this.getRowConstraints().get(i).setPercentHeight(value); } if (mImgView.getFitWidth() != widthForFit) mImgView.setFitWidth(widthForFit); }
/** * Computes the actual scaling of an Image in an ImageView. If the preserveRatio property on the * ImageView is false the scaling has no meaning so NaN is returned. * * @return The scale factor of the image in relation to display coordinates */ public double computeActualScale() { if (!imageView.isPreserveRatio()) { actualScale = Double.NaN; } else if (doScaleRecompute) { Image localImage = imageView.getImage(); Rectangle2D localViewport = imageView.getViewport(); double w = 0; double h = 0; if (localViewport != null && localViewport.getWidth() > 0 && localViewport.getHeight() > 0) { w = localViewport.getWidth(); h = localViewport.getHeight(); } else if (localImage != null) { w = localImage.getWidth(); h = localImage.getHeight(); } double localFitWidth = imageView.getFitWidth(); double localFitHeight = imageView.getFitHeight(); if (w > 0 && h > 0 && (localFitWidth > 0 || localFitHeight > 0)) { if (localFitWidth <= 0 || (localFitHeight > 0 && localFitWidth * h > localFitHeight * w)) { w = w * localFitHeight / h; } else { w = localFitWidth; } actualScale = w / localImage.getWidth(); } doScaleRecompute = false; } return actualScale; }
public void zoomOut() { if (mImageView.getFitWidth() > 450 || mImageView.getFitHeight() > 600) { mImageView.setFitWidth(mImageView.getFitWidth() * .9); mImageView.setFitHeight(mImageView.getFitHeight() * .9); } }
public void zoomIn() { if (mImageView.getFitWidth() < 3000 || mImageView.getFitHeight() < 3000) { mImageView.setFitWidth(mImageView.getFitWidth() * 1.1); mImageView.setFitHeight(mImageView.getFitHeight() * 1.1); } }
/* ADMIN SCENE */ public void start(Stage primaryStage) throws Exception { /** Done by Marco */ primaryStage.setTitle("PubFinder"); primaryStage.setResizable(false); PubDataAccessor.PubDataAccessor(); /*Welcome scene*/ WelcomeScene.welcomeScene(); welcomeScene = WelcomeScene.welcomeScene; /*Welcome scene*/ /** End of Marcos Work */ /** Done by Shafiq and Anotnino */ /* Admin add scene*/ AdminAddScene.adminAddscene(); adminAddScene = AdminAddScene.adminAddScene; /* Admin add scene*/ /*Admin login scene*/ AdminLoginScene.adminloginscene(); adminLoginScene = AdminLoginScene.adminLoginScene; /*Admin login scene*/ /*Admin choice scene*/ AdminChoiceScene.adminchoicescene(); adminChoiceScene = AdminChoiceScene.adminChoiceScene; /*Admin choice scene*/ /* Admin Edit Scene*/ adminEditScene = AdminEditScene.editScene; /* Admin Edit Scene*/ /** End of Shafiq and Anotonino's Work */ /*Pub button scene*/ pubLayout = new StackPane(); /** Done by Ahmad */ searchNameInput = new TextField(); searchNameInput.setId("search-field"); searchNameInput.setPromptText("NAME"); /** End of Ahmad's Work */ searchStreetInput = new TextField(); searchStreetInput.setId("search-field"); searchStreetInput.setPromptText("STREET"); searchAgeInput = new TextField(); searchAgeInput.setId("search-field"); searchAgeInput.setPromptText("AGE"); /** Done by Aseel */ CheckBox searchStudentDiscount = new CheckBox("DISCOUNTS"); CheckBox searchBySpecialEvents = new CheckBox("EVENTS"); CheckBox searchWithoutFees = new CheckBox("NO FEES"); searchStudentDiscount.setId("check-search"); searchBySpecialEvents.setId("check-search"); searchWithoutFees.setId("check-search"); ComboBox searchByRating = new ComboBox( FXCollections.observableArrayList( "\uF005", "\uF005\uF005", "\uF005\uF005\uF005", "\uF005\uF005\uF005\uF005", "\uF005\uF005\uF005\uF005\uF005")); searchByRating.setTooltip(new Tooltip("RATING")); searchByRating.setPromptText("RATING"); searchByRating.setId("combo-search"); ComboBox searchByArea = new ComboBox( FXCollections.observableArrayList( "All", "Avenyn", "Linné", "Haga", "Järntorget", "Magasinsgatan", "Vasastaden", "Gamlestaden", "Heden", "Masthugget", "Stigberget", "Other")); searchByArea.setTooltip(new Tooltip("AREA")); searchByArea.setPromptText("AREA"); searchByArea.setId("combo-search"); /** End of Aseel's Work */ /** Done by Marco */ pubLayout.setId("pubs"); search = new Button("SEARCH"); search.setId("button-search"); GridPane inputGrid = new GridPane(); inputGrid.setMaxHeight(100); inputGrid.setHgap(10); inputGrid.setVgap(10); inputGrid.setId("searchGrid"); StackPane.setAlignment(inputGrid, Pos.TOP_LEFT); StackPane.setAlignment(search, Pos.TOP_RIGHT); /** End of Marco's Work */ search.setOnAction(e -> searchForPubs()); /** Done by Ahmad */ searchNameInput.setOnKeyReleased( event1 -> { if (event1.getCode() == KeyCode.ENTER) { searchForPubs(); } }); /** End of Ahmad's Work */ /** Done by Marco */ searchStreetInput.setOnKeyReleased( event2 -> { if (event2.getCode() == KeyCode.ENTER) { searchForPubs(); } }); /** End of Marco's Work */ /** Done by Ahmad */ searchAgeInput.setOnKeyReleased( event3 -> { if (event3.getCode() == KeyCode.ENTER) { searchForPubs(); } }); /** End of Ahmad's Work */ /** Done by Shafiq & Anotnino */ searchStudentDiscount.setOnAction( event4 -> { if (searchStudentDiscount.isSelected()) { discount = 1; } if (!searchStudentDiscount.isSelected()) { discount = 0; } }); searchWithoutFees.setOnAction( event5 -> { if (searchWithoutFees.isSelected()) { fee = 0; } if (!searchWithoutFees.isSelected()) { fee = 1; } }); searchBySpecialEvents.setOnAction( event6 -> { if (searchBySpecialEvents.isSelected()) { searchEvent = true; } if (!searchBySpecialEvents.isSelected()) { searchEvent = false; } }); searchByRating.setOnAction( event7 -> { if (searchByRating.getSelectionModel().isSelected(0)) { numberOfStars = 1; } else if (searchByRating.getSelectionModel().isSelected(1)) { numberOfStars = 2; } else if (searchByRating.getSelectionModel().isSelected(2)) { numberOfStars = 3; } else if (searchByRating.getSelectionModel().isSelected(3)) { numberOfStars = 4; } else if (searchByRating.getSelectionModel().isSelected(4)) { numberOfStars = 5; } }); /** End of Shafiq and Anotino's Work */ /** Done by Aseel and Antonino */ searchByArea.setOnAction( event8 -> { if (searchByArea.getSelectionModel().isSelected(0)) { area_checker = 2; } if (searchByArea.getSelectionModel().isSelected(1)) { area = 0; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(2)) { area = 2; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(3)) { area = 3; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(4)) { area = 4; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(5)) { area = 5; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(6)) { area = 6; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(7)) { area = 7; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(8)) { area = 8; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(9)) { area = 9; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(10)) { area = 10; area_checker = 1; } else if (searchByArea.getSelectionModel().isSelected(11)) { area = 11; area_checker = 1; } }); /** End of Aeel and Antonino's Work */ /** Done by marco */ ScrollPane pubScroll = new ScrollPane(); pubScroll.setId("scroll"); pubScroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); pubScroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); pubs = new GridPane(); pubScroll.setContent(pubs); pubs.setId("pub-grid"); pubs.setAlignment(Pos.CENTER); pubLayout.getChildren().add(pubScroll); inputGrid.add(searchNameInput, 1, 1); inputGrid.add(searchStreetInput, 2, 1); inputGrid.add(searchAgeInput, 3, 1); inputGrid.add(searchByRating, 4, 1); inputGrid.add(searchByArea, 5, 1); inputGrid.add(searchStudentDiscount, 6, 1); inputGrid.add(searchBySpecialEvents, 7, 1); inputGrid.add(searchWithoutFees, 8, 1); pubLayout.getChildren().add(inputGrid); pubLayout.getChildren().add(search); noPub = new Label("No pubs found"); searchForPubs(); pubScene = new Scene(pubLayout, 1000, 600); pubScene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm()); /*Pub button scene*/ /*Pub scene*/ ScrollPane pubPageLayout = new ScrollPane(); pubPageLayout.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); pubPageLayout.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); pubPageLayout.setFitToWidth(true); pubPageLayout.setContent(xPane); xPane.setId("pubScene"); pubPageLayout.setId("gej"); star.setId("starButton"); eventLabel.setId("eventLabel"); /*Items*/ xPane.add(back, 1, 1); back.setId("button-logout"); back.setOnAction( (event) -> { primaryStage.setScene(pubScene); xPane .getChildren() .removeAll(description, rating, overlay, pubName, map, star, rates, events); descriptionGrid .getChildren() .removeAll(age, open, address, type, discountForStudents, entranceFees); events.getChildren().removeAll(eventDescriptionGrid); eventDescriptionGrid.getChildren().removeAll(eventLabel, eventPane); eventPane.getChildren().removeAll(eventGrid); eventGrid.getChildren().removeAll(eventName, eventDescription); star.setText("0 \uF08A"); star.setStyle( "#starButton{-fx-text-fill: #fff;} #starButton:hover{-fx-text-fill: #fff;}"); }); /** End of Marco's work */ /** Done by Shafiq & Antonino */ star.setOnAction( event -> { int rate = PubDataAccessor.checkRate(this.id); int rateUpdate = rate + 1; /** End of Shafiq & Antonino's Work */ /** Done by marco */ star.setText((rateUpdate) + " \uF004"); PubDataAccessor.updateRate(this.id); star.setStyle("-fx-text-fill: #731a2b;"); }); overlay.setHeight(header.getFitHeight()); overlay.setWidth(header.getFitWidth() + 24); overlay.setX(0); overlay.setY(0); overlay.fillProperty().set(javafx.scene.paint.Color.rgb(115, 26, 43, 0.3)); pubPage = new Scene(pubPageLayout, 1000, 600); pubPage.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm()); /*Pub scene*/ primaryStage.setScene(welcomeScene); primaryStage.show(); Main.primaryStage = primaryStage; /** End of Marcos work */ }