author | avstepan |
Mon, 11 Jan 2016 17:51:54 +0300 | |
changeset 35667 | ed476aba94de |
parent 25859 | 3317bb8137f4 |
child 45025 | 9ad3afa82b5e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22260
c9185e010e03
8031082: Fix non-missing doclint problems in client libraries
darcy
parents:
21777
diff
changeset
|
2 |
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt; |
|
27 |
||
28 |
import java.awt.RenderingHints.Key; |
|
29 |
import java.awt.geom.AffineTransform; |
|
30 |
import java.awt.image.ImageObserver; |
|
31 |
import java.awt.image.BufferedImageOp; |
|
32 |
import java.awt.image.BufferedImage; |
|
33 |
import java.awt.image.RenderedImage; |
|
34 |
import java.awt.image.renderable.RenderableImage; |
|
35 |
import java.awt.font.GlyphVector; |
|
36 |
import java.awt.font.FontRenderContext; |
|
37 |
import java.awt.font.TextAttribute; |
|
38 |
import java.text.AttributedCharacterIterator; |
|
39 |
import java.util.Map; |
|
40 |
||
41 |
/** |
|
35667 | 42 |
* This {@code Graphics2D} class extends the |
2 | 43 |
* {@link Graphics} class to provide more sophisticated |
44 |
* control over geometry, coordinate transformations, color management, |
|
45 |
* and text layout. This is the fundamental class for rendering |
|
46 |
* 2-dimensional shapes, text and images on the Java(tm) platform. |
|
22260
c9185e010e03
8031082: Fix non-missing doclint problems in client libraries
darcy
parents:
21777
diff
changeset
|
47 |
* |
2 | 48 |
* <h2>Coordinate Spaces</h2> |
35667 | 49 |
* All coordinates passed to a {@code Graphics2D} object are specified |
2 | 50 |
* in a device-independent coordinate system called User Space, which is |
35667 | 51 |
* used by applications. The {@code Graphics2D} object contains |
2 | 52 |
* an {@link AffineTransform} object as part of its rendering state |
53 |
* that defines how to convert coordinates from user space to |
|
54 |
* device-dependent coordinates in Device Space. |
|
55 |
* <p> |
|
56 |
* Coordinates in device space usually refer to individual device pixels |
|
57 |
* and are aligned on the infinitely thin gaps between these pixels. |
|
35667 | 58 |
* Some {@code Graphics2D} objects can be used to capture rendering |
2 | 59 |
* operations for storage into a graphics metafile for playback on a |
60 |
* concrete device of unknown physical resolution at a later time. Since |
|
61 |
* the resolution might not be known when the rendering operations are |
|
35667 | 62 |
* captured, the {@code Graphics2D Transform} is set up |
2 | 63 |
* to transform user coordinates to a virtual device space that |
64 |
* approximates the expected resolution of the target device. Further |
|
65 |
* transformations might need to be applied at playback time if the |
|
66 |
* estimate is incorrect. |
|
67 |
* <p> |
|
68 |
* Some of the operations performed by the rendering attribute objects |
|
35667 | 69 |
* occur in the device space, but all {@code Graphics2D} methods take |
2 | 70 |
* user space coordinates. |
71 |
* <p> |
|
35667 | 72 |
* Every {@code Graphics2D} object is associated with a target that |
2 | 73 |
* defines where rendering takes place. A |
74 |
* {@link GraphicsConfiguration} object defines the characteristics |
|
75 |
* of the rendering target, such as pixel format and resolution. |
|
76 |
* The same rendering target is used throughout the life of a |
|
35667 | 77 |
* {@code Graphics2D} object. |
2 | 78 |
* <p> |
35667 | 79 |
* When creating a {@code Graphics2D} object, the |
80 |
* {@code GraphicsConfiguration} |
|
21777 | 81 |
* specifies the <a name="deftransform">default transform</a> for |
35667 | 82 |
* the target of the {@code Graphics2D} (a |
2 | 83 |
* {@link Component} or {@link Image}). This default transform maps the |
84 |
* user space coordinate system to screen and printer device coordinates |
|
85 |
* such that the origin maps to the upper left hand corner of the |
|
86 |
* target region of the device with increasing X coordinates extending |
|
87 |
* to the right and increasing Y coordinates extending downward. |
|
88 |
* The scaling of the default transform is set to identity for those devices |
|
89 |
* that are close to 72 dpi, such as screen devices. |
|
90 |
* The scaling of the default transform is set to approximately 72 user |
|
91 |
* space coordinates per square inch for high resolution devices, such as |
|
92 |
* printers. For image buffers, the default transform is the |
|
35667 | 93 |
* {@code Identity} transform. |
2 | 94 |
* |
95 |
* <h2>Rendering Process</h2> |
|
96 |
* The Rendering Process can be broken down into four phases that are |
|
35667 | 97 |
* controlled by the {@code Graphics2D} rendering attributes. |
2 | 98 |
* The renderer can optimize many of these steps, either by caching the |
99 |
* results for future calls, by collapsing multiple virtual steps into |
|
100 |
* a single operation, or by recognizing various attributes as common |
|
101 |
* simple cases that can be eliminated by modifying other parts of the |
|
102 |
* operation. |
|
103 |
* <p> |
|
104 |
* The steps in the rendering process are: |
|
105 |
* <ol> |
|
106 |
* <li> |
|
107 |
* Determine what to render. |
|
108 |
* <li> |
|
35667 | 109 |
* Constrain the rendering operation to the current {@code Clip}. |
110 |
* The {@code Clip} is specified by a {@link Shape} in user |
|
2 | 111 |
* space and is controlled by the program using the various clip |
35667 | 112 |
* manipulation methods of {@code Graphics} and |
113 |
* {@code Graphics2D}. This <i>user clip</i> |
|
2 | 114 |
* is transformed into device space by the current |
35667 | 115 |
* {@code Transform} and combined with the |
2 | 116 |
* <i>device clip</i>, which is defined by the visibility of windows and |
117 |
* device extents. The combination of the user clip and device clip |
|
118 |
* defines the <i>composite clip</i>, which determines the final clipping |
|
119 |
* region. The user clip is not modified by the rendering |
|
120 |
* system to reflect the resulting composite clip. |
|
121 |
* <li> |
|
122 |
* Determine what colors to render. |
|
123 |
* <li> |
|
124 |
* Apply the colors to the destination drawing surface using the current |
|
35667 | 125 |
* {@link Composite} attribute in the {@code Graphics2D} context. |
2 | 126 |
* </ol> |
127 |
* <br> |
|
128 |
* The three types of rendering operations, along with details of each |
|
129 |
* of their particular rendering processes are: |
|
130 |
* <ol> |
|
131 |
* <li> |
|
35667 | 132 |
* <b><a name="rendershape">{@code Shape} operations</a></b> |
2 | 133 |
* <ol> |
134 |
* <li> |
|
35667 | 135 |
* If the operation is a {@code draw(Shape)} operation, then |
2 | 136 |
* the {@link Stroke#createStrokedShape(Shape) createStrokedShape} |
137 |
* method on the current {@link Stroke} attribute in the |
|
35667 | 138 |
* {@code Graphics2D} context is used to construct a new |
139 |
* {@code Shape} object that contains the outline of the specified |
|
140 |
* {@code Shape}. |
|
2 | 141 |
* <li> |
35667 | 142 |
* The {@code Shape} is transformed from user space to device space |
143 |
* using the current {@code Transform} |
|
144 |
* in the {@code Graphics2D} context. |
|
2 | 145 |
* <li> |
35667 | 146 |
* The outline of the {@code Shape} is extracted using the |
2 | 147 |
* {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of |
35667 | 148 |
* {@code Shape}, which returns a |
2 | 149 |
* {@link java.awt.geom.PathIterator PathIterator} |
35667 | 150 |
* object that iterates along the boundary of the {@code Shape}. |
2 | 151 |
* <li> |
35667 | 152 |
* If the {@code Graphics2D} object cannot handle the curved segments |
153 |
* that the {@code PathIterator} object returns then it can call the |
|
2 | 154 |
* alternate |
155 |
* {@link Shape#getPathIterator(AffineTransform, double) getPathIterator} |
|
35667 | 156 |
* method of {@code Shape}, which flattens the {@code Shape}. |
2 | 157 |
* <li> |
35667 | 158 |
* The current {@link Paint} in the {@code Graphics2D} context |
2 | 159 |
* is queried for a {@link PaintContext}, which specifies the |
160 |
* colors to render in device space. |
|
161 |
* </ol> |
|
162 |
* <li> |
|
163 |
* <b><a name=rendertext>Text operations</a></b> |
|
164 |
* <ol> |
|
165 |
* <li> |
|
166 |
* The following steps are used to determine the set of glyphs required |
|
35667 | 167 |
* to render the indicated {@code String}: |
2 | 168 |
* <ol> |
169 |
* <li> |
|
35667 | 170 |
* If the argument is a {@code String}, then the current |
171 |
* {@code Font} in the {@code Graphics2D} context is asked to |
|
172 |
* convert the Unicode characters in the {@code String} into a set of |
|
2 | 173 |
* glyphs for presentation with whatever basic layout and shaping |
174 |
* algorithms the font implements. |
|
175 |
* <li> |
|
176 |
* If the argument is an |
|
177 |
* {@link AttributedCharacterIterator}, |
|
178 |
* the iterator is asked to convert itself to a |
|
179 |
* {@link java.awt.font.TextLayout TextLayout} |
|
35667 | 180 |
* using its embedded font attributes. The {@code TextLayout} |
2 | 181 |
* implements more sophisticated glyph layout algorithms that |
182 |
* perform Unicode bi-directional layout adjustments automatically |
|
183 |
* for multiple fonts of differing writing directions. |
|
184 |
* <li> |
|
185 |
* If the argument is a |
|
186 |
* {@link GlyphVector}, then the |
|
35667 | 187 |
* {@code GlyphVector} object already contains the appropriate |
2 | 188 |
* font-specific glyph codes with explicit coordinates for the position of |
189 |
* each glyph. |
|
190 |
* </ol> |
|
191 |
* <li> |
|
35667 | 192 |
* The current {@code Font} is queried to obtain outlines for the |
2 | 193 |
* indicated glyphs. These outlines are treated as shapes in user space |
194 |
* relative to the position of each glyph that was determined in step 1. |
|
195 |
* <li> |
|
196 |
* The character outlines are filled as indicated above |
|
35667 | 197 |
* under <a href="#rendershape">{@code Shape} operations</a>. |
2 | 198 |
* <li> |
35667 | 199 |
* The current {@code Paint} is queried for a |
200 |
* {@code PaintContext}, which specifies |
|
2 | 201 |
* the colors to render in device space. |
202 |
* </ol> |
|
203 |
* <li> |
|
35667 | 204 |
* <b><a name= renderingimage>{@code Image} Operations</a></b> |
2 | 205 |
* <ol> |
206 |
* <li> |
|
207 |
* The region of interest is defined by the bounding box of the source |
|
35667 | 208 |
* {@code Image}. |
2 | 209 |
* This bounding box is specified in Image Space, which is the |
35667 | 210 |
* {@code Image} object's local coordinate system. |
2 | 211 |
* <li> |
35667 | 212 |
* If an {@code AffineTransform} is passed to |
2 | 213 |
* {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)}, |
35667 | 214 |
* the {@code AffineTransform} is used to transform the bounding |
215 |
* box from image space to user space. If no {@code AffineTransform} |
|
2 | 216 |
* is supplied, the bounding box is treated as if it is already in user space. |
217 |
* <li> |
|
35667 | 218 |
* The bounding box of the source {@code Image} is transformed from user |
219 |
* space into device space using the current {@code Transform}. |
|
2 | 220 |
* Note that the result of transforming the bounding box does not |
221 |
* necessarily result in a rectangular region in device space. |
|
222 |
* <li> |
|
35667 | 223 |
* The {@code Image} object determines what colors to render, |
2 | 224 |
* sampled according to the source to destination |
35667 | 225 |
* coordinate mapping specified by the current {@code Transform} and the |
2 | 226 |
* optional image transform. |
227 |
* </ol> |
|
228 |
* </ol> |
|
229 |
* |
|
230 |
* <h2>Default Rendering Attributes</h2> |
|
35667 | 231 |
* The default values for the {@code Graphics2D} rendering attributes are: |
22260
c9185e010e03
8031082: Fix non-missing doclint problems in client libraries
darcy
parents:
21777
diff
changeset
|
232 |
* <dl> |
35667 | 233 |
* <dt><i>{@code Paint}</i> |
234 |
* <dd>The color of the {@code Component}. |
|
235 |
* <dt><i>{@code Font}</i> |
|
236 |
* <dd>The {@code Font} of the {@code Component}. |
|
237 |
* <dt><i>{@code Stroke}</i> |
|
2 | 238 |
* <dd>A square pen with a linewidth of 1, no dashing, miter segment joins |
239 |
* and square end caps. |
|
35667 | 240 |
* <dt><i>{@code Transform}</i> |
2 | 241 |
* <dd>The |
242 |
* {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform} |
|
35667 | 243 |
* for the {@code GraphicsConfiguration} of the {@code Component}. |
244 |
* <dt><i>{@code Composite}</i> |
|
2 | 245 |
* <dd>The {@link AlphaComposite#SRC_OVER} rule. |
35667 | 246 |
* <dt><i>{@code Clip}</i> |
247 |
* <dd>No rendering {@code Clip}, the output is clipped to the |
|
248 |
* {@code Component}. |
|
2 | 249 |
* </dl> |
250 |
* |
|
251 |
* <h2>Rendering Compatibility Issues</h2> |
|
252 |
* The JDK(tm) 1.1 rendering model is based on a pixelization model |
|
253 |
* that specifies that coordinates |
|
254 |
* are infinitely thin, lying between the pixels. Drawing operations are |
|
255 |
* performed using a one-pixel wide pen that fills the |
|
256 |
* pixel below and to the right of the anchor point on the path. |
|
257 |
* The JDK 1.1 rendering model is consistent with the |
|
258 |
* capabilities of most of the existing class of platform |
|
259 |
* renderers that need to resolve integer coordinates to a |
|
260 |
* discrete pen that must fall completely on a specified number of pixels. |
|
261 |
* <p> |
|
262 |
* The Java 2D(tm) (Java(tm) 2 platform) API supports antialiasing renderers. |
|
263 |
* A pen with a width of one pixel does not need to fall |
|
264 |
* completely on pixel N as opposed to pixel N+1. The pen can fall |
|
265 |
* partially on both pixels. It is not necessary to choose a bias |
|
266 |
* direction for a wide pen since the blending that occurs along the |
|
267 |
* pen traversal edges makes the sub-pixel position of the pen |
|
268 |
* visible to the user. On the other hand, when antialiasing is |
|
269 |
* turned off by setting the |
|
270 |
* {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint key |
|
271 |
* to the |
|
272 |
* {@link RenderingHints#VALUE_ANTIALIAS_OFF VALUE_ANTIALIAS_OFF} |
|
273 |
* hint value, the renderer might need |
|
274 |
* to apply a bias to determine which pixel to modify when the pen |
|
275 |
* is straddling a pixel boundary, such as when it is drawn |
|
276 |
* along an integer coordinate in device space. While the capabilities |
|
277 |
* of an antialiasing renderer make it no longer necessary for the |
|
278 |
* rendering model to specify a bias for the pen, it is desirable for the |
|
279 |
* antialiasing and non-antialiasing renderers to perform similarly for |
|
280 |
* the common cases of drawing one-pixel wide horizontal and vertical |
|
281 |
* lines on the screen. To ensure that turning on antialiasing by |
|
282 |
* setting the |
|
283 |
* {@link RenderingHints#KEY_ANTIALIASING KEY_ANTIALIASING} hint |
|
284 |
* key to |
|
285 |
* {@link RenderingHints#VALUE_ANTIALIAS_ON VALUE_ANTIALIAS_ON} |
|
286 |
* does not cause such lines to suddenly become twice as wide and half |
|
287 |
* as opaque, it is desirable to have the model specify a path for such |
|
288 |
* lines so that they completely cover a particular set of pixels to help |
|
289 |
* increase their crispness. |
|
290 |
* <p> |
|
291 |
* Java 2D API maintains compatibility with JDK 1.1 rendering |
|
292 |
* behavior, such that legacy operations and existing renderer |
|
293 |
* behavior is unchanged under Java 2D API. Legacy |
|
35667 | 294 |
* methods that map onto general {@code draw} and |
295 |
* {@code fill} methods are defined, which clearly indicates |
|
296 |
* how {@code Graphics2D} extends {@code Graphics} based |
|
297 |
* on settings of {@code Stroke} and {@code Transform} |
|
2 | 298 |
* attributes and rendering hints. The definition |
299 |
* performs identically under default attribute settings. |
|
35667 | 300 |
* For example, the default {@code Stroke} is a |
301 |
* {@code BasicStroke} with a width of 1 and no dashing and the |
|
2 | 302 |
* default Transform for screen drawing is an Identity transform. |
303 |
* <p> |
|
304 |
* The following two rules provide predictable rendering behavior whether |
|
305 |
* aliasing or antialiasing is being used. |
|
306 |
* <ul> |
|
307 |
* <li> Device coordinates are defined to be between device pixels which |
|
21278 | 308 |
* avoids any inconsistent results between aliased and antialiased |
2 | 309 |
* rendering. If coordinates were defined to be at a pixel's center, some |
310 |
* of the pixels covered by a shape, such as a rectangle, would only be |
|
311 |
* half covered. |
|
312 |
* With aliased rendering, the half covered pixels would either be |
|
313 |
* rendered inside the shape or outside the shape. With anti-aliased |
|
314 |
* rendering, the pixels on the entire edge of the shape would be half |
|
315 |
* covered. On the other hand, since coordinates are defined to be |
|
316 |
* between pixels, a shape like a rectangle would have no half covered |
|
317 |
* pixels, whether or not it is rendered using antialiasing. |
|
35667 | 318 |
* <li> Lines and paths stroked using the {@code BasicStroke} |
2 | 319 |
* object may be "normalized" to provide consistent rendering of the |
320 |
* outlines when positioned at various points on the drawable and |
|
321 |
* whether drawn with aliased or antialiased rendering. This |
|
322 |
* normalization process is controlled by the |
|
323 |
* {@link RenderingHints#KEY_STROKE_CONTROL KEY_STROKE_CONTROL} hint. |
|
324 |
* The exact normalization algorithm is not specified, but the goals |
|
325 |
* of this normalization are to ensure that lines are rendered with |
|
326 |
* consistent visual appearance regardless of how they fall on the |
|
327 |
* pixel grid and to promote more solid horizontal and vertical |
|
328 |
* lines in antialiased mode so that they resemble their non-antialiased |
|
329 |
* counterparts more closely. A typical normalization step might |
|
330 |
* promote antialiased line endpoints to pixel centers to reduce the |
|
331 |
* amount of blending or adjust the subpixel positioning of |
|
332 |
* non-antialiased lines so that the floating point line widths |
|
333 |
* round to even or odd pixel counts with equal likelihood. This |
|
334 |
* process can move endpoints by up to half a pixel (usually towards |
|
335 |
* positive infinity along both axes) to promote these consistent |
|
336 |
* results. |
|
337 |
* </ul> |
|
338 |
* <p> |
|
339 |
* The following definitions of general legacy methods |
|
340 |
* perform identically to previously specified behavior under default |
|
341 |
* attribute settings: |
|
342 |
* <ul> |
|
343 |
* <li> |
|
35667 | 344 |
* For {@code fill} operations, including {@code fillRect}, |
345 |
* {@code fillRoundRect}, {@code fillOval}, |
|
346 |
* {@code fillArc}, {@code fillPolygon}, and |
|
347 |
* {@code clearRect}, {@link #fill(Shape) fill} can now be called |
|
348 |
* with the desired {@code Shape}. For example, when filling a |
|
2 | 349 |
* rectangle: |
350 |
* <pre> |
|
351 |
* fill(new Rectangle(x, y, w, h)); |
|
352 |
* </pre> |
|
353 |
* is called. |
|
22260
c9185e010e03
8031082: Fix non-missing doclint problems in client libraries
darcy
parents:
21777
diff
changeset
|
354 |
* |
2 | 355 |
* <li> |
35667 | 356 |
* Similarly, for draw operations, including {@code drawLine}, |
357 |
* {@code drawRect}, {@code drawRoundRect}, |
|
358 |
* {@code drawOval}, {@code drawArc}, {@code drawPolyline}, |
|
359 |
* and {@code drawPolygon}, {@link #draw(Shape) draw} can now be |
|
360 |
* called with the desired {@code Shape}. For example, when drawing a |
|
2 | 361 |
* rectangle: |
362 |
* <pre> |
|
363 |
* draw(new Rectangle(x, y, w, h)); |
|
364 |
* </pre> |
|
365 |
* is called. |
|
22260
c9185e010e03
8031082: Fix non-missing doclint problems in client libraries
darcy
parents:
21777
diff
changeset
|
366 |
* |
2 | 367 |
* <li> |
35667 | 368 |
* The {@code draw3DRect} and {@code fill3DRect} methods were |
369 |
* implemented in terms of the {@code drawLine} and |
|
370 |
* {@code fillRect} methods in the {@code Graphics} class which |
|
371 |
* would predicate their behavior upon the current {@code Stroke} |
|
372 |
* and {@code Paint} objects in a {@code Graphics2D} context. |
|
2 | 373 |
* This class overrides those implementations with versions that use |
35667 | 374 |
* the current {@code Color} exclusively, overriding the current |
375 |
* {@code Paint} and which uses {@code fillRect} to describe |
|
2 | 376 |
* the exact same behavior as the preexisting methods regardless of the |
35667 | 377 |
* setting of the current {@code Stroke}. |
2 | 378 |
* </ul> |
35667 | 379 |
* The {@code Graphics} class defines only the {@code setColor} |
2 | 380 |
* method to control the color to be painted. Since the Java 2D API extends |
35667 | 381 |
* the {@code Color} object to implement the new {@code Paint} |
2 | 382 |
* interface, the existing |
35667 | 383 |
* {@code setColor} method is now a convenience method for setting the |
384 |
* current {@code Paint} attribute to a {@code Color} object. |
|
385 |
* {@code setColor(c)} is equivalent to {@code setPaint(c)}. |
|
2 | 386 |
* <p> |
35667 | 387 |
* The {@code Graphics} class defines two methods for controlling |
2 | 388 |
* how colors are applied to the destination. |
389 |
* <ol> |
|
390 |
* <li> |
|
35667 | 391 |
* The {@code setPaintMode} method is implemented as a convenience |
392 |
* method to set the default {@code Composite}, equivalent to |
|
393 |
* {@code setComposite(new AlphaComposite.SrcOver)}. |
|
2 | 394 |
* <li> |
35667 | 395 |
* The {@code setXORMode(Color xorcolor)} method is implemented |
396 |
* as a convenience method to set a special {@code Composite} object that |
|
397 |
* ignores the {@code Alpha} components of source colors and sets the |
|
2 | 398 |
* destination color to the value: |
399 |
* <pre> |
|
400 |
* dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel); |
|
401 |
* </pre> |
|
402 |
* </ol> |
|
403 |
* |
|
404 |
* @author Jim Graham |
|
405 |
* @see java.awt.RenderingHints |
|
406 |
*/ |
|
407 |
public abstract class Graphics2D extends Graphics { |
|
408 |
||
409 |
/** |
|
35667 | 410 |
* Constructs a new {@code Graphics2D} object. Since |
411 |
* {@code Graphics2D} is an abstract class, and since it must be |
|
2 | 412 |
* customized by subclasses for different output devices, |
35667 | 413 |
* {@code Graphics2D} objects cannot be created directly. |
414 |
* Instead, {@code Graphics2D} objects must be obtained from another |
|
415 |
* {@code Graphics2D} object, created by a |
|
416 |
* {@code Component}, or obtained from images such as |
|
2 | 417 |
* {@link BufferedImage} objects. |
418 |
* @see java.awt.Component#getGraphics |
|
419 |
* @see java.awt.Graphics#create |
|
420 |
*/ |
|
421 |
protected Graphics2D() { |
|
422 |
} |
|
423 |
||
424 |
/** |
|
425 |
* Draws a 3-D highlighted outline of the specified rectangle. |
|
426 |
* The edges of the rectangle are highlighted so that they |
|
427 |
* appear to be beveled and lit from the upper left corner. |
|
428 |
* <p> |
|
429 |
* The colors used for the highlighting effect are determined |
|
430 |
* based on the current color. |
|
431 |
* The resulting rectangle covers an area that is |
|
432 |
* <code>width + 1</code> pixels wide |
|
433 |
* by <code>height + 1</code> pixels tall. This method |
|
35667 | 434 |
* uses the current {@code Color} exclusively and ignores |
435 |
* the current {@code Paint}. |
|
2 | 436 |
* @param x the x coordinate of the rectangle to be drawn. |
437 |
* @param y the y coordinate of the rectangle to be drawn. |
|
438 |
* @param width the width of the rectangle to be drawn. |
|
439 |
* @param height the height of the rectangle to be drawn. |
|
440 |
* @param raised a boolean that determines whether the rectangle |
|
441 |
* appears to be raised above the surface |
|
442 |
* or sunk into the surface. |
|
443 |
* @see java.awt.Graphics#fill3DRect |
|
444 |
*/ |
|
445 |
public void draw3DRect(int x, int y, int width, int height, |
|
446 |
boolean raised) { |
|
447 |
Paint p = getPaint(); |
|
448 |
Color c = getColor(); |
|
449 |
Color brighter = c.brighter(); |
|
450 |
Color darker = c.darker(); |
|
451 |
||
452 |
setColor(raised ? brighter : darker); |
|
453 |
//drawLine(x, y, x, y + height); |
|
454 |
fillRect(x, y, 1, height + 1); |
|
455 |
//drawLine(x + 1, y, x + width - 1, y); |
|
456 |
fillRect(x + 1, y, width - 1, 1); |
|
457 |
setColor(raised ? darker : brighter); |
|
458 |
//drawLine(x + 1, y + height, x + width, y + height); |
|
459 |
fillRect(x + 1, y + height, width, 1); |
|
460 |
//drawLine(x + width, y, x + width, y + height - 1); |
|
461 |
fillRect(x + width, y, 1, height); |
|
462 |
setPaint(p); |
|
463 |
} |
|
464 |
||
465 |
/** |
|
466 |
* Paints a 3-D highlighted rectangle filled with the current color. |
|
467 |
* The edges of the rectangle are highlighted so that it appears |
|
468 |
* as if the edges were beveled and lit from the upper left corner. |
|
469 |
* The colors used for the highlighting effect and for filling are |
|
35667 | 470 |
* determined from the current {@code Color}. This method uses |
471 |
* the current {@code Color} exclusively and ignores the current |
|
472 |
* {@code Paint}. |
|
2 | 473 |
* @param x the x coordinate of the rectangle to be filled. |
474 |
* @param y the y coordinate of the rectangle to be filled. |
|
475 |
* @param width the width of the rectangle to be filled. |
|
476 |
* @param height the height of the rectangle to be filled. |
|
477 |
* @param raised a boolean value that determines whether the |
|
478 |
* rectangle appears to be raised above the surface |
|
479 |
* or etched into the surface. |
|
480 |
* @see java.awt.Graphics#draw3DRect |
|
481 |
*/ |
|
482 |
public void fill3DRect(int x, int y, int width, int height, |
|
483 |
boolean raised) { |
|
484 |
Paint p = getPaint(); |
|
485 |
Color c = getColor(); |
|
486 |
Color brighter = c.brighter(); |
|
487 |
Color darker = c.darker(); |
|
488 |
||
489 |
if (!raised) { |
|
490 |
setColor(darker); |
|
491 |
} else if (p != c) { |
|
492 |
setColor(c); |
|
493 |
} |
|
494 |
fillRect(x+1, y+1, width-2, height-2); |
|
495 |
setColor(raised ? brighter : darker); |
|
496 |
//drawLine(x, y, x, y + height - 1); |
|
497 |
fillRect(x, y, 1, height); |
|
498 |
//drawLine(x + 1, y, x + width - 2, y); |
|
499 |
fillRect(x + 1, y, width - 2, 1); |
|
500 |
setColor(raised ? darker : brighter); |
|
501 |
//drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1); |
|
502 |
fillRect(x + 1, y + height - 1, width - 1, 1); |
|
503 |
//drawLine(x + width - 1, y, x + width - 1, y + height - 2); |
|
504 |
fillRect(x + width - 1, y, 1, height - 1); |
|
505 |
setPaint(p); |
|
506 |
} |
|
507 |
||
508 |
/** |
|
35667 | 509 |
* Strokes the outline of a {@code Shape} using the settings of the |
510 |
* current {@code Graphics2D} context. The rendering attributes |
|
511 |
* applied include the {@code Clip}, {@code Transform}, |
|
512 |
* {@code Paint}, {@code Composite} and |
|
513 |
* {@code Stroke} attributes. |
|
514 |
* @param s the {@code Shape} to be rendered |
|
2 | 515 |
* @see #setStroke |
516 |
* @see #setPaint |
|
517 |
* @see java.awt.Graphics#setColor |
|
518 |
* @see #transform |
|
519 |
* @see #setTransform |
|
520 |
* @see #clip |
|
521 |
* @see #setClip |
|
522 |
* @see #setComposite |
|
523 |
*/ |
|
524 |
public abstract void draw(Shape s); |
|
525 |
||
526 |
/** |
|
527 |
* Renders an image, applying a transform from image space into user space |
|
528 |
* before drawing. |
|
529 |
* The transformation from user space into device space is done with |
|
35667 | 530 |
* the current {@code Transform} in the {@code Graphics2D}. |
2 | 531 |
* The specified transformation is applied to the image before the |
35667 | 532 |
* transform attribute in the {@code Graphics2D} context is applied. |
533 |
* The rendering attributes applied include the {@code Clip}, |
|
534 |
* {@code Transform}, and {@code Composite} attributes. |
|
2 | 535 |
* Note that no rendering is done if the specified transform is |
536 |
* noninvertible. |
|
537 |
* @param img the specified image to be rendered. |
|
35667 | 538 |
* This method does nothing if {@code img} is null. |
2 | 539 |
* @param xform the transformation from image space into user space |
540 |
* @param obs the {@link ImageObserver} |
|
35667 | 541 |
* to be notified as more of the {@code Image} |
2 | 542 |
* is converted |
35667 | 543 |
* @return {@code true} if the {@code Image} is |
2 | 544 |
* fully loaded and completely rendered, or if it's null; |
35667 | 545 |
* {@code false} if the {@code Image} is still being loaded. |
2 | 546 |
* @see #transform |
547 |
* @see #setTransform |
|
548 |
* @see #setComposite |
|
549 |
* @see #clip |
|
550 |
* @see #setClip |
|
551 |
*/ |
|
552 |
public abstract boolean drawImage(Image img, |
|
553 |
AffineTransform xform, |
|
554 |
ImageObserver obs); |
|
555 |
||
556 |
/** |
|
35667 | 557 |
* Renders a {@code BufferedImage} that is |
2 | 558 |
* filtered with a |
559 |
* {@link BufferedImageOp}. |
|
35667 | 560 |
* The rendering attributes applied include the {@code Clip}, |
561 |
* {@code Transform} |
|
562 |
* and {@code Composite} attributes. This is equivalent to: |
|
2 | 563 |
* <pre> |
564 |
* img1 = op.filter(img, null); |
|
565 |
* drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null); |
|
566 |
* </pre> |
|
567 |
* @param op the filter to be applied to the image before rendering |
|
35667 | 568 |
* @param img the specified {@code BufferedImage} to be rendered. |
569 |
* This method does nothing if {@code img} is null. |
|
2 | 570 |
* @param x the x coordinate of the location in user space where |
571 |
* the upper left corner of the image is rendered |
|
572 |
* @param y the y coordinate of the location in user space where |
|
573 |
* the upper left corner of the image is rendered |
|
574 |
* |
|
575 |
* @see #transform |
|
576 |
* @see #setTransform |
|
577 |
* @see #setComposite |
|
578 |
* @see #clip |
|
579 |
* @see #setClip |
|
580 |
*/ |
|
581 |
public abstract void drawImage(BufferedImage img, |
|
582 |
BufferedImageOp op, |
|
583 |
int x, |
|
584 |
int y); |
|
585 |
||
586 |
/** |
|
587 |
* Renders a {@link RenderedImage}, |
|
588 |
* applying a transform from image |
|
589 |
* space into user space before drawing. |
|
590 |
* The transformation from user space into device space is done with |
|
35667 | 591 |
* the current {@code Transform} in the {@code Graphics2D}. |
2 | 592 |
* The specified transformation is applied to the image before the |
35667 | 593 |
* transform attribute in the {@code Graphics2D} context is applied. |
594 |
* The rendering attributes applied include the {@code Clip}, |
|
595 |
* {@code Transform}, and {@code Composite} attributes. Note |
|
2 | 596 |
* that no rendering is done if the specified transform is |
597 |
* noninvertible. |
|
598 |
* @param img the image to be rendered. This method does |
|
35667 | 599 |
* nothing if {@code img} is null. |
2 | 600 |
* @param xform the transformation from image space into user space |
601 |
* @see #transform |
|
602 |
* @see #setTransform |
|
603 |
* @see #setComposite |
|
604 |
* @see #clip |
|
605 |
* @see #setClip |
|
606 |
*/ |
|
607 |
public abstract void drawRenderedImage(RenderedImage img, |
|
608 |
AffineTransform xform); |
|
609 |
||
610 |
/** |
|
611 |
* Renders a |
|
612 |
* {@link RenderableImage}, |
|
613 |
* applying a transform from image space into user space before drawing. |
|
614 |
* The transformation from user space into device space is done with |
|
35667 | 615 |
* the current {@code Transform} in the {@code Graphics2D}. |
2 | 616 |
* The specified transformation is applied to the image before the |
35667 | 617 |
* transform attribute in the {@code Graphics2D} context is applied. |
618 |
* The rendering attributes applied include the {@code Clip}, |
|
619 |
* {@code Transform}, and {@code Composite} attributes. Note |
|
2 | 620 |
* that no rendering is done if the specified transform is |
621 |
* noninvertible. |
|
622 |
*<p> |
|
35667 | 623 |
* Rendering hints set on the {@code Graphics2D} object might |
624 |
* be used in rendering the {@code RenderableImage}. |
|
2 | 625 |
* If explicit control is required over specific hints recognized by a |
35667 | 626 |
* specific {@code RenderableImage}, or if knowledge of which hints |
627 |
* are used is required, then a {@code RenderedImage} should be |
|
628 |
* obtained directly from the {@code RenderableImage} |
|
2 | 629 |
* and rendered using |
630 |
*{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}. |
|
631 |
* @param img the image to be rendered. This method does |
|
35667 | 632 |
* nothing if {@code img} is null. |
2 | 633 |
* @param xform the transformation from image space into user space |
634 |
* @see #transform |
|
635 |
* @see #setTransform |
|
636 |
* @see #setComposite |
|
637 |
* @see #clip |
|
638 |
* @see #setClip |
|
639 |
* @see #drawRenderedImage |
|
640 |
*/ |
|
641 |
public abstract void drawRenderableImage(RenderableImage img, |
|
642 |
AffineTransform xform); |
|
643 |
||
644 |
/** |
|
35667 | 645 |
* Renders the text of the specified {@code String}, using the |
646 |
* current text attribute state in the {@code Graphics2D} context. |
|
2 | 647 |
* The baseline of the |
648 |
* first character is at position (<i>x</i>, <i>y</i>) in |
|
649 |
* the User Space. |
|
35667 | 650 |
* The rendering attributes applied include the {@code Clip}, |
651 |
* {@code Transform}, {@code Paint}, {@code Font} and |
|
652 |
* {@code Composite} attributes. For characters in script |
|
2 | 653 |
* systems such as Hebrew and Arabic, the glyphs can be rendered from |
654 |
* right to left, in which case the coordinate supplied is the |
|
655 |
* location of the leftmost character on the baseline. |
|
656 |
* @param str the string to be rendered |
|
657 |
* @param x the x coordinate of the location where the |
|
35667 | 658 |
* {@code String} should be rendered |
2 | 659 |
* @param y the y coordinate of the location where the |
35667 | 660 |
* {@code String} should be rendered |
661 |
* @throws NullPointerException if {@code str} is |
|
662 |
* {@code null} |
|
2 | 663 |
* @see java.awt.Graphics#drawBytes |
664 |
* @see java.awt.Graphics#drawChars |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22260
diff
changeset
|
665 |
* @since 1.0 |
2 | 666 |
*/ |
667 |
public abstract void drawString(String str, int x, int y); |
|
668 |
||
669 |
/** |
|
35667 | 670 |
* Renders the text specified by the specified {@code String}, |
671 |
* using the current text attribute state in the {@code Graphics2D} context. |
|
2 | 672 |
* The baseline of the first character is at position |
673 |
* (<i>x</i>, <i>y</i>) in the User Space. |
|
35667 | 674 |
* The rendering attributes applied include the {@code Clip}, |
675 |
* {@code Transform}, {@code Paint}, {@code Font} and |
|
676 |
* {@code Composite} attributes. For characters in script systems |
|
2 | 677 |
* such as Hebrew and Arabic, the glyphs can be rendered from right to |
678 |
* left, in which case the coordinate supplied is the location of the |
|
679 |
* leftmost character on the baseline. |
|
35667 | 680 |
* @param str the {@code String} to be rendered |
2 | 681 |
* @param x the x coordinate of the location where the |
35667 | 682 |
* {@code String} should be rendered |
2 | 683 |
* @param y the y coordinate of the location where the |
35667 | 684 |
* {@code String} should be rendered |
685 |
* @throws NullPointerException if {@code str} is |
|
686 |
* {@code null} |
|
2 | 687 |
* @see #setPaint |
688 |
* @see java.awt.Graphics#setColor |
|
689 |
* @see java.awt.Graphics#setFont |
|
690 |
* @see #setTransform |
|
691 |
* @see #setComposite |
|
692 |
* @see #setClip |
|
693 |
*/ |
|
694 |
public abstract void drawString(String str, float x, float y); |
|
695 |
||
696 |
/** |
|
697 |
* Renders the text of the specified iterator applying its attributes |
|
698 |
* in accordance with the specification of the {@link TextAttribute} class. |
|
699 |
* <p> |
|
700 |
* The baseline of the first character is at position |
|
701 |
* (<i>x</i>, <i>y</i>) in User Space. |
|
702 |
* For characters in script systems such as Hebrew and Arabic, |
|
703 |
* the glyphs can be rendered from right to left, in which case the |
|
704 |
* coordinate supplied is the location of the leftmost character |
|
705 |
* on the baseline. |
|
706 |
* @param iterator the iterator whose text is to be rendered |
|
707 |
* @param x the x coordinate where the iterator's text is to be |
|
708 |
* rendered |
|
709 |
* @param y the y coordinate where the iterator's text is to be |
|
710 |
* rendered |
|
35667 | 711 |
* @throws NullPointerException if {@code iterator} is |
712 |
* {@code null} |
|
2 | 713 |
* @see #setPaint |
714 |
* @see java.awt.Graphics#setColor |
|
715 |
* @see #setTransform |
|
716 |
* @see #setComposite |
|
717 |
* @see #setClip |
|
718 |
*/ |
|
719 |
public abstract void drawString(AttributedCharacterIterator iterator, |
|
720 |
int x, int y); |
|
721 |
||
722 |
/** |
|
723 |
* Renders the text of the specified iterator applying its attributes |
|
724 |
* in accordance with the specification of the {@link TextAttribute} class. |
|
725 |
* <p> |
|
726 |
* The baseline of the first character is at position |
|
727 |
* (<i>x</i>, <i>y</i>) in User Space. |
|
728 |
* For characters in script systems such as Hebrew and Arabic, |
|
729 |
* the glyphs can be rendered from right to left, in which case the |
|
730 |
* coordinate supplied is the location of the leftmost character |
|
731 |
* on the baseline. |
|
732 |
* @param iterator the iterator whose text is to be rendered |
|
733 |
* @param x the x coordinate where the iterator's text is to be |
|
734 |
* rendered |
|
735 |
* @param y the y coordinate where the iterator's text is to be |
|
736 |
* rendered |
|
35667 | 737 |
* @throws NullPointerException if {@code iterator} is |
738 |
* {@code null} |
|
2 | 739 |
* @see #setPaint |
740 |
* @see java.awt.Graphics#setColor |
|
741 |
* @see #setTransform |
|
742 |
* @see #setComposite |
|
743 |
* @see #setClip |
|
744 |
*/ |
|
745 |
public abstract void drawString(AttributedCharacterIterator iterator, |
|
746 |
float x, float y); |
|
747 |
||
748 |
/** |
|
749 |
* Renders the text of the specified |
|
750 |
* {@link GlyphVector} using |
|
35667 | 751 |
* the {@code Graphics2D} context's rendering attributes. |
752 |
* The rendering attributes applied include the {@code Clip}, |
|
753 |
* {@code Transform}, {@code Paint}, and |
|
754 |
* {@code Composite} attributes. The {@code GlyphVector} |
|
2 | 755 |
* specifies individual glyphs from a {@link Font}. |
35667 | 756 |
* The {@code GlyphVector} can also contain the glyph positions. |
2 | 757 |
* This is the fastest way to render a set of characters to the |
758 |
* screen. |
|
35667 | 759 |
* @param g the {@code GlyphVector} to be rendered |
2 | 760 |
* @param x the x position in User Space where the glyphs should |
761 |
* be rendered |
|
762 |
* @param y the y position in User Space where the glyphs should |
|
763 |
* be rendered |
|
35667 | 764 |
* @throws NullPointerException if {@code g} is {@code null}. |
2 | 765 |
* |
766 |
* @see java.awt.Font#createGlyphVector |
|
767 |
* @see java.awt.font.GlyphVector |
|
768 |
* @see #setPaint |
|
769 |
* @see java.awt.Graphics#setColor |
|
770 |
* @see #setTransform |
|
771 |
* @see #setComposite |
|
772 |
* @see #setClip |
|
773 |
*/ |
|
774 |
public abstract void drawGlyphVector(GlyphVector g, float x, float y); |
|
775 |
||
776 |
/** |
|
35667 | 777 |
* Fills the interior of a {@code Shape} using the settings of the |
778 |
* {@code Graphics2D} context. The rendering attributes applied |
|
779 |
* include the {@code Clip}, {@code Transform}, |
|
780 |
* {@code Paint}, and {@code Composite}. |
|
781 |
* @param s the {@code Shape} to be filled |
|
2 | 782 |
* @see #setPaint |
783 |
* @see java.awt.Graphics#setColor |
|
784 |
* @see #transform |
|
785 |
* @see #setTransform |
|
786 |
* @see #setComposite |
|
787 |
* @see #clip |
|
788 |
* @see #setClip |
|
789 |
*/ |
|
790 |
public abstract void fill(Shape s); |
|
791 |
||
792 |
/** |
|
35667 | 793 |
* Checks whether or not the specified {@code Shape} intersects |
2 | 794 |
* the specified {@link Rectangle}, which is in device |
35667 | 795 |
* space. If {@code onStroke} is false, this method checks |
796 |
* whether or not the interior of the specified {@code Shape} |
|
797 |
* intersects the specified {@code Rectangle}. If |
|
798 |
* {@code onStroke} is {@code true}, this method checks |
|
799 |
* whether or not the {@code Stroke} of the specified |
|
800 |
* {@code Shape} outline intersects the specified |
|
801 |
* {@code Rectangle}. |
|
2 | 802 |
* The rendering attributes taken into account include the |
35667 | 803 |
* {@code Clip}, {@code Transform}, and {@code Stroke} |
2 | 804 |
* attributes. |
805 |
* @param rect the area in device space to check for a hit |
|
35667 | 806 |
* @param s the {@code Shape} to check for a hit |
2 | 807 |
* @param onStroke flag used to choose between testing the |
35667 | 808 |
* stroked or the filled shape. If the flag is {@code true}, the |
809 |
* {@code Stroke} outline is tested. If the flag is |
|
810 |
* {@code false}, the filled {@code Shape} is tested. |
|
811 |
* @return {@code true} if there is a hit; {@code false} |
|
2 | 812 |
* otherwise. |
813 |
* @see #setStroke |
|
814 |
* @see #fill |
|
815 |
* @see #draw |
|
816 |
* @see #transform |
|
817 |
* @see #setTransform |
|
818 |
* @see #clip |
|
819 |
* @see #setClip |
|
820 |
*/ |
|
821 |
public abstract boolean hit(Rectangle rect, |
|
822 |
Shape s, |
|
823 |
boolean onStroke); |
|
824 |
||
825 |
/** |
|
826 |
* Returns the device configuration associated with this |
|
35667 | 827 |
* {@code Graphics2D}. |
828 |
* @return the device configuration of this {@code Graphics2D}. |
|
2 | 829 |
*/ |
830 |
public abstract GraphicsConfiguration getDeviceConfiguration(); |
|
831 |
||
832 |
/** |
|
35667 | 833 |
* Sets the {@code Composite} for the {@code Graphics2D} context. |
834 |
* The {@code Composite} is used in all drawing methods such as |
|
835 |
* {@code drawImage}, {@code drawString}, {@code draw}, |
|
836 |
* and {@code fill}. It specifies how new pixels are to be combined |
|
2 | 837 |
* with the existing pixels on the graphics device during the rendering |
838 |
* process. |
|
35667 | 839 |
* <p>If this {@code Graphics2D} context is drawing to a |
840 |
* {@code Component} on the display screen and the |
|
841 |
* {@code Composite} is a custom object rather than an |
|
842 |
* instance of the {@code AlphaComposite} class, and if |
|
843 |
* there is a security manager, its {@code checkPermission} |
|
844 |
* method is called with an {@code AWTPermission("readDisplayPixels")} |
|
2 | 845 |
* permission. |
846 |
* @throws SecurityException |
|
35667 | 847 |
* if a custom {@code Composite} object is being |
2 | 848 |
* used to render to the screen and a security manager |
35667 | 849 |
* is set and its {@code checkPermission} method |
2 | 850 |
* does not allow the operation. |
35667 | 851 |
* @param comp the {@code Composite} object to be used for rendering |
2 | 852 |
* @see java.awt.Graphics#setXORMode |
853 |
* @see java.awt.Graphics#setPaintMode |
|
854 |
* @see #getComposite |
|
855 |
* @see AlphaComposite |
|
856 |
* @see SecurityManager#checkPermission |
|
857 |
* @see java.awt.AWTPermission |
|
858 |
*/ |
|
859 |
public abstract void setComposite(Composite comp); |
|
860 |
||
861 |
/** |
|
35667 | 862 |
* Sets the {@code Paint} attribute for the |
863 |
* {@code Graphics2D} context. Calling this method |
|
864 |
* with a {@code null Paint} object does |
|
865 |
* not have any effect on the current {@code Paint} attribute |
|
866 |
* of this {@code Graphics2D}. |
|
867 |
* @param paint the {@code Paint} object to be used to generate |
|
868 |
* color during the rendering process, or {@code null} |
|
2 | 869 |
* @see java.awt.Graphics#setColor |
870 |
* @see #getPaint |
|
871 |
* @see GradientPaint |
|
872 |
* @see TexturePaint |
|
873 |
*/ |
|
874 |
public abstract void setPaint( Paint paint ); |
|
875 |
||
876 |
/** |
|
35667 | 877 |
* Sets the {@code Stroke} for the {@code Graphics2D} context. |
878 |
* @param s the {@code Stroke} object to be used to stroke a |
|
879 |
* {@code Shape} during the rendering process |
|
2 | 880 |
* @see BasicStroke |
881 |
* @see #getStroke |
|
882 |
*/ |
|
883 |
public abstract void setStroke(Stroke s); |
|
884 |
||
885 |
/** |
|
886 |
* Sets the value of a single preference for the rendering algorithms. |
|
887 |
* Hint categories include controls for rendering quality and overall |
|
888 |
* time/quality trade-off in the rendering process. Refer to the |
|
35667 | 889 |
* {@code RenderingHints} class for definitions of some common |
2 | 890 |
* keys and values. |
891 |
* @param hintKey the key of the hint to be set. |
|
892 |
* @param hintValue the value indicating preferences for the specified |
|
893 |
* hint category. |
|
894 |
* @see #getRenderingHint(RenderingHints.Key) |
|
895 |
* @see RenderingHints |
|
896 |
*/ |
|
897 |
public abstract void setRenderingHint(Key hintKey, Object hintValue); |
|
898 |
||
899 |
/** |
|
900 |
* Returns the value of a single preference for the rendering algorithms. |
|
901 |
* Hint categories include controls for rendering quality and overall |
|
902 |
* time/quality trade-off in the rendering process. Refer to the |
|
35667 | 903 |
* {@code RenderingHints} class for definitions of some common |
2 | 904 |
* keys and values. |
905 |
* @param hintKey the key corresponding to the hint to get. |
|
906 |
* @return an object representing the value for the specified hint key. |
|
907 |
* Some of the keys and their associated values are defined in the |
|
35667 | 908 |
* {@code RenderingHints} class. |
2 | 909 |
* @see RenderingHints |
910 |
* @see #setRenderingHint(RenderingHints.Key, Object) |
|
911 |
*/ |
|
912 |
public abstract Object getRenderingHint(Key hintKey); |
|
913 |
||
914 |
/** |
|
915 |
* Replaces the values of all preferences for the rendering |
|
35667 | 916 |
* algorithms with the specified {@code hints}. |
2 | 917 |
* The existing values for all rendering hints are discarded and |
918 |
* the new set of known hints and values are initialized from the |
|
919 |
* specified {@link Map} object. |
|
920 |
* Hint categories include controls for rendering quality and |
|
921 |
* overall time/quality trade-off in the rendering process. |
|
35667 | 922 |
* Refer to the {@code RenderingHints} class for definitions of |
2 | 923 |
* some common keys and values. |
924 |
* @param hints the rendering hints to be set |
|
925 |
* @see #getRenderingHints |
|
926 |
* @see RenderingHints |
|
927 |
*/ |
|
928 |
public abstract void setRenderingHints(Map<?,?> hints); |
|
929 |
||
930 |
/** |
|
931 |
* Sets the values of an arbitrary number of preferences for the |
|
932 |
* rendering algorithms. |
|
933 |
* Only values for the rendering hints that are present in the |
|
35667 | 934 |
* specified {@code Map} object are modified. |
2 | 935 |
* All other preferences not present in the specified |
936 |
* object are left unmodified. |
|
937 |
* Hint categories include controls for rendering quality and |
|
938 |
* overall time/quality trade-off in the rendering process. |
|
35667 | 939 |
* Refer to the {@code RenderingHints} class for definitions of |
2 | 940 |
* some common keys and values. |
941 |
* @param hints the rendering hints to be set |
|
942 |
* @see RenderingHints |
|
943 |
*/ |
|
944 |
public abstract void addRenderingHints(Map<?,?> hints); |
|
945 |
||
946 |
/** |
|
947 |
* Gets the preferences for the rendering algorithms. Hint categories |
|
948 |
* include controls for rendering quality and overall time/quality |
|
949 |
* trade-off in the rendering process. |
|
950 |
* Returns all of the hint key/value pairs that were ever specified in |
|
951 |
* one operation. Refer to the |
|
35667 | 952 |
* {@code RenderingHints} class for definitions of some common |
2 | 953 |
* keys and values. |
35667 | 954 |
* @return a reference to an instance of {@code RenderingHints} |
2 | 955 |
* that contains the current preferences. |
956 |
* @see RenderingHints |
|
957 |
* @see #setRenderingHints(Map) |
|
958 |
*/ |
|
959 |
public abstract RenderingHints getRenderingHints(); |
|
960 |
||
961 |
/** |
|
35667 | 962 |
* Translates the origin of the {@code Graphics2D} context to the |
2 | 963 |
* point (<i>x</i>, <i>y</i>) in the current coordinate system. |
35667 | 964 |
* Modifies the {@code Graphics2D} context so that its new origin |
2 | 965 |
* corresponds to the point (<i>x</i>, <i>y</i>) in the |
35667 | 966 |
* {@code Graphics2D} context's former coordinate system. All |
2 | 967 |
* coordinates used in subsequent rendering operations on this graphics |
968 |
* context are relative to this new origin. |
|
969 |
* @param x the specified x coordinate |
|
970 |
* @param y the specified y coordinate |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22260
diff
changeset
|
971 |
* @since 1.0 |
2 | 972 |
*/ |
973 |
public abstract void translate(int x, int y); |
|
974 |
||
975 |
/** |
|
976 |
* Concatenates the current |
|
35667 | 977 |
* {@code Graphics2D Transform} |
2 | 978 |
* with a translation transform. |
979 |
* Subsequent rendering is translated by the specified |
|
980 |
* distance relative to the previous position. |
|
981 |
* This is equivalent to calling transform(T), where T is an |
|
35667 | 982 |
* {@code AffineTransform} represented by the following matrix: |
2 | 983 |
* <pre> |
984 |
* [ 1 0 tx ] |
|
985 |
* [ 0 1 ty ] |
|
986 |
* [ 0 0 1 ] |
|
987 |
* </pre> |
|
988 |
* @param tx the distance to translate along the x-axis |
|
989 |
* @param ty the distance to translate along the y-axis |
|
990 |
*/ |
|
991 |
public abstract void translate(double tx, double ty); |
|
992 |
||
993 |
/** |
|
35667 | 994 |
* Concatenates the current {@code Graphics2D} |
995 |
* {@code Transform} with a rotation transform. |
|
2 | 996 |
* Subsequent rendering is rotated by the specified radians relative |
997 |
* to the previous origin. |
|
35667 | 998 |
* This is equivalent to calling {@code transform(R)}, where R is an |
999 |
* {@code AffineTransform} represented by the following matrix: |
|
2 | 1000 |
* <pre> |
1001 |
* [ cos(theta) -sin(theta) 0 ] |
|
1002 |
* [ sin(theta) cos(theta) 0 ] |
|
1003 |
* [ 0 0 1 ] |
|
1004 |
* </pre> |
|
1005 |
* Rotating with a positive angle theta rotates points on the positive |
|
1006 |
* x axis toward the positive y axis. |
|
1007 |
* @param theta the angle of rotation in radians |
|
1008 |
*/ |
|
1009 |
public abstract void rotate(double theta); |
|
1010 |
||
1011 |
/** |
|
35667 | 1012 |
* Concatenates the current {@code Graphics2D} |
1013 |
* {@code Transform} with a translated rotation |
|
2 | 1014 |
* transform. Subsequent rendering is transformed by a transform |
1015 |
* which is constructed by translating to the specified location, |
|
1016 |
* rotating by the specified radians, and translating back by the same |
|
1017 |
* amount as the original translation. This is equivalent to the |
|
1018 |
* following sequence of calls: |
|
1019 |
* <pre> |
|
1020 |
* translate(x, y); |
|
1021 |
* rotate(theta); |
|
1022 |
* translate(-x, -y); |
|
1023 |
* </pre> |
|
1024 |
* Rotating with a positive angle theta rotates points on the positive |
|
1025 |
* x axis toward the positive y axis. |
|
1026 |
* @param theta the angle of rotation in radians |
|
1027 |
* @param x the x coordinate of the origin of the rotation |
|
1028 |
* @param y the y coordinate of the origin of the rotation |
|
1029 |
*/ |
|
1030 |
public abstract void rotate(double theta, double x, double y); |
|
1031 |
||
1032 |
/** |
|
35667 | 1033 |
* Concatenates the current {@code Graphics2D} |
1034 |
* {@code Transform} with a scaling transformation |
|
2 | 1035 |
* Subsequent rendering is resized according to the specified scaling |
1036 |
* factors relative to the previous scaling. |
|
35667 | 1037 |
* This is equivalent to calling {@code transform(S)}, where S is an |
1038 |
* {@code AffineTransform} represented by the following matrix: |
|
2 | 1039 |
* <pre> |
1040 |
* [ sx 0 0 ] |
|
1041 |
* [ 0 sy 0 ] |
|
1042 |
* [ 0 0 1 ] |
|
1043 |
* </pre> |
|
1044 |
* @param sx the amount by which X coordinates in subsequent |
|
1045 |
* rendering operations are multiplied relative to previous |
|
1046 |
* rendering operations. |
|
1047 |
* @param sy the amount by which Y coordinates in subsequent |
|
1048 |
* rendering operations are multiplied relative to previous |
|
1049 |
* rendering operations. |
|
1050 |
*/ |
|
1051 |
public abstract void scale(double sx, double sy); |
|
1052 |
||
1053 |
/** |
|
35667 | 1054 |
* Concatenates the current {@code Graphics2D} |
1055 |
* {@code Transform} with a shearing transform. |
|
2 | 1056 |
* Subsequent renderings are sheared by the specified |
1057 |
* multiplier relative to the previous position. |
|
35667 | 1058 |
* This is equivalent to calling {@code transform(SH)}, where SH |
1059 |
* is an {@code AffineTransform} represented by the following |
|
2 | 1060 |
* matrix: |
1061 |
* <pre> |
|
1062 |
* [ 1 shx 0 ] |
|
1063 |
* [ shy 1 0 ] |
|
1064 |
* [ 0 0 1 ] |
|
1065 |
* </pre> |
|
1066 |
* @param shx the multiplier by which coordinates are shifted in |
|
1067 |
* the positive X axis direction as a function of their Y coordinate |
|
1068 |
* @param shy the multiplier by which coordinates are shifted in |
|
1069 |
* the positive Y axis direction as a function of their X coordinate |
|
1070 |
*/ |
|
1071 |
public abstract void shear(double shx, double shy); |
|
1072 |
||
1073 |
/** |
|
35667 | 1074 |
* Composes an {@code AffineTransform} object with the |
1075 |
* {@code Transform} in this {@code Graphics2D} according |
|
2 | 1076 |
* to the rule last-specified-first-applied. If the current |
35667 | 1077 |
* {@code Transform} is Cx, the result of composition |
1078 |
* with Tx is a new {@code Transform} Cx'. Cx' becomes the |
|
1079 |
* current {@code Transform} for this {@code Graphics2D}. |
|
1080 |
* Transforming a point p by the updated {@code Transform} Cx' is |
|
2 | 1081 |
* equivalent to first transforming p by Tx and then transforming |
35667 | 1082 |
* the result by the original {@code Transform} Cx. In other |
2 | 1083 |
* words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary, |
1084 |
* so further modifications to Tx do not affect rendering. |
|
35667 | 1085 |
* @param Tx the {@code AffineTransform} object to be composed with |
1086 |
* the current {@code Transform} |
|
2 | 1087 |
* @see #setTransform |
1088 |
* @see AffineTransform |
|
1089 |
*/ |
|
1090 |
public abstract void transform(AffineTransform Tx); |
|
1091 |
||
1092 |
/** |
|
35667 | 1093 |
* Overwrites the Transform in the {@code Graphics2D} context. |
2 | 1094 |
* WARNING: This method should <b>never</b> be used to apply a new |
1095 |
* coordinate transform on top of an existing transform because the |
|
35667 | 1096 |
* {@code Graphics2D} might already have a transform that is |
2 | 1097 |
* needed for other purposes, such as rendering Swing |
1098 |
* components or applying a scaling transformation to adjust for the |
|
1099 |
* resolution of a printer. |
|
1100 |
* <p>To add a coordinate transform, use the |
|
35667 | 1101 |
* {@code transform}, {@code rotate}, {@code scale}, |
1102 |
* or {@code shear} methods. The {@code setTransform} |
|
2 | 1103 |
* method is intended only for restoring the original |
35667 | 1104 |
* {@code Graphics2D} transform after rendering, as shown in this |
2 | 1105 |
* example: |
21777 | 1106 |
* <pre> |
2 | 1107 |
* // Get the current transform |
1108 |
* AffineTransform saveAT = g2.getTransform(); |
|
1109 |
* // Perform transformation |
|
1110 |
* g2d.transform(...); |
|
1111 |
* // Render |
|
1112 |
* g2d.draw(...); |
|
1113 |
* // Restore original transform |
|
1114 |
* g2d.setTransform(saveAT); |
|
21777 | 1115 |
* </pre> |
2 | 1116 |
* |
35667 | 1117 |
* @param Tx the {@code AffineTransform} that was retrieved |
1118 |
* from the {@code getTransform} method |
|
2 | 1119 |
* @see #transform |
1120 |
* @see #getTransform |
|
1121 |
* @see AffineTransform |
|
1122 |
*/ |
|
1123 |
public abstract void setTransform(AffineTransform Tx); |
|
1124 |
||
1125 |
/** |
|
35667 | 1126 |
* Returns a copy of the current {@code Transform} in the |
1127 |
* {@code Graphics2D} context. |
|
1128 |
* @return the current {@code AffineTransform} in the |
|
1129 |
* {@code Graphics2D} context. |
|
2 | 1130 |
* @see #transform |
1131 |
* @see #setTransform |
|
1132 |
*/ |
|
1133 |
public abstract AffineTransform getTransform(); |
|
1134 |
||
1135 |
/** |
|
35667 | 1136 |
* Returns the current {@code Paint} of the |
1137 |
* {@code Graphics2D} context. |
|
1138 |
* @return the current {@code Graphics2D Paint}, |
|
2 | 1139 |
* which defines a color or pattern. |
1140 |
* @see #setPaint |
|
1141 |
* @see java.awt.Graphics#setColor |
|
1142 |
*/ |
|
1143 |
public abstract Paint getPaint(); |
|
1144 |
||
1145 |
/** |
|
35667 | 1146 |
* Returns the current {@code Composite} in the |
1147 |
* {@code Graphics2D} context. |
|
1148 |
* @return the current {@code Graphics2D Composite}, |
|
2 | 1149 |
* which defines a compositing style. |
1150 |
* @see #setComposite |
|
1151 |
*/ |
|
1152 |
public abstract Composite getComposite(); |
|
1153 |
||
1154 |
/** |
|
35667 | 1155 |
* Sets the background color for the {@code Graphics2D} context. |
2 | 1156 |
* The background color is used for clearing a region. |
35667 | 1157 |
* When a {@code Graphics2D} is constructed for a |
1158 |
* {@code Component}, the background color is |
|
1159 |
* inherited from the {@code Component}. Setting the background color |
|
1160 |
* in the {@code Graphics2D} context only affects the subsequent |
|
1161 |
* {@code clearRect} calls and not the background color of the |
|
1162 |
* {@code Component}. To change the background |
|
1163 |
* of the {@code Component}, use appropriate methods of |
|
1164 |
* the {@code Component}. |
|
21278 | 1165 |
* @param color the background color that is used in |
35667 | 1166 |
* subsequent calls to {@code clearRect} |
2 | 1167 |
* @see #getBackground |
1168 |
* @see java.awt.Graphics#clearRect |
|
1169 |
*/ |
|
1170 |
public abstract void setBackground(Color color); |
|
1171 |
||
1172 |
/** |
|
1173 |
* Returns the background color used for clearing a region. |
|
35667 | 1174 |
* @return the current {@code Graphics2D Color}, |
2 | 1175 |
* which defines the background color. |
1176 |
* @see #setBackground |
|
1177 |
*/ |
|
1178 |
public abstract Color getBackground(); |
|
1179 |
||
1180 |
/** |
|
35667 | 1181 |
* Returns the current {@code Stroke} in the |
1182 |
* {@code Graphics2D} context. |
|
1183 |
* @return the current {@code Graphics2D Stroke}, |
|
2 | 1184 |
* which defines the line style. |
1185 |
* @see #setStroke |
|
1186 |
*/ |
|
1187 |
public abstract Stroke getStroke(); |
|
1188 |
||
1189 |
/** |
|
35667 | 1190 |
* Intersects the current {@code Clip} with the interior of the |
1191 |
* specified {@code Shape} and sets the {@code Clip} to the |
|
1192 |
* resulting intersection. The specified {@code Shape} is |
|
1193 |
* transformed with the current {@code Graphics2D} |
|
1194 |
* {@code Transform} before being intersected with the current |
|
1195 |
* {@code Clip}. This method is used to make the current |
|
1196 |
* {@code Clip} smaller. |
|
1197 |
* To make the {@code Clip} larger, use {@code setClip}. |
|
2 | 1198 |
* The <i>user clip</i> modified by this method is independent of the |
1199 |
* clipping associated with device bounds and visibility. If no clip has |
|
1200 |
* previously been set, or if the clip has been cleared using |
|
35667 | 1201 |
* {@link Graphics#setClip(Shape) setClip} with a {@code null} |
1202 |
* argument, the specified {@code Shape} becomes the new |
|
2 | 1203 |
* user clip. |
35667 | 1204 |
* @param s the {@code Shape} to be intersected with the current |
1205 |
* {@code Clip}. If {@code s} is {@code null}, |
|
1206 |
* this method clears the current {@code Clip}. |
|
2 | 1207 |
*/ |
1208 |
public abstract void clip(Shape s); |
|
1209 |
||
1210 |
/** |
|
35667 | 1211 |
* Get the rendering context of the {@code Font} within this |
1212 |
* {@code Graphics2D} context. |
|
2 | 1213 |
* The {@link FontRenderContext} |
1214 |
* encapsulates application hints such as anti-aliasing and |
|
1215 |
* fractional metrics, as well as target device specific information |
|
1216 |
* such as dots-per-inch. This information should be provided by the |
|
1217 |
* application when using objects that perform typographical |
|
35667 | 1218 |
* formatting, such as {@code Font} and |
1219 |
* {@code TextLayout}. This information should also be provided |
|
2 | 1220 |
* by applications that perform their own layout and need accurate |
1221 |
* measurements of various characteristics of glyphs such as advance |
|
1222 |
* and line height when various rendering hints have been applied to |
|
1223 |
* the text rendering. |
|
1224 |
* |
|
1225 |
* @return a reference to an instance of FontRenderContext. |
|
1226 |
* @see java.awt.font.FontRenderContext |
|
1227 |
* @see java.awt.Font#createGlyphVector |
|
1228 |
* @see java.awt.font.TextLayout |
|
1229 |
* @since 1.2 |
|
1230 |
*/ |
|
1231 |
||
1232 |
public abstract FontRenderContext getFontRenderContext(); |
|
1233 |
||
1234 |
} |