apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/AppPlatform.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


  79         
  80         assert applicationDataFolder != null;
  81         
  82         return applicationDataFolder;
  83     }
  84     
  85     
  86     public static synchronized String getUserLibraryFolder() {
  87         
  88         if (userLibraryFolder == null) {
  89             userLibraryFolder = getApplicationDataFolder() + "/Library"; //NOI18N
  90         }
  91         
  92         return userLibraryFolder;
  93     }
  94     
  95     public static boolean requestStart(
  96             AppNotificationHandler notificationHandler, Application.Parameters parameters)  
  97     throws IOException {
  98         if (IS_MAC) {
  99             return requestStartMac(notificationHandler, parameters);
 100         } else {

 101             if (EditorPlatform.isAssertionEnabled()) {
 102                 // Development mode : we do not delegate to the existing instance
 103                 notificationHandler.handleLaunch(parameters.getUnnamed());
 104                 return true;
 105             } else {
 106                 return requestStartGeneric(notificationHandler, parameters);
 107             }
 108         }
 109     }
 110     
 111     public interface AppNotificationHandler {
 112         public void handleLaunch(List<String> files);
 113         public void handleOpenFilesAction(List<String> files);
 114         public void handleMessageBoxFailure(Exception x);
 115         public void handleQuitAction();
 116     }
 117     
 118     
 119     /*
 120      * Private (requestStartGeneric)
 121      */
 122     
 123     private static synchronized boolean requestStartGeneric(
 124             AppNotificationHandler notificationHandler, Application.Parameters parameters) 
 125     throws IOException {
 126         assert notificationHandler != null;
 127         assert parameters != null;
 128         assert messageBox == null;
 129         


 176             this.eventHandler = eventHandler;
 177         }
 178         
 179         /*
 180          * MessageBox.Delegate
 181          */
 182         
 183         @Override
 184         public void messageBoxDidGetMessage(MessageBoxMessage message) {
 185             assert Platform.isFxApplicationThread() == false;
 186             Platform.runLater(() -> eventHandler.handleOpenFilesAction(message));
 187         }
 188 
 189         @Override
 190         public void messageBoxDidCatchException(Exception x) {
 191             assert Platform.isFxApplicationThread() == false;
 192             Platform.runLater(() -> eventHandler.handleMessageBoxFailure(x));
 193         }
 194         
 195     } 
 196     
 197     
 198     
 199     /*
 200      * Private (requestStartMac)
 201      */
 202     
 203     private static boolean requestStartMac(
 204             AppNotificationHandler notificationHandler, Application.Parameters parameters) {
 205         
 206         Platform.setImplicitExit(false);
 207         notificationHandler.handleLaunch(Collections.emptyList());
 208         Deprecation.setPlatformEventHandler(new MacEventHandler(notificationHandler,
 209                 Deprecation.getPlatformEventHandler()));
 210         
 211         return true;
 212     }
 213     
 214     private static class MacEventHandler extends com.sun.glass.ui.Application.EventHandler {
 215         
 216         private final AppNotificationHandler notificationHandler;
 217         private final com.sun.glass.ui.Application.EventHandler oldEventHandler;
 218         private int openFilesCount;
 219         
 220         public MacEventHandler(AppNotificationHandler notificationHandler,
 221                 com.sun.glass.ui.Application.EventHandler oldEventHandler) {
 222             assert notificationHandler != null;
 223             this.notificationHandler = notificationHandler;
 224             this.oldEventHandler = oldEventHandler;
 225         }
 226         
 227         /*
 228          * com.sun.glass.ui.Application.AppNotificationHandler
 229          */
 230         @Override
 231         public void handleDidFinishLaunchingAction(com.sun.glass.ui.Application app, long time) {
 232             if (oldEventHandler != null) {
 233                 oldEventHandler.handleDidFinishLaunchingAction(app, time);
 234             }
 235         }
 236 
 237         @Override
 238         public void handleDidBecomeActiveAction(com.sun.glass.ui.Application app, long time) {
 239             if (oldEventHandler != null) {
 240                 oldEventHandler.handleDidBecomeActiveAction(app, time);
 241             }
 242         }
 243 
 244         @Override
 245         public void handleOpenFilesAction(com.sun.glass.ui.Application app, long time, final String[] files) {
 246             if (oldEventHandler != null) {
 247                 oldEventHandler.handleOpenFilesAction(app, time, files);
 248             }
 249             
 250             /*
 251              * When SB is started from NB or test environment on Mac OS, this 
 252              * method is called a first time with dummy parameter like this:
 253              * files[0] == "com.oracle.javafx.scenebuilder.app.SceneBuilderApp". //NOI18N
 254              * We ignore this call here.
 255              * 
 256              * With Eclipse on Mac, files[0] == System.getProperty("java.class.path") (!) //NOI18N
 257              */
 258             final boolean openRejected;
 259             if (startingFromTestBed) {
 260                 openRejected = true;
 261             } else if (openFilesCount++ == 0) {
 262                 openRejected = (files.length == 1) 
 263                         && ( files[0].equals(SceneBuilderApp.class.getName()) || //NOI18N
 264                              files[0].equals(System.getProperty("java.class.path"))); //NOI18N
 265             } else {
 266                 openRejected = false;
 267             }
 268             
 269             if (openRejected == false) {
 270                 notificationHandler.handleOpenFilesAction(Arrays.asList(files));
 271             }
 272         }
 273 
 274         @Override
 275         public void handleQuitAction(com.sun.glass.ui.Application app, long time) {
 276             if (oldEventHandler != null) {
 277                 oldEventHandler.handleQuitAction(app, time);
 278             }
 279             notificationHandler.handleQuitAction();
 280         }  
 281     } 
 282     
 283     
 284     /*
 285      * Some code to help starting Scene Builder application from SQE java code.
 286      * This is relevant on Mac only.
 287      */
 288     
 289     private static boolean startingFromTestBed;
 290     
 291     public static void setStartingFromTestBed(boolean macWorkaroundEnabled) {
 292         AppPlatform.startingFromTestBed = macWorkaroundEnabled;
 293     }
 294 }


  79         
  80         assert applicationDataFolder != null;
  81         
  82         return applicationDataFolder;
  83     }
  84     
  85     
  86     public static synchronized String getUserLibraryFolder() {
  87         
  88         if (userLibraryFolder == null) {
  89             userLibraryFolder = getApplicationDataFolder() + "/Library"; //NOI18N
  90         }
  91         
  92         return userLibraryFolder;
  93     }
  94     
  95     public static boolean requestStart(
  96             AppNotificationHandler notificationHandler, Application.Parameters parameters)  
  97     throws IOException {
  98         if (IS_MAC) {
  99             Platform.setImplicitExit(false);
 100         }
 101 
 102         if (EditorPlatform.isAssertionEnabled()) {
 103             // Development mode : we do not delegate to the existing instance
 104             notificationHandler.handleLaunch(parameters.getUnnamed());
 105             return true;
 106         } else {
 107             return requestStartGeneric(notificationHandler, parameters);
 108         }
 109     }

 110     
 111     public interface AppNotificationHandler {
 112         public void handleLaunch(List<String> files);
 113         public void handleOpenFilesAction(List<String> files);
 114         public void handleMessageBoxFailure(Exception x);
 115         public void handleQuitAction();
 116     }
 117     
 118     
 119     /*
 120      * Private (requestStartGeneric)
 121      */
 122     
 123     private static synchronized boolean requestStartGeneric(
 124             AppNotificationHandler notificationHandler, Application.Parameters parameters) 
 125     throws IOException {
 126         assert notificationHandler != null;
 127         assert parameters != null;
 128         assert messageBox == null;
 129         


 176             this.eventHandler = eventHandler;
 177         }
 178         
 179         /*
 180          * MessageBox.Delegate
 181          */
 182         
 183         @Override
 184         public void messageBoxDidGetMessage(MessageBoxMessage message) {
 185             assert Platform.isFxApplicationThread() == false;
 186             Platform.runLater(() -> eventHandler.handleOpenFilesAction(message));
 187         }
 188 
 189         @Override
 190         public void messageBoxDidCatchException(Exception x) {
 191             assert Platform.isFxApplicationThread() == false;
 192             Platform.runLater(() -> eventHandler.handleMessageBoxFailure(x));
 193         }
 194         
 195     } 


































































































 196 }