@Override public void setDrawMode(DrawMode drawMode) { this.drawMode = drawMode; switch (drawMode) { case TileEraser: ImageCursor cursor = new ImageCursor(new Image("images/eraser.png")); drawCanvas.setCursor(cursor); break; case Select: drawCanvas.setCursor(Cursor.CROSSHAIR); break; case ScriptPencil: drawCanvas.setCursor(Cursor.CLOSED_HAND); break; case ScriptEraser: drawCanvas.setCursor(Cursor.OPEN_HAND); break; default: setCurrentTile(getCurrentTile()); break; } }
public static Cursor provideCursorObjectEnumPropertyLine(ObjectProperty property, PropertiesTable tb, Object owningObject) { ImageCursor c1 = new ImageCursor(new Image("https://svn.java.net/svn/fxtest-golden~images-svn/ControlsTests/JavaProgBarInd80x80.gif")); List possibleTooltips = new ArrayList(); possibleTooltips.add(null); possibleTooltips.add(c1); tb.addObjectEnumPropertyLine(property, possibleTooltips, owningObject); return c1; }
/** @param scene JavaFX Scene where cursor is monitored * @param display SWT Display where the scene's cursor is set */ public static void apply(final Scene scene, final Display display) { // Track JFX cursor, update SWT cursor final ChangeListener<Cursor> cursor_listener = (prop, old, newCursor) -> { // Standard cursors and null are handled by FXCanvas. // Image-based cursors need to be translated into SWT cursor // with code based on GEF FXCanvasEx, // https://github.com/eclipse/gef4/blob/master/org.eclipse.gef4.fx.swt/src/org/eclipse/gef4/fx/swt/canvas/FXCanvasEx.java if (! (newCursor instanceof ImageCursor)) return; // Custom cursor, convert image final ImageCursor cursor = (ImageCursor) newCursor; final ImageData imageData = ImageConverter.convertToSWT(cursor.getImage()); final double hotspotX = cursor.getHotspotX(); final double hotspotY = cursor.getHotspotY(); org.eclipse.swt.graphics.Cursor swtCursor = new org.eclipse.swt.graphics.Cursor( display, imageData, (int) hotspotX, (int) hotspotY); // Set platform cursor on CursorFrame so that it can be // retrieved by FXCanvas' HostContainer // which ultimately sets the cursor on the FXCanvas try { final Method currentCursorFrameAccessor = Cursor.class.getDeclaredMethod("getCurrentFrame", new Class[] {}); currentCursorFrameAccessor.setAccessible(true); final CursorFrame currentCursorFrame = (CursorFrame) currentCursorFrameAccessor.invoke(newCursor, new Object[] {}); currentCursorFrame.setPlatforCursor(org.eclipse.swt.graphics.Cursor.class, swtCursor); } catch (Exception ex) { logger.log(Level.WARNING, "Cannot update SWT cursor from JFX cursor", ex); } }; scene.cursorProperty().addListener(cursor_listener); }
@Override public void start(Stage stage) throws Exception { //stage = new Stage(StageStyle.DECORATED); stage = SceneBuilder.setFullScreen(stage); stage.setScene(new Scene(SceneBuilder.setFxmlLoader(Url.START_UP,new StartUpController(stage)))); //cursor Image image = new Image(Url.CURSOR); //pass in the image path stage.getScene().setCursor(new ImageCursor(image)); setUserAgentStylesheet(STYLESHEET_MODENA); stage.show(); }
/** * @param currentTile the currentTile to set * @return Same tile (necessary for callback support) */ public Tile setCurrentTile(Tile currentTile) { if (drawMode == DrawMode.TileEraser) { drawMode = DrawMode.Pencil1px; } this.currentTile = currentTile; ImageCursor cursor = new ImageCursor(TileUtils.getImage(currentTile, getCurrentPlatform()), 2, 2); drawCanvas.setCursor(cursor); return currentTile; }
public static Cursor loadCursor() { return new ImageCursor(loadImage("img\\cursor.png")); }
public ChangeMouseOnPass(T node, Image onEnter, Image onExit, boolean keepOldHandlers) { this(node, onEnter==null ? null : new ImageCursor(onEnter), onExit==null ? null : new ImageCursor(onExit), keepOldHandlers); }
public ChangeMouseOnPress(T node, Image onPress, Image onRelease, boolean keepOldHandlers) { this(node, onPress==null ? null : new ImageCursor(onPress), onRelease==null ? null : new ImageCursor(onRelease), keepOldHandlers); }
@Override public void start(Stage stage) throws Exception { stage.setResizable(false); Group root = new Group(); root.getStyleClass().add("mainStage"); Scene scene = new Scene(root, 832, 290, Color.BISQUE); scene.getStylesheets().add("styles/sample.css"); TilePane tp = new TilePane(); tp.setPrefColumns(5); tp.setVgap(30); tp.setHgap(15); tp.setPadding(new Insets(10)); tp.getChildren().add( new MyButton("CLOSED_HAND", Cursor.CLOSED_HAND)); tp.getChildren().add( new MyButton("CROSSHAIR", Cursor.CROSSHAIR)); tp.getChildren().add( new MyButton("DEFAULT", Cursor.DEFAULT)); tp.getChildren().add( new MyButton("DISAPPEAR", Cursor.DISAPPEAR)); tp.getChildren().add( new MyButton("E_RESIZE", Cursor.E_RESIZE)); tp.getChildren().add( new MyButton("H_RESIZE", Cursor.H_RESIZE)); tp.getChildren().add( new MyButton("HAND", Cursor.HAND)); tp.getChildren().add( new MyButton("MOVE", Cursor.MOVE)); tp.getChildren().add( new MyButton("N_RESIZE", Cursor.N_RESIZE)); tp.getChildren().add( new MyButton("NE_RESIZE", Cursor.NE_RESIZE)); tp.getChildren().add( new MyButton("NONE", Cursor.NONE)); tp.getChildren().add( new MyButton("NW_RESIZE", Cursor.NW_RESIZE)); tp.getChildren().add( new MyButton("OPEN_HAND", Cursor.OPEN_HAND)); tp.getChildren().add( new MyButton("S_RESIZE", Cursor.S_RESIZE)); tp.getChildren().add( new MyButton("SE_RESIZE", Cursor.SE_RESIZE)); tp.getChildren().add( new MyButton("SW_RESIZE", Cursor.SW_RESIZE)); tp.getChildren().add( new MyButton("TEXT", Cursor.TEXT)); tp.getChildren().add( new MyButton("V_RESIZE", Cursor.V_RESIZE)); tp.getChildren().add( new MyButton("W_RESIZE", Cursor.W_RESIZE)); tp.getChildren().add( new MyButton("WAIT", Cursor.WAIT)); Image img = new Image(getClass().getResourceAsStream("/images/close.png")); ImageCursor CURSOR_SEEK = new ImageCursor(img); tp.getChildren().add( new MyButton("CUSTOM CURSOR", CURSOR_SEEK)); root.getChildren().addAll(tp); stage.setTitle("JavaFx Cursors Demo"); stage.setScene(scene); stage.show(); }
/** * Sets global game cursor using given name to find * the image cursor within assets/ui/cursors/. * Hotspot is location of the pointer end on the image. * * @param imageName name of image file * @param hotspot hotspot location */ public final void setCursor(String imageName, Point2D hotspot) { root.setCursor(new ImageCursor(FXGL.getAssetLoader().loadCursorImage(imageName), hotspot.getX(), hotspot.getY())); }