Search in sources :

Example 6 with AddShape

use of net.sf.latexdraw.commands.shape.AddShape 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)

Aggregations

AddShape (net.sf.latexdraw.commands.shape.AddShape)6 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)6 Inject (net.sf.latexdraw.util.Inject)6 Collections (java.util.Collections)5 Platform (javafx.application.Platform)5 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)5 LangTool (net.sf.latexdraw.util.LangTool)5 Arrays (java.util.Arrays)4 Function (java.util.function.Function)4 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)4 Point3D (javafx.geometry.Point3D)4 Cursor (javafx.scene.Cursor)4 MouseButton (javafx.scene.input.MouseButton)4 FileChooser (javafx.stage.FileChooser)4 InitTextSetter (net.sf.latexdraw.commands.shape.InitTextSetter)4 InsertPicture (net.sf.latexdraw.commands.shape.InsertPicture)4 MathUtils (net.sf.latexdraw.models.MathUtils)4 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)4 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)4