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();
}
}
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;
}
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);
}
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);
}
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());
}
Aggregations