下面列出了怎么用javafx.scene.Cursor的API类实例代码及写法,或者点击链接到github查看源代码。
public void registerListener() {
setOnMouseEntered(event -> {
if (!isDisabled()) {
requestFocus();
setCursor(remoteCursor != null ? remoteCursor : Cursor.DEFAULT);
}
});
setOnMouseExited(event -> {
if (!isDisabled()) {
setCursor(Cursor.DEFAULT);
}
});
zoomLevelProperty().addListener(l -> {
if (getImage() != null) {
setFitHeight(getImage().getHeight() * zoomLevelProperty().get());
}
});
}
@Override
public Node apply(Region region, Wrapper<Point2D> mouseLocation) {
final DoubleProperty xProperty = region.layoutXProperty();
final DoubleProperty yProperty = region.layoutYProperty();
final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty();
final DoubleBinding halfHeightProperty = heightProperty.divide(2);
final Rectangle resizeHandleW = new Rectangle(handleRadius, handleRadius, Color.BLACK);
resizeHandleW.xProperty().bind(xProperty.subtract(handleRadius / 2));
resizeHandleW.yProperty().bind(yProperty.add(halfHeightProperty).subtract(handleRadius / 2));
setUpDragging(resizeHandleW, mouseLocation, Cursor.W_RESIZE);
resizeHandleW.setOnMouseDragged(event -> {
if(mouseLocation.value != null) {
dragWest(event, mouseLocation, region, handleRadius);
mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY());
}
});
return resizeHandleW;
}
/** Activate mode
*
* <p>Display required UI elements, hook event handlers
* @param mode Desired mode
*/
private void startMode(final Mode mode)
{
this.mode = mode;
if (mode == Mode.APPEND)
{
handle_group.getScene().addEventFilter(MouseEvent.MOUSE_PRESSED, append_mouse_filter);
handle_group.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, append_mouse_filter);
handle_group.getChildren().setAll(line);
line.setVisible(false);
if (cursor_add != null)
handle_group.getScene().setCursor(cursor_add);
}
else
{
final ObservableList<Node> parent = handle_group.getChildren();
parent.clear();
for (int i = 0; i < points.size(); ++i)
parent.add(new Handle(i));
handle_group.getScene().setCursor(Cursor.HAND);
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
initializeConnections();
isConnectionInProgress = new SimpleBooleanProperty(false);
isConnectionInProgress.addListener(
(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
if (newValue != null) {
mainViewContainer.setDisable(newValue);
mainViewContainer.getScene().setCursor(newValue ? Cursor.WAIT : Cursor.DEFAULT);
}
}
);
timeoutField.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
timeoutField.setText(newValue.replaceAll("[^\\d]", ""));
}
});
}
@Override
public Node apply(Region region, Wrapper<Point2D> mouseLocation) {
final DoubleProperty xProperty = region.layoutXProperty();
final DoubleProperty yProperty = region.layoutYProperty();
final Rectangle resizeHandleNW = new Rectangle(handleRadius, handleRadius, Color.BLACK);
resizeHandleNW.xProperty().bind(xProperty.subtract(handleRadius / 2));
resizeHandleNW.yProperty().bind(yProperty.subtract(handleRadius / 2));
setUpDragging(resizeHandleNW, mouseLocation, Cursor.NW_RESIZE);
resizeHandleNW.setOnMouseDragged(event -> {
if(mouseLocation.value != null) {
dragNorth(event, mouseLocation, region, handleRadius);
dragWest(event, mouseLocation, region, handleRadius);
mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY());
}
});
return resizeHandleNW;
}
private void initLine() {
// mouse transparent if not editable
line.setMouseTransparent(true);
pickLine.setPickOnBounds(true);
pickLine.setStroke(Color.TRANSPARENT);
pickLine.setStrokeWidth(getPickingDistance());
pickLine.mouseTransparentProperty().bind(editableIndicatorProperty().not());
pickLine.setOnMousePressed(mouseEvent -> {
/*
* Record a delta distance for the drag and drop operation. Because layoutLine() sets the start/end points
* we have to use these here. It is enough to use the start point. For X indicators, start x and end x are
* identical and for Y indicators start y and end y are identical.
*/
dragDelta.x = pickLine.getStartX() - mouseEvent.getX();
dragDelta.y = pickLine.getStartY() - mouseEvent.getY();
pickLine.setCursor(Cursor.MOVE);
mouseEvent.consume();
});
}
@Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
/* Drag and Drop */
borderPane.setOnMousePressed(event -> {
xOffset = getLocalStage().getX() - event.getScreenX();
yOffset = getLocalStage().getY() - event.getScreenY();
borderPane.setCursor(Cursor.CLOSED_HAND);
});
borderPane.setOnMouseDragged(event -> {
getLocalStage().setX(event.getScreenX() + xOffset);
getLocalStage().setY(event.getScreenY() + yOffset);
});
borderPane.setOnMouseReleased(event -> {
borderPane.setCursor(Cursor.DEFAULT);
});
//设置图标
setIcon("images/icon_chatroom.png");
//房间号选择
roomIDChoiceBox.getSelectionModel().selectedItemProperty().addListener(
(ObservableValue<? extends String> ov, String old_val, String new_val)->
{roomID = new_val;});
}
private void changeCursorToScale(Edge edge) {
if (edge == Edge.None) {
changeCursorToDefault();
return;
}
if (edge == Edge.TopLeft || edge == Edge.BottomRight) {
canvas.setCursor(Cursor.NW_RESIZE);
return;
}
if (edge == Edge.TopRight || edge == Edge.BottomLeft) {
canvas.setCursor(Cursor.NE_RESIZE);
return;
}
if (edge == Edge.Top || edge == Edge.Bottom) {
canvas.setCursor(Cursor.N_RESIZE);
return;
}
if (edge == Edge.Left || edge == Edge.Right) {
canvas.setCursor(Cursor.W_RESIZE);
return;
}
throw new IllegalStateException("couldn't find correct cursor for edge:" + edge.name());
}
@Override
protected void configureBindings() {
buttonBinder()
.toProduce(() -> new UpdateTemplates(templatePane, svgGen, true))
.on(updateTemplates)
.bind();
nodeBinder()
.usingInteraction(DnD::new)
.toProduce(i -> new LoadTemplate(svgGen, drawing, new File((String) i.getSrcObject().orElseThrow().getUserData()),
statusController.getProgressBar(), statusController.getLabel(), app))
.on(templatePane)
.first(c -> templatePane.setCursor(Cursor.CLOSED_HAND))
.then((i, c) -> {
final Node srcObj = i.getSrcObject().orElseThrow();
final Point3D pt3d = i.getTgtObject().orElseThrow().sceneToLocal(srcObj.localToScene(i.getTgtLocalPoint())).
subtract(Canvas.ORIGIN.getX() + srcObj.getLayoutX(), Canvas.ORIGIN.getY() + srcObj.getLayoutY(), 0d);
c.setPosition(ShapeFactory.INST.createPoint(pt3d));
})
.when(i -> i.getSrcObject().orElse(null) instanceof ImageView &&
i.getSrcObject().get().getUserData() instanceof String &&
i.getTgtObject().orElse(null) instanceof Canvas)
.endOrCancel(i -> templatePane.setCursor(Cursor.MOVE))
.bind();
}
public PauseResumeButton(boolean isPaused) {
this.isPaused[0] = isPaused;
this.imagePause = new Image(getClass().getResourceAsStream("/gearth/ui/buttons/files/ButtonPause.png"));
this.imagePauseOnHover = new Image(getClass().getResourceAsStream("/gearth/ui/buttons/files/ButtonPauseHover.png"));
this.imageResume = new Image(getClass().getResourceAsStream("/gearth/ui/buttons/files/ButtonResume.png"));
this.imageResumeOnHover = new Image(getClass().getResourceAsStream("/gearth/ui/buttons/files/ButtonResumeHover.png"));
this.imageView = new ImageView();
setCursor(Cursor.DEFAULT);
getChildren().add(imageView);
setOnMouseEntered(onMouseHover);
setOnMouseExited(onMouseHoverDone);
imageView.setImage(isPaused() ? imageResume : imagePause);
setEventHandler(MouseEvent.MOUSE_CLICKED, event -> click());
}
private void setupListeners() {
final TextField textField = getSkinnable();
button.setOnMouseReleased(event -> mouseReleased());
button.setOnMousePressed(event -> mousePressed());
button.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
if(graphic.isVisible())button.setCursor(Cursor.HAND);
else button.setCursor(Cursor.DEFAULT);
});
button.setOnMouseMoved(event -> {
if(graphic.isVisible())button.setCursor(Cursor.HAND);
else button.setCursor(Cursor.DEFAULT);
});
textField.textProperty().addListener((observable, oldValue, newValue) -> textChanged());
textField.focusedProperty().addListener((observable, oldValue, newValue) -> focusChanged());
button.setMinWidth(10);
button.setMinHeight(10);
graphic.setMinWidth(10);
graphic.setMinHeight(10);
}
@Override
public Node apply(Region region, Wrapper<Point2D> mouseLocation) {
final DoubleProperty xProperty = region.layoutXProperty();
final DoubleProperty yProperty = region.layoutYProperty();
final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty();
final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty();
final Rectangle resizeHandleSE = new Rectangle(handleRadius, handleRadius, Color.BLACK);
resizeHandleSE.xProperty().bind(xProperty.add(widthProperty).subtract(handleRadius / 2));
resizeHandleSE.yProperty().bind(yProperty.add(heightProperty).subtract(handleRadius / 2));
setUpDragging(resizeHandleSE, mouseLocation, Cursor.SE_RESIZE);
resizeHandleSE.setOnMouseDragged(event -> {
if(mouseLocation.value != null) {
dragSouth(event, mouseLocation, region, handleRadius);
dragEast(event, mouseLocation, region, handleRadius);
mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY());
}
});
return resizeHandleSE;
}
@Override
public Node apply(Region region, Wrapper<Point2D> mouseLocation) {
final DoubleProperty xProperty = region.layoutXProperty();
final DoubleProperty yProperty = region.layoutYProperty();
final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty();
final DoubleBinding halfWidthProperty = widthProperty.divide(2);
final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty();
final Rectangle resizeHandleS = new Rectangle(handleRadius, handleRadius, Color.BLACK);
resizeHandleS.xProperty().bind(xProperty.add(halfWidthProperty).subtract(handleRadius / 2));
resizeHandleS.yProperty().bind(yProperty.add(heightProperty).subtract(handleRadius / 2));
setUpDragging(resizeHandleS, mouseLocation, Cursor.S_RESIZE);
resizeHandleS.setOnMouseDragged(event -> {
if(mouseLocation.value != null) {
dragSouth(event, mouseLocation, region, handleRadius);
mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY());
}
});
return resizeHandleS;
}
/** setOnMouseExited */
private void mouseExit(final MouseEvent e)
{
deselectMouseAnnotation();
// Redraw if we are actively panning or zooming, or crosshair needs to hide
final boolean need_redraw = mouse_mode.ordinal() > MouseMode.INTERNAL_MODES.ordinal() || show_crosshair;
// Clear mouse position so drawMouseModeFeedback() won't restore cursor
mouse_current = Optional.empty();
// Reset cursor
PlotCursors.setCursor(this, Cursor.DEFAULT);
if (need_redraw)
requestRedraw();
}
protected void mouseOver(MouseEvent event) {
if (isInDraggableZone(event) || dragging) {
region.setCursor(Cursor.S_RESIZE);
} else {
region.setCursor(Cursor.DEFAULT);
}
}
/**
* Disable the TiVo controls and the recording list
*/
private void disableUI() {
if (!uiDisabled) {
logger.debug("Disabling UI");
mainApp.getPrimaryStage().getScene().setCursor(Cursor.WAIT);
uiDisabled = true;
}
}
Button(Color colorWeak, Color colorStrong) {
this.colorStrong = colorStrong;
this.colorWeak = colorWeak;
configureDesign();
setCursor(Cursor.HAND);
getChildren().addAll(rectangleVisual, rectangleSmall, rectangleBig, rectangleWatch);
}
/**
* Creates a new instance of Zoomer.
*
* @param zoomMode initial value of {@link #axisModeProperty() axisMode} property
* @param animated initial value of {@link #animatedProperty() animated} property
*/
public Zoomer(final AxisMode zoomMode, final boolean animated) {
super();
setAxisMode(zoomMode);
setAnimated(animated);
setZoomCursor(Cursor.CROSSHAIR);
setDragCursor(Cursor.CLOSED_HAND);
zoomRectangle.setManaged(false);
zoomRectangle.getStyleClass().add(STYLE_CLASS_ZOOM_RECT);
getChartChildren().add(zoomRectangle);
registerMouseHandlers();
chartProperty().addListener((change, o, n) -> {
if (o != null) {
o.getToolBar().getChildren().remove(zoomButtons);
o.getPlotArea().setBottom(null);
xRangeSlider.prefWidthProperty().unbind();
}
if (n != null) {
if (isAddButtonsToToolBar()) {
n.getToolBar().getChildren().add(zoomButtons);
}
/* always create the slider, even if not visible at first */
final ZoomRangeSlider slider = new ZoomRangeSlider(n);
if (isSliderVisible()) {
n.getPlotArea().setBottom(slider);
xRangeSlider.prefWidthProperty().bind(n.getCanvasForeground().widthProperty());
}
}
});
}
private void setEnhancedDeviceSettings(Stage primaryStage, Scene scene) {
var isARM = System.getProperty("os.arch").toUpperCase().contains("ARM");
if (isARM) {
primaryStage.setFullScreen(true);
primaryStage.setFullScreenExitHint("");
}
if (Platform.isSupported(ConditionalFeature.INPUT_TOUCH)) {
scene.setCursor(Cursor.NONE);
}
}
public EditDataSet() {
super();
editable = true;
setDragCursor(Cursor.CROSSHAIR);
selectRectangle.setManaged(false);
selectRectangle.getStyleClass().add(STYLE_CLASS_SELECT_RECT);
getChartChildren().add(selectRectangle);
registerMouseHandlers();
registerKeyHandlers();
markerPane.setManaged(false);
// register marker pane
chartProperty().addListener((change, o, n) -> {
if (o != null) {
o.getCanvasForeground().getChildren().remove(markerPane);
o.getPlotArea().setBottom(null);
// markerPane.prefWidthProperty().unbind();
// markerPane.prefHeightProperty().unbind();
}
if (n != null) {
n.getCanvasForeground().getChildren().add(markerPane);
markerPane.toFront();
markerPane.setVisible(true);
// markerPane.prefWidthProperty().bind(n.getCanvas().widthProperty());
// markerPane.prefHeightProperty().bind(n.getCanvas().heightProperty());
}
});
}
private Node createBox(Cursor cursor) {
Label label = new Label(cursor.toString());
label.setAlignment(Pos.CENTER);
label.setPrefSize(85, 85);
label.setStyle("-fx-border-color: #aaaaaa; -fx-background-color: #dddddd;");
label.setCursor(cursor);
return label;
}
@Override
public Control getDisplay() {
var checkbox = new JFXCheckBox("");
checkbox.styleProperty().set("-jfx-checked-color: -primary-button-color;");
checkbox.setMnemonicParsing(false);
checkbox.setCursor(Cursor.HAND);
checkbox.selectedProperty().bindBidirectional(this.value);
GridPane.setColumnIndex(checkbox, 1);
return checkbox;
}
/**
* Creates a new instance of the indicator.
*
* @param axis the axis this indicator is associated with
* @param text the text to be shown by the label. Value of {@link #textProperty()}.
*/
protected AbstractValueIndicator(Axis axis, final String text) {
super();
this.axis = axis;
setText(text);
label.mouseTransparentProperty().bind(editableIndicatorProperty().not());
label.pickOnBoundsProperty().set(true);
label.setOnMousePressed(mouseEvent -> {
/*
* Record a delta distance for the drag and drop operation. PROBLEM: At this point, we need to know the
* relative position of the label with respect to the indicator value.
*/
Point2D c = label.sceneToLocal(mouseEvent.getSceneX(), mouseEvent.getSceneY());
dragDelta.x = -(c.getX() + xOffset);
dragDelta.y = c.getY() + yOffset;
label.setCursor(Cursor.MOVE);
mouseEvent.consume();
});
editableIndicatorProperty().addListener((ch, o, n) -> updateMouseListener(n));
updateMouseListener(isEditable());
chartProperty().addListener((obs, oldChart, newChart) -> {
if (oldChart != null) {
removeAxisListener();
removePluginsListListener(oldChart);
}
if (newChart != null) {
addAxisListener();
addPluginsListListener(newChart);
}
});
textProperty().addListener((obs, oldText, newText) -> layoutChildren());
}
private Cursor getCursor(MouseEvent me, Pane pane) {
Cursor cursor = Cursor.DEFAULT;
double grp = 4;
double width = pane.getWidth();
double height = pane.getHeight();
double x = me.getX();
double y = me.getY();
if (x < grp && y < grp) {
// cursor = Cursor.SE_RESIZE;
type = 1;
} else if (x > (width - grp) && y < grp) {
// cursor = Cursor.SW_RESIZE;
type = 2;
} else if (x < grp && y > (height - grp)) {
// cursor = Cursor.SW_RESIZE;
type = 3;
} else if (x > (width - grp) && y > (height - grp)) {
// cursor = Cursor.SE_RESIZE;
type = 4;
} else if (x < grp) {
// cursor = Cursor.H_RESIZE;
type = 5;
} else if (x > (width - grp)) {
// cursor = Cursor.H_RESIZE;
type = 6;
} else if (y < grp) {
cursor = Cursor.V_RESIZE;
type = 7;
} else if (y > (height - grp)) {
// cursor = Cursor.V_RESIZE;
type = 8;
} else {
type = 0;
}
return cursor;
}
private void showDragCursorOnBorders(MouseEvent mouseEvent) {
if (primaryStage.isMaximized() || primaryStage.isFullScreen() || maximized) {
this.setCursor(Cursor.DEFAULT);
return; // maximized mode does not support resize
}
if (!primaryStage.isResizable()) {
return;
}
double x = mouseEvent.getX();
double y = mouseEvent.getY();
if (contentPlaceHolder.getBorder() != null && contentPlaceHolder.getBorder().getStrokes().size() > 0) {
double borderWidth = contentPlaceHolder.snappedLeftInset();
if (isRightEdge(x)) {
if (y < borderWidth) {
this.setCursor(Cursor.NE_RESIZE);
} else if (y > this.getHeight() - borderWidth) {
this.setCursor(Cursor.SE_RESIZE);
} else {
this.setCursor(Cursor.E_RESIZE);
}
} else if (isLeftEdge(x)) {
if (y < borderWidth) {
this.setCursor(Cursor.NW_RESIZE);
} else if (y > this.getHeight() - borderWidth) {
this.setCursor(Cursor.SW_RESIZE);
} else {
this.setCursor(Cursor.W_RESIZE);
}
} else if (isTopEdge(y)) {
this.setCursor(Cursor.N_RESIZE);
} else if (isBottomEdge(y)) {
this.setCursor(Cursor.S_RESIZE);
} else {
this.setCursor(Cursor.DEFAULT);
}
}
}
@Override
public void mouseEntered(CircuitManager manager, CircuitState state) {
Scene scene = manager.getSimulatorWindow().getScene();
prevCursor = scene.getCursor();
scene.setCursor(Cursor.TEXT);
entered = true;
}
public ResizeListener(Stage stage) {
this.stage = stage;
isPressed = false;
cursorEvent = Cursor.DEFAULT;
border = 3;
stageStartH = 0;
stageStartW = 0;
stageStartX = 0;
stageStartY = 0;
this.addResizeListener();
}
/**
* Create a new web displayable.
*
* @param url the url for the displayable.
*/
public WebDisplayable(String url) {
this.url = url;
webView = new WebView();
webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
webView.setCursor(Cursor.NONE);
webView.setZoom(zoomLevel);
webEngine.load(getUrl());
webEngine.getLoadWorker().exceptionProperty().addListener((ObservableValue<? extends Throwable> ov, Throwable t, Throwable t1) -> {
LOGGER.log(Level.WARNING, "Website loading exception: ", t1);
});
}
/**
* Swaps the mouse cursor type between DEFAULT and HAND
*
* @param node
*/
public static void setMouseCursor(Node node) {
node.addEventHandler(MouseEvent.MOUSE_EXITED, event -> {
node.setCursor(Cursor.DEFAULT);
});
node.addEventHandler(MouseEvent.MOUSE_ENTERED, event -> {
node.setCursor(Cursor.HAND);
});
}
public void fillAt(final double x, final double y, final long fill)
{
if (!isVisible.getAsBoolean())
{
LOG.info("Selected source is not visible -- will not fill");
return;
}
final int level = 0;
final int time = 0;
final MaskInfo<UnsignedLongType> maskInfo = new MaskInfo<>(time, level, new UnsignedLongType(fill));
final Scene scene = viewer.getScene();
final Cursor previousCursor = scene.getCursor();
scene.setCursor(Cursor.WAIT);
try
{
final Mask<UnsignedLongType> mask = source.generateMask(maskInfo, FOREGROUND_CHECK);
final Interval affectedInterval = fillMaskAt(x, y, this.viewer, mask, source, assignment, FILL_VALUE, this.fillDepth.get());
requestRepaint.run();
source.applyMask(mask, affectedInterval, FOREGROUND_CHECK);
} catch (final MaskInUse e)
{
LOG.debug(e.getMessage());
} finally
{
scene.setCursor(previousCursor);
}
}