annotate agent/src/share/classes/sun/jvm/hotspot/ui/SourceCodePanel.java @ 152:c70a245cad3a

6670684: 4/5 SA command universe did not print out CMS space information Summary: Forward port of Yumin's fix for 6670684 from HSX-11; Yumin verified the port was correct. Reviewed-by: dcubed
author dcubed
date Fri, 09 May 2008 08:55:13 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.ui;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.net.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import javax.swing.text.BadLocationException;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 /** Panel supporting loading of and scrolling through source code.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 Contains convenience routines for implementing the Editor
a61af66fc99e Initial load
duke
parents:
diff changeset
37 interface. */
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public class SourceCodePanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private JTextArea source;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private RowHeader header;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private String filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Amount of white space between edges, line numbers and icons
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private static final int LINE_NO_SPACE = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Size of icons in resources directory
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private static final int ICON_SIZE = 12;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Icons used in panel drawing
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private static Icon topFrameCurLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static Icon lowerFrameCurLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static Icon breakpoint;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // State
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private int highlightedLine = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private Set/*<Integer>*/ breakpoints = new HashSet(); // Zero-based lines internally
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Parent Editor container and EditorCommands object for setting breakpoints
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private EditorCommands comm;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private Editor parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 /** Support for displaying icons and line numbers in row header of
a61af66fc99e Initial load
duke
parents:
diff changeset
59 scroll pane */
a61af66fc99e Initial load
duke
parents:
diff changeset
60 class RowHeader extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private JViewport view;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 private boolean showLineNumbers;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 private int width;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 private int rowHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 private boolean initted;
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public RowHeader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 initted = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public void ancestorResized(HierarchyEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 recomputeSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 });
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public void paint(Graphics g) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 super.paint(g);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 if (getShowLineNumbers()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Visible region of header panel, in coordinate system of the
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // panel, is provided by clip bounds of Graphics object. This
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // is used to figure out which line numbers to draw.
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Rectangle clip = g.getClipBounds();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // To avoid missing lines, round down starting line number and
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // round up ending line number
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int start = clip.y / rowHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int end = start + (clip.height + (rowHeight - 1)) / rowHeight;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Draw these line numbers, right justified to look better
a61af66fc99e Initial load
duke
parents:
diff changeset
89 FontMetrics fm = getFontMetrics(getFont());
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int ascent = fm.getMaxAscent(); // Causes proper alignment -- trial-and-error
a61af66fc99e Initial load
duke
parents:
diff changeset
91 for (int i = start; i <= end; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Line numbers are 1-based
a61af66fc99e Initial load
duke
parents:
diff changeset
93 String str = Integer.toString(i + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 int strWidth = GraphicsUtilities.getStringWidth(str, fm);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 g.drawString(str, width - strWidth - LINE_NO_SPACE, ascent + rowHeight * i);
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Draw breakpoint if necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (breakpoints.contains(new Integer(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 breakpoint.paintIcon(this, g, LINE_NO_SPACE, rowHeight * i);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Draw current line icon if necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (i == highlightedLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // FIXME: use correct icon (not always topmost frame)
a61af66fc99e Initial load
duke
parents:
diff changeset
105 topFrameCurLine.paintIcon(this, g, LINE_NO_SPACE, rowHeight * i);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public boolean getShowLineNumbers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return showLineNumbers;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public void setShowLineNumbers(boolean val) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 if (val != showLineNumbers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 showLineNumbers = val;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 recomputeSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Force re-layout
a61af66fc99e Initial load
duke
parents:
diff changeset
120 invalidate();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 validate();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public void setFont(Font f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 super.setFont(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 rowHeight = getFontMetrics(f).getHeight();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 recomputeSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void setViewport(JViewport view) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 this.view = view;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void recomputeSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 if (!initted) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (view == null) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 width = ICON_SIZE + 2 * LINE_NO_SPACE;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 int numLines = 1 + source.getLineOfOffset(source.getDocument().getEndPosition().getOffset() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 String str = Integer.toString(numLines);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (getShowLineNumbers()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Compute width based on whether we are drawing line numbers
a61af66fc99e Initial load
duke
parents:
diff changeset
144 width += GraphicsUtilities.getStringWidth(str, getFontMetrics(getFont())) + LINE_NO_SPACE;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // FIXME: add on width for all icons (breakpoint, current line,
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // current line in caller frame)
a61af66fc99e Initial load
duke
parents:
diff changeset
148 Dimension d = new Dimension(width, numLines * getFontMetrics(getFont()).getHeight());
a61af66fc99e Initial load
duke
parents:
diff changeset
149 setSize(d);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 setPreferredSize(d);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 } catch (BadLocationException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public SourceCodePanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 maybeLoadIcons();
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Build user interface
a61af66fc99e Initial load
duke
parents:
diff changeset
161 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 source = new JTextArea();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 source.setEditable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 source.getCaret().setVisible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 header = new RowHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 header.setShowLineNumbers(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 JScrollPane scroller = new JScrollPane(source);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 JViewport rowView = new JViewport();
a61af66fc99e Initial load
duke
parents:
diff changeset
169 rowView.setView(header);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 header.setViewport(rowView);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 rowView.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 scroller.setRowHeader(rowView);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 add(scroller, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // Reset font now that header and source are present
a61af66fc99e Initial load
duke
parents:
diff changeset
175 setFont(getFont());
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 source.addFocusListener(new FocusAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public void focusGained(FocusEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 source.getCaret().setVisible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 });
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 source.addKeyListener(new KeyAdapter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 public void keyPressed(KeyEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (e.getKeyCode() == KeyEvent.VK_F9) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 int lineNo = getCurrentLineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Only the debugger can figure out whether we are setting
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // or clearing a breakpoint, since it has the debug
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // information available and knows whether we're on a
a61af66fc99e Initial load
duke
parents:
diff changeset
190 // valid line
a61af66fc99e Initial load
duke
parents:
diff changeset
191 comm.toggleBreakpointAtLine(parent, lineNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 });
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public void setFont(Font f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 super.setFont(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (source != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 source.setFont(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (header != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 header.setFont(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 public boolean getShowLineNumbers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return header.getShowLineNumbers();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 public void setShowLineNumbers(boolean val) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 header.setShowLineNumbers(val);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 public boolean openFile(String filename) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 this.filename = filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
219 File file = new File(filename);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 int len = (int) file.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 StringBuffer buf = new StringBuffer(len); // Approximation
a61af66fc99e Initial load
duke
parents:
diff changeset
222 char[] tmp = new char[4096];
a61af66fc99e Initial load
duke
parents:
diff changeset
223 FileReader in = new FileReader(file);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 int res = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 res = in.read(tmp, 0, tmp.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 if (res >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
228 buf.append(tmp, 0, res);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 } while (res != -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 in.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 String text = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 source.setText(text);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 header.recomputeSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 } catch (IOException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public String getSourceFileName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 return filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 /** Line number is one-based */
a61af66fc99e Initial load
duke
parents:
diff changeset
246 public int getCurrentLineNumber() {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return 1 + source.getLineOfOffset(source.getCaretPosition());
a61af66fc99e Initial load
duke
parents:
diff changeset
249 } catch (BadLocationException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
a61af66fc99e Initial load
duke
parents:
diff changeset
254 /** Line number is one-based */
a61af66fc99e Initial load
duke
parents:
diff changeset
255 public void showLineNumber(int lineNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int offset = source.getLineStartOffset(lineNo - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 Rectangle rect = source.modelToView(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (rect == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 source.scrollRectToVisible(rect);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 } catch (BadLocationException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 /** Line number is one-based */
a61af66fc99e Initial load
duke
parents:
diff changeset
269 public void highlightLineNumber(int lineNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 highlightedLine = lineNo - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 public void showBreakpointAtLine(int lineNo) { breakpoints.add(new Integer(lineNo - 1)); repaint(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 public boolean hasBreakpointAtLine(int lineNo){ return breakpoints.contains(new Integer(lineNo - 1)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 public void clearBreakpointAtLine(int lineNo) { breakpoints.remove(new Integer(lineNo - 1)); repaint(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 public void clearBreakpoints() { breakpoints.clear(); repaint(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 public void setEditorCommands(EditorCommands comm, Editor parent) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 this.comm = comm;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 this.parent = parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 public void requestFocus() {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 source.requestFocus();
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
289 //
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 private void maybeLoadIcons() {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if (topFrameCurLine == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
293 topFrameCurLine = loadIcon("resources/arrow.png");
a61af66fc99e Initial load
duke
parents:
diff changeset
294 lowerFrameCurLine = loadIcon("resources/triangle.png");
a61af66fc99e Initial load
duke
parents:
diff changeset
295 breakpoint = loadIcon("resources/breakpoint.png");
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 private Icon loadIcon(String which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 URL url = getClass().getResource(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return new ImageIcon(url);
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }