* graphics state. The rendering attributes applied include the * clip, transform, paint or color, and composite. * @see #setPaint * @see java.awt.Graphics#setColor * @see #transform * @see #setTransform * @see #setComposite * @see #clip * @see #setClip */ public void fill(Shape s) { addDrawingRect(s.getBounds()); mPrintMetrics.fill(this); } /** * Checks to see if the outline of a Shape intersects the specified * Rectangle in device space. * The rendering attributes taken into account include the * clip, transform, and stroke attributes. * @param rect The area in device space to check for a hit. * @param s The shape to check for a hit. * @param onStroke Flag to choose between testing the stroked or * the filled shape. * @return True if there is a hit, false otherwise. * @see #setStroke * @see #fill * @see #draw * @see #transform * @see #setTransform * @see #clip * @see #setClip */ public boolean hit(Rectangle rect, Shape s, boolean onStroke) { return mGraphics.hit(rect, s, onStroke); } /** * Sets the Composite in the current graphics state. Composite is used * in all drawing methods such as drawImage, drawString, draw, * and fill. It specifies how new pixels are to be combined with * the existing pixels on the graphics device in the rendering process. * @param comp The Composite object to be used for drawing. * @see java.awt.Graphics#setXORMode * @see java.awt.Graphics#setPaintMode * @see AlphaComposite */ public void setComposite(Composite comp) { mGraphics.setComposite(comp); } /** * Sets the Paint in the current graphics state. * @param paint The Paint object to be used to generate color in * the rendering process. * @see java.awt.Graphics#setColor * @see GradientPaint * @see TexturePaint */ public void setPaint(Paint paint) { mGraphics.setPaint(paint); } /** * Sets the Stroke in the current graphics state. * @param s The Stroke object to be used to stroke a Shape in * the rendering process. * @see BasicStroke */ public void setStroke(Stroke s) { mGraphics.setStroke(s); } /** * Sets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hintCategory The category of hint to be set. * @param hintValue The value indicating preferences for the specified * hint category. * @see RenderingHints */ public void setRenderingHint(Key hintCategory, Object hintValue) { mGraphics.setRenderingHint(hintCategory, hintValue); } /** * Returns the preferences for the rendering algorithms. * @param hintCategory The category of hint to be set. * @return The preferences for rendering algorithms. * @see RenderingHings */ public Object getRenderingHint(Key hintCategory) { return mGraphics.getRenderingHint(hintCategory); } /** * Sets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hints The rendering hints to be set * @see RenderingHints */ public void setRenderingHints(Map<?,?> hints) { mGraphics.setRenderingHints(hints); } /** * Adds a number of preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hints The rendering hints to be set * @see RenderingHints */ public void addRenderingHints(Map<?,?> hints) { mGraphics.addRenderingHints(hints); } /** * Gets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @see RenderingHints */ public RenderingHints getRenderingHints() { return mGraphics.getRenderingHints(); } /** * Composes a Transform object with the transform in this * Graphics2D according to the rule last-specified-first-applied. * If the currrent transform is Cx, the result of composition * with Tx is a new transform Cx'. Cx' becomes the current * transform for this Graphics2D. * Transforming a point p by the updated transform Cx' is * equivalent to first transforming p by Tx and then transforming * the result by the original transform Cx. In other words, * Cx'(p) = Cx(Tx(p)). * A copy of the Tx is made, if necessary, so further * modifications to Tx do not affect rendering. * @param Tx The Transform object to be composed with the current * transform. * @see #setTransform * @see TransformChain * @see AffineTransform */ public void transform(AffineTransform Tx) { mGraphics.transform(Tx); } /** * Sets the Transform in the current graphics state. * @param Tx The Transform object to be used in the rendering process. * @see #transform * @see TransformChain * @see AffineTransform */ public void setTransform(AffineTransform Tx) { mGraphics.setTransform(Tx); } /** * Returns the current Transform in the Graphics2D state. * @see #transform * @see #setTransform */ public AffineTransform getTransform() { return mGraphics.getTransform(); } /** * Returns the current Paint in the Graphics2D state. * @see #setPaint * @see java.awt.Graphics#setColor */ public Paint getPaint() { return mGraphics.getPaint(); } /** * Returns the current Composite in the Graphics2D state. * @see #setComposite */ public Composite getComposite() { return mGraphics.getComposite(); } /** * Sets the background color in this context used for clearing a region. * When Graphics2D is constructed for a component, the backgroung color is * inherited from the component. Setting the background color in the * Graphics2D context only affects the subsequent clearRect() calls and * not the background color of the component. To change the background * of the component, use appropriate methods of the component. * @param color The background color that should be used in * subsequent calls to clearRect(). * @see getBackground * @see Graphics.clearRect() */ public void setBackground(Color color) { mGraphics.setBackground(color); } /** * Returns the background color used for clearing a region. * @see setBackground */ public Color getBackground() { return mGraphics.getBackground(); } /** * Returns the current Stroke in the Graphics2D state. * @see setStroke */ public Stroke getStroke() { return mGraphics.getStroke(); } /** * Intersects the current clip with the interior of the specified Shape * and sets the current clip to the resulting intersection. * The indicated shape is transformed with the current transform in the * Graphics2D state before being intersected with the current clip. * This method is used to make the current clip smaller. * To make the clip larger, use any setClip method. * @param s The Shape to be intersected with the current clip. */ public void clip(Shape s) { mGraphics.clip(s); } /** * Return true if the Rectangle <code>rect</code> * intersects the area into which the application * has drawn. */ public boolean hitsDrawingArea(Rectangle rect) { return mDrawingArea.intersects((float) rect.getMinY(), (float) rect.getMaxY()); } /** * Return the object holding the summary of the * drawing done by the printing application. */ public PeekMetrics getMetrics() { return mPrintMetrics; } /* Support Routines for Calculating the Drawing Area */ /** * Shift the rectangle 'rect' to the position ('x', 'y') * and add the resulting rectangle to the area representing * the part of the page which is drawn into. */ private void addDrawingRect(Rectangle2D rect, float x, float y) { addDrawingRect((float) (rect.getX() + x), (float) (rect.getY() + y), (float) rect.getWidth(), (float) rect.getHeight()); } private void addDrawingRect(float x, float y, float width, float height) { Rectangle2D.Float bbox = new Rectangle2D.Float(x, y, width, height); addDrawingRect(bbox); } /** * Add the rectangle 'rect' to the area representing * the part of the page which is drawn into. */ private void addDrawingRect(Rectangle2D rect) { /* For testing purposes the following line can be uncommented. When uncommented it causes the entire page to be rasterized thus eliminating errors caused by a faulty bounding box calculation. */ //mDrawingArea.addInfinite(); AffineTransform matrix = getTransform(); Shape transShape = matrix.createTransformedShape(rect); Rectangle2D transRect = transShape.getBounds2D(); mDrawingArea.add((float) transRect.getMinY(), (float) transRect.getMaxY()); } /** * Add the stroked shape to the area representing * the part of the page which is drawn into. */ private void addStrokeShape(Shape s) { Shape transShape = getStroke().createStrokedShape(s); addDrawingRect(transShape.getBounds2D()); } /* Image Observer */ /** * Notify this object when the height or width become available * for an image. */ public synchronized boolean imageUpdate(Image img, int infoFlags, int x, int y, int width, int height) { boolean gotInfo = false; if((infoFlags & (WIDTH | HEIGHT)) != 0) { gotInfo = true; notify(); } return gotInfo; } private synchronized int getImageWidth(Image img) { /* Wait for the width the image to * become available. */ while (img.getWidth(this) == -1) { try { wait(); } catch (InterruptedException e) { } } return img.getWidth(this); } private synchronized int getImageHeight(Image img) { /* Wait for the height the image to * become available. */ while (img.getHeight(this) == -1) { try { wait(); } catch (InterruptedException e) { } } return img.getHeight(this); } /** * This private class does not return from its constructor * until 'img's width and height are available. */ protected class ImageWaiter implements ImageObserver { private int mWidth; private int mHeight; private boolean badImage = false; ImageWaiter(Image img) { waitForDimensions(img); } public int getWidth() { return mWidth; } public int getHeight() { return mHeight; } synchronized private void waitForDimensions(Image img) { mHeight = img.getHeight(this); mWidth = img.getWidth(this); while (!badImage && (mWidth < 0 || mHeight < 0)) { try { Thread.sleep(50); } catch(InterruptedException e) { // do nothing. } mHeight = img.getHeight(this); mWidth = img.getWidth(this); } if (badImage) { mHeight = 0; mWidth = 0; } } synchronized public boolean imageUpdate(Image image, int flags, int x, int y, int w, int h) { boolean dontCallMeAgain = (flags & (HEIGHT | ABORT | ERROR)) != 0; badImage = (flags & (ABORT | ERROR)) != 0; return dontCallMeAgain; } }}Lines 1501–1918 of 1918. Previous lines
* graphics state. The rendering attributes applied include the * clip, transform, paint or color, and composite. * @see #setPaint * @see java.awt.Graphics#setColor * @see #transform * @see #setTransform * @see #setComposite * @see #clip * @see #setClip */ public void fill(Shape s) { addDrawingRect(s.getBounds()); mPrintMetrics.fill(this); } /** * Checks to see if the outline of a Shape intersects the specified * Rectangle in device space. * The rendering attributes taken into account include the * clip, transform, and stroke attributes. * @param rect The area in device space to check for a hit. * @param s The shape to check for a hit. * @param onStroke Flag to choose between testing the stroked or * the filled shape. * @return True if there is a hit, false otherwise. * @see #setStroke * @see #fill * @see #draw * @see #transform * @see #setTransform * @see #clip * @see #setClip */ public boolean hit(Rectangle rect, Shape s, boolean onStroke) { return mGraphics.hit(rect, s, onStroke); } /** * Sets the Composite in the current graphics state. Composite is used * in all drawing methods such as drawImage, drawString, draw, * and fill. It specifies how new pixels are to be combined with * the existing pixels on the graphics device in the rendering process. * @param comp The Composite object to be used for drawing. * @see java.awt.Graphics#setXORMode * @see java.awt.Graphics#setPaintMode * @see AlphaComposite */ public void setComposite(Composite comp) { mGraphics.setComposite(comp); } /** * Sets the Paint in the current graphics state. * @param paint The Paint object to be used to generate color in * the rendering process. * @see java.awt.Graphics#setColor * @see GradientPaint * @see TexturePaint */ public void setPaint(Paint paint) { mGraphics.setPaint(paint); } /** * Sets the Stroke in the current graphics state. * @param s The Stroke object to be used to stroke a Shape in * the rendering process. * @see BasicStroke */ public void setStroke(Stroke s) { mGraphics.setStroke(s); } /** * Sets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hintCategory The category of hint to be set. * @param hintValue The value indicating preferences for the specified * hint category. * @see RenderingHints */ public void setRenderingHint(Key hintCategory, Object hintValue) { mGraphics.setRenderingHint(hintCategory, hintValue); } /** * Returns the preferences for the rendering algorithms. * @param hintCategory The category of hint to be set. * @return The preferences for rendering algorithms. * @see RenderingHings */ public Object getRenderingHint(Key hintCategory) { return mGraphics.getRenderingHint(hintCategory); } /** * Sets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hints The rendering hints to be set * @see RenderingHints */ public void setRenderingHints(Map<?,?> hints) { mGraphics.setRenderingHints(hints); } /** * Adds a number of preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hints The rendering hints to be set * @see RenderingHints */ public void addRenderingHints(Map<?,?> hints) { mGraphics.addRenderingHints(hints); } /** * Gets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @see RenderingHints */ public RenderingHints getRenderingHints() { return mGraphics.getRenderingHints(); } /** * Composes a Transform object with the transform in this * Graphics2D according to the rule last-specified-first-applied. * If the currrent transform is Cx, the result of composition * with Tx is a new transform Cx'. Cx' becomes the current * transform for this Graphics2D. * Transforming a point p by the updated transform Cx' is * equivalent to first transforming p by Tx and then transforming * the result by the original transform Cx. In other words, * Cx'(p) = Cx(Tx(p)). * A copy of the Tx is made, if necessary, so further * modifications to Tx do not affect rendering. * @param Tx The Transform object to be composed with the current * transform. * @see #setTransform * @see TransformChain * @see AffineTransform */ public void transform(AffineTransform Tx) { mGraphics.transform(Tx); } /** * Sets the Transform in the current graphics state. * @param Tx The Transform object to be used in the rendering process. * @see #transform * @see TransformChain * @see AffineTransform */ public void setTransform(AffineTransform Tx) { mGraphics.setTransform(Tx); } /** * Returns the current Transform in the Graphics2D state. * @see #transform * @see #setTransform */ public AffineTransform getTransform() { return mGraphics.getTransform(); } /** * Returns the current Paint in the Graphics2D state. * @see #setPaint * @see java.awt.Graphics#setColor */ public Paint getPaint() { return mGraphics.getPaint(); } /** * Returns the current Composite in the Graphics2D state. * @see #setComposite */ public Composite getComposite() { return mGraphics.getComposite(); } /** * Sets the background color in this context used for clearing a region. * When Graphics2D is constructed for a component, the backgroung color is * inherited from the component. Setting the background color in the * Graphics2D context only affects the subsequent clearRect() calls and * not the background color of the component. To change the background * of the component, use appropriate methods of the component. * @param color The background color that should be used in * subsequent calls to clearRect(). * @see getBackground * @see Graphics.clearRect() */ public void setBackground(Color color) { mGraphics.setBackground(color); } /** * Returns the background color used for clearing a region. * @see setBackground */ public Color getBackground() { return mGraphics.getBackground(); } /** * Returns the current Stroke in the Graphics2D state. * @see setStroke */ public Stroke getStroke() { return mGraphics.getStroke(); } /** * Intersects the current clip with the interior of the specified Shape * and sets the current clip to the resulting intersection. * The indicated shape is transformed with the current transform in the * Graphics2D state before being intersected with the current clip. * This method is used to make the current clip smaller. * To make the clip larger, use any setClip method. * @param s The Shape to be intersected with the current clip. */ public void clip(Shape s) { mGraphics.clip(s); } /** * Return true if the Rectangle <code>rect</code> * intersects the area into which the application * has drawn. */ public boolean hitsDrawingArea(Rectangle rect) { return mDrawingArea.intersects((float) rect.getMinY(), (float) rect.getMaxY()); } /** * Return the object holding the summary of the * drawing done by the printing application. */ public PeekMetrics getMetrics() { return mPrintMetrics; } /* Support Routines for Calculating the Drawing Area */ /** * Shift the rectangle 'rect' to the position ('x', 'y') * and add the resulting rectangle to the area representing * the part of the page which is drawn into. */ private void addDrawingRect(Rectangle2D rect, float x, float y) { addDrawingRect((float) (rect.getX() + x), (float) (rect.getY() + y), (float) rect.getWidth(), (float) rect.getHeight()); } private void addDrawingRect(float x, float y, float width, float height) { Rectangle2D.Float bbox = new Rectangle2D.Float(x, y, width, height); addDrawingRect(bbox); } /** * Add the rectangle 'rect' to the area representing * the part of the page which is drawn into. */ private void addDrawingRect(Rectangle2D rect) { /* For testing purposes the following line can be uncommented. When uncommented it causes the entire page to be rasterized thus eliminating errors caused by a faulty bounding box calculation. */ //mDrawingArea.addInfinite(); AffineTransform matrix = getTransform(); Shape transShape = matrix.createTransformedShape(rect); Rectangle2D transRect = transShape.getBounds2D(); mDrawingArea.add((float) transRect.getMinY(), (float) transRect.getMaxY()); } /** * Add the stroked shape to the area representing * the part of the page which is drawn into. */ private void addStrokeShape(Shape s) { Shape transShape = getStroke().createStrokedShape(s); addDrawingRect(transShape.getBounds2D()); } /* Image Observer */ /** * Notify this object when the height or width become available * for an image. */ public synchronized boolean imageUpdate(Image img, int infoFlags, int x, int y, int width, int height) { boolean gotInfo = false; if((infoFlags & (WIDTH | HEIGHT)) != 0) { gotInfo = true; notify(); } return gotInfo; } private synchronized int getImageWidth(Image img) { /* Wait for the width the image to * become available. */ while (img.getWidth(this) == -1) { try { wait(); } catch (InterruptedException e) { } } return img.getWidth(this); } private synchronized int getImageHeight(Image img) { /* Wait for the height the image to * become available. */ while (img.getHeight(this) == -1) { try { wait(); } catch (InterruptedException e) { } } return img.getHeight(this); } /** * This private class does not return from its constructor * until 'img's width and height are available. */ protected class ImageWaiter implements ImageObserver { private int mWidth; private int mHeight; private boolean badImage = false; ImageWaiter(Image img) { waitForDimensions(img); } public int getWidth() { return mWidth; } public int getHeight() { return mHeight; } synchronized private void waitForDimensions(Image img) { mHeight = img.getHeight(this); mWidth = img.getWidth(this); while (!badImage && (mWidth < 0 || mHeight < 0)) { try { Thread.sleep(50); } catch(InterruptedException e) { // do nothing. } mHeight = img.getHeight(this); mWidth = img.getWidth(this); } if (badImage) { mHeight = 0; mWidth = 0; } } synchronized public boolean imageUpdate(Image image, int flags, int x, int y, int w, int h) { boolean dontCallMeAgain = (flags & (HEIGHT | ABORT | ERROR)) != 0; badImage = (flags & (ABORT | ERROR)) != 0; return dontCallMeAgain; } } }