use of net.sf.latexdraw.model.api.shape.Shape in project latexdraw by arnobl.
the class TestShapePositioner method testOneShapeBackground.
@Test
public void testOneShapeBackground() {
Cmds.of(selectOneShape, selectOneShape).execute();
final Shape s1 = drawing.getShapeAt(0).orElseThrow();
final Shape s2 = drawing.getShapeAt(1).orElseThrow();
Cmds.of(() -> clickOn("#backgroundB")).execute();
assertEquals(s2, drawing.getShapeAt(0).orElseThrow());
assertEquals(s1, drawing.getShapeAt(1).orElseThrow());
}
use of net.sf.latexdraw.model.api.shape.Shape 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.Shape in project latexdraw by arnobl.
the class MoveBackForegroundShapes method moveForeground.
/**
* Puts the shapes in the foreground.
*/
private void moveForeground() {
final int size = shape.size();
prepareMove();
for (int i = 0; i < size; i++) {
final Shape sh = sortedSh.get(i);
formerId[i] = drawing.getShapes().indexOf(sh);
drawing.removeShape(sh);
drawing.addShape(sh);
}
drawing.setModified(true);
}
use of net.sf.latexdraw.model.api.shape.Shape in project latexdraw by arnobl.
the class Canvas method getIntersectedShapes.
public List<Shape> getIntersectedShapes(final Bounds selectionBorder) {
final Rectangle selectionRec = new Rectangle(selectionBorder.getMinX() + Canvas.ORIGIN.getX(), selectionBorder.getMinY() + Canvas.ORIGIN.getY(), selectionBorder.getWidth(), selectionBorder.getHeight());
// Transforming the selection rectangle to match the transformation of the canvas.
selectionRec.getTransforms().setAll(getLocalToSceneTransform());
return getViews().getChildren().stream().filter(view -> {
Bounds bounds;
final Transform transform = view.getLocalToParentTransform();
if (transform.isIdentity()) {
bounds = selectionBorder;
} else {
try {
bounds = transform.createInverse().transform(selectionBorder);
} catch (final NonInvertibleTransformException ex) {
bounds = selectionBorder;
}
}
return view.intersects(bounds) && ((ViewShape<?>) view).getActivatedShapes().stream().anyMatch(sh -> !javafx.scene.shape.Shape.intersect(sh, selectionRec).getLayoutBounds().isEmpty());
}).map(view -> (Shape) view.getUserData()).collect(Collectors.toList());
}
use of net.sf.latexdraw.model.api.shape.Shape in project latexdraw by arnobl.
the class TestShapePositioner method testSeveralShapesBackground.
@Test
public void testSeveralShapesBackground() {
Cmds.of(selectThreeShapes, selectTwoShapes).execute();
selectShapeAt.execute(Arrays.asList(1, 2));
final Shape s2 = drawing.getShapeAt(1).orElseThrow();
final Shape s3 = drawing.getShapeAt(2).orElseThrow();
Cmds.of(() -> clickOn("#backgroundB")).execute();
assertEquals(s2, drawing.getShapeAt(0).orElseThrow());
assertEquals(s3, drawing.getShapeAt(1).orElseThrow());
}
Aggregations