Search in sources :

Example 1 with IDrawing

use of net.sf.latexdraw.models.interfaces.shape.IDrawing in project latexdraw by arnobl.

the class Border method configureBindings.

@Override
protected void configureBindings() {
    addBinding(new DnD2Scale(this));
    configureMovePointBinding();
    nodeBinder(MoveCtrlPoint.class, new DnD()).on(ctrlPt1Handlers).on(ctrlPt2Handlers).first((c, i) -> {
        final IGroup group = canvas.getDrawing().getSelection();
        if (group.size() == 1 && group.getShapeAt(0) instanceof IControlPointShape) {
            c.setPoint(i.getSrcObject().map(h -> ((CtrlPointHandler) h).getPoint()).orElse(null));
            c.setShape((IControlPointShape) group.getShapeAt(0));
            c.setIsFirstCtrlPt(ctrlPt1Handlers.contains(i.getSrcObject().orElse(null)));
        }
    }).then((c, i) -> {
        final Point3D startPt = i.getSrcObject().map(n -> n.localToParent(i.getSrcLocalPoint())).orElse(new Point3D(0d, 0d, 0d));
        final Point3D endPt = i.getSrcObject().map(n -> n.localToParent(i.getEndLocalPt())).orElse(new Point3D(0d, 0d, 0d));
        final IPoint ptToMove = i.getSrcObject().map(n -> ((CtrlPointHandler) n).getPoint()).orElse(ShapeFactory.INST.createPoint());
        final double x = ptToMove.getX() + endPt.getX() - startPt.getX();
        final double y = ptToMove.getY() + endPt.getY() - startPt.getY();
        c.setNewCoord(grid.getTransformedPointToGrid(new Point3D(x, y, 0d)));
    }).exec().bind();
    nodeBinder(RotateShapes.class, new DnD()).on(rotHandler).first((c, i) -> {
        final IDrawing drawing = canvas.getDrawing();
        c.setGravityCentre(drawing.getSelection().getGravityCentre());
        c.getGc().translate(canvas.getOrigin().getX(), canvas.getOrigin().getY());
        c.setShape(drawing.getSelection().duplicateDeep(false));
    }).then((c, i) -> c.setRotationAngle(c.getGc().computeRotationAngle(ShapeFactory.INST.createPoint(canvas.sceneToLocal(i.getSrcScenePoint())), ShapeFactory.INST.createPoint(canvas.sceneToLocal(i.getEndScenePt()))))).exec().bind();
    addBinding(new DnD2ArcAngle(this));
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) Command(org.malai.command.Command) MovePtHandler(net.sf.latexdraw.handlers.MovePtHandler) Point3D(javafx.geometry.Point3D) URL(java.net.URL) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) ScaleHandler(net.sf.latexdraw.handlers.ScaleHandler) FXCollections(javafx.collections.FXCollections) MathUtils(net.sf.latexdraw.models.MathUtils) MovePointShape(net.sf.latexdraw.commands.shape.MovePointShape) JfXWidgetBinding(org.malai.javafx.binding.JfXWidgetBinding) Function(java.util.function.Function) IArc(net.sf.latexdraw.models.interfaces.shape.IArc) Position(net.sf.latexdraw.models.interfaces.shape.Position) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) ResourceBundle(java.util.ResourceBundle) ListChangeListener(javafx.collections.ListChangeListener) IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) ScaleShapes(net.sf.latexdraw.commands.shape.ScaleShapes) DnD(org.malai.javafx.interaction.library.DnD) ArcAngleHandler(net.sf.latexdraw.handlers.ArcAngleHandler) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) Node(javafx.scene.Node) ShapeProperties(net.sf.latexdraw.commands.shape.ShapeProperties) ModifyShapeProperty(net.sf.latexdraw.commands.shape.ModifyShapeProperty) RotationHandler(net.sf.latexdraw.handlers.RotationHandler) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Collectors(java.util.stream.Collectors) MoveCtrlPoint(net.sf.latexdraw.commands.shape.MoveCtrlPoint) Cursor(javafx.scene.Cursor) List(java.util.List) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) CtrlPointHandler(net.sf.latexdraw.handlers.CtrlPointHandler) ObservableList(javafx.collections.ObservableList) Handler(net.sf.latexdraw.handlers.Handler) RotateShapes(net.sf.latexdraw.commands.shape.RotateShapes) RotateShapes(net.sf.latexdraw.commands.shape.RotateShapes) CtrlPointHandler(net.sf.latexdraw.handlers.CtrlPointHandler) IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) Point3D(javafx.geometry.Point3D) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD)

Example 2 with IDrawing

use of net.sf.latexdraw.models.interfaces.shape.IDrawing in project latexdraw by arnobl.

the class TestIDrawing method testConstructor.

@Test
public void testConstructor() {
    IDrawing d = ShapeFactory.INST.createDrawing();
    assertNotNull(d.getSelection());
    assertNotNull(d.getShapes());
}
Also used : IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) Test(org.junit.Test)

Aggregations

IDrawing (net.sf.latexdraw.models.interfaces.shape.IDrawing)2 URL (java.net.URL)1 Arrays (java.util.Arrays)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 FXCollections (javafx.collections.FXCollections)1 ListChangeListener (javafx.collections.ListChangeListener)1 ObservableList (javafx.collections.ObservableList)1 Initializable (javafx.fxml.Initializable)1 Point3D (javafx.geometry.Point3D)1 Cursor (javafx.scene.Cursor)1 Node (javafx.scene.Node)1 ModifyShapeProperty (net.sf.latexdraw.commands.shape.ModifyShapeProperty)1 MoveCtrlPoint (net.sf.latexdraw.commands.shape.MoveCtrlPoint)1 MovePointShape (net.sf.latexdraw.commands.shape.MovePointShape)1 RotateShapes (net.sf.latexdraw.commands.shape.RotateShapes)1 ScaleShapes (net.sf.latexdraw.commands.shape.ScaleShapes)1 ShapeProperties (net.sf.latexdraw.commands.shape.ShapeProperties)1