1 |
/* TransferHandler.java -- |
/* TransferHandler.java -- |
2 |
Copyright (C) 2004 Free Software Foundation, Inc. |
Copyright (C) 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
43 |
import java.awt.datatransfer.Transferable; |
import java.awt.datatransfer.Transferable; |
44 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
45 |
import java.awt.event.InputEvent; |
import java.awt.event.InputEvent; |
46 |
|
import java.awt.Toolkit; |
47 |
import java.io.Serializable; |
import java.io.Serializable; |
48 |
|
|
49 |
public class TransferHandler implements Serializable |
public class TransferHandler implements Serializable |
63 |
TransferHandler transferHandler = component.getTransferHandler(); |
TransferHandler transferHandler = component.getTransferHandler(); |
64 |
Clipboard clipboard = getClipboard(component); |
Clipboard clipboard = getClipboard(component); |
65 |
|
|
66 |
|
if (clipboard == null) |
67 |
|
{ |
68 |
|
// Access denied! |
69 |
|
Toolkit.getDefaultToolkit().beep(); |
70 |
|
return; |
71 |
|
} |
72 |
|
|
73 |
if (command.equals(COMMAND_COPY)) |
if (command.equals(COMMAND_COPY)) |
74 |
transferHandler.exportToClipboard(component, clipboard, COPY); |
transferHandler.exportToClipboard(component, clipboard, COPY); |
75 |
else if (command.equals(COMMAND_CUT)) |
else if (command.equals(COMMAND_CUT)) |
84 |
} |
} |
85 |
|
|
86 |
/** |
/** |
87 |
* Get the system cliboard. If not available, create and return the VM-local |
* Get the system cliboard or null if the caller isn't allowed to |
88 |
* clipboard. |
* access the system clipboard. |
89 |
* |
* |
90 |
* @param component a component, used to get the toolkit. |
* @param component a component, used to get the toolkit. |
91 |
* @return the clipboard |
* @return the clipboard |
93 |
private static Clipboard getClipboard(JComponent component) |
private static Clipboard getClipboard(JComponent component) |
94 |
{ |
{ |
95 |
try |
try |
96 |
{ |
{ |
97 |
SecurityManager sm = System.getSecurityManager(); |
return component.getToolkit().getSystemClipboard(); |
98 |
if (sm != null) |
} |
99 |
sm.checkSystemClipboardAccess(); |
catch (SecurityException se) |
100 |
|
{ |
101 |
// We may access the system clipboard. |
return null; |
102 |
return component.getToolkit().getSystemClipboard(); |
} |
|
} |
|
|
catch (Exception e) |
|
|
{ |
|
|
// We may not access system clipboard. |
|
|
// Create VM-local clipboard if none exists yet. |
|
|
if (clipboard == null) |
|
|
clipboard = new Clipboard("Clipboard"); |
|
|
return clipboard; |
|
|
} |
|
103 |
} |
} |
104 |
} |
} |
105 |
|
|
118 |
private static Action cutAction = new TransferAction(COMMAND_CUT); |
private static Action cutAction = new TransferAction(COMMAND_CUT); |
119 |
private static Action pasteAction = new TransferAction(COMMAND_PASTE); |
private static Action pasteAction = new TransferAction(COMMAND_PASTE); |
120 |
|
|
|
/** |
|
|
* Clipboard if system clipboard may not be used. |
|
|
* Package-private to avoid an accessor method. |
|
|
*/ |
|
|
static Clipboard clipboard; |
|
|
|
|
121 |
private int sourceActions; |
private int sourceActions; |
122 |
private Icon visualRepresentation; |
private Icon visualRepresentation; |
123 |
|
|