KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > breakpoints > BreakpointAnnotationListener


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.breakpoints;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26 import org.netbeans.api.debugger.Breakpoint;
27 import org.netbeans.api.debugger.DebuggerManager;
28 import org.netbeans.api.debugger.DebuggerManagerAdapter;
29 import org.netbeans.modules.scripting.php.dbginterface.DebuggerAnnotation;
30 import org.netbeans.modules.scripting.php.dbginterface.breakpoints.*;
31
32
33 /**
34  * Listens on {@org.netbeans.api.debugger.DebuggerManager} on
35  * {@link org.netbeans.api.debugger.DebuggerManager#PROP_BREAKPOINTS}
36  * property and annotates JPDA Debugger line breakpoints in NetBeans editor.
37  *
38  * @author Jan Jancura
39  */

40 public class BreakpointAnnotationListener extends DebuggerManagerAdapter
41     implements PropertyChangeListener JavaDoc {
42
43     private Map JavaDoc<Breakpoint, DebuggerAnnotation> breakpointToAnnotation = new HashMap JavaDoc<Breakpoint, DebuggerAnnotation>();
44
45
46     public String JavaDoc[] getProperties() {
47         return new String JavaDoc[] { DebuggerManager.PROP_BREAKPOINTS };
48     }
49
50     /**
51      * Called when some breakpoint is added.
52      *
53      * @param b breakpoint
54      */

55     public void breakpointAdded(Breakpoint b) {
56         if (! (b instanceof PhpBreakpoint)) {
57             return;
58         }
59         addAnnotation(b);
60     }
61
62     /**
63      * Called when some breakpoint is removed.
64      *
65      * @param breakpoint
66      */

67     public void breakpointRemoved(Breakpoint b) {
68         if (! (b instanceof PhpBreakpoint)) {
69             return;
70         }
71         removeAnnotation(b);
72     }
73
74     /**
75      * This method gets called when a bound property is changed.
76      * @param evt A PropertyChangeEvent object describing the event source
77      * and the property that has changed.
78      */

79
80     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
81         if (evt.getPropertyName() != Breakpoint.PROP_ENABLED) {
82             return;
83         }
84         removeAnnotation((Breakpoint) evt.getSource());
85         addAnnotation((Breakpoint) evt.getSource());
86     }
87
88     private void addAnnotation(Breakpoint b) {
89         breakpointToAnnotation.put(b,
90             new DebuggerAnnotation(
91             b.isEnabled() ?
92                 DebuggerAnnotation.BREAKPOINT_ANNOTATION_TYPE :
93                 DebuggerAnnotation.DISABLED_BREAKPOINT_ANNOTATION_TYPE,
94             ((PhpBreakpoint) b).getLine()));
95         b.addPropertyChangeListener(Breakpoint.PROP_ENABLED, this);
96     }
97
98     private void removeAnnotation(Breakpoint b) {
99         DebuggerAnnotation annotation = (DebuggerAnnotation)
100         breakpointToAnnotation.remove(b);
101         
102         if (annotation == null) {
103             return;
104         }
105         
106         annotation.detach();
107         b.removePropertyChangeListener(Breakpoint.PROP_ENABLED, this);
108     }
109 }
110
Popular Tags