diff options
| author | Mario Torre <neugens@limasoftware.net> | 2008-05-29 16:41:39 +0000 |
|---|---|---|
| committer | Mario Torre <neugens@limasoftware.net> | 2008-05-29 16:41:39 +0000 |
| commit | c191297d1febe4e68c77215726c451c095d9c954 (patch) | |
| tree | e8c9585dd1ab0ad6353c50e9d4a7f08f7075fa5b /gnu/java/awt/java2d/AbstractGraphics2D.java | |
| parent | 1a8cbdd821fd0bcd92cd104abc091ababd777973 (diff) | |
| download | classpath-c191297d1febe4e68c77215726c451c095d9c954.tar.gz | |
2008-05-29 Mario Torre <neugens@aicas.com>
* gnu/java/awt/java2d/AbstractGraphics2D.java (setColor): now set directly
the foreground color the application wants to use to draw. On null, behave
like OpenJDK, drawing black.
(renderScanline): fixed NPE, paintContext never initialized. Correctely
retrieve destination raster
(getColor): Return the correct type.
(static initializer): HashMap now typed.
(background): now defaults to black and not null.
(getPaintContext): new method. Initialize lazily the PaintContext.
(foreground): new field.
(isForegroundColorNull): likewise.
(getDeviceBounds): made abstract.
* gnu/java/awt/java2d/RasterGraphics.java (getDeviceBounds): new method.
* gnu/java/awt/java2d/ScanlineConverter.java (renderShape): pass correct
value of Y to doScanline.
* gnu/java/awt/peer/x/GLGraphics.java (getDeviceBounds): new method.
(setBackground): synch with new Escher 2.0 API.
* gnu/java/awt/peer/x/XGraphicsConfiguration.java (getDefaultTransform):
implemented.
(getBounds): new method.
* java/awt/AlphaComposite.java (derive(int) and derive(float)):
new methods.
* java/awt/image/WritableRaster.java (createWritableTranslatedChild):
now call createWritableChild.
(createWritableChild): reformatted.
Diffstat (limited to 'gnu/java/awt/java2d/AbstractGraphics2D.java')
| -rw-r--r-- | gnu/java/awt/java2d/AbstractGraphics2D.java | 88 |
1 files changed, 65 insertions, 23 deletions
diff --git a/gnu/java/awt/java2d/AbstractGraphics2D.java b/gnu/java/awt/java2d/AbstractGraphics2D.java index 36ba0f430..a65fde9b2 100644 --- a/gnu/java/awt/java2d/AbstractGraphics2D.java +++ b/gnu/java/awt/java2d/AbstractGraphics2D.java @@ -37,6 +37,7 @@ exception statement from your version. */ package gnu.java.awt.java2d; +import gnu.java.awt.peer.x.XDialogPeer; import gnu.java.util.LRUCache; import java.awt.AWTError; @@ -210,14 +211,20 @@ public abstract class AbstractGraphics2D /** * The paint context during rendering. */ - private PaintContext paintContext; + private PaintContext paintContext = null; /** * The background. */ - private Color background; + private Color background = Color.WHITE; /** + * Foreground color, as set by setColor. + */ + private Color foreground = Color.BLACK; + private boolean isForegroundColorNull = true; + + /** * The current font. */ private Font font; @@ -266,15 +273,19 @@ public abstract class AbstractGraphics2D private static final BasicStroke STANDARD_STROKE = new BasicStroke(); - private static final HashMap STANDARD_HINTS; - static { - HashMap hints = new HashMap(); - hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); - hints.put(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_DEFAULT); - STANDARD_HINTS = hints; - } + private static final HashMap<Key, Object> STANDARD_HINTS; + static + { + + HashMap<Key, Object> hints = new HashMap<Key, Object>(); + hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); + hints.put(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_DEFAULT); + + STANDARD_HINTS = hints; + } + /** * Creates a new AbstractGraphics2D instance. */ @@ -1058,10 +1069,10 @@ public abstract class AbstractGraphics2D */ public Color getColor() { - Color c = null; - if (paint instanceof Color) - c = (Color) paint; - return c; + if (isForegroundColorNull) + return null; + + return this.foreground; } /** @@ -1071,7 +1082,22 @@ public abstract class AbstractGraphics2D */ public void setColor(Color color) { - setPaint(color); + if (color == null) + { + this.foreground = Color.BLACK; + isForegroundColorNull = true; + } + else + { + this.foreground = color; + isForegroundColorNull = false; + } + + // free resources if needed, then put the paint context to null + if (this.paintContext != null) + this.paintContext.dispose(); + + this.paintContext = null; } public void setPaintMode() @@ -1639,10 +1665,7 @@ public abstract class AbstractGraphics2D * * @return the bounds of the target */ - protected Rectangle getDeviceBounds() - { - return destinationRaster.getBounds(); - } + protected abstract Rectangle getDeviceBounds(); /** * Draws a line in optimization mode. The implementation should respect the @@ -1763,7 +1786,8 @@ public abstract class AbstractGraphics2D */ public void renderScanline(int y, ScanlineCoverage c) { - PaintContext pCtx = paintContext; + PaintContext pCtx = getPaintContext(); + int x0 = c.getMinX(); int x1 = c.getMaxX(); Raster paintRaster = pCtx.getRaster(x0, y, x1 - x0, 1); @@ -1797,9 +1821,11 @@ public abstract class AbstractGraphics2D CompositeContext cCtx = composite.createContext(paintColorModel, getColorModel(), renderingHints); - WritableRaster targetChild = destinationRaster.createWritableTranslatedChild(-x0,- y); + WritableRaster raster = getDestinationRaster(); + WritableRaster targetChild = raster.createWritableTranslatedChild(-x0, -y); + cCtx.compose(paintRaster, targetChild, targetChild); - updateRaster(destinationRaster, x0, y, x1 - x0, 1); + updateRaster(raster, x0, y, x1 - x0, 1); cCtx.dispose(); } @@ -1986,4 +2012,20 @@ public abstract class AbstractGraphics2D } } + private PaintContext getPaintContext() + { + if (this.paintContext == null) + { + return this.foreground.createContext(getColorModel(), + getDeviceBounds(), + getClipBounds(), + getTransform(), + getRenderingHints()); + } + else + { + return this.paintContext; + } + } + } |
