Package at.kugel.tool.buildtray

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

package at.kugel.tool.buildtray;

import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import at.kugel.tool.buildtray.config.Version;

/**
* Create a popup menu for each item in the actions.
*
* @author <a href="http://www.code-cop.org/">Peter Kofler</a>
*/
class PopupBuilder {

   private final PopupMenu popup = new PopupMenu();

   public void createAboutRefresh(GlobalActions globalActions) {
      addAbout(globalActions);
      addSeparator();
      addRefresh(globalActions);
   }

   public void addBroseEditConfig(IndividualActions individualActions) {
      addSeparator();
      addBrowse(individualActions);
      addDisplay(individualActions);
      addConfig(individualActions);
   }

   public void createClosingExit(GlobalActions globalActions) {
      addSeparator();
      addExit(globalActions);
   }

   public PopupMenu getPopup() {
      return popup;
   }

   private void addAbout(final GlobalActions globalActions) {
      String version = new Version().get();
      addEntry("BuildServerSystemTray v" + version, new ActionListener() {
         @Override
         public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            globalActions.about();
         }
      });
   }

   private void addBrowse(final IndividualActions actions) {
      addEntry("open " + actions.getName() + " in web browser", new ActionListener() {
         @Override
         public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            actions.openBrowser();
         }
      });
   }

   private void addEntry(String label, ActionListener command) {
      MenuItem item = new MenuItem(label);
      item.addActionListener(command);
      popup.add(item);
   }

   private void addRefresh(final GlobalActions globalActions) {
      addEntry("refresh build status now", new ActionListener() {
         @Override
         public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            globalActions.refresh();
         }
      });
   }

   private void addDisplay(final IndividualActions actions) {
      addEntry("display annotated " + actions.getName() + " response", new ActionListener() {
         @Override
         public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            actions.showServerResponse();
         }
      });
   }

   private void addSeparator() {
      popup.addSeparator();
   }

   private void addConfig(final IndividualActions actions) {
      addEntry("edit " + actions.getName() + " configuration and reload", new ActionListener() {
         @Override
         public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            actions.editConfiguration();
         }
      });
   }

   private void addExit(final GlobalActions globalActions) {
      addEntry("exit", new ActionListener() {
         @Override
         public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
            globalActions.exit();
         }
      });
   }

}
TOP

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

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.