1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.xmlhammer.gui.actions;
22
23 import java.awt.Toolkit;
24 import java.awt.event.KeyEvent;
25
26 import javax.swing.ImageIcon;
27 import javax.swing.JComponent;
28 import javax.swing.KeyStroke;
29 import javax.swing.text.JTextComponent;
30
31 import org.bounce.RunnableAction;
32 import org.xmlhammer.gui.XMLHammer;
33
34 /***
35 * An action that can be used to paste from the clipboard.
36 *
37 * @version $Revision: 1.8 $, $Date: 2007/07/04 19:42:49 $
38 * @author Edwin Dankert <edankert@gmail.com>
39 */
40 public class PasteAction extends RunnableAction {
41 private static final long serialVersionUID = -4335419476073457119L;
42
43 private XMLHammer parent = null;
44
45 /***
46 * The constructor for the action which allows for pasting content.
47 *
48 * @param parent the XML Parent
49 */
50 public PasteAction( XMLHammer parent) {
51 super( "Paste");
52
53 this.parent = parent;
54
55 putValue( MNEMONIC_KEY, new Integer( 'P'));
56 putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
57 putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/etool16/paste_edit.gif")));
58 putValue( SHORT_DESCRIPTION, "Paste");
59
60 setEnabled( false);
61 }
62
63 /***
64 * The implementation of the paste action, called after a user action.
65 */
66 public void run() {
67 JComponent component = parent.getLastSelectedComponent();
68
69 if ( component instanceof JTextComponent) {
70 ((JTextComponent)component).paste();
71 }
72 }
73 }