Java Code Examples for javafx.scene.input.MouseEvent#getEventType()

The following examples show how to use javafx.scene.input.MouseEvent#getEventType() . 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: VuMeterSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void handleMouseEvent(final MouseEvent EVENT) {        
    if (active && MouseEvent.MOUSE_ENTERED == EVENT.getEventType()) {
        final Region SRC = (Region) EVENT.getSource();            
        if (Orientation.HORIZONTAL == getSkinnable().getOrientation()) {
            for (int i = 0 ; i < leds.size() ; i++) {
                leds.get(i).getStyleClass().remove("led-on");
                if (i <= leds.indexOf(SRC)) {
                    leds.get(i).getStyleClass().add("led-on");
                }                
            }            
        } else {
            for (int i = 0 ; i < leds.size() ; i++) {
                leds.get(i).getStyleClass().remove("led-on");
                if (i >= leds.indexOf(SRC)) {
                    leds.get(i).getStyleClass().add("led-on");
                }
            }
        }
    }
}
 
Example 2
Source File: PointerEventHandler.java    From jfxvnc with Apache License 2.0 6 votes vote down vote up
private void sendMouseEvents(MouseEvent event) {

    xPosProperty.set((int) Math.floor(event.getX() / zoomLevel));
    yPosProperty.set((int) Math.floor(event.getY() / zoomLevel));

    byte buttonMask = 0;
    if (event.getEventType() == MouseEvent.MOUSE_PRESSED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
      if (event.isMiddleButtonDown()) {
        buttonMask = 2;
      } else if (event.isSecondaryButtonDown()) {
        buttonMask = 4;
      } else {
        buttonMask = 1;
      }
      fire(new PointerEvent(buttonMask, xPosProperty.get(), yPosProperty.get()));
    } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED || event.getEventType() == MouseEvent.MOUSE_MOVED) {
      buttonMask = 0;
    }

    fire(new PointerEvent(buttonMask, xPosProperty.get(), yPosProperty.get()));

  }
 
Example 3
Source File: ParetoPanel.java    From charts with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the clicks on DataDots and ParetoBars
 * @param EVT
 */
private void handleMouseEvents(final MouseEvent EVT) {
    final EventType<? extends MouseEvent> TYPE = EVT.getEventType();
    double                                X    = EVT.getX();
    double                                Y    = EVT.getY();

    if(MouseEvent.MOUSE_PRESSED.equals(TYPE)) {
        for (DataDot dot: dataDots) {
            if(insideDataDot(X,Y,dot)) {
                showPopup(EVT.getScreenX(),EVT.getScreenY(),dot);
                return;
            }
        }
        for(ParetoBar bar: paretoModel.getData()) {
            if(insideBar(X,Y,bar)) {
                if(EVT.isShiftDown()){
                    filterChartByBar(bar);
                }else {
                    cascadeIntoBar(bar);
                }
                break;
            }
        }

    }
}
 
Example 4
Source File: HeatControlSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void handleMouseEvent(final MouseEvent MOUSE_EVENT) {
    final Object    SRC  = MOUSE_EVENT.getSource();
    final EventType TYPE = MOUSE_EVENT.getEventType();
    if (SRC.equals(targetIndicator)) {
        if (MouseEvent.MOUSE_PRESSED == TYPE) {    
            userAction = true;
            value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getTarget()));
            resizeText();                
        } else if (MouseEvent.MOUSE_DRAGGED == TYPE) {
            touchRotate(MOUSE_EVENT.getSceneX() - getSkinnable().getLayoutX(), MOUSE_EVENT.getSceneY() - getSkinnable().getLayoutY(), targetIndicatorRotate);                
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {                
            getSkinnable().setTarget(Double.parseDouble(newTarget));
            fadeBack();
        }
    }
}
 
Example 5
Source File: ModernSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
public void handleMouseEvent(final MouseEvent EVENT) {
    if (gauge.isDisabled()) return;
    final EventType TYPE = EVENT.getEventType();
    if (MouseEvent.MOUSE_PRESSED.equals(TYPE)) {
        gauge.fireEvent(gauge.BTN_PRESSED_EVENT);
        centerKnob.setFill(new LinearGradient(0.5 * size, 0.2708333333333333 * size,
                                              0.5 * size, 0.7291666666666666 * size,
                                              false, CycleMethod.NO_CYCLE,
                                              new Stop(0.0, Color.rgb(31, 31, 31)),
                                              new Stop(1.0, Color.rgb(69, 70, 73))));
        valueText.setTranslateY(size * 0.501);
        subTitleText.setTranslateY(size * 0.3525);
        unitText.setTranslateY(size * 0.6675);
    } else if (MouseEvent.MOUSE_RELEASED.equals(TYPE)) {
        gauge.fireEvent(gauge.BTN_RELEASED_EVENT);
        centerKnob.setFill(new LinearGradient(0.5 * size, 0.2708333333333333 * size,
                                              0.5 * size, 0.7291666666666666 * size,
                                              false, CycleMethod.NO_CYCLE,
                                              new Stop(0.0, Color.rgb(69, 70, 73)),
                                              new Stop(1.0, Color.rgb(31, 31, 31))));
        valueText.setTranslateY(size * 0.5);
        subTitleText.setTranslateY(size * 0.35);
        unitText.setTranslateY(size * 0.67);
    }
}
 
Example 6
Source File: WebViewEventDispatcher.java    From oim-fx with MIT License 5 votes vote down vote up
private void processMouseEvent(MouseEvent ev) {
    if (page == null) {
        return;
    }

    // RT-24511
    EventType<? extends MouseEvent> type = ev.getEventType();
    double x = ev.getX();
    double y = ev.getY();
    double screenX = ev.getScreenX();
    double screenY = ev.getScreenY();
    if (type == MouseEvent.MOUSE_EXITED) {
        type = MouseEvent.MOUSE_MOVED;
        x = Short.MIN_VALUE;
        y = Short.MIN_VALUE;
        Point2D screenPoint = webView.localToScreen(x, y);
        if (screenPoint == null) {
            return;
        }
        screenX = screenPoint.getX();
        screenY = screenPoint.getY();
    }

    final Integer id = idMap.get(type);
    if (id == null) {
        // not supported by webkit
        return;
    }
    WCMouseEvent mouseEvent =
            new WCMouseEvent(id, idMap.get(ev.getButton()),
                ev.getClickCount(), (int) x, (int) y,
                (int) screenX, (int) screenY,
                System.currentTimeMillis(),
                ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(),
                ev.isMetaDown(), ev.isPopupTrigger());
    page.dispatchMouseEvent(mouseEvent);
    ev.consume();
}
 
Example 7
Source File: MouseEventHandler.java    From CrazyAlpha with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public void handle(MouseEvent event) {
        if (event.getEventType() == MouseEvent.MOUSE_MOVED) {
            BaseModel model = Game.getInstance().getModelManager().getAllModels()[0];
            model.setX(event.getX());
            model.setY(event.getY());
//            System.out.printf("getX=%f, getY=%f\n", model.x, model.y);
        }
    }
 
Example 8
Source File: MouseDragSnippet.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
protected void onMouseEvent(MouseEvent event) {
	if (pressed == null) {
		// no processing if no node is pressed
		return;
	}

	// node is pressed, process all mouse events
	EventType<? extends Event> type = event.getEventType();
	if (type.equals(MouseEvent.MOUSE_RELEASED)) {
		System.out.println("release " + pressed);
		pressed.setEffect(null);
		IAnchor ifxAnchor = anchors.get(pressed);
		if (ifxAnchor != null) {
			Set<AnchorKey> keys = ifxAnchor.positionsUnmodifiableProperty()
					.keySet();
			for (AnchorKey key : keys) {
				key.getAnchored().setEffect(new BoxBlur());
			}
		}
		pressed = null;
		nodesUnderMouse.clear();
	} else if (type.equals(MouseEvent.MOUSE_DRAGGED)) {
		double dx = event.getSceneX() - startMousePosition.getX();
		double dy = event.getSceneY() - startMousePosition.getY();
		pressed.setLayoutX(startLayoutPosition.getX() + dx);
		pressed.setLayoutY(startLayoutPosition.getY() + dy);
		boolean changed = updateNodesUnderMouse(event.getSceneX(),
				event.getSceneY());
		if (changed) {
			System.out.println(
					"targets: " + Arrays.asList(nodesUnderMouse.toArray()));
		}
	}
}
 
Example 9
Source File: GaugeSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public void handleMouseEvent(final MouseEvent EVENT) {
    if (gauge.isDisabled()) return;
    final EventType TYPE = EVENT.getEventType();
    if (MouseEvent.MOUSE_PRESSED == TYPE) {
        gauge.fireEvent(gauge.BTN_PRESSED_EVENT);
        drawKnob(true);
    } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
        gauge.fireEvent(gauge.BTN_RELEASED_EVENT);
        drawKnob(false);
    }
}
 
Example 10
Source File: VSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public void handleMouseEvent(final MouseEvent EVENT) {
    if (gauge.isDisabled()) return;
    final EventType TYPE = EVENT.getEventType();
    if (MouseEvent.MOUSE_PRESSED == TYPE) {
        gauge.fireEvent(gauge.BTN_PRESSED_EVENT);
        drawKnob(true);
    } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
        gauge.fireEvent(gauge.BTN_RELEASED_EVENT);
        drawKnob(false);
    }
}
 
Example 11
Source File: UICanvas.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	MouseButton btn = event.getButton();
	if (!(event.getTarget() instanceof Canvas)) {
		return;
	}

	Canvas c = (Canvas) event.getTarget();
	Point2D p = c.sceneToLocal(event.getSceneX(), event.getSceneY());
	int mousex = (int) p.getX();
	int mousey = (int) p.getY();

	if (event.getEventType() == MouseEvent.MOUSE_MOVED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
		canvas.mouseMoved(mousex, mousey);
		canvas.setLastMousePosition(mousex, mousey);
		if (mouseDown) {
			this.canvas.requestPaint();
		}
	} else {
		if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
			mouseDown = true;
			canvas.mousePressed(mousex, mousey, btn);
		} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
			canvas.mouseReleased(mousex, mousey, btn);
			mouseDown = false;
			canvas.requestPaint();
		}
	}

}
 
Example 12
Source File: InteractiveGaugeSkin.java    From medusademo with Apache License 2.0 5 votes vote down vote up
public void handleMouseEvent(final MouseEvent EVENT) {
    if (getSkinnable().isDisabled()) return;
    final EventType TYPE = EVENT.getEventType();
    if (MouseEvent.MOUSE_PRESSED == TYPE) {
        getSkinnable().fireEvent(getSkinnable().BTN_PRESSED_EVENT);
        drawKnob(true);
    } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
        getSkinnable().fireEvent(getSkinnable().BTN_RELEASED_EVENT);
        drawKnob(false);
    }
}
 
Example 13
Source File: HSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public void handleMouseEvent(final MouseEvent EVENT) {
    if (gauge.isDisabled()) return;
    final EventType TYPE = EVENT.getEventType();
    if (MouseEvent.MOUSE_PRESSED == TYPE) {
        gauge.fireEvent(gauge.BTN_PRESSED_EVENT);
        drawKnob(true);
    } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
        gauge.fireEvent(gauge.BTN_RELEASED_EVENT);
        drawKnob(false);
    }
}
 
Example 14
Source File: CardAppleMouse.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void processMouseEvent(MouseEvent event) {
    if (event.getEventType() == MouseEvent.MOUSE_MOVED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
        Node source = (Node) event.getSource();
        updateLocation(event.getSceneX(), event.getSceneY(), source.getBoundsInLocal());
        event.consume();
    }
    if (event.getEventType() == MouseEvent.MOUSE_PRESSED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
        mousePressed(event);
        event.consume();
    } else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
        mouseReleased(event);
        event.consume();
    }
}
 
Example 15
Source File: ResizeHelper.java    From JavaFX-Chat with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(),
            mouseEventY = mouseEvent.getSceneY(),
            sceneWidth = scene.getWidth(),
            sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType)) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if(MouseEvent.MOUSE_EXITED.equals(mouseEventType) || MouseEvent.MOUSE_EXITED_TARGET.equals(mouseEventType)){
        scene.setCursor(Cursor.DEFAULT);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) {
        if (Cursor.DEFAULT.equals(cursorEvent) == false) {
            if (Cursor.W_RESIZE.equals(cursorEvent) == false && Cursor.E_RESIZE.equals(cursorEvent) == false) {
                double minHeight = stage.getMinHeight() > (border*2) ? stage.getMinHeight() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.N_RESIZE.equals(cursorEvent) == true || Cursor.NE_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        stage.setHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        stage.setHeight(mouseEventY + startY);
                    }
                }
            }

            if (Cursor.N_RESIZE.equals(cursorEvent) == false && Cursor.S_RESIZE.equals(cursorEvent) == false) {
                double minWidth = stage.getMinWidth() > (border*2) ? stage.getMinWidth() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.W_RESIZE.equals(cursorEvent) == true || Cursor.SW_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        stage.setWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        stage.setWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
Example 16
Source File: ResizeHelper.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(), 
           mouseEventY = mouseEvent.getSceneY(),
           sceneWidth = scene.getWidth(),
           sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType) == true) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType) == true) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType) == true) {
        if (Cursor.DEFAULT.equals(cursorEvent) == false) {
            if (Cursor.W_RESIZE.equals(cursorEvent) == false && Cursor.E_RESIZE.equals(cursorEvent) == false) {
                double minHeight = stage.getMinHeight() > (border*2) ? stage.getMinHeight() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.N_RESIZE.equals(cursorEvent) == true || Cursor.NE_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        stage.setHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        stage.setHeight(mouseEventY + startY);
                    }
                }
            }

            if (Cursor.N_RESIZE.equals(cursorEvent) == false && Cursor.S_RESIZE.equals(cursorEvent) == false) {
                double minWidth = stage.getMinWidth() > (border*2) ? stage.getMinWidth() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.W_RESIZE.equals(cursorEvent) == true || Cursor.SW_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        stage.setWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        stage.setWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
Example 17
Source File: ParallelCoordinatesChart.java    From charts with Apache License 2.0 4 votes vote down vote up
private void handleMouseEvent(final MouseEvent EVT) {
    final EventType<? extends MouseEvent> TYPE = EVT.getEventType();
    final double                          X    = EVT.getX();
    final double                          Y    = EVT.getY();

    if (MouseEvent.MOUSE_PRESSED.equals(TYPE)) {
        selectedCategory = selectCategory(X, Y);
        selectionStartY  = null == selectedCategory ? -1 : Y;
        if (selectionStartY >= HEADER_HEIGHT) {
            selectedObjects.clear();
            selectionRectCategory = selectedCategory;
            selectionRect.setX(selectionStartX);
            selectionRect.setY(Y);
            selectionRect.setWidth(0);
            selectionRect.setHeight(0);
            rect.setVisible(true);
            resizeSelectionRect();
        } else {
            rect.setVisible(false);
            /*
            selectionRect.setX(0);
            selectionRect.setY(0);
            selectionRect.setWidth(0);
            selectionRect.setHeight(0);
            resizeSelectionRect();
            */
            dragText.setVisible(true);
            dragText.setText(selectedCategory);
            dragText.setX(X - dragText.getLayoutBounds().getWidth() * 0.5);
            dragText.setY(Y);
        }
        wasDragged = false;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(TYPE)) {
        if (rect.isVisible()) {
            selectionRect.setHeight(Helper.clamp(selectionStartY, height - 0.5, Y) - selectionRect.getY());
            selectionRect.setWidth(AXIS_WIDTH);
            resizeSelectionRect();
        } else if (dragText.isVisible()) {
            dragText.setX(X - dragText.getLayoutBounds().getWidth() * 0.5);
            dragText.setY(Y);
        }
        wasDragged = true;
    } else if (MouseEvent.MOUSE_RELEASED.equals(TYPE)) {
        if (dragText.isVisible() && wasDragged) {
            dragText.setVisible(false);
            String targetCategory = selectCategory(X, Y);
            if (null != targetCategory) {
                shiftCategory(dragText.getText(), categories.indexOf(targetCategory));
                selectionRect.setX(getAxisXOfCategory(selectionRectCategory) - AXIS_WIDTH * 0.5);
                redraw();
            }
        } else if (rect.isVisible() && wasDragged) {
            selectionEndY = null == selectedCategory ? -1 : Helper.clamp(selectionStartY, height - 0.5, Y);
            if (selectionStartY > HEADER_HEIGHT && selectionEndY > -1) {
                selectionRect.setWidth(10);
                selectionRect.setY(selectionStartY);
                selectionRect.setHeight(selectionEndY - selectionStartY);
                selectObjectsAtCategory(selectedCategory, selectionStartY, selectionEndY);
            } else {
                selectedItems.clear();
            }
        } else {
            selectedItems.clear();
            if (getSmoothConnections()) {
                drawSmoothConnections();
            } else {
                drawConnections();
            }
        }
        wasDragged = false;
    }
}
 
Example 18
Source File: InfluenceAnalysisUI.java    From SONDY with GNU General Public License v3.0 4 votes vote down vote up
public final VBox createNetworkVisualization(){
    System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
    Viewer viewer = new Viewer(AppParameters.authorNetwork, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
    view = viewer.addDefaultView(false); 
    viewer.enableAutoLayout();
    view.resizeFrame(Main.columnWidthLEFT, 290);
    swingNode = new CustomSwingNode();
    swingNode.setContent(view);
    swingNode.resize(Main.columnWidthLEFT, 290);
    EventHandler<MouseEvent> mouseHandlerGraphClick = new EventHandler<MouseEvent>() { 
        @Override 
        public void handle(MouseEvent mouseEvent) { 
            if (mouseEvent.getEventType() == MouseEvent.MOUSE_PRESSED) {
                if(mouseEvent.getButton() == MouseButton.SECONDARY){
                    Node node = (Node) view.findNodeOrSpriteAt(mouseEvent.getX(), mouseEvent.getY());
                    if(node != null){
                        userMessages(node.getId());
                    }
                }
                if(mouseEvent.getButton() == MouseButton.PRIMARY){
                    double translateCoeff = view.getCamera().getViewPercent();
                    Point3 center = view.getCamera().getViewCenter();
                    if(mouseEvent.getY()>175){
                        view.getCamera().setViewCenter(center.x, center.y-5*translateCoeff, center.z);
                    }else{
                        view.getCamera().setViewCenter(center.x, center.y+5*translateCoeff, center.z);
                    }
                    if(mouseEvent.getX()>275){
                        view.getCamera().setViewCenter(center.x+5*translateCoeff, center.y, center.z);
                    }else{
                        view.getCamera().setViewCenter(center.x-5*translateCoeff, center.y, center.z);
                    }
                }
                if(mouseEvent.getButton() == MouseButton.MIDDLE){
                    view.getCamera().setViewPercent(view.getCamera().getViewPercent()/2);
                }
            }
        }
    };   
    EventHandler<ScrollEvent> mouseHandlerGraphScroll = new EventHandler<ScrollEvent>() { 
        @Override
        public void handle(ScrollEvent event) {
            if(event.getDeltaY() < 0){
                view.getCamera().setViewPercent(view.getCamera().getViewPercent()*2);
            }else{
                view.getCamera().setViewPercent(view.getCamera().getViewPercent()/2);
            }
        }
    };   
    swingNode.setOnMousePressed(mouseHandlerGraphClick);
    swingNode.setOnScroll(mouseHandlerGraphScroll);
    VBox graphBox = new VBox();
    graphBox.getChildren().addAll(new Rectangle(Main.columnWidthLEFT,0),swingNode);
    initializeNetworkVisualizationStyle();
    return graphBox;
}
 
Example 19
Source File: ResizeHelper.java    From CustomStage with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(),
            mouseEventY = mouseEvent.getSceneY(),
            sceneWidth = scene.getWidth(),
            sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType)) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if (MouseEvent.MOUSE_EXITED.equals(mouseEventType) || MouseEvent.MOUSE_EXITED_TARGET.equals(mouseEventType)) {
        scene.setCursor(Cursor.DEFAULT);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) {
        if (!Cursor.DEFAULT.equals(cursorEvent)) {
            if (!Cursor.W_RESIZE.equals(cursorEvent) && !Cursor.E_RESIZE.equals(cursorEvent)) {
                double minHeight = stage.getMinHeight() > (border * 2) ? stage.getMinHeight() : (border * 2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.N_RESIZE.equals(cursorEvent)
                        || Cursor.NE_RESIZE.equals(cursorEvent)) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        setStageHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        setStageHeight(mouseEventY + startY);
                    }
                }
            }

            if (!Cursor.N_RESIZE.equals(cursorEvent) && !Cursor.S_RESIZE.equals(cursorEvent)) {
                double minWidth = stage.getMinWidth() > (border * 2) ? stage.getMinWidth() : (border * 2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.W_RESIZE.equals(cursorEvent)
                        || Cursor.SW_RESIZE.equals(cursorEvent)) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        setStageWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        setStageWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
Example 20
Source File: GaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void handleMouseEvent(final MouseEvent MOUSE_EVENT) {
    final Object    SRC  = MOUSE_EVENT.getSource();
    final EventType TYPE = MOUSE_EVENT.getEventType();
    if (getSkinnable().isInteractive() && SRC.equals(threshold)) {
        if (MouseEvent.MOUSE_PRESSED == TYPE) {
            unit.setText("Threshold");
            value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getThreshold()));
            resizeText();
        } else if (MouseEvent.MOUSE_DRAGGED == TYPE) {
            touchRotate(MOUSE_EVENT.getSceneX() - getSkinnable().getLayoutX(), MOUSE_EVENT.getSceneY() - getSkinnable().getLayoutY(), thresholdRotate);
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
            getSkinnable().setThreshold(Double.parseDouble(value.getText()));
            fadeBackToInteractive();
        }
    } else if (getSkinnable().isInteractive() && SRC instanceof Marker) {
        if (MouseEvent.MOUSE_PRESSED == TYPE) {
            unit.setText(((Marker) SRC).getText());
            value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", ((Marker) SRC).getValue()));
            resizeText();
        } else if (MouseEvent.MOUSE_DRAGGED == TYPE) {
            touchRotate(MOUSE_EVENT.getSceneX() - getSkinnable().getLayoutX(), MOUSE_EVENT.getSceneY() - getSkinnable().getLayoutY(), getSkinnable().getMarkers().get(SRC));
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
            ((Marker) SRC).setValue(Double.parseDouble(value.getText()));
            fadeBackToInteractive();
        }
    } else if (getSkinnable().isInteractive() && SRC.equals(minMeasuredValue)) {
        if (MouseEvent.MOUSE_PRESSED == TYPE) {
            unit.setText("Min");
            value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMinMeasuredValue()));
            resizeText();
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
            fadeBackToInteractive();
        }
    } else if (getSkinnable().isInteractive() && SRC.equals(maxMeasuredValue)) {
        if (MouseEvent.MOUSE_PRESSED == TYPE) {
            unit.setText("Max");
            value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMaxMeasuredValue()));
            resizeText();
        } else if (MouseEvent.MOUSE_RELEASED == TYPE) {
            fadeBackToInteractive();
        }
    }
}