< prev index next >

test/jdk/java/awt/dnd/ImageTransferTest/ImageTransferTest.java

Print this page




   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 4397404 4720930 8197926
  28  * @summary tests that images of all supported native image formats are
  29  * transferred properly
  30  * @library /test/lib
  31  * @library ../../regtesthelpers/process/
  32  * @build jdk.test.lib.Platform ProcessResults ProcessCommunicator
  33  * @author gas@sparc.spb.su area=Clipboard
  34  * @run main/timeout=240 ImageTransferTest
  35  */
  36 
  37 import jdk.test.lib.Platform;
  38 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
  39 import test.java.awt.regtesthelpers.process.ProcessResults;
  40 
  41 import java.awt.*;
  42 import java.awt.datatransfer.DataFlavor;
  43 import java.awt.datatransfer.SystemFlavorMap;
  44 import java.awt.datatransfer.Transferable;
  45 import java.awt.datatransfer.UnsupportedFlavorException;
  46 import java.awt.dnd.DnDConstants;
  47 import java.awt.dnd.DragSource;


 132     }
 133 }
 134 
 135 abstract class ImageTransferer {
 136     Image image;
 137     String[] formats;
 138     int fi; // current format index
 139     Frame frame = new Frame();
 140 
 141 
 142     ImageTransferer() {
 143         image = createImage();
 144         frame.setSize(100, 100);
 145     }
 146 
 147     private static Image createImage() {
 148         int w = 100;
 149         int h = 100;
 150         int[] pix = new int[w * h];
 151 

 152         int index = 0;
 153         for (int y = 0; y < h; y++) {
 154             for (int x = 0; x < w; x++) {
 155                 int red = 127;
 156                 int green = 127;
 157                 int blue = y > h / 2 ? 127 : 0;
 158                 int alpha = 255;
 159                 if (x < w / 4 && y < h / 4) {
 160                     alpha = 0;
 161                     red = 0;
 162                 }
 163                 pix[index++] =
 164                         (alpha << 24) | (red << 16) | (green << 8) | blue;


 165             }
 166         }
 167         return Toolkit.getDefaultToolkit().
 168                 createImage(new MemoryImageSource(w, h, pix, 0, w));
 169     }
 170 
 171 
 172     static String[] retrieveFormatsToTest() {
 173         SystemFlavorMap sfm =
 174                 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
 175         java.util.List<String> ln =
 176                 sfm.getNativesForFlavor(DataFlavor.imageFlavor);
 177         if (Platform.isWindows() &&  !ln.contains("METAFILEPICT"))
 178         {
 179             // for test failing on JDK without this fix
 180             ln.add("METAFILEPICT");
 181         }
 182         return ln.toArray(new String[ln.size()]);
 183     }
 184 
 185     static void leaveFormat(String format) {
 186         SystemFlavorMap sfm =
 187                 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
 188         sfm.setFlavorsForNative(format,


 216                     return false;
 217                 }
 218             }
 219         } else {
 220             for (int i = 0; i < ib1.length; i++) {
 221                 if ((ib1[i] & 0x00FFFFFF) != (ib2[i] & 0x00FFFFFF)) {
 222                     System.err.println("different pixels: " +
 223                     Integer.toHexString(ib1[i]) + " " +
 224                     Integer.toHexString(ib2[i]));
 225                     return false;
 226                 }
 227             }
 228         }
 229         return true;
 230     }
 231 
 232     private static int[] getImageData(Image image) {
 233         int width = image.getWidth(null);
 234         int height = image.getHeight(null);
 235         BufferedImage bimage =
 236                 new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
 237         Graphics2D g2d = bimage.createGraphics();
 238         try {
 239             g2d.drawImage(image, 0, 0, width, height, null);
 240         } finally {
 241             g2d.dispose();
 242         }
 243         return bimage.getRGB(0, 0, width, height, null, 0, width);
 244     }
 245 
 246     public static int sign(int n) {
 247         return n < 0 ? -1 : n == 0 ? 0 : 1;
 248     }
 249 
 250 }
 251 
 252 
 253 class ImageDragSource extends ImageTransferer {
 254     boolean[] passedArray;
 255 
 256     ImageDragSource() {




   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 4397404 4720930 8197926 8176556
  28  * @summary tests that images of all supported native image formats are
  29  * transferred properly
  30  * @library /test/lib
  31  * @library ../../regtesthelpers/process/
  32  * @build jdk.test.lib.Platform ProcessResults ProcessCommunicator
  33  * @author gas@sparc.spb.su area=Clipboard
  34  * @run main/timeout=240 ImageTransferTest
  35  */
  36 
  37 import jdk.test.lib.Platform;
  38 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
  39 import test.java.awt.regtesthelpers.process.ProcessResults;
  40 
  41 import java.awt.*;
  42 import java.awt.datatransfer.DataFlavor;
  43 import java.awt.datatransfer.SystemFlavorMap;
  44 import java.awt.datatransfer.Transferable;
  45 import java.awt.datatransfer.UnsupportedFlavorException;
  46 import java.awt.dnd.DnDConstants;
  47 import java.awt.dnd.DragSource;


 132     }
 133 }
 134 
 135 abstract class ImageTransferer {
 136     Image image;
 137     String[] formats;
 138     int fi; // current format index
 139     Frame frame = new Frame();
 140 
 141 
 142     ImageTransferer() {
 143         image = createImage();
 144         frame.setSize(100, 100);
 145     }
 146 
 147     private static Image createImage() {
 148         int w = 100;
 149         int h = 100;
 150         int[] pix = new int[w * h];
 151 
 152         BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
 153         int index = 0;
 154         for (int y = 0; y < h; y++) {
 155             for (int x = 0; x < w; x++) {
 156                 int red = 127;
 157                 int green = 127;
 158                 int blue = y > h / 2 ? 127 : 0;

 159                 if (x < w / 4 && y < h / 4) {

 160                     red = 0;
 161                 }
 162                 pix[index] =
 163                         (red << 16) | (green << 8) | blue;
 164                 img.setRGB(x, y, pix[index]);
 165                 index++;
 166             }
 167         }
 168         return (Image)img;

 169     }
 170 
 171 
 172     static String[] retrieveFormatsToTest() {
 173         SystemFlavorMap sfm =
 174                 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
 175         java.util.List<String> ln =
 176                 sfm.getNativesForFlavor(DataFlavor.imageFlavor);
 177         if (Platform.isWindows() &&  !ln.contains("METAFILEPICT"))
 178         {
 179             // for test failing on JDK without this fix
 180             ln.add("METAFILEPICT");
 181         }
 182         return ln.toArray(new String[ln.size()]);
 183     }
 184 
 185     static void leaveFormat(String format) {
 186         SystemFlavorMap sfm =
 187                 (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
 188         sfm.setFlavorsForNative(format,


 216                     return false;
 217                 }
 218             }
 219         } else {
 220             for (int i = 0; i < ib1.length; i++) {
 221                 if ((ib1[i] & 0x00FFFFFF) != (ib2[i] & 0x00FFFFFF)) {
 222                     System.err.println("different pixels: " +
 223                     Integer.toHexString(ib1[i]) + " " +
 224                     Integer.toHexString(ib2[i]));
 225                     return false;
 226                 }
 227             }
 228         }
 229         return true;
 230     }
 231 
 232     private static int[] getImageData(Image image) {
 233         int width = image.getWidth(null);
 234         int height = image.getHeight(null);
 235         BufferedImage bimage =
 236                 new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
 237         Graphics2D g2d = bimage.createGraphics();
 238         try {
 239             g2d.drawImage(image, 0, 0, width, height, null);
 240         } finally {
 241             g2d.dispose();
 242         }
 243         return bimage.getRGB(0, 0, width, height, null, 0, width);
 244     }
 245 
 246     public static int sign(int n) {
 247         return n < 0 ? -1 : n == 0 ? 0 : 1;
 248     }
 249 
 250 }
 251 
 252 
 253 class ImageDragSource extends ImageTransferer {
 254     boolean[] passedArray;
 255 
 256     ImageDragSource() {


< prev index next >