Search in sources :

Example 1 with DnD

use of io.github.interacto.jfx.interaction.library.DnD in project latexdraw by arnobl.

the class TemplateManager method configureBindings.

@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();
}
Also used : Button(javafx.scene.control.Button) Initializable(javafx.fxml.Initializable) Drawing(net.sf.latexdraw.model.api.shape.Drawing) Point3D(javafx.geometry.Point3D) URL(java.net.URL) Bindings(javafx.beans.binding.Bindings) Command(io.github.interacto.command.Command) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) JfxInstrument(io.github.interacto.jfx.instrument.JfxInstrument) FontPosture(javafx.scene.text.FontPosture) Canvas(net.sf.latexdraw.view.jfx.Canvas) UpdateTemplates(net.sf.latexdraw.command.UpdateTemplates) Label(javafx.scene.control.Label) TitledPane(javafx.scene.control.TitledPane) Node(javafx.scene.Node) Font(javafx.scene.text.Font) LoadTemplate(net.sf.latexdraw.command.LoadTemplate) File(java.io.File) Objects(java.util.Objects) 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) JfxUI(io.github.interacto.jfx.ui.JfxUI) NotNull(org.jetbrains.annotations.NotNull) DnD(io.github.interacto.jfx.interaction.library.DnD) Point3D(javafx.geometry.Point3D) Node(javafx.scene.Node) Canvas(net.sf.latexdraw.view.jfx.Canvas) LoadTemplate(net.sf.latexdraw.command.LoadTemplate) ImageView(javafx.scene.image.ImageView) UpdateTemplates(net.sf.latexdraw.command.UpdateTemplates) File(java.io.File)

Example 2 with DnD

use of io.github.interacto.jfx.interaction.library.DnD in project latexdraw by arnobl.

the class CanvasController method configureBindings.

@Override
protected void configureBindings() {
    nodeBinder().usingInteraction(DnD::new).toProduce(MoveCamera::new).on(canvas).first(c -> {
        c.setScrollPane(canvas.getScrollPane());
        canvas.setCursor(Cursor.MOVE);
    }).then((i, c) -> {
        final ScrollPane pane = canvas.getScrollPane();
        c.setPx(pane.getHvalue() - (i.getTgtLocalPoint().getX() - i.getSrcLocalPoint().getX()) / canvas.getWidth());
        c.setPy(pane.getVvalue() - (i.getTgtLocalPoint().getY() - i.getSrcLocalPoint().getY()) / canvas.getHeight());
    }).when(i -> i.getButton() == MouseButton.MIDDLE).endOrCancel(i -> canvas.setCursor(Cursor.DEFAULT)).continuousExecution().bind();
    nodeBinder().toProduce(() -> new ChangeCursor(Cursor.HAND, canvas)).usingInteraction(MouseEntered::new).on(canvas.getSelectionBorder()).bind();
    nodeBinder().toProduce(() -> new ChangeCursor(Cursor.DEFAULT, canvas)).usingInteraction(MouseExited::new).on(canvas.getSelectionBorder()).bind();
}
Also used : Initializable(javafx.fxml.Initializable) MouseButton(javafx.scene.input.MouseButton) URL(java.net.URL) MagneticGrid(net.sf.latexdraw.view.jfx.MagneticGrid) Cursor(javafx.scene.Cursor) MoveCamera(io.github.interacto.jfx.command.MoveCamera) Inject(net.sf.latexdraw.util.Inject) ScrollPane(javafx.scene.control.ScrollPane) ResourceBundle(java.util.ResourceBundle) MouseExited(io.github.interacto.jfx.interaction.library.MouseExited) MouseEntered(io.github.interacto.jfx.interaction.library.MouseEntered) Canvas(net.sf.latexdraw.view.jfx.Canvas) ChangeCursor(io.github.interacto.jfx.command.ChangeCursor) DnD(io.github.interacto.jfx.interaction.library.DnD) MouseEntered(io.github.interacto.jfx.interaction.library.MouseEntered) ScrollPane(javafx.scene.control.ScrollPane) DnD(io.github.interacto.jfx.interaction.library.DnD) ChangeCursor(io.github.interacto.jfx.command.ChangeCursor) MouseExited(io.github.interacto.jfx.interaction.library.MouseExited)

Example 3 with DnD

use of io.github.interacto.jfx.interaction.library.DnD in project latexdraw by arnobl.

the class Pencil method bindDnDToDrawFreeHandShape.

/**
 * Binds a DnD interaction to create shape.
 */
private void bindDnDToDrawFreeHandShape() {
    nodeBinder().usingInteraction(() -> new DnD(false, true)).toProduce(i -> {
        final Shape sh = editing.createShapeInstance();
        final Point pt = getAdaptedPoint(i.getSrcLocalPoint());
        sh.getPoints().get(0).setPoint(pt.getX(), pt.getY());
        return new AddShape(sh, canvas.getDrawing());
    }).on(canvas).first((i, c) -> canvas.requestFocus()).then((i, c) -> {
        final Point last = c.getShape().getPtAt(-1);
        final Point endPt = getAdaptedPoint(i.getTgtLocalPoint());
        if (!MathUtils.INST.equalsDouble(last.getX(), endPt.getX(), 0.0001) && !MathUtils.INST.equalsDouble(last.getY(), endPt.getY(), 0.0001)) {
            c.setShape(ShapeFactory.INST.createFreeHandFrom((Freehand) c.getShape(), endPt));
        }
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).endOrCancel(i -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY && editing.getCurrentChoice() == EditionChoice.FREE_HAND).strictStart().bind();
}
Also used : EditingService(net.sf.latexdraw.service.EditingService) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) Freehand(net.sf.latexdraw.model.api.shape.Freehand) Point3D(javafx.geometry.Point3D) BorderPos(net.sf.latexdraw.model.api.shape.BorderPos) InsertPicture(net.sf.latexdraw.command.shape.InsertPicture) Function(java.util.function.Function) Polyline(net.sf.latexdraw.model.api.shape.Polyline) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Shape(net.sf.latexdraw.model.api.shape.Shape) Inject(net.sf.latexdraw.util.Inject) PointsData(io.github.interacto.jfx.interaction.library.PointsData) MathUtils(net.sf.latexdraw.model.MathUtils) AddShape(net.sf.latexdraw.command.shape.AddShape) Canvas(net.sf.latexdraw.view.jfx.Canvas) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) Click(io.github.interacto.jfx.interaction.library.Click) InitTextSetter(net.sf.latexdraw.command.shape.InitTextSetter) MultiClick(io.github.interacto.jfx.interaction.library.MultiClick) ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) Polygon(net.sf.latexdraw.model.api.shape.Polygon) Press(io.github.interacto.jfx.interaction.library.Press) PositionShape(net.sf.latexdraw.model.api.shape.PositionShape) Point(net.sf.latexdraw.model.api.shape.Point) MagneticGrid(net.sf.latexdraw.view.jfx.MagneticGrid) Objects(java.util.Objects) FileChooser(javafx.stage.FileChooser) SquaredShape(net.sf.latexdraw.model.api.shape.SquaredShape) RectangularShape(net.sf.latexdraw.model.api.shape.RectangularShape) NotNull(org.jetbrains.annotations.NotNull) DnD(io.github.interacto.jfx.interaction.library.DnD) AddShape(net.sf.latexdraw.command.shape.AddShape) ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) Shape(net.sf.latexdraw.model.api.shape.Shape) AddShape(net.sf.latexdraw.command.shape.AddShape) ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) PositionShape(net.sf.latexdraw.model.api.shape.PositionShape) SquaredShape(net.sf.latexdraw.model.api.shape.SquaredShape) RectangularShape(net.sf.latexdraw.model.api.shape.RectangularShape) Freehand(net.sf.latexdraw.model.api.shape.Freehand) DnD(io.github.interacto.jfx.interaction.library.DnD) Point(net.sf.latexdraw.model.api.shape.Point)

Aggregations

DnD (io.github.interacto.jfx.interaction.library.DnD)3 Inject (net.sf.latexdraw.util.Inject)3 Canvas (net.sf.latexdraw.view.jfx.Canvas)3 URL (java.net.URL)2 Objects (java.util.Objects)2 ResourceBundle (java.util.ResourceBundle)2 Initializable (javafx.fxml.Initializable)2 Point3D (javafx.geometry.Point3D)2 Cursor (javafx.scene.Cursor)2 MouseButton (javafx.scene.input.MouseButton)2 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)2 MagneticGrid (net.sf.latexdraw.view.jfx.MagneticGrid)2 Command (io.github.interacto.command.Command)1 ChangeCursor (io.github.interacto.jfx.command.ChangeCursor)1 MoveCamera (io.github.interacto.jfx.command.MoveCamera)1 JfxInstrument (io.github.interacto.jfx.instrument.JfxInstrument)1 Click (io.github.interacto.jfx.interaction.library.Click)1 MouseEntered (io.github.interacto.jfx.interaction.library.MouseEntered)1 MouseExited (io.github.interacto.jfx.interaction.library.MouseExited)1 MultiClick (io.github.interacto.jfx.interaction.library.MultiClick)1