use of javafx.scene.Cursor in project Malai by arnobl.
the class Pencil method configureBindings.
@Override
protected void configureBindings() {
// A DnD interaction with the left button of the mouse will produce an AddShape command while interacting on the canvas.
// A temporary view of the created shape is created and displayed by the canvas.
// This view is removed at the end of the interaction.
nodeBinder(AddShape.class, new DnD()).on(canvas).map(i -> new AddShape(drawing, new MyRect(i.getSrcLocalPoint().getX(), i.getSrcLocalPoint().getY()))).first((c, i) -> canvas.setTmpShape(ViewFactory.INSTANCE.createViewShape(c.getShape()))).then((c, i) -> {
final MyRect sh = (MyRect) c.getShape();
sh.setWidth(i.getEndLocalPt().getX() - sh.getX());
sh.setHeight(i.getEndLocalPt().getY() - sh.getY());
}).when(i -> i.getButton() == MouseButton.PRIMARY).end((c, i) -> canvas.setTmpShape(null)).log(LogLevel.INTERACTION).strictStart().help(new AddRectHelpAnimation(learningPane, canvas)).bind();
// A DnD interaction with the right button of the mouse moves the targeted shape.
// To incrementally moves the shape, the DnD interaction has its parameter 'updateSrcOnUpdate' set to true:
// At each interaction updates, the source point and object take the latest target point and object.
// The DnD interaction can be stopped (aborted) by pressing the key 'ESC'. This cancels the ongoing command (that thus needs to be undoable).
nodeBinder(MoveShape.class, new DnD(true, true)).on(canvas.getShapesPane().getChildren()).map(i -> {
final MyShape sh = i.getSrcObject().map(o -> (MyShape) o.getUserData()).get();
return new MoveShape(sh, Bindings.createDoubleBinding(() -> sh.getX() + (i.getEndScenePt().getX() - i.getSrcScenePoint().getX()), i.endScenePtProperty(), i.srcScenePointProperty()), Bindings.createDoubleBinding(() -> sh.getY() + (i.getEndScenePt().getY() - i.getSrcScenePoint().getY()), i.endScenePtProperty(), i.srcScenePointProperty()));
}).when(i -> i.getButton() == MouseButton.SECONDARY).exec().first((c, i) -> {
// Required to grab the focus to get key events
Platform.runLater(() -> i.getSrcObject().get().requestFocus());
i.getSrcObject().get().setEffect(new DropShadow(20d, Color.BLACK));
}).endOrCancel((c, i) -> i.getSrcObject().get().setEffect(null)).strictStart().help(new MoveRectHelpAnimation(learningPane, canvas)).bind();
// nodeBinder(MoveShape.class, new CancellableDnD(true)).
// // The binding dynamically registers elements of the given observable list.
// // When nodes are added to this list, these nodes register the binding.
// // When nodes are removed from this list, their binding is cancelled.
// // This permits to interact on nodes (here, shapes) that are dynamically added to/removed from the canvas.
// on(canvas.getShapesPane().getChildren()).
// map(i -> new MoveShape(i.getSrcObject().map(o ->(MyShape) o.getUserData()).orElse(null))).
// then((a, i) -> a.setCoord(a.getShape().getX() + (i.getEndScenePt().getX() - i.getSrcScenePoint().getX()),
// a.getShape().getY() + (i.getEndScenePt().getY() - i.getSrcScenePoint().getY()))).
// when(i -> i.getButton() == MouseButton.SECONDARY).
// // exec(true): this allows to execute the command each time the interaction updates (and 'when' is true).
// exec(true).
// first((a, i) -> {
// // Required to grab the focus to get key events
// Platform.runLater(() -> i.getSrcObject().get().requestFocus());
// i.getSrcObject().get().setEffect(new DropShadow(20d, Color.BLACK));
// }).
// end((a, i) -> i.getSrcObject().get().setEffect(null)).
// strictStart().
// bind();
/*
* A DnD on the colour picker produces ChangeCol commands when the target of the DnD is a shape
* (the shape we want to change the colour). The interim feedback changes the cursor during the DnD to show the dragged colour.
* Note that the feedback callback is not optimised here as the colour does not change during the DnD. The cursor
* should be changed in 'first'
*/
nodeBinder(ChangeColour.class, new DnD()).on(lineCol).map(i -> new ChangeColour(lineCol.getValue(), null)).then((a, i) -> i.getEndObjet().map(view -> (MyShape) view.getUserData()).ifPresent(sh -> a.setShape(sh))).when(i -> i.getEndObjet().orElse(null) instanceof Shape).feedback(() -> lineCol.getScene().setCursor(new ColorCursor(lineCol.getValue()))).endOrCancel((a, i) -> lineCol.getScene().setCursor(Cursor.DEFAULT)).bind();
/*
* A mouse pressure creates an anonymous command that simply shows a message in the console.
*/
anonCmdBinder(() -> System.out.println("An example of the anonymous command."), new Press()).on(canvas).bind();
/*
* A widget binding that execute a command asynchronously.
* Widgets and properties are provided to the binding to:
* show/hide the cancel button, provide widgets with information regarding the progress of the command execution.
*/
buttonBinder(Save.class).on(save).async(cancel, progressbar.progressProperty(), textProgress.textProperty()).bind();
}
use of javafx.scene.Cursor in project Gargoyle by callakrsos.
the class DockNode method handle.
@Override
public void handle(MouseEvent event) {
// if(event.getSource() instanceof DockTabPane)
// return;
// System.err.println(event.getPickResult().getIntersectedNode());
Cursor cursor = Cursor.DEFAULT;
// TODO: use escape to cancel resize/drag operation like visual studio
if (!this.isFloating() || !this.isStageResizable()) {
return;
}
if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
sizeLast = new Point2D(event.getScreenX(), event.getScreenY());
} else if (event.getEventType() == MouseEvent.MOUSE_MOVED) {
Insets insets = borderPane.getPadding();
sizeWest = event.getX() < insets.getLeft();
sizeEast = event.getX() > borderPane.getWidth() - insets.getRight();
sizeNorth = event.getY() < insets.getTop();
sizeSouth = event.getY() > borderPane.getHeight() - insets.getBottom();
if (sizeWest) {
if (sizeNorth) {
cursor = Cursor.NW_RESIZE;
} else if (sizeSouth) {
cursor = Cursor.SW_RESIZE;
} else {
cursor = Cursor.W_RESIZE;
}
} else if (sizeEast) {
if (sizeNorth) {
cursor = Cursor.NE_RESIZE;
} else if (sizeSouth) {
cursor = Cursor.SE_RESIZE;
} else {
cursor = Cursor.E_RESIZE;
}
} else if (sizeNorth) {
cursor = Cursor.N_RESIZE;
} else if (sizeSouth) {
cursor = Cursor.S_RESIZE;
}
this.getScene().setCursor(cursor);
} else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED && this.isMouseResizeZone()) {
Point2D sizeCurrent = new Point2D(event.getScreenX(), event.getScreenY());
Point2D sizeDelta = sizeCurrent.subtract(sizeLast);
double newX = stage.getX(), newY = stage.getY(), newWidth = stage.getWidth(), newHeight = stage.getHeight();
if (sizeNorth) {
newHeight -= sizeDelta.getY();
newY += sizeDelta.getY();
} else if (sizeSouth) {
newHeight += sizeDelta.getY();
}
if (sizeWest) {
newWidth -= sizeDelta.getX();
newX += sizeDelta.getX();
} else if (sizeEast) {
newWidth += sizeDelta.getX();
}
// TODO: find a way to do this synchronously and eliminate the flickering of moving the stage
// around, also file a bug report for this feature if a work around can not be found this
// primarily occurs when dragging north/west but it also appears in native windows and Visual
// Studio, so not that big of a concern.
// Bug report filed:
// https://bugs.openjdk.java.net/browse/JDK-8133332
double currentX = sizeLast.getX(), currentY = sizeLast.getY();
if (newWidth >= stage.getMinWidth()) {
stage.setX(newX);
stage.setWidth(newWidth);
currentX = sizeCurrent.getX();
}
if (newHeight >= stage.getMinHeight()) {
stage.setY(newY);
stage.setHeight(newHeight);
currentY = sizeCurrent.getY();
}
sizeLast = new Point2D(currentX, currentY);
// while we are actively resizing
if (sizeNorth || sizeSouth || sizeWest || sizeEast) {
event.consume();
}
}
}
use of javafx.scene.Cursor in project org.csstudio.display.builder by kasemir.
the class ImagePlot method mouseDown.
/**
* onMousePressed
*/
private void mouseDown(final MouseEvent e) {
// Don't start mouse actions when user invokes context menu
if (!e.isPrimaryButtonDown() || (PlatformInfo.is_mac_os_x && e.isControlDown()))
return;
// -> User clicked outside of tracker. Remove it.
if (roi_tracker != null) {
removeROITracker();
// User needs to click again for that.
return;
}
// Select any tracker
final Point2D current = new Point2D(e.getX(), e.getY());
for (RegionOfInterest roi : rois) if (roi.isVisible() && roi.isInteractive()) {
final Rectangle rect = roiToScreen(roi);
if (rect.contains(current.getX(), current.getY())) {
// Check if complete ROI is visible,
// because otherwise tracker would extend beyond the
// current image viewport
final Rectangle2D image_rect = GraphicsUtils.convert(image_area);
if (image_rect.contains(rect.x, rect.y, rect.width, rect.height)) {
roi_tracker = new Tracker(image_rect);
roi_tracker.setPosition(rect.x, rect.y, rect.width, rect.height);
ChildCare.addChild(getParent(), roi_tracker);
final int index = rois.indexOf(roi);
roi_tracker.setListener((old_pos, new_pos) -> updateRoiFromScreen(index, new_pos));
return;
}
}
}
mouse_start = mouse_current = Optional.of(current);
final int clicks = e.getClickCount();
if (mouse_mode == MouseMode.NONE) {
if (crosshair) {
updateLocationInfo(e.getX(), e.getY());
requestRedraw();
}
} else if (mouse_mode == MouseMode.PAN) {
// Determine start of 'pan'
mouse_start_x_range = x_axis.getValueRange();
mouse_start_y_range = y_axis.getValueRange();
mouse_mode = MouseMode.PAN_PLOT;
} else if (mouse_mode == MouseMode.ZOOM_IN && clicks == 1) {
// Reset cursor from SIZE* to CROSS.
if (y_axis.getBounds().contains(current.getX(), current.getY())) {
mouse_mode = MouseMode.ZOOM_IN_Y;
PlotCursors.setCursor(this, mouse_mode);
} else if (image_area.contains(current.getX(), current.getY())) {
mouse_mode = MouseMode.ZOOM_IN_PLOT;
PlotCursors.setCursor(this, mouse_mode);
} else if (x_axis.getBounds().contains(current.getX(), current.getY())) {
mouse_mode = MouseMode.ZOOM_IN_X;
PlotCursors.setCursor(this, mouse_mode);
}
} else if ((mouse_mode == MouseMode.ZOOM_IN && clicks == 2) || mouse_mode == MouseMode.ZOOM_OUT)
zoomInOut(current.getX(), current.getY(), ZOOM_FACTOR);
}
use of javafx.scene.Cursor in project jgnash by ccavanaugh.
the class BudgetTableController method initialize.
@FXML
private void initialize() {
runningTotalsButton.selectedProperty().setValue(preferences.getBoolean(RUNNING_TOTALS, false));
rateLimitExecutor = new ScheduledThreadPoolExecutor(1, new DefaultDaemonThreadFactory("Budget View Rate Limit Executor"), new ThreadPoolExecutor.DiscardPolicy());
tableWidthChangeListener = (observable, oldValue, newValue) -> {
if (newValue != null && !oldValue.equals(newValue)) {
optimizeColumnWidths();
}
};
handleFontHeightChange();
yearSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(LocalDate.now().getYear() - YEAR_MARGIN, LocalDate.now().getYear() + YEAR_MARGIN, LocalDate.now().getYear(), 1));
accountTreeView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
accountTreeView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
accountTreeView.setShowRoot(false);
accountTreeView.setEditable(true);
accountTreeView.fixedCellSizeProperty().bind(rowHeight);
accountSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountSummaryTable.getStyleClass().addAll(StyleClass.HIDDEN_ROW_FOCUS);
accountSummaryTable.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
accountSummaryTable.setItems(expandedAccountList);
accountSummaryTable.fixedCellSizeProperty().bind(rowHeight);
accountSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountSummaryTable));
accountTypeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountTypeTable.getStyleClass().addAll(StyleClass.HIDDEN_COLUMN_HEADER, StyleClass.HIDDEN_ROW_FOCUS);
accountTypeTable.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
accountTypeTable.setItems(accountGroupList);
accountTypeTable.fixedCellSizeProperty().bind(rowHeight);
accountTypeTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
accountTypeTable.setSelectionModel(new NullTableViewSelectionModel<>(accountTypeTable));
// widths need to be bound to the tree view widths for drag/resizing to work
accountTypeTable.minWidthProperty().bind(accountTreeView.minWidthProperty());
accountTypeTable.prefWidthProperty().bind(accountTreeView.prefWidthProperty());
accountGroupPeriodSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
accountGroupPeriodSummaryTable.getStyleClass().addAll(StyleClass.HIDDEN_COLUMN_HEADER, StyleClass.HIDDEN_ROW_FOCUS);
accountGroupPeriodSummaryTable.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
accountGroupPeriodSummaryTable.setItems(accountGroupList);
accountGroupPeriodSummaryTable.fixedCellSizeProperty().bind(rowHeight);
accountGroupPeriodSummaryTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountGroupPeriodSummaryTable));
buildAccountTreeTable();
buildAccountTypeTable();
buildAccountSummaryTable();
buildAccountGroupSummaryTable();
accountSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountGroupPeriodSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
accountTreeView.expandedItemCountProperty().addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(this::updateExpandedAccountList));
// Calling handleBudgetChange which works for most changes, but can trigger an exception.
// handleBudgetUpdate rate limits and prevents an exception.
final ChangeListener<Object> budgetChangeListener = (observable, oldValue, newValue) -> handleBudgetUpdate();
budget.addListener(budgetChangeListener);
yearSpinner.valueProperty().addListener(budgetChangeListener);
runningTotalsButton.selectedProperty().addListener(budgetChangeListener);
visibleColumnCount.addListener(budgetChangeListener);
runningTotalsButton.selectedProperty().addListener((observable, oldValue, newValue) -> preferences.putBoolean(RUNNING_TOTALS, newValue));
/* Setting the tables as un-managed effectively removes these tables from the GridPane. The tables are
redundant if showing the amounts as running balances. */
accountSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
accountGroupPeriodSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
horizontalScrollBar.setMin(0);
horizontalScrollBar.maxProperty().bind(periodCount.subtract(visibleColumnCount));
horizontalScrollBar.setUnitIncrement(1);
horizontalScrollBar.disableProperty().bind(periodCount.lessThanOrEqualTo(1));
// shift the table right and left with the ScrollBar value
horizontalScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
/* must be synchronized to prevent a race condition from multiple events and an out of
* bounds exception */
synchronized (this) {
/* don't try unless columns exist. This can occur if the UI is not large enough to display
* a minimum of one period of information.
*/
if (periodTable.getColumns().size() > 0) {
final int newIndex = (int) Math.round(newValue.doubleValue());
if (newIndex > index) {
while (newIndex > index) {
handleShiftRight();
}
} else if (newIndex < index) {
while (newIndex < index) {
handleShiftLeft();
}
}
}
}
});
// listen for changes in the font scale and update. Listener needs to be weak to prevent memory leaks
fontScaleListener = (observable, oldValue, newValue) -> handleFontHeightChange();
ThemeManager.fontScaleProperty().addListener(new WeakChangeListener<>(fontScaleListener));
// cursor handler
accountTreeView.setOnMouseMoved(this::handleMouseMove);
// drag handler
accountTreeView.setOnMouseDragged(this::handleDividerDrag);
// drag handler
accountTreeView.setOnMousePressed(this::handleMouseClicked);
// cursor handler
accountTypeTable.setOnMouseMoved(this::handleMouseMove);
// drag handler
accountTypeTable.setOnMouseDragged(this::handleDividerDrag);
// drag handler
accountTypeTable.setOnMousePressed(this::handleMouseClicked);
JavaFXUtils.runLater(() -> accountTreeView.setPrefWidth(preferences.getDouble(ACCOUNT_COLUMN_WIDTH, INITIAL_WIDTH * 2)));
}
use of javafx.scene.Cursor in project processing by processing.
the class PSurfaceFX method setCursor.
public void setCursor(int kind) {
Cursor c;
switch(kind) {
case PConstants.ARROW:
c = Cursor.DEFAULT;
break;
case PConstants.CROSS:
c = Cursor.CROSSHAIR;
break;
case PConstants.HAND:
c = Cursor.HAND;
break;
case PConstants.MOVE:
c = Cursor.MOVE;
break;
case PConstants.TEXT:
c = Cursor.TEXT;
break;
case PConstants.WAIT:
c = Cursor.WAIT;
break;
default:
c = Cursor.DEFAULT;
break;
}
lastCursor = c;
canvas.getScene().setCursor(c);
}
Aggregations