Search in sources :

Example 1 with ISquaredShape

use of net.sf.latexdraw.models.interfaces.shape.ISquaredShape 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

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Function (java.util.function.Function)1 Platform (javafx.application.Platform)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 Point3D (javafx.geometry.Point3D)1 Cursor (javafx.scene.Cursor)1 MouseButton (javafx.scene.input.MouseButton)1 FileChooser (javafx.stage.FileChooser)1 AddShape (net.sf.latexdraw.commands.shape.AddShape)1 InitTextSetter (net.sf.latexdraw.commands.shape.InitTextSetter)1 InsertPicture (net.sf.latexdraw.commands.shape.InsertPicture)1 MathUtils (net.sf.latexdraw.models.MathUtils)1 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)1 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)1 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)1 IControlPointShape (net.sf.latexdraw.models.interfaces.shape.IControlPointShape)1 IFreehand (net.sf.latexdraw.models.interfaces.shape.IFreehand)1 IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)1