Java Code Examples for javafx.scene.image.ImageView#setOnMousePressed()
The following examples show how to use
javafx.scene.image.ImageView#setOnMousePressed() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageButton.java From SmartCity-ParkingManagement with Apache License 2.0 | 5 votes |
public void updateImages(final Image selected, final Image unselected) { final ImageView iv = new ImageView(selected); getChildren().add(iv); iv.setOnMousePressed(λ -> iv.setImage(unselected)); iv.setOnMouseReleased(λ -> iv.setImage(selected)); super.setGraphic(iv); }
Example 2
Source File: CImageDisplay.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
@Override public Node getNode( PageActionManager actionmanager, CPageData inputdata, Window parentwindow, TabPane[] parenttabpanes, CollapsibleNode nodetocollapsewhenactiontriggered) { inputdata.addInlineActionDataRef(this.inlineactiondataref); this.actionmanager = actionmanager; SFile thumbnail = getThumbnail(inputdata, datareference); if (!thumbnail.isEmpty()) { ByteArrayInputStream imagedata = new ByteArrayInputStream(thumbnail.getContent()); Image image = new Image(imagedata); double imagewidth = image.getWidth(); double imageheight = image.getHeight(); thumbnailview = new ImageView(image); thumbnailview.setFitWidth(imagewidth); thumbnailview.setFitHeight(imageheight); thumbnailview.setOnMousePressed(actionmanager.getMouseHandler()); actionmanager.registerInlineAction(thumbnailview, fullimageaction); BorderPane border = new BorderPane(); border.setBorder(new Border( new BorderStroke(Color.web("#ddeeff"), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(3)), new BorderStroke(Color.web("#bbccdd"), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1)))); border.setCenter(thumbnailview); border.setMaxHeight(imageheight + 6); border.setMaxWidth(imagewidth + 6); DropShadow ds = new DropShadow(); ds.setRadius(3.0); ds.setOffsetX(1.5); ds.setOffsetY(1.5); ds.setColor(Color.color(0.2, 0.2, 0.2)); border.setEffect(ds); if (this.islabel) { FlowPane thispane = new FlowPane(); Label thislabel = new Label(label); thislabel.setFont( Font.font(thislabel.getFont().getName(), FontPosture.ITALIC, thislabel.getFont().getSize())); thislabel.setMinWidth(120); thislabel.setWrapText(true); thislabel.setMaxWidth(120); thispane.setRowValignment(VPos.TOP); thispane.getChildren().add(thislabel); thispane.getChildren().add(border); return thispane; } else { return border; } } return null; }
Example 3
Source File: CImageDisplay.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
@Override public void forceUpdateData(DataElt dataelt) { if (dataelt == null) throw new RuntimeException(String.format("data element is null")); if (!dataelt.getType().printType().equals(inlineactiondataref.getType())) throw new RuntimeException( String.format("inline data with name = %s does not have expected %s type, actually found %s", inlineactiondataref.getName(), inlineactiondataref.getType(), dataelt.getType())); LargeBinaryDataElt largefileelt = (LargeBinaryDataElt) dataelt; largefile = largefileelt.getPayload(); if (!largefile.isEmpty()) { final Stage imagepopup = new Stage(); imagepopup.initModality(Modality.APPLICATION_MODAL); imagepopup.initOwner(actionmanager.getClientSession().getMainFrame().getPrimaryStage()); Image image = new Image(new ByteArrayInputStream(largefile.getContent())); ImageView imageview = new ImageView(image); imageview.setFitWidth(image.getWidth()); imageview.setFitHeight(image.getHeight()); imageview.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent arg0) { FileChooser filechooser = new FileChooser(); filechooser.setTitle("Save image to file"); filechooser.setInitialFileName(largefile.getFileName()); filechooser.getExtensionFilters() .add(new FileChooser.ExtensionFilter("PNG files (*.PNG)", "*.PNG")); File file = filechooser.showSaveDialog(imagepopup); if (file != null) { try { FileOutputStream fos = new FileOutputStream(file, false); fos.write(largefile.getContent()); fos.close(); imagepopup.close(); } catch (IOException e) { logger.warning("Error writing file " + e.getMessage()); for (int i = 0; i < e.getStackTrace().length; i++) logger.warning(" " + e.getStackTrace()[i]); } } } }); ScrollPane scrollpane = new ScrollPane(); scrollpane.setContent(imageview); Scene dialogscene = new Scene(scrollpane); imagepopup.setScene(dialogscene); imagepopup.show(); imageview.requestFocus(); } }
Example 4
Source File: OverView.java From CrazyAlpha with GNU General Public License v2.0 | 4 votes |
public OverView() { root = new Pane(); Game.getInstance().resetMedia(); GameMap map = Game.getInstance().getMapManager().getCurrentMap(); ImageView mapIv = new ImageView(map.getMapImage()); mapIv.setFitWidth(Game.getInstance().getWidth()); mapIv.setFitHeight(Game.getInstance().getHeight()); Label nameLbl = new Label("Game Over!"); nameLbl.setTextFill(Color.WHITESMOKE); nameLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 80)); nameLbl.setLayoutX(50); nameLbl.setLayoutY(50); Label scoreLbl = new Label(); scoreLbl.setTextFill(Color.WHITESMOKE); scoreLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 60)); scoreLbl.setLayoutX(50); scoreLbl.setLayoutY(map.getHeight() - scoreLbl.getHeight() - 140); if (Game.getInstance().getScore() > Game.getInstance().getDataManager().getHighestScore()) { // 刷新高分记录! scoreLbl.setText("New Record: " + Game.getInstance().getScore()); Game.getInstance().getDataManager().setHighestScore(Game.getInstance().getScore()); } else scoreLbl.setText("Score: " + Game.getInstance().getScore()); Reflection reflection = new Reflection(); reflection.setFraction(1.0); nameLbl.setEffect(reflection); ImageView homeBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_home")); homeBtn.setFitWidth(165 * 1.5); homeBtn.setFitHeight(65 * 1.5); homeBtn.setLayoutX(map.getWidth() - homeBtn.getFitWidth() - 20); homeBtn.setLayoutY(map.getHeight() - homeBtn.getFitHeight() - 60); homeBtn.setEffect(reflection); homeBtn.setOnMouseEntered(event -> { homeBtn.setEffect(new Glow(0.8)); Game.getInstance().getButtonOverMusic().play(); }); homeBtn.setOnMouseExited(event -> { homeBtn.setEffect(reflection); Game.getInstance().getButtonOverMusic().stop(); }); homeBtn.setOnMousePressed(event -> { homeBtn.setEffect(new GaussianBlur()); Game.getInstance().getButtonClickMusic().play(); }); homeBtn.setOnMouseReleased(event -> { homeBtn.setEffect(new Glow(0.8)); Game.getInstance().home(); }); root.getChildren().add(mapIv); root.getChildren().add(nameLbl); root.getChildren().add(scoreLbl); root.getChildren().add(homeBtn); makeFadeTransition(homeBtn, 2000, 1, 0.7); makeFadeTransition(mapIv, 3000, 1, 0.8); makeScaleTransition(mapIv, 10000, 0.25, 0.25); }
Example 5
Source File: PauseView.java From CrazyAlpha with GNU General Public License v2.0 | 4 votes |
public PauseView() { root = new Pane(); Game.getInstance().resetMedia(); map = Game.getInstance().getMapManager().getCurrentMap(); mapIv = new ImageView(map.getMapImage()); mapIv.setFitWidth(Game.getInstance().getWidth()); mapIv.setFitHeight(Game.getInstance().getHeight()); nameLbl = new Label("CrazyAlpha!"); nameLbl.setTextFill(Color.WHITESMOKE); nameLbl.setFont(Game.getInstance().getResouceManager().getFont("Starcraft", 120)); nameLbl.setLayoutX(50); nameLbl.setLayoutY(50); Reflection reflection1 = new Reflection(); reflection1.setFraction(1.0); nameLbl.setEffect(reflection1); Reflection reflection02 = new Reflection(); reflection02.setFraction(0.4); resumeBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_resume")); resumeBtn.setFitWidth(165 * 1.5); resumeBtn.setFitHeight(65 * 1.5); exitBtn = new ImageView(Game.getInstance().getResouceManager().getControl("btn_exit")); exitBtn.setFitWidth(165 * 1.5); exitBtn.setFitHeight(65 * 1.5); resumeBtn.setLayoutX(map.getWidth() - resumeBtn.getFitWidth() - 20); resumeBtn.setLayoutY(map.getHeight() - resumeBtn.getFitHeight() - exitBtn.getFitHeight() - 120); resumeBtn.setEffect(reflection02); resumeBtn.setOnMouseEntered(event -> { resumeBtn.setEffect(new Glow(0.8)); Game.getInstance().getButtonOverMusic().play(); }); resumeBtn.setOnMouseExited(event -> { resumeBtn.setEffect(reflection02); Game.getInstance().getButtonClickMusic().stop(); }); resumeBtn.setOnMousePressed(event -> { resumeBtn.setEffect(new GaussianBlur()); Game.getInstance().getButtonClickMusic().play(); Game.getInstance().resume(); }); resumeBtn.setOnMouseReleased(event -> { resumeBtn.setEffect(new Glow(0.8)); }); exitBtn.setLayoutX(map.getWidth() - exitBtn.getFitWidth() - 20); exitBtn.setLayoutY(map.getHeight() - exitBtn.getFitHeight() - 60); exitBtn.setEffect(reflection02); exitBtn.setOnMouseEntered(event -> { exitBtn.setEffect(new Glow(0.8)); Game.getInstance().getButtonOverMusic().play(); }); exitBtn.setOnMouseExited(event -> { exitBtn.setEffect(reflection02); Game.getInstance().getButtonOverMusic().stop(); }); exitBtn.setOnMousePressed(event -> { exitBtn.setEffect(new GaussianBlur()); Game.getInstance().getButtonClickMusic().play(); }); exitBtn.setOnMouseReleased(event -> { exitBtn.setEffect(new Glow(0.8)); Game.getInstance().exit(); }); root.getChildren().add(mapIv); root.getChildren().add(nameLbl); root.getChildren().add(resumeBtn); root.getChildren().add(exitBtn); makeFadeTransition(resumeBtn, 2000, 1, 0.7); makeFadeTransition(exitBtn, 2000, 1, 0.7); makeFadeTransition(mapIv, 3000, 1, 0.8); makeScaleTransition(mapIv, 10000, 0.25, 0.25); }
Example 6
Source File: Splash.java From marathonv5 with Apache License 2.0 | 4 votes |
Splash() { state = STATE_SHOW_TITLE; stateArg = 0; initTimeline(); background = new ImageView(); background.setFocusTraversable(true); background.setImage(Config.getImages().get(Config.IMAGE_BACKGROUND)); background.setFitWidth(Config.SCREEN_WIDTH); background.setFitHeight(Config.SCREEN_HEIGHT); background.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { Main.getMainFrame().startGame(); } }); background.setOnKeyPressed(new EventHandler<KeyEvent>() { public void handle(KeyEvent ke) { Main.getMainFrame().startGame(); } }); brick = new ImageView(); brick.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BRICK)); brick.setTranslateX(-1000); brick.setTranslateY(brick.getImage().getHeight()); brickShadow = new ImageView(); brickShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BRICKSHADOW)); brickShadow.setTranslateX(-1000); breaker = new ImageView(); breaker.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BREAKER)); breaker.setTranslateX(-1000); breaker.setTranslateY(brick.getTranslateY() + brick.getImage().getHeight() * 5 / 4); breakerShadow = new ImageView(); breakerShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BREAKERSHADOW)); breakerShadow.setTranslateX(-1000); strike = new ImageView(); strike.setImage(Config.getImages().get(Config.IMAGE_SPLASH_STRIKE)); strike.setTranslateY(brick.getTranslateY() - (strike.getImage().getHeight() - brick.getImage().getHeight()) / 2); strike.setVisible(false); pressanykey = new ImageView(); pressanykey.setImage(Config.getImages().get(Config.IMAGE_SPLASH_PRESSANYKEY)); pressanykey.setTranslateX((Config.SCREEN_WIDTH - pressanykey.getImage().getWidth()) / 2); double y = breaker.getTranslateY() + breaker.getImage().getHeight(); pressanykey.setTranslateY(y + (Config.SCREEN_HEIGHT - y) / 2); pressanykey.setOpacity(0); strikeShadow = new ImageView(); strikeShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_STRIKESHADOW)); strikeShadow.setTranslateX(-1000); pressanykeyShadow = new ImageView(); pressanykeyShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_PRESSANYKEYSHADOW)); pressanykeyShadow.setTranslateX(-1000); sun = new ImageView(); sun.setImage(Config.getImages().get(Config.IMAGE_SPLASH_SUN)); sun.setTranslateX(-1000); NODES = new ImageView[] {brick, breaker, strike, pressanykey}; NODES_SHADOWS = new ImageView[] {brickShadow, breakerShadow, strikeShadow, pressanykeyShadow}; Group group = new Group(); group.getChildren().add(background); group.getChildren().addAll(NODES_SHADOWS); group.getChildren().addAll(NODES); group.getChildren().add(sun); getChildren().add(group); }
Example 7
Source File: Splash.java From marathonv5 with Apache License 2.0 | 4 votes |
Splash() { state = STATE_SHOW_TITLE; stateArg = 0; initTimeline(); background = new ImageView(); background.setFocusTraversable(true); background.setImage(Config.getImages().get(Config.IMAGE_BACKGROUND)); background.setFitWidth(Config.SCREEN_WIDTH); background.setFitHeight(Config.SCREEN_HEIGHT); background.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { Main.getMainFrame().startGame(); } }); background.setOnKeyPressed(new EventHandler<KeyEvent>() { public void handle(KeyEvent ke) { Main.getMainFrame().startGame(); } }); brick = new ImageView(); brick.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BRICK)); brick.setTranslateX(-1000); brick.setTranslateY(brick.getImage().getHeight()); brickShadow = new ImageView(); brickShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BRICKSHADOW)); brickShadow.setTranslateX(-1000); breaker = new ImageView(); breaker.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BREAKER)); breaker.setTranslateX(-1000); breaker.setTranslateY(brick.getTranslateY() + brick.getImage().getHeight() * 5 / 4); breakerShadow = new ImageView(); breakerShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BREAKERSHADOW)); breakerShadow.setTranslateX(-1000); strike = new ImageView(); strike.setImage(Config.getImages().get(Config.IMAGE_SPLASH_STRIKE)); strike.setTranslateY(brick.getTranslateY() - (strike.getImage().getHeight() - brick.getImage().getHeight()) / 2); strike.setVisible(false); pressanykey = new ImageView(); pressanykey.setImage(Config.getImages().get(Config.IMAGE_SPLASH_PRESSANYKEY)); pressanykey.setTranslateX((Config.SCREEN_WIDTH - pressanykey.getImage().getWidth()) / 2); double y = breaker.getTranslateY() + breaker.getImage().getHeight(); pressanykey.setTranslateY(y + (Config.SCREEN_HEIGHT - y) / 2); pressanykey.setOpacity(0); strikeShadow = new ImageView(); strikeShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_STRIKESHADOW)); strikeShadow.setTranslateX(-1000); pressanykeyShadow = new ImageView(); pressanykeyShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_PRESSANYKEYSHADOW)); pressanykeyShadow.setTranslateX(-1000); sun = new ImageView(); sun.setImage(Config.getImages().get(Config.IMAGE_SPLASH_SUN)); sun.setTranslateX(-1000); NODES = new ImageView[] {brick, breaker, strike, pressanykey}; NODES_SHADOWS = new ImageView[] {brickShadow, breakerShadow, strikeShadow, pressanykeyShadow}; Group group = new Group(); group.getChildren().add(background); group.getChildren().addAll(NODES_SHADOWS); group.getChildren().addAll(NODES); group.getChildren().add(sun); getChildren().add(group); }
Example 8
Source File: Splash.java From netbeans with Apache License 2.0 | 4 votes |
Splash() { state = STATE_SHOW_TITLE; stateArg = 0; initTimeline(); background = new ImageView(); background.setFocusTraversable(true); background.setImage(Config.getImages().get(Config.IMAGE_BACKGROUND)); background.setFitWidth(Config.SCREEN_WIDTH); background.setFitHeight(Config.SCREEN_HEIGHT); background.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { Main.getMainFrame().startGame(); } }); background.setOnKeyPressed(new EventHandler<KeyEvent>() { public void handle(KeyEvent ke) { Main.getMainFrame().startGame(); } }); brick = new ImageView(); brick.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BRICK)); brick.setTranslateX(-1000); brick.setTranslateY(brick.getImage().getHeight()); brickShadow = new ImageView(); brickShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BRICKSHADOW)); brickShadow.setTranslateX(-1000); breaker = new ImageView(); breaker.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BREAKER)); breaker.setTranslateX(-1000); breaker.setTranslateY(brick.getTranslateY() + brick.getImage().getHeight() * 5 / 4); breakerShadow = new ImageView(); breakerShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_BREAKERSHADOW)); breakerShadow.setTranslateX(-1000); strike = new ImageView(); strike.setImage(Config.getImages().get(Config.IMAGE_SPLASH_STRIKE)); strike.setTranslateY(brick.getTranslateY() - (strike.getImage().getHeight() - brick.getImage().getHeight()) / 2); strike.setVisible(false); pressanykey = new ImageView(); pressanykey.setImage(Config.getImages().get(Config.IMAGE_SPLASH_PRESSANYKEY)); pressanykey.setTranslateX((Config.SCREEN_WIDTH - pressanykey.getImage().getWidth()) / 2); double y = breaker.getTranslateY() + breaker.getImage().getHeight(); pressanykey.setTranslateY(y + (Config.SCREEN_HEIGHT - y) / 2); pressanykey.setOpacity(0); strikeShadow = new ImageView(); strikeShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_STRIKESHADOW)); strikeShadow.setTranslateX(-1000); pressanykeyShadow = new ImageView(); pressanykeyShadow.setImage(Config.getImages().get(Config.IMAGE_SPLASH_PRESSANYKEYSHADOW)); pressanykeyShadow.setTranslateX(-1000); sun = new ImageView(); sun.setImage(Config.getImages().get(Config.IMAGE_SPLASH_SUN)); sun.setTranslateX(-1000); NODES = new ImageView[] {brick, breaker, strike, pressanykey}; NODES_SHADOWS = new ImageView[] {brickShadow, breakerShadow, strikeShadow, pressanykeyShadow}; Group group = new Group(); group.getChildren().add(background); group.getChildren().addAll(NODES_SHADOWS); group.getChildren().addAll(NODES); group.getChildren().add(sun); getChildren().add(group); }