Search in sources :

Example 1 with Picture

use of net.sf.latexdraw.model.api.shape.Picture in project latexdraw by arnobl.

the class InsertPicture method doCmdBody.

@Override
protected void doCmdBody() {
    // Asks the user for the picture to load.
    final File file = fileChooser.showOpenDialog(null);
    if (file != null && file.canRead()) {
        ((Picture) shape).setPathSource(file.getAbsolutePath());
        loaded = true;
    }
    if (loaded) {
        super.redo();
    }
}
Also used : Picture(net.sf.latexdraw.model.api.shape.Picture) File(java.io.File)

Example 2 with Picture

use of net.sf.latexdraw.model.api.shape.Picture in project latexdraw by arnobl.

the class PictureImpl method duplicate.

@Override
@NotNull
public Picture duplicate() {
    final Picture pic = ShapeFactory.INST.createPicture(getPosition());
    pic.copy(this);
    return pic;
}
Also used : Picture(net.sf.latexdraw.model.api.shape.Picture) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Picture

use of net.sf.latexdraw.model.api.shape.Picture in project latexdraw by arnobl.

the class TestCanvasCreation method testDrawPicture.

@Test
public void testDrawPicture() {
    final FileChooser c = Mockito.mock(FileChooser.class);
    final URL resource = getClass().getResource("/LaTeXDrawSmall.png");
    final Point2D pos = point(canvas).query();
    when(c.showOpenDialog(Mockito.any())).thenReturn(new File(resource.getPath()));
    when(setter.isActivated()).thenReturn(true);
    when(setter.getPosition()).thenReturn(ShapeFactory.INST.createPoint(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), -Canvas.getMargins() + canvas.screenToLocal(pos).getY()));
    Cmds.of(CmdFXVoid.of(() -> {
        editing.setCurrentChoice(EditionChoice.PICTURE);
        pencil.setPictureFileChooser(c);
        textAutoSize.setText("gridGapProp");
    }), () -> moveTo(pos).clickOn(MouseButton.PRIMARY)).execute();
    assertEquals(1, drawing.size());
    assertTrue(drawing.getShapeAt(0).orElseThrow() instanceof Picture);
    final Picture sh = (Picture) drawing.getShapeAt(0).orElseThrow();
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), sh.getPosition().getX(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getY(), sh.getPosition().getY(), 1d);
}
Also used : Point2D(javafx.geometry.Point2D) Picture(net.sf.latexdraw.model.api.shape.Picture) FileChooser(javafx.stage.FileChooser) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 4 with Picture

use of net.sf.latexdraw.model.api.shape.Picture in project latexdraw by arnobl.

the class TestCanvasTranslation method testShapeTranslationOK.

@Theory
public void testShapeTranslationOK(@ShapeData final Shape sh) {
    if (sh instanceof Picture) {
        ((Picture) sh).setPathSource(getClass().getResource("/Arc.png").getFile());
    }
    Cmds.of(CmdFXVoid.of(() -> {
        canvas.getSelectionBorder().setFill(new Color(1d, 1d, 1d, 0.1d));
        sh.setFilled(true);
        sh.translate(-canvas.getOrigin().getX(), -canvas.getOrigin().getY());
        canvas.getDrawing().addShape(sh);
        canvas.getDrawing().setSelection(List.of(sh));
    }), requestFocusCanvas).execute();
    final Point tl = sh.getTopLeftPoint();
    Cmds.of(() -> drag(canvas.getSelectionBorder()).dropBy(101, 163)).execute();
    assertEquals(tl.getX() + 101d, sh.getTopLeftPoint().getX(), 5d);
    assertEquals(tl.getY() + 163d, sh.getTopLeftPoint().getY(), 5d);
}
Also used : Picture(net.sf.latexdraw.model.api.shape.Picture) Color(javafx.scene.paint.Color) Point(net.sf.latexdraw.model.api.shape.Point) Theory(org.junit.experimental.theories.Theory)

Example 5 with Picture

use of net.sf.latexdraw.model.api.shape.Picture in project latexdraw by arnobl.

the class PolymorphPictureTest method testPathPicture.

@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#createDiversifiedPicture")
default void testPathPicture(final Picture sh) throws IOException {
    final File tmpFile = Files.temporaryFolder();
    sh.setPathSource(ParameteriseShapeData.INST.getTestPNG(tmpFile.toPath()).toString());
    final Picture s2 = produceOutputShapeFrom(sh);
    assertEquals(sh.getPathSource(), s2.getPathSource());
}
Also used : Picture(net.sf.latexdraw.model.api.shape.Picture) File(java.io.File) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Picture (net.sf.latexdraw.model.api.shape.Picture)7 File (java.io.File)3 Test (org.junit.jupiter.api.Test)2 URL (java.net.URL)1 Point2D (javafx.geometry.Point2D)1 Color (javafx.scene.paint.Color)1 FileChooser (javafx.stage.FileChooser)1 Point (net.sf.latexdraw.model.api.shape.Point)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.junit.Test)1 Theory (org.junit.experimental.theories.Theory)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1