javafx.scene.input.TouchEvent Java Examples
The following examples show how to use
javafx.scene.input.TouchEvent.
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: SizableImageView.java From Augendiagnose with GNU General Public License v2.0 | 6 votes |
/** * Handle a touch event. * * @param event * The touch event. */ private void handleTouchEvent(final TouchEvent event) { if (event.getEventType().equals(TouchEvent.TOUCH_PRESSED)) { mTouchCount = event.getTouchCount(); } else if (event.getEventType().equals(TouchEvent.TOUCH_RELEASED)) { // getTouchCount gives the number of touch points before the release. mTouchCount = event.getTouchCount() - 1; } if (mTouchCount > 1) { List<TouchPoint> touchPoints = event.getTouchPoints(); double sumX = 0; double sumY = 0; for (TouchPoint point : touchPoints) { sumX += point.getX(); sumY += point.getY(); } mTouchXProperty.set(sumX / touchPoints.size()); mTouchYProperty.set(sumY / touchPoints.size()); } }
Example #2
Source File: HeatControlSkin.java From Enzo with Apache License 2.0 | 6 votes |
private void handleTouchEvent(final TouchEvent TOUCH_EVENT) { final Object SRC = TOUCH_EVENT.getSource(); final EventType TYPE = TOUCH_EVENT.getEventType(); if (SRC.equals(targetIndicator)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getTarget())); resizeText(); } else if (TouchEvent.TOUCH_MOVED == TYPE) { touchRotate(TOUCH_EVENT.getTouchPoint().getSceneX() - getSkinnable().getLayoutX(), TOUCH_EVENT.getTouchPoint().getSceneY() - getSkinnable().getLayoutY(), targetIndicatorRotate); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { getSkinnable().setTarget(Double.parseDouble(value.getText())); fadeBack(); } } }
Example #3
Source File: CustomNavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 5 votes |
private MenuButton buildSubmenu(MenuItem item) { Menu menu = (Menu) item; MenuButton menuButton = new MenuButton(); menuButton.setPopupSide(Side.RIGHT); menuButton.graphicProperty().bind(menu.graphicProperty()); menuButton.textProperty().bind(menu.textProperty()); menuButton.disableProperty().bind(menu.disableProperty()); menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); menuButton.getStyleClass().addAll(item.getStyleClass()); Bindings.bindContent(menuButton.getItems(), menu.getItems()); // To determine if a TOUCH_RELEASED event happens. // The MOUSE_ENTERED results in an unexpected behaviour on touch events. // Event filter triggers before the handler. menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true); // Only when ALWAYS or SOMETIMES if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu if (isTouchUsed) { isTouchUsed = false; return; } // When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES) if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior()) || (hoveredBtn != null && hoveredBtn.isShowing())) { menuButton.show(); // Shows the context-menu if (hoveredBtn != null && hoveredBtn != menuButton) { hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self } } hoveredBtn = menuButton; // Add the button as previously hovered }); } return menuButton; }
Example #4
Source File: NavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 5 votes |
private MenuButton buildSubmenu(MenuItem item) { Menu menu = (Menu) item; MenuButton menuButton = new MenuButton(); menuButton.setPopupSide(Side.RIGHT); menuButton.graphicProperty().bind(menu.graphicProperty()); menuButton.textProperty().bind(menu.textProperty()); menuButton.disableProperty().bind(menu.disableProperty()); menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); menuButton.getStyleClass().addAll(item.getStyleClass()); Bindings.bindContent(menuButton.getItems(), menu.getItems()); // To determine if a TOUCH_RELEASED event happens. // The MOUSE_ENTERED results in an unexpected behaviour on touch events. // Event filter triggers before the handler. menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true); // Only when ALWAYS or SOMETIMES if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu if (isTouchUsed) { isTouchUsed = false; return; } // When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES) if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior()) || (hoveredBtn != null && hoveredBtn.isShowing())) { menuButton.show(); // Shows the context-menu if (hoveredBtn != null && hoveredBtn != menuButton) { hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self } } hoveredBtn = menuButton; // Add the button as previously hovered }); } return menuButton; }
Example #5
Source File: DialogPopup.java From robovm-samples with Apache License 2.0 | 5 votes |
private void installDismissEventHandler(Window window) { oldEventDispatcher = window.getEventDispatcher(); window.setEventDispatcher((event, tail) -> { EventType<?> eventType = event.getEventType(); if (eventType == MouseEvent.MOUSE_PRESSED || eventType == TouchEvent.TOUCH_PRESSED) { // Dismiss hide(); } else { // Event in the popup window. tail.dispatchEvent(event); } return null; }); }
Example #6
Source File: SpaceFXView.java From SpaceFX with Apache License 2.0 | 4 votes |
public SpaceFXView(Stage stage) { gameSoundTheme = Media.getMedia(getClass().getResource("RaceToMars.mp3").toExternalForm(), stage); soundTheme = Media.getMedia(getClass().getResource("CityStomper.mp3").toExternalForm(), stage); gameMediaPlayer = MediaPlayer.getMediaPlayer(gameSoundTheme); mediaPlayer = MediaPlayer.getMediaPlayer(soundTheme); init(stage); initOnBackground(stage); stage.showingProperty().addListener((p,o,value) -> { if(!value) { screenTimer.stop(); timer.stop(); mediaPlayer.stop(); } }); Pane pane = new Pane(canvas, shipTouchArea, hallOfFameBox, playerInitialsLabel, playerInitialsDigits, saveInitialsButton); //pane.setPrefSize(WIDTH, HEIGHT); pane.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); if (SHOW_BUTTONS) { canvas.addEventHandler(TouchEvent.TOUCH_PRESSED, touchHandler); shipTouchArea.setOnTouchMoved(e -> { spaceShip.x = e.getTouchPoint().getX(); spaceShip.y = e.getTouchPoint().getY(); }); } else { shipTouchArea.setOnMouseDragged(e -> { spaceShip.x = e.getX(); spaceShip.y = e.getY(); }); } saveInitialsButton.setOnAction(e -> storePlayer()); setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))); getChildren().add(pane); // Start playing background music if (PLAY_MUSIC) { mediaPlayer.play(); } // Start timer to toggle between start screen and hall of fame screenTimer.start(); }
Example #7
Source File: RadialBargraphSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void handleTouchEvent(final TouchEvent TOUCH_EVENT) { final Object SRC = TOUCH_EVENT.getSource(); final EventType TYPE = TOUCH_EVENT.getEventType(); if (SRC.equals(threshold)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText("Threshold"); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getThreshold())); resizeText(); } else if (TouchEvent.TOUCH_MOVED == TYPE) { touchRotate(TOUCH_EVENT.getTouchPoint().getSceneX() - getSkinnable().getLayoutX(), TOUCH_EVENT.getTouchPoint().getSceneY() - getSkinnable().getLayoutY(), thresholdRotate); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { getSkinnable().setThreshold(Double.parseDouble(value.getText())); fadeBackToInteractive(); } } else if (SRC instanceof Marker) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText(((Marker) SRC).getText()); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", ((Marker) SRC).getValue())); resizeText(); } else if (TouchEvent.TOUCH_MOVED == TYPE) { touchRotate(TOUCH_EVENT.getTouchPoint().getSceneX() - getSkinnable().getLayoutX(), TOUCH_EVENT.getTouchPoint().getSceneY() - getSkinnable().getLayoutY(), getSkinnable().getMarkers().get(SRC)); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { ((Marker) SRC).setValue(Double.parseDouble(value.getText())); fadeBackToInteractive(); } } else if (SRC.equals(minMeasuredValue)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText("Min"); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMinMeasuredValue())); resizeText(); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { fadeBackToInteractive(); } } else if (SRC.equals(maxMeasuredValue)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText("Max"); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMaxMeasuredValue())); resizeText(); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { fadeBackToInteractive(); } } }
Example #8
Source File: GaugeSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void handleTouchEvent(final TouchEvent TOUCH_EVENT) { final Object SRC = TOUCH_EVENT.getSource(); final EventType TYPE = TOUCH_EVENT.getEventType(); if (SRC.equals(threshold)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText("Threshold"); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getThreshold())); resizeText(); } else if (TouchEvent.TOUCH_MOVED == TYPE) { touchRotate(TOUCH_EVENT.getTouchPoint().getSceneX() - getSkinnable().getLayoutX(), TOUCH_EVENT.getTouchPoint().getSceneY() - getSkinnable().getLayoutY(), thresholdRotate); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { getSkinnable().setThreshold(Double.parseDouble(value.getText())); fadeBackToInteractive(); } } else if (SRC instanceof Marker) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText(((Marker) SRC).getText()); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", ((Marker) SRC).getValue())); resizeText(); } else if (TouchEvent.TOUCH_MOVED == TYPE) { touchRotate(TOUCH_EVENT.getTouchPoint().getSceneX() - getSkinnable().getLayoutX(), TOUCH_EVENT.getTouchPoint().getSceneY() - getSkinnable().getLayoutY(), getSkinnable().getMarkers().get(SRC)); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { ((Marker) SRC).setValue(Double.parseDouble(value.getText())); fadeBackToInteractive(); } } else if (SRC.equals(minMeasuredValue)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText("Min"); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMinMeasuredValue())); resizeText(); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { fadeBackToInteractive(); } } else if (SRC.equals(maxMeasuredValue)) { if (TouchEvent.TOUCH_PRESSED == TYPE) { unit.setText("Max"); value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMaxMeasuredValue())); resizeText(); } else if (TouchEvent.TOUCH_RELEASED == TYPE) { fadeBackToInteractive(); } } }