Search in sources :

Example 6 with Drawing

use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.

the class LaTeXDraw method start.

@Override
public void start(final Stage stage) {
    final Task<Void> task = new Task<>() {

        @Override
        protected Void call() throws IOException {
            updateProgress(0.1, 1d);
            final CountDownLatch latch = new CountDownLatch(1);
            Platform.runLater(() -> {
                mainStage = new Stage(StageStyle.DECORATED);
                mainStage.setIconified(true);
                injector = new LatexdrawInjector(LaTeXDraw.this);
                latch.countDown();
            });
            // We need to wait for the javafx thread to perform its job before loading the UI (because of the injector).
            try {
                latch.await();
            } catch (final InterruptedException ex) {
                Thread.currentThread().interrupt();
                throw new RuntimeException(ex);
            }
            final PreferencesService prefs = injector.getInstance(PreferencesService.class);
            prefs.readPreferences();
            final Parent root = // NON-NLS
            FXMLLoader.load(// NON-NLS
            getClass().getResource("/fxml/UI.fxml"), // NON-NLS
            prefs.getBundle(), injector.getInstance(BuilderFactory.class), cl -> injector.getInstance(cl));
            updateProgress(0.6, 1d);
            final Scene scene = new Scene(root);
            updateProgress(0.7, 1d);
            // NON-NLS
            scene.getStylesheets().add("css/style.css");
            // Binding the title of the app on the title of the drawing.
            mainStage.titleProperty().bind(injector.getInstance(Drawing.class).titleProperty().concat(" -- " + LABEL_APP));
            updateProgress(0.8, 1d);
            Platform.runLater(() -> {
                mainStage.setScene(scene);
                updateProgress(0.9, 1d);
                setModified(false);
                mainStage.show();
                registerScene(scene);
                // Preventing the stage to close automatically.
                mainStage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, WindowEvent::consume);
                // NON-NLS
                mainStage.getIcons().add(new Image("/res/LaTeXDrawIcon.png"));
                mainStage.centerOnScreen();
                injector.getInstance(TabSelector.class).centreViewport();
                injector.getInstance(Canvas.class).requestFocus();
                // Checking a new version if required.
                if (VersionChecker.WITH_UPDATE && injector.getInstance(PreferencesSetter.class).isVersionCheckEnable()) {
                    new Thread(new VersionChecker(injector.getInstance(StatusBarController.class), prefs.getBundle())).start();
                }
                setModified(false);
            });
            return null;
        }
    };
    task.setOnFailed(BadaboomCollector.INSTANCE);
    showSplash(stage, task);
    new Thread(task).start();
}
Also used : Drawing(net.sf.latexdraw.model.api.shape.Drawing) Task(javafx.concurrent.Task) Parent(javafx.scene.Parent) TabSelector(net.sf.latexdraw.instrument.TabSelector) Canvas(net.sf.latexdraw.view.jfx.Canvas) StatusBarController(net.sf.latexdraw.instrument.StatusBarController) CountDownLatch(java.util.concurrent.CountDownLatch) Scene(javafx.scene.Scene) Image(javafx.scene.image.Image) BuilderFactory(javafx.util.BuilderFactory) PreferencesService(net.sf.latexdraw.service.PreferencesService) VersionChecker(net.sf.latexdraw.util.VersionChecker) WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage)

Example 7 with Drawing

use of net.sf.latexdraw.model.api.shape.Drawing in project latexdraw by arnobl.

the class TestMetaShapeCustomiser method testActivatedOnSelectionRemoval.

@Test
public void testActivatedOnSelectionRemoval() {
    Mockito.when(injector.getInstance(Hand.class).isActivated()).thenReturn(true);
    meta.initialize(null, null);
    final Drawing dr = injector.getInstance(Drawing.class);
    dr.getSelection().addShape(ShapeFactory.INST.createRectangle());
    dr.getSelection().removeShape(0);
    assertFalse(meta.isActivated());
}
Also used : Drawing(net.sf.latexdraw.model.api.shape.Drawing) Test(org.junit.Test)

Aggregations

Drawing (net.sf.latexdraw.model.api.shape.Drawing)7 Test (org.junit.Test)3 Objects (java.util.Objects)2 ResourceBundle (java.util.ResourceBundle)2 Label (javafx.scene.control.Label)2 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)2 Inject (net.sf.latexdraw.util.Inject)2 NotNull (org.jetbrains.annotations.NotNull)2 Command (io.github.interacto.command.Command)1 JfxInstrument (io.github.interacto.jfx.instrument.JfxInstrument)1 DnD (io.github.interacto.jfx.interaction.library.DnD)1 JfxUI (io.github.interacto.jfx.ui.JfxUI)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 HostServices (javafx.application.HostServices)1