|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.ui; |
|
38 |
| |
|
39 |
| import java.util.ArrayList; |
|
40 |
| |
|
41 |
| import javax.swing.*; |
|
42 |
| import javax.swing.tree.*; |
|
43 |
| import javax.swing.text.BadLocationException; |
|
44 |
| import java.awt.event.*; |
|
45 |
| import java.awt.*; |
|
46 |
| |
|
47 |
| import edu.rice.cs.plt.lambda.Lambda; |
|
48 |
| import edu.rice.cs.drjava.model.RegionManager; |
|
49 |
| import edu.rice.cs.drjava.model.RegionManagerListener; |
|
50 |
| import edu.rice.cs.drjava.model.debug.*; |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public class BreakpointsPanel extends RegionsTreePanel<Breakpoint> { |
|
57 |
| protected JButton _goToButton; |
|
58 |
| protected JButton _enableDisableButton; |
|
59 |
| protected JButton _removeButton; |
|
60 |
| protected JButton _removeAllButton; |
|
61 |
| protected final Debugger _debugger; |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
38
| public BreakpointsPanel(MainFrame frame, RegionManager<Breakpoint> breakpointManager) {
|
|
68 |
38
| super(frame, "Breakpoints", breakpointManager);
|
|
69 |
| |
|
70 |
38
| _regionManager.addListener(new RegionManagerListener<Breakpoint>() {
|
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
0
| public void regionAdded(final Breakpoint bp) {
|
|
76 |
0
| assert EventQueue.isDispatchThread();
|
|
77 |
0
| addRegion(bp);
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
0
| public void regionChanged(final Breakpoint bp) {
|
|
85 |
0
| assert EventQueue.isDispatchThread();
|
|
86 |
| |
|
87 |
0
| DefaultMutableTreeNode regNode = _regionToTreeNode.get(bp);
|
|
88 |
0
| ((DefaultTreeModel)_regTree.getModel()).nodeChanged(regNode);
|
|
89 |
| } |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
0
| public void regionRemoved(final Breakpoint bp) { removeRegion(bp); }
|
|
96 |
| }); |
|
97 |
38
| _debugger = _model.getDebugger();
|
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
0
| protected void performDefaultAction() { goToRegion(); }
|
|
102 |
| |
|
103 |
| |
|
104 |
38
| protected JComponent[] makeButtons() {
|
|
105 |
38
| Action goToAction = new AbstractAction("Go to") {
|
|
106 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
107 |
0
| goToRegion();
|
|
108 |
| } |
|
109 |
| }; |
|
110 |
38
| _goToButton = new JButton(goToAction);
|
|
111 |
| |
|
112 |
38
| Action enableDisableAction = new AbstractAction("Disable") {
|
|
113 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
114 |
0
| enableDisableBreakpoint();
|
|
115 |
| } |
|
116 |
| }; |
|
117 |
38
| _enableDisableButton = new JButton(enableDisableAction);
|
|
118 |
| |
|
119 |
38
| Action removeAction = new AbstractAction("Remove") {
|
|
120 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
121 |
| |
|
122 |
0
| for (Breakpoint bp: getSelectedRegions()) _regionManager.removeRegion(bp);
|
|
123 |
| |
|
124 |
| } |
|
125 |
| }; |
|
126 |
38
| _removeButton = new JButton(removeAction);
|
|
127 |
| |
|
128 |
38
| Action removeAllAction = new AbstractAction("Remove All") {
|
|
129 |
0
| public void actionPerformed(ActionEvent ae) {
|
|
130 |
| |
|
131 |
0
| _regionManager.clearRegions();
|
|
132 |
| |
|
133 |
| } |
|
134 |
| }; |
|
135 |
38
| _removeAllButton = new JButton(removeAllAction);
|
|
136 |
| |
|
137 |
38
| JComponent[] buts = new JComponent[] {
|
|
138 |
| _enableDisableButton, |
|
139 |
| _goToButton, |
|
140 |
| _removeButton, |
|
141 |
| _removeAllButton |
|
142 |
| }; |
|
143 |
| |
|
144 |
38
| return buts;
|
|
145 |
| } |
|
146 |
| |
|
147 |
| |
|
148 |
38
| protected void _updateButtons() {
|
|
149 |
38
| ArrayList<Breakpoint> regs = getSelectedRegions();
|
|
150 |
38
| _goToButton.setEnabled(regs.size() == 1);
|
|
151 |
38
| _removeButton.setEnabled(regs.size() > 0);
|
|
152 |
38
| _removeAllButton.setEnabled(_rootNode != null && _rootNode.getDepth() > 0);
|
|
153 |
38
| _enableDisableButton.setEnabled(regs.size() > 0);
|
|
154 |
38
| if (regs.size() > 0) {
|
|
155 |
0
| if (regs.get(0).isEnabled()) _enableDisableButton.setText("Disable");
|
|
156 |
0
| else _enableDisableButton.setText("Enable");
|
|
157 |
| } |
|
158 |
38
| _removeAllButton.setEnabled(_rootNode != null && _rootNode.getDepth() > 0);
|
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
0
| protected void closeIfEmpty() {
|
|
163 |
| |
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
38
| protected AbstractAction[] makePopupMenuActions() {
|
|
168 |
38
| AbstractAction[] acts = new AbstractAction[] {
|
|
169 |
| new AbstractAction("Go to") { |
|
170 |
0
| public void actionPerformed(ActionEvent e) { goToRegion(); }
|
|
171 |
| }, |
|
172 |
| |
|
173 |
| new AbstractAction("Remove") { |
|
174 |
0
| public void actionPerformed(ActionEvent e) {
|
|
175 |
0
| for (Breakpoint bp: getSelectedRegions()) _regionManager .removeRegion(bp);
|
|
176 |
| } |
|
177 |
| } |
|
178 |
| }; |
|
179 |
38
| return acts;
|
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
0
| protected void goToRegion() {
|
|
184 |
0
| ArrayList<Breakpoint> bps = getSelectedRegions();
|
|
185 |
0
| if (bps.size() == 1) _debugger.scrollToSource(bps.get(0));
|
|
186 |
| } |
|
187 |
| |
|
188 |
| |
|
189 |
0
| protected void enableDisableBreakpoint() {
|
|
190 |
0
| final ArrayList<Breakpoint> bps = getSelectedRegions();
|
|
191 |
0
| if (bps.size() > 0) {
|
|
192 |
0
| final boolean newState = !bps.get(0).isEnabled();
|
|
193 |
0
| for (Breakpoint bp: bps) {
|
|
194 |
0
| _regionManager.changeRegion(bp, new Lambda<Breakpoint,Object>() {
|
|
195 |
0
| public Object value(Breakpoint bp) {
|
|
196 |
0
| bp.setEnabled(newState);
|
|
197 |
0
| return null;
|
|
198 |
| } |
|
199 |
| }); |
|
200 |
| } |
|
201 |
| } |
|
202 |
| } |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
0
| protected RegionTreeUserObj<Breakpoint> makeRegionTreeUserObj(Breakpoint bp) {
|
|
208 |
0
| return new BreakpointRegionTreeUserObj(bp);
|
|
209 |
| } |
|
210 |
| |
|
211 |
| |
|
212 |
| protected static class BreakpointRegionTreeUserObj extends RegionTreeUserObj<Breakpoint> { |
|
213 |
0
| public BreakpointRegionTreeUserObj (Breakpoint bp) { super(bp); }
|
|
214 |
0
| public String toString() {
|
|
215 |
0
| final StringBuilder sb = new StringBuilder();
|
|
216 |
0
| sb.append(lineNumber());
|
|
217 |
0
| try {
|
|
218 |
0
| if (!_region.isEnabled()) { sb.append(" (disabled)"); }
|
|
219 |
0
| sb.append(": ");
|
|
220 |
0
| int length = Math.min(120, _region.getEndOffset()-_region.getStartOffset());
|
|
221 |
0
| sb.append(_region.getDocument().getText(_region.getStartOffset(), length).trim());
|
|
222 |
| } catch(BadLocationException bpe) { } |
|
223 |
0
| return sb.toString();
|
|
224 |
| } |
|
225 |
| } |
|
226 |
| } |