Search in sources :

Example 1 with PreferencesService

use of net.sf.latexdraw.service.PreferencesService in project latexdraw by arnobl.

the class InsertPSTCodeTest method commonCanDoFixture.

@Override
protected void commonCanDoFixture() {
    drawing = ShapeFactory.INST.createDrawing();
    lang = new PreferencesService().getBundle();
    statusBar = new Label();
}
Also used : Label(javafx.scene.control.Label) PreferencesService(net.sf.latexdraw.service.PreferencesService)

Example 2 with PreferencesService

use of net.sf.latexdraw.service.PreferencesService 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 3 with PreferencesService

use of net.sf.latexdraw.service.PreferencesService in project latexdraw by arnobl.

the class TestMagneticGrid method setUp.

@BeforeEach
void setUp() {
    prefW = new SimpleDoubleProperty(100d);
    prefH = new SimpleDoubleProperty(50d);
    zoom = new SimpleDoubleProperty(1d);
    canvas = Mockito.mock(Canvas.class);
    Mockito.when(canvas.prefHeightProperty()).thenReturn(prefH);
    Mockito.when(canvas.prefWidthProperty()).thenReturn(prefW);
    Mockito.when(canvas.getPrefHeight()).thenReturn(50d);
    Mockito.when(canvas.getPrefWidth()).thenReturn(100d);
    Mockito.when(canvas.getPPCDrawing()).thenReturn(50);
    Mockito.when(canvas.zoomProperty()).thenReturn(zoom);
    Mockito.when(canvas.getZoom()).thenAnswer(inv -> zoom.get());
    prefs = new PreferencesService();
    grid = new MagneticGrid(canvas, prefs);
    prefs.gridStyleProperty().set(GridStyle.STANDARD);
}
Also used : SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Canvas(net.sf.latexdraw.view.jfx.Canvas) MagneticGrid(net.sf.latexdraw.view.jfx.MagneticGrid) PreferencesService(net.sf.latexdraw.service.PreferencesService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with PreferencesService

use of net.sf.latexdraw.service.PreferencesService in project latexdraw by arnobl.

the class TestVersionChecker method testCheckVersionNoNewVersion.

@Test
public void testCheckVersionNoNewVersion() throws InterruptedException {
    final StatusBarController controller = mock(StatusBarController.class);
    final FutureTask<Void> future = new FutureTask<>(new VersionChecker(controller, new PreferencesService().getBundle()), null);
    final ExecutorService taskExecutor = Executors.newFixedThreadPool(1);
    taskExecutor.execute(future);
    taskExecutor.shutdown();
    taskExecutor.awaitTermination(5L, TimeUnit.SECONDS);
}
Also used : FutureTask(java.util.concurrent.FutureTask) ExecutorService(java.util.concurrent.ExecutorService) StatusBarController(net.sf.latexdraw.instrument.StatusBarController) PreferencesService(net.sf.latexdraw.service.PreferencesService) Test(org.junit.jupiter.api.Test)

Example 5 with PreferencesService

use of net.sf.latexdraw.service.PreferencesService in project latexdraw by arnobl.

the class TestArcStyle method testGetLabel.

@ParameterizedTest
@EnumSource
void testGetLabel(final ArcStyle style) {
    final ResourceBundle bundle = new PreferencesService().getBundle();
    assertNotNull(style.getLabel(bundle));
    assertFalse(style.getLabel(bundle).isEmpty());
}
Also used : ResourceBundle(java.util.ResourceBundle) PreferencesService(net.sf.latexdraw.service.PreferencesService) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PreferencesService (net.sf.latexdraw.service.PreferencesService)6 ResourceBundle (java.util.ResourceBundle)2 StatusBarController (net.sf.latexdraw.instrument.StatusBarController)2 Canvas (net.sf.latexdraw.view.jfx.Canvas)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 FutureTask (java.util.concurrent.FutureTask)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 Task (javafx.concurrent.Task)1 Parent (javafx.scene.Parent)1 Scene (javafx.scene.Scene)1 Label (javafx.scene.control.Label)1 Image (javafx.scene.image.Image)1 Stage (javafx.stage.Stage)1 WindowEvent (javafx.stage.WindowEvent)1 BuilderFactory (javafx.util.BuilderFactory)1 TabSelector (net.sf.latexdraw.instrument.TabSelector)1 Drawing (net.sf.latexdraw.model.api.shape.Drawing)1