Search in sources :

Example 1 with IPositionShape

use of net.sf.latexdraw.models.interfaces.shape.IPositionShape 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(AddShape.class, new Press()).on(canvas).map(i -> {
        final IPositionShape sh = (IPositionShape) createShapeInstance();
        sh.setPosition(getAdaptedPoint(i.getSrcLocalPoint()));
        return new AddShape(sh, canvas.getDrawing());
    }).when(i -> i.getButton() == MouseButton.PRIMARY).bind().activationProperty().bind(activatedProp.and(currentChoice.isEqualTo(EditionChoice.GRID).or(currentChoice.isEqualTo(EditionChoice.DOT)).or(currentChoice.isEqualTo(EditionChoice.AXES))));
    // 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(AddShape.class, new Press()).on(canvas).map(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).when(i -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty()).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.TEXT).and(activatedProp));
}
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) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Press(org.malai.javafx.interaction.library.Press)

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