Search in sources :

Example 1 with ViewText

use of net.sf.latexdraw.view.jfx.ViewText in project latexdraw by arnobl.

the class TestCanvasSelection method testEditTextDoesNotCreateANewOne.

@Test
public void testEditTextDoesNotCreateANewOne() {
    when(pencil.getCurrentChoice()).thenReturn(EditionChoice.TEXT);
    when(pencil.createShapeInstance()).thenReturn(ShapeFactory.INST.createText());
    new CompositeGUIVoidCommand(addText, waitFXEvents).execute();
    final ViewText v = (ViewText) canvas.getViews().getChildren().get(0);
    doubleClickOn(v).sleep(10).write("@bar bar").sleep(10).type(KeyCode.ENTER).sleep(SLEEP);
    assertEquals(1, canvas.getDrawing().size());
    assertEquals(1, canvas.getViews().getChildren().size());
}
Also used : ViewText(net.sf.latexdraw.view.jfx.ViewText) Test(org.junit.Test)

Example 2 with ViewText

use of net.sf.latexdraw.view.jfx.ViewText 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 3 with ViewText

use of net.sf.latexdraw.view.jfx.ViewText in project latexdraw by arnobl.

the class Hand method dbleClickToInitTextSetter.

/**
 * Double click to initialise the text setter to edit plot and text shapes.
 */
private void dbleClickToInitTextSetter() {
    // For text shapes.
    nodeBinder(InitTextSetter.class, new DoubleClick()).on(canvas.getViews().getChildren()).map(i -> {
        final IText text = ((ViewText) i.getClickData().getSrcObject().get().getParent()).getModel();
        return new InitTextSetter(textSetter, textSetter, null, ShapeFactory.INST.createPoint(text.getPosition().getX() * canvas.getZoom(), text.getPosition().getY() * canvas.getZoom()), text, null);
    }).when(i -> i.getClickData().getSrcObject().isPresent() && i.getClickData().getSrcObject().get().getParent() instanceof ViewText).strictStart().bind();
    // For plot shapes.
    nodeBinder(InitTextSetter.class, new DoubleClick()).on(canvas.getViews().getChildren()).map(i -> {
        final IPlot plot = getViewShape(i.getClickData().getSrcObject()).map(view -> ((ViewPlot) view).getModel()).get();
        return new InitTextSetter(textSetter, textSetter, null, ShapeFactory.INST.createPoint(plot.getPosition().getX() * canvas.getZoom(), plot.getPosition().getY() * canvas.getZoom()), null, plot);
    }).when(i -> i.getClickData().getSrcObject().isPresent() && i.getClickData().getSrcObject().get().getParent() != null && getViewShape(i.getClickData().getSrcObject()).orElse(null) instanceof ViewPlot).strictStart().bind();
}
Also used : MouseButton(javafx.scene.input.MouseButton) ViewText(net.sf.latexdraw.view.jfx.ViewText) Command(org.malai.command.Command) BoundingBox(javafx.geometry.BoundingBox) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) SelectShapes(net.sf.latexdraw.commands.shape.SelectShapes) JfXWidgetBinding(org.malai.javafx.binding.JfXWidgetBinding) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) ArrayList(java.util.ArrayList) ViewShape(net.sf.latexdraw.view.jfx.ViewShape) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) ListChangeListener(javafx.collections.ListChangeListener) Transform(javafx.scene.transform.Transform) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) Canvas(net.sf.latexdraw.view.jfx.Canvas) DnD(org.malai.javafx.interaction.library.DnD) KeyCode(javafx.scene.input.KeyCode) Node(javafx.scene.Node) LSystem(net.sf.latexdraw.util.LSystem) IText(net.sf.latexdraw.models.interfaces.shape.IText) Rectangle(javafx.scene.shape.Rectangle) UpdateToGrid(net.sf.latexdraw.commands.shape.UpdateToGrid) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) TranslateShapes(net.sf.latexdraw.commands.shape.TranslateShapes) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) List(java.util.List) Press(org.malai.javafx.interaction.library.Press) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) Optional(java.util.Optional) DoubleClick(org.malai.javafx.interaction.library.DoubleClick) Collections(java.util.Collections) Shape(javafx.scene.shape.Shape) Bounds(javafx.geometry.Bounds) IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) ViewText(net.sf.latexdraw.view.jfx.ViewText) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) DoubleClick(org.malai.javafx.interaction.library.DoubleClick) ViewPlot(net.sf.latexdraw.view.jfx.ViewPlot) IText(net.sf.latexdraw.models.interfaces.shape.IText)

Aggregations

ViewText (net.sf.latexdraw.view.jfx.ViewText)3 Platform (javafx.application.Platform)2 IText (net.sf.latexdraw.models.interfaces.shape.IText)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 ResourceBundle (java.util.ResourceBundle)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 ListChangeListener (javafx.collections.ListChangeListener)1 FXML (javafx.fxml.FXML)1 Initializable (javafx.fxml.Initializable)1 BoundingBox (javafx.geometry.BoundingBox)1 Bounds (javafx.geometry.Bounds)1 Cursor (javafx.scene.Cursor)1 Node (javafx.scene.Node)1 TextArea (javafx.scene.control.TextArea)1 TitledPane (javafx.scene.control.TitledPane)1