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

Print this page
rev 9717 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by:


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.X11;
  27 

  28 import java.awt.datatransfer.Transferable;
  29 
  30 import java.io.ByteArrayOutputStream;
  31 import java.io.IOException;
  32 
  33 import java.util.Hashtable;
  34 import java.util.Map;
  35 
  36 import sun.awt.AppContext;
  37 import sun.awt.SunToolkit;
  38 import sun.awt.UNIXToolkit;
  39 
  40 import sun.awt.datatransfer.DataTransferer;
  41 
  42 /**
  43  * A class which interfaces with the X11 selection service.
  44  */
  45 public final class XSelection {
  46 
  47     /* Maps atoms to XSelection instances. */


  70     /* The PropertyNotify event handler for incremental data transfer. */
  71     private static final XEventDispatcher incrementalTransferHandler =
  72         new IncrementalTransferHandler();
  73     /* The context for the current request - protected with awtLock. */
  74     private static WindowPropertyGetter propertyGetter = null;
  75 
  76     // The orders of the lock acquisition:
  77     //   XClipboard -> XSelection -> awtLock.
  78     //   lock -> awtLock.
  79 
  80     /* The X atom for the underlying selection. */
  81     private final XAtom selectionAtom;
  82 
  83     /*
  84      * Owner-related variables - protected with synchronized (this).
  85      */
  86 
  87     /* The contents supplied by the current owner. */
  88     private Transferable contents = null;
  89     /* The format-to-flavor map for the current owner. */
  90     private Map formatMap = null;
  91     /* The formats supported by the current owner was set. */
  92     private long[] formats = null;
  93     /* The AppContext in which the current owner was set. */
  94     private AppContext appContext = null;
  95     // The X server time of the last XConvertSelection() call;
  96     // protected with 'lock' and awtLock.
  97     private static long lastRequestServerTime;
  98     /* The time at which the current owner was set. */
  99     private long ownershipTime = 0;
 100     // True if we are the owner of this selection.
 101     private boolean isOwner;
 102     private OwnershipListener ownershipListener = null;
 103     private final Object stateLock = new Object();
 104 
 105     static {
 106         XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
 107                                     new SelectionEventHandler());
 108     }
 109 
 110     /*


 117 
 118     /**
 119      * Creates a selection object.
 120      *
 121      * @param atom   the selection atom.
 122      * @param clpbrd the corresponding clipoboard
 123      * @exception NullPointerException if atom is <code>null</code>.
 124      */
 125     public XSelection(XAtom atom) {
 126         if (atom == null) {
 127             throw new NullPointerException("Null atom");
 128         }
 129         selectionAtom = atom;
 130         table.put(selectionAtom, this);
 131     }
 132 
 133     public XAtom getSelectionAtom() {
 134         return selectionAtom;
 135     }
 136 
 137     public synchronized boolean setOwner(Transferable contents, Map formatMap,

 138                                          long[] formats, long time)
 139     {
 140         long owner = XWindow.getXAWTRootWindow().getWindow();
 141         long selection = selectionAtom.getAtom();
 142 
 143         // ICCCM prescribes that CurrentTime should not be used for SetSelectionOwner.
 144         if (time == XConstants.CurrentTime) {
 145             time = XToolkit.getCurrentServerTime();
 146         }
 147 
 148         this.contents = contents;
 149         this.formatMap = formatMap;
 150         this.formats = formats;
 151         this.appContext = AppContext.getAppContext();
 152         this.ownershipTime = time;
 153 
 154         XToolkit.awtLock();
 155         try {
 156             XlibWrapper.XSetSelectionOwner(XToolkit.getDisplay(),
 157                                            selection, owner, time);




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.X11;
  27 
  28 import java.awt.datatransfer.DataFlavor;
  29 import java.awt.datatransfer.Transferable;
  30 
  31 import java.io.ByteArrayOutputStream;
  32 import java.io.IOException;
  33 
  34 import java.util.Hashtable;
  35 import java.util.Map;
  36 
  37 import sun.awt.AppContext;
  38 import sun.awt.SunToolkit;
  39 import sun.awt.UNIXToolkit;
  40 
  41 import sun.awt.datatransfer.DataTransferer;
  42 
  43 /**
  44  * A class which interfaces with the X11 selection service.
  45  */
  46 public final class XSelection {
  47 
  48     /* Maps atoms to XSelection instances. */


  71     /* The PropertyNotify event handler for incremental data transfer. */
  72     private static final XEventDispatcher incrementalTransferHandler =
  73         new IncrementalTransferHandler();
  74     /* The context for the current request - protected with awtLock. */
  75     private static WindowPropertyGetter propertyGetter = null;
  76 
  77     // The orders of the lock acquisition:
  78     //   XClipboard -> XSelection -> awtLock.
  79     //   lock -> awtLock.
  80 
  81     /* The X atom for the underlying selection. */
  82     private final XAtom selectionAtom;
  83 
  84     /*
  85      * Owner-related variables - protected with synchronized (this).
  86      */
  87 
  88     /* The contents supplied by the current owner. */
  89     private Transferable contents = null;
  90     /* The format-to-flavor map for the current owner. */
  91     private Map<Long, DataFlavor> formatMap = null;
  92     /* The formats supported by the current owner was set. */
  93     private long[] formats = null;
  94     /* The AppContext in which the current owner was set. */
  95     private AppContext appContext = null;
  96     // The X server time of the last XConvertSelection() call;
  97     // protected with 'lock' and awtLock.
  98     private static long lastRequestServerTime;
  99     /* The time at which the current owner was set. */
 100     private long ownershipTime = 0;
 101     // True if we are the owner of this selection.
 102     private boolean isOwner;
 103     private OwnershipListener ownershipListener = null;
 104     private final Object stateLock = new Object();
 105 
 106     static {
 107         XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
 108                                     new SelectionEventHandler());
 109     }
 110 
 111     /*


 118 
 119     /**
 120      * Creates a selection object.
 121      *
 122      * @param atom   the selection atom.
 123      * @param clpbrd the corresponding clipoboard
 124      * @exception NullPointerException if atom is <code>null</code>.
 125      */
 126     public XSelection(XAtom atom) {
 127         if (atom == null) {
 128             throw new NullPointerException("Null atom");
 129         }
 130         selectionAtom = atom;
 131         table.put(selectionAtom, this);
 132     }
 133 
 134     public XAtom getSelectionAtom() {
 135         return selectionAtom;
 136     }
 137 
 138     public synchronized boolean setOwner(Transferable contents,
 139                                          Map<Long, DataFlavor> formatMap,
 140                                          long[] formats, long time)
 141     {
 142         long owner = XWindow.getXAWTRootWindow().getWindow();
 143         long selection = selectionAtom.getAtom();
 144 
 145         // ICCCM prescribes that CurrentTime should not be used for SetSelectionOwner.
 146         if (time == XConstants.CurrentTime) {
 147             time = XToolkit.getCurrentServerTime();
 148         }
 149 
 150         this.contents = contents;
 151         this.formatMap = formatMap;
 152         this.formats = formats;
 153         this.appContext = AppContext.getAppContext();
 154         this.ownershipTime = time;
 155 
 156         XToolkit.awtLock();
 157         try {
 158             XlibWrapper.XSetSelectionOwner(XToolkit.getDisplay(),
 159                                            selection, owner, time);