Example usage for java.awt SplashScreen getSplashScreen

List of usage examples for java.awt SplashScreen getSplashScreen

Introduction

In this page you can find the example usage for java.awt SplashScreen getSplashScreen.

Prototype

public static SplashScreen getSplashScreen() 

Source Link

Document

Returns the SplashScreen object used for Java startup splash screen control on systems that support display.

Usage

From source file:org.tros.torgo.Main.java

/**
 * Initialize the splash graphic.//ww  w. j  a v a  2  s.  c  o m
 */
private static void splashInit() {
    mySplash = SplashScreen.getSplashScreen();
    if (mySplash != null) {
        try {
            // if there are any problems displaying the splash this will be null
            splashDimension = mySplash.getSize();
            splashImage = ImageIO.read(mySplash.getImageURL());

            // create the Graphics environment for drawing status info
            splashGraphics = mySplash.createGraphics();
            font = new Font(Font.SANS_SERIF, Font.PLAIN, 16);
            splashGraphics.setFont(font);
            splashGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

            // initialize the status info
            splashText("Starting");
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:SplashScreenTest.java

/**
 * This method draws on the splash screen.
 *//*w  ww .  ja v  a2  s  . c om*/
private static void init1() {
    splash = SplashScreen.getSplashScreen();
    if (splash == null) {
        System.err.println("Did you specify a splash image with -splash or in the manifest?");
        System.exit(1);
    }

    try {
        for (int i = 0; i <= 100; i++) {
            drawOnSplash(i);
            Thread.sleep(100); // simulate startup work
        }
    } catch (InterruptedException e) {
    }
}

From source file:JDK6SplashTest.java

public JDK6SplashTest() {
    super("SplashScreen demo");
    setSize(500, 300);/*from ww  w.j a  v a 2  s.  com*/
    setLayout(new BorderLayout());
    Menu m1 = new Menu("File");
    MenuItem mi1 = new MenuItem("Exit");
    m1.add(mi1);
    mi1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }

    });

    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    mb.add(m1);
    final SplashScreen splash = SplashScreen.getSplashScreen();
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Graphics2D g = (Graphics2D) splash.createGraphics();
    if (g == null) {
        System.out.println("g is null");
        return;
    }
    for (int i = 0; i < 100; i++) {
        renderSplashFrame(g, i);
        splash.update();
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
    }
    splash.close();
    setVisible(true);
    toFront();
}

From source file:at.nullpointer.trayrss.gui.TrayRSSSplashScreen.java

/**
 * Creates a TrayRSSSplashScreen Object and retrieves a reference to the actual SplashScreen given with the java vm
 * parameter -splash. Also the splash screen timer is initiated.
 *//*from  w ww . j a  va 2s  .c o m*/
public TrayRSSSplashScreen() {

    super();

    try {
        this.splash = SplashScreen.getSplashScreen();
    } catch (NullPointerException e) {
        LOG.warn("No splash screen found!");
        LOG.debug("at TrayRSSSplashScreen#TrayRSSSplashScreen()");
    }

    this.start = System.currentTimeMillis();
}

From source file:SplashDemo.java

public SplashDemo() {
    super("SplashScreen demo");
    setSize(300, 200);/*  www.  j a v  a  2  s  .  c  o m*/
    setLayout(new BorderLayout());
    Menu m1 = new Menu("File");
    MenuItem mi1 = new MenuItem("Exit");
    m1.add(mi1);
    mi1.addActionListener(this);
    this.addWindowListener(closeWindow);

    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    mb.add(m1);
    final SplashScreen splash = SplashScreen.getSplashScreen();
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Graphics2D g = splash.createGraphics();
    if (g == null) {
        System.out.println("g is null");
        return;
    }
    for (int i = 0; i < 100; i++) {
        renderSplashFrame(g, i);
        splash.update();
        try {
            Thread.sleep(90);
        } catch (InterruptedException e) {
        }
    }
    splash.close();
    setVisible(true);
    toFront();
}

From source file:edu.stanford.epadd.launcher.Splash.java

public Splash() {
    final SplashScreen splash = (System.getProperty("nobrowseropen") == null) ? SplashScreen.getSplashScreen()
            : null;//from  w ww . j  a v  a  2s  . c o  m
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Rectangle r = splash.getBounds();
    g = splash.createGraphics();
    if (g == null) {
        System.out.println("splash.createGraphics() returned null");
        return;
    }
    System.out.println("splash url = " + splash.getImageURL() + " w=" + r.getWidth() + " h=" + r.getHeight()
            + " size=" + r.getSize() + " loc=" + r.getLocation());
    //      setVisible(true);
    //      toFront();
}

From source file:edu.stanford.epadd.launcher.Splash.java

public Splash() {
    final SplashScreen splash = (System.getProperty("nobrowseropen") == null) ? SplashScreen.getSplashScreen()
            : null;//from   ww  w .jav a 2s . c  om
    if (splash == null) {
        System.out.println("SplashScreen.getSplashScreen() returned null");
        return;
    }
    Rectangle r = splash.getBounds();
    g = splash.createGraphics();
    if (g == null) {
        System.out.println("splash.createGraphics() returned null");
        return;
    }

    /* code to prevent text from appearing too pixelated - https://stackoverflow.com/questions/31536952/how-to-fix-text-quality-in-java-graphics */
    Map<?, ?> desktopHints = (Map<?, ?>) Toolkit.getDefaultToolkit()
            .getDesktopProperty("awt.font.desktophints");
    if (desktopHints != null) {
        g.setRenderingHints(desktopHints);
    }
    System.out.println("splash url = " + splash.getImageURL() + " w=" + r.getWidth() + " h=" + r.getHeight()
            + " size=" + r.getSize() + " loc=" + r.getLocation());
    //      setVisible(true);
    //      toFront();
}

From source file:org.datacleaner.bootstrap.Bootstrap.java

private void runInternal() throws FileSystemException {
    logger.info("Welcome to DataCleaner {}", Version.getVersion());

    // determine whether to run in command line interface mode
    final boolean cliMode = _options.isCommandLineMode();
    final CliArguments arguments = _options.getCommandLineArguments();

    logger.info("CLI mode={}, use -usage to view usage options", cliMode);

    if (cliMode) {

        try {/*from ww  w . j  av  a 2s .  co  m*/
            if (!GraphicsEnvironment.isHeadless()) {
                // hide splash screen
                final SplashScreen splashScreen = SplashScreen.getSplashScreen();
                if (splashScreen != null) {
                    splashScreen.close();
                }
            }
        } catch (Exception e) {
            // ignore this condition - may happen rarely on e.g. X windows
            // systems when the user is not authorized to access the
            // graphics environment.
            logger.trace("Swallowing exception caused by trying to hide splash screen", e);
        }

        if (arguments.isUsageMode()) {
            final PrintWriter out = new PrintWriter(System.out);
            try {
                CliArguments.printUsage(out);
            } finally {
                FileHelper.safeClose(out);
            }

            exitCommandLine(null, 1);
            return;
        }

        if (arguments.isVersionMode()) {
            final PrintWriter out = new PrintWriter(System.out);
            try {
                CliArguments.printVersion(out);
            } finally {
                FileHelper.safeClose(out);
            }

            exitCommandLine(null, 1);
            return;
        }
    }

    if (!cliMode) {
        // set up error handling that displays an error dialog
        final DCUncaughtExceptionHandler exceptionHandler = new DCUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);

        // init the look and feel
        LookAndFeelManager.get().init();
    }

    // initially use a temporary non-persistent user preferences object.
    // This is just to have basic settings available for eg. resolving
    // files.
    final UserPreferences initialUserPreferences = new UserPreferencesImpl(null);

    final String configurationFilePath = arguments.getConfigurationFile();
    final FileObject configurationFile = resolveFile(configurationFilePath, "conf.xml", initialUserPreferences);

    Injector injector = Guice.createInjector(new DCModuleImpl(DataCleanerHome.get(), configurationFile));

    // configuration loading can be multithreaded, so begin early
    final DataCleanerConfiguration configuration = injector.getInstance(DataCleanerConfiguration.class);

    // log usage
    final UsageLogger usageLogger = injector.getInstance(UsageLogger.class);
    usageLogger.logApplicationStartup();

    if (cliMode) {
        // run in CLI mode

        int exitCode = 0;
        try (final CliRunner runner = new CliRunner(arguments)) {
            runner.run(configuration);
        } catch (Throwable e) {
            logger.error("Error occurred while running DataCleaner command line mode", e);
            exitCode = 1;
        } finally {
            exitCommandLine(configuration, exitCode);
        }
        return;
    } else {
        // run in GUI mode
        final AnalysisJobBuilderWindow analysisJobBuilderWindow;

        // initialize Mac OS specific settings
        final MacOSManager macOsManager = injector.getInstance(MacOSManager.class);
        macOsManager.init();

        // check for job file
        final String jobFilePath = _options.getCommandLineArguments().getJobFile();
        if (jobFilePath != null) {
            final FileObject jobFile = resolveFile(jobFilePath, null, initialUserPreferences);
            injector = OpenAnalysisJobActionListener.open(jobFile, configuration, injector);
        }

        final UserPreferences userPreferences = injector.getInstance(UserPreferences.class);

        analysisJobBuilderWindow = injector.getInstance(AnalysisJobBuilderWindow.class);

        final Datastore singleDatastore;
        if (_options.isSingleDatastoreMode()) {
            DatastoreCatalog datastoreCatalog = configuration.getDatastoreCatalog();
            singleDatastore = _options.getSingleDatastore(datastoreCatalog);
            if (singleDatastore == null) {
                logger.info("Single datastore mode was enabled, but datastore was null!");
            } else {
                logger.info("Initializing single datastore mode with {}", singleDatastore);
                analysisJobBuilderWindow.setDatastoreSelectionEnabled(false);
                analysisJobBuilderWindow.setDatastore(singleDatastore, true);
            }
        } else {
            singleDatastore = null;
        }

        // show the window
        analysisJobBuilderWindow.open();

        if (singleDatastore != null) {
            // this part has to be done after displaying the window (a lot
            // of initialization goes on there)
            final AnalysisJobBuilder analysisJobBuilder = analysisJobBuilderWindow.getAnalysisJobBuilder();
            try (final DatastoreConnection con = singleDatastore.openConnection()) {
                final InjectorBuilder injectorBuilder = injector.getInstance(InjectorBuilder.class);
                _options.initializeSingleDatastoreJob(analysisJobBuilder, con.getDataContext(),
                        injectorBuilder);
            }
        }

        final Image welcomeImage = _options.getWelcomeImage();
        if (welcomeImage != null) {
            // Ticket #834: make sure to show welcome dialog in swing's
            // dispatch thread.
            WidgetUtils.invokeSwingAction(new Runnable() {
                @Override
                public void run() {
                    final WelcomeDialog welcomeDialog = new WelcomeDialog(analysisJobBuilderWindow,
                            welcomeImage);
                    welcomeDialog.setVisible(true);
                }
            });
        }

        final WindowContext windowContext = injector.getInstance(WindowContext.class);

        // set up HTTP service for ExtensionSwap installation
        loadExtensionSwapService(userPreferences, windowContext, configuration, usageLogger);

        final ExitActionListener exitActionListener = _options.getExitActionListener();
        if (exitActionListener != null) {
            windowContext.addExitActionListener(exitActionListener);
        }
    }
}

From source file:org.eobjects.datacleaner.bootstrap.Bootstrap.java

private void runInternal() throws FileSystemException {
    logger.info("Welcome to DataCleaner {}", Version.getVersion());

    // determine whether to run in command line interface mode
    final boolean cliMode = _options.isCommandLineMode();
    final CliArguments arguments = _options.getCommandLineArguments();

    logger.info("CLI mode={}, use -usage to view usage options", cliMode);

    if (cliMode) {

        if (!GraphicsEnvironment.isHeadless()) {
            // hide splash screen
            final SplashScreen splashScreen = SplashScreen.getSplashScreen();
            if (splashScreen != null) {
                splashScreen.close();/*from   w  ww .j a  va2  s  .com*/
            }
        }

        if (arguments.isUsageMode()) {
            final PrintWriter out = new PrintWriter(System.out);
            try {
                CliArguments.printUsage(out);
            } finally {
                FileHelper.safeClose(out);
            }

            exitCommandLine(null, 1);
            return;
        }
    }

    if (!cliMode) {
        // set up error handling that displays an error dialog
        final DCUncaughtExceptionHandler exceptionHandler = new DCUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);

        // init the look and feel
        LookAndFeelManager.get().init();
    }

    // initially use a temporary non-persistent user preferences object.
    // This is just to have basic settings available for eg. resolving
    // files.
    final UserPreferences initialUserPreferences = new UserPreferencesImpl(null);

    final String configurationFilePath = arguments.getConfigurationFile();
    final FileObject configurationFile = resolveFile(configurationFilePath, "conf.xml", initialUserPreferences);

    Injector injector = Guice.createInjector(new DCModule(DataCleanerHome.get(), configurationFile));

    // configuration loading can be multithreaded, so begin early
    final AnalyzerBeansConfiguration configuration = injector.getInstance(AnalyzerBeansConfiguration.class);

    // log usage
    final UsageLogger usageLogger = injector.getInstance(UsageLogger.class);
    usageLogger.logApplicationStartup();

    if (cliMode) {
        // run in CLI mode

        int exitCode = 0;
        final CliRunner runner = new CliRunner(arguments);
        try {
            runner.run(configuration);
        } catch (Throwable e) {
            logger.error("Error occurred while running DataCleaner command line mode", e);
            exitCode = 1;
        } finally {
            runner.close();
            exitCommandLine(configuration, exitCode);
        }
        return;
    } else {
        // run in GUI mode
        final AnalysisJobBuilderWindow analysisJobBuilderWindow;

        // initialize Mac OS specific settings
        final MacOSManager macOsManager = injector.getInstance(MacOSManager.class);
        macOsManager.init();

        // check for job file
        final String jobFilePath = _options.getCommandLineArguments().getJobFile();
        if (jobFilePath != null) {
            final FileObject jobFile = resolveFile(jobFilePath, null, initialUserPreferences);
            injector = OpenAnalysisJobActionListener.open(jobFile, configuration, injector);
        }

        final UserPreferences userPreferences = injector.getInstance(UserPreferences.class);

        analysisJobBuilderWindow = injector.getInstance(AnalysisJobBuilderWindow.class);

        final Datastore singleDatastore;
        if (_options.isSingleDatastoreMode()) {
            DatastoreCatalog datastoreCatalog = configuration.getDatastoreCatalog();
            singleDatastore = _options.getSingleDatastore(datastoreCatalog);
            if (singleDatastore == null) {
                logger.info("Single datastore mode was enabled, but datastore was null!");
            } else {
                logger.info("Initializing single datastore mode with {}", singleDatastore);
                analysisJobBuilderWindow.setDatastoreSelectionEnabled(false);
                analysisJobBuilderWindow.setDatastore(singleDatastore, true);
            }
        } else {
            singleDatastore = null;
        }

        // show the window
        analysisJobBuilderWindow.open();

        if (singleDatastore != null) {
            // this part has to be done after displaying the window (a lot
            // of initialization goes on there)
            final AnalysisJobBuilder analysisJobBuilder = analysisJobBuilderWindow.getAnalysisJobBuilder();
            final DatastoreConnection con = singleDatastore.openConnection();
            final InjectorBuilder injectorBuilder = injector.getInstance(InjectorBuilder.class);
            try {
                _options.initializeSingleDatastoreJob(analysisJobBuilder, con.getDataContext(),
                        injectorBuilder);
            } finally {
                con.close();
            }
        }

        final Image welcomeImage = _options.getWelcomeImage();
        if (welcomeImage != null) {
            // Ticket #834: make sure to show welcome dialog in swing's
            // dispatch thread.
            WidgetUtils.invokeSwingAction(new Runnable() {
                @Override
                public void run() {
                    final WelcomeDialog welcomeDialog = new WelcomeDialog(analysisJobBuilderWindow,
                            welcomeImage);
                    welcomeDialog.setVisible(true);
                }
            });
        }

        final WindowContext windowContext = injector.getInstance(WindowContext.class);

        final HttpClient httpClient = injector.getInstance(HttpClient.class);

        // set up HTTP service for ExtensionSwap installation
        loadExtensionSwapService(userPreferences, windowContext, configuration, httpClient, usageLogger);

        final ExitActionListener exitActionListener = _options.getExitActionListener();
        if (exitActionListener != null) {
            windowContext.addExitActionListener(exitActionListener);
        }
    }
}