KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > actions > SourcesViewAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.debugger.jpda.ui.actions;
22
23
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import javax.swing.AbstractAction JavaDoc;
28 import javax.swing.ImageIcon JavaDoc;
29
30 import org.netbeans.modules.debugger.jpda.ui.views.SourcesView;
31
32 import org.openide.util.NbBundle;
33 import org.openide.util.Utilities;
34 import org.openide.windows.Mode;
35 import org.openide.windows.TopComponent;
36 import org.openide.windows.WindowManager;
37
38
39 /**
40  * Opens Call Stack TopComponent.
41  *
42  * @author Jan Jancura
43  */

44 public class SourcesViewAction extends AbstractAction JavaDoc {
45
46     public SourcesViewAction () {
47         putValue (
48             Action.NAME,
49             NbBundle.getMessage (
50                 SourcesViewAction.class,
51                 "CTL_SourcesViewAction"
52             )
53         );
54         putValue (
55             Action.SMALL_ICON,
56             new ImageIcon JavaDoc (Utilities.loadImage ("org/netbeans/modules/debugger/jpda/resources/root.gif")) // NOI18N
57
);
58     }
59
60     public void actionPerformed (ActionEvent JavaDoc evt) {
61         if (activateComponent (SourcesView.class)) return;
62         SourcesView v = new SourcesView ();
63         v.open ();
64         v.requestActive ();
65     }
66     // TODO Rewrite this code - it creates all TopComponents !!!
67
static boolean activateComponent (Class JavaDoc componentClass) {
68         Iterator JavaDoc it = WindowManager.getDefault ().getModes ().iterator ();
69         while (it.hasNext ()) {
70             Mode m = (Mode) it.next ();
71             TopComponent[] tcs = m.getTopComponents ();
72             int i, k = tcs.length;
73             for (i = 0; i < k; i++)
74                 if (tcs [i].getClass ().equals (componentClass)) {
75                     tcs [i].open ();
76                     tcs [i].requestActive ();
77                     return true;
78                 }
79         }
80         return false;
81     }
82 }
83
84
Popular Tags