Search in sources :

Example 1 with TranslateShapes

use of net.sf.latexdraw.commands.shape.TranslateShapes in project latexdraw by arnobl.

the class Hand method bindDnDTranslate.

/**
 * A DnD on a shape view allows to translate the underlying shape.
 */
private void bindDnDTranslate() {
    nodeBinder(TranslateShapes.class, new DnD(true, true)).on(canvas.getViews().getChildren()).on(canvas.getSelectionBorder()).map(i -> new TranslateShapes(canvas.getDrawing(), canvas.getDrawing().getSelection().duplicateDeep(false))).then((c, i) -> {
        final IPoint startPt = grid.getTransformedPointToGrid(i.getSrcScenePoint());
        final IPoint endPt = grid.getTransformedPointToGrid(i.getEndScenePt());
        c.setT(endPt.getX() - startPt.getX(), endPt.getY() - startPt.getY());
    }).when(i -> i.getButton() == MouseButton.PRIMARY && !canvas.getDrawing().getSelection().isEmpty()).exec().first((c, i) -> {
        i.getSrcObject().ifPresent(node -> Platform.runLater(() -> node.requestFocus()));
        canvas.setCursor(Cursor.MOVE);
    }).cancel((c, i) -> canvas.update()).strictStart().bind();
}
Also used : MouseButton(javafx.scene.input.MouseButton) ViewText(net.sf.latexdraw.view.jfx.ViewText) Command(org.malai.command.Command) BoundingBox(javafx.geometry.BoundingBox) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) SelectShapes(net.sf.latexdraw.commands.shape.SelectShapes) JfXWidgetBinding(org.malai.javafx.binding.JfXWidgetBinding) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) ArrayList(java.util.ArrayList) ViewShape(net.sf.latexdraw.view.jfx.ViewShape) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) ListChangeListener(javafx.collections.ListChangeListener) Transform(javafx.scene.transform.Transform) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Canvas(net.sf.latexdraw.view.jfx.Canvas) DnD(org.malai.javafx.interaction.library.DnD) KeyCode(javafx.scene.input.KeyCode) Node(javafx.scene.Node) LSystem(net.sf.latexdraw.util.LSystem) IText(net.sf.latexdraw.models.interfaces.shape.IText) Rectangle(javafx.scene.shape.Rectangle) UpdateToGrid(net.sf.latexdraw.commands.shape.UpdateToGrid) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) TranslateShapes(net.sf.latexdraw.commands.shape.TranslateShapes) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) List(java.util.List) Press(org.malai.javafx.interaction.library.Press) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) Optional(java.util.Optional) DoubleClick(org.malai.javafx.interaction.library.DoubleClick) Collections(java.util.Collections) Shape(javafx.scene.shape.Shape) Bounds(javafx.geometry.Bounds) TranslateShapes(net.sf.latexdraw.commands.shape.TranslateShapes) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Platform (javafx.application.Platform)1 ListChangeListener (javafx.collections.ListChangeListener)1 BoundingBox (javafx.geometry.BoundingBox)1 Bounds (javafx.geometry.Bounds)1 Cursor (javafx.scene.Cursor)1 Node (javafx.scene.Node)1 KeyCode (javafx.scene.input.KeyCode)1 MouseButton (javafx.scene.input.MouseButton)1 Rectangle (javafx.scene.shape.Rectangle)1 Shape (javafx.scene.shape.Shape)1 NonInvertibleTransformException (javafx.scene.transform.NonInvertibleTransformException)1 Transform (javafx.scene.transform.Transform)1 InitTextSetter (net.sf.latexdraw.commands.shape.InitTextSetter)1 SelectShapes (net.sf.latexdraw.commands.shape.SelectShapes)1 TranslateShapes (net.sf.latexdraw.commands.shape.TranslateShapes)1 UpdateToGrid (net.sf.latexdraw.commands.shape.UpdateToGrid)1