jdk/test/java/awt/Paint/PgramUserBoundsTest.java
author mfang
Wed, 17 Aug 2011 14:18:26 -0700
changeset 10294 8fcdae2a7ec7
parent 9653 6a1eff16874d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     1
/*
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     4
 *
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     8
 *
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    13
 * accompanied this code).
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    14
 *
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    18
 *
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    21
 * questions.
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    22
 */
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    23
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    24
/**
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    25
 * @test
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    26
 * @bug 7043054
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    27
 * @summary Verifies that Paint objects receive the appropriate user space
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    28
 *          bounds in their createContext() method
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    29
 * @run main PgramUserBoundsTest
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    30
 */
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    31
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    32
import java.awt.Color;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    33
import java.awt.Graphics2D;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    34
import java.awt.Paint;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    35
import java.awt.PaintContext;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    36
import java.awt.RenderingHints;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    37
import java.awt.Rectangle;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    38
import java.awt.geom.AffineTransform;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    39
import java.awt.geom.Line2D;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    40
import java.awt.geom.Rectangle2D;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    41
import java.awt.image.BufferedImage;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    42
import java.awt.image.ColorModel;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    43
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    44
public class PgramUserBoundsTest {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    45
    static final int MinX = 10;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    46
    static final int MinY = 20;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    47
    static final int MaxX = 30;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    48
    static final int MaxY = 50;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    49
    static AffineTransform identity = new AffineTransform();
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    50
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    51
    public static void main(String argv[]) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    52
        BufferedImage bimg =
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    53
            new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    54
        Graphics2D g2d = bimg.createGraphics();
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    55
        g2d.setPaint(new BoundsCheckerPaint(MinX, MinY, MaxX, MaxY));
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    56
        testAll(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    57
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    58
                             RenderingHints.VALUE_ANTIALIAS_ON);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    59
        testAll(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    60
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    61
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    62
    static void testAll(Graphics2D g2d) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    63
        g2d.setTransform(identity);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    64
        g2d.translate(100, 100);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    65
        testPrimitives(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    66
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    67
        g2d.setTransform(identity);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    68
        g2d.scale(10, 10);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    69
        testPrimitives(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    70
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    71
        g2d.setTransform(identity);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    72
        g2d.rotate(Math.PI/6);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    73
        testPrimitives(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    74
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    75
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    76
    static void testPrimitives(Graphics2D g2d) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    77
        testLine(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    78
        testRect(g2d);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    79
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    80
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    81
    static void testLine(Graphics2D g2d) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    82
        testLine(g2d, MinX, MinY, MaxX, MaxY);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    83
        testLine(g2d, MaxX, MinY, MinX, MaxY);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    84
        testLine(g2d, MinX, MaxY, MaxX, MinY);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    85
        testLine(g2d, MaxX, MaxY, MinX, MinY);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    86
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    87
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    88
    static void testRect(Graphics2D g2d) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    89
        g2d.fillRect(MinX, MinY, MaxX - MinX, MaxY - MinY);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    90
        g2d.fill(new Rectangle(MinX, MinY, MaxX - MinX, MaxY - MinY));
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    91
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    92
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    93
    static void testLine(Graphics2D g2d, int x1, int y1, int x2, int y2) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    94
        g2d.drawLine(x1, y1, x2, y2);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    95
        g2d.draw(new Line2D.Double(x1, y1, x2, y2));
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    96
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    97
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    98
    static class BoundsCheckerPaint implements Paint {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
    99
        private Color c = Color.WHITE;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   100
        private Rectangle2D expectedBounds;
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   101
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   102
        public BoundsCheckerPaint(double x1, double y1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   103
                                  double x2, double y2)
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   104
        {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   105
            expectedBounds = new Rectangle2D.Double();
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   106
            expectedBounds.setFrameFromDiagonal(x1, y1, x2, y2);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   107
        }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   108
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   109
        public int getTransparency() {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   110
            return c.getTransparency();
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   111
        }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   112
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   113
        public PaintContext createContext(ColorModel cm,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   114
                                          Rectangle deviceBounds,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   115
                                          Rectangle2D userBounds,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   116
                                          AffineTransform xform,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   117
                                          RenderingHints hints)
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   118
        {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   119
            System.out.println("user bounds = "+userBounds);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   120
            if (!userBounds.equals(expectedBounds)) {
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   121
                throw new RuntimeException("bounds fail to match");
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   122
            }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   123
            return c.createContext(cm, deviceBounds, userBounds, xform, hints);
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   124
        }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   125
    }
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
diff changeset
   126
}