KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > debugger > jpda > JPDABreakpoint


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.api.debugger.jpda;
21
22 import com.sun.jdi.request.EventRequest;
23
24 import java.util.Collection JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import org.netbeans.api.debugger.Breakpoint;
29 import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent;
30 import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener;
31
32 /**
33  * Abstract definition of JPDA breakpoint.
34  *
35  * @author Jan Jancura
36  */

37 public class JPDABreakpoint extends Breakpoint {
38
39     // static ..................................................................
40

41     /** Property name constant. */
42     public static final String JavaDoc PROP_SUSPEND = "suspend"; // NOI18N
43
/** Property name constant. */
44     public static final String JavaDoc PROP_HIDDEN = "hidden"; // NOI18N
45
/** Property name constant. */
46     public static final String JavaDoc PROP_PRINT_TEXT = "printText"; // NOI18N
47

48     /** Suspend property value constant. */
49     public static final int SUSPEND_ALL = EventRequest.SUSPEND_ALL;
50     /** Suspend property value constant. */
51     public static final int SUSPEND_EVENT_THREAD = EventRequest.SUSPEND_EVENT_THREAD;
52     /** Suspend property value constant. */
53     public static final int SUSPEND_NONE = EventRequest.SUSPEND_NONE;
54
55     
56     // private variables .....................................................
57

58     /** Set of actions. */
59     private boolean enabled = true;
60     private boolean hidden = false;
61     private int suspend = SUSPEND_ALL;
62     private String JavaDoc printText;
63     private Collection JavaDoc<JPDABreakpointListener> breakpointListeners = new HashSet JavaDoc<JPDABreakpointListener>();
64     
65    
66     JPDABreakpoint () {
67     }
68     
69
70     // main methods ............................................................
71

72     /**
73      * Gets value of suspend property.
74      *
75      * @return value of suspend property
76      */

77     public int getSuspend () {
78         return suspend;
79     }
80
81     /**
82      * Sets value of suspend property.
83      *
84      * @param s a new value of suspend property
85      */

86     public void setSuspend (int s) {
87         if (s == suspend) return;
88         int old = suspend;
89         suspend = s;
90         firePropertyChange (PROP_SUSPEND, new Integer JavaDoc (old), new Integer JavaDoc (s));
91     }
92     
93     /**
94      * Gets value of hidden property.
95      *
96      * @return value of hidden property
97      */

98     public boolean isHidden () {
99         return hidden;
100     }
101
102     /**
103      * Sets value of hidden property.
104      *
105      * @param h a new value of hidden property
106      */

107     public void setHidden (boolean h) {
108         if (h == hidden) return;
109         boolean old = hidden;
110         hidden = h;
111         firePropertyChange (PROP_HIDDEN, Boolean.valueOf (old), Boolean.valueOf (h));
112     }
113     
114     /**
115      * Gets value of print text property.
116      *
117      * @return value of print text property
118      */

119     public String JavaDoc getPrintText () {
120         return printText;
121     }
122
123     /**
124      * Sets value of print text property.
125      *
126      * @param printText a new value of print text property
127      */

128     public void setPrintText (String JavaDoc printText) {
129         if (this.printText == printText) return;
130         String JavaDoc old = this.printText;
131         this.printText = printText;
132         firePropertyChange (PROP_PRINT_TEXT, old, printText);
133     }
134
135     /**
136      * Test whether the breakpoint is enabled.
137      *
138      * @return <code>true</code> if so
139      */

140     public boolean isEnabled () {
141         return enabled;
142     }
143     
144     /**
145      * Disables the breakpoint.
146      */

147     public void disable () {
148         if (!enabled) return;
149         enabled = false;
150         firePropertyChange
151             (PROP_ENABLED, Boolean.TRUE, Boolean.FALSE);
152     }
153     
154     /**
155      * Enables the breakpoint.
156      */

157     public void enable () {
158         if (enabled) return;
159         enabled = true;
160         firePropertyChange
161             (PROP_ENABLED, Boolean.FALSE, Boolean.TRUE);
162     }
163     
164     /**
165      * Adds a JPDABreakpointListener.
166      *
167      * @param listener the listener to add
168      */

169     public synchronized void addJPDABreakpointListener (
170         JPDABreakpointListener listener
171     ) {
172         breakpointListeners.add (listener);
173     }
174
175     /**
176      * Removes a JPDABreakpointListener.
177      *
178      * @param listener the listener to remove
179      */

180     public synchronized void removeJPDABreakpointListener (
181         JPDABreakpointListener listener
182     ){
183         breakpointListeners.remove (listener);
184     }
185
186     /**
187      * Fire JPDABreakpointEvent.
188      *
189      * @param event a event to be fired
190      */

191     void fireJPDABreakpointChange (JPDABreakpointEvent event) {
192         Iterator JavaDoc<JPDABreakpointListener> i =
193                 new HashSet JavaDoc<JPDABreakpointListener>(breakpointListeners).iterator();
194         while (i.hasNext ())
195             i.next().breakpointReached (event);
196     }
197 }
198
Popular Tags