com.sun.javafx.application.PlatformImpl Java Examples

The following examples show how to use com.sun.javafx.application.PlatformImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainWindow.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @param controller
 * 		Window context.
 *
 * @return main window instance.
 */
public static MainWindow get(GuiController controller) {
	if(window == null) {
		MainWindow app = window = new MainWindow(controller);
		PlatformImpl.startup(() -> {
           	Stage stage = new Stage();
           	try {
				Field field = Stage.class.getDeclaredField("primary");
				field.setAccessible(true);
				field.setBoolean(stage, true);
           		app.init();
               	app.start(stage);
               } catch (Exception ex) {
           		throw new RuntimeException(ex);
           	}
			// Disable CSS logger, it complains a lot about non-issues
			try {
				ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class)
						.setLoggerLevel("javafx.css", "OFF");
			} catch (IllegalArgumentException ignored) {
				// Expected: logger may not exist
			}
		});
	}
	return window;
}
 
Example #2
Source File: AppManager.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * 退出程序
 */
private static void quit(){
    // 退出程序
    Platform.runLater(() -> {
        // 退出监听
        PlatformImpl.addListener(new PlatformImpl.FinishListener() {
            @Override
            public void idle(boolean implicitExit) {
                LogUtils.d( "FinishListener idle");
            }
            @Override
            public void exitCalled() {
                LogUtils.d( "FinishListener exitCalled");
                System.exit(0); //kill process
            }
        });
        Platform.exit();
    });
}
 
Example #3
Source File: Launcher.java    From fxlauncher with Apache License 2.0 6 votes vote down vote up
private void startApplication() throws Exception {
    if (app != null) {
        final LauncherParams params = new LauncherParams(getParameters(), superLauncher.getManifest());
        app.getParameters().getNamed().putAll(params.getNamed());
        app.getParameters().getRaw().addAll(params.getRaw());
        app.getParameters().getUnnamed().addAll(params.getUnnamed());

        PlatformImpl.setApplicationName(app.getClass());
        superLauncher.setPhase("Application Init");
        app.start(primaryStage);
    } else {
        // Start any executable jar (i.E. Spring Boot);
        String firstFile = superLauncher.getManifest().files.get(0).file;
        log.info(String.format("No app class defined, starting first file (%s)", firstFile));
        Path cacheDir = superLauncher.getManifest().resolveCacheDir(getParameters().getNamed());
        String command = String.format("java -jar %s/%s", cacheDir.toAbsolutePath(), firstFile);
        log.info(String.format("Execute command '%s'", command));
        Runtime.getRuntime().exec(command);
    }
}
 
Example #4
Source File: DevToolsDebugProxy.java    From Javafx-WebView-Debugger with MIT License 5 votes vote down vote up
@Override
public void releaseDebugger(final boolean shuttingDown, @Nullable Runnable runnable) {
    if (!myIsEnabled) return;

    myIsShuttingDown = shuttingDown;
    if (myDebuggerIsPaused.get()) {
        Runnable action = () -> {
            if (myDebugger != null && myDebugger.isEnabled()) {
                if (myOnDebuggerResumedRunnable == null) {
                    myOnDebuggerResumedRunnable = runnable;
                } else if (runnable != null) {
                    // already being paused, chain them
                    Runnable other = myOnDebuggerResumedRunnable;
                    myOnDebuggerResumedRunnable = () -> {
                        other.run();
                        runnable.run();
                    };
                }
                debuggerSend(String.format("{\"id\":%d,\"method\":\"%s\"}", myDebuggerId++, DebuggerState.RUNNING.method), EMPTY_EVAL_SCRIPT);
            } else if (runnable != null) {
                runnable.run();
            }
        };

        if (Platform.isFxApplicationThread()) {
            action.run();
        } else {
            PlatformImpl.runAndWait(action);
        }
    } else if (runnable != null) {
        runnable.run();
    }
}
 
Example #5
Source File: CreateDataset.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, ReflectionException {
	PlatformImpl.startup(() -> {
	});

	final AffineTransform3D tf = new AffineTransform3D();
	tf.set(
			4.0, 0.0, 0.0, 1.0,
			0.0, 5.0, 0.0, 5.0,
			0.0, 0.0, 40., -1.
	      );
	final N5Reader reader = new N5FSReader(
			"/home/phil/local/tmp/sample_a_padded_20160501.n5");
	final DataSource<UnsignedByteType, VolatileUnsignedByteType> raw = N5Data.openRawAsSource(
			reader,
			"volumes/raw/data/s0",
			tf,
			new SharedQueue(1, 20),
			1,
			"NAME"
	                                                                                            );


	final CreateDataset cd = new CreateDataset(raw);

	Platform.runLater(() -> {
		final Button b = new Button("BUTTON");
		b.setOnAction(e -> LOG.info( "Got new dataset meta: {}", cd.showDialog()));
		final Scene scene = new Scene(b);
		final Stage stage = new Stage();
		stage.setScene(scene);
		stage.show();
	});
}
 
Example #6
Source File: MatchSelectionExample.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
	final List<String> filenames = Files.list(Paths.get(System.getProperty("user.home"))).map(Path::toAbsolutePath).map(Path::toString).collect(Collectors.toList());
	Collections.sort(filenames);
	PlatformImpl.startup(() -> {});
	Platform.setImplicitExit(true);
	Platform.runLater(() -> {

		final MenuButton button = new MenuButton("Select!");
		final DirectoryChooser chooser = new DirectoryChooser();
		final MenuItem chooserButton = new MenuItem("Browse");
		chooserButton.setOnAction(e -> chooser.showDialog(null));

		button.getItems().setAll(
				chooserButton,
				MatchSelectionExample.menu("Recent...", System.out::println, filenames),
				MatchSelectionExample.menu("Favorites...", System.out::println, filenames));


		final Stage stage = new Stage();
		final Scene scene = new Scene(button);
		stage.setScene(scene);
		stage.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
			if (KeyCode.ESCAPE.equals(e.getCode())) {
				if (!e.isConsumed())
					stage.close();
				e.consume();
			}
		});
		stage.show();
	});
}
 
Example #7
Source File: Main.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void runLater(Runnable runnable) {
	PlatformImpl.runLater(new Runnable() {
		@Override
		public void run() {
			try {
				runnable.run();
			} catch (Throwable e){
				getPluginProxy().log(e);
			}
		}
	});
}
 
Example #8
Source File: JavaFxThreadInvoker.java    From chat-socket with MIT License 5 votes vote down vote up
@Override
public void invokeLater(Runnable runnable) {
    if (PlatformImpl.isFxApplicationThread()) {
        executeAsync(() -> invokeLater(runnable));
    } else {
        Platform.runLater(runnable);
    }
}
 
Example #9
Source File: LoginStageTest.java    From oim-fx with MIT License 4 votes vote down vote up
/**
 * @param args
 *            the command line arguments
 */
public static void main(String[] args) {
	launch(args);
	PlatformImpl.setTaskbarApplication(false);
}
 
Example #10
Source File: CatmaidJsonLoader.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
		PlatformImpl.startup(() -> {});
		final Path path = Paths.get(System.getProperty("user.home"), "Downloads", "catmaid-meshes", "Block3.json");
		final TriangleMesh mesh = new CatmaidJsonLoader().loadMesh(path);
		final double[] min = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY};
		final double[] max = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY};
		for (int i = 0; i < mesh.getPoints().size(); i += 3) {
			for (int d = 0; d < 3; ++d) {
				min[d] = Math.min(min[d], mesh.getPoints().get(i + d));
				max[d] = Math.max(max[d], mesh.getPoints().get(i + d));
			}
		}
		System.out.print(Arrays.toString(min) +" " + Arrays.toString(max));
		final Interval interval = Intervals.smallestContainingInterval(new FinalRealInterval(min, max));
		final MeshView mv = new MeshView(mesh);
		mv.setMaterial(Meshes.painteraPhongMaterial(Color.WHITE));
		mv.setDrawMode(DrawMode.FILL);
		mv.setCullFace(CullFace.BACK);
		final Viewer3DFX viewer = new Viewer3DFX(800, 600);
		viewer.meshesEnabledProperty().set(true);
		mv.setOpacity(1.0);
		viewer.setInitialTransformToInterval(interval);
		final MeshView mv2 = new MeshView(mesh);
		mv.setMaterial(Meshes.painteraPhongMaterial());
		mv.setDrawMode(DrawMode.FILL);
		mv.setCullFace(CullFace.BACK);
		mv2.setTranslateX(100);
		viewer.meshesGroup().getChildren().addAll(mv, mv2);
		Platform.setImplicitExit(true);
		Platform.runLater(() -> {
			final Scene scene = new Scene(viewer);
			final Stage stage = new Stage();
			stage.setScene(scene);
			stage.setWidth(800);
			stage.setHeight(600);
			stage.show();
		});
//		final String mesh = "<IndexedTriangleSet  index='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35'><Coordinate point='440474 99212 136120 440474 119212 136120 460474 99212 136120 460474 99212 136120 440474 119212 136120 460474 119212 136120 440474 99212 136120 460474 99212 136120 460474 99212 156120 440474 99212 136120 460474 99212 156120 440474 99212 156120 440474 119212 136120 440474 119212 156120 460474 119212 156120 440474 119212 136120 460474 119212 156120 460474 119212 136120 440474 99212 156120 460474 119212 156120 440474 119212 156120 440474 99212 156120 460474 99212 156120 460474 119212 156120 440474 99212 136120 440474 119212 156120 440474 119212 136120 440474 99212 136120 440474 99212 156120 440474 119212 156120 460474 99212 136120 460474 119212 136120 460474 99212 156120 460474 119212 136120 460474 119212 156120 460474 99212 156120'/></IndexedTriangleSet>";
//		final Document doc = Jsoup.parse(mesh);
//		System.out.println(doc);
//		System.out.println(doc.select("IndexedTriangleSet").attr("index"));
	}
 
Example #11
Source File: ObjLoader.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
		PlatformImpl.startup(() -> {});
		// https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html
//		final String objFile = "al.obj";
//		final String objFile = "diamond.obj";
		final String objFile = "alfa147.obj";
		final Path path = Paths.get(System.getProperty("user.home"), "Downloads", objFile);
		final TriangleMesh mesh = new ObjLoader().loadMesh(path);
		final double[] min = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY};
		final double[] max = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY};
		for (int i = 0; i < mesh.getPoints().size(); i += 3) {
			for (int d = 0; d < 3; ++d) {
				min[d] = Math.min(min[d], mesh.getPoints().get(i + d));
				max[d] = Math.max(max[d], mesh.getPoints().get(i + d));
			}
		}
		final Interval interval = Intervals.smallestContainingInterval(new FinalRealInterval(min, max));
		final MeshView mv = new MeshView(mesh);
		mv.setMaterial(Meshes.painteraPhongMaterial(Color.WHITE));
		mv.setDrawMode(DrawMode.FILL);
		mv.setCullFace(CullFace.BACK);
		final Viewer3DFX viewer = new Viewer3DFX(800, 600);
		viewer.meshesEnabledProperty().set(true);
		mv.setOpacity(1.0);
		viewer.setInitialTransformToInterval(interval);
		final MeshView mv2 = new MeshView(mesh);
		mv.setMaterial(Meshes.painteraPhongMaterial());
		mv.setDrawMode(DrawMode.FILL);
		mv.setCullFace(CullFace.BACK);
		mv2.setTranslateX(100);
		viewer.meshesGroup().getChildren().addAll(mv, mv2);
//		final double factor = 1;
//		final double w = 1*factor, h = 2*factor, d = 3*factor;
//		final Box box = new Box(w, h, d);
//		box.setCullFace(CullFace.NONE);
//		box.setOpacity(1.0);
//		box.setMaterial(Meshes.painteraPhongMaterial(Color.RED));
//		viewer.meshesGroup().getChildren().add(box);
		Platform.setImplicitExit(true);
		Platform.runLater(() -> {
			final Scene scene = new Scene(viewer);
			final Stage stage = new Stage();
			stage.setScene(scene);
			stage.setWidth(800);
			stage.setHeight(600);
			stage.show();
		});
	}
 
Example #12
Source File: JavaFxViewFactory.java    From chat-socket with MIT License 4 votes vote down vote up
private MainWindow createMainWindowIfNecessary() {
    if (mainWindow == null) {
        PlatformImpl.runAndWait(() -> mainWindow = new MainWindow());
    }
    return mainWindow;
}
 
Example #13
Source File: JavaFxThreadInvoker.java    From chat-socket with MIT License 4 votes vote down vote up
@Override
public void invokeAndWait(Runnable runnable) {
    PlatformImpl.runAndWait(runnable);
}
 
Example #14
Source File: JavaFXCompatibilityWrapper.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Start the JavaFX runtime and run runnable on the JavaFX
 * Application thread.
 * <p>
 * On Java 9, PlatformImpl is no longer available, so we have to use
 * the new Platform.startup() function instead.
 */
static void platformStartup(Runnable runnable) {
	PlatformImpl.startup(runnable);
}
 
Example #15
Source File: MdSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 2 votes vote down vote up
private void createScene() {
        PlatformImpl.startup(() -> {
            Browser browser = new Browser();

            Scene scene = new Scene(browser, 80, 20);
//            scene.getStylesheets().add("equal_sizes.css");

            Stage stage = new Stage();

            stage.setTitle("Hello Java FX");
            stage.setResizable(true);
            stage.setScene(scene);

            webEngine = browser.webEngine;


            // Set up the embedded browser:
//            webEngine = browser.webEngine;
//                webEngine.load("http://heise.de");

            // https://stackoverflow.com/questions/38432698/webview-size-in-javafx-stage
            browser.prefHeightProperty().bind(stage.heightProperty());
            browser.prefWidthProperty().bind(stage.widthProperty());


//                ScrollPane scrollPane = new ScrollPane();
//                scrollPane.setContent(browser);
            webEngine.loadContent("<b>asdf</b>");
//            webEngine.setUserStyleSheetLocation("equal_sizes.css");


//                root.getChildren().addAll(scrollPane);
//                scene.setRoot(root);
//                stage.setScene(scene);


//            root.getChildren().add(browser);
//                children.add(browser);

            jfxPanel.setScene(scene);
        });

        while (webEngine == null) {
            Utils.sleep(25);
        }
    }