Search in sources :

Example 1 with Canvas

use of net.sf.latexdraw.view.jfx.Canvas in project latexdraw by arnobl.

the class Hand method bindPressureToSelectShape.

/**
 * Pressure to select shapes
 */
private void bindPressureToSelectShape() {
    nodeBinder(SelectShapes.class, new Press()).on(canvas.getViews().getChildren()).first((c, i) -> {
        c.setDrawing(canvas.getDrawing());
        getViewShape(i.getSrcObject()).map(src -> src.getModel()).ifPresent(targetSh -> {
            if (i.isShiftPressed()) {
                canvas.getDrawing().getSelection().getShapes().stream().filter(sh -> sh != targetSh).forEach(sh -> c.addShape(sh));
                return;
            }
            if (i.isCtrlPressed()) {
                canvas.getDrawing().getSelection().getShapes().forEach(sh -> c.addShape(sh));
                c.addShape(targetSh);
                return;
            }
            c.setShape(targetSh);
        });
    }).bind();
    // A simple pressure on the canvas deselects the shapes
    nodeBinder(SelectShapes.class, new Press()).on(canvas).first((c, i) -> c.setDrawing(canvas.getDrawing())).when(i -> i.getSrcObject().orElse(null) instanceof Canvas).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) SelectShapes(net.sf.latexdraw.commands.shape.SelectShapes) Canvas(net.sf.latexdraw.view.jfx.Canvas) Press(org.malai.javafx.interaction.library.Press)

Example 2 with Canvas

use of net.sf.latexdraw.view.jfx.Canvas in project latexdraw by arnobl.

the class TestModifyMagneticGrid method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    grid = new MagneticGridImpl(new Canvas());
    // Cannot have two runners so cannot use mock to mock Canvas:
    CommandsRegistry.INSTANCE.removeAllHandlers();
    switch(property) {
        case STYLE:
            mementoCmd = () -> grid.getGridStyle();
            value = GridStyle.STANDARD;
            break;
        case MAGNETIC:
            mementoCmd = () -> grid.isMagnetic();
            value = true;
            break;
        case GRID_SPACING:
            mementoCmd = () -> grid.getGridSpacing();
            value = 11;
            break;
    }
    memento = mementoCmd.get();
}
Also used : Canvas(net.sf.latexdraw.view.jfx.Canvas) MagneticGridImpl(net.sf.latexdraw.view.jfx.MagneticGridImpl) Before(org.junit.Before)

Example 3 with Canvas

use of net.sf.latexdraw.view.jfx.Canvas in project latexdraw by arnobl.

the class TestTabSelector method start.

@Override
public void start(final Stage aStage) {
    super.start(aStage);
    tabPane = find("#tabPane");
    final int width = 800;
    final int height = 600;
    stage.minHeightProperty().unbind();
    stage.minWidthProperty().unbind();
    final Canvas canvas = injector.getInstance(Canvas.class);
    canvas.setMaxWidth(width);
    canvas.setMaxHeight(height);
    canvas.getScene().getWindow().setWidth(width);
    canvas.getScene().getWindow().setHeight(height);
    stage.setMaxWidth(width);
    stage.setMaxHeight(height);
    stage.setMinWidth(width);
    stage.setMinHeight(height);
    stage.centerOnScreen();
    stage.toFront();
}
Also used : Canvas(net.sf.latexdraw.view.jfx.Canvas)

Example 4 with Canvas

use of net.sf.latexdraw.view.jfx.Canvas in project latexdraw by arnobl.

the class TestTabSelector method testClickCanvasActivationsOnSelectedShape.

@Test
public void testClickCanvasActivationsOnSelectedShape() {
    final IRectangle rectangle = ShapeFactory.INST.createRectangle(ShapeFactory.INST.createPoint(), 100, 50);
    final Canvas canvas = injector.getInstance(Canvas.class);
    Platform.runLater(() -> {
        canvas.getDrawing().addShape(rectangle);
        canvas.getDrawing().getSelection().addShape(rectangle);
    });
    WaitForAsyncUtils.waitForFxEvents();
    clickOn(tabPane.lookup("#tabPST"));
    clickOn(tabPane.lookup("#canvasTab"));
    WaitForAsyncUtils.waitForFxEvents();
    sleep(100L);
    Mockito.verify(deleter, Mockito.times(1)).setActivated(true);
}
Also used : Canvas(net.sf.latexdraw.view.jfx.Canvas) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle) Test(org.junit.Test)

Example 5 with Canvas

use of net.sf.latexdraw.view.jfx.Canvas in project latexdraw by arnobl.

the class TestAlignShape method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    canvas = Mockito.mock(Canvas.class);
    final IShapeFactory fac = ShapeFactory.INST;
    shapes = fac.createGroup();
    shapes.addShape(fac.createRectangle(fac.createPoint(10d, -2d), 6d, 6d));
    shapes.addShape(fac.createRectangle(fac.createPoint(-5d, 20d), 12d, 15d));
    shapes.addShape(fac.createRectangle(fac.createPoint(14d, 60d), 20d, 16d));
    views = new Group();
    IntStream.range(0, shapes.size()).forEach(i -> {
        views.getChildren().add(ViewFactory.INSTANCE.createView(shapes.getShapeAt(i)).get());
        Mockito.when(canvas.getViewFromShape(shapes.getShapeAt(i))).thenReturn(Optional.of((ViewShape<?>) views.getChildren().get(i)));
    });
}
Also used : IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) Group(javafx.scene.Group) Canvas(net.sf.latexdraw.view.jfx.Canvas) ViewShape(net.sf.latexdraw.view.jfx.ViewShape) IShapeFactory(net.sf.latexdraw.models.interfaces.shape.IShapeFactory) Before(org.junit.Before)

Aggregations

Canvas (net.sf.latexdraw.view.jfx.Canvas)6 Cursor (javafx.scene.Cursor)2 Node (javafx.scene.Node)2 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)2 Inject (net.sf.latexdraw.util.Inject)2 ViewShape (net.sf.latexdraw.view.jfx.ViewShape)2 Before (org.junit.Before)2 DnD (org.malai.javafx.interaction.library.DnD)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 ResourceBundle (java.util.ResourceBundle)1 Platform (javafx.application.Platform)1 Bindings (javafx.beans.binding.Bindings)1 ListChangeListener (javafx.collections.ListChangeListener)1 FXML (javafx.fxml.FXML)1 Initializable (javafx.fxml.Initializable)1