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