< prev index next >

modules/javafx.graphics/src/main/java/javafx/application/Application.java

Print this page
rev 10897 : 8199357: Remove references to applets and Java Web Start from FX
Reviewed-by:
   1 /*
   2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  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


 325      * NOTE: This method is not called on the JavaFX Application Thread. An
 326      * application must not construct a Scene or a Stage in this
 327      * method.
 328      * An application may construct other JavaFX objects in this method.
 329      * </p>
 330      * @throws java.lang.Exception if something goes wrong
 331      */
 332     public void init() throws Exception {
 333     }
 334 
 335     /**
 336      * The main entry point for all JavaFX applications.
 337      * The start method is called after the init method has returned,
 338      * and after the system is ready for the application to begin running.
 339      *
 340      * <p>
 341      * NOTE: This method is called on the JavaFX Application Thread.
 342      * </p>
 343      *
 344      * @param primaryStage the primary stage for this application, onto which
 345      * the application scene can be set. The primary stage will be embedded in
 346      * the browser if the application was launched as an applet.
 347      * Applications may create other stages, if needed, but they will not be
 348      * primary stages and will not be embedded in the browser.
 349      * @throws java.lang.Exception if something goes wrong
 350      */
 351     public abstract void start(Stage primaryStage) throws Exception;
 352 
 353     /**
 354      * This method is called when the application should stop, and provides a
 355      * convenient place to prepare for application exit and destroy resources.
 356      *
 357      * <p>
 358      * The implementation of this method provided by the Application class does nothing.
 359      * </p>
 360      *
 361      * <p>
 362      * NOTE: This method is called on the JavaFX Application Thread.
 363      * </p>
 364      * @throws java.lang.Exception if something goes wrong
 365      */
 366     public void stop() throws Exception {
 367     }
 368 
 369     private HostServices hostServices = null;
 370 
 371     /**
 372      * Gets the HostServices provider for this application. This provides
 373      * the ability to get the code base and document base for this application,
 374      * and to access the enclosing web page.
 375      *
 376      * @return the HostServices provider
 377      */
 378     public final HostServices getHostServices() {
 379         synchronized (this) {
 380             if (hostServices == null) {
 381                 hostServices = new HostServices(this);
 382             }
 383             return hostServices;
 384         }
 385     }
 386 
 387     /**
 388      * Retrieves the parameters for this Application, including any arguments
 389      * passed on the command line and any parameters specified in a JNLP file
 390      * for an applet or WebStart application.
 391      *
 392      * <p>
 393      * NOTE: this method should not be called from the Application constructor,
 394      * as it will return null. It may be called in the init() method or any
 395      * time after that.
 396      * </p>
 397      *
 398      * @return the parameters for this Application, or null if called from the
 399      * constructor.
 400      */
 401     public final Parameters getParameters() {
 402         return ParametersImpl.getParameters(this);
 403     }
 404 
 405     /**
 406      * Notifies the preloader with an application-generated notification.
 407      * Application code calls this method with a PreloaderNotification that is
 408      * delivered to the
 409      * {@link Preloader#handleApplicationNotification
 410      * Preloader.handleApplicationNotification} method.


 412      * preloader to show progress during a long application initialization
 413      * step.
 414      *
 415      * <p>
 416      * NOTE: the notification will be delivered only to the preloader's
 417      * handleApplicationNotification() method; this means, for example, that
 418      * if this method is called with a ProgressNotification, that notification
 419      * will not be delivered to the {@link Preloader#handleProgressNotification
 420      * Preloader.handleProgressNotification}
 421      * method.
 422      * </p>
 423      *
 424      * @param info the application-generated preloader notification
 425      */
 426     public final void notifyPreloader(PreloaderNotification info) {
 427         LauncherImpl.notifyPreloader(this, info);
 428     }
 429 
 430     /**
 431      * Encapsulates the set of parameters for an application. This includes
 432      * arguments passed on the command line, unnamed parameters specified
 433      * in a JNLP file, and &lt;name,value&gt; pairs specified in a JNLP file.
 434      *
 435      * <p>
 436      * Note that the application and the preloader both get the same set
 437      * of parameters for a given run of an application.
 438      * </p>
 439      * @since JavaFX 2.0
 440      */
 441     public static abstract class Parameters {
 442 
 443         /**
 444          * Constructs a new {@code Parameters} instance.
 445          */
 446         public Parameters() {
 447         }
 448 
 449         /**
 450          * Retrieves a read-only list of the raw arguments. This list
 451          * may be empty, but is never null. In the case of a standalone
 452          * application, it is the ordered list of arguments specified on the
 453          * command line. In the case of an applet or WebStart application,
 454          * it includes unnamed parameters as well as named parameters. For
 455          * named parameters, each &lt;name,value&gt; pair is represented as
 456          * a single argument of the form: "--name=value".
 457          *
 458          * @return a read-only list of raw application arguments
 459          */
 460         public abstract List<String> getRaw();
 461 
 462         /**
 463          * Retrieves a read-only list of the unnamed parameters. This list
 464          * may be empty, but is never null. The named parameters, that is
 465          * the parameters that are represented as &lt;name,value&gt; pairs, are
 466          * filtered out.
 467          *
 468          * @return a read-only list of unnamed parameters.
 469          */
 470         public abstract List<String> getUnnamed();
 471 
 472         /**
 473          * Retrieves a read-only map of the named parameters. It may be
 474          * empty, but is never null.
 475          * Named parameters include those &lt;name,value&gt; pairs explicitly
 476          * specified in a JNLP file. It also includes any command line
 477          * arguments of the form: "--name=value".
 478          *
 479          * @return a read-only map of named parameters.
 480          */
 481         public abstract Map<String, String> getNamed();
 482 
 483     }
 484 
 485     private static String userAgentStylesheet = null;
 486 
 487     /**
 488      * Get the user agent stylesheet used by the whole application. This is
 489      * used to provide default styling for all ui controls and other nodes.
 490      * A value of null means the platform default stylesheet is being used.
 491      * <p>
 492      * NOTE: This method must be called on the JavaFX Application Thread.
 493      * </p>
 494      *
 495      * @return The URL to the stylesheet as a String.
 496      * @since JavaFX 8.0


   1 /*
   2  * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  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


 325      * NOTE: This method is not called on the JavaFX Application Thread. An
 326      * application must not construct a Scene or a Stage in this
 327      * method.
 328      * An application may construct other JavaFX objects in this method.
 329      * </p>
 330      * @throws java.lang.Exception if something goes wrong
 331      */
 332     public void init() throws Exception {
 333     }
 334 
 335     /**
 336      * The main entry point for all JavaFX applications.
 337      * The start method is called after the init method has returned,
 338      * and after the system is ready for the application to begin running.
 339      *
 340      * <p>
 341      * NOTE: This method is called on the JavaFX Application Thread.
 342      * </p>
 343      *
 344      * @param primaryStage the primary stage for this application, onto which
 345      * the application scene can be set.

 346      * Applications may create other stages, if needed, but they will not be
 347      * primary stages.
 348      * @throws java.lang.Exception if something goes wrong
 349      */
 350     public abstract void start(Stage primaryStage) throws Exception;
 351 
 352     /**
 353      * This method is called when the application should stop, and provides a
 354      * convenient place to prepare for application exit and destroy resources.
 355      *
 356      * <p>
 357      * The implementation of this method provided by the Application class does nothing.
 358      * </p>
 359      *
 360      * <p>
 361      * NOTE: This method is called on the JavaFX Application Thread.
 362      * </p>
 363      * @throws java.lang.Exception if something goes wrong
 364      */
 365     public void stop() throws Exception {
 366     }
 367 
 368     private HostServices hostServices = null;
 369 
 370     /**
 371      * Gets the HostServices provider for this application. This provides
 372      * the ability to get the code base and document base for this application,
 373      * and to show a web page in a browser.
 374      *
 375      * @return the HostServices provider
 376      */
 377     public final HostServices getHostServices() {
 378         synchronized (this) {
 379             if (hostServices == null) {
 380                 hostServices = new HostServices(this);
 381             }
 382             return hostServices;
 383         }
 384     }
 385 
 386     /**
 387      * Retrieves the parameters for this Application, including any arguments
 388      * passed on the command line.

 389      *
 390      * <p>
 391      * NOTE: this method should not be called from the Application constructor,
 392      * as it will return null. It may be called in the init() method or any
 393      * time after that.
 394      * </p>
 395      *
 396      * @return the parameters for this Application, or null if called from the
 397      * constructor.
 398      */
 399     public final Parameters getParameters() {
 400         return ParametersImpl.getParameters(this);
 401     }
 402 
 403     /**
 404      * Notifies the preloader with an application-generated notification.
 405      * Application code calls this method with a PreloaderNotification that is
 406      * delivered to the
 407      * {@link Preloader#handleApplicationNotification
 408      * Preloader.handleApplicationNotification} method.


 410      * preloader to show progress during a long application initialization
 411      * step.
 412      *
 413      * <p>
 414      * NOTE: the notification will be delivered only to the preloader's
 415      * handleApplicationNotification() method; this means, for example, that
 416      * if this method is called with a ProgressNotification, that notification
 417      * will not be delivered to the {@link Preloader#handleProgressNotification
 418      * Preloader.handleProgressNotification}
 419      * method.
 420      * </p>
 421      *
 422      * @param info the application-generated preloader notification
 423      */
 424     public final void notifyPreloader(PreloaderNotification info) {
 425         LauncherImpl.notifyPreloader(this, info);
 426     }
 427 
 428     /**
 429      * Encapsulates the set of parameters for an application. This includes
 430      * arguments passed on the command line.

 431      *
 432      * <p>
 433      * Note that the application and the preloader both get the same set
 434      * of parameters for a given run of an application.
 435      * </p>
 436      * @since JavaFX 2.0
 437      */
 438     public static abstract class Parameters {
 439 
 440         /**
 441          * Constructs a new {@code Parameters} instance.
 442          */
 443         public Parameters() {
 444         }
 445 
 446         /**
 447          * Retrieves a read-only list of the raw arguments. This list
 448          * may be empty, but is never null. In the case of a standalone
 449          * application, it is the ordered list of arguments specified on the
 450          * command line.
 451          * For
 452          * named parameters, each &lt;name,value&gt; pair is represented as
 453          * a single argument of the form: "--name=value".
 454          *
 455          * @return a read-only list of raw application arguments
 456          */
 457         public abstract List<String> getRaw();
 458 
 459         /**
 460          * Retrieves a read-only list of the unnamed parameters. This list
 461          * may be empty, but is never null. The named parameters, that is
 462          * the parameters that are represented as &lt;name,value&gt; pairs, are
 463          * filtered out.
 464          *
 465          * @return a read-only list of unnamed parameters.
 466          */
 467         public abstract List<String> getUnnamed();
 468 
 469         /**
 470          * Retrieves a read-only map of the named parameters. It may be
 471          * empty, but is never null.
 472          * Named parameters include any command line

 473          * arguments of the form: "--name=value".
 474          *
 475          * @return a read-only map of named parameters.
 476          */
 477         public abstract Map<String, String> getNamed();
 478 
 479     }
 480 
 481     private static String userAgentStylesheet = null;
 482 
 483     /**
 484      * Get the user agent stylesheet used by the whole application. This is
 485      * used to provide default styling for all ui controls and other nodes.
 486      * A value of null means the platform default stylesheet is being used.
 487      * <p>
 488      * NOTE: This method must be called on the JavaFX Application Thread.
 489      * </p>
 490      *
 491      * @return The URL to the stylesheet as a String.
 492      * @since JavaFX 8.0


< prev index next >