List of usage examples for java.awt SplashScreen close
public void close() throws IllegalStateException
From source file:Main.java
public static void main(String args[]) throws Exception { SplashScreen splash = SplashScreen.getSplashScreen(); splash.close(); }
From source file:javarestart.JavaRestartLauncher.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println("Usage: <URL> {<MainClass>}"); return;//from w w w. j a v a 2 s .co m } if (args[0].equals("fork")) { String[] args2 = new String[args.length - 1]; for (int i = 0; i < args.length - 1; i++) { args2[i] = args[i + 1]; } fork(args2); return; } AppClassloader loader = new AppClassloader(args[0]); Thread.currentThread().setContextClassLoader(loader); String main; JSONObject obj = getJSON(args[0]); if (args.length < 2) { main = (String) obj.get("main"); } else { main = args[1]; } String splash = (String) obj.get("splash"); if (splash != null) { SplashScreen scr = SplashScreen.getSplashScreen(); if (scr != null) { URL url = loader.getResource(splash); scr.setImageURL(url); } } //auto close splash after 45 seconds Thread splashClose = new Thread() { @Override public void run() { try { sleep(45000); } catch (InterruptedException e) { } SplashScreen scr = SplashScreen.getSplashScreen(); if ((scr != null) && (scr.isVisible())) { scr.close(); } } }; splashClose.setDaemon(true); splashClose.start(); Class mainClass = loader.loadClass(main); Method mainMethod = mainClass.getMethod("main", String[].class); mainMethod.setAccessible(true); mainMethod.invoke(null, new Object[] { new String[0] }); }
From source file:com.devbury.desktoplib.systemtray.SystemTrayApplication.java
public void start() { logSystemInfo();/* ww w . j a v a 2 s.c o m*/ try { if (!isSystemTraySupported()) { JOptionPane.showMessageDialog(null, "Could not start application. This application requires system tray support and your platform " + "does not provide this.", "System Tray Not Supported", JOptionPane.ERROR_MESSAGE); throw new RuntimeException("SystemTray is not supported"); } else { logger.debug("SystemTray is supported"); } if (applicationContext == null) { String[] locations = buildConfigLocations(); logger.debug("Creating context from " + configLocationsToString(locations)); applicationContext = new ClassPathXmlApplicationContext(locations); logger.debug("Context finished building"); } // get the TrayIconDefinition instances Map defs = applicationContext.getBeansOfType(TrayIconDefinition.class); if (defs == null || defs.isEmpty()) { throw new RuntimeException("No TrayIconDefinition instances exist in the context"); } SystemTray tray = newSystemTray(); Iterator<TrayIconDefinition> it = defs.values().iterator(); LinkedList<TrayIcon> installedIcons = new LinkedList<TrayIcon>(); while (it.hasNext()) { TrayIconDefinition def = (TrayIconDefinition) it.next(); try { TrayIcon ti = def.buildTrayIcon(); tray.add(ti); installedIcons.add(ti); } catch (Throwable t) { logger.error("Could not add TrayIconDefinition " + def); } } // get the monitor object out of the context to block on Object monitor = applicationContext.getBean("applicationShutdownService"); // if there was a splash screen shut it down SplashScreen splash = newSplashScreen(); if (splash != null) { logger.debug("Shutting down splash screen"); splash.close(); } synchronized (monitor) { monitor.wait(); } logger.debug("Application shutting down"); Iterator<TrayIcon> trayIconIt = installedIcons.iterator(); while (trayIconIt.hasNext()) { TrayIcon ti = (TrayIcon) trayIconIt.next(); tray.remove(ti); } applicationContext.close(); logger.debug("Application stopped"); } catch (Throwable t) { logger.error("Unresolved exception", t); logger.error("Application shutting down"); if (applicationContext != null) { applicationContext.close(); } logger.error("Application stopped"); } }
From source file:JDK6SplashTest.java
public JDK6SplashTest() { super("SplashScreen demo"); setSize(500, 300);/*w w w . j ava2s .c o m*/ 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:SplashDemo.java
public SplashDemo() { super("SplashScreen demo"); setSize(300, 200);//from w w w . jav a 2 s. com 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: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 .ja va 2 s . co m } 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); } } }
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 {// w w w . j a va2s . c o 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:jatoo.app.App.java
public App(final String title) { this.title = title; //// w w w . j a va 2s.co m // load properties properties = new AppProperties(new File(getWorkingDirectory(), "app.properties")); properties.loadSilently(); // // resources texts = new ResourcesTexts(getClass(), new ResourcesTexts(App.class)); images = new ResourcesImages(getClass(), new ResourcesImages(App.class)); // // create & initialize the window if (isDialog()) { window = new JDialog((Frame) null, getTitle()); if (isUndecorated()) { ((JDialog) window).setUndecorated(true); ((JDialog) window).setBackground(new Color(0, 0, 0, 0)); } ((JDialog) window).setResizable(isResizable()); } else { window = new JFrame(getTitle()); if (isUndecorated()) { ((JFrame) window).setUndecorated(true); ((JFrame) window).setBackground(new Color(0, 0, 0, 0)); } ((JFrame) window).setResizable(isResizable()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { System.exit(0); } @Override public void windowIconified(final WindowEvent e) { if (isHideWhenMinimized()) { hide(); } } }); // // set icon images // is either all icons from initializer package // or all icons from app package List<Image> windowIconImages = new ArrayList<>(); String[] windowIconImagesNames = new String[] { "016", "020", "022", "024", "032", "048", "064", "128", "256", "512" }; for (String size : windowIconImagesNames) { try { windowIconImages.add(new ImageIcon(getClass().getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } if (windowIconImages.size() == 0) { for (String size : windowIconImagesNames) { try { windowIconImages .add(new ImageIcon(App.class.getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } } window.setIconImages(windowIconImages); // // this is the place for to call init method // after all local components are created // from now (after init) is only configuration init(); // // set content pane ( and ansure transparency ) JComponent contentPane = getContentPane(); contentPane.setOpaque(false); ((RootPaneContainer) window).setContentPane(contentPane); // // pack the window right after the set of the content pane window.pack(); // // center window (as default in case restore fails) // and try to restore the last location window.setLocationRelativeTo(null); window.setLocation(properties.getLocation(window.getLocation())); if (!isUndecorated()) { if (properties.getLastUndecorated(isUndecorated()) == isUndecorated()) { if (isResizable() && isSizePersistent()) { final String currentLookAndFeel = String.valueOf(UIManager.getLookAndFeel()); if (properties.getLastLookAndFeel(currentLookAndFeel).equals(currentLookAndFeel)) { window.setSize(properties.getSize(window.getSize())); } } } } // // fix location if out of screen Rectangle intersection = window.getGraphicsConfiguration().getBounds().intersection(window.getBounds()); if ((intersection.width < window.getWidth() * 1 / 2) || (intersection.height < window.getHeight() * 1 / 2)) { UIUtils.setWindowLocationRelativeToScreen(window); } // // restore some properties setAlwaysOnTop(properties.isAlwaysOnTop()); setHideWhenMinimized(properties.isHideWhenMinimized()); setTransparency(properties.getTransparency(transparency)); // // null is also a good value for margins glue gaps (is [0,0,0,0]) Insets marginsGlueGaps = getMarginsGlueGaps(); if (marginsGlueGaps == null) { marginsGlueGaps = new Insets(0, 0, 0, 0); } // // glue to margins on Ctrl + ARROWS if (isGlueToMarginsOnCtrlArrows()) { UIUtils.setActionForCtrlDownKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginBottom(window, marginsGlueGaps.bottom)); UIUtils.setActionForCtrlLeftKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginLeft(window, marginsGlueGaps.left)); UIUtils.setActionForCtrlRightKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginRight(window, marginsGlueGaps.right)); UIUtils.setActionForCtrlUpKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginTop(window, marginsGlueGaps.top)); } // // drag to move ( when provided component is not null ) JComponent dragToMoveComponent = getDragToMoveComponent(); if (dragToMoveComponent != null) { // // move the window by dragging the UI component int marginsGlueRange = Math.min(window.getGraphicsConfiguration().getBounds().width, window.getGraphicsConfiguration().getBounds().height); marginsGlueRange /= 60; marginsGlueRange = Math.max(marginsGlueRange, 15); UIUtils.forwardDragAsMove(dragToMoveComponent, window, marginsGlueRange, marginsGlueGaps); // // window popup dragToMoveComponent.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { windowPopup = getWindowPopup(e.getLocationOnScreen()); windowPopup.setVisible(true); } } }); // // always dispose the popup when window lose the focus window.addFocusListener(new FocusAdapter() { public void focusLost(final FocusEvent e) { if (windowPopup != null) { windowPopup.setVisible(false); windowPopup = null; } } }); } // // tray icon if (hasTrayIcon()) { if (SystemTray.isSupported()) { Image trayIconImage = windowIconImages.get(0); Dimension trayIconSize = SystemTray.getSystemTray().getTrayIconSize(); for (Image windowIconImage : windowIconImages) { if (Math.abs(trayIconSize.width - windowIconImage.getWidth(null)) < Math .abs(trayIconImage.getWidth(null) - windowIconImage.getWidth(null))) { trayIconImage = windowIconImage; } } final TrayIcon trayIcon = new TrayIcon(trayIconImage); trayIcon.setPopupMenu(getTrayIconPopup()); trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() >= 2) { if (window.isVisible()) { hide(); } else { show(); } } } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { logger.error( "unexpected exception trying to add the tray icon ( the desktop system tray is missing? )", e); } } else { logger.error("the system tray is not supported on the current platform"); } } // // hidden or not if (properties.isVisible()) { window.setVisible(true); } // // close the splash screen // if there is one try { SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { splash.close(); } } catch (UnsupportedOperationException e) { getLogger().info("splash screen not supported", e); } // // add shutdown hook for #destroy() Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { App.this.destroy(); } }); // // after init afterInit(); }