use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.
the class TemplateManager method configureBindings.
@Override
protected void configureBindings() {
buttonBinder().toProduce(() -> new UpdateTemplates(templatePane, svgGen, true)).on(updateTemplates).bind();
nodeBinder().usingInteraction(DnD::new).toProduce(i -> new LoadTemplate(svgGen, drawing, new File((String) i.getSrcObject().orElseThrow().getUserData()), statusController.getProgressBar(), statusController.getLabel(), app)).on(templatePane).first(c -> templatePane.setCursor(Cursor.CLOSED_HAND)).then((i, c) -> {
final Node srcObj = i.getSrcObject().orElseThrow();
final Point3D pt3d = i.getTgtObject().orElseThrow().sceneToLocal(srcObj.localToScene(i.getTgtLocalPoint())).subtract(Canvas.ORIGIN.getX() + srcObj.getLayoutX(), Canvas.ORIGIN.getY() + srcObj.getLayoutY(), 0d);
c.setPosition(ShapeFactory.INST.createPoint(pt3d));
}).when(i -> i.getSrcObject().orElse(null) instanceof ImageView && i.getSrcObject().get().getUserData() instanceof String && i.getTgtObject().orElse(null) instanceof Canvas).endOrCancel(i -> templatePane.setCursor(Cursor.MOVE)).bind();
}
use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.
the class TestCodeInserter method setUp.
@BeforeEach
public void setUp(final Drawing drawing, final CodeInserter codeInserter) {
label = new Label();
progressBar = new ProgressBar();
Mockito.when(status.getLabel()).thenReturn(label);
Mockito.when(status.getProgressBar()).thenReturn(progressBar);
this.drawing = drawing;
inserter = codeInserter;
Cmds.of(CmdFXVoid.of(() -> {
try {
FxToolkit.registerStage(() -> inserter.getInsertCodeDialogue().orElse(null));
WaitForAsyncUtils.waitForFxEvents();
} catch (final TimeoutException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
inserter.setActivated(true);
}), CmdFXVoid.of(() -> inserter.getInsertCodeDialogue().ifPresent(stage -> {
stage.show();
stage.toFront();
}))).execute();
}
use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.
the class PSTCodeGenerator method getDrawingCode.
@Override
public String getDrawingCode() {
if (drawing.isEmpty()) {
return "";
}
final StringBuilder cache = new StringBuilder();
final Point origin = handler.getOriginDrawingPoint();
final Point tl = handler.getTopRightDrawingPoint();
final Point br = handler.getBottomLeftDrawingPoint();
final int ppc = handler.getPPCDrawing();
final Set<String> addedColours = new HashSet<>();
final StringBuilder shapeCode = new StringBuilder();
final String eol = SystemUtils.getInstance().eol;
commentCode(cache);
cache.append(packagePstricks).append("% ").append(packageForSpacePicture.replaceAll(eol, eol + "% "));
addPkgs(cache);
cache.append(eol);
final boolean hasBegan = startlatexParams(cache);
if (withLatexParams && latexdata.isPositionHoriCentre()) {
// NON-NLS
cache.append("\\begin{center}").append(eol);
}
final float scaleF = MathUtils.INST.getCutNumberFloat(latexdata.getScale());
// NON-NLS
cache.append("\\psscalebox{").append(scaleF).append(' ').append(scaleF).append("} % Change this value to rescale the drawing.");
cache.append(eol).append('{').append(eol);
// NON-NLS
cache.append("\\begin{pspicture}(");
cache.append(0).append(',').append(MathUtils.INST.getCutNumberFloat((origin.getY() - br.getY()) / ppc)).append(')').append('(');
cache.append(MathUtils.INST.getCutNumberFloat((tl.getX() - origin.getX()) / ppc)).append(',').append(MathUtils.INST.getCutNumberFloat((origin.getY() - tl.getY()) / ppc));
cache.append(')').append(eol);
drawing.getShapes().forEach(shape -> viewsFactory.createView(shape).ifPresent(pstView -> {
shapeCode.append(pstView.getCode(origin, ppc)).append(eol);
final String generateColourCode = pstView.generateColourCode(addedColours);
if (!generateColourCode.isEmpty()) {
cache.append(generateColourCode).append(eol);
}
}));
cache.append(shapeCode).append(// NON-NLS
"\\end{pspicture}").append(eol).append('}').append(eol);
endlatexParams(cache, hasBegan);
return cache.toString();
}
use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.
the class TestDrawing method testConstructor.
@Test
public void testConstructor() {
final Drawing d = ShapeFactory.INST.createDrawing();
assertNotNull(d.getSelection());
assertNotNull(d.getShapes());
}
use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.
the class TestMetaShapeCustomiser method testActivatedOnSelection.
@Test
public void testActivatedOnSelection() {
meta.initialize(null, null);
final Drawing dr = injector.getInstance(Drawing.class);
dr.getSelection().addShape(ShapeFactory.INST.createRectangle());
assertTrue(meta.isActivated());
}
Aggregations