< prev index next >

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

Print this page

        

*** 22,32 **** */ /* * @test * @key headful ! * @bug 4397404 4720930 8197926 * @summary tests that images of all supported native image formats are * transferred properly * @library /test/lib * @library ../../regtesthelpers/process/ * @build jdk.test.lib.Platform ProcessResults ProcessCommunicator --- 22,32 ---- */ /* * @test * @key headful ! * @bug 4397404 4720930 8197926 8176556 * @summary tests that images of all supported native image formats are * transferred properly * @library /test/lib * @library ../../regtesthelpers/process/ * @build jdk.test.lib.Platform ProcessResults ProcessCommunicator
*** 132,156 **** } } abstract class ImageTransferer { Image image; String[] formats; int fi; // current format index Frame frame = new Frame(); ImageTransferer() { ! image = createImage(); frame.setSize(100, 100); } ! private static Image createImage() { int w = 100; int h = 100; int[] pix = new int[w * h]; int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127; --- 132,164 ---- } } abstract class ImageTransferer { Image image; + Image imageForJpeg; String[] formats; int fi; // current format index Frame frame = new Frame(); ImageTransferer() { ! image = createImage(false); ! imageForJpeg = createImage(true); frame.setSize(100, 100); } ! private static Image createImage(boolean forJpeg) { int w = 100; int h = 100; int[] pix = new int[w * h]; + BufferedImage img; + if (!forJpeg) { + img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + } else { + img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + } int index = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int red = 127; int green = 127;
*** 158,173 **** int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } ! pix[index++] = ! (alpha << 24) | (red << 16) | (green << 8) | blue; } } ! return Toolkit.getDefaultToolkit(). ! createImage(new MemoryImageSource(w, h, pix, 0, w)); } static String[] retrieveFormatsToTest() { SystemFlavorMap sfm = --- 166,187 ---- int alpha = 255; if (x < w / 4 && y < h / 4) { alpha = 0; red = 0; } ! if (!forJpeg) { ! pix[index] = ! (alpha <<24) | (red << 16) | (green << 8) | blue; ! } else { ! pix[index] = ! (red << 16) | (green << 8) | blue; ! } ! img.setRGB(x, y, pix[index]); ! index++; } } ! return (Image)img; } static String[] retrieveFormatsToTest() { SystemFlavorMap sfm =
*** 266,276 **** } }; new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_COPY, ! dge -> dge.startDrag(null, new ImageSelection(image), dsl)); leaveFormat(formats[fi]); } void notifyTransferSuccess(boolean status) { --- 280,296 ---- } }; new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_COPY, ! dge -> { ! if (formats[fi].equals("JFIF") || formats[fi].equals("image/jpeg")) { ! dge.startDrag(null, new ImageSelection(imageForJpeg), dsl); ! } else { ! dge.startDrag(null, new ImageSelection(image), dsl); ! } ! }); leaveFormat(formats[fi]); } void notifyTransferSuccess(boolean status) {
*** 312,321 **** --- 332,349 ---- dtde.dropComplete(false); notifyTransferSuccess(false); return; } + /* + * We are using RGB source image for jpeg + * because there is no support for alpha channel. + * Also we are not verifying pixel data for jpeg + * in areImagesIdentical() since it is a lossy format. + * So after image drop we are not handling any needed + * special cases for jpeg. + */ if (im == null) { System.err.println("getTransferData returned null"); dtde.dropComplete(false); notifyTransferSuccess(false); } else if (areImagesIdentical(image, im)) {
< prev index next >