Search in sources :

Example 1 with AddShape

use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.

the class Pencil method bindDnDToDrawFreeHandShape.

/**
 * Binds a DnD interaction to create shape.
 */
private void bindDnDToDrawFreeHandShape() {
    nodeBinder(AddShape.class, new DnD(false, true)).on(canvas).map(i -> {
        final IShape sh = createShapeInstance();
        final IPoint pt = getAdaptedPoint(i.getSrcLocalPoint());
        sh.getPoints().get(0).setPoint(pt.getX(), pt.getY());
        return new AddShape(sh, canvas.getDrawing());
    }).first((c, i) -> Platform.runLater(() -> canvas.requestFocus())).then((c, i) -> {
        final IPoint last = c.getShape().get().getPtAt(-1);
        final IPoint endPt = getAdaptedPoint(i.getEndLocalPt());
        if (!MathUtils.INST.equalsDouble(last.getX(), endPt.getX(), 0.0001) && !MathUtils.INST.equalsDouble(last.getY(), endPt.getY(), 0.0001)) {
            c.setShape(ShapeFactory.INST.createFreeHandFrom((IFreehand) c.getShape().get(), endPt));
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY && currentChoice.get() == EditionChoice.FREE_HAND).strictStart().bind();
}
Also used : ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Point3D(javafx.geometry.Point3D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) MathUtils(net.sf.latexdraw.models.MathUtils) AddShape(net.sf.latexdraw.commands.shape.AddShape) Function(java.util.function.Function) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) InsertPicture(net.sf.latexdraw.commands.shape.InsertPicture) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ObjectProperty(javafx.beans.property.ObjectProperty) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) LangTool(net.sf.latexdraw.util.LangTool) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) MultiClick(org.malai.javafx.interaction.library.MultiClick) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Press(org.malai.javafx.interaction.library.Press) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Collections(java.util.Collections) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) AddShape(net.sf.latexdraw.commands.shape.AddShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IShape(net.sf.latexdraw.models.interfaces.shape.IShape)

Example 2 with AddShape

use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.

the class EditingSelector method configureBindings.

@Override
protected void configureBindings() {
    final ToggleButton[] nodes = button2EditingChoiceMap.keySet().toArray(new ToggleButton[button2EditingChoiceMap.size() + 1]);
    nodes[nodes.length - 1] = handB;
    toggleButtonBinder(AddShape.class).on(handB).map(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(pencil.textSetter.getPosition()), pencil.textSetter.getTextField().getText()), canvas.getDrawing())).when(i -> pencil.textSetter.isActivated() && !pencil.textSetter.getTextField().getText().isEmpty()).bind();
    toggleButtonBinder(ModifyPencilStyle.class).on(nodes).first((c, i) -> {
        c.setEditingChoice(button2EditingChoiceMap.get(i.getWidget()));
        c.setPencil(pencil);
    }).bind();
    toggleButtonBinder(ActivateInactivateInstruments.class).on(nodes).first((c, i) -> {
        final ToggleButton button = i.getWidget();
        c.setActivateFirst(false);
        if (button != textB) {
            c.addInstrumentToInactivate(pencil.textSetter);
        }
        /* Selection of the instruments to activate/deactivate. */
        if (button == handB) {
            final boolean noSelection = canvas.getDrawing().getSelection().isEmpty();
            c.addInstrumentToActivate(hand);
            if (!noSelection) {
                c.addInstrumentToActivate(deleter);
            }
            c.addInstrumentToInactivate(pencil);
            if (noSelection) {
                c.addInstrumentToInactivate(metaShapeCustomiser);
                c.addInstrumentToInactivate(border);
            } else {
                c.addInstrumentToActivate(metaShapeCustomiser);
                c.addInstrumentToActivate(border);
            }
        } else {
            c.addInstrumentToInactivate(hand);
            c.addInstrumentToInactivate(border);
            c.addInstrumentToInactivate(deleter);
            c.addInstrumentToActivate(pencil);
            c.addInstrumentToActivate(metaShapeCustomiser);
        }
    }).bind();
    buttonBinder(ActivateInactivateInstruments.class).on(codeB).first(cmd -> cmd.addInstrumentToActivate(codeInserter)).bind();
}
Also used : Button(javafx.scene.control.Button) Initializable(javafx.fxml.Initializable) Command(org.malai.command.Command) ActivateInactivateInstruments(org.malai.javafx.command.ActivateInactivateInstruments) ModifyPencilStyle(net.sf.latexdraw.commands.ModifyPencilStyle) URL(java.net.URL) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) HashMap(java.util.HashMap) JfxInstrument(org.malai.javafx.instrument.JfxInstrument) AddShape(net.sf.latexdraw.commands.shape.AddShape) FXML(javafx.fxml.FXML) ToggleGroup(javafx.scene.control.ToggleGroup) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) ToggleButton(javafx.scene.control.ToggleButton) Map(java.util.Map) Canvas(net.sf.latexdraw.view.jfx.Canvas) ToggleButton(javafx.scene.control.ToggleButton) AddShape(net.sf.latexdraw.commands.shape.AddShape) ModifyPencilStyle(net.sf.latexdraw.commands.ModifyPencilStyle) ActivateInactivateInstruments(org.malai.javafx.command.ActivateInactivateInstruments)

Example 3 with AddShape

use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.

the class TextSetter method configureBindings.

@Override
protected void configureBindings() {
    // Key Enter to validate the text.
    keyNodeBinder(ModifyShapeProperty.class).on(textField).with(KeyCode.ENTER).map(i -> new ModifyShapeProperty(ShapeProperties.TEXT, ShapeFactory.INST.createGroup(text), textField.getText())).when(i -> !pencil.isActivated() && text != null && !textField.getText().isEmpty()).bind();
    // Key Enter to validate the equation of a plot shape.
    keyNodeBinder(ModifyShapeProperty.class).on(textField).with(KeyCode.ENTER).map(i -> new ModifyShapeProperty(ShapeProperties.PLOT_EQ, ShapeFactory.INST.createGroup(plot), textField.getText())).when(i -> !pencil.isActivated() && plot != null && checkValidPlotFct()).bind();
    // Key Enter to add a text shape.
    keyNodeBinder(AddShape.class).on(textField).with(KeyCode.ENTER).map(i -> {
        text = (IText) pencil.createShapeInstance();
        text.setPosition(ShapeFactory.INST.createPoint(position.getX(), position.getY()));
        text.setText(textField.getText());
        return new AddShape(text, canvas.getDrawing());
    }).when(i -> pencil.isActivated() && pencil.getCurrentChoice() == EditionChoice.TEXT && !textField.getText().isEmpty()).bind();
    // Key Enter to add a plot shape.
    keyNodeBinder(AddShape.class).on(textField).with(KeyCode.ENTER).map(i -> {
        plot = (IPlot) pencil.createShapeInstance();
        plot.setPosition(ShapeFactory.INST.createPoint(position.getX(), position.getY() + textField.getHeight()));
        plot.setPlotEquation(textField.getText());
        return new AddShape(plot, canvas.getDrawing());
    }).when(i -> pencil.isActivated() && pencil.getCurrentChoice() == EditionChoice.PLOT && checkValidPlotFct()).bind();
    keyNodeBinder(ActivateInactivateInstruments.class).on(textField).map(i -> new ActivateInactivateInstruments(null, Collections.singletonList(this), false, false)).with(KeyCode.ENTER).when(i -> textField.isValidText() && !textField.getText().isEmpty()).bind();
    keyNodeBinder(ActivateInactivateInstruments.class).on(textField).map(i -> new ActivateInactivateInstruments(null, Collections.singletonList(this), false, false)).with(KeyCode.ESCAPE).bind();
}
Also used : KeyCode(javafx.scene.input.KeyCode) Initializable(javafx.fxml.Initializable) Command(org.malai.command.Command) ActivateInactivateInstruments(org.malai.javafx.command.ActivateInactivateInstruments) URL(java.net.URL) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) LangTool(net.sf.latexdraw.util.LangTool) ShapeProperties(net.sf.latexdraw.commands.shape.ShapeProperties) IText(net.sf.latexdraw.models.interfaces.shape.IText) PSFunctionParser(net.sf.latexdraw.parsers.ps.PSFunctionParser) ModifyShapeProperty(net.sf.latexdraw.commands.shape.ModifyShapeProperty) AddShape(net.sf.latexdraw.commands.shape.AddShape) TextAreaAutoSize(net.sf.latexdraw.ui.TextAreaAutoSize) Platform(javafx.application.Platform) Tuple(net.sf.latexdraw.util.Tuple) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Collections(java.util.Collections) AddShape(net.sf.latexdraw.commands.shape.AddShape) ModifyShapeProperty(net.sf.latexdraw.commands.shape.ModifyShapeProperty) ActivateInactivateInstruments(org.malai.javafx.command.ActivateInactivateInstruments)

Example 4 with AddShape

use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.

the class Pencil method bindMultiClic2AddShape.

/**
 * Binds a multi-click interaction to creates multi-point shapes.
 */
private void bindMultiClic2AddShape() {
    final Function<MultiClick, AddShape> creation = i -> new AddShape(setInitialPtsShape(createShapeInstance(), i.getPoints().get(0)), canvas.getDrawing());
    // Binding for polygons
    nodeBinder(AddShape.class, new MultiClick(3)).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolygonFrom((IPolygon) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.POLYGON).and(activatedProp));
    // Binding for polyline
    nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolylineFrom((IPolyline) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.LINES).and(activatedProp));
    // Binding for bézier curves
    nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createBezierCurveFrom((IBezierCurve) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        ((IControlPointShape) c.getShape().get()).balance();
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.BEZIER_CURVE).and(activatedProp));
}
Also used : MultiClick(org.malai.javafx.interaction.library.MultiClick) ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Point3D(javafx.geometry.Point3D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) MathUtils(net.sf.latexdraw.models.MathUtils) AddShape(net.sf.latexdraw.commands.shape.AddShape) Function(java.util.function.Function) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) InsertPicture(net.sf.latexdraw.commands.shape.InsertPicture) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ObjectProperty(javafx.beans.property.ObjectProperty) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) LangTool(net.sf.latexdraw.util.LangTool) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) MultiClick(org.malai.javafx.interaction.library.MultiClick) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Press(org.malai.javafx.interaction.library.Press) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Collections(java.util.Collections) AddShape(net.sf.latexdraw.commands.shape.AddShape) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon)

Example 5 with AddShape

use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.

the class Pencil method bindPressToAddShape.

/**
 * Binds a press interaction to add a shape.
 */
private void bindPressToAddShape() {
    // Add axes, grids, or dots
    nodeBinder(AddShape.class, new Press()).on(canvas).map(i -> {
        final IPositionShape sh = (IPositionShape) createShapeInstance();
        sh.setPosition(getAdaptedPoint(i.getSrcLocalPoint()));
        return new AddShape(sh, canvas.getDrawing());
    }).when(i -> i.getButton() == MouseButton.PRIMARY).bind().activationProperty().bind(activatedProp.and(currentChoice.isEqualTo(EditionChoice.GRID).or(currentChoice.isEqualTo(EditionChoice.DOT)).or(currentChoice.isEqualTo(EditionChoice.AXES))));
    // When a user starts to type a text using the text setter and then he clicks somewhere else in the canvas,
    // the text typed must be added (if possible to the canvas) before starting typing a new text.
    nodeBinder(AddShape.class, new Press()).on(canvas).map(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).when(i -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty()).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.TEXT).and(activatedProp));
}
Also used : ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Point3D(javafx.geometry.Point3D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) MathUtils(net.sf.latexdraw.models.MathUtils) AddShape(net.sf.latexdraw.commands.shape.AddShape) Function(java.util.function.Function) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) InsertPicture(net.sf.latexdraw.commands.shape.InsertPicture) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ObjectProperty(javafx.beans.property.ObjectProperty) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) LangTool(net.sf.latexdraw.util.LangTool) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) MultiClick(org.malai.javafx.interaction.library.MultiClick) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Press(org.malai.javafx.interaction.library.Press) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Collections(java.util.Collections) AddShape(net.sf.latexdraw.commands.shape.AddShape) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Press(org.malai.javafx.interaction.library.Press)

Aggregations

AddShape (net.sf.latexdraw.commands.shape.AddShape)6 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)6 Inject (net.sf.latexdraw.util.Inject)6 Collections (java.util.Collections)5 Platform (javafx.application.Platform)5 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)5 LangTool (net.sf.latexdraw.util.LangTool)5 Arrays (java.util.Arrays)4 Function (java.util.function.Function)4 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)4 Point3D (javafx.geometry.Point3D)4 Cursor (javafx.scene.Cursor)4 MouseButton (javafx.scene.input.MouseButton)4 FileChooser (javafx.stage.FileChooser)4 InitTextSetter (net.sf.latexdraw.commands.shape.InitTextSetter)4 InsertPicture (net.sf.latexdraw.commands.shape.InsertPicture)4 MathUtils (net.sf.latexdraw.models.MathUtils)4 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)4 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)4