98 frame.setSize(300, 300); 99 frame.setVisible(true); 100 } 101 102 private class MousePopupListener extends MouseAdapter { 103 104 @Override 105 public void mousePressed(MouseEvent e) { showPopup(e); } 106 @Override 107 public void mouseClicked(MouseEvent e) { showPopup(e); } 108 @Override 109 public void mouseReleased(MouseEvent e) { showPopup(e); } 110 111 private void showPopup(MouseEvent e) { 112 if (e.isPopupTrigger()) { 113 popup.show(MenuMultiresolutionIconTest.this, e.getX(), e.getY()); 114 } 115 } 116 } 117 118 private static boolean is2x() { 119 120 return GraphicsEnvironment.getLocalGraphicsEnvironment(). 121 getDefaultScreenDevice().getDefaultConfiguration(). 122 getDefaultTransform().getScaleX() > 1.001; 123 } 124 125 private boolean eqColors(Color c1, Color c2) { 126 127 int tol = 15; 128 return ( 129 Math.abs(c2.getRed() - c1.getRed() ) < tol && 130 Math.abs(c2.getGreen() - c1.getGreen()) < tol && 131 Math.abs(c2.getBlue() - c1.getBlue() ) < tol); 132 } 133 134 private void checkIconColor(Point p, String what) { 135 136 Color expected = is2x() ? C2X : C1X; 137 Color c = r.getPixelColor(p.x + SZ / 2, p.y + SZ / 2); 138 if (!eqColors(c, expected)) { 139 frame.dispose(); 140 throw new RuntimeException("invalid " + what + "menu item icon " + 141 "color, expected: " + expected + ", got: " + c); 142 } 143 System.out.println(what + "item icon check passed"); 144 } 145 146 private void doTest() { 147 148 r.waitForIdle(2 * DELAY); 149 150 Point p = getLocationOnScreen(); 151 r.mouseMove(p.x + getWidth() / 4, p.y + getHeight() / 4); 152 r.waitForIdle(DELAY); 153 r.click(InputEvent.BUTTON3_DOWN_MASK); 154 r.waitForIdle(DELAY); 155 p = popupItem.getLocationOnScreen(); 156 checkIconColor(p, "popup "); 160 r.mouseMove(p.x + menu.getWidth() / 2, p.y + menu.getHeight() / 2); 161 r.waitForIdle(DELAY); 162 r.click(); 163 p = menu.getItem(0).getLocationOnScreen(); 164 checkIconColor(p, ""); 165 r.waitForIdle(DELAY); 166 167 p = menu.getItem(1).getLocationOnScreen(); 168 checkIconColor(p, "radiobutton "); 169 r.waitForIdle(DELAY); 170 171 p = menu.getItem(2).getLocationOnScreen(); 172 checkIconColor(p, "checkbox "); 173 r.waitForIdle(DELAY); 174 175 frame.dispose(); 176 } 177 178 public static void main(String s[]) throws Exception { 179 180 // TODO: remove is2x() after JDK-8150844 fix 181 if (is2x() == "2".equals(System.getProperty(SCALE))) { 182 (new MenuMultiresolutionIconTest()).doTest(); 183 } 184 } 185 } | 98 frame.setSize(300, 300); 99 frame.setVisible(true); 100 } 101 102 private class MousePopupListener extends MouseAdapter { 103 104 @Override 105 public void mousePressed(MouseEvent e) { showPopup(e); } 106 @Override 107 public void mouseClicked(MouseEvent e) { showPopup(e); } 108 @Override 109 public void mouseReleased(MouseEvent e) { showPopup(e); } 110 111 private void showPopup(MouseEvent e) { 112 if (e.isPopupTrigger()) { 113 popup.show(MenuMultiresolutionIconTest.this, e.getX(), e.getY()); 114 } 115 } 116 } 117 118 private boolean eqColors(Color c1, Color c2) { 119 120 int tol = 15; 121 return ( 122 Math.abs(c2.getRed() - c1.getRed() ) < tol && 123 Math.abs(c2.getGreen() - c1.getGreen()) < tol && 124 Math.abs(c2.getBlue() - c1.getBlue() ) < tol); 125 } 126 127 private void checkIconColor(Point p, String what) { 128 129 String scale = System.getProperty(SCALE); 130 Color expected = "2".equals(scale) ? C2X : C1X; 131 Color c = r.getPixelColor(p.x + SZ / 2, p.y + SZ / 2); 132 if (!eqColors(c, expected)) { 133 frame.dispose(); 134 throw new RuntimeException("invalid " + what + "menu item icon " + 135 "color, expected: " + expected + ", got: " + c); 136 } 137 System.out.println(what + "item icon check passed"); 138 } 139 140 private void doTest() { 141 142 r.waitForIdle(2 * DELAY); 143 144 Point p = getLocationOnScreen(); 145 r.mouseMove(p.x + getWidth() / 4, p.y + getHeight() / 4); 146 r.waitForIdle(DELAY); 147 r.click(InputEvent.BUTTON3_DOWN_MASK); 148 r.waitForIdle(DELAY); 149 p = popupItem.getLocationOnScreen(); 150 checkIconColor(p, "popup "); 154 r.mouseMove(p.x + menu.getWidth() / 2, p.y + menu.getHeight() / 2); 155 r.waitForIdle(DELAY); 156 r.click(); 157 p = menu.getItem(0).getLocationOnScreen(); 158 checkIconColor(p, ""); 159 r.waitForIdle(DELAY); 160 161 p = menu.getItem(1).getLocationOnScreen(); 162 checkIconColor(p, "radiobutton "); 163 r.waitForIdle(DELAY); 164 165 p = menu.getItem(2).getLocationOnScreen(); 166 checkIconColor(p, "checkbox "); 167 r.waitForIdle(DELAY); 168 169 frame.dispose(); 170 } 171 172 public static void main(String s[]) throws Exception { 173 174 (new MenuMultiresolutionIconTest()).doTest(); 175 } 176 } |