Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.application;
027
028import com.sun.javafx.application.PlatformImpl;
029
030/**
031 * Application platform support class.
032 */
033public final class Platform {
034
035    // To prevent instantiation
036    private Platform() {
037    }
038
039    /**
040     * Run the specified Runnable on the JavaFX Application Thread at some
041     * unspecified
042     * time in the future. This method, which may be called from any thread,
043     * will post the Runnable to an event queue and then return immediately to
044     * the caller. The Runnables are executed in the order they are posted.
045     * A runnable passed into the runLater method will be
046     * executed before any Runnable passed into a subsequent call to runLater.
047     *
048     * @param runnable the Runnable whose run method will be executed on the
049     * JavaFX Application Thread
050     */
051    public static void runLater(Runnable runnable) {
052        PlatformImpl.runLater(runnable);
053    }
054
055    // NOTE: Add the following if we decide to expose it publicly
056//    public static void runAndWait(Runnable runnable) {
057//        PlatformImpl.runAndWait(runnable);
058//    }
059
060    /**
061     * Returns true if the calling thread is the JavaFX Application Thread.
062     * Use this call the ensure that a given task is being executed
063     * (or not being executed) on the JavaFX Application Thread.
064     *
065     * @return true if running on the JavaFX Application Thread
066     */
067    public static boolean isFxApplicationThread() {
068        return PlatformImpl.isFxApplicationThread();
069    }
070
071    /**
072     * Causes the JavaFX application to terminate. If this method is called
073     * after the Application start method is called, then the JavaFX launcher
074     * will call the Application stop method and terminate the JavaFX
075     * application thread. The launcher thread will then shutdown. If there
076     * are no other non-daemon threads that are running, the Java VM will exit.
077     * If this method is called from the Preloader or the Application init
078     * method, then the Application stop method may not be called.
079     *
080     * <p>Note: if the application is embedded in a browser, then this method
081     * may have no effect.
082     */
083    public static void exit() {
084        PlatformImpl.exit();
085    }
086
087    /**
088     * Sets the implicitExit attribute to the specified value. If this
089     * attribute is true, the JavaFX runtime will implicitly shutdown
090     * when the last window is closed; the JavaFX launcher will call the
091     * {@link Application#stop} method and terminate the JavaFX
092     * application thread.
093     * If this attribute is false, the application will continue to
094     * run normally even after the last window is closed, until the
095     * application calls {@link #exit}.
096     * The default value is true.
097     *
098     * @param implicitExit a flag indicating whether or not to implicitly exit
099     * when the last window is closed.
100     * @since 2.2
101     */
102    public static void setImplicitExit(boolean implicitExit) {
103        PlatformImpl.setImplicitExit(implicitExit);
104    }
105
106    /**
107     * Gets the value of the implicitExit attribute.
108     *
109     * @return the implicitExit attribute
110     * @since 2.2
111     */
112    public static boolean isImplicitExit() {
113        return PlatformImpl.isImplicitExit();
114    }
115
116    /**
117     * Queries whether a specific conditional feature is supported
118     * by the platform.
119     * <p>
120     * For example:
121     * <pre>
122     * // Query whether filter effects are supported
123     * if (Platform.isSupported(ConditionalFeature.EFFECT)) {
124     *    // use effects
125     * }
126     * </pre>
127     *
128     * @param feature the conditional feature in question.
129     */
130    public static boolean isSupported(ConditionalFeature feature) {
131        return PlatformImpl.isSupported(feature);
132    }
133}