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 cut content.
36 *
37 * @version $Revision: 1.8 $, $Date: 2007/07/04 19:42:49 $
38 * @author Edwin Dankert <edankert@gmail.com>
39 */
40 public class CutAction extends RunnableAction {
41 private static final long serialVersionUID = 939638802470121637L;
42
43 private XMLHammer parent = null;
44
45 /***
46 * The constructor for the action which allows cutting content.
47 *
48 * @param parent the XML Hammer
49 */
50 public CutAction( XMLHammer parent) {
51 super( "Cut");
52
53 this.parent = parent;
54
55 putValue( MNEMONIC_KEY, new Integer( 't'));
56 putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
57 putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/etool16/cut_edit.gif")));
58 putValue( SHORT_DESCRIPTION, "Cut");
59
60 setEnabled( false);
61 }
62
63 /***
64 * The implementation of the cut action, called
65 * after a user action.
66 */
67 public void run() {
68 JComponent component = parent.getLastSelectedComponent();
69
70 if ( component instanceof JTextComponent) {
71 ((JTextComponent)component).cut();
72 }
73 }
74 }