Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2012 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* If you wish your version of this file to be governed by only the CDDL |
28 |
* or only the GPL Version 2, indicate your decision by adding |
29 |
* "[Contributor] elects to include this software in this distribution |
30 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
31 |
* single choice of license, a recipient has the option to distribute |
32 |
* your version of this file under either the CDDL, the GPL Version 2 or |
33 |
* to extend the choice of license to its licensees as provided above. |
34 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
35 |
* Version 2 license, then the option applies only if the new code is |
36 |
* made subject to such option by the copyright holder. |
37 |
* |
38 |
* Contributor(s): |
39 |
* |
40 |
* Portions Copyrighted 2012 Sun Microsystems, Inc. |
41 |
*/ |
42 |
package org.netbeans.modules.debugger.jpda.ui.models; |
43 |
|
44 |
import java.awt.Dimension; |
45 |
import java.awt.Insets; |
46 |
import java.awt.datatransfer.Transferable; |
47 |
import java.awt.event.ActionEvent; |
48 |
import java.awt.event.ActionListener; |
49 |
import java.beans.PropertyChangeEvent; |
50 |
import java.beans.PropertyChangeListener; |
51 |
import java.io.IOException; |
52 |
import java.util.ArrayList; |
53 |
import java.util.List; |
54 |
import javax.swing.AbstractButton; |
55 |
import javax.swing.ImageIcon; |
56 |
import javax.swing.JToggleButton; |
57 |
import javax.swing.border.EmptyBorder; |
58 |
import org.netbeans.api.debugger.DebuggerEngine; |
59 |
import org.netbeans.api.debugger.DebuggerManager; |
60 |
import org.netbeans.api.debugger.jpda.JPDABreakpoint; |
61 |
import org.netbeans.api.debugger.jpda.JPDADebugger; |
62 |
import org.netbeans.api.debugger.jpda.LineBreakpoint; |
63 |
import org.netbeans.spi.debugger.ContextProvider; |
64 |
import org.netbeans.spi.debugger.DebuggerServiceRegistration; |
65 |
import org.netbeans.spi.viewmodel.ExtendedNodeModel; |
66 |
import org.netbeans.spi.viewmodel.ExtendedNodeModelFilter; |
67 |
import org.netbeans.spi.viewmodel.ModelEvent; |
68 |
import org.netbeans.spi.viewmodel.ModelListener; |
69 |
import org.netbeans.spi.viewmodel.NodeModel; |
70 |
import org.netbeans.spi.viewmodel.UnknownTypeException; |
71 |
import org.openide.util.ImageUtilities; |
72 |
import org.openide.util.NbBundle; |
73 |
import org.openide.util.RequestProcessor; |
74 |
import org.openide.util.WeakListeners; |
75 |
import org.openide.util.datatransfer.PasteType; |
76 |
|
77 |
/** |
78 |
* |
79 |
* @author Martin Entlicher |
80 |
*/ |
81 |
@DebuggerServiceRegistration(path="netbeans-JPDASession/BreakpointsView", types=ExtendedNodeModelFilter.class) |
82 |
public class BreakpointModelActiveSessionFilter implements ExtendedNodeModelFilter, |
83 |
PropertyChangeListener { |
84 |
|
85 |
private static final String DEACTIVATED_LINE_BREAKPOINT = |
86 |
"org/netbeans/modules/debugger/resources/editor/Breakpoint_stroke.png"; // NOI18N |
87 |
private static final String DEACTIVATED_DISABLED_LINE_BREAKPOINT = |
88 |
"org/netbeans/modules/debugger/resources/editor/DisabledBreakpoint_stroke.png"; // NOI18N |
89 |
private static final String DEACTIVATED_NONLINE_BREAKPOINT = |
90 |
"org/netbeans/modules/debugger/resources/editor/Breakpoint_nonline_stroke.png"; // NOI18N |
91 |
private static final String DEACTIVATED_DISABLED_NONLINE_BREAKPOINT = |
92 |
"org/netbeans/modules/debugger/resources/editor/DisabledBreakpoint_nonline_stroke.png"; // NOI18N |
93 |
|
94 |
private static final RequestProcessor RP = new RequestProcessor(BreakpointModelActiveSessionFilter.class.getName()); |
95 |
|
96 |
private JPDADebugger debugger; |
97 |
private final List<ModelListener> listeners = new ArrayList<ModelListener>(); |
98 |
|
99 |
public BreakpointModelActiveSessionFilter(ContextProvider contextProvider) { |
100 |
debugger = contextProvider.lookupFirst(null, JPDADebugger.class); |
101 |
debugger.addPropertyChangeListener(WeakListeners.propertyChange(this, debugger)); |
102 |
} |
103 |
|
104 |
@Override |
105 |
public String getDisplayName(NodeModel original, Object node) throws UnknownTypeException { |
106 |
return original.getDisplayName(node); |
107 |
} |
108 |
|
109 |
@Override |
110 |
public String getShortDescription(NodeModel original, Object node) throws UnknownTypeException { |
111 |
return original.getShortDescription(node); |
112 |
} |
113 |
|
114 |
@Override |
115 |
public String getIconBaseWithExtension(ExtendedNodeModel original, Object node) throws UnknownTypeException { |
116 |
if (debugger.getBreakpointsActive()) { |
117 |
return original.getIconBaseWithExtension(node); |
118 |
} else { |
119 |
if (node instanceof LineBreakpoint) { |
120 |
LineBreakpoint breakpoint = (LineBreakpoint)node; |
121 |
if (!breakpoint.isEnabled()) { |
122 |
return DEACTIVATED_DISABLED_LINE_BREAKPOINT; |
123 |
} else { |
124 |
return DEACTIVATED_LINE_BREAKPOINT; |
125 |
} |
126 |
} else if (node instanceof JPDABreakpoint) { |
127 |
JPDABreakpoint breakpoint = (JPDABreakpoint) node; |
128 |
if (!breakpoint.isEnabled()) { |
129 |
return DEACTIVATED_DISABLED_NONLINE_BREAKPOINT; |
130 |
} else { |
131 |
return DEACTIVATED_NONLINE_BREAKPOINT; |
132 |
} |
133 |
} |
134 |
throw new UnknownTypeException(node); |
135 |
} |
136 |
} |
137 |
|
138 |
@Override |
139 |
public String getIconBase(NodeModel original, Object node) throws UnknownTypeException { |
140 |
throw new UnsupportedOperationException("Not supported, overriden by getIconBaseWithExtension()."); |
141 |
} |
142 |
|
143 |
@Override |
144 |
public void setName(ExtendedNodeModel original, Object node, String name) throws UnknownTypeException { |
145 |
throw new UnsupportedOperationException("Not supported yet."); |
146 |
} |
147 |
|
148 |
@Override |
149 |
public boolean canRename(ExtendedNodeModel original, Object node) throws UnknownTypeException { |
150 |
return original.canRename(node); |
151 |
} |
152 |
|
153 |
@Override |
154 |
public boolean canCopy(ExtendedNodeModel original, Object node) throws UnknownTypeException { |
155 |
return original.canCopy(node); |
156 |
} |
157 |
|
158 |
@Override |
159 |
public boolean canCut(ExtendedNodeModel original, Object node) throws UnknownTypeException { |
160 |
return original.canCut(node); |
161 |
} |
162 |
|
163 |
@Override |
164 |
public Transferable clipboardCopy(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException { |
165 |
return original.clipboardCopy(node); |
166 |
} |
167 |
|
168 |
@Override |
169 |
public Transferable clipboardCut(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException { |
170 |
return original.clipboardCut(node); |
171 |
} |
172 |
|
173 |
@Override |
174 |
public PasteType[] getPasteTypes(ExtendedNodeModel original, Object node, Transferable t) throws UnknownTypeException { |
175 |
return original.getPasteTypes(node, t); |
176 |
} |
177 |
|
178 |
@Override |
179 |
public void propertyChange(PropertyChangeEvent evt) { |
180 |
String propertyName = evt.getPropertyName(); |
181 |
if (JPDADebugger.PROP_BREAKPOINTS_ACTIVE.equals(propertyName)) { |
182 |
fireChangeEvent(new ModelEvent.NodeChanged(this, null, ModelEvent.NodeChanged.ICON_MASK)); |
183 |
} |
184 |
} |
185 |
|
186 |
@Override |
187 |
public void addModelListener(ModelListener l) { |
188 |
synchronized (listeners) { |
189 |
listeners.add(l); |
190 |
} |
191 |
} |
192 |
|
193 |
@Override |
194 |
public void removeModelListener(ModelListener l) { |
195 |
synchronized (listeners) { |
196 |
listeners.remove(l); |
197 |
} |
198 |
} |
199 |
|
200 |
private void fireChangeEvent(ModelEvent me) { |
201 |
List<ModelListener> ls; |
202 |
synchronized (listeners) { |
203 |
ls = new ArrayList<ModelListener>(listeners); |
204 |
} |
205 |
for (ModelListener ml : ls) { |
206 |
ml.modelChanged(me); |
207 |
} |
208 |
} |
209 |
|
210 |
|
211 |
@NbBundle.Messages({"CTL_DeactivateAllBreakpoints=Deactivate all breakpoints", |
212 |
"CTL_ActivateAllBreakpoints=Activate all breakpoints"}) |
213 |
public static AbstractButton createActivateBreakpointsActionButton() { |
214 |
ImageIcon icon = ImageUtilities.loadImageIcon(DEACTIVATED_LINE_BREAKPOINT, false); |
215 |
final JToggleButton button = new JToggleButton(icon); |
216 |
// ensure small size, just for the icon |
217 |
Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8); |
218 |
button.setPreferredSize(size); |
219 |
button.setMargin(new Insets(1, 1, 1, 1)); |
220 |
button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button))); |
221 |
button.setToolTipText(Bundle.CTL_DeactivateAllBreakpoints()); |
222 |
button.setFocusable(false); |
223 |
button.addActionListener(new ActionListener() { |
224 |
@Override |
225 |
public void actionPerformed(ActionEvent e) { |
226 |
DebuggerEngine engine = DebuggerManager.getDebuggerManager().getCurrentEngine(); |
227 |
final JPDADebugger debugger = engine.lookupFirst(null, JPDADebugger.class); |
228 |
final boolean active = !button.isSelected(); |
229 |
if (active) { |
230 |
button.setToolTipText(Bundle.CTL_DeactivateAllBreakpoints()); |
231 |
} else { |
232 |
button.setToolTipText(Bundle.CTL_ActivateAllBreakpoints()); |
233 |
} |
234 |
RP.post(new Runnable() { |
235 |
@Override |
236 |
public void run() { |
237 |
debugger.setBreakpointsActive(active); |
238 |
} |
239 |
}); |
240 |
} |
241 |
}); |
242 |
return button; |
243 |
} |
244 |
|
245 |
} |