Search in sources :

Example 31 with Shape

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

the class TestPSTShape method testLoadRotationAngleParams.

@Override
@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#getDiversifiedShapes")
public void testLoadRotationAngleParams(final Shape sh) {
    assumeFalse(sh instanceof Polygon || sh instanceof BezierCurve);
    final Shape s2 = produceOutputShapeFrom(sh);
    CompareShapeMatcher.INST.assertEqualShapeRotationAngle(sh, s2);
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Polygon(net.sf.latexdraw.model.api.shape.Polygon) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 32 with Shape

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

the class TestPSTShape method testFreeHandPointsCurves.

@Test
public void testFreeHandPointsCurves() {
    final Freehand fh = ShapeFactory.INST.createFreeHand(Arrays.asList(ShapeFactory.INST.createPoint(50d, 70d), ShapeFactory.INST.createPoint(100d, 90d), ShapeFactory.INST.createPoint(110d, 100d), ShapeFactory.INST.createPoint(150d, 180d)));
    fh.setInterval(1);
    fh.setType(FreeHandStyle.CURVES);
    final Shape s2 = produceOutputShapeFrom(fh);
    assertThat(s2.getPoints()).isEqualTo(Arrays.asList(ShapeFactory.INST.createPoint(50d, 70d), ShapeFactory.INST.createPoint(75d, 80d), ShapeFactory.INST.createPoint(105d, 95d), ShapeFactory.INST.createPoint(130d, 140d)));
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Freehand(net.sf.latexdraw.model.api.shape.Freehand) PolymorphShapeTest(net.sf.latexdraw.view.PolymorphShapeTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with Shape

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

the class Canvas method defineShapeListBindingOnAdd.

private void defineShapeListBindingOnAdd(@NotNull final Change<? extends Shape> evt) {
    final List<? extends Shape> added = List.copyOf(evt.getAddedSubList());
    Platform.runLater(() -> added.forEach(sh -> viewFactory.createView(sh).ifPresent(v -> {
        final int index = drawing.getShapes().indexOf(sh);
        if (index != -1) {
            shapesToViewMap.put(sh, v);
            if (index == drawing.size()) {
                shapesPane.getChildren().add(v);
            } else {
                shapesPane.getChildren().add(index, v);
            }
        }
    })));
}
Also used : Change(javafx.collections.ListChangeListener.Change) Point2D(java.awt.geom.Point2D) Flushable(net.sf.latexdraw.util.Flushable) Rectangle2D(java.awt.geom.Rectangle2D) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) Parent(javafx.scene.Parent) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Inject(net.sf.latexdraw.util.Inject) ScrollPane(javafx.scene.control.ScrollPane) Preferenciable(io.github.interacto.properties.Preferenciable) Document(org.w3c.dom.Document) Map(java.util.Map) Transform(javafx.scene.transform.Transform) Pane(javafx.scene.layout.Pane) Rectangle(javafx.scene.shape.Rectangle) Reinitialisable(io.github.interacto.properties.Reinitialisable) JavaFxScheduler(io.reactivex.rxjavafx.schedulers.JavaFxScheduler) Group(javafx.scene.Group) Point(net.sf.latexdraw.model.api.shape.Point) Collectors(java.util.stream.Collectors) Modifiable(io.github.interacto.properties.Modifiable) ViewsSynchroniserHandler(net.sf.latexdraw.view.ViewsSynchroniserHandler) Objects(java.util.Objects) Platform(javafx.application.Platform) BadaboomCollector(net.sf.latexdraw.util.BadaboomCollector) Nullable(org.jetbrains.annotations.Nullable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) StrokeLineCap(javafx.scene.shape.StrokeLineCap) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) Bounds(javafx.geometry.Bounds) Drawing(net.sf.latexdraw.model.api.shape.Drawing) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) Shape(net.sf.latexdraw.model.api.shape.Shape) LNamespace(net.sf.latexdraw.util.LNamespace) JavaFxObservable(io.reactivex.rxjavafx.observables.JavaFxObservable) Node(org.w3c.dom.Node) Zoomable(io.github.interacto.properties.Zoomable) MathUtils(net.sf.latexdraw.model.MathUtils) Redo(io.github.interacto.command.library.Redo) Modifying(net.sf.latexdraw.command.Modifying) Color(javafx.scene.paint.Color) CommandsRegistry(io.github.interacto.command.CommandsRegistry) NodeList(org.w3c.dom.NodeList) Undo(io.github.interacto.command.library.Undo) Click(io.github.interacto.jfx.interaction.library.Click) TimeUnit(java.util.concurrent.TimeUnit) PreferencesService(net.sf.latexdraw.service.PreferencesService) Element(org.w3c.dom.Element) Point(net.sf.latexdraw.model.api.shape.Point)

Example 34 with Shape

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

the class Canvas method updateSelectionBorders.

private void updateSelectionBorders() {
    if (selectionBorder.isDisable()) {
        return;
    }
    final List<Shape> selection = List.copyOf(drawing.getSelection().getShapes());
    if (selection.isEmpty()) {
        selectionBorder.setVisible(false);
    } else {
        final Rectangle2D rec = selection.stream().map(sh -> shapesToViewMap.get(sh)).filter(vi -> vi != null).map(vi -> {
            final Bounds b = vi.getBoundsInParent();
            return (Rectangle2D) new Rectangle2D.Double(b.getMinX(), b.getMinY(), b.getWidth(), b.getHeight());
        }).reduce(Rectangle2D::createUnion).orElseGet(() -> new Rectangle2D.Double());
        setVisibleSelectionBorder(rec.getMinX(), rec.getMinY(), rec.getWidth(), rec.getHeight(), false);
    }
}
Also used : Change(javafx.collections.ListChangeListener.Change) Point2D(java.awt.geom.Point2D) Flushable(net.sf.latexdraw.util.Flushable) Rectangle2D(java.awt.geom.Rectangle2D) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) Parent(javafx.scene.Parent) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Inject(net.sf.latexdraw.util.Inject) ScrollPane(javafx.scene.control.ScrollPane) Preferenciable(io.github.interacto.properties.Preferenciable) Document(org.w3c.dom.Document) Map(java.util.Map) Transform(javafx.scene.transform.Transform) Pane(javafx.scene.layout.Pane) Rectangle(javafx.scene.shape.Rectangle) Reinitialisable(io.github.interacto.properties.Reinitialisable) JavaFxScheduler(io.reactivex.rxjavafx.schedulers.JavaFxScheduler) Group(javafx.scene.Group) Point(net.sf.latexdraw.model.api.shape.Point) Collectors(java.util.stream.Collectors) Modifiable(io.github.interacto.properties.Modifiable) ViewsSynchroniserHandler(net.sf.latexdraw.view.ViewsSynchroniserHandler) Objects(java.util.Objects) Platform(javafx.application.Platform) BadaboomCollector(net.sf.latexdraw.util.BadaboomCollector) Nullable(org.jetbrains.annotations.Nullable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) StrokeLineCap(javafx.scene.shape.StrokeLineCap) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) Bounds(javafx.geometry.Bounds) Drawing(net.sf.latexdraw.model.api.shape.Drawing) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) Shape(net.sf.latexdraw.model.api.shape.Shape) LNamespace(net.sf.latexdraw.util.LNamespace) JavaFxObservable(io.reactivex.rxjavafx.observables.JavaFxObservable) Node(org.w3c.dom.Node) Zoomable(io.github.interacto.properties.Zoomable) MathUtils(net.sf.latexdraw.model.MathUtils) Redo(io.github.interacto.command.library.Redo) Modifying(net.sf.latexdraw.command.Modifying) Color(javafx.scene.paint.Color) CommandsRegistry(io.github.interacto.command.CommandsRegistry) NodeList(org.w3c.dom.NodeList) Undo(io.github.interacto.command.library.Undo) Click(io.github.interacto.jfx.interaction.library.Click) TimeUnit(java.util.concurrent.TimeUnit) PreferencesService(net.sf.latexdraw.service.PreferencesService) Element(org.w3c.dom.Element) Shape(net.sf.latexdraw.model.api.shape.Shape) Bounds(javafx.geometry.Bounds) Rectangle2D(java.awt.geom.Rectangle2D)

Example 35 with Shape

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

the class TestShapePositioner method testOneShapeForeground.

@Test
public void testOneShapeForeground() {
    Cmds.of(selectOneShape, selectOneShape).execute();
    selectShapeAt.execute(Collections.singletonList(0));
    final Shape s1 = drawing.getShapeAt(0).orElseThrow();
    final Shape s2 = drawing.getShapeAt(1).orElseThrow();
    Cmds.of(() -> clickOn("#foregroundB")).execute();
    assertEquals(s2, drawing.getShapeAt(0).orElseThrow());
    assertEquals(s1, drawing.getShapeAt(1).orElseThrow());
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Test(org.junit.Test)

Aggregations

Shape (net.sf.latexdraw.model.api.shape.Shape)75 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 MethodSource (org.junit.jupiter.params.provider.MethodSource)41 Test (org.junit.Test)12 Point (net.sf.latexdraw.model.api.shape.Point)8 PositionShape (net.sf.latexdraw.model.api.shape.PositionShape)7 HelperTest (net.sf.latexdraw.HelperTest)6 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)6 Circle (net.sf.latexdraw.model.api.shape.Circle)6 RectangularShape (net.sf.latexdraw.model.api.shape.RectangularShape)6 NotNull (org.jetbrains.annotations.NotNull)6 Click (io.github.interacto.jfx.interaction.library.Click)5 ArrayList (java.util.ArrayList)5 Objects (java.util.Objects)5 MathUtils (net.sf.latexdraw.model.MathUtils)5 Rectangle (net.sf.latexdraw.model.api.shape.Rectangle)5 Inject (net.sf.latexdraw.util.Inject)5 CommandsRegistry (io.github.interacto.command.CommandsRegistry)3 Redo (io.github.interacto.command.library.Redo)3 Undo (io.github.interacto.command.library.Undo)3