/hg/gfx-test: * src/org/gfxtest/testsuites/PrintTestCircles.java:
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Tue May 22 03:01:08 PDT 2012
changeset 9d3dfd9343a9 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=9d3dfd9343a9
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Tue May 22 12:03:36 2012 +0200
* src/org/gfxtest/testsuites/PrintTestCircles.java:
Refactored - print test now use anonymous class which implements
set of callback functions to make this test suite simpler.
diffstat:
ChangeLog | 6 +
src/org/gfxtest/testsuites/PrintTestCircles.java | 335 +++++++++++++---------
2 files changed, 208 insertions(+), 133 deletions(-)
diffs (412 lines):
diff -r 4b394a083c4d -r 9d3dfd9343a9 ChangeLog
--- a/ChangeLog Mon May 21 11:26:43 2012 +0200
+++ b/ChangeLog Tue May 22 12:03:36 2012 +0200
@@ -1,3 +1,9 @@
+2012-05-22 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/gfxtest/testsuites/PrintTestCircles.java:
+ Refactored - print test now use anonymous class which implements
+ set of callback functions to make this test suite simpler.
+
2012-05-21 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/testsuites/PrintTestLines.java:
diff -r 4b394a083c4d -r 9d3dfd9343a9 src/org/gfxtest/testsuites/PrintTestCircles.java
--- a/src/org/gfxtest/testsuites/PrintTestCircles.java Mon May 21 11:26:43 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestCircles.java Tue May 22 12:03:36 2012 +0200
@@ -77,6 +77,52 @@
{
/**
+ * Method which renders set of circles using various colors and
+ * stroke styles. For each circle, the callback function/method is called to
+ * perform all required setup.
+ *
+ * @param image
+ * image to which circles are to be drawn
+ * @param graphics2d
+ * graphics canvas
+ * @param radiusStep
+ * between two near circles
+ * @param circleDrawCallback
+ * class containing set of callback methods
+ */
+ private void drawCircle(TestImage image, Graphics2D graphics2d, int radiusStep, CommonCircleDrawCallbacks circleDrawCallback)
+ {
+ // setup rendering
+ circleDrawCallback.setup(image, graphics2d);
+
+ // image width and height
+ final int width = image.getWidth();
+ final int height = image.getHeight();
+
+ // horizontal coordinates of circle center
+ final int xc = width >> 1;
+ final int yc = height >> 1;
+
+ // maximum radius
+ final int maxRadius = Math.min(width, height) - BORDER;
+
+ // index to color palette
+ int colorIndex = 0;
+
+ // draw all circles onto a paper
+ for (int radius = MINIMUM_RADIUS; radius < maxRadius; radius += radiusStep)
+ {
+ // setup can be made for each circle
+ circleDrawCallback.iterationCallBack(xc, yc, radius, maxRadius, colorIndex++);
+ // render the circle
+ graphics2d.drawOval(xc - radius, yc - radius, radius << 1, radius << 1);
+ }
+
+ // cleanup rendering
+ circleDrawCallback.cleanup();
+ }
+
+ /**
* Test basic behavior of method Graphics.drawOval().
* Color of all rendered circles are set to black.
*
@@ -88,26 +134,18 @@
*/
public TestResult testDrawCircleBasicStyle(TestImage image, Graphics2D graphics2d)
{
- // set drawing color
- graphics2d.setColor(Color.BLACK);
-
- // image width and height
- final int width = image.getWidth();
- final int height = image.getHeight();
-
- // horizontal coordinates of line endpoints
- final int xc = width >> 1;
- final int yc = height >> 1;
-
- // max. radius
- final int maxRadius = Math.min(width, height) - BORDER;
-
- // draw all circles onto a paper
- for (int r = 10; r < maxRadius; r += CIRCLE_RADIUS_STEP)
+ drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP, new CommonCircleDrawCallbacks()
{
- // render the circle
- graphics2d.drawOval(xc - r, yc - r, r << 1, r << 1);
- }
+ /**
+ * Callback function called before each circle is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+ {
+ // nothing need to be changed
+ return;
+ }
+ });
// test return value
return TestResult.PASSED;
@@ -125,31 +163,19 @@
*/
public TestResult testDrawCircleColorPalette(TestImage image, Graphics2D graphics2d)
{
- // set drawing color
- graphics2d.setColor(Color.BLACK);
-
- // image width and height
- final int width = image.getWidth();
- final int height = image.getHeight();
-
- // horizontal coordinates of line endpoints
- final int xc = width >> 1;
- final int yc = height >> 1;
-
- // max. radius
- final int maxRadius = Math.min(width, height) - BORDER;
-
- // index to color palette
- int colorIndex = 0;
-
- // draw all circles onto a paper
- for (int r = 10; r < maxRadius; r += CIRCLE_RADIUS_STEP)
+ drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP, new CommonCircleDrawCallbacks()
{
- // set circle color
- graphics2d.setColor(ColorPalette.getColor(colorIndex++));
- // render the circle
- graphics2d.drawOval(xc - r, yc - r, r << 1, r << 1);
- }
+ /**
+ * Callback function called before each circle is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+ {
+ // set circle color
+ this.graphics.setColor(ColorPalette.getColor(index));
+ return;
+ }
+ });
// test return value
return TestResult.PASSED;
@@ -167,29 +193,21 @@
*/
public TestResult testDrawCircleGrayScale(TestImage image, Graphics2D graphics2d)
{
- // set drawing color
- graphics2d.setColor(Color.BLACK);
-
- // image width and height
- final int width = image.getWidth();
- final int height = image.getHeight();
-
- // horizontal coordinates of line endpoints
- final int xc = width >> 1;
- final int yc = height >> 1;
-
- // max. radius
- final int maxRadius = Math.min(width, height) - BORDER;
-
- // draw all circles onto a paper
- for (int r = 10; r < maxRadius; r += CIRCLE_RADIUS_STEP)
+ drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP, new CommonCircleDrawCallbacks()
{
- float gray = r * 1.0f / maxRadius;
- // set circle color
- graphics2d.setColor(GrayscalePalette.createGrayscaleColor(gray));
- // render the circle
- graphics2d.drawOval(xc - r, yc - r, r << 1, r << 1);
- }
+ /**
+ * Callback function called before each circle is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+ {
+ // compute grayscale value
+ float gray = radius * 1.0f / maxRadius;
+ // set circle color
+ this.graphics.setColor(GrayscalePalette.createGrayscaleColor(gray));
+ return;
+ }
+ });
// test return value
return TestResult.PASSED;
@@ -207,29 +225,21 @@
*/
public TestResult testDrawCircleGrayScaleInv(TestImage image, Graphics2D graphics2d)
{
- // set drawing color
- graphics2d.setColor(Color.BLACK);
-
- // image width and height
- final int width = image.getWidth();
- final int height = image.getHeight();
-
- // horizontal coordinates of line endpoints
- final int xc = width >> 1;
- final int yc = height >> 1;
-
- // max. radius
- final int maxRadius = Math.min(width, height) - BORDER;
-
- // draw all circles onto a paper
- for (int r = 10; r < maxRadius; r += CIRCLE_RADIUS_STEP)
+ drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP, new CommonCircleDrawCallbacks()
{
- float gray = 1.0f - r * 1.0f / maxRadius;
- // set circle color
- graphics2d.setColor(GrayscalePalette.createGrayscaleColor(gray));
- // render the circle
- graphics2d.drawOval(xc - r, yc - r, r << 1, r << 1);
- }
+ /**
+ * Callback function called before each circle is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+ {
+ // compute grayscale value
+ float gray = 1.0f - radius * 1.0f / maxRadius;
+ // set circle color
+ this.graphics.setColor(GrayscalePalette.createGrayscaleColor(gray));
+ return;
+ }
+ });
// test return value
return TestResult.PASSED;
@@ -248,31 +258,29 @@
*/
public TestResult testDrawCircleChangeWidth(TestImage image, Graphics2D graphics2d)
{
- // set drawing color
- graphics2d.setColor(Color.BLACK);
+ drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP << 1, new CommonCircleDrawCallbacks()
+ {
+ private float strokeWidth = 0.0f;
- // image width and height
- final int width = image.getWidth();
- final int height = image.getHeight();
+ /**
+ * Callback function called before each circle is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+ {
+ this.graphics.setStroke(new BasicStroke(this.strokeWidth));
+ changeStrokeWidth();
+ return;
+ }
- // horizontal coordinates of line endpoints
- final int xc = width >> 1;
- final int yc = height >> 1;
-
- // stroke width
- float strokeWidth = 0.0f;
-
- // max. radius
- final int maxRadius = Math.min(width, height) - BORDER;
-
- // draw all circles onto a paper
- for (int r = 10; r < maxRadius; r += CIRCLE_RADIUS_STEP * 2)
- {
- graphics2d.setStroke(new BasicStroke(strokeWidth));
- strokeWidth = strokeWidth < MAX_STROKE_WIDTH ? strokeWidth + 0.5f : strokeWidth;
- // render the circle
- graphics2d.drawOval(xc - r, yc - r, r << 1, r << 1);
- }
+ /**
+ * Changes stroke width.
+ */
+ private void changeStrokeWidth()
+ {
+ this.strokeWidth = this.strokeWidth < MAX_STROKE_WIDTH ? this.strokeWidth + 0.5f : this.strokeWidth;
+ }
+ });
// test return value
return TestResult.PASSED;
@@ -291,31 +299,34 @@
*/
public TestResult testDrawCircleChangeWidthInv(TestImage image, Graphics2D graphics2d)
{
- // set drawing color
- graphics2d.setColor(Color.BLACK);
+ drawCircle(image, graphics2d, CIRCLE_RADIUS_STEP << 1, new CommonCircleDrawCallbacks()
+ {
+ private float strokeWidth = MAX_STROKE_WIDTH - 2;
- // image width and height
- final int width = image.getWidth();
- final int height = image.getHeight();
+ /**
+ * Callback function called before each circle is rendered.
+ */
+ @Override
+ public void iterationCallBack(int x, int y, int radius, int maxRadius, int index)
+ {
+ this.graphics.setStroke(new BasicStroke(this.strokeWidth));
+ changeStrokeWidth();
+ return;
+ }
- // horizontal coordinates of line endpoints
- final int xc = width >> 1;
- final int yc = height >> 1;
-
- // stroke width
- float strokeWidth = 0.0f;
-
- // max. radius
- final int maxRadius = Math.min(width, height) - BORDER;
-
- // draw all circles onto a paper
- for (int r = maxRadius; r > 10; r -= CIRCLE_RADIUS_STEP * 2)
- {
- graphics2d.setStroke(new BasicStroke(strokeWidth));
- strokeWidth = strokeWidth < MAX_STROKE_WIDTH ? strokeWidth + 0.5f : strokeWidth;
- // render the circle
- graphics2d.drawOval(xc - r, yc - r, r << 1, r << 1);
- }
+ /**
+ * Changes stroke width.
+ */
+ private void changeStrokeWidth()
+ {
+ this.strokeWidth -= 0.5f;
+ // stroke width should not be less than zero
+ if (this.strokeWidth < 0.0f)
+ {
+ this.strokeWidth = 0.0f;
+ }
+ }
+ });
// test return value
return TestResult.PASSED;
@@ -332,3 +343,61 @@
new PrintTestCircles().runTestSuite(args);
}
}
+
+/**
+ * Class representing set of callback methods called for each rendered circle.
+ *
+ * @author Pavel Tisnovsky
+ */
+abstract class CommonCircleDrawCallbacks
+{
+ /**
+ * Image to which circles are to be drawn.
+ */
+ protected TestImage image;
+
+ /**
+ * Graphics canvas.
+ */
+ protected Graphics2D graphics;
+
+ /**
+ * Setup phase.
+ *
+ * @param image
+ * image to which circles are to be drawn
+ * @param graphics2d
+ * graphics canvas
+ */
+ public void setup(TestImage image, Graphics2D graphics)
+ {
+ this.image = image;
+ this.graphics = graphics;
+ // set drawing color
+ graphics.setColor(Color.BLACK);
+ }
+
+ /**
+ * This method is called for each rendered horizontal circle.
+ *
+ * @param x
+ * horizontal coordinate of a circle center
+ * @param y
+ * vertical coordinate of a circle center
+ * @param radius
+ * circle radius
+ * @param maxRadius
+ * maximum allowable circle radius
+ * @param colorIndex
+ * color index
+ */
+ public abstract void iterationCallBack(int x, int y, int radius, int maxRadius, int colorIndex);
+
+ /**
+ * Cleanup phase.
+ */
+ public void cleanup()
+ {
+ return;
+ }
+}
More information about the distro-pkg-dev
mailing list