Package at.kugel.tool.buildtray

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

package at.kugel.tool.buildtray;

import java.awt.PopupMenu;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import at.kugel.tool.buildtray.action.HtmlRegularExpressionActions;
import at.kugel.tool.buildtray.action.ServerConfigAndResponseActions;
import at.kugel.tool.buildtray.config.Config;
import at.kugel.tool.buildtray.config.MultiConfig;
import at.kugel.tool.buildtray.status.SetStatusAble;

/**
* Creates the Actions and sets up the popup menu and status display with them.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
class ActionsBuilder {

   private MultiConfig configs;
   private HtmlRegularExpressionActions globalActions;
   private ServerConfigAndResponseActions[] namedActions;

   public void loadConfigs(MultiConfig confs) {
      configs = confs;
   }

   public void createActions() {
      globalActions = new HtmlRegularExpressionActions(configs);

      namedActions = new ServerConfigAndResponseActions[configs.size()];
      int i=0;
      for (Config c : configs) {
         namedActions[i++] = new ServerConfigAndResponseActions(c);
      }
   }

   public void registerActionsToTray(TrayIconFactory factory) {
      PopupMenu popup = createPopupMenu();

      factory.setRightClickPopup(popup);
      factory.setLeftClickDefault(namedActions[0]);
   }

   private PopupMenu createPopupMenu() {
      PopupBuilder builder = new PopupBuilder();
      builder.createAboutRefresh(globalActions);
      for (int i = 0; i < namedActions.length; i++) {
         builder.addBroseEditConfig(namedActions[i]);
      }
      builder.createClosingExit(globalActions);
      return builder.getPopup();
   }

   public void setStatusDisplayToActions(SetStatusAble statusDisplay) {
      globalActions.setStatusDisplay(statusDisplay);

      for (ServerConfigAndResponseActions action : namedActions) {
         action.setStatusDisplay(statusDisplay);
      }
   }

   public void registerActionsToTimer() {
      final GlobalActions actions = this.globalActions;
      Timer timer = new Timer("Build Server Polling", true);
      timer.scheduleAtFixedRate(new TimerTask() {
         @Override
         public void run() {
            actions.refresh();
         }
      }, new Date(), getFirstConfig().getPollingMs());
   }

   public Config getFirstConfig() {
      return configs.getFirstConfig();
   }

}
TOP

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

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.