use of net.sf.latexdraw.models.interfaces.shape.IGroup in project latexdraw by arnobl.
the class PSTLatexdrawListener method exitPscustom.
@Override
public void exitPscustom(final net.sf.latexdraw.parsers.pst.PSTParser.PscustomContext ctx) {
final IGroup customshapes = shapes.peek();
if (ctx.pstctx.starredCmd(ctx.cmd)) {
setShapeForStar(customshapes);
}
IFreehand fh = null;
final IGroup gp = ShapeFactory.INST.createGroup();
// The different created freehand shapes must be merged into a single one.
for (final IShape sh : customshapes.getShapes()) {
if (sh instanceof IFreehand) {
final IFreehand ifh = (IFreehand) sh;
if (fh == null) {
gp.addShape(ifh);
fh = ifh;
// This shape is now the reference shape used for the merge.
fh.setInterval(1);
} else {
if (ifh.getNbPoints() == 0) {
// If the shape has a single point, it means it is a closepath command
fh.setOpened(ifh.isOpened());
} else {
// Otherwise, the shape has two points. So, we take the last one and add it to the first shape.
final IFreehand fh2 = ShapeFactory.INST.createFreeHandFrom(fh, ifh.getPtAt(ifh.getNbPoints() - 1));
gp.getShapes().set(gp.getShapes().indexOf(fh), fh2);
fh = fh2;
fh.setType(ifh.getType());
}
}
}
}
customshapes.getShapes().setAll(gp.getShapes());
gp.getShapes().clear();
psCustomLatestPt = new Point2D(0d, 0d);
}
use of net.sf.latexdraw.models.interfaces.shape.IGroup in project latexdraw by arnobl.
the class InsertPSTCode method doCmdBody.
@Override
protected void doCmdBody() {
try {
final PSTLatexdrawListener listener = new PSTLatexdrawListener();
final PSTParser parser = new PSTParser(new CommonTokenStream(new PSTLexer(CharStreams.fromString(code))));
parser.addParseListener(listener);
parser.pstCode(new PSTContext());
final IGroup group = ShapeFactory.INST.createGroup();
group.getShapes().addAll(listener.getShapes());
if (!group.isEmpty()) {
final IShape sh = group.size() > 1 ? group : group.getShapeAt(0);
final IPoint 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();
if (statusBar != null) {
statusBar.setText(LangTool.INSTANCE.getBundle().getString("LaTeXDrawFrame.36"));
}
}
} catch (final RecognitionException ex) {
BadaboomCollector.INSTANCE.add(ex);
if (statusBar != null) {
statusBar.setText(LangTool.INSTANCE.getBundle().getString("LaTeXDrawFrame.34"));
}
}
done();
}
use of net.sf.latexdraw.models.interfaces.shape.IGroup in project latexdraw by arnobl.
the class ShapeTextCustomiser method update.
@Override
protected void update(final IGroup shape) {
if (shape.isTypeOf(ITextProp.class)) {
setActivated(true);
final TextPosition tp = shape.getTextPosition();
bButton.setSelected(tp == TextPosition.BOT);
brButton.setSelected(tp == TextPosition.BOT_RIGHT);
blButton.setSelected(tp == TextPosition.BOT_LEFT);
tButton.setSelected(tp == TextPosition.TOP);
trButton.setSelected(tp == TextPosition.TOP_RIGHT);
tlButton.setSelected(tp == TextPosition.TOP_LEFT);
centreButton.setSelected(tp == TextPosition.CENTER);
lButton.setSelected(tp == TextPosition.LEFT);
rButton.setSelected(tp == TextPosition.RIGHT);
// Otherwise it means that this field is currently being edited and must not be updated.
if (!packagesField.isFocused()) {
packagesField.setText(LaTeXGenerator.getPackages());
}
// Updating the log field.
Platform.runLater(() -> shape.getShapes().stream().filter(sh -> sh instanceof IText && canvas.getViewFromShape(sh).orElse(null) instanceof ViewText && ((ViewText) canvas.getViewFromShape(sh).get()).getCompilationData().isPresent()).findFirst().ifPresent(txt -> {
final ViewText view = (ViewText) canvas.getViewFromShape(txt).get();
final Future<?> currentCompil = view.getCurrentCompilation();
if (currentCompil != null) {
try {
currentCompil.get();
} catch (final InterruptedException | ExecutionException ex) {
BadaboomCollector.INSTANCE.add(ex);
}
}
logField.setText(view.getCompilationData().orElse(""));
}));
} else {
setActivated(false);
}
}
use of net.sf.latexdraw.models.interfaces.shape.IGroup in project latexdraw by arnobl.
the class PSTLatexdrawListener method flatLastGroup.
private void flatLastGroup() {
if (shapes.size() > 1) {
final IGroup last = shapes.pop();
shapes.peek().getShapes().addAll(last.getShapes());
last.clear();
}
}
use of net.sf.latexdraw.models.interfaces.shape.IGroup in project latexdraw by arnobl.
the class Border method updatePointsHandlers.
private void updatePointsHandlers() {
final IGroup selection = canvas.getDrawing().getSelection();
if (selection.size() == 1) {
final IShape sh = selection.getShapeAt(0);
updateMvPtHandlers(sh);
updateCtrlPtHandlers(sh);
updateArcHandlers(sh);
}
}
Aggregations