javafx-ui-common/src/com/sun/javafx/application/PlatformImpl.java

Print this page




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.application;
  27 
  28 import com.sun.javafx.PlatformUtil;
  29 import com.sun.javafx.css.StyleManager;
  30 import com.sun.javafx.runtime.SystemProperties;
  31 


  32 import java.security.AccessControlContext;
  33 import java.util.List;
  34 import java.util.Set;
  35 import java.util.concurrent.CopyOnWriteArraySet;
  36 import java.util.concurrent.CountDownLatch;
  37 import java.util.concurrent.atomic.AtomicBoolean;
  38 import java.util.concurrent.atomic.AtomicInteger;
  39 
  40 import javafx.application.Application;
  41 import javafx.application.ConditionalFeature;
  42 
  43 import com.sun.javafx.tk.TKListener;
  44 import com.sun.javafx.tk.TKStage;
  45 import com.sun.javafx.tk.Toolkit;
  46 import java.security.AccessController;
  47 import java.security.PrivilegedAction;
  48 
  49 public class PlatformImpl {
  50 
  51     private static AtomicBoolean initialized = new AtomicBoolean(false);


  59     private static AtomicInteger pendingRunnables = new AtomicInteger(0);
  60     private static AtomicInteger numWindows = new AtomicInteger(0);
  61     private static volatile boolean firstWindowShown = false;
  62     private static volatile boolean lastWindowClosed = false;
  63     private static AtomicBoolean reallyIdle = new AtomicBoolean(false);
  64     private static Set<FinishListener> finishListeners =
  65             new CopyOnWriteArraySet<FinishListener>();
  66     private final static Object runLaterLock = new Object();
  67     private static Boolean isGraphicsSupported;
  68     private static Boolean isControlsSupported;
  69     private static Boolean isMediaSupported;
  70     private static Boolean isWebSupported;
  71     private static Boolean isSWTSupported;
  72     private static Boolean isSwingSupported;
  73     private static Boolean isFXMLSupported;
  74     private static Boolean hasTwoLevelFocus;
  75     private static Boolean hasVirtualKeyboard;
  76     private static Boolean hasTouch;
  77     private static Boolean hasMultiTouch;
  78     private static Boolean hasPointer;

  79 
  80     /**
  81      * Set a flag indicating whether this application should show up in the
  82      * task bar. The default value is true.
  83      *
  84      * @param taskbarApplication the new value of this attribute
  85      */
  86     public static void setTaskbarApplication(boolean taskbarApplication) {
  87         PlatformImpl.taskbarApplication = taskbarApplication;
  88     }
  89 
  90     /**
  91      * Returns the current value of the taskBarApplication flag.
  92      *
  93      * @return the current state of the flag.
  94      */
  95     public static boolean isTaskbarApplication() {
  96         return taskbarApplication;
  97     }
  98 


 127                     if (s.equalsIgnoreCase("none")) {
 128                         hasVirtualKeyboard = false;
 129                     } else if (s.equalsIgnoreCase("javafx")) {
 130                         hasVirtualKeyboard = true;
 131                     } else if (s.equalsIgnoreCase("native")) {
 132                         hasVirtualKeyboard = true;
 133                     }
 134                 }
 135                 s = System.getProperty("com.sun.javafx.touch");
 136                 if (s != null) {
 137                     hasTouch = Boolean.valueOf(s);
 138                 }
 139                 s = System.getProperty("com.sun.javafx.multiTouch");
 140                 if (s != null) {
 141                     hasMultiTouch = Boolean.valueOf(s);
 142                 }
 143                 s = System.getProperty("com.sun.javafx.pointer");
 144                 if (s != null) {
 145                     hasPointer = Boolean.valueOf(s);
 146                 }




 147                 return null;
 148             }
 149         });
 150 
 151         if (!taskbarApplication) {
 152             AccessController.doPrivileged(new PrivilegedAction<Void>() {
 153                 @Override public Void run() {
 154                     System.setProperty("glass.taskbarApplication", "false");
 155                     return null;
 156                 }
 157             });
 158         }
 159 
 160         // Create Toolkit listener and register it with the Toolkit.
 161         // Call notifyFinishListeners when we get notified.
 162         toolkitListener = new TKListener() {
 163             @Override public void changedTopLevelWindows(List<TKStage> windows) {
 164                 numWindows.set(windows.size());
 165                 checkIdle();
 166             }
 167         };
 168         Toolkit.getToolkit().addTkListener(toolkitListener);
 169 
 170         Toolkit.getToolkit().startup(new Runnable() {
 171             @Override public void run() {
 172                 startupLatch.countDown();
 173                 r.run();
 174             }
 175         });

















 176     }
 177 
 178     private static void waitForStart() {
 179         // If the startup runnable has not yet been called, then wait it.
 180         // Note that we check the count before calling await() to avoid
 181         // the try/catch which is unnecessary after startup.
 182         if (startupLatch.getCount() > 0) {
 183             try {
 184                 startupLatch.await();
 185             } catch (InterruptedException ex) {
 186                 ex.printStackTrace();
 187             }
 188         }
 189     }
 190 
 191     public static boolean isFxApplicationThread() {
 192         return Toolkit.getToolkit().isFxUserThread();
 193     }
 194 
 195     public static void runLater(final Runnable r) {




  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.application;
  27 
  28 import com.sun.javafx.PlatformUtil;
  29 import com.sun.javafx.css.StyleManager;
  30 import com.sun.javafx.runtime.SystemProperties;
  31 
  32 import java.lang.reflect.InvocationTargetException;
  33 import java.lang.reflect.Method;
  34 import java.security.AccessControlContext;
  35 import java.util.List;
  36 import java.util.Set;
  37 import java.util.concurrent.CopyOnWriteArraySet;
  38 import java.util.concurrent.CountDownLatch;
  39 import java.util.concurrent.atomic.AtomicBoolean;
  40 import java.util.concurrent.atomic.AtomicInteger;
  41 
  42 import javafx.application.Application;
  43 import javafx.application.ConditionalFeature;
  44 
  45 import com.sun.javafx.tk.TKListener;
  46 import com.sun.javafx.tk.TKStage;
  47 import com.sun.javafx.tk.Toolkit;
  48 import java.security.AccessController;
  49 import java.security.PrivilegedAction;
  50 
  51 public class PlatformImpl {
  52 
  53     private static AtomicBoolean initialized = new AtomicBoolean(false);


  61     private static AtomicInteger pendingRunnables = new AtomicInteger(0);
  62     private static AtomicInteger numWindows = new AtomicInteger(0);
  63     private static volatile boolean firstWindowShown = false;
  64     private static volatile boolean lastWindowClosed = false;
  65     private static AtomicBoolean reallyIdle = new AtomicBoolean(false);
  66     private static Set<FinishListener> finishListeners =
  67             new CopyOnWriteArraySet<FinishListener>();
  68     private final static Object runLaterLock = new Object();
  69     private static Boolean isGraphicsSupported;
  70     private static Boolean isControlsSupported;
  71     private static Boolean isMediaSupported;
  72     private static Boolean isWebSupported;
  73     private static Boolean isSWTSupported;
  74     private static Boolean isSwingSupported;
  75     private static Boolean isFXMLSupported;
  76     private static Boolean hasTwoLevelFocus;
  77     private static Boolean hasVirtualKeyboard;
  78     private static Boolean hasTouch;
  79     private static Boolean hasMultiTouch;
  80     private static Boolean hasPointer;
  81     private static boolean isThreadMerged = false;
  82 
  83     /**
  84      * Set a flag indicating whether this application should show up in the
  85      * task bar. The default value is true.
  86      *
  87      * @param taskbarApplication the new value of this attribute
  88      */
  89     public static void setTaskbarApplication(boolean taskbarApplication) {
  90         PlatformImpl.taskbarApplication = taskbarApplication;
  91     }
  92 
  93     /**
  94      * Returns the current value of the taskBarApplication flag.
  95      *
  96      * @return the current state of the flag.
  97      */
  98     public static boolean isTaskbarApplication() {
  99         return taskbarApplication;
 100     }
 101 


 130                     if (s.equalsIgnoreCase("none")) {
 131                         hasVirtualKeyboard = false;
 132                     } else if (s.equalsIgnoreCase("javafx")) {
 133                         hasVirtualKeyboard = true;
 134                     } else if (s.equalsIgnoreCase("native")) {
 135                         hasVirtualKeyboard = true;
 136                     }
 137                 }
 138                 s = System.getProperty("com.sun.javafx.touch");
 139                 if (s != null) {
 140                     hasTouch = Boolean.valueOf(s);
 141                 }
 142                 s = System.getProperty("com.sun.javafx.multiTouch");
 143                 if (s != null) {
 144                     hasMultiTouch = Boolean.valueOf(s);
 145                 }
 146                 s = System.getProperty("com.sun.javafx.pointer");
 147                 if (s != null) {
 148                     hasPointer = Boolean.valueOf(s);
 149                 }
 150                 s = System.getProperty("javafx.embed.singleThread");
 151                 if (s != null) {
 152                     isThreadMerged = Boolean.valueOf(s);
 153                 }
 154                 return null;
 155             }
 156         });
 157 
 158         if (!taskbarApplication) {
 159             AccessController.doPrivileged(new PrivilegedAction<Void>() {
 160                 @Override public Void run() {
 161                     System.setProperty("glass.taskbarApplication", "false");
 162                     return null;
 163                 }
 164             });
 165         }
 166 
 167         // Create Toolkit listener and register it with the Toolkit.
 168         // Call notifyFinishListeners when we get notified.
 169         toolkitListener = new TKListener() {
 170             @Override public void changedTopLevelWindows(List<TKStage> windows) {
 171                 numWindows.set(windows.size());
 172                 checkIdle();
 173             }
 174         };
 175         Toolkit.getToolkit().addTkListener(toolkitListener);
 176 
 177         Toolkit.getToolkit().startup(new Runnable() {
 178             @Override public void run() {
 179                 startupLatch.countDown();
 180                 r.run();
 181             }
 182         });
 183 
 184         //Initialize the thread merging mechanism
 185         if (isThreadMerged) {
 186             //Use reflection in case we are running compact profile
 187             try {
 188                 Class swingFXUtilsClass = Class.forName("javafx.embed.swing.SwingFXUtils");
 189                 Method installFwEventQueue = swingFXUtilsClass.getMethod("installFwEventQueue");
 190 
 191                 waitForStart();
 192                 installFwEventQueue.invoke(null);
 193 
 194             } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
 195                 throw new RuntimeException("Property javafx.embed.singleThread is not supported");
 196             } catch (InvocationTargetException e) {
 197                 throw new RuntimeException(e);
 198             }
 199         }
 200     }
 201 
 202     private static void waitForStart() {
 203         // If the startup runnable has not yet been called, then wait it.
 204         // Note that we check the count before calling await() to avoid
 205         // the try/catch which is unnecessary after startup.
 206         if (startupLatch.getCount() > 0) {
 207             try {
 208                 startupLatch.await();
 209             } catch (InterruptedException ex) {
 210                 ex.printStackTrace();
 211             }
 212         }
 213     }
 214 
 215     public static boolean isFxApplicationThread() {
 216         return Toolkit.getToolkit().isFxUserThread();
 217     }
 218 
 219     public static void runLater(final Runnable r) {