annotate agent/src/share/classes/sun/jvm/hotspot/ui/Annotation.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
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 2000-2003 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.font.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.awt.geom.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 /** This can be extended, along with AnnotatedMemoryPanel, to be an
a61af66fc99e Initial load
duke
parents:
diff changeset
36 arbitrarily complex mechanism, supporting user interaction,
a61af66fc99e Initial load
duke
parents:
diff changeset
37 etc. */
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public class Annotation {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private Interval interval;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // List<String>
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private java.util.List strings;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // List<Integer>
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private java.util.List heights;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private Color baseColor;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private int width;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private int height;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private int x;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private int y;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 /** The Annotation can handle the sense of lowAddress and
a61af66fc99e Initial load
duke
parents:
diff changeset
52 highAddress being swapped. */
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public Annotation(Address lowAddress,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 Address highAddress,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 String s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 strings = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 heights = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 for (StringTokenizer tok = new StringTokenizer(s, "\n"); tok.hasMoreTokens(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 strings.add(tok.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (AddressOps.lessThan(highAddress, lowAddress)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 Address temp = lowAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 lowAddress = highAddress;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 highAddress = temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 interval = new Interval(lowAddress, highAddress);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public Interval getInterval() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return interval;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public Address getLowAddress() {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return (Address) getInterval().getLowEndpoint();
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 Address getHighAddress() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return (Address) getInterval().getHighEndpoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 /** Draw the annotation at its current (x, y) position with its
a61af66fc99e Initial load
duke
parents:
diff changeset
82 current color */
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public void draw(Graphics g) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 g.setColor(baseColor);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int tmpY = y;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 for (int i = 0; i < strings.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 String s = (String) strings.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 Integer h = (Integer) heights.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 g.drawString(s, x, tmpY);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 tmpY += h.intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 /** Sets the base color of this annotation. The annotation may
a61af66fc99e Initial load
duke
parents:
diff changeset
95 render sub-portions in a different color if desired. */
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public void setColor(Color c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 this.baseColor = c;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 /** Returns the base color of this annotation. */
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public Color getColor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return baseColor;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 /** Computes width and height for this Annotation. Retrieve the
a61af66fc99e Initial load
duke
parents:
diff changeset
106 computed information using getWidth() and getHeight(). Separated
a61af66fc99e Initial load
duke
parents:
diff changeset
107 because the width and height only need to be recomputed if the
a61af66fc99e Initial load
duke
parents:
diff changeset
108 font changes. */
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public void computeWidthAndHeight(Graphics g) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 width = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 height = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 heights.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 for (Iterator iter = strings.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 String s = (String) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 Rectangle2D bounds = GraphicsUtilities.getStringBounds(s, g);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 width = Math.max(width, (int) bounds.getWidth());
a61af66fc99e Initial load
duke
parents:
diff changeset
117 height += (int) bounds.getHeight();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 heights.add(new Integer((int) bounds.getHeight()));
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public int getWidth() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return width;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public int getHeight() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return height;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 /** Set the x and y position of this annotation */
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public void setXAndY(int x, int y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 this.x = x; this.y = y;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 public void setX(int x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 this.x = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 public int getX() {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return x;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public void setY(int y) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 this.y = y;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 public int getY() {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return y;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public Rectangle getBounds() {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return new Rectangle(x, y, width, height);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 String result = "Annotation: lowAddr: " + getLowAddress() + " highAddr: " + getHighAddress() + " strings: " + strings.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 for (int i = 0; i < strings.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 result += "\n" + (String) strings.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }