classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Getting the system clipboard in javax/swing/TransferHa


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Getting the system clipboard in javax/swing/TransferHandler
Date: Sun, 13 Nov 2005 21:06:50 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

The private method getClipboard in TransferHandler was always returning the VM local clipboard and not the system clipboard in the case when the security manager is not installed (typical case).

With this patch, I am able to paste the external data from the system clipboard into the text field if manually calling the .paste() method (test case for PR 24733 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24733>). Ctrl-V still does not show any signs of life.

PR 24733 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24733>
2005-11-13  Audrius Meskauskas  <address@hidden>

* javax/swing/TransferHandler.java (getClipboard): Rewritten.

Index: javax/swing/TransferHandler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/TransferHandler.java,v
retrieving revision 1.10
diff -u -r1.10 TransferHandler.java
--- javax/swing/TransferHandler.java    19 Oct 2005 15:45:05 -0000      1.10
+++ javax/swing/TransferHandler.java    13 Nov 2005 19:19:44 -0000
@@ -75,30 +75,38 @@
        }
     }
   
+    /**
+     * Get the system cliboard. If not available, create and return the 
VM-local
+     * clipboard.
+     * 
+     * @param component a component, used to get the toolkit.
+     * @return the clipboard
+     */
     private static Clipboard getClipboard(JComponent component)
     {
-      SecurityManager sm = System.getSecurityManager();
-    
-      if (sm != null)
-       {
-         try
-           {
-             sm.checkSystemClipboardAccess();
+      // Avoid throwing exception if the system clipboard access failed
+      // in the past.
+      if (clipboard != null)
+        return clipboard;
+      else
+        {
+          try
+            {
+              SecurityManager sm = System.getSecurityManager();
+              if (sm != null)
+                sm.checkSystemClipboardAccess();
 
-             // We may access system clipboard.
-             return component.getToolkit().getSystemClipboard();
-           }
-         catch (SecurityException e)
-           {
-             // We may not access system clipboard.
-           }
-       }
-    
-      // Create VM-local clipboard if non exists yet.
-      if (clipboard == null)
-        clipboard = new Clipboard("Clipboard");
-
-      return clipboard;
+              // We may access system clipboard.
+              return component.getToolkit().getSystemClipboard();
+            }
+          catch (Exception e)
+            {
+              // We may not access system clipboard.
+              // Create VM-local clipboard if none exists yet.
+              clipboard = new Clipboard("Clipboard");
+              return clipboard;
+            }
+        }
     }
   }
   

reply via email to

[Prev in Thread] Current Thread [Next in Thread]