jdk/src/java.desktop/unix/classes/sun/awt/X11/XSelection.java
changeset 26037 508779ce6619
parent 26007 dba8f49653ce
parent 25859 3317bb8137f4
child 35667 ed476aba94de
equal deleted inserted replaced
25992:e9b05e933ddd 26037:508779ce6619
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    41 import sun.awt.datatransfer.DataTransferer;
    41 import sun.awt.datatransfer.DataTransferer;
    42 
    42 
    43 /**
    43 /**
    44  * A class which interfaces with the X11 selection service.
    44  * A class which interfaces with the X11 selection service.
    45  */
    45  */
    46 public final class XSelection {
    46 final class XSelection {
    47 
    47 
    48     /* Maps atoms to XSelection instances. */
    48     /* Maps atoms to XSelection instances. */
    49     private static final Hashtable<XAtom, XSelection> table = new Hashtable<XAtom, XSelection>();
    49     private static final Hashtable<XAtom, XSelection> table = new Hashtable<XAtom, XSelection>();
    50     /* Prevents from parallel selection data request processing. */
    50     /* Prevents from parallel selection data request processing. */
    51     private static final Object lock = new Object();
    51     private static final Object lock = new Object();
   117     }
   117     }
   118 
   118 
   119     /**
   119     /**
   120      * Creates a selection object.
   120      * Creates a selection object.
   121      *
   121      *
   122      * @param atom   the selection atom.
   122      * @param  atom the selection atom
   123      * @param clpbrd the corresponding clipoboard
   123      * @throws NullPointerException if atom is {@code null}
   124      * @exception NullPointerException if atom is <code>null</code>.
       
   125      */
   124      */
   126     public XSelection(XAtom atom) {
   125     XSelection(XAtom atom) {
   127         if (atom == null) {
   126         if (atom == null) {
   128             throw new NullPointerException("Null atom");
   127             throw new NullPointerException("Null atom");
   129         }
   128         }
   130         selectionAtom = atom;
   129         selectionAtom = atom;
   131         table.put(selectionAtom, this);
   130         table.put(selectionAtom, this);
   133 
   132 
   134     public XAtom getSelectionAtom() {
   133     public XAtom getSelectionAtom() {
   135         return selectionAtom;
   134         return selectionAtom;
   136     }
   135     }
   137 
   136 
   138     public synchronized boolean setOwner(Transferable contents,
   137     synchronized boolean setOwner(Transferable contents,
   139                                          Map<Long, DataFlavor> formatMap,
   138                                   Map<Long, DataFlavor> formatMap,
   140                                          long[] formats, long time)
   139                                   long[] formats, long time) {
   141     {
       
   142         long owner = XWindow.getXAWTRootWindow().getWindow();
   140         long owner = XWindow.getXAWTRootWindow().getWindow();
   143         long selection = selectionAtom.getAtom();
   141         long selection = selectionAtom.getAtom();
   144 
   142 
   145         // ICCCM prescribes that CurrentTime should not be used for SetSelectionOwner.
   143         // ICCCM prescribes that CurrentTime should not be used for SetSelectionOwner.
   146         if (time == XConstants.CurrentTime) {
   144         if (time == XConstants.CurrentTime) {
   433         }
   431         }
   434 
   432 
   435         return data != null ? data : new byte[0];
   433         return data != null ? data : new byte[0];
   436     }
   434     }
   437 
   435 
   438     void validateDataGetter(WindowPropertyGetter propertyGetter)
   436     private void validateDataGetter(WindowPropertyGetter propertyGetter)
   439             throws IOException
   437             throws IOException
   440     {
   438     {
   441         // The order of checks is important because a property getter
   439         // The order of checks is important because a property getter
   442         // has not been executed in case of timeout as well as in case of
   440         // has not been executed in case of timeout as well as in case of
   443         // changed selection owner.
   441         // changed selection owner.