/hg/gfx-test: * src/org/gfxtest/testsuites/PrintTestLines.java:

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Mon May 21 02:24:03 PDT 2012


changeset 4b394a083c4d in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=4b394a083c4d
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon May 21 11:26:43 2012 +0200

	* src/org/gfxtest/testsuites/PrintTestLines.java:
	Another refactoring - now for vertical line rendering tests.


diffstat:

 ChangeLog                                      |    5 +
 src/org/gfxtest/testsuites/PrintTestLines.java |  318 +++++++++++++-----------
 2 files changed, 182 insertions(+), 141 deletions(-)

diffs (truncated from 502 to 500 lines):

diff -r 4e7e5cbdb27a -r 4b394a083c4d ChangeLog
--- a/ChangeLog	Fri May 18 14:33:30 2012 +0200
+++ b/ChangeLog	Mon May 21 11:26:43 2012 +0200
@@ -1,3 +1,8 @@
+2012-05-21  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/gfxtest/testsuites/PrintTestLines.java:
+	Another refactoring - now for vertical line rendering tests.
+
 2012-05-18  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/gfxtest/framework/PrintTest.java:
diff -r 4e7e5cbdb27a -r 4b394a083c4d src/org/gfxtest/testsuites/PrintTestLines.java
--- a/src/org/gfxtest/testsuites/PrintTestLines.java	Fri May 18 14:33:30 2012 +0200
+++ b/src/org/gfxtest/testsuites/PrintTestLines.java	Mon May 21 11:26:43 2012 +0200
@@ -85,7 +85,7 @@
      *            image to which lines are to be drawn
      * @param graphics2d
      *            graphics canvas
-     * @param offset
+     * @param verticalStep
      *            between two near lines
      * @param horizontalLineDrawCallbacks
      *            class containing set of callback methods
@@ -127,11 +127,37 @@
      *            image to which lines are to be drawn
      * @param graphics2d
      *            graphics canvas
+     * @param horizontalStep
+     *            between two near lines
      * @param verticalLineDrawCallbacks
      *            class containing set of callback methods
      */
-    private void drawVerticalLines(TestImage image, Graphics2D graphics, VerticalLineDrawCallbacks verticalLineDrawCallbacks)
+    private void drawVerticalLines(TestImage image, Graphics2D graphics, int horizontalStep, VerticalLineDrawCallbacks verticalLineDrawCallbacks)
     {
+        // setup rendering
+        verticalLineDrawCallbacks.setup(image, graphics);
+
+        // image width and height
+        final int width = image.getWidth();
+        final int height = image.getHeight();
+
+        // horizontal coordinates of line endpoints
+        final int y1 = BORDER;
+        final int y2 = height - BORDER;
+
+        // index to color palette
+        int colorIndex = 0;
+
+        // draw all lines onto a paper
+        for (int x = 0; x < width; x += horizontalStep)
+        {
+            // setup can be made for each line
+            verticalLineDrawCallbacks.iterationCallBack(x, colorIndex++);
+            // render the line
+            graphics.drawLine(x, y1, x, y2);
+        }
+        // cleanup rendering
+        verticalLineDrawCallbacks.cleanup();
     }
 
     /**
@@ -143,10 +169,12 @@
      *            image to which lines are to be drawn
      * @param graphics2d
      *            graphics canvas
+     * @param diagonalStep
+     *            between two near lines
      * @param diagonalLineDrawCallbacks
      *            class containing set of callback methods
      */
-    private void drawDiagonalLines(TestImage image, Graphics2D graphics, DiagonalLineDrawCallbacks diagonalLineDrawCallbacks)
+    private void drawDiagonalLines(TestImage image, Graphics2D graphics, int diagonalStep, DiagonalLineDrawCallbacks diagonalLineDrawCallbacks)
     {
         // setup rendering
         diagonalLineDrawCallbacks.setup(image, graphics);
@@ -164,11 +192,13 @@
         int x2 = BORDER;
         int y2 = BORDER;
 
-        int index = 0;
+        // index to color palette
+        int colorIndex = 0;
 
         // draw all lines onto a paper
         for (int d = 0; d < length; d += DIAGONAL_STEP)
         {
+            // first endpoint
             if (x1 < width - BORDER)
             {
                 x1 += DIAGONAL_STEP;
@@ -177,6 +207,7 @@
             {
                 y1 += DIAGONAL_STEP;
             }
+            // second endpoint
             if (y2 < height - BORDER)
             {
                 y2 += DIAGONAL_STEP;
@@ -186,7 +217,7 @@
                 x2 += DIAGONAL_STEP;
             }
             // setup can be made for each line
-            diagonalLineDrawCallbacks.iterationCallBack(length, index++);
+            diagonalLineDrawCallbacks.iterationCallBack(length, colorIndex++);
             // render the line
             graphics.drawLine(x1, y1, x2, y2);
         }
@@ -209,6 +240,9 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP, new HorizontalLineDrawCallbacks()
         {
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
@@ -235,6 +269,9 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP, new HorizontalLineDrawCallbacks()
         {
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
@@ -263,9 +300,13 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP, new HorizontalLineDrawCallbacks()
         {
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
+                // compute grayscale value
                 float gray = y * 1.0f / this.image.getHeight();
                 // set line color
                 this.graphics.setColor(GrayscalePalette.createGrayscaleColor(gray));
@@ -291,9 +332,14 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP << 1, new HorizontalLineDrawCallbacks()
         {
-            // stroke width
+            /**
+             * Stroke width.
+             */
             float strokeWidth = 0.0f;
 
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
@@ -324,9 +370,14 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP << 1, new HorizontalLineDrawCallbacks()
         {
-            // stroke width
+            /**
+             * Stroke width.
+             */
             float strokeWidth = 0.0f;
 
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
@@ -356,9 +407,14 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP << 1, new HorizontalLineDrawCallbacks()
         {
-            // stroke width
+            /**
+             * Stroke width.
+             */
             float strokeWidth = 0.0f;
 
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
@@ -388,9 +444,14 @@
     {
         drawHorizontalLines(image, graphics, VERTICAL_STEP << 1, new HorizontalLineDrawCallbacks()
         {
-            // stroke width
+            /**
+             * Stroke width.
+             */
             float strokeWidth = 0.0f;
 
+            /**
+             * Callback function called before each line is rendered.
+             */
             @Override
             public void iterationCallBack(int y, int index)
             {
@@ -418,23 +479,17 @@
      */
     public TestResult testDrawVerticalLinesBasicStyle(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
-
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP)
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP, new VerticalLineDrawCallbacks()
         {
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                return;
+            }
+        });
 
         // test return value
         return TestResult.PASSED;
@@ -453,28 +508,19 @@
      */
     public TestResult testDrawVerticalLinesColorPalette(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
-
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-
-        // index to color palette
-        int colorIndex = 0;
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP)
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP, new VerticalLineDrawCallbacks()
         {
-            // set line color
-            graphics.setColor(ColorPalette.getColor(colorIndex++));
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                // set line color
+                this.graphics.setColor(ColorPalette.getColor(index));
+                return;
+            }
+        });
 
         // test return value
         return TestResult.PASSED;
@@ -493,26 +539,20 @@
      */
     public TestResult testDrawVerticalLinesGrayScale(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
-
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP)
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP, new VerticalLineDrawCallbacks()
         {
-            float gray = x * 1.0f / width;
-            // set line color
-            graphics.setColor(GrayscalePalette.createGrayscaleColor(gray));
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                // compute grayscale value
+                float gray = x * 1.0f / this.image.getWidth();
+                // set line color
+                this.graphics.setColor(GrayscalePalette.createGrayscaleColor(gray));
+            }
+        });
 
         // test return value
         return TestResult.PASSED;
@@ -531,26 +571,25 @@
      */
     public TestResult testDrawVerticalLinesChangeWidth(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP << 1, new VerticalLineDrawCallbacks()
+        {
+            /**
+             * Stroke width.
+             */
+            float strokeWidth = 0.0f;
 
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-        float strokeWidth = 0.0f; 
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP * 2)
-        {
-            graphics.setStroke(new BasicStroke(strokeWidth));
-            strokeWidth = strokeWidth < MAX_STROKE_WIDTH ? strokeWidth + 0.5f : strokeWidth;
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                // set stroke width
+                this.graphics.setStroke(new BasicStroke(this.strokeWidth));
+                // set new stroke width
+                this.strokeWidth = this.strokeWidth < MAX_STROKE_WIDTH ? this.strokeWidth + STROKE_WIDTH_DELTA : this.strokeWidth;
+            }
+        });
 
         // test return value
         return TestResult.PASSED;
@@ -569,26 +608,25 @@
      */
     public TestResult testDrawVerticalLinesChangeWidthCapButt(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP << 1, new VerticalLineDrawCallbacks()
+        {
+            /**
+             * Stroke width.
+             */
+            float strokeWidth = 0.0f;
 
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-        float strokeWidth = 0.0f; 
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP * 2)
-        {
-            graphics.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
-            strokeWidth = strokeWidth < MAX_STROKE_WIDTH ? strokeWidth + 0.5f : strokeWidth;
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                // set stroke width
+                this.graphics.setStroke(new BasicStroke(this.strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+                // set new stroke width
+                this.strokeWidth = this.strokeWidth < MAX_STROKE_WIDTH ? this.strokeWidth + STROKE_WIDTH_DELTA : this.strokeWidth;
+            }
+        });
 
         // test return value
         return TestResult.PASSED;
@@ -607,26 +645,25 @@
      */
     public TestResult testDrawVerticalLinesChangeWidthCapRound(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP << 1, new VerticalLineDrawCallbacks()
+        {
+            /**
+             * Stroke width.
+             */
+            float strokeWidth = 0.0f;
 
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-        float strokeWidth = 0.0f; 
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP * 2)
-        {
-            graphics.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
-            strokeWidth = strokeWidth < MAX_STROKE_WIDTH ? strokeWidth + 0.5f : strokeWidth;
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                // set stroke width
+                this.graphics.setStroke(new BasicStroke(this.strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
+                // set new stroke width
+                this.strokeWidth = this.strokeWidth < MAX_STROKE_WIDTH ? this.strokeWidth + STROKE_WIDTH_DELTA : this.strokeWidth;
+            }
+        });
 
         // test return value
         return TestResult.PASSED;
@@ -645,26 +682,25 @@
      */
     public TestResult testDrawVerticalLinesChangeWidthCapSquare(TestImage image, Graphics2D graphics)
     {
-        // set drawing color
-        graphics.setColor(Color.BLACK);
+        drawVerticalLines(image, graphics, HORIZONTAL_STEP << 1, new VerticalLineDrawCallbacks()
+        {
+            /**
+             * Stroke width.
+             */
+            float strokeWidth = 0.0f;
 
-        // image width and height
-        final int width = image.getWidth();
-        final int height = image.getHeight();
-
-        // horizontal coordinates of line endpoints
-        final int y1 = BORDER;
-        final int y2 = height - BORDER;
-        float strokeWidth = 0.0f; 
-
-        // draw all lines onto a paper
-        for (int x = 0; x < width; x += HORIZONTAL_STEP * 2)
-        {
-            graphics.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL));
-            strokeWidth = strokeWidth < MAX_STROKE_WIDTH ? strokeWidth + 0.5f : strokeWidth;
-            // render the line
-            graphics.drawLine(x, y1, x, y2);
-        }
+            /**
+             * Callback function called before each line is rendered.
+             */
+            @Override
+            public void iterationCallBack(int x, int index)
+            {
+                // set stroke width
+                this.graphics.setStroke(new BasicStroke(this.strokeWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL));
+                // set new stroke width
+                this.strokeWidth = this.strokeWidth < MAX_STROKE_WIDTH ? this.strokeWidth + STROKE_WIDTH_DELTA : this.strokeWidth;
+            }
+        });
 



More information about the distro-pkg-dev mailing list