1 /* 2 * Copyright (c) 2009, 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 * @bug 6657026 27 * @summary Tests shared MetalBumps in different application contexts 28 * @author Sergey Malenkov 29 */ 30 31 import sun.awt.SunToolkit; 32 33 import java.awt.Color; 34 import java.awt.Component; 35 import java.awt.Font; 36 import java.awt.FontMetrics; 37 import java.awt.Graphics; 38 import java.awt.Image; 39 import java.awt.Rectangle; 40 import java.awt.Shape; 41 import java.awt.image.BufferedImage; 42 import java.awt.image.ImageObserver; 43 import java.text.AttributedCharacterIterator; 44 import javax.swing.Icon; 45 import javax.swing.plaf.metal.MetalBorders.ToolBarBorder; 46 47 public class Test6657026 extends ToolBarBorder implements Runnable { 48 49 public static void main(String[] args) throws Exception { 50 new Test6657026().test(); 51 52 ThreadGroup group = new ThreadGroup("$$$"); 53 Thread thread = new Thread(group, new Test6657026()); 54 thread.start(); 55 thread.join(); 56 } 57 58 public void run() { 59 SunToolkit.createNewAppContext(); 60 test(); 61 } 62 63 private void test() { 64 MyGraphics mg = new MyGraphics(); 65 Icon icon = bumps; 66 icon.paintIcon(mg.component, mg, 0, 0); 67 if (mg.image != null) { 68 boolean failed = true; 69 int value = mg.image.getRGB(0, 0); 70 for (int x = 0; x < mg.image.getWidth(); x++) { 71 for (int y = 0; y < mg.image.getHeight(); y++) { 72 int current = mg.image.getRGB(x, y); 73 if (current != value) { 74 mg.image.setRGB(x, y, value); 75 failed = false; 76 } 77 78 } 79 } 80 if (failed) { 81 throw new Error("shared metal bumps"); 82 } 83 } 84 } 85 86 private static class MyGraphics extends Graphics { 87 88 private final Component component = new Component() {}; 89 private BufferedImage image; 90 91 public Graphics create() { 92 return null; // TODO: check 93 } 94 95 public void translate(int x, int y) { 96 // TODO: check 97 } 98 99 public Color getColor() { 100 return null; // TODO: check 101 } 102 103 public void setColor(Color color) { 104 // TODO: check 105 } 106 107 public void setPaintMode() { 108 // TODO: check 109 } 110 111 public void setXORMode(Color c1) { 112 // TODO: check 113 } 114 115 public Font getFont() { 116 return null; // TODO: check 117 } 118 119 public void setFont(Font font) { 120 // TODO: check 121 } 122 123 public FontMetrics getFontMetrics(Font font) { 124 return null; // TODO: check 125 } 126 127 public Rectangle getClipBounds() { 128 return null; // TODO: check 129 } 130 131 public void clipRect(int x, int y, int width, int height) { 132 // TODO: check 133 } 134 135 public void setClip(int x, int y, int width, int height) { 136 // TODO: check 137 } 138 139 public Shape getClip() { 140 return null; // TODO: check 141 } 142 143 public void setClip(Shape clip) { 144 // TODO: check 145 } 146 147 public void copyArea(int x, int y, int width, int height, int dx, int dy) { 148 // TODO: check 149 } 150 151 public void drawLine(int x1, int y1, int x2, int y2) { 152 // TODO: check 153 } 154 155 public void fillRect(int x, int y, int width, int height) { 156 // TODO: check 157 } 158 159 public void clearRect(int x, int y, int width, int height) { 160 // TODO: check 161 } 162 163 public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { 164 // TODO: check 165 } 166 167 public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { 168 // TODO: check 169 } 170 171 public void drawOval(int x, int y, int width, int height) { 172 // TODO: check 173 } 174 175 public void fillOval(int x, int y, int width, int height) { 176 // TODO: check 177 } 178 179 public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { 180 // TODO: check 181 } 182 183 public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { 184 // TODO: check 185 } 186 187 public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { 188 // TODO: check 189 } 190 191 public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { 192 // TODO: check 193 } 194 195 public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { 196 // TODO: check 197 } 198 199 public void drawString(String str, int x, int y) { 200 // TODO: check 201 } 202 203 public void drawString(AttributedCharacterIterator iterator, int x, int y) { 204 // TODO: check 205 } 206 207 public boolean drawImage(Image img, int x, int y, ImageObserver observer) { 208 return false; // TODO: check 209 } 210 211 public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { 212 return false; // TODO: check 213 } 214 215 public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { 216 return false; // TODO: check 217 } 218 219 public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { 220 return false; // TODO: check 221 } 222 223 public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { 224 if (img instanceof BufferedImage) { 225 this.image = (BufferedImage) img; 226 } 227 return false; // TODO: check 228 } 229 230 public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { 231 return false; // TODO: check 232 } 233 234 public void dispose() { 235 // TODO: check 236 } 237 } 238 }