KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > DebuggerManagerListener


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 package org.netbeans.modules.debugger.ui;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import javax.swing.SwingUtilities JavaDoc;
23
24 import org.netbeans.api.debugger.DebuggerEngine;
25 import org.netbeans.api.debugger.DebuggerManager;
26 import org.netbeans.api.debugger.DebuggerManagerAdapter;
27
28 import org.openide.awt.ToolbarPool;
29 import org.openide.windows.TopComponentGroup;
30 import org.openide.windows.WindowManager;
31
32
33 /**
34  * This listener notifies about changes in the
35  * {@link DebuggerManager}.
36  *
37  * @author Jan Jancura
38  */

39 public class DebuggerManagerListener extends DebuggerManagerAdapter {
40     
41     private boolean isOpened = false;
42     
43     public void propertyChange (PropertyChangeEvent JavaDoc evt) {
44         if ( (DebuggerManager.getDebuggerManager ().getCurrentEngine ()
45                != null) &&
46              (!isOpened)
47         ) {
48             // Open debugger TopComponentGroup.
49
SwingUtilities.invokeLater (new Runnable JavaDoc () {
50                 public void run () {
51                     TopComponentGroup group = WindowManager.getDefault ().
52                         findTopComponentGroup ("debugger"); // NOI18N
53
if (group != null) {
54                         group.open ();
55                         if (ToolbarPool.getDefault ().
56                             getConfiguration ().equals
57                             (ToolbarPool.DEFAULT_CONFIGURATION)
58                         )
59                             ToolbarPool.getDefault ().setConfiguration
60                                 ("Debugging"); // NOI18N
61
}
62                 }
63             });
64             isOpened = true;
65         }
66         if ( (evt.getPropertyName () == DebuggerManager.PROP_DEBUGGER_ENGINES)
67                 &&
68              ((DebuggerEngine[]) evt.getNewValue ()).length == 0
69         ) {
70             closeDebuggerUI();
71             isOpened = false;
72         }
73     }
74     
75     static void closeDebuggerUI() {
76         /*
77         java.util.logging.Logger.getLogger("org.netbeans.modules.debugger.jpda").fine("CLOSING TopComponentGroup...");
78         StringWriter sw = new StringWriter();
79         new Exception("Stack Trace").fillInStackTrace().printStackTrace(new java.io.PrintWriter(sw));
80         java.util.logging.Logger.getLogger("org.netbeans.modules.debugger.jpda").fine(sw.toString());
81          */

82         // Close debugger TopComponentGroup.
83
if (SwingUtilities.isEventDispatchThread()) {
84             doCloseDebuggerUI();
85         } else {
86             SwingUtilities.invokeLater(new Runnable JavaDoc () {
87                 public void run () {
88                     doCloseDebuggerUI();
89                 }
90             });
91         }
92         //java.util.logging.Logger.getLogger("org.netbeans.modules.debugger.jpda").fine("TopComponentGroup closed.");
93
}
94     
95     private static void doCloseDebuggerUI() {
96         TopComponentGroup group = WindowManager.getDefault ().
97                 findTopComponentGroup ("debugger"); // NOI18N
98
if (group != null) {
99             group.close ();
100             if (ToolbarPool.getDefault().getConfiguration().equals("Debugging")) { // NOI18N
101
ToolbarPool.getDefault().setConfiguration(ToolbarPool.DEFAULT_CONFIGURATION);
102             }
103         }
104     }
105     
106     public String JavaDoc[] getProperties () {
107         return new String JavaDoc [] {
108             DebuggerManager.PROP_DEBUGGER_ENGINES,
109             DebuggerManager.PROP_CURRENT_ENGINE
110         };
111     }
112     
113 }
114
Popular Tags