src/solaris/classes/sun/awt/X11/XDataTransferer.java

Print this page




  28 import java.awt.Image;
  29 
  30 import java.awt.datatransfer.DataFlavor;
  31 import java.awt.datatransfer.Transferable;
  32 import java.awt.datatransfer.UnsupportedFlavorException;
  33 
  34 import java.awt.image.BufferedImage;
  35 import java.awt.image.ColorModel;
  36 import java.awt.image.WritableRaster;
  37 
  38 import java.io.BufferedReader;
  39 import java.io.InputStream;
  40 import java.io.InputStreamReader;
  41 import java.io.IOException;
  42 
  43 import java.net.URI;
  44 import java.net.URISyntaxException;
  45 
  46 import java.util.ArrayList;
  47 import java.util.Iterator;

  48 import java.util.List;
  49 
  50 import javax.imageio.ImageIO;
  51 import javax.imageio.ImageTypeSpecifier;
  52 import javax.imageio.ImageWriter;
  53 import javax.imageio.spi.ImageWriterSpi;
  54 
  55 import sun.awt.datatransfer.DataTransferer;
  56 import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
  57 
  58 import java.io.ByteArrayOutputStream;
  59 import java.util.stream.Stream;
  60 
  61 /**
  62  * Platform-specific support for the data transfer subsystem.
  63  */
  64 public class XDataTransferer extends DataTransferer {
  65     static final XAtom FILE_NAME_ATOM = XAtom.get("FILE_NAME");
  66     static final XAtom DT_NET_FILE_ATOM = XAtom.get("_DT_NETFILE");
  67     static final XAtom PNG_ATOM = XAtom.get("PNG");


 313             DataFlavor df = new DataFlavor(nat);
 314             if (primaryType.equals(df.getPrimaryType())) {
 315                 return true;
 316             }
 317         } catch (Exception e) {
 318             // Not a MIME format.
 319         }
 320 
 321         return false;
 322     }
 323 
 324     /*
 325      * The XDnD protocol prescribes that the Atoms used as targets for data
 326      * transfer should have string names that represent the corresponding MIME
 327      * types.
 328      * To meet this requirement we check if the passed native format constitutes
 329      * a valid MIME and return a list of flavors to which the data in this MIME
 330      * type can be translated by the Data Transfer subsystem.
 331      */
 332     @Override
 333     public List<DataFlavor> getPlatformMappingsForNative(String nat) {
 334         List<DataFlavor> flavors = new ArrayList<>();
 335 
 336         if (nat == null) {
 337             return flavors;
 338         }
 339 
 340         DataFlavor df = null;
 341 
 342         try {
 343             df = new DataFlavor(nat);
 344         } catch (Exception e) {
 345             // The string doesn't constitute a valid MIME type.
 346             return flavors;
 347         }
 348 
 349         DataFlavor value = df;
 350         final String primaryType = df.getPrimaryType();
 351         final String baseType = primaryType + "/" + df.getSubType();
 352 
 353         // For text formats we map natives to MIME strings instead of data
 354         // flavors to enable dynamic text native-to-flavor mapping generation.


 375 
 376             BufferedImage bufferedImage =
 377                 new BufferedImage(model, raster, model.isAlphaPremultiplied(),
 378                                   null);
 379 
 380             defaultSpecifier = new ImageTypeSpecifier(bufferedImage);
 381         }
 382 
 383         return defaultSpecifier;
 384     }
 385 
 386     /*
 387      * The XDnD protocol prescribes that the Atoms used as targets for data
 388      * transfer should have string names that represent the corresponding MIME
 389      * types.
 390      * To meet this requirement we return a list of formats that represent
 391      * MIME types to which the data in this flavor can be translated by the Data
 392      * Transfer subsystem.
 393      */
 394     @Override
 395     public List<String> getPlatformMappingsForFlavor(DataFlavor df) {
 396         List<String> natives = new ArrayList<>(1);
 397 
 398         if (df == null) {
 399             return natives;
 400         }
 401 
 402         String charset = df.getParameter("charset");
 403         String baseType = df.getPrimaryType() + "/" + df.getSubType();
 404         String mimeType = baseType;
 405 
 406         if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
 407             mimeType += ";charset=" + charset;
 408         }
 409 
 410         // Add a mapping to the MIME native whenever the representation class
 411         // doesn't require translation.
 412         if (df.getRepresentationClass() != null &&
 413             (df.isRepresentationClassInputStream() ||
 414              df.isRepresentationClassByteBuffer() ||
 415              byte[].class.equals(df.getRepresentationClass()))) {
 416             natives.add(mimeType);




  28 import java.awt.Image;
  29 
  30 import java.awt.datatransfer.DataFlavor;
  31 import java.awt.datatransfer.Transferable;
  32 import java.awt.datatransfer.UnsupportedFlavorException;
  33 
  34 import java.awt.image.BufferedImage;
  35 import java.awt.image.ColorModel;
  36 import java.awt.image.WritableRaster;
  37 
  38 import java.io.BufferedReader;
  39 import java.io.InputStream;
  40 import java.io.InputStreamReader;
  41 import java.io.IOException;
  42 
  43 import java.net.URI;
  44 import java.net.URISyntaxException;
  45 
  46 import java.util.ArrayList;
  47 import java.util.Iterator;
  48 import java.util.LinkedHashSet;
  49 import java.util.List;
  50 
  51 import javax.imageio.ImageIO;
  52 import javax.imageio.ImageTypeSpecifier;
  53 import javax.imageio.ImageWriter;
  54 import javax.imageio.spi.ImageWriterSpi;
  55 
  56 import sun.awt.datatransfer.DataTransferer;
  57 import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
  58 
  59 import java.io.ByteArrayOutputStream;
  60 import java.util.stream.Stream;
  61 
  62 /**
  63  * Platform-specific support for the data transfer subsystem.
  64  */
  65 public class XDataTransferer extends DataTransferer {
  66     static final XAtom FILE_NAME_ATOM = XAtom.get("FILE_NAME");
  67     static final XAtom DT_NET_FILE_ATOM = XAtom.get("_DT_NETFILE");
  68     static final XAtom PNG_ATOM = XAtom.get("PNG");


 314             DataFlavor df = new DataFlavor(nat);
 315             if (primaryType.equals(df.getPrimaryType())) {
 316                 return true;
 317             }
 318         } catch (Exception e) {
 319             // Not a MIME format.
 320         }
 321 
 322         return false;
 323     }
 324 
 325     /*
 326      * The XDnD protocol prescribes that the Atoms used as targets for data
 327      * transfer should have string names that represent the corresponding MIME
 328      * types.
 329      * To meet this requirement we check if the passed native format constitutes
 330      * a valid MIME and return a list of flavors to which the data in this MIME
 331      * type can be translated by the Data Transfer subsystem.
 332      */
 333     @Override
 334     public LinkedHashSet<DataFlavor> getPlatformMappingsForNative(String nat) {
 335         LinkedHashSet<DataFlavor> flavors = new LinkedHashSet<>();
 336 
 337         if (nat == null) {
 338             return flavors;
 339         }
 340 
 341         DataFlavor df = null;
 342 
 343         try {
 344             df = new DataFlavor(nat);
 345         } catch (Exception e) {
 346             // The string doesn't constitute a valid MIME type.
 347             return flavors;
 348         }
 349 
 350         DataFlavor value = df;
 351         final String primaryType = df.getPrimaryType();
 352         final String baseType = primaryType + "/" + df.getSubType();
 353 
 354         // For text formats we map natives to MIME strings instead of data
 355         // flavors to enable dynamic text native-to-flavor mapping generation.


 376 
 377             BufferedImage bufferedImage =
 378                 new BufferedImage(model, raster, model.isAlphaPremultiplied(),
 379                                   null);
 380 
 381             defaultSpecifier = new ImageTypeSpecifier(bufferedImage);
 382         }
 383 
 384         return defaultSpecifier;
 385     }
 386 
 387     /*
 388      * The XDnD protocol prescribes that the Atoms used as targets for data
 389      * transfer should have string names that represent the corresponding MIME
 390      * types.
 391      * To meet this requirement we return a list of formats that represent
 392      * MIME types to which the data in this flavor can be translated by the Data
 393      * Transfer subsystem.
 394      */
 395     @Override
 396     public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
 397         LinkedHashSet<String> natives = new LinkedHashSet<>(1);
 398 
 399         if (df == null) {
 400             return natives;
 401         }
 402 
 403         String charset = df.getParameter("charset");
 404         String baseType = df.getPrimaryType() + "/" + df.getSubType();
 405         String mimeType = baseType;
 406 
 407         if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
 408             mimeType += ";charset=" + charset;
 409         }
 410 
 411         // Add a mapping to the MIME native whenever the representation class
 412         // doesn't require translation.
 413         if (df.getRepresentationClass() != null &&
 414             (df.isRepresentationClassInputStream() ||
 415              df.isRepresentationClassByteBuffer() ||
 416              byte[].class.equals(df.getRepresentationClass()))) {
 417             natives.add(mimeType);