use of org.malai.javafx.interaction.library.DnD in project latexdraw by arnobl.
the class TemplateManager method configureBindings.
@Override
protected void configureBindings() {
buttonBinder(UpdateTemplates.class).on(updateTemplates).first(c -> {
c.setTemplatesPane(templatePane);
c.updateThumbnails(true);
}).bind();
nodeBinder(LoadTemplate.class, new DnD()).on(templatePane).first((c, i) -> {
c.setDrawing(drawing);
c.setFile(new File((String) i.getSrcObject().get().getUserData()));
c.setOpenSaveManager(SVGDocumentGenerator.INSTANCE);
c.setProgressBar(statusController.getProgressBar());
c.setStatusWidget(statusController.getLabel());
c.setUi(LaTeXDraw.getInstance());
}).then((c, i) -> {
final Node srcObj = i.getSrcObject().get();
final Point3D pt3d = i.getEndObjet().get().sceneToLocal(srcObj.localToScene(i.getEndLocalPt())).subtract(Canvas.ORIGIN.getX() + srcObj.getLayoutX(), Canvas.ORIGIN.getY() + srcObj.getLayoutY(), 0d);
c.setPosition(ShapeFactory.INST.createPoint(pt3d));
}).feedback(() -> templatePane.setCursor(Cursor.CLOSED_HAND)).when(i -> i.getSrcObject().orElse(null) instanceof ImageView && i.getSrcObject().get().getUserData() instanceof String && i.getEndObjet().orElse(null) instanceof Canvas).bind();
}
use of org.malai.javafx.interaction.library.DnD in project latexdraw by arnobl.
the class Hand method bindDnDTranslate.
/**
* A DnD on a shape view allows to translate the underlying shape.
*/
private void bindDnDTranslate() {
nodeBinder(TranslateShapes.class, new DnD(true, true)).on(canvas.getViews().getChildren()).on(canvas.getSelectionBorder()).map(i -> new TranslateShapes(canvas.getDrawing(), canvas.getDrawing().getSelection().duplicateDeep(false))).then((c, i) -> {
final IPoint startPt = grid.getTransformedPointToGrid(i.getSrcScenePoint());
final IPoint endPt = grid.getTransformedPointToGrid(i.getEndScenePt());
c.setT(endPt.getX() - startPt.getX(), endPt.getY() - startPt.getY());
}).when(i -> i.getButton() == MouseButton.PRIMARY && !canvas.getDrawing().getSelection().isEmpty()).exec().first((c, i) -> {
i.getSrcObject().ifPresent(node -> Platform.runLater(() -> node.requestFocus()));
canvas.setCursor(Cursor.MOVE);
}).cancel((c, i) -> canvas.update()).strictStart().bind();
}
use of org.malai.javafx.interaction.library.DnD in project latexdraw by arnobl.
the class Pencil method bindDnDToDrawSquaredShape.
/**
* Binds a DnD interaction to draw squared shapes.
*/
private void bindDnDToDrawSquaredShape() {
nodeBinder(AddShape.class, new DnD(false, true)).on(canvas).map(i -> {
final ISquaredShape sq = (ISquaredShape) createShapeInstance();
final IPoint pt = getAdaptedPoint(i.getSrcLocalPoint());
sq.setPosition(pt.getX() - 1d, pt.getY() - 1d);
sq.setWidth(2d);
return new AddShape(sq, canvas.getDrawing());
}).first((c, i) -> {
Platform.runLater(() -> canvas.requestFocus());
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).then((c, i) -> updateShapeFromCentre((ISquaredShape) c.getShape().get(), getAdaptedPoint(i.getSrcLocalPoint()), getAdaptedPoint(i.getEndLocalPt()).getX())).endOrCancel((c, i) -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY).strictStart().bind().activationProperty().bind(activatedProp.and(currentChoice.isEqualTo(EditionChoice.SQUARE).or(currentChoice.isEqualTo(EditionChoice.CIRCLE).or(currentChoice.isEqualTo(EditionChoice.CIRCLE_ARC)))));
}
use of org.malai.javafx.interaction.library.DnD in project Malai by arnobl.
the class MoveShape method testCanCancelDnDWithObsList.
@Test
public void testCanCancelDnDWithObsList() {
new NodeBinder<>(MoveShape.class, new DnD(true, true), instrument).map(i -> new MoveShape((Rectangle) i.getSrcObject().get())).on(widget1.getChildren()).first((c, i) -> Platform.runLater(() -> i.getSrcObject().get().requestFocus())).then((c, i) -> c.setCoord(((Rectangle) i.getSrcObject().get()).getX() + (i.getEndScenePt().getX() - i.getSrcScenePoint().getX()), ((Rectangle) i.getSrcObject().get()).getY() + (i.getEndScenePt().getY() - i.getSrcScenePoint().getY()))).end((c, i) -> fail("")).exec().bind();
Rectangle rec2 = new Rectangle(200d, 200d, 70d, 50d);
Platform.runLater(() -> widget1.getChildren().addAll(rec2));
WaitForAsyncUtils.waitForFxEvents();
drag(rec2).moveBy(100, 100).type(KeyCode.ESCAPE).sleep(50L);
assertEquals(0, instrument.exec.get());
}
Aggregations