This implements TransferHandler.exportToClipboard(). This is accompanied
by a Mauve test.
2006-10-17 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/TransferHandler.java
(exportToClipboard): Implemented.
/Roman
Index: javax/swing/TransferHandler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/TransferHandler.java,v
retrieving revision 1.17
diff -u -1 -5 -r1.17 TransferHandler.java
--- javax/swing/TransferHandler.java 17 Oct 2006 15:26:14 -0000 1.17
+++ javax/swing/TransferHandler.java 17 Oct 2006 20:13:54 -0000
@@ -342,34 +342,71 @@
* Subclasses should implement this method to remove the data that has been
* transferred when the action was <code>MOVE</code>.
*
* The default implementation does nothing because MOVE is not supported.
*
* @param c the source component
* @param data the data that has been transferred or <code>null</code>
* when the action is NONE
* @param action the action that has been performed
*/
protected void exportDone(JComponent c, Transferable data, int action)
{
// Nothing to do in the default implementation.
}
+ /**
+ * Exports the property of the component <code>c</code> that was
+ * specified for this TransferHandler to the clipboard, performing
+ * the specified action.
+ *
+ * This will check if the action is allowed by calling
+ * [EMAIL PROTECTED] #getSourceActions(JComponent)}. If the action is not allowed,
+ * then no export is performed.
+ *
+ * In either case the method [EMAIL PROTECTED] #exportDone} will be called with
+ * the action that has been performed, or [EMAIL PROTECTED] #NONE} if the action
+ * was not allowed or could otherwise not be completed.
+ * Any IllegalStateException that is thrown by the Clipboard due to
+ * beeing unavailable will be propagated through this method.
+ *
+ * @param c the component from which to export
+ * @param clip the clipboard to which the data will be exported
+ * @param action the action to perform
+ *
+ * @throws IllegalStateException when the clipboard is not available
+ */
public void exportToClipboard(JComponent c, Clipboard clip, int action)
- throws NotImplementedException
+ throws IllegalStateException
{
- // TODO: Implement this properly
+ action &= getSourceActions(c);
+ Transferable transferable = createTransferable(c);
+ if (transferable != null && action != NONE)
+ {
+ try
+ {
+ clip.setContents(transferable, null);
+ exportDone(c, transferable, action);
+ }
+ catch (IllegalStateException ex)
+ {
+ exportDone(c, transferable, NONE);
+ throw ex;
+ }
+ }
+ else
+ exportDone(c, null, NONE);
}
public int getSourceActions(JComponent c)
{
return sourceActions;
}
public Icon getVisualRepresentation(Transferable t)
{
return visualRepresentation;
}
public boolean importData(JComponent c, Transferable t)
throws NotImplementedException
{