List of usage examples for javafx.scene.input KeyCode SPACE
KeyCode SPACE
To view the source code for javafx.scene.input KeyCode SPACE.
Click Source Link
From source file:de.unibw.inf2.fishification.FishWorld.java
private void registerKeys() { getWorldCanvas().setOnKeyPressed(new EventHandler<KeyEvent>() { @Override/*from w w w . ja va2s . c om*/ public void handle(KeyEvent keyEvent) { if (keyEvent.getCode().equals(KeyCode.DIGIT1)) { toggleFps(); } else if (keyEvent.getCode().equals(KeyCode.DIGIT2)) { toggleBackground(); } else if (keyEvent.getCode().equals(KeyCode.DIGIT3)) { toggleWaveEffect(); } else if (keyEvent.getCode().equals(KeyCode.DIGIT0)) { asyncTakeScreenshot(); } else if (keyEvent.getCode().equals(KeyCode.ENTER)) { feedFish("all"); } else if (keyEvent.getCode().equals(KeyCode.SPACE)) { togglePause(); } } }); }
From source file:Main.java
@Override public void start(final Stage stage) { stage.setTitle("Xylophone"); camOffset.getChildren().add(cam);/* w ww.j a v a 2 s . c o m*/ resetCam(); final Scene scene = new Scene(camOffset, 800, 600, true); scene.setFill(new RadialGradient(225, 0.85, 300, 300, 500, false, CycleMethod.NO_CYCLE, new Stop[] { new Stop(0f, Color.BLUE), new Stop(1f, Color.LIGHTBLUE) })); scene.setCamera(new PerspectiveCamera()); final AudioClip bar1Note = new AudioClip(Main.class.getResource("audio/Note1.wav").toString()); final AudioClip bar2Note = new AudioClip(Main.class.getResource("audio/Note2.wav").toString()); final AudioClip bar3Note = new AudioClip(Main.class.getResource("audio/Note3.wav").toString()); final AudioClip bar4Note = new AudioClip(Main.class.getResource("audio/Note4.wav").toString()); final AudioClip bar5Note = new AudioClip(Main.class.getResource("audio/Note5.wav").toString()); final AudioClip bar6Note = new AudioClip(Main.class.getResource("audio/Note6.wav").toString()); final AudioClip bar7Note = new AudioClip(Main.class.getResource("audio/Note7.wav").toString()); final AudioClip bar8Note = new AudioClip(Main.class.getResource("audio/Note8.wav").toString()); Group rectangleGroup = new Group(); rectangleGroup.getTransforms().add(shear); rectangleGroup.setDepthTest(DepthTest.ENABLE); double xStart = 260.0; double xOffset = 30.0; double yPos = 300.0; double zPos = 0.0; double barWidth = 22.0; double barDepth = 7.0; // Base1 Cube base1Cube = new Cube(1.0, new Color(0.2, 0.12, 0.1, 1.0), 1.0); base1Cube.setTranslateX(xStart + 135); base1Cube.setTranslateZ(yPos + 20.0); base1Cube.setTranslateY(11.0); base1Cube.setScaleX(barWidth * 11.5); base1Cube.setScaleZ(10.0); base1Cube.setScaleY(barDepth * 2.0); // Base2 Cube base2Cube = new Cube(1.0, new Color(0.2, 0.12, 0.1, 1.0), 1.0); base2Cube.setTranslateX(xStart + 135); base2Cube.setTranslateZ(yPos - 20.0); base2Cube.setTranslateY(11.0); base2Cube.setScaleX(barWidth * 11.5); base2Cube.setScaleZ(10.0); base2Cube.setScaleY(barDepth * 2.0); // Bar1 Cube bar1Cube = new Cube(1.0, Color.PURPLE, 1.0); bar1Cube.setTranslateX(xStart + 1 * xOffset); bar1Cube.setTranslateZ(yPos); bar1Cube.setScaleX(barWidth); bar1Cube.setScaleZ(100.0); bar1Cube.setScaleY(barDepth); // Bar2 Cube bar2Cube = new Cube(1.0, Color.BLUEVIOLET, 1.0); bar2Cube.setTranslateX(xStart + 2 * xOffset); bar2Cube.setTranslateZ(yPos); bar2Cube.setScaleX(barWidth); bar2Cube.setScaleZ(95.0); bar2Cube.setScaleY(barDepth); // Bar3 Cube bar3Cube = new Cube(1.0, Color.BLUE, 1.0); bar3Cube.setTranslateX(xStart + 3 * xOffset); bar3Cube.setTranslateZ(yPos); bar3Cube.setScaleX(barWidth); bar3Cube.setScaleZ(90.0); bar3Cube.setScaleY(barDepth); // Bar4 Cube bar4Cube = new Cube(1.0, Color.GREEN, 1.0); bar4Cube.setTranslateX(xStart + 4 * xOffset); bar4Cube.setTranslateZ(yPos); bar4Cube.setScaleX(barWidth); bar4Cube.setScaleZ(85.0); bar4Cube.setScaleY(barDepth); // Bar5 Cube bar5Cube = new Cube(1.0, Color.GREENYELLOW, 1.0); bar5Cube.setTranslateX(xStart + 5 * xOffset); bar5Cube.setTranslateZ(yPos); bar5Cube.setScaleX(barWidth); bar5Cube.setScaleZ(80.0); bar5Cube.setScaleY(barDepth); // Bar6 Cube bar6Cube = new Cube(1.0, Color.YELLOW, 1.0); bar6Cube.setTranslateX(xStart + 6 * xOffset); bar6Cube.setTranslateZ(yPos); bar6Cube.setScaleX(barWidth); bar6Cube.setScaleZ(75.0); bar6Cube.setScaleY(barDepth); // Bar7 Cube bar7Cube = new Cube(1.0, Color.ORANGE, 1.0); bar7Cube.setTranslateX(xStart + 7 * xOffset); bar7Cube.setTranslateZ(yPos); bar7Cube.setScaleX(barWidth); bar7Cube.setScaleZ(70.0); bar7Cube.setScaleY(barDepth); // Bar8 Cube bar8Cube = new Cube(1.0, Color.RED, 1.0); bar8Cube.setTranslateX(xStart + 8 * xOffset); bar8Cube.setTranslateZ(yPos); bar8Cube.setScaleX(barWidth); bar8Cube.setScaleZ(65.0); bar8Cube.setScaleY(barDepth); bar1Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar1Note.play(); } }); bar2Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar2Note.play(); } }); bar3Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar3Note.play(); } }); bar4Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar4Note.play(); } }); bar5Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar5Note.play(); } }); bar6Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar6Note.play(); } }); bar7Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar7Note.play(); } }); bar8Cube.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { bar8Note.play(); } }); rectangleGroup.getChildren().addAll(base1Cube, base2Cube, bar1Cube, bar2Cube, bar3Cube, bar4Cube, bar5Cube, bar6Cube, bar7Cube, bar8Cube); rectangleGroup.setScaleX(2.5); rectangleGroup.setScaleY(2.5); rectangleGroup.setScaleZ(2.5); cam.getChildren().add(rectangleGroup); double halfSceneWidth = 375; // scene.getWidth()/2.0; double halfSceneHeight = 275; // scene.getHeight()/2.0; cam.p.setX(halfSceneWidth); cam.ip.setX(-halfSceneWidth); cam.p.setY(halfSceneHeight); cam.ip.setY(-halfSceneHeight); frameCam(stage, scene); scene.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { mousePosX = me.getX(); mousePosY = me.getY(); mouseOldX = me.getX(); mouseOldY = me.getY(); //System.out.println("scene.setOnMousePressed " + me); } }); scene.setOnMouseDragged(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) { mouseOldX = mousePosX; mouseOldY = mousePosY; mousePosX = me.getX(); mousePosY = me.getY(); mouseDeltaX = mousePosX - mouseOldX; mouseDeltaY = mousePosY - mouseOldY; if (me.isAltDown() && me.isShiftDown() && me.isPrimaryButtonDown()) { double rzAngle = cam.rz.getAngle(); cam.rz.setAngle(rzAngle - mouseDeltaX); } else if (me.isAltDown() && me.isPrimaryButtonDown()) { double ryAngle = cam.ry.getAngle(); cam.ry.setAngle(ryAngle - mouseDeltaX); double rxAngle = cam.rx.getAngle(); cam.rx.setAngle(rxAngle + mouseDeltaY); } else if (me.isShiftDown() && me.isPrimaryButtonDown()) { double yShear = shear.getY(); shear.setY(yShear + mouseDeltaY / 1000.0); double xShear = shear.getX(); shear.setX(xShear + mouseDeltaX / 1000.0); } else if (me.isAltDown() && me.isSecondaryButtonDown()) { double scale = cam.s.getX(); double newScale = scale + mouseDeltaX * 0.01; cam.s.setX(newScale); cam.s.setY(newScale); cam.s.setZ(newScale); } else if (me.isAltDown() && me.isMiddleButtonDown()) { double tx = cam.t.getX(); double ty = cam.t.getY(); cam.t.setX(tx + mouseDeltaX); cam.t.setY(ty + mouseDeltaY); } } }); scene.setOnKeyPressed(new EventHandler<KeyEvent>() { public void handle(KeyEvent ke) { if (KeyCode.A.equals(ke.getCode())) { resetCam(); shear.setX(0.0); shear.setY(0.0); } if (KeyCode.F.equals(ke.getCode())) { frameCam(stage, scene); shear.setX(0.0); shear.setY(0.0); } if (KeyCode.SPACE.equals(ke.getCode())) { if (stage.isFullScreen()) { stage.setFullScreen(false); frameCam(stage, scene); } else { stage.setFullScreen(true); frameCam(stage, scene); } } } }); stage.setScene(scene); stage.show(); }
From source file:net.sourceforge.pmd.util.fxdesigner.XPathPanelController.java
private void initialiseAutoCompletion() { EventStream<Integer> changesEventStream = xpathExpressionArea.plainTextChanges().map(characterChanges -> { if (characterChanges.getRemoved().length() > 0) { return characterChanges.getRemovalEnd() - 1; }/*from w ww .j a v a 2s.co m*/ return characterChanges.getInsertionEnd(); }); EventStream<Integer> keyCombo = EventStreams.eventsOf(xpathExpressionArea, KeyEvent.KEY_PRESSED) .filter(key -> key.isControlDown() && key.getCode().equals(KeyCode.SPACE)) .map(searchPoint -> xpathExpressionArea.getCaretPosition()); // captured in the closure final ContextMenu autoCompletePopup = new ContextMenuWithNoArrows(); autoCompletePopup.setId("xpathAutocomplete"); autoCompletePopup.setHideOnEscape(true); EventStreams.merge(keyCombo, changesEventStream).map(searchPoint -> { int indexOfSlash = xpathExpressionArea.getText().lastIndexOf("/", searchPoint - 1) + 1; String input = xpathExpressionArea.getText(); if (searchPoint > input.length()) { searchPoint = input.length(); } input = input.substring(indexOfSlash, searchPoint); return Tuples.t(indexOfSlash, input); }).filter(t -> StringUtils.isAlpha(t._2)).subscribe(s -> autoComplete(s._1, s._2, autoCompletePopup)); }
From source file:org.beryx.viewreka.fxapp.codearea.ViewrekaCodeArea.java
public ViewrekaCodeArea() { applyConfiguration(CONFIG);//from ww w . j a v a 2s .co m ContextMenu cm = new ContextMenu(); setPopupWindow(cm); setPopupAlignment(PopupAlignment.CARET_BOTTOM); setPopupAnchorOffset(new Point2D(-20, 1)); cm.setOnShown(ev -> codeTemplatesCoordinates = new double[] { cm.getX(), cm.getY() }); EventHandler<? super KeyEvent> tabHandler = EventHandlerHelper .on(EventPattern.keyPressed(KeyCode.SPACE, KeyCombination.CONTROL_DOWN)) .act(ev -> showContextMenu(cm)).create(); EventHandlerHelper.install(onKeyPressedProperty(), tabHandler); }
From source file:qupath.lib.gui.tma.TMASummaryViewer.java
private void initialize() { model = new TMATableModel(); groupByIDProperty.addListener((v, o, n) -> refreshTableData()); MenuBar menuBar = new MenuBar(); Menu menuFile = new Menu("File"); MenuItem miOpen = new MenuItem("Open..."); miOpen.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.SHORTCUT_DOWN)); miOpen.setOnAction(e -> {// w ww . ja v a 2s. c o m File file = QuPathGUI.getDialogHelper(stage).promptForFile(null, null, "TMA data files", new String[] { "qptma" }); if (file == null) return; setInputFile(file); }); MenuItem miSave = new MenuItem("Save As..."); miSave.setAccelerator( new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); miSave.setOnAction( e -> SummaryMeasurementTableCommand.saveTableModel(model, null, Collections.emptyList())); MenuItem miImportFromImage = new MenuItem("Import from current image..."); miImportFromImage.setAccelerator( new KeyCodeCombination(KeyCode.I, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); miImportFromImage.setOnAction(e -> setTMAEntriesFromOpenImage()); MenuItem miImportFromProject = new MenuItem("Import from current project... (experimental)"); miImportFromProject.setAccelerator( new KeyCodeCombination(KeyCode.P, KeyCombination.SHORTCUT_DOWN, KeyCombination.SHIFT_DOWN)); miImportFromProject.setOnAction(e -> setTMAEntriesFromOpenProject()); MenuItem miImportClipboard = new MenuItem("Import from clipboard..."); miImportClipboard.setOnAction(e -> { String text = Clipboard.getSystemClipboard().getString(); if (text == null) { DisplayHelpers.showErrorMessage("Import scores", "Clipboard is empty!"); return; } int n = importScores(text); if (n > 0) { setTMAEntries(new ArrayList<>(entriesBase)); } DisplayHelpers.showMessageDialog("Import scores", "Number of scores imported: " + n); }); Menu menuEdit = new Menu("Edit"); MenuItem miCopy = new MenuItem("Copy table to clipboard"); miCopy.setOnAction(e -> { SummaryMeasurementTableCommand.copyTableContentsToClipboard(model, Collections.emptyList()); }); combinedPredicate.addListener((v, o, n) -> { // We want any other changes triggered by this to have happened, // so that the data has already been updated Platform.runLater(() -> handleTableContentChange()); }); // Reset the scores for missing cores - this ensures they will be NaN and not influence subsequent results MenuItem miResetMissingScores = new MenuItem("Reset scores for missing cores"); miResetMissingScores.setOnAction(e -> { int changes = 0; for (TMAEntry entry : entriesBase) { if (!entry.isMissing()) continue; boolean changed = false; for (String m : entry.getMeasurementNames().toArray(new String[0])) { if (!TMASummaryEntry.isSurvivalColumn(m) && !Double.isNaN(entry.getMeasurementAsDouble(m))) { entry.putMeasurement(m, null); changed = true; } } if (changed) changes++; } if (changes == 0) { logger.info("No changes made when resetting scores for missing cores!"); return; } logger.info("{} change(s) made when resetting scores for missing cores!", changes); table.refresh(); updateSurvivalCurves(); if (scatterPane != null) scatterPane.updateChart(); if (histogramDisplay != null) histogramDisplay.refreshHistogram(); }); menuEdit.getItems().add(miResetMissingScores); QuPathGUI.addMenuItems(menuFile, miOpen, miSave, null, miImportClipboard, null, miImportFromImage, miImportFromProject); menuBar.getMenus().add(menuFile); menuEdit.getItems().add(miCopy); menuBar.getMenus().add(menuEdit); menuFile.setOnShowing(e -> { boolean imageDataAvailable = QuPathGUI.getInstance() != null && QuPathGUI.getInstance().getImageData() != null && QuPathGUI.getInstance().getImageData().getHierarchy().getTMAGrid() != null; miImportFromImage.setDisable(!imageDataAvailable); boolean projectAvailable = QuPathGUI.getInstance() != null && QuPathGUI.getInstance().getProject() != null && !QuPathGUI.getInstance().getProject().getImageList().isEmpty(); miImportFromProject.setDisable(!projectAvailable); }); // Double-clicking previously used for comments... but conflicts with tree table expansion // table.setOnMouseClicked(e -> { // if (!e.isPopupTrigger() && e.getClickCount() > 1) // promptForComment(); // }); table.setPlaceholder(new Text("Drag TMA data folder onto window, or choose File -> Open")); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); BorderPane pane = new BorderPane(); pane.setTop(menuBar); menuBar.setUseSystemMenuBar(true); // Create options ToolBar toolbar = new ToolBar(); Label labelMeasurementMethod = new Label("Combination method"); labelMeasurementMethod.setLabelFor(comboMeasurementMethod); labelMeasurementMethod .setTooltip(new Tooltip("Method whereby measurements for multiple cores with the same " + TMACoreObject.KEY_UNIQUE_ID + " will be combined")); CheckBox cbHidePane = new CheckBox("Hide pane"); cbHidePane.setSelected(hidePaneProperty.get()); cbHidePane.selectedProperty().bindBidirectional(hidePaneProperty); CheckBox cbGroupByID = new CheckBox("Group by ID"); entriesBase.addListener((Change<? extends TMAEntry> event) -> { if (!event.getList().stream().anyMatch(e -> e.getMetadataValue(TMACoreObject.KEY_UNIQUE_ID) != null)) { cbGroupByID.setSelected(false); cbGroupByID.setDisable(true); } else { cbGroupByID.setDisable(false); } }); cbGroupByID.setSelected(groupByIDProperty.get()); cbGroupByID.selectedProperty().bindBidirectional(groupByIDProperty); CheckBox cbUseSelected = new CheckBox("Use selection only"); cbUseSelected.selectedProperty().bindBidirectional(useSelectedProperty); CheckBox cbSkipMissing = new CheckBox("Hide missing cores"); cbSkipMissing.selectedProperty().bindBidirectional(skipMissingCoresProperty); skipMissingCoresProperty.addListener((v, o, n) -> { table.refresh(); updateSurvivalCurves(); if (histogramDisplay != null) histogramDisplay.refreshHistogram(); updateSurvivalCurves(); if (scatterPane != null) scatterPane.updateChart(); }); toolbar.getItems().addAll(labelMeasurementMethod, comboMeasurementMethod, new Separator(Orientation.VERTICAL), cbHidePane, new Separator(Orientation.VERTICAL), cbGroupByID, new Separator(Orientation.VERTICAL), cbUseSelected, new Separator(Orientation.VERTICAL), cbSkipMissing); comboMeasurementMethod.getItems().addAll(MeasurementCombinationMethod.values()); comboMeasurementMethod.getSelectionModel().select(MeasurementCombinationMethod.MEDIAN); selectedMeasurementCombinationProperty.addListener((v, o, n) -> table.refresh()); ContextMenu popup = new ContextMenu(); MenuItem miSetMissing = new MenuItem("Set missing"); miSetMissing.setOnAction(e -> setSelectedMissingStatus(true)); MenuItem miSetAvailable = new MenuItem("Set available"); miSetAvailable.setOnAction(e -> setSelectedMissingStatus(false)); MenuItem miExpand = new MenuItem("Expand all"); miExpand.setOnAction(e -> { if (table.getRoot() == null) return; for (TreeItem<?> item : table.getRoot().getChildren()) { item.setExpanded(true); } }); MenuItem miCollapse = new MenuItem("Collapse all"); miCollapse.setOnAction(e -> { if (table.getRoot() == null) return; for (TreeItem<?> item : table.getRoot().getChildren()) { item.setExpanded(false); } }); popup.getItems().addAll(miSetMissing, miSetAvailable, new SeparatorMenuItem(), miExpand, miCollapse); table.setContextMenu(popup); table.setRowFactory(e -> { TreeTableRow<TMAEntry> row = new TreeTableRow<>(); // // Make rows invisible if they don't pass the predicate // row.visibleProperty().bind(Bindings.createBooleanBinding(() -> { // TMAEntry entry = row.getItem(); // if (entry == null || (entry.isMissing() && skipMissingCoresProperty.get())) // return false; // return entries.getPredicate() == null || entries.getPredicate().test(entry); // }, // skipMissingCoresProperty, // entries.predicateProperty())); // Style rows according to what they contain row.styleProperty().bind(Bindings.createStringBinding(() -> { if (row.isSelected()) return ""; TMAEntry entry = row.getItem(); if (entry == null || entry instanceof TMASummaryEntry) return ""; else if (entry.isMissing()) return "-fx-background-color:rgb(225,225,232)"; else return "-fx-background-color:rgb(240,240,245)"; }, row.itemProperty(), row.selectedProperty())); // row.itemProperty().addListener((v, o, n) -> { // if (n == null || n instanceof TMASummaryEntry || row.isSelected()) // row.setStyle(""); // else if (n.isMissing()) // row.setStyle("-fx-background-color:rgb(225,225,232)"); // else // row.setStyle("-fx-background-color:rgb(240,240,245)"); // }); return row; }); BorderPane paneTable = new BorderPane(); paneTable.setTop(toolbar); paneTable.setCenter(table); MasterDetailPane mdTablePane = new MasterDetailPane(Side.RIGHT, paneTable, createSidePane(), true); mdTablePane.showDetailNodeProperty().bind(Bindings.createBooleanBinding( () -> !hidePaneProperty.get() && !entriesBase.isEmpty(), hidePaneProperty, entriesBase)); mdTablePane.setDividerPosition(2.0 / 3.0); pane.setCenter(mdTablePane); model.getEntries().addListener(new ListChangeListener<TMAEntry>() { @Override public void onChanged(ListChangeListener.Change<? extends TMAEntry> c) { if (histogramDisplay != null) histogramDisplay.refreshHistogram(); updateSurvivalCurves(); if (scatterPane != null) scatterPane.updateChart(); } }); Label labelPredicate = new Label(); labelPredicate.setPadding(new Insets(5, 5, 5, 5)); labelPredicate.setAlignment(Pos.CENTER); // labelPredicate.setStyle("-fx-background-color: rgba(20, 120, 20, 0.15);"); labelPredicate.setStyle("-fx-background-color: rgba(120, 20, 20, 0.15);"); labelPredicate.textProperty().addListener((v, o, n) -> { if (n.trim().length() > 0) pane.setBottom(labelPredicate); else pane.setBottom(null); }); labelPredicate.setMaxWidth(Double.MAX_VALUE); labelPredicate.setMaxHeight(labelPredicate.getPrefHeight()); labelPredicate.setTextAlignment(TextAlignment.CENTER); predicateMeasurements.addListener((v, o, n) -> { if (n == null) labelPredicate.setText(""); else if (n instanceof TablePredicate) { TablePredicate tp = (TablePredicate) n; if (tp.getOriginalCommand().trim().isEmpty()) labelPredicate.setText(""); else labelPredicate.setText("Predicate: " + tp.getOriginalCommand()); } else labelPredicate.setText("Predicate: " + n.toString()); }); // predicate.set(new TablePredicate("\"Tumor\" > 100")); scene = new Scene(pane); scene.addEventHandler(KeyEvent.KEY_PRESSED, e -> { KeyCode code = e.getCode(); if ((code == KeyCode.SPACE || code == KeyCode.ENTER) && entrySelected != null) { promptForComment(); return; } }); }