Search in sources :

Example 1 with PositionShape

use of net.sf.latexdraw.model.api.shape.PositionShape in project latexdraw by arnobl.

the class Pencil method bindPressToAddShape.

/**
 * Binds a press interaction to add a shape.
 */
private void bindPressToAddShape() {
    // Add axes, grids, or dots
    nodeBinder().usingInteraction(Press::new).toProduce(i -> {
        final PositionShape sh = (PositionShape) editing.createShapeInstance();
        sh.setPosition(getAdaptedPoint(i.getSrcLocalPoint()));
        return new AddShape(sh, canvas.getDrawing());
    }).on(canvas).when(i -> i.getButton() == MouseButton.PRIMARY && (editing.getCurrentChoice() == EditionChoice.GRID || editing.getCurrentChoice() == EditionChoice.DOT || editing.getCurrentChoice() == EditionChoice.AXES)).bind();
    // When a user starts to type a text using the text setter and then he clicks somewhere else in the canvas,
    // the text typed must be added (if possible to the canvas) before starting typing a new text.
    nodeBinder().usingInteraction(Press::new).toProduce(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).on(canvas).when(i -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty() && editing.getCurrentChoice() == EditionChoice.TEXT).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) PositionShape(net.sf.latexdraw.model.api.shape.PositionShape) Press(io.github.interacto.jfx.interaction.library.Press)

Aggregations

Click (io.github.interacto.jfx.interaction.library.Click)1 DnD (io.github.interacto.jfx.interaction.library.DnD)1 MultiClick (io.github.interacto.jfx.interaction.library.MultiClick)1 PointsData (io.github.interacto.jfx.interaction.library.PointsData)1 Press (io.github.interacto.jfx.interaction.library.Press)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Point3D (javafx.geometry.Point3D)1 MouseButton (javafx.scene.input.MouseButton)1 FileChooser (javafx.stage.FileChooser)1 AddShape (net.sf.latexdraw.command.shape.AddShape)1 InitTextSetter (net.sf.latexdraw.command.shape.InitTextSetter)1 InsertPicture (net.sf.latexdraw.command.shape.InsertPicture)1 MathUtils (net.sf.latexdraw.model.MathUtils)1 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)1 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)1 BorderPos (net.sf.latexdraw.model.api.shape.BorderPos)1 ControlPointShape (net.sf.latexdraw.model.api.shape.ControlPointShape)1 Freehand (net.sf.latexdraw.model.api.shape.Freehand)1