List of usage examples for javafx.scene.shape Rectangle addEventHandler
public final <T extends Event> void addEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)
From source file:snpviewer.SnpViewer.java
private void drawSavedRegions(String chrom) { selectionOverlayPane.getChildren().clear(); if (savedRegions.isEmpty()) { selectionOverlayPane.getChildren().add(dragSelectRectangle); return;//from www . ja va 2s. co m } for (RegionSummary r : savedRegions) { if (r.getChromosome() == null) { selectionOverlayPane.getChildren().add(dragSelectRectangle); return; } if (r.getChromosome().equalsIgnoreCase(chrom)) { drawRegionSummary(r, chrom); } } int rectCounter = 0; for (final Rectangle rect : savedRegionsDisplay) { final int counter = rectCounter; final ContextMenu scm = new ContextMenu(); final MenuItem scmItem1 = new MenuItem("Display Flanking SNP IDs"); scmItem1.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * flanking snp ids and coordinates */ displayFlankingSnpIDs(rect); } }); final MenuItem scmItem2 = new MenuItem("Write Region to File"); scmItem2.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and * write SNPs in region to file */ writeRegionToFile(rect); } }); } }); final MenuItem scmItem3 = new MenuItem("Remove this Saved Region"); scmItem3.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and * write SNPs in region to file */ removeSavedRegion(counter); } }); final MenuItem scmItem4 = new MenuItem("Show/Hide Saved Regions"); scmItem4.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * write SNPs in region to file */ hideSavedRegionsMenu.selectedProperty().setValue(!hideSavedRegionsMenu.isSelected()); hideSavedRegionsMenu.fire(); } }); final MenuItem scmItem5 = new MenuItem("Zoom Region"); scmItem5.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { /* get coordinates of selection and report back * write SNPs in region to file */ zoomRegion(rect); } }); final MenuItem scmItem6 = new MenuItem("Write Saved Regions to File"); scmItem6.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { Platform.runLater(new Runnable() { @Override public void run() { /* get coordinates of selection and report back * write SNPs in region to file */ writeSavedRegionsToFile(); } }); } }); scm.getItems().add(scmItem1); scm.getItems().add(scmItem2); scm.getItems().add(scmItem3); scm.getItems().add(scmItem4); scm.getItems().add(scmItem5); scm.getItems().add(scmItem6); rect.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { ocm.hide(); if (scm.isShowing()) { scm.hide(); } if (e.getButton() == MouseButton.SECONDARY) { if (chromosomeSelector.getSelectionModel().isEmpty()) { for (MenuItem mi : scm.getItems()) { mi.setDisable(true); } } else { for (MenuItem mi : scm.getItems()) { mi.setDisable(false); } } scm.show(selectionOverlayPane, e.getScreenX(), e.getScreenY()); } } }); rect.setVisible(true); selectionOverlayPane.getChildren().add(rect); rectCounter++; } selectionOverlayPane.getChildren().add(dragSelectRectangle); }