Search in sources :

Example 1 with ActivateInactivateInstruments

use of io.github.interacto.jfx.command.ActivateInactivateInstruments in project latexdraw by arnobl.

the class TextSetter method configureBindings.

@Override
protected void configureBindings() {
    final var bindingFragment = shortcutBinder().on(textField).end(() -> canvas.requestFocus());
    final var enterBinder = bindingFragment.with(KeyCode.ENTER);
    // Key Enter to validate the text.
    enterBinder.toProduce(() -> new ModifyShapeProperty<>(ShapeProperties.TEXT, ShapeFactory.INST.createGroup(text), textField.getText())).when(() -> text != null && editing.getCurrentChoice() == EditionChoice.HAND && !textField.getText().isEmpty()).bind();
    // Key Enter to validate the equation of a plot shape.
    enterBinder.toProduce(() -> new ModifyShapeProperty<>(ShapeProperties.PLOT_EQ, ShapeFactory.INST.createGroup(plot), textField.getText())).when(() -> plot != null && editing.getCurrentChoice() == EditionChoice.HAND && checkValidPlotFct()).bind();
    // Key Enter to add a text shape.
    enterBinder.toProduce(() -> {
        text = (Text) editing.createShapeInstance();
        text.setPosition(ShapeFactory.INST.createPoint(position.getX(), position.getY()));
        text.setText(textField.getText());
        return new AddShape(text, drawing);
    }).when(() -> editing.getCurrentChoice() == EditionChoice.TEXT && !textField.getText().isEmpty()).bind();
    // Key Enter to add a plot shape.
    enterBinder.toProduce(() -> {
        plot = (Plot) editing.createShapeInstance();
        plot.setPosition(ShapeFactory.INST.createPoint(position.getX(), position.getY() + textField.getHeight()));
        plot.setPlotEquation(textField.getText());
        return new AddShape(plot, drawing);
    }).when(() -> editing.getCurrentChoice() == EditionChoice.PLOT && checkValidPlotFct()).bind();
    enterBinder.toProduce(() -> new ActivateInactivateInstruments(null, Collections.singletonList(this), false, false)).when(() -> textField.isValidText() && !textField.getText().isEmpty()).bind();
    bindingFragment.toProduce(() -> new ActivateInactivateInstruments(null, Collections.singletonList(this), false, false)).with(KeyCode.ESCAPE).bind();
}
Also used : AddShape(net.sf.latexdraw.command.shape.AddShape) ActivateInactivateInstruments(io.github.interacto.jfx.command.ActivateInactivateInstruments)

Example 2 with ActivateInactivateInstruments

use of io.github.interacto.jfx.command.ActivateInactivateInstruments in project latexdraw by arnobl.

the class EditingSelector method configureBindings.

@Override
protected void configureBindings() {
    final var shapeBaseBinder = toggleButtonBinder().on(getShapeButtons()).end(() -> canvas.requestFocus());
    toggleButtonBinder().toProduce(() -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).on(handB).when(() -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty()).end(() -> canvas.requestFocus()).bind();
    shapeBaseBinder.on(handB).toProduce(i -> new ModifyEditingMode(editing, (EditionChoice) i.getWidget().getUserData())).bind();
    toggleButtonBinder().toProduce(ActivateInactivateInstruments::new).on(handB).first(c -> {
        final boolean noSelection = canvas.getDrawing().getSelection().isEmpty();
        c.setActivateFirst(false);
        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);
        }
    }).end(i -> canvas.requestFocus()).bind();
    shapeBaseBinder.toProduce(ActivateInactivateInstruments::new).first((i, c) -> {
        c.setActivateFirst(false);
        if (i.getWidget() != textB) {
            c.addInstrumentToInactivate(textSetter);
        }
        c.addInstrumentToInactivate(hand);
        c.addInstrumentToInactivate(border);
        c.addInstrumentToInactivate(deleter);
        c.addInstrumentToActivate(pencil);
        c.addInstrumentToActivate(metaShapeCustomiser);
    }).bind();
    buttonBinder().toProduce(ActivateInactivateInstruments::new).on(codeB).first(c -> c.addInstrumentToActivate(codeInserter)).end(() -> canvas.requestFocus()).bind();
}
Also used : Button(javafx.scene.control.Button) EditingService(net.sf.latexdraw.service.EditingService) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) ModifyEditingMode(net.sf.latexdraw.command.ModifyEditingMode) ActivateInactivateInstruments(io.github.interacto.jfx.command.ActivateInactivateInstruments) URL(java.net.URL) Objects(java.util.Objects) FXML(javafx.fxml.FXML) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) ToggleGroup(javafx.scene.control.ToggleGroup) Inject(net.sf.latexdraw.util.Inject) ResourceBundle(java.util.ResourceBundle) ToggleButton(javafx.scene.control.ToggleButton) JfxInstrument(io.github.interacto.jfx.instrument.JfxInstrument) AddShape(net.sf.latexdraw.command.shape.AddShape) NotNull(org.jetbrains.annotations.NotNull) Canvas(net.sf.latexdraw.view.jfx.Canvas) ModifyEditingMode(net.sf.latexdraw.command.ModifyEditingMode) AddShape(net.sf.latexdraw.command.shape.AddShape) ActivateInactivateInstruments(io.github.interacto.jfx.command.ActivateInactivateInstruments)

Aggregations

ActivateInactivateInstruments (io.github.interacto.jfx.command.ActivateInactivateInstruments)2 AddShape (net.sf.latexdraw.command.shape.AddShape)2 JfxInstrument (io.github.interacto.jfx.instrument.JfxInstrument)1 URL (java.net.URL)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 ResourceBundle (java.util.ResourceBundle)1 FXML (javafx.fxml.FXML)1 Initializable (javafx.fxml.Initializable)1 Button (javafx.scene.control.Button)1 ToggleButton (javafx.scene.control.ToggleButton)1 ToggleGroup (javafx.scene.control.ToggleGroup)1 ModifyEditingMode (net.sf.latexdraw.command.ModifyEditingMode)1 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)1 EditingService (net.sf.latexdraw.service.EditingService)1 Inject (net.sf.latexdraw.util.Inject)1 Canvas (net.sf.latexdraw.view.jfx.Canvas)1 NotNull (org.jetbrains.annotations.NotNull)1