Mercurial > dive4elements > river
changeset 1752:b7b424ae32a8
Added /dev/null Graphics2D object to be used in the info rendering pass of the diagram generation.
flys-artifacts/trunk@3055 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 21 Oct 2011 13:25:24 +0000 |
parents | 27b8836abec9 |
children | 741ba9e34c7d |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/java2d/NOPGraphics2D.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java |
diffstat | 4 files changed, 589 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Oct 21 08:21:45 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 21 13:25:24 2011 +0000 @@ -1,3 +1,21 @@ +2011-10-21 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + To obtain the size of a diagram it is rendered twice. The + second time the generated image is omitted so the concrete + rendered image is not needed. To save CPU cycles in this pass + the image is rendered to to /dev/null Graphics2D object. + + * src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java: + Added boolean system property "info.rendering.nop.graphics" (default: false). + With this property set the info rendering is done via a new + NOPGraphics2D opbject which does not render the image. + + * src/main/java/de/intevation/flys/java2d/NOPGraphics2D.java: + New. Implements java.awt.Graphics2D trivial empty methods. + This prevents rendering. + + * src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java: + Commented out spamy debug output 2011-10-21 Raimund Renkert <raimund.renkert@intevation.de> * src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java: @@ -15,7 +33,7 @@ 2011-10-20 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/services/CrossSectionKMService.java: - Service to lookup the Nth nearest neighbors for a set of given + New. Service to lookup the Nth nearest neighbors for a set of given cross section ids and kms. * doc/conf/conf.xml: Registered service.
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Fri Oct 21 08:21:45 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java Fri Oct 21 13:25:24 2011 +0000 @@ -1,9 +1,17 @@ package de.intevation.flys.exports; -import java.awt.Transparency; +import de.intevation.flys.java2d.NOPGraphics2D; + import java.io.IOException; import java.io.OutputStream; +import java.awt.Transparency; +import java.awt.Graphics2D; + +import java.awt.geom.Rectangle2D; + +import java.awt.image.BufferedImage; + import org.w3c.dom.Document; import org.apache.log4j.Logger; @@ -31,6 +39,9 @@ */ public abstract class ChartInfoGenerator implements OutGenerator { + public static final boolean USE_NOP_GRAPHICS = + Boolean.getBoolean("info.rendering.nop.graphics"); + /** The logger used in this generator.*/ private static Logger logger = Logger.getLogger(ChartInfoGenerator.class); @@ -106,7 +117,35 @@ ChartRenderingInfo info = new ChartRenderingInfo(); - chart.createBufferedImage(size[0], size[1], Transparency.BITMASK, info); + long startTime = System.currentTimeMillis(); + + if (USE_NOP_GRAPHICS) { + BufferedImage image = + new BufferedImage(size[0], size[1], Transparency.BITMASK); + + Graphics2D g2d = image.createGraphics(); + Graphics2D nop = new NOPGraphics2D(g2d); + + chart.draw( + nop, + new Rectangle2D.Double(0, 0, size[0], size[1]), + null, + info); + + nop.dispose(); + } + else { + chart.createBufferedImage( + size[0], size[1], Transparency.BITMASK, info); + } + + long stopTime = System.currentTimeMillis(); + + if (logger.isDebugEnabled()) { + logger.debug("Rendering info took: " + + (stopTime-startTime) + "ms"); + } + InfoGeneratorHelper helper = new InfoGeneratorHelper(generator); Document doc = helper.createInfoDocument(chart, info);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/java2d/NOPGraphics2D.java Fri Oct 21 13:25:24 2011 +0000 @@ -0,0 +1,528 @@ +package de.intevation.flys.java2d; + +import java.util.Map; + +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.Image; +import java.awt.Color; +import java.awt.Composite; +import java.awt.Paint; +import java.awt.GraphicsConfiguration; +import java.awt.Stroke; +import java.awt.Rectangle; +import java.awt.Font; +import java.awt.FontMetrics; + +import java.awt.image.RenderedImage; + +import java.awt.image.BufferedImage; +import java.awt.image.BufferedImageOp; +import java.awt.image.ImageObserver; + +import java.awt.image.renderable.RenderableImage; + +import java.awt.geom.AffineTransform; + +import java.text.AttributedCharacterIterator; + +import java.awt.font.GlyphVector; +import java.awt.font.FontRenderContext; + +import java.awt.RenderingHints; + +public final class NOPGraphics2D +extends Graphics2D +{ + private Graphics2D parent; + + public NOPGraphics2D(Graphics2D parent) { + this.parent = parent; + } + + @Override + public final void addRenderingHints(Map<?,?> hints) { + parent.addRenderingHints(hints); + } + + @Override + public final void clip(Shape s) { + } + + @Override + public final void draw(Shape s) { + } + + @Override + public final void drawGlyphVector(GlyphVector g, float x, float y) { + } + + @Override + public final void drawImage( + BufferedImage img, + BufferedImageOp op, + int x, + int y + ) { + } + + @Override + public final boolean drawImage( + Image img, + AffineTransform xform, + ImageObserver obs + ) { + return true; + } + + @Override + public final void drawRenderableImage( + RenderableImage img, + AffineTransform xform + ) { + } + + @Override + public final void drawRenderedImage( + RenderedImage img, + AffineTransform xform + ) { + } + + @Override + public final void drawString( + AttributedCharacterIterator iterator, + float x, + float y + ) { + } + + @Override + public final void drawString( + AttributedCharacterIterator iterator, + int x, + int y + ) { + } + + @Override + public final void drawString(String str, float x, float y) { + } + + @Override + public final void drawString(String str, int x, int y) { + } + + @Override + public final void fill(Shape s) { + } + + @Override + public final Color getBackground() { + return parent.getBackground(); + } + + @Override + public final Composite getComposite() { + return parent.getComposite(); + } + + @Override + public final GraphicsConfiguration getDeviceConfiguration() { + return parent.getDeviceConfiguration(); + } + + @Override + public final FontRenderContext getFontRenderContext() { + return parent.getFontRenderContext(); + } + + @Override + public final Paint getPaint() { + return parent.getPaint(); + } + + @Override + public final Object getRenderingHint(RenderingHints.Key hintKey) { + return parent.getRenderingHint(hintKey); + } + + @Override + public final RenderingHints getRenderingHints() { + return parent.getRenderingHints(); + } + + @Override + public final Stroke getStroke() { + return parent.getStroke(); + } + + @Override + public final AffineTransform getTransform() { + return parent.getTransform(); + } + + @Override + public final boolean hit(Rectangle rect, Shape s, boolean onStroke) { + return parent.hit(rect, s, onStroke); + } + + @Override + public final void rotate(double theta) { + parent.rotate(theta); + } + + @Override + public final void rotate(double theta, double x, double y) { + parent.rotate(theta); + } + + @Override + public final void scale(double sx, double sy) { + parent.scale(sx, sy); + } + + @Override + public final void setBackground(Color color) { + parent.setBackground(color); + } + + @Override + public final void setComposite(Composite comp) { + parent.setComposite(comp); + } + + @Override + public final void setPaint(Paint paint) { + parent.setPaint(paint); + } + + @Override + public final void setRenderingHint( + RenderingHints.Key hintKey, + Object hintValue + ) { + parent.setRenderingHint(hintKey, hintValue); + } + + @Override + public final void setRenderingHints(Map<?,?> hints) { + parent.setRenderingHints(hints); + } + + @Override + public final void setStroke(Stroke s) { + parent.setStroke(s); + } + + @Override + public final void setTransform(AffineTransform Tx) { + parent.setTransform(Tx); + } + + + @Override + public final void shear(double shx, double shy) { + parent.shear(shx, shy); + } + + @Override + public final void transform(AffineTransform Tx) { + parent.transform(Tx); + } + + @Override + public final void translate(double tx, double ty) { + parent.translate(tx, ty); + } + + @Override + public final void translate(int tx, int ty) { + parent.translate(tx, ty); + } + + @Override + public final void dispose() { + parent.dispose(); + } + + @Override + public final boolean drawImage( + Image img, + int x, + int y, + int width, + int height, + Color bgcolor, + ImageObserver observer + ) { + return true; + } + + @Override + public final boolean drawImage( + Image img, + int dx1, + int dy1, + int dx2, + int dy2, + int sx1, + int sy1, + int sx2, + int sy2, + Color bgcolor, + ImageObserver observer + ) { + return true; + } + + @Override + public final boolean drawImage( + Image img, + int dx1, + int dy1, + int dx2, + int dy2, + int sx1, + int sy1, + int sx2, + int sy2, + ImageObserver observer + ) { + return true; + } + + @Override + public final boolean drawImage( + Image img, + int x, + int y, + Color bgcolor, + ImageObserver observer + ) { + return true; + } + + @Override + public final boolean drawImage( + Image img, + int x, + int y, + int width, + int height, + ImageObserver observer + ) { + return true; + } + + @Override + public final boolean drawImage( + Image img, + int x, + int y, + ImageObserver observer + ) { + return true; + } + + @Override + public final void fillPolygon( + int [] xPoints, + int [] yPoints, + int nPoints + ) { + } + + @Override + public final void drawPolygon( + int [] xPoints, + int [] yPoints, + int nPoints + ) { + } + + @Override + public final void drawPolyline( + int [] xPoints, + int [] yPoints, + int nPoints + ) { + } + + @Override + public final void fillArc( + int x, + int y, + int width, + int height, + int startAngle, + int arcAngle + ) { + } + + @Override + public final void drawArc( + int x, + int y, + int width, + int height, + int startAngle, + int arcAngle + ) { + } + + @Override + public final void fillOval( + int x, + int y, + int width, + int height + ) { + } + + @Override + public final void drawOval( + int x, + int y, + int width, + int height + ) { + } + + @Override + public final void fillRoundRect( + int x, + int y, + int width, + int height, + int arcWidth, + int arcHeight + ) { + } + + @Override + public final void drawRoundRect( + int x, + int y, + int width, + int height, + int arcWidth, + int arcHeight + ) { + } + + @Override + public final void clearRect( + int x, + int y, + int width, + int height + ) { + } + + @Override + public final void fillRect( + int x, + int y, + int width, + int height + ) { + } + + @Override + public final void drawLine( + int x1, + int y1, + int x2, + int y2 + ) { + } + + @Override + public final void copyArea( + int x, + int y, + int width, + int height, + int dx, + int dy + ) { + } + + @Override + public final void setClip( + int x, + int y, + int width, + int height + ) { + parent.setClip(x, y, width, height); + } + + @Override + public final void setClip(Shape shape) { + parent.setClip(shape); + } + + @Override + public final Shape getClip() { + return parent.getClip(); + } + + @Override + public final void clipRect( + int x, + int y, + int width, + int height + ) { + parent.clipRect(x, y, width, height); + } + + @Override + public final Rectangle getClipBounds() { + return parent.getClipBounds(); + } + + @Override + public final FontMetrics getFontMetrics(Font f) { + return parent.getFontMetrics(f); + } + + @Override + public final void setFont(Font font) { + parent.setFont(font); + } + + @Override + public final Font getFont() { + return parent.getFont(); + } + + @Override + public final void setXORMode(Color c1) { + parent.setXORMode(c1); + } + + @Override + public final void setPaintMode() { + parent.setPaintMode(); + } + + @Override + public final void setColor(Color c) { + parent.setColor(c); + } + + @Override + public final Color getColor() { + return parent.getColor(); + } + + @Override + public final Graphics create() { + return new NOPGraphics2D((Graphics2D)parent.create()); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri Oct 21 08:21:45 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri Oct 21 13:25:24 2011 +0000 @@ -127,7 +127,7 @@ if(textOrientation.equals("horizontal")) { o = 0f; } - logger.debug("orientation: " + o); + //logger.debug("orientation: " + o); this.setRotationAngle(o * (Math.PI / 180f)); this.setRotationAnchor(TextAnchor.CENTER_LEFT); this.setTextAnchor(TextAnchor.CENTER_LEFT);