Search in sources :

Example 1 with Group

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

the class ShapeGrouper method configureBindings.

@Override
protected void configureBindings() {
    buttonBinder().toProduce(() -> new SeparateShapes(canvas.getDrawing(), getSelectCmd().map(sel -> sel.getShapes()).filter(sel -> sel.size() == 1 && sel.get(0) instanceof Group).map(sel -> (Group) sel.get(0)).orElseThrow())).when(() -> getSelectCmd().map(sel -> sel.getShapes()).filter(sel -> sel.size() == 1 && sel.get(0) instanceof Group).isPresent()).on(sepB).bind();
    buttonBinder().toProduce(() -> new JoinShapes(canvas.getDrawing(), getSelectCmd().map(sel -> sel.getShapes()).orElse(List.of()))).on(groupB).bind();
}
Also used : Button(javafx.scene.control.Button) EditingService(net.sf.latexdraw.service.EditingService) SeparateShapes(net.sf.latexdraw.command.shape.SeparateShapes) Drawing(net.sf.latexdraw.model.api.shape.Drawing) URL(java.net.URL) FXML(javafx.fxml.FXML) Group(net.sf.latexdraw.model.api.shape.Group) List(java.util.List) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) AnchorPane(javafx.scene.layout.AnchorPane) JoinShapes(net.sf.latexdraw.command.shape.JoinShapes) Canvas(net.sf.latexdraw.view.jfx.Canvas) Group(net.sf.latexdraw.model.api.shape.Group) JoinShapes(net.sf.latexdraw.command.shape.JoinShapes) SeparateShapes(net.sf.latexdraw.command.shape.SeparateShapes)

Example 2 with Group

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

the class JoinShapesTest method doCheckers.

@Override
protected Stream<Runnable> doCheckers() {
    return Stream.of(() -> {
        assertThat(drawing.getShapes()).hasSize(3);
        assertThat(drawing.getShapes().get(0)).isEqualTo(s1);
        assertThat(drawing.getShapes().get(1)).isEqualTo(s3);
        assertThat(drawing.getShapes().get(2)).isInstanceOf(Group.class);
        final Group group = (Group) drawing.getShapes().get(2);
        assertThat(group.getShapeAt(0).orElseThrow()).isEqualTo(s0);
        assertThat(group.getShapeAt(1).orElseThrow()).isEqualTo(s2);
        assertThat(group.getShapeAt(2).orElseThrow()).isEqualTo(s4);
        assertThat(drawing.isModified()).isTrue();
    });
}
Also used : Group(net.sf.latexdraw.model.api.shape.Group)

Example 3 with Group

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

the class TestDrawing method testSetSelectionList2.

@Test
public void testSetSelectionList2() {
    final List<Shape> list = new ArrayList<>();
    final Group selection = drawing.getSelection();
    final Shape sh = ShapeFactory.INST.createRectangle();
    final Shape sh2 = ShapeFactory.INST.createRectangle();
    list.add(sh);
    list.add(sh2);
    drawing.setSelection(list);
    assertEquals(selection, drawing.getSelection());
    assertEquals(2, drawing.getSelection().size());
    assertEquals(sh, drawing.getSelection().getShapeAt(0).orElseThrow());
    assertEquals(sh2, drawing.getSelection().getShapeAt(1).orElseThrow());
}
Also used : Group(net.sf.latexdraw.model.api.shape.Group) Shape(net.sf.latexdraw.model.api.shape.Shape) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with Group

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

the class InsertPSTCode method doCmdBody.

@Override
protected void doCmdBody() {
    final PSTLatexdrawListener listener = new PSTLatexdrawListener();
    final PSTLexer lexer = new PSTLexer(CharStreams.fromString(code));
    final PSTParser parser = new PSTParser(new CommonTokenStream(lexer));
    parser.addParseListener(listener);
    parser.pstCode(new PSTContext());
    final Group group = ShapeFactory.INST.createGroup();
    group.getShapes().addAll(listener.flatShapes());
    if (!group.isEmpty()) {
        final Shape sh = group.size() > 1 ? group : group.getShapeAt(0).orElseThrow();
        final Point tl = sh.getTopLeftPoint();
        final double tx = tl.getX() < 0d ? -tl.getX() + 50d : 0d;
        final double ty = tl.getY() < 0d ? -tl.getY() + 50d : 0d;
        shapes = Optional.of(sh);
        sh.translate(tx, ty);
        redo();
        statusBar.setText(lang.getString("codeConverted"));
    }
    parser.getInterpreter().clearDFA();
    lexer.getInterpreter().clearDFA();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Group(net.sf.latexdraw.model.api.shape.Group) PSTLexer(net.sf.latexdraw.parser.pst.PSTLexer) Shape(net.sf.latexdraw.model.api.shape.Shape) PSTLatexdrawListener(net.sf.latexdraw.parser.pst.PSTLatexdrawListener) PSTContext(net.sf.latexdraw.parser.pst.PSTContext) Point(net.sf.latexdraw.model.api.shape.Point) PSTParser(net.sf.latexdraw.parser.pst.PSTParser)

Example 5 with Group

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

the class TestShapeGrouper method testUnGroup.

@Test
public void testUnGroup() {
    Cmds.of(selectOneGroup).execute();
    final Group group = (Group) drawing.getShapeAt(0).orElseThrow();
    Cmds.of(clickSep).execute();
    assertEquals(2, drawing.size());
    assertEquals(group.getShapeAt(0).orElseThrow(), drawing.getShapeAt(0).orElseThrow());
    assertEquals(group.getShapeAt(1).orElseThrow(), drawing.getShapeAt(1).orElseThrow());
}
Also used : Group(net.sf.latexdraw.model.api.shape.Group) Test(org.junit.Test)

Aggregations

Group (net.sf.latexdraw.model.api.shape.Group)8 Test (org.junit.Test)4 Shape (net.sf.latexdraw.model.api.shape.Shape)3 ArrayList (java.util.ArrayList)2 URL (java.net.URL)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 FXML (javafx.fxml.FXML)1 Button (javafx.scene.control.Button)1 AnchorPane (javafx.scene.layout.AnchorPane)1 HelperTest (net.sf.latexdraw.HelperTest)1 JoinShapes (net.sf.latexdraw.command.shape.JoinShapes)1 SeparateShapes (net.sf.latexdraw.command.shape.SeparateShapes)1 Drawing (net.sf.latexdraw.model.api.shape.Drawing)1 Point (net.sf.latexdraw.model.api.shape.Point)1 PSTContext (net.sf.latexdraw.parser.pst.PSTContext)1 PSTLatexdrawListener (net.sf.latexdraw.parser.pst.PSTLatexdrawListener)1 PSTLexer (net.sf.latexdraw.parser.pst.PSTLexer)1 PSTParser (net.sf.latexdraw.parser.pst.PSTParser)1 EditingService (net.sf.latexdraw.service.EditingService)1