View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  package org.xmlhammer.gui.actions;
22  
23  import java.awt.event.ActionEvent;
24  
25  import javax.swing.AbstractAction;
26  import javax.swing.Action;
27  import javax.swing.ImageIcon;
28  import javax.swing.JButton;
29  import javax.swing.JPopupMenu;
30  
31  public class NewCompositeAction extends AbstractAction {
32      private static final long serialVersionUID = 7225392795009711541L;
33      JPopupMenu popup = null;
34      
35      public NewCompositeAction() {
36          putValue( SMALL_ICON, new ImageIcon(getClass().getResource("/org/xmlhammer/gui/icons/etool16/new_wiz_badge.gif")));
37          putValue( NAME, "New");
38          putValue( SHORT_DESCRIPTION, "New Project");
39      }
40      
41      private JPopupMenu getPopup() {
42          if (popup == null) {
43              popup = new JPopupMenu();
44          }
45          
46          return popup;
47      }
48      
49      public void add(Action action) {
50          getPopup().add(action);
51      }
52      
53      public void actionPerformed(ActionEvent event) {
54          getPopup().show((JButton)event.getSource(), 0, ((JButton)event.getSource()).getSize().height);
55      }
56  }