Search in sources :

Example 1 with Drawing

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();
}
Also used : Button(javafx.scene.control.Button) Initializable(javafx.fxml.Initializable) Drawing(net.sf.latexdraw.model.api.shape.Drawing) Point3D(javafx.geometry.Point3D) URL(java.net.URL) Bindings(javafx.beans.binding.Bindings) Command(io.github.interacto.command.Command) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) JfxInstrument(io.github.interacto.jfx.instrument.JfxInstrument) FontPosture(javafx.scene.text.FontPosture) Canvas(net.sf.latexdraw.view.jfx.Canvas) UpdateTemplates(net.sf.latexdraw.command.UpdateTemplates) Label(javafx.scene.control.Label) TitledPane(javafx.scene.control.TitledPane) Node(javafx.scene.Node) Font(javafx.scene.text.Font) LoadTemplate(net.sf.latexdraw.command.LoadTemplate) File(java.io.File) Objects(java.util.Objects) FXML(javafx.fxml.FXML) Cursor(javafx.scene.Cursor) FlowPane(javafx.scene.layout.FlowPane) ImageView(javafx.scene.image.ImageView) SVGDocumentGenerator(net.sf.latexdraw.view.svg.SVGDocumentGenerator) JfxUI(io.github.interacto.jfx.ui.JfxUI) NotNull(org.jetbrains.annotations.NotNull) DnD(io.github.interacto.jfx.interaction.library.DnD) Point3D(javafx.geometry.Point3D) Node(javafx.scene.Node) Canvas(net.sf.latexdraw.view.jfx.Canvas) LoadTemplate(net.sf.latexdraw.command.LoadTemplate) ImageView(javafx.scene.image.ImageView) UpdateTemplates(net.sf.latexdraw.command.UpdateTemplates) File(java.io.File)

Example 2 with Drawing

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Injector(net.sf.latexdraw.util.Injector) Drawing(net.sf.latexdraw.model.api.shape.Drawing) TimeoutException(java.util.concurrent.TimeoutException) FxToolkit(org.testfx.api.FxToolkit) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) ProgressBar(javafx.scene.control.ProgressBar) ResourceBundle(java.util.ResourceBundle) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) HostServices(javafx.application.HostServices) FxRobot(org.testfx.api.FxRobot) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ApplicationExtension(org.testfx.framework.junit5.ApplicationExtension) Label(javafx.scene.control.Label) Text(net.sf.latexdraw.model.api.shape.Text) InvocationTargetException(java.lang.reflect.InvocationTargetException) WaitForAsyncUtils(org.testfx.util.WaitForAsyncUtils) BadaboomCollector(net.sf.latexdraw.util.BadaboomCollector) Test(org.junit.jupiter.api.Test) ConfigureInjection(net.sf.latexdraw.data.ConfigureInjection) InjectionExtension(net.sf.latexdraw.data.InjectionExtension) PreferencesService(net.sf.latexdraw.service.PreferencesService) Mockito(org.mockito.Mockito) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Rectangle(net.sf.latexdraw.model.api.shape.Rectangle) Label(javafx.scene.control.Label) ProgressBar(javafx.scene.control.ProgressBar) TimeoutException(java.util.concurrent.TimeoutException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Drawing

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();
}
Also used : VerticalPosition(net.sf.latexdraw.view.latex.VerticalPosition) Drawing(net.sf.latexdraw.model.api.shape.Drawing) Set(java.util.Set) Point(net.sf.latexdraw.model.api.shape.Point) LaTeXGenerator(net.sf.latexdraw.view.latex.LaTeXGenerator) LaTeXDataService(net.sf.latexdraw.service.LaTeXDataService) ViewsSynchroniserHandler(net.sf.latexdraw.view.ViewsSynchroniserHandler) HashSet(java.util.HashSet) Objects(java.util.Objects) Inject(net.sf.latexdraw.util.Inject) SystemUtils(net.sf.latexdraw.util.SystemUtils) MathUtils(net.sf.latexdraw.model.MathUtils) NotNull(org.jetbrains.annotations.NotNull) Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point) HashSet(java.util.HashSet)

Example 4 with Drawing

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());
}
Also used : Drawing(net.sf.latexdraw.model.api.shape.Drawing) Test(org.junit.Test)

Example 5 with Drawing

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());
}
Also used : Drawing(net.sf.latexdraw.model.api.shape.Drawing) Test(org.junit.Test)

Aggregations

Drawing (net.sf.latexdraw.model.api.shape.Drawing)7 Test (org.junit.Test)3 Objects (java.util.Objects)2 ResourceBundle (java.util.ResourceBundle)2 Label (javafx.scene.control.Label)2 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)2 Inject (net.sf.latexdraw.util.Inject)2 NotNull (org.jetbrains.annotations.NotNull)2 Command (io.github.interacto.command.Command)1 JfxInstrument (io.github.interacto.jfx.instrument.JfxInstrument)1 DnD (io.github.interacto.jfx.interaction.library.DnD)1 JfxUI (io.github.interacto.jfx.ui.JfxUI)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 HostServices (javafx.application.HostServices)1