< prev index next >

test/jdk/java/awt/image/multiresolution/MultiresolutionIconTest.java

Print this page


   1 /*
   2  * Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 
  24 /*
  25  * @test
  26  * @key headful
  27  * @bug 8150724 8151303
  28  * @author a.stepanov
  29  * @summary Check that correct resolution variants are chosen for icons
  30  *          when multiresolution image is used for their construction.
  31  *
  32  * @library ../../../../lib/testlibrary/
  33  * @build ExtendedRobot
  34  * @run main/othervm/timeout=240 -Dsun.java2d.uiScale=1 MultiresolutionIconTest
  35  * @run main/othervm/timeout=240 -Dsun.java2d.uiScale=2 MultiresolutionIconTest
  36  */
  37 
  38 
  39 // TODO: please remove the "@requires" tag after 8151303 fix
  40 
  41 
  42 import java.awt.*;
  43 import java.awt.event.InputEvent;
  44 import java.awt.image.BaseMultiResolutionImage;
  45 import java.awt.image.BufferedImage;
  46 import javax.swing.*;
  47 
  48 public class MultiresolutionIconTest extends JFrame {
  49 
  50     private final static int SZ = 100;
  51     private final static int N = 5; // number of components
  52 
  53     private final static String SCALE = "sun.java2d.uiScale";
  54     private final static Color C1X = Color.RED;
  55     private final static Color C2X = Color.BLUE;
  56 
  57     private JLabel lbl;
  58     private JTabbedPane tabbedPane;
  59 
  60     private final ExtendedRobot r;
  61 


 119         p.add(lbl);
 120 
 121         tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
 122         tabbedPane.addTab("", tabIcon, p);
 123         getContentPane().add(tabbedPane);
 124 
 125         setResizable(false);
 126         setVisible(true);
 127     }
 128 
 129     private boolean checkPressedColor(int x, int y, Color ok) {
 130 
 131         r.mouseMove(x, y);
 132         r.waitForIdle();
 133         r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
 134         r.waitForIdle(100);
 135         Color c = r.getPixelColor(x, y);
 136         r.waitForIdle(100);
 137         r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
 138         r.waitForIdle(100);
 139         if (!c.equals(ok)) { return false; }











 140         // check the icon's color hasn't changed
 141         // after the mouse was released
 142         c = r.getPixelColor(x, y);
 143         return c.equals(ok);
 144     }
 145 
 146     private boolean checkTabIcon(
 147         int xStart, int xEnd, int yStart, int yEnd, Color ok, Color nok) {
 148 
 149         for (int y = yStart; y < yEnd; y += 2) {
 150             for (int x = xStart; x < xEnd; x += 2) {
 151                 Color c = r.getPixelColor(x, y);
 152                 if (c.equals(nok)) { return false; }
 153                 else if (c.equals(ok)) {
 154                     // shift a bit to avoid the selection effects
 155                     return checkPressedColor(x + 5, y + 5, ok);
 156                 }
 157             }
 158         }
 159 


   1 /*
   2  * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 
  24 /*
  25  * @test
  26  * @key headful
  27  * @bug 8150724 8151303 8169187
  28  * @author a.stepanov
  29  * @summary Check that correct resolution variants are chosen for icons
  30  *          when multiresolution image is used for their construction.
  31  *
  32  * @library ../../../../lib/testlibrary/
  33  * @build ExtendedRobot
  34  * @run main/othervm/timeout=240 -Dsun.java2d.uiScale=1 MultiresolutionIconTest
  35  * @run main/othervm/timeout=240 -Dsun.java2d.uiScale=2 MultiresolutionIconTest
  36  */
  37 




  38 import java.awt.*;
  39 import java.awt.event.InputEvent;
  40 import java.awt.image.BaseMultiResolutionImage;
  41 import java.awt.image.BufferedImage;
  42 import javax.swing.*;
  43 
  44 public class MultiresolutionIconTest extends JFrame {
  45 
  46     private final static int SZ = 100;
  47     private final static int N = 5; // number of components
  48 
  49     private final static String SCALE = "sun.java2d.uiScale";
  50     private final static Color C1X = Color.RED;
  51     private final static Color C2X = Color.BLUE;
  52 
  53     private JLabel lbl;
  54     private JTabbedPane tabbedPane;
  55 
  56     private final ExtendedRobot r;
  57 


 115         p.add(lbl);
 116 
 117         tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
 118         tabbedPane.addTab("", tabIcon, p);
 119         getContentPane().add(tabbedPane);
 120 
 121         setResizable(false);
 122         setVisible(true);
 123     }
 124 
 125     private boolean checkPressedColor(int x, int y, Color ok) {
 126 
 127         r.mouseMove(x, y);
 128         r.waitForIdle();
 129         r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
 130         r.waitForIdle(100);
 131         Color c = r.getPixelColor(x, y);
 132         r.waitForIdle(100);
 133         r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
 134         r.waitForIdle(100);
 135 
 136         if (!c.equals(ok)) {
 137             Rectangle bounds = new Rectangle(x, y, 1, 1);
 138             BufferedImage image = r.createScreenCapture(bounds);
 139             r.waitForIdle(200);
 140             Color locColor = new Color(image.getRGB((int)bounds.getWidth()/2, (int)bounds.getHeight()/2), true);
 141             
 142             if(!locColor.equals(ok)) {
 143                 System.out.println("Pressed color "+locColor+" does not match the expected color "+ok);
 144                 return false; 
 145             }
 146         }
 147         // check the icon's color hasn't changed
 148         // after the mouse was released
 149         c = r.getPixelColor(x, y);
 150         return c.equals(ok);
 151     }
 152 
 153     private boolean checkTabIcon(
 154         int xStart, int xEnd, int yStart, int yEnd, Color ok, Color nok) {
 155 
 156         for (int y = yStart; y < yEnd; y += 2) {
 157             for (int x = xStart; x < xEnd; x += 2) {
 158                 Color c = r.getPixelColor(x, y);
 159                 if (c.equals(nok)) { return false; }
 160                 else if (c.equals(ok)) {
 161                     // shift a bit to avoid the selection effects
 162                     return checkPressedColor(x + 5, y + 5, ok);
 163                 }
 164             }
 165         }
 166 


< prev index next >