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

Print this page
rev 9830 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by: darcy, prr


   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.awt.dnd.DnDConstants;
  31 import java.awt.dnd.InvalidDnDOperationException;
  32 
  33 import java.util.Map;
  34 
  35 /**
  36  * An abstract class for drag protocols on X11 systems.
  37  * Contains protocol-independent drag source code.
  38  *
  39  * @since 1.5
  40  */
  41 abstract class XDragSourceProtocol {
  42     private final XDragSourceProtocolListener listener;
  43 
  44     private boolean initialized = false;
  45 
  46     private long targetWindow = 0;
  47     private long targetProxyWindow = 0;
  48     private int targetProtocolVersion = 0;


  67     /**
  68      * Returns the protocol name. The protocol name cannot be null.
  69      */
  70     public abstract String getProtocolName();
  71 
  72     /**
  73      * Initializes a drag operation with the specified supported drop actions,
  74      * contents and data formats.
  75      *
  76      * @param actions a bitwise mask of <code>DnDConstants</code> that represent
  77      *                the supported drop actions.
  78      * @param contents the contents for the drag operation.
  79      * @param formats an array of Atoms that represent the supported data formats.
  80      * @param formats an array of Atoms that represent the supported data formats.
  81      * @throws InvalidDnDOperationException if a drag operation is already
  82      * initialized.
  83      * @throws IllegalArgumentException if some argument has invalid value.
  84      * @throws XException if some X call failed.
  85      */
  86     public final void initializeDrag(int actions, Transferable contents,
  87                                      Map formatMap, long[] formats)
  88       throws InvalidDnDOperationException,
  89              IllegalArgumentException, XException {
  90         XToolkit.awtLock();
  91         try {
  92             try {
  93                 if (initialized) {
  94                     throw new InvalidDnDOperationException("Already initialized");
  95                 }
  96 
  97                 initializeDragImpl(actions, contents, formatMap, formats);
  98 
  99                 initialized = true;
 100             } finally {
 101                 if (!initialized) {
 102                     cleanup();
 103                 }
 104             }
 105         } finally {
 106             XToolkit.awtUnlock();
 107         }
 108     }
 109 
 110     /* The caller must hold AWT_LOCK. */
 111     protected abstract void initializeDragImpl(int actions,
 112                                                Transferable contents,
 113                                                Map formatMap, long[] formats)

 114       throws InvalidDnDOperationException, IllegalArgumentException, XException;
 115 
 116     /**
 117      * Terminates the current drag operation (if any) and resets the internal
 118      * state of this object.
 119      *
 120      * @throws XException if some X call failed.
 121      */
 122     public void cleanup() {
 123         initialized = false;
 124         cleanupTargetInfo();
 125     }
 126 
 127     /**
 128      * Clears the information on the current drop target.
 129      *
 130      * @throws XException if some X call failed.
 131      */
 132     public void cleanupTargetInfo() {
 133         targetWindow = 0;




   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 import java.awt.datatransfer.DataFlavor;
  30 
  31 import java.awt.dnd.DnDConstants;
  32 import java.awt.dnd.InvalidDnDOperationException;
  33 
  34 import java.util.Map;
  35 
  36 /**
  37  * An abstract class for drag protocols on X11 systems.
  38  * Contains protocol-independent drag source code.
  39  *
  40  * @since 1.5
  41  */
  42 abstract class XDragSourceProtocol {
  43     private final XDragSourceProtocolListener listener;
  44 
  45     private boolean initialized = false;
  46 
  47     private long targetWindow = 0;
  48     private long targetProxyWindow = 0;
  49     private int targetProtocolVersion = 0;


  68     /**
  69      * Returns the protocol name. The protocol name cannot be null.
  70      */
  71     public abstract String getProtocolName();
  72 
  73     /**
  74      * Initializes a drag operation with the specified supported drop actions,
  75      * contents and data formats.
  76      *
  77      * @param actions a bitwise mask of <code>DnDConstants</code> that represent
  78      *                the supported drop actions.
  79      * @param contents the contents for the drag operation.
  80      * @param formats an array of Atoms that represent the supported data formats.
  81      * @param formats an array of Atoms that represent the supported data formats.
  82      * @throws InvalidDnDOperationException if a drag operation is already
  83      * initialized.
  84      * @throws IllegalArgumentException if some argument has invalid value.
  85      * @throws XException if some X call failed.
  86      */
  87     public final void initializeDrag(int actions, Transferable contents,
  88                                      Map<Long, DataFlavor> formatMap, long[] formats)
  89       throws InvalidDnDOperationException,
  90              IllegalArgumentException, XException {
  91         XToolkit.awtLock();
  92         try {
  93             try {
  94                 if (initialized) {
  95                     throw new InvalidDnDOperationException("Already initialized");
  96                 }
  97 
  98                 initializeDragImpl(actions, contents, formatMap, formats);
  99 
 100                 initialized = true;
 101             } finally {
 102                 if (!initialized) {
 103                     cleanup();
 104                 }
 105             }
 106         } finally {
 107             XToolkit.awtUnlock();
 108         }
 109     }
 110 
 111     /* The caller must hold AWT_LOCK. */
 112     protected abstract void initializeDragImpl(int actions,
 113                                                Transferable contents,
 114                                                Map<Long, DataFlavor> formatMap,
 115                                                long[] formats)
 116       throws InvalidDnDOperationException, IllegalArgumentException, XException;
 117 
 118     /**
 119      * Terminates the current drag operation (if any) and resets the internal
 120      * state of this object.
 121      *
 122      * @throws XException if some X call failed.
 123      */
 124     public void cleanup() {
 125         initialized = false;
 126         cleanupTargetInfo();
 127     }
 128 
 129     /**
 130      * Clears the information on the current drop target.
 131      *
 132      * @throws XException if some X call failed.
 133      */
 134     public void cleanupTargetInfo() {
 135         targetWindow = 0;