Package net.sf.cannagrower.gui

Source Code of net.sf.cannagrower.gui.PopupMenuEvent

package net.sf.cannagrower.gui;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import net.sf.cannagrower.data.Event;
import net.sf.cannagrower.i18n.Messages;

public class PopupMenuEvent extends JPopupMenu {

  private static final long     serialVersionUID = 1L;
 
  private PanelPlantation plantationViewer;
  /**
   * This is the default constructor
   *
   * @param hardwares Vector where new hardware will be added
   */
  public PopupMenuEvent(PanelPlantation plantationViewer) {
    super();
    this.plantationViewer=plantationViewer;
    initialize();
  }

  /**
   * This method initializes this
   *
   * @return void
   */
  private void initialize() {
    for (Class<?> eventType : Event.getEvents()) {
      // Adding jMenu
      JMenuItem jMenuItem = new JMenuItem();
      jMenuItem.setText(Messages.getMessage(Event.class
          .getSimpleName().toLowerCase()
          + "." + eventType.getSimpleName().toLowerCase()));
      jMenuItem.setIcon(Event.getIcon(eventType));
     
      jMenuItem.setName(eventType.getName());
      jMenuItem
          .addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(
                java.awt.event.ActionEvent e) {
              JMenuItem jMenuItem = (JMenuItem) e.getSource();
              try {
                Event event=(Event) Class.forName(jMenuItem.getName()).newInstance();
                plantationViewer.plantation.getEvents().store(event);
                plantationViewer.getJListEvents().setSelectedValue(event, true);
              } catch (Exception ex) {
                Messages.showException(ex);
              }
            }
          });
      add(jMenuItem);
    }
  }
}
TOP

Related Classes of net.sf.cannagrower.gui.PopupMenuEvent

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.