KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > debugger > 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.debugger.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
29 import org.netbeans.api.debugger.DebuggerManagerAdapter;
30 import org.netbeans.modules.ant.debugger.DebuggerAnnotation;
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 breakpointToAnnotation = new HashMap JavaDoc ();
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 AntBreakpoint)) return;
57         addAnnotation (b);
58     }
59
60     /**
61     * Called when some breakpoint is removed.
62     *
63     * @param breakpoint
64     */

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

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