test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 import java.awt.BorderLayout;
  24 import java.awt.Color;
  25 import java.awt.Cursor;
  26 import java.awt.Dialog;
  27 import java.awt.Frame;
  28 import java.awt.Graphics;
  29 import java.awt.Graphics2D;
  30 import java.awt.Image;
  31 import java.awt.Label;
  32 import java.awt.Point;
  33 import java.awt.TextArea;
  34 import java.awt.Toolkit;

  35 import java.awt.image.BufferedImage;
  36 import java.util.LinkedList;
  37 import java.util.List;
  38 import javax.swing.JApplet;
  39 import sun.awt.OSInfo;
  40 import sun.awt.image.MultiResolutionImage;




  41 
  42 /**
  43  * @test
  44  * @bug 8028212
  45  * @summary [macosx] Custom Cursor HiDPI support
  46  * @author Alexander Scherbatiy
  47  * @run applet/manual=yesno MultiResolutionCursorTest.html
  48  */
  49 public class MultiResolutionCursorTest extends JApplet {
  50     //Declare things used in the test, like buttons and labels here
  51 
  52     static final int sizes[] = {16, 32, 128};
  53     static final Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE};
  54 
  55     public void init() {
  56         //Create instructions for the user here, as well as set up
  57         // the environment -- set the layout manager, add buttons,
  58         // etc.
  59         this.setLayout(new BorderLayout());
  60 


 102     static class MultiResolutionCursor extends BufferedImage implements MultiResolutionImage {
 103 
 104         List<Image> highResolutionImages;
 105 
 106         public MultiResolutionCursor() {
 107             super(sizes[0], sizes[0], BufferedImage.TYPE_INT_RGB);
 108 
 109             draw(getGraphics(), 0);
 110             highResolutionImages = new LinkedList<>();
 111             highResolutionImages.add(this);
 112 
 113             for (int i = 1; i < sizes.length; i++) {
 114                 BufferedImage highResolutionImage =
 115                         new BufferedImage(sizes[i], sizes[i], BufferedImage.TYPE_INT_RGB);
 116                 draw(highResolutionImage.getGraphics(), i);
 117                 highResolutionImages.add(highResolutionImage);
 118             }
 119         }
 120 
 121         @Override
 122         public Image getResolutionVariant(int width, int height) {








 123 
 124             for (int i = 0; i < sizes.length; i++) {
 125                 Image image = highResolutionImages.get(i);
 126                 int w = image.getWidth(null);
 127                 int h = image.getHeight(null);
 128 
 129                 if (width <= w && height <= h) {
 130                     return image;
 131                 }
 132             }
 133 
 134             return highResolutionImages.get(highResolutionImages.size() - 1);
 135         }
 136 
 137         void draw(Graphics graphics, int index) {
 138             Graphics2D g2 = (Graphics2D) graphics;
 139             Color color = colors[index];
 140             g2.setColor(color);
 141             g2.fillRect(0, 0, sizes[index], sizes[index]);
 142         }
 143 
 144         @Override
 145         public List<Image> getResolutionVariants() {
 146             return highResolutionImages;
 147         }






 148     }
 149 }// class BlockedWindowTest
 150 
 151 /* Place other classes related to the test after this line */
 152 /**
 153  * **************************************************
 154  * Standard Test Machinery DO NOT modify anything below -- it's a standard chunk
 155  * of code whose purpose is to make user interaction uniform, and thereby make
 156  * it simpler to read and understand someone else's test.
 157  * **************************************************
 158  */
 159 /**
 160  * This is part of the standard test machinery. It creates a dialog (with the
 161  * instructions), and is the interface for sending text messages to the user. To
 162  * print the instructions, send an array of strings to Sysout.createDialog
 163  * WithInstructions method. Put one line of instructions per array entry. To
 164  * display a message for the tester to see, simply call Sysout.println with the
 165  * string to be displayed. This mimics System.out.println but works within the
 166  * test harness as well as standalone.
 167  */




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 import java.awt.BorderLayout;
  24 import java.awt.Color;
  25 import java.awt.Cursor;
  26 import java.awt.Dialog;
  27 import java.awt.Frame;
  28 import java.awt.Graphics;
  29 import java.awt.Graphics2D;
  30 import java.awt.Image;
  31 import java.awt.Label;
  32 import java.awt.Point;
  33 import java.awt.TextArea;
  34 import java.awt.Toolkit;
  35 import java.awt.geom.AffineTransform;
  36 import java.awt.image.BufferedImage;
  37 import java.util.LinkedList;
  38 import java.util.List;
  39 import javax.swing.JApplet;
  40 import sun.awt.OSInfo;
  41 import java.awt.image.MultiResolutionImage;
  42 import sun.awt.image.ImageResolutionHelper;
  43 import sun.awt.image.ImageResolutionHelperType;
  44 import static sun.awt.image.ImageResolutionHelperType.DPI_AWARE;
  45 import static sun.awt.image.ImageResolutionHelperType.TRANSFORM_AWARE;
  46 
  47 /**
  48  * @test
  49  * @bug 8028212
  50  * @summary [macosx] Custom Cursor HiDPI support
  51  * @author Alexander Scherbatiy
  52  * @run applet/manual=yesno MultiResolutionCursorTest.html
  53  */
  54 public class MultiResolutionCursorTest extends JApplet {
  55     //Declare things used in the test, like buttons and labels here
  56 
  57     static final int sizes[] = {16, 32, 128};
  58     static final Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE};
  59 
  60     public void init() {
  61         //Create instructions for the user here, as well as set up
  62         // the environment -- set the layout manager, add buttons,
  63         // etc.
  64         this.setLayout(new BorderLayout());
  65 


 107     static class MultiResolutionCursor extends BufferedImage implements MultiResolutionImage {
 108 
 109         List<Image> highResolutionImages;
 110 
 111         public MultiResolutionCursor() {
 112             super(sizes[0], sizes[0], BufferedImage.TYPE_INT_RGB);
 113 
 114             draw(getGraphics(), 0);
 115             highResolutionImages = new LinkedList<>();
 116             highResolutionImages.add(this);
 117 
 118             for (int i = 1; i < sizes.length; i++) {
 119                 BufferedImage highResolutionImage =
 120                         new BufferedImage(sizes[i], sizes[i], BufferedImage.TYPE_INT_RGB);
 121                 draw(highResolutionImage.getGraphics(), i);
 122                 highResolutionImages.add(highResolutionImage);
 123             }
 124         }
 125 
 126         @Override
 127         public Image getResolutionVariant(float logicalDPIX, float logicalDPIY,
 128                 float baseWidth, float baseHeight, float destWidth, float destHeight) {
 129             ImageResolutionHelper helper = getPlatformHelper();
 130             float w = helper.getHiDPISize(logicalDPIX, baseWidth, destWidth);
 131             float h = helper.getHiDPISize(logicalDPIY, baseHeight, destHeight);
 132             return getResolutionVariant(w, h);
 133         }
 134 
 135         private Image getResolutionVariant(float width, float height) {
 136 
 137             for (int i = 0; i < sizes.length; i++) {
 138                 Image image = highResolutionImages.get(i);
 139                 int w = image.getWidth(null);
 140                 int h = image.getHeight(null);
 141 
 142                 if (width <= w && height <= h) {
 143                     return image;
 144                 }
 145             }
 146 
 147             return highResolutionImages.get(highResolutionImages.size() - 1);
 148         }
 149 
 150         void draw(Graphics graphics, int index) {
 151             Graphics2D g2 = (Graphics2D) graphics;
 152             Color color = colors[index];
 153             g2.setColor(color);
 154             g2.fillRect(0, 0, sizes[index], sizes[index]);
 155         }
 156 
 157         @Override
 158         public List<Image> getResolutionVariants() {
 159             return highResolutionImages;
 160         }
 161 
 162         static ImageResolutionHelper getPlatformHelper() {
 163             return OSInfo.OSType.WINDOWS.equals(OSInfo.getOSType())
 164                     ? DPI_AWARE : TRANSFORM_AWARE;
 165         }
 166 
 167     }
 168 }// class BlockedWindowTest
 169 
 170 /* Place other classes related to the test after this line */
 171 /**
 172  * **************************************************
 173  * Standard Test Machinery DO NOT modify anything below -- it's a standard chunk
 174  * of code whose purpose is to make user interaction uniform, and thereby make
 175  * it simpler to read and understand someone else's test.
 176  * **************************************************
 177  */
 178 /**
 179  * This is part of the standard test machinery. It creates a dialog (with the
 180  * instructions), and is the interface for sending text messages to the user. To
 181  * print the instructions, send an array of strings to Sysout.createDialog
 182  * WithInstructions method. Put one line of instructions per array entry. To
 183  * display a message for the tester to see, simply call Sysout.println with the
 184  * string to be displayed. This mimics System.out.println but works within the
 185  * test harness as well as standalone.
 186  */