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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2014, 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

@@ -23,10 +23,11 @@
  * questions.
  */
 
 package java.awt.dnd;
 
+import java.awt.AWTError;
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.Toolkit;

@@ -40,10 +41,11 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.TooManyListenersException;
 
 import sun.awt.AWTAccessor;
+import sun.awt.ComponentFactory;
 
 /**
  * The <code>DragSourceContext</code> class is responsible for managing the
  * initiator side of the Drag and Drop protocol. In particular, it is responsible
  * for managing drag event notifications to the

@@ -182,12 +184,16 @@
      *         if dragImage is non-null and offset is null
      */
     public DragSourceContext(DragGestureEvent trigger, Cursor dragCursor,
                              Image dragImage, Point offset, Transferable t,
                              DragSourceListener dsl) {
-        DragSourceContextPeer dscp = Toolkit.getDefaultToolkit()
-                .createDragSourceContextPeer(trigger);
+        Toolkit toolkit = Toolkit.getDefaultToolkit();
+        if (!(toolkit instanceof ComponentFactory)) {
+            throw new AWTError("Unsupported toolkit: " + toolkit);
+        }
+        DragSourceContextPeer dscp = ((ComponentFactory) toolkit).
+                createDragSourceContextPeer(trigger);
 
         if (dscp == null) {
             throw new NullPointerException("DragSourceContextPeer");
         }