src/java.desktop/share/classes/java/awt/dnd/DropTargetContext.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -88,23 +88,26 @@
      */
 
     public Component getComponent() { return dropTarget.getComponent(); }
 
     /**
-     * Called when associated with the <code>DropTargetContextPeer</code>.
+     * Called when associated with the peer object.
      *
-     * @param dtcp the <code>DropTargetContextPeer</code>
+     * @param  dtcp the peer object
+     * @throws IllegalArgumentException if provided peer is not supported
      */
-
-    public void addNotify(DropTargetContextPeer dtcp) {
-        dropTargetContextPeer = dtcp;
+    public void addNotify(final Object dtcp) throws IllegalArgumentException {
+        if (dtcp instanceof DropTargetContextPeer) {
+            dropTargetContextPeer = (DropTargetContextPeer) dtcp;
+        } else {
+            throw new IllegalArgumentException("Unsupported peer");
+        }
     }
 
     /**
      * Called when disassociated with the <code>DropTargetContextPeer</code>.
      */
-
     public void removeNotify() {
         dropTargetContextPeer = null;
         transferable          = null;
     }
 

@@ -410,11 +413,11 @@
     /**
      * The DropTarget associated with this DropTargetContext.
      *
      * @serial
      */
-    private DropTarget dropTarget;
+    private final DropTarget dropTarget;
 
     private transient DropTargetContextPeer dropTargetContextPeer;
 
     private transient Transferable transferable;
 }