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.event.ActionEvent;
045: import java.util.Iterator;
046: import javax.swing.Action;
047: import javax.swing.AbstractAction;
048: import javax.swing.ImageIcon;
049:
050: import org.netbeans.modules.debugger.ui.views.View;
051:
052: import org.openide.util.NbBundle;
053: import org.openide.util.Utilities;
054: import org.openide.windows.Mode;
055: import org.openide.windows.TopComponent;
056: import org.openide.windows.WindowManager;
057:
058: /**
059: * Opens View TopComponent.
060: *
061: * @author Jan Jancura, Martin Entlicher
062: */
063: public class ViewActions extends AbstractAction {
064:
065: private String viewName;
066:
067: private ViewActions(String viewName) {
068: this .viewName = viewName;
069: }
070:
071: public Object getValue(String key) {
072: if (key == Action.NAME) {
073: return NbBundle.getMessage(ViewActions.class,
074: (String) super .getValue(key));
075: }
076: Object value = super .getValue(key);
077: if (key == Action.SMALL_ICON) {
078: if (value instanceof String) {
079: value = new ImageIcon(Utilities
080: .loadImage((String) value));
081: }
082: }
083: return value;
084: }
085:
086: public void actionPerformed(ActionEvent evt) {
087: openComponent(viewName, true);
088: }
089:
090: static TopComponent openComponent(String viewName, boolean activate) {
091: TopComponent view = WindowManager.getDefault()
092: .findTopComponent(viewName);
093: if (view == null) {
094: throw new IllegalArgumentException(viewName);
095: }
096: view.open();
097: if (activate) {
098: view.requestActive();
099: }
100: return view;
101: }
102:
103: /**
104: * Creates an action that opens Breakpoints TopComponent.
105: */
106: public static Action createBreakpointsViewAction() {
107: ViewActions action = new ViewActions("breakpointsView");
108: action.putValue(Action.NAME, "CTL_BreakpointsAction");
109: action.putValue(Action.SMALL_ICON,
110: "org/netbeans/modules/debugger/resources/breakpointsView/Breakpoint.gif" // NOI18N
111: );
112: return action;
113: }
114:
115: /**
116: * Creates an action that opens Call Stack TopComponent.
117: */
118: public static Action createCallStackViewAction() {
119: ViewActions action = new ViewActions("callstackView");
120: action.putValue(Action.NAME, "CTL_CallStackAction");
121: action.putValue(Action.SMALL_ICON,
122: "org/netbeans/modules/debugger/resources/callStackView/call_stack_16.png" // NOI18N
123: );
124: return action;
125: }
126:
127: /**
128: * Creates an action that opens Local Variables TopComponent.
129: */
130: public static Action createLocalsViewAction() {
131: ViewActions action = new ViewActions("localsView");
132: action.putValue(Action.NAME, "CTL_LocalVariablesAction");
133: action.putValue(Action.SMALL_ICON,
134: "org/netbeans/modules/debugger/resources/localsView/local_variable_16.png" // NOI18N
135: );
136: return action;
137: }
138:
139: /**
140: * Creates an action that opens Sessions TopComponent.
141: */
142: public static Action createSessionsViewAction() {
143: ViewActions action = new ViewActions("sessionsView");
144: action.putValue(Action.NAME, "CTL_SessionsAction");
145: action.putValue(Action.SMALL_ICON,
146: "org/netbeans/modules/debugger/resources/sessionsView/session_16.png" // NOI18N
147: );
148: return action;
149: }
150:
151: /**
152: * Creates an action that opens Threads TopComponent.
153: */
154: public static Action createThreadsViewAction() {
155: ViewActions action = new ViewActions("threadsView");
156: action.putValue(Action.NAME, "CTL_ThreadsAction");
157: action.putValue(Action.SMALL_ICON,
158: "org/netbeans/modules/debugger/resources/threadsView/ThreadGroup.gif" // NOI18N
159: );
160: return action;
161: }
162:
163: /**
164: * Creates an action that opens Watches TopComponent.
165: */
166: public static Action createWatchesViewAction() {
167: ViewActions action = new ViewActions("watchesView");
168: action.putValue(Action.NAME, "CTL_WatchesAction");
169: action.putValue(Action.SMALL_ICON,
170: "org/netbeans/modules/debugger/resources/watchesView/watch_16.png" // NOI18N
171: );
172: return action;
173: }
174:
175: }
|