Package at.kugel.tool.buildtray

Source Code of at.kugel.tool.buildtray.Main

package at.kugel.tool.buildtray;

import java.awt.AWTException;
import java.awt.SplashScreen;

import at.kugel.tool.buildtray.config.MultiConfig;
import at.kugel.tool.buildtray.status.SetStatusAble;

/**
* Build Tray Main Starter. Loads images display the tray, start polling threads and close splash screen.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
public final class Main {

   public static void main(String[] args) throws AWTException, InterruptedException {
      TrayIconFactory.handleTrayNotSupported();

      handleEmptyArguments(args);

      final long startTime = System.currentTimeMillis();

      TrayIconFactory factory = new TrayIconFactory();
      SetStatusAble tray = factory.create();

      ActionsBuilder builder = new ActionsBuilder();
      builder.loadConfigs(new MultiConfig(args));
      builder.createActions();
      builder.registerActionsToTray(factory);
      builder.setStatusDisplayToActions(tray);
      builder.registerActionsToTimer();

      closeSplashScreen(startTime + builder.getFirstConfig().getSplashWaitMs());
   }

   private static void handleEmptyArguments(String[] args) {
      if (args.length == 0) {
         System.out.println("Usage: java -jar BuildServerSystemTray.jar <path to config files, e.g. \"config/Hudson-1.2.properties\">");
         System.exit(2);
      }
   }

   private static void closeSplashScreen(long untilMs) throws InterruptedException {
      SplashScreen screen = SplashScreen.getSplashScreen();
      if (screen != null) {
         long splashWaitMs = untilMs - System.currentTimeMillis();
         if (splashWaitMs > 0) {
            Thread.sleep(splashWaitMs);
         }
         screen.close();
      }
   }

}
TOP

Related Classes of at.kugel.tool.buildtray.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.