Search in sources :

Example 6 with IGroup

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);
}
Also used : IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) Point2D(javafx.geometry.Point2D) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IShape(net.sf.latexdraw.models.interfaces.shape.IShape)

Example 7 with IGroup

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();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) PSTLexer(net.sf.latexdraw.parsers.pst.PSTLexer) PSTLatexdrawListener(net.sf.latexdraw.parsers.pst.PSTLatexdrawListener) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) PSTContext(net.sf.latexdraw.parsers.pst.PSTContext) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) RecognitionException(org.antlr.v4.runtime.RecognitionException) PSTParser(net.sf.latexdraw.parsers.pst.PSTParser)

Example 8 with IGroup

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);
    }
}
Also used : Initializable(javafx.fxml.Initializable) ViewText(net.sf.latexdraw.view.jfx.ViewText) TitledPane(javafx.scene.control.TitledPane) TextPosition(net.sf.latexdraw.models.interfaces.shape.TextPosition) TextArea(javafx.scene.control.TextArea) URL(java.net.URL) ShapeProperties(net.sf.latexdraw.commands.shape.ShapeProperties) IText(net.sf.latexdraw.models.interfaces.shape.IText) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) ModifyLatexProperties(net.sf.latexdraw.commands.ModifyLatexProperties) ITextProp(net.sf.latexdraw.models.interfaces.prop.ITextProp) LaTeXGenerator(net.sf.latexdraw.view.latex.LaTeXGenerator) ExecutionException(java.util.concurrent.ExecutionException) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Future(java.util.concurrent.Future) ResourceBundle(java.util.ResourceBundle) ToggleButton(javafx.scene.control.ToggleButton) LatexProperties(net.sf.latexdraw.commands.LatexProperties) BadaboomCollector(net.sf.latexdraw.badaboom.BadaboomCollector) ViewText(net.sf.latexdraw.view.jfx.ViewText) TextPosition(net.sf.latexdraw.models.interfaces.shape.TextPosition) Future(java.util.concurrent.Future) IText(net.sf.latexdraw.models.interfaces.shape.IText)

Example 9 with IGroup

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();
    }
}
Also used : IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup)

Example 10 with IGroup

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);
    }
}
Also used : IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IShape(net.sf.latexdraw.models.interfaces.shape.IShape)

Aggregations

IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)12 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)7 Test (org.junit.Test)5 URL (java.net.URL)3 ResourceBundle (java.util.ResourceBundle)3 Initializable (javafx.fxml.Initializable)3 ShapeProperties (net.sf.latexdraw.commands.shape.ShapeProperties)3 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 FXCollections (javafx.collections.FXCollections)2 ListChangeListener (javafx.collections.ListChangeListener)2 ObservableList (javafx.collections.ObservableList)2 Point3D (javafx.geometry.Point3D)2 Cursor (javafx.scene.Cursor)2 Node (javafx.scene.Node)2 ModifyShapeProperty (net.sf.latexdraw.commands.shape.ModifyShapeProperty)2