View Javadoc

1   package org.xmlhammer.gui.output.actions;
2   
3   import java.awt.Toolkit;
4   import java.awt.datatransfer.Clipboard;
5   import java.awt.datatransfer.StringSelection;
6   import java.awt.event.KeyEvent;
7   
8   import javax.swing.ImageIcon;
9   import javax.swing.KeyStroke;
10  
11  import org.bounce.RunnableAction;
12  
13  public class CopyAction extends RunnableAction {
14      private static final long serialVersionUID = -6546100768134624390L;
15  
16      private String text = null;
17  
18      public CopyAction() {
19          super("Copy");
20  
21          putValue(MNEMONIC_KEY, new Integer('C'));
22          putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
23          putValue(SHORT_DESCRIPTION, "Copy");
24          putValue(SMALL_ICON, new ImageIcon(getClass().getResource("/org/xmlhammer/gui/icons/etool16/copy_edit.gif")));
25      }
26      
27      public void setText(String text) {
28          this.text = text;
29      }
30      
31      @Override
32      public void run() {
33          Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
34          clipboard.setContents(new StringSelection(text), null);    
35      }
36  }