001/* Copyright (C) 2000, 2002, 2004, 2006,  Free Software Foundation
002
003This file is part of GNU Classpath.
004
005GNU Classpath is free software; you can redistribute it and/or modify
006it under the terms of the GNU General Public License as published by
007the Free Software Foundation; either version 2, or (at your option)
008any later version.
009
010GNU Classpath is distributed in the hope that it will be useful, but
011WITHOUT ANY WARRANTY; without even the implied warranty of
012MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013General Public License for more details.
014
015You should have received a copy of the GNU General Public License
016along with GNU Classpath; see the file COPYING.  If not, write to the
017Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01802110-1301 USA.
019
020Linking this library statically or dynamically with other modules is
021making a combined work based on this library.  Thus, the terms and
022conditions of the GNU General Public License cover the whole
023combination.
024
025As a special exception, the copyright holders of this library give you
026permission to link this library with independent modules to produce an
027executable, regardless of the license terms of these independent
028modules, and to copy and distribute the resulting executable under
029terms of your choice, provided that you also meet, for each linked
030independent module, the terms and conditions of the license of that
031module.  An independent module is a module which is not derived from
032or based on this library.  If you modify this library, you may extend
033this exception to your version of the library, but you are not
034obligated to do so.  If you do not wish to do so, delete this
035exception statement from your version. */
036
037
038package java.awt;
039
040import java.awt.font.FontRenderContext;
041import java.awt.font.GlyphVector;
042import java.awt.geom.AffineTransform;
043import java.awt.image.BufferedImage;
044import java.awt.image.BufferedImageOp;
045import java.awt.image.ImageObserver;
046import java.awt.image.RenderedImage;
047import java.awt.image.renderable.RenderableImage;
048import java.awt.print.PageFormat;
049import java.awt.print.Printable;
050import java.text.AttributedCharacterIterator;
051import java.util.Map;
052
053/**
054 * An abstract class defining a device independent two-dimensional vector 
055 * graphics API.  Concrete subclasses implement this API for output of 
056 * vector graphics to:
057 * <p>
058 * <ul>
059 * <li>a {@link javax.swing.JComponent} - in the 
060 *     {@link javax.swing.JComponent#paint(Graphics)} method, the incoming 
061 *     {@link Graphics} should always be an instance of 
062 *     <code>Graphics2D</code>;</li> 
063 * <li>a {@link BufferedImage} - see 
064 *     {@link BufferedImage#createGraphics()};</li>
065 * <li>a {@link java.awt.print.PrinterJob} - in the 
066 *     {@link Printable#print(Graphics, PageFormat, int)} method, the incoming
067 *     {@link Graphics} should always be an instance of 
068 *     <code>Graphics2D</code>.</li>
069 * </ul>
070 * <p>
071 * Third party libraries provide support for output to other formats via this 
072 * API, including encapsulated postscript (EPS), portable document format (PDF),
073 * and scalable vector graphics (SVG).
074 * 
075 * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
076 */
077public abstract class Graphics2D extends Graphics
078{
079
080  protected Graphics2D()
081  {
082  }
083  
084  public void draw3DRect(int x, int y, int width, int height,
085                         boolean raised)
086  {
087    super.draw3DRect(x, y, width, height, raised);
088  }
089  
090  public void fill3DRect(int x, int y, int width, int height,
091                         boolean raised)
092  {
093    super.fill3DRect(x, y, width, height, raised);
094  }
095
096  /**
097   * Draws an outline around a shape using the current stroke and paint.
098   * 
099   * @param shape  the shape (<code>null</code> not permitted).
100   * 
101   * @see #getStroke()
102   * @see #getPaint()
103   */
104  public abstract void draw(Shape shape);
105
106  public abstract boolean drawImage(Image image, AffineTransform xform,
107                                    ImageObserver obs);
108
109  public abstract void drawImage(BufferedImage image,
110                                 BufferedImageOp op,
111                                 int x,
112                                 int y);
113
114  public abstract void drawRenderedImage(RenderedImage image,
115                                         AffineTransform xform);
116
117  public abstract void drawRenderableImage(RenderableImage image,
118                                           AffineTransform xform);
119
120  /**
121   * Draws a string at the specified location, using the current font.
122   * 
123   * @param text  the string to draw.
124   * @param x  the x-coordinate.
125   * @param y  the y-coordinate.
126   * 
127   * @see Graphics#setFont(Font)
128   */
129  public abstract void drawString(String text, int x, int y);
130
131  /**
132   * Draws a string at the specified location, using the current font.
133   * 
134   * @param text  the string to draw.
135   * @param x  the x-coordinate.
136   * @param y  the y-coordinate.
137   * 
138   * @see Graphics#setFont(Font)
139   */
140  public abstract void drawString(String text, float x, float y);
141    
142  /**
143   * Draws an attributed string at the specified location.
144   * 
145   * @param iterator  the source of the attributed text.
146   * @param x  the x-coordinate.
147   * @param y  the y-coordinate.
148   */
149  public abstract void drawString(AttributedCharacterIterator iterator,
150                                  int x, int y);
151
152  /**
153   * Draws an attributed string at the specified location.
154   * 
155   * @param iterator  the source of the attributed text.
156   * @param x  the x-coordinate.
157   * @param y  the y-coordinate.
158   */
159  public abstract void drawString(AttributedCharacterIterator iterator,
160                                  float x, float y);
161
162  /**
163   * Fills the interior of the specified <code>shape</code> using the current
164   * paint.
165   * 
166   * @param shape  the shape to fill (<code>null</code> not permitted).
167   * 
168   * @see #draw(Shape)
169   * @see #getPaint()
170   */
171  public abstract void fill(Shape shape);
172    
173  public abstract boolean hit(Rectangle rect, Shape text,
174                              boolean onStroke);
175
176  public abstract GraphicsConfiguration getDeviceConfiguration();
177
178  /**
179   * Sets the current compositing rule.
180   * 
181   * @param comp  the composite.
182   * 
183   * @see #getComposite()
184   */
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   * @see #getPaint()
193   */
194  public abstract void setPaint(Paint paint);
195
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   * @see #getStroke()
202   */
203  public abstract void setStroke(Stroke stroke);
204
205  /**
206   * Adds or updates a hint in the current rendering hints table.
207   * 
208   * @param hintKey  the hint key.
209   * @param hintValue  the hint value.
210   */
211  public abstract void setRenderingHint(RenderingHints.Key hintKey,
212                                        Object hintValue);
213
214  /**
215   * Returns the current value of a rendering hint.
216   * 
217   * @param hintKey  the key for the hint.
218   * 
219   * @return The value for the specified hint.
220   */
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   * @see #addRenderingHints(Map)
229   */
230  public abstract void setRenderingHints(Map<?,?> hints);
231
232  /**
233   * Adds/updates the rendering hint.
234   * 
235   * @param hints  the hints to add or update.
236   */
237  public abstract void addRenderingHints(Map<?,?> hints);
238
239  /**
240   * Returns the current rendering hints.
241   * 
242   * @return The current rendering hints.
243   */
244  public abstract RenderingHints getRenderingHints();
245
246  public abstract void translate(int x, int y);
247
248  public abstract void translate(double tx, double ty);
249    
250  public abstract void rotate(double theta);
251
252  public abstract void rotate(double theta, double x, double y);
253
254  public abstract void scale(double scaleX, double scaleY);
255
256  public abstract void shear(double shearX, double shearY);
257
258  /**
259   * Sets the current transform to a concatenation of <code>transform</code>
260   * and the existing transform.
261   * 
262   * @param transform  the transform.
263   */
264  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   * @see #getTransform()
274   */
275  public abstract void setTransform(AffineTransform transform);
276
277  /**
278   * Returns the current transform.
279   * 
280   * @return The current transform.
281   * 
282   * @see #setTransform(AffineTransform)
283   */
284  public abstract AffineTransform getTransform();
285
286  /**
287   * Returns the current paint.
288   * 
289   * @return The current paint.
290   * 
291   * @see #setPaint(Paint)
292   */
293  public abstract Paint getPaint();
294
295  /**
296   * Returns the current compositing rule.
297   * 
298   * @return The current compositing rule.
299   * 
300   * @see #setComposite(Composite)
301   */
302  public abstract Composite getComposite();
303
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   * @see #getBackground()
311   */
312  public abstract void setBackground(Color color);
313
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   * @see #setBackground(Color)
321   */
322  public abstract Color getBackground();
323
324  /**
325   * Returns the current stroke.
326   * 
327   * @return The current stroke.
328   * 
329   * @see #setStroke(Stroke)
330   */
331  public abstract Stroke getStroke();    
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   * @see Graphics#setClip(Shape)
340   */
341  public abstract void clip(Shape s);
342
343  /**
344   * Returns the font render context.
345   * 
346   * @return The font render context.
347   */
348  public abstract FontRenderContext getFontRenderContext();
349
350  /**
351   * Draws a glyph vector at the specified location.
352   * 
353   * @param g  the glyph vector.
354   * @param x  the x-coordinate.
355   * @param y  the y-coordinate.
356   */
357  public abstract void drawGlyphVector(GlyphVector g, float x, float y);
358}