001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.ui.actions;
043:
044: import java.awt.Component;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import java.awt.image.BufferedImage;
048: import java.beans.PropertyChangeListener;
049: import javax.swing.Action;
050: import javax.swing.ImageIcon;
051: import javax.swing.JButton;
052: import javax.swing.JMenuItem;
053: import javax.swing.JPopupMenu;
054: import org.netbeans.spi.project.ActionProvider;
055: import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions;
056: import org.openide.awt.Actions;
057: import org.openide.awt.DropDownButtonFactory;
058: import org.openide.util.Exceptions;
059: import org.openide.util.Lookup;
060: import org.openide.util.NbBundle;
061: import org.openide.util.Utilities;
062: import org.openide.util.actions.Presenter;
063: import org.openide.util.lookup.Lookups;
064:
065: /**
066: *
067: * @author Martin Entlicher
068: */
069: public class DebugMainProjectAction implements Action,
070: Presenter.Toolbar {
071:
072: private Action delegate;
073:
074: /** Creates a new instance of DebugMainProjectAction */
075: public DebugMainProjectAction() {
076: delegate = MainProjectSensitiveActions
077: .mainProjectCommandAction(
078: ActionProvider.COMMAND_DEBUG,
079: NbBundle.getMessage(
080: DebugMainProjectAction.class,
081: "LBL_DebugMainProjectAction_Name"),
082: new ImageIcon(
083: Utilities
084: .loadImage("org/netbeans/modules/debugger/resources/debugProject.png"))); // NOI18N
085: delegate
086: .putValue("iconBase",
087: "org/netbeans/modules/debugger/resources/debugProject.png"); //NOI18N
088: }
089:
090: public Object getValue(String arg0) {
091: return delegate.getValue(arg0);
092: }
093:
094: public void putValue(String arg0, Object arg1) {
095: delegate.putValue(arg0, arg1);
096: }
097:
098: public void setEnabled(boolean arg0) {
099: delegate.setEnabled(arg0);
100: }
101:
102: public boolean isEnabled() {
103: return delegate.isEnabled();
104: }
105:
106: public void addPropertyChangeListener(PropertyChangeListener arg0) {
107: delegate.addPropertyChangeListener(arg0);
108: }
109:
110: public void removePropertyChangeListener(PropertyChangeListener arg0) {
111: delegate.removePropertyChangeListener(arg0);
112: }
113:
114: public void actionPerformed(ActionEvent arg0) {
115: delegate.actionPerformed(arg0);
116: }
117:
118: public Component getToolbarPresenter() {
119: JPopupMenu menu = new JPopupMenu();
120: JButton button = DropDownButtonFactory.createDropDownButton(
121: new ImageIcon(new BufferedImage(16, 16,
122: BufferedImage.TYPE_INT_ARGB)), menu);
123: JMenuItem item = new JMenuItem(Actions
124: .cutAmpersand((String) getValue(NAME)));//"<html><b>"+Actions.cutAmpersand((String) getValue(NAME))+"</b></html>") {
125: item.setEnabled(delegate.isEnabled());
126: menu.add(item);
127: item.addActionListener(new ActionListener() {
128: public void actionPerformed(ActionEvent e) {
129: DebugMainProjectAction.this .actionPerformed(e);
130: }
131: });
132: try {
133: final ConnectAction ca = (ConnectAction) Lookups
134: .forPath("Actions/Debug")
135: .lookup(
136: new Lookup.Template(
137: Action.class,
138: "Actions/Debug/org-netbeans-modules-debugger-ui-actions-ConnectAction",
139: null)) // NOI18N
140: .allInstances().iterator().next();
141: item = new JMenuItem(Actions.cutAmpersand((String) ca
142: .getValue(NAME)));
143: Actions.connect(item, ca);
144: menu.add(item);
145: } catch (java.util.NoSuchElementException nsee) {
146: Exceptions.printStackTrace(nsee);
147: }
148: Actions.connect(button, this);
149: return button;
150: }
151:
152: }
|