jdk/src/macosx/classes/sun/lwawt/macosx/CDataTransferer.java
changeset 23652 11515e3c3f85
parent 23328 4c53a6ebc779
child 24530 479661529a54
equal deleted inserted replaced
23651:e41298d0da2f 23652:11515e3c3f85
    50         "FILE_NAME",
    50         "FILE_NAME",
    51         "TIFF",
    51         "TIFF",
    52         "RICH_TEXT",
    52         "RICH_TEXT",
    53         "HTML",
    53         "HTML",
    54         "PDF",
    54         "PDF",
    55         "URL"
    55         "URL",
       
    56         "PNG",
       
    57         "JFIF"
    56     };
    58     };
    57 
    59 
    58     static {
    60     static {
    59         Map<String, Long> nameMap = new HashMap<>(predefinedClipboardNames.length, 1.0f);
    61         Map<String, Long> nameMap = new HashMap<>(predefinedClipboardNames.length, 1.0f);
    60         Map<Long, String> formatMap = new HashMap<>(predefinedClipboardNames.length, 1.0f);
    62         Map<Long, String> formatMap = new HashMap<>(predefinedClipboardNames.length, 1.0f);
    72     public static final int CF_TIFF        = 3;
    74     public static final int CF_TIFF        = 3;
    73     public static final int CF_RICH_TEXT   = 4;
    75     public static final int CF_RICH_TEXT   = 4;
    74     public static final int CF_HTML        = 5;
    76     public static final int CF_HTML        = 5;
    75     public static final int CF_PDF         = 6;
    77     public static final int CF_PDF         = 6;
    76     public static final int CF_URL         = 7;
    78     public static final int CF_URL         = 7;
    77     public static final int CF_PNG         = 10;
    79     public static final int CF_PNG         = 8;
    78     public static final int CF_JPEG        = 11;
    80     public static final int CF_JPEG        = 9;
    79 
    81 
    80     private CDataTransferer() {}
    82     private CDataTransferer() {}
    81 
    83 
    82     private static CDataTransferer fTransferer;
    84     private static CDataTransferer fTransferer;
    83 
    85 
   202     @Override
   204     @Override
   203     public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {
   205     public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {
   204         return handler;
   206         return handler;
   205     }
   207     }
   206 
   208 
   207     private native byte[] imageDataToPlatformImageBytes(int[] rData, int nW, int nH);
       
   208     @Override
   209     @Override
   209     protected byte[] imageToPlatformBytes(Image image, long format) {
   210     protected byte[] imageToPlatformBytes(Image image, long format) {
   210         int w = image.getWidth(null);
   211         return CImage.getCreator().getPlatformImageBytes(image);
   211         int h = image.getHeight(null);
       
   212         BufferedImage bimage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
       
   213         Graphics g = bimage.getGraphics();
       
   214         g.drawImage(image, 0, 0, w, h, null);
       
   215         g.dispose();
       
   216         Raster raster = bimage.getRaster();
       
   217         DataBuffer buffer = raster.getDataBuffer();
       
   218         return imageDataToPlatformImageBytes(((DataBufferInt)buffer).getData(),
       
   219                                              raster.getWidth(),
       
   220                                              raster.getHeight());
       
   221     }
   212     }
   222 
   213 
   223     private static native String[] nativeDragQueryFile(final byte[] bytes);
   214     private static native String[] nativeDragQueryFile(final byte[] bytes);
   224     @Override
   215     @Override
   225     protected String[] dragQueryFile(final byte[] bytes) {
   216     protected String[] dragQueryFile(final byte[] bytes) {
   226         if (bytes == null) return null;
   217         if (bytes == null) return null;
   227         if (new String(bytes).startsWith("Unsupported type")) return null;
   218         if (new String(bytes).startsWith("Unsupported type")) return null;
   228         return nativeDragQueryFile(bytes);
   219         return nativeDragQueryFile(bytes);
   229     }
   220     }
   230 
   221 
   231     private native Image getImageForByteStream(byte[] bytes);
       
   232     /**
       
   233      * Translates a byte array which contains
       
   234      * platform-specific image data in the given format into an Image.
       
   235      */
       
   236     @Override
   222     @Override
   237     protected Image platformImageBytesToImage(byte[] bytes, long format) throws IOException {
   223     protected Image platformImageBytesToImage(byte[] bytes, long format) throws IOException {
   238         return getImageForByteStream(bytes);
   224         return CImage.getCreator().createImageFromPlatformImageBytes(bytes);
   239     }
   225     }
   240 
   226 
   241     @Override
   227     @Override
   242     protected ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList) throws IOException {
   228     protected ByteArrayOutputStream convertFileListToBytes(ArrayList<String> fileList) throws IOException {
   243         ByteArrayOutputStream bos = new ByteArrayOutputStream();
   229         ByteArrayOutputStream bos = new ByteArrayOutputStream();