Search in sources :

Example 1 with ViewPlot

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

the class TestCanvasSelection method testClickPlotSelectsShape.

@Test
public void testClickPlotSelectsShape() {
    new CompositeGUIVoidCommand(addPlot, waitFXEvents).execute();
    final ViewPlot vplot = (ViewPlot) getPane().getChildren().get(0);
    new CompositeGUIVoidCommand(() -> clickOn(vplot), waitFXEvents).execute();
    assertEquals(1, canvas.getDrawing().getSelection().size());
    assertSame(addedPlot, canvas.getDrawing().getSelection().getShapeAt(0));
}
Also used : ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) Test(org.junit.Test)

Example 2 with ViewPlot

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

the class TestCanvasSelection method testEditPlotDoesNotCreateANewOne.

@Test
public void testEditPlotDoesNotCreateANewOne() {
    when(pencil.getCurrentChoice()).thenReturn(EditionChoice.PLOT);
    when(pencil.createShapeInstance()).thenReturn(ShapeFactory.INST.createPlot(ShapeFactory.INST.createPoint(), 0, 5, "x", false));
    ShapePlotCustomiser plot = (ShapePlotCustomiser) injectorFactory.call(ShapePlotCustomiser.class);
    plot.maxXSpinner = Mockito.mock(Spinner.class);
    plot.minXSpinner = Mockito.mock(Spinner.class);
    plot.nbPtsSpinner = Mockito.mock(Spinner.class);
    when(plot.maxXSpinner.getValue()).thenReturn(10d);
    when(plot.minXSpinner.getValue()).thenReturn(0d);
    when(plot.nbPtsSpinner.getValue()).thenReturn(10);
    new CompositeGUIVoidCommand(addPlot, waitFXEvents).execute();
    final ViewPlot v = (ViewPlot) canvas.getViews().getChildren().get(0);
    doubleClickOn(v).sleep(10).type(KeyCode.DELETE).write("x 2 mul").sleep(10).type(KeyCode.ENTER).sleep(SLEEP);
    assertEquals(1, canvas.getDrawing().size());
    assertEquals(1, canvas.getViews().getChildren().size());
}
Also used : Spinner(javafx.scene.control.Spinner) ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) Test(org.junit.Test)

Example 3 with ViewPlot

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

the class Hand method dbleClickToInitTextSetter.

/**
 * Double click to initialise the text setter to edit plot and text shapes.
 */
private void dbleClickToInitTextSetter() {
    // For text shapes.
    nodeBinder(InitTextSetter.class, new DoubleClick()).on(canvas.getViews().getChildren()).map(i -> {
        final IText text = ((ViewText) i.getClickData().getSrcObject().get().getParent()).getModel();
        return new InitTextSetter(textSetter, textSetter, null, ShapeFactory.INST.createPoint(text.getPosition().getX() * canvas.getZoom(), text.getPosition().getY() * canvas.getZoom()), text, null);
    }).when(i -> i.getClickData().getSrcObject().isPresent() && i.getClickData().getSrcObject().get().getParent() instanceof ViewText).strictStart().bind();
    // For plot shapes.
    nodeBinder(InitTextSetter.class, new DoubleClick()).on(canvas.getViews().getChildren()).map(i -> {
        final IPlot plot = getViewShape(i.getClickData().getSrcObject()).map(view -> ((ViewPlot) view).getModel()).get();
        return new InitTextSetter(textSetter, textSetter, null, ShapeFactory.INST.createPoint(plot.getPosition().getX() * canvas.getZoom(), plot.getPosition().getY() * canvas.getZoom()), null, plot);
    }).when(i -> i.getClickData().getSrcObject().isPresent() && i.getClickData().getSrcObject().get().getParent() != null && getViewShape(i.getClickData().getSrcObject()).orElse(null) instanceof ViewPlot).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) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) ViewText(net.sf.latexdraw.view.jfx.ViewText) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) DoubleClick(org.malai.javafx.interaction.library.DoubleClick) ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) IText(net.sf.latexdraw.models.interfaces.shape.IText)

Aggregations

ViewPlot (net.sf.latexdraw.view.jfx.ViewPlot)3 Test (org.junit.Test)2 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 Spinner (javafx.scene.control.Spinner)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