Search in sources :

Example 6 with DnD

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();
}
Also used : Button(javafx.scene.control.Button) Initializable(javafx.fxml.Initializable) LoadTemplate(net.sf.latexdraw.commands.LoadTemplate) Point3D(javafx.geometry.Point3D) URL(java.net.URL) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) Bindings(javafx.beans.binding.Bindings) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) FontPosture(javafx.scene.text.FontPosture) IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) Canvas(net.sf.latexdraw.view.jfx.Canvas) DnD(org.malai.javafx.interaction.library.DnD) UpdateTemplates(net.sf.latexdraw.commands.UpdateTemplates) Label(javafx.scene.control.Label) TitledPane(javafx.scene.control.TitledPane) Node(javafx.scene.Node) Font(javafx.scene.text.Font) JfxInstrument(org.malai.javafx.instrument.JfxInstrument) File(java.io.File) LaTeXDraw(net.sf.latexdraw.LaTeXDraw) FXML(javafx.fxml.FXML) Cursor(javafx.scene.Cursor) FlowPane(javafx.scene.layout.FlowPane) ImageView(javafx.scene.image.ImageView) SVGDocumentGenerator(net.sf.latexdraw.view.svg.SVGDocumentGenerator) Point3D(javafx.geometry.Point3D) Node(javafx.scene.Node) Canvas(net.sf.latexdraw.view.jfx.Canvas) DnD(org.malai.javafx.interaction.library.DnD) ImageView(javafx.scene.image.ImageView) UpdateTemplates(net.sf.latexdraw.commands.UpdateTemplates) File(java.io.File)

Example 7 with DnD

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();
}
Also used : MouseButton(javafx.scene.input.MouseButton) ViewText(net.sf.latexdraw.view.jfx.ViewText) Command(org.malai.command.Command) BoundingBox(javafx.geometry.BoundingBox) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) SelectShapes(net.sf.latexdraw.commands.shape.SelectShapes) JfXWidgetBinding(org.malai.javafx.binding.JfXWidgetBinding) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) ArrayList(java.util.ArrayList) ViewShape(net.sf.latexdraw.view.jfx.ViewShape) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) ListChangeListener(javafx.collections.ListChangeListener) Transform(javafx.scene.transform.Transform) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Canvas(net.sf.latexdraw.view.jfx.Canvas) DnD(org.malai.javafx.interaction.library.DnD) KeyCode(javafx.scene.input.KeyCode) Node(javafx.scene.Node) LSystem(net.sf.latexdraw.util.LSystem) IText(net.sf.latexdraw.models.interfaces.shape.IText) Rectangle(javafx.scene.shape.Rectangle) UpdateToGrid(net.sf.latexdraw.commands.shape.UpdateToGrid) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) TranslateShapes(net.sf.latexdraw.commands.shape.TranslateShapes) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) List(java.util.List) Press(org.malai.javafx.interaction.library.Press) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) Optional(java.util.Optional) DoubleClick(org.malai.javafx.interaction.library.DoubleClick) Collections(java.util.Collections) Shape(javafx.scene.shape.Shape) Bounds(javafx.geometry.Bounds) TranslateShapes(net.sf.latexdraw.commands.shape.TranslateShapes) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD)

Example 8 with DnD

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)))));
}
Also used : ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Point3D(javafx.geometry.Point3D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) MathUtils(net.sf.latexdraw.models.MathUtils) AddShape(net.sf.latexdraw.commands.shape.AddShape) Function(java.util.function.Function) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) InsertPicture(net.sf.latexdraw.commands.shape.InsertPicture) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ObjectProperty(javafx.beans.property.ObjectProperty) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) LangTool(net.sf.latexdraw.util.LangTool) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) MultiClick(org.malai.javafx.interaction.library.MultiClick) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Press(org.malai.javafx.interaction.library.Press) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Collections(java.util.Collections) AddShape(net.sf.latexdraw.commands.shape.AddShape) ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD)

Example 9 with DnD

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());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) KeyCode(javafx.scene.input.KeyCode) NodeBinder(org.malai.javafx.binding.NodeBinder) Undoable(org.malai.undo.Undoable) Rectangle(javafx.scene.shape.Rectangle) DoubleProperty(javafx.beans.property.DoubleProperty) CommandImpl(org.malai.command.CommandImpl) WaitForAsyncUtils(org.testfx.util.WaitForAsyncUtils) Platform(javafx.application.Platform) Test(org.junit.jupiter.api.Test) Stage(javafx.stage.Stage) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DnD(org.malai.javafx.interaction.library.DnD) Pane(javafx.scene.layout.Pane) Rectangle(javafx.scene.shape.Rectangle) DnD(org.malai.javafx.interaction.library.DnD) Test(org.junit.jupiter.api.Test)

Aggregations

DnD (org.malai.javafx.interaction.library.DnD)9 Cursor (javafx.scene.Cursor)8 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)6 Inject (net.sf.latexdraw.util.Inject)6 URL (java.net.URL)5 ResourceBundle (java.util.ResourceBundle)5 Platform (javafx.application.Platform)5 Initializable (javafx.fxml.Initializable)5 Point3D (javafx.geometry.Point3D)5 MouseButton (javafx.scene.input.MouseButton)5 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)5 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)5 Arrays (java.util.Arrays)4 Function (java.util.function.Function)4 ListChangeListener (javafx.collections.ListChangeListener)4 Node (javafx.scene.Node)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 MathUtils (net.sf.latexdraw.models.MathUtils)3 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)3