This implements a missing method in TransferHandler.importData(). This
is accompanied by an extensive Mauve test to that method.

2006-10-28  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/TransferHandler.java
        (importData): Implemented stub method. Added API docs.

/Roman

Index: javax/swing/TransferHandler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/TransferHandler.java,v
retrieving revision 1.18
diff -u -1 -5 -r1.18 TransferHandler.java
--- javax/swing/TransferHandler.java	17 Oct 2006 20:15:43 -0000	1.18
+++ javax/swing/TransferHandler.java	28 Oct 2006 10:37:33 -0000
@@ -395,34 +395,75 @@
       }
     else
       exportDone(c, null, NONE);
   } 
 
   public int getSourceActions(JComponent c)
   {
     return sourceActions;
   }
 
   public Icon getVisualRepresentation(Transferable t)
   {
     return visualRepresentation;
   }
 
+  /**
+   * Imports the transfer data represented by <code>t</code> into the specified
+   * component <code>c</code> by setting the property of this TransferHandler
+   * on that component. If this succeeds, this method returns
+   * <code>true</code>, otherwise <code>false</code>.
+   * 
+   *
+   * @param c the component to import into
+   * @param t the transfer data to import
+   *
+   * @return <code>true</code> if the transfer succeeds, <code>false</code>
+   *         otherwise
+   */
   public boolean importData(JComponent c, Transferable t) 
-    throws NotImplementedException
   {
-    return false;
+    boolean ok = false;
+    PropertyDescriptor prop = getPropertyDescriptor(c);
+    if (prop != null)
+      {
+        Method writer = prop.getWriteMethod();
+        if (writer != null)
+          {
+            Class[] params = writer.getParameterTypes();
+            if (params.length == 1)
+              {
+                DataFlavor flavor = getPropertyDataFlavor(params[0],
+                                                   t.getTransferDataFlavors());
+                if (flavor != null)
+                  {
+                    try
+                      {
+                        Object value = t.getTransferData(flavor);
+                        writer.invoke(c, new Object[]{ value });
+                        ok = true;
+                      }
+                    catch (Exception ex)
+                      {
+                        // If anything goes wrong here, do nothing and return
+                        // false;
+                      }
+                  }
+              }
+          }
+      }
+    return ok;
   }
 
   /**
    * Returns the property descriptor for the property of this TransferHandler
    * in the specified component, or <code>null</code> if no such property
    * exists in the component. This method only returns properties that are
    * at least readable (that is, it has a public no-arg getter method).
    *
    * @param c the component to check
    *
    * @return the property descriptor for the property of this TransferHandler
    *         in the specified component, or <code>null</code> if no such
    *         property exists in the component
    */
   private PropertyDescriptor getPropertyDescriptor(JComponent c)

Reply via email to