use of org.malai.ex.util.ColorCursor 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(new DnD(), i -> new AddShape(drawing, new MyRect(i.getSrcLocalPoint().getX(), i.getSrcLocalPoint().getY()))).on(canvas).first((i, c) -> canvas.setTmpShape(ViewFactory.INSTANCE.createViewShape(c.getShape()))).then((i, c) -> {
final MyRect sh = (MyRect) c.getShape();
sh.setWidth(i.getTgtLocalPoint().getX() - sh.getX());
sh.setHeight(i.getTgtLocalPoint().getY() - sh.getY());
}).when(i -> i.getButton() == MouseButton.PRIMARY).end((i, c) -> 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(new DnD(true, true), // In the command these binding are @autoUnbind to be unbound on their command termination.
i -> {
final MyShape sh = i.getSrcObject().map(o -> (MyShape) o.getUserData()).get();
return new MoveShape(sh, Bindings.createDoubleBinding(() -> sh.getX() + (i.getTgtScenePoint().getX() - i.getSrcScenePoint().getX()), i.tgtScenePointProperty(), i.srcScenePointProperty()), Bindings.createDoubleBinding(() -> sh.getY() + (i.getTgtScenePoint().getY() - i.getSrcScenePoint().getY()), i.tgtScenePointProperty(), i.srcScenePointProperty()));
}).on(canvas.getShapesPane().getChildren()).when(i -> i.getButton() == MouseButton.SECONDARY).exec().first((i, c) -> {
// 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((i, c) -> i.getSrcObject().get().setEffect(null)).strictStart().help(new MoveRectHelpAnimation(learningPane, canvas)).throttle(40L).bind();
// nodeBinder(new DnD(true, true), i -> new MoveShape(i.getSrcObject().map(o ->(MyShape) o.getUserData()).orElse(null))).
// // 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()).
// then((i, c) -> c.setCoord(c.getShape().getX() + (i.getTgtScenePoint().getX() - i.getSrcScenePoint().getX()),
// c.getShape().getY() + (i.getTgtScenePoint().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((i, c) -> {
// // 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((i, c) -> 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(new DnD(), i -> new ChangeColour(lineCol.getValue(), null)).on(lineCol).then((i, c) -> i.getTgtObject().map(view -> (MyShape) view.getUserData()).ifPresent(sh -> c.setShape(sh))).when(i -> i.getTgtObject().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(new Press(), () -> System.out.println("An example of the anonymous command.")).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::new).on(save).async(cancel, progressbar.progressProperty(), textProgress.textProperty()).bind();
}
Aggregations