Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/aspectj/tools/ajde/netbeans/AJGroupAction.java


1   
2   /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3    *
4    * This file is part of the IDE support for the AspectJ(tm)
5    * programming language; see http://aspectj.org
6    *
7    * The contents of this file are subject to the Mozilla Public License
8    * Version 1.1 (the "License"); you may not use this file except in
9    * compliance with the License. You may obtain a copy of the License at
10   * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11   *
12   * Software distributed under the License is distributed on an "AS IS" basis,
13   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14   * for the specific language governing rights and limitations under the
15   * License.
16   *
17   * The Original Code is AspectJ.
18   *
19   * The Initial Developer of the Original Code is Xerox Corporation. Portions
20   * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21   * All Rights Reserved.
22   *
23   * Contributor(s): Phil Sager (psager@mb.sympatico.ca)
24   */
25   
26   
27  package org.aspectj.tools.ajde.netbeans;
28  
29  import java.awt.event.ActionEvent;
30  import java.awt.Component;
31  import javax.swing.*;
32  
33  import org.openide.awt.JMenuPlus;
34  import org.openide.util.HelpCtx;
35  import org.openide.util.NbBundle;
36  import org.openide.util.actions.Presenter;
37  import org.openide.util.actions.SystemAction;
38  
39  /** Action which just holds a few other SystemAction's for grouping purposes.
40   *
41   * @author  Phil Sager
42   */
43  public class AJGroupAction extends SystemAction implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar {
44      
45      public void actionPerformed(ActionEvent ev) {
46          // do nothing; should not be called
47      }
48      
49      public String getName() {
50          return NbBundle.getMessage(AJGroupAction.class, "LBL_GroupAction");
51      }
52      
53      protected String iconResource() {
54          return "/org/aspectj/ajde/resources/actions/startAjde.gif";
55      }
56      
57      public HelpCtx getHelpCtx() {
58          return HelpCtx.DEFAULT_HELP;
59          // If you will provide context help then use:
60          // return new HelpCtx (AJGroupAction.class);
61      }
62      
63      /** Perform extra initialization of this action's singleton. 
64       * PLEASE do not use constructors for this purpose! */
65        protected void initialize () {
66              super.setEnabled(false);
67        }
68      
69      /** List of system actions to be displayed within this one's toolbar or submenu. */
70      private static final SystemAction[] grouped() {
71          return new SystemAction[] {
72                                      SystemAction.get(AJStartBrowserAction.class),
73                                      SystemAction.get(AJBuildAction.class),
74                                      //SystemAction.get(AJRunAction.class),
75                                      SystemAction.get(AJOptionsAction.class)};
76      }
77      
78      private static Icon icon = null;
79      public JMenuItem getMenuPresenter() {
80          // JMenuPlus reported to avoid a strange Windows-specific native code bug (null pData):
81          JMenu menu = new JMenuPlus(getName());
82          if (icon == null) icon = new ImageIcon(AJGroupAction.class.getResource(iconResource()));
83          menu.setIcon(icon);
84          SystemAction[] grouped = grouped();
85          for (int i = 0; i < grouped.length; i++) {
86              SystemAction action = grouped[i];
87              if (action instanceof Presenter.Menu) {
88                  menu.add(((Presenter.Menu) action).getMenuPresenter());
89              }
90          }
91          return menu;
92      }
93      
94      public JMenuItem getPopupPresenter() {
95          JMenu menu = new JMenu(getName());
96          // Conventional not to set an icon here.
97          SystemAction[] grouped = grouped();
98          for (int i = 0; i < grouped.length; i++) {
99              SystemAction action = grouped[i];
100             if (action == null) {
101                 menu.addSeparator();
102             } else if (action instanceof Presenter.Popup) {
103                 menu.add(((Presenter.Popup) action).getPopupPresenter());
104             }
105         }
106         return menu;
107     }
108     
109     public Component getToolbarPresenter() {
110         JToolBar toolbar = new JToolBar();
111         toolbar.setName(getName());
112             // In JDK 1.3 you may add: getName ()
113         SystemAction[] grouped = grouped();
114         for (int i = 0; i < grouped.length; i++) {
115             SystemAction action = grouped[i];
116             if (action instanceof Presenter.Toolbar && i != 1) {
117                 toolbar.add(((Presenter.Toolbar) action).getToolbarPresenter());
118             }
119         }
120         return toolbar;
121     }
122  
123 }