1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53:
54:
57: public final class TextLayout implements Cloneable
58: {
59: public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy ();
60: ClasspathTextLayoutPeer peer;
61:
62: public static class CaretPolicy
63: {
64: public CaretPolicy ()
65: {
66:
67: }
68:
69: public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2,
70: TextLayout layout)
71: {
72: return layout.peer.getStrongCaret(hit1, hit2);
73: }
74: }
75:
76: public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
77: {
78: AttributedString as = new AttributedString (text);
79: ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
80: peer = tk.getClasspathTextLayoutPeer(as, frc);
81: }
82:
83: public TextLayout (String string, Font font, FontRenderContext frc)
84: {
85: AttributedString as = new AttributedString (string);
86: as.addAttribute (TextAttribute.FONT, font);
87: ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
88: peer = tk.getClasspathTextLayoutPeer(as, frc);
89: }
90:
91: public TextLayout (String string, Map attributes, FontRenderContext frc)
92: {
93: AttributedString as = new AttributedString (string, attributes);
94: ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
95: peer = tk.getClasspathTextLayoutPeer(as, frc);
96: }
97:
98: protected Object clone ()
99: {
100: try
101: {
102: TextLayout tl = (TextLayout) super.clone ();
103: tl.peer = (ClasspathTextLayoutPeer) this.peer.clone();
104: return tl;
105: }
106: catch (CloneNotSupportedException e)
107: {
108:
109: throw new InternalError ();
110: }
111: }
112:
113:
114: public void draw (Graphics2D g2, float x, float y)
115: {
116: peer.draw(g2, x, y);
117: }
118:
119: public boolean equals (Object obj)
120: {
121: if (! (obj instanceof TextLayout))
122: return false;
123:
124: return equals ((TextLayout) obj);
125: }
126:
127: public boolean equals (TextLayout tl)
128: {
129: return this.peer.equals(tl.peer);
130: }
131:
132: public float getAdvance ()
133: {
134: return peer.getAdvance();
135: }
136:
137: public float getAscent ()
138: {
139: return peer.getAscent();
140: }
141:
142: public byte getBaseline ()
143: {
144: return peer.getBaseline();
145: }
146:
147: public float[] getBaselineOffsets ()
148: {
149: return peer.getBaselineOffsets();
150: }
151:
152: public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
153: {
154: return peer.getBlackBoxBounds(firstEndpoint, secondEndpoint);
155: }
156:
157: public Rectangle2D getBounds()
158: {
159: return peer.getBounds();
160: }
161:
162: public float[] getCaretInfo (TextHitInfo hit)
163: {
164: return getCaretInfo(hit, getBounds());
165: }
166:
167: public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)
168: {
169: return peer.getCaretInfo(hit, bounds);
170: }
171:
172: public Shape getCaretShape (TextHitInfo hit)
173: {
174: return getCaretShape(hit, getBounds());
175: }
176:
177: public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)
178: {
179: return peer.getCaretShape(hit, bounds);
180: }
181:
182: public Shape[] getCaretShapes (int offset)
183: {
184: return getCaretShapes(offset, getBounds());
185: }
186:
187: public Shape[] getCaretShapes (int offset, Rectangle2D bounds)
188: {
189: return getCaretShapes(offset, getBounds(), DEFAULT_CARET_POLICY);
190: }
191:
192: public Shape[] getCaretShapes (int offset, Rectangle2D bounds,
193: TextLayout.CaretPolicy policy)
194: {
195: return peer.getCaretShapes(offset, bounds, policy);
196: }
197:
198: public int getCharacterCount ()
199: {
200: return peer.getCharacterCount();
201: }
202:
203: public byte getCharacterLevel (int index)
204: {
205: return peer.getCharacterLevel(index);
206: }
207:
208: public float getDescent ()
209: {
210: return peer.getDescent();
211: }
212:
213: public TextLayout getJustifiedLayout (float justificationWidth)
214: {
215: return peer.getJustifiedLayout(justificationWidth);
216: }
217:
218: public float getLeading ()
219: {
220: return peer.getLeading();
221: }
222:
223: public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint)
224: {
225: return getLogicalHighlightShape (firstEndpoint, secondEndpoint, getBounds());
226: }
227:
228: public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
229: Rectangle2D bounds)
230: {
231: return peer.getLogicalHighlightShape(firstEndpoint, secondEndpoint, bounds);
232: }
233:
234: public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
235: TextHitInfo secondEndpoint)
236: {
237: return peer.getLogicalRangesForVisualSelection(firstEndpoint, secondEndpoint);
238: }
239:
240: public TextHitInfo getNextLeftHit (int offset)
241: {
242: return getNextLeftHit(offset, DEFAULT_CARET_POLICY);
243: }
244:
245: public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy)
246: {
247: return peer.getNextLeftHit(offset, policy);
248: }
249:
250: public TextHitInfo getNextLeftHit (TextHitInfo hit)
251: {
252: return getNextLeftHit(hit.getCharIndex());
253: }
254:
255: public TextHitInfo getNextRightHit (int offset)
256: {
257: return getNextRightHit(offset, DEFAULT_CARET_POLICY);
258: }
259:
260: public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy)
261: {
262: return peer.getNextRightHit(offset, policy);
263: }
264:
265: public TextHitInfo getNextRightHit (TextHitInfo hit)
266: {
267: return getNextRightHit(hit.getCharIndex());
268: }
269:
270: public Shape getOutline (AffineTransform tx)
271: {
272: return peer.getOutline(tx);
273: }
274:
275: public float getVisibleAdvance ()
276: {
277: return peer.getVisibleAdvance();
278: }
279:
280: public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
281: TextHitInfo secondEndpoint)
282: {
283: return getVisualHighlightShape(firstEndpoint, secondEndpoint, getBounds());
284: }
285:
286: public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
287: TextHitInfo secondEndpoint,
288: Rectangle2D bounds)
289: {
290: return peer.getVisualHighlightShape(firstEndpoint, secondEndpoint, bounds);
291: }
292:
293: public TextHitInfo getVisualOtherHit (TextHitInfo hit)
294: {
295: return peer.getVisualOtherHit(hit);
296: }
297:
298: protected void handleJustify (float justificationWidth)
299: {
300: peer.handleJustify(justificationWidth);
301: }
302:
303: public int hashCode ()
304: {
305: return peer.hashCode();
306: }
307:
308: public TextHitInfo hitTestChar (float x, float y)
309: {
310: return hitTestChar(x, y, getBounds());
311: }
312:
313: public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)
314: {
315: return peer.hitTestChar(x, y, bounds);
316: }
317:
318: public boolean isLeftToRight ()
319: {
320: return peer.isLeftToRight();
321: }
322:
323: public boolean isVertical ()
324: {
325: return peer.isVertical();
326: }
327:
328: public String toString ()
329: {
330: return peer.toString();
331: }
332: }