Graphics2D.java 10.3 KB
Newer Older
1
/* Copyright (C) 2000, 2002, 2004, 2006,  Free Software Foundation
Tom Tromey committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


package java.awt;

import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
48 49
import java.awt.print.PageFormat;
import java.awt.print.Printable;
Tom Tromey committed
50 51 52 53
import java.text.AttributedCharacterIterator;
import java.util.Map;

/**
54 55
 * An abstract class defining a device independent two-dimensional vector
 * graphics API.  Concrete subclasses implement this API for output of
56
 * vector graphics to:
57 58
 * <p>
 * <ul>
59 60 61 62 63
 * <li>a {@link javax.swing.JComponent} - in the
 *     {@link javax.swing.JComponent#paint(Graphics)} method, the incoming
 *     {@link Graphics} should always be an instance of
 *     <code>Graphics2D</code>;</li>
 * <li>a {@link BufferedImage} - see
64
 *     {@link BufferedImage#createGraphics()};</li>
65
 * <li>a {@link java.awt.print.PrinterJob} - in the
66
 *     {@link Printable#print(Graphics, PageFormat, int)} method, the incoming
67
 *     {@link Graphics} should always be an instance of
68
 *     <code>Graphics2D</code>.</li>
69 70
 * </ul>
 * <p>
71
 * Third party libraries provide support for output to other formats via this
72 73
 * API, including encapsulated postscript (EPS), portable document format (PDF),
 * and scalable vector graphics (SVG).
74
 *
Tom Tromey committed
75 76 77 78 79 80 81 82
 * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
 */
public abstract class Graphics2D extends Graphics
{

  protected Graphics2D()
  {
  }
83

Tom Tromey committed
84
  public void draw3DRect(int x, int y, int width, int height,
85
                         boolean raised)
Tom Tromey committed
86 87 88
  {
    super.draw3DRect(x, y, width, height, raised);
  }
89

Tom Tromey committed
90
  public void fill3DRect(int x, int y, int width, int height,
91
                         boolean raised)
Tom Tromey committed
92 93 94 95
  {
    super.fill3DRect(x, y, width, height, raised);
  }

96 97
  /**
   * Draws an outline around a shape using the current stroke and paint.
98
   *
99
   * @param shape  the shape (<code>null</code> not permitted).
100
   *
101 102 103
   * @see #getStroke()
   * @see #getPaint()
   */
Tom Tromey committed
104 105 106
  public abstract void draw(Shape shape);

  public abstract boolean drawImage(Image image, AffineTransform xform,
107
                                    ImageObserver obs);
Tom Tromey committed
108 109

  public abstract void drawImage(BufferedImage image,
110 111 112
                                 BufferedImageOp op,
                                 int x,
                                 int y);
Tom Tromey committed
113 114

  public abstract void drawRenderedImage(RenderedImage image,
115
                                         AffineTransform xform);
Tom Tromey committed
116 117 118 119

  public abstract void drawRenderableImage(RenderableImage image,
                                           AffineTransform xform);

120 121
  /**
   * Draws a string at the specified location, using the current font.
122
   *
123 124 125
   * @param text  the string to draw.
   * @param x  the x-coordinate.
   * @param y  the y-coordinate.
126
   *
127 128
   * @see Graphics#setFont(Font)
   */
Tom Tromey committed
129 130
  public abstract void drawString(String text, int x, int y);

131 132
  /**
   * Draws a string at the specified location, using the current font.
133
   *
134 135 136
   * @param text  the string to draw.
   * @param x  the x-coordinate.
   * @param y  the y-coordinate.
137
   *
138 139
   * @see Graphics#setFont(Font)
   */
Tom Tromey committed
140
  public abstract void drawString(String text, float x, float y);
141

142 143
  /**
   * Draws an attributed string at the specified location.
144
   *
145 146 147 148
   * @param iterator  the source of the attributed text.
   * @param x  the x-coordinate.
   * @param y  the y-coordinate.
   */
Tom Tromey committed
149 150 151
  public abstract void drawString(AttributedCharacterIterator iterator,
                                  int x, int y);

152 153
  /**
   * Draws an attributed string at the specified location.
154
   *
155 156 157 158
   * @param iterator  the source of the attributed text.
   * @param x  the x-coordinate.
   * @param y  the y-coordinate.
   */
Tom Tromey committed
159
  public abstract void drawString(AttributedCharacterIterator iterator,
160
                                  float x, float y);
Tom Tromey committed
161

162 163 164
  /**
   * Fills the interior of the specified <code>shape</code> using the current
   * paint.
165
   *
166
   * @param shape  the shape to fill (<code>null</code> not permitted).
167
   *
168 169 170
   * @see #draw(Shape)
   * @see #getPaint()
   */
Tom Tromey committed
171
  public abstract void fill(Shape shape);
172

Tom Tromey committed
173
  public abstract boolean hit(Rectangle rect, Shape text,
174
                              boolean onStroke);
Tom Tromey committed
175 176 177

  public abstract GraphicsConfiguration getDeviceConfiguration();

178 179
  /**
   * Sets the current compositing rule.
180
   *
181
   * @param comp  the composite.
182
   *
183 184
   * @see #getComposite()
   */
Tom Tromey committed
185
  public abstract void setComposite(Composite comp);
186

187 188
  /**
   * Sets the paint to be used for subsequent drawing operations.
189
   *
190
   * @param paint  the paint (<code>null</code> not permitted).
191
   *
192 193
   * @see #getPaint()
   */
Tom Tromey committed
194 195
  public abstract void setPaint(Paint paint);

196 197
  /**
   * Sets the stroke to be used for subsequent drawing operations.
198
   *
199
   * @param stroke  the stroke (<code>null</code> not permitted).
200
   *
201 202
   * @see #getStroke()
   */
Tom Tromey committed
203 204
  public abstract void setStroke(Stroke stroke);

205 206
  /**
   * Adds or updates a hint in the current rendering hints table.
207
   *
208 209 210
   * @param hintKey  the hint key.
   * @param hintValue  the hint value.
   */
Tom Tromey committed
211 212 213
  public abstract void setRenderingHint(RenderingHints.Key hintKey,
                                        Object hintValue);

214 215
  /**
   * Returns the current value of a rendering hint.
216
   *
217
   * @param hintKey  the key for the hint.
218
   *
219 220
   * @return The value for the specified hint.
   */
Tom Tromey committed
221
  public abstract Object getRenderingHint(RenderingHints.Key hintKey);
222

223 224
  /**
   * Replaces the current rendering hints with the supplied hints.
225
   *
226
   * @param hints  the hints.
227
   *
228 229
   * @see #addRenderingHints(Map)
   */
230
  public abstract void setRenderingHints(Map<?,?> hints);
Tom Tromey committed
231

232 233
  /**
   * Adds/updates the rendering hint.
234
   *
235 236
   * @param hints  the hints to add or update.
   */
237
  public abstract void addRenderingHints(Map<?,?> hints);
Tom Tromey committed
238

239 240
  /**
   * Returns the current rendering hints.
241
   *
242 243
   * @return The current rendering hints.
   */
Tom Tromey committed
244 245 246 247 248
  public abstract RenderingHints getRenderingHints();

  public abstract void translate(int x, int y);

  public abstract void translate(double tx, double ty);
249

Tom Tromey committed
250 251 252 253 254 255 256 257
  public abstract void rotate(double theta);

  public abstract void rotate(double theta, double x, double y);

  public abstract void scale(double scaleX, double scaleY);

  public abstract void shear(double shearX, double shearY);

258 259 260
  /**
   * Sets the current transform to a concatenation of <code>transform</code>
   * and the existing transform.
261
   *
262 263 264
   * @param transform  the transform.
   */
  public abstract void transform(AffineTransform transform);
265

266 267
  /**
   * Sets the current transform.  If the caller specifies a <code>null</code>
268
   * transform, this method should set the current transform to the
269
   * identity transform.
270
   *
271
   * @param transform  the transform (<code>null</code> permitted).
272
   *
273 274 275 276 277 278
   * @see #getTransform()
   */
  public abstract void setTransform(AffineTransform transform);

  /**
   * Returns the current transform.
279
   *
280
   * @return The current transform.
281
   *
282 283
   * @see #setTransform(AffineTransform)
   */
Tom Tromey committed
284 285
  public abstract AffineTransform getTransform();

286 287
  /**
   * Returns the current paint.
288
   *
289
   * @return The current paint.
290
   *
291 292
   * @see #setPaint(Paint)
   */
Tom Tromey committed
293 294
  public abstract Paint getPaint();

295 296
  /**
   * Returns the current compositing rule.
297
   *
298
   * @return The current compositing rule.
299
   *
300 301
   * @see #setComposite(Composite)
   */
Tom Tromey committed
302 303
  public abstract Composite getComposite();

304
  /**
305
   * Sets the background color (used by the
306
   * {@link Graphics#clearRect(int, int, int, int)} method).
307
   *
308
   * @param color  the color.
309
   *
310 311
   * @see #getBackground()
   */
Tom Tromey committed
312 313
  public abstract void setBackground(Color color);

314
  /**
315
   * Returns the color used by the
316
   * {@link Graphics#clearRect(int, int, int, int)} method.
317
   *
318
   * @return The background color.
319
   *
320 321
   * @see #setBackground(Color)
   */
Tom Tromey committed
322 323
  public abstract Color getBackground();

324 325
  /**
   * Returns the current stroke.
326
   *
327
   * @return The current stroke.
328
   *
329 330
   * @see #setStroke(Stroke)
   */
331
  public abstract Stroke getStroke();
Tom Tromey committed
332

333
  /**
334
   * Sets the clip region to the intersection of the current clipping region
335
   * and <code>s</code>.
336
   *
337
   * @param s  the shape to intersect with the current clipping region.
338
   *
339 340
   * @see Graphics#setClip(Shape)
   */
Tom Tromey committed
341 342
  public abstract void clip(Shape s);

343 344
  /**
   * Returns the font render context.
345
   *
346 347 348 349 350 351
   * @return The font render context.
   */
  public abstract FontRenderContext getFontRenderContext();

  /**
   * Draws a glyph vector at the specified location.
352
   *
353 354 355 356 357
   * @param g  the glyph vector.
   * @param x  the x-coordinate.
   * @param y  the y-coordinate.
   */
  public abstract void drawGlyphVector(GlyphVector g, float x, float y);
Tom Tromey committed
358
}