/ui/src/com/bluemarsh/jswat/ui/actions/CopyAction.java

http://jswat.googlecode.com/ · Java · 64 lines · 27 code · 6 blank · 31 comment · 2 complexity · 5ad0c1a981033b0bc8ba3d6c35eff404 MD5 · raw file

  1. /*
  2. * The contents of this file are subject to the terms of the Common Development
  3. * and Distribution License (the License). You may not use this file except in
  4. * compliance with the License.
  5. *
  6. * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
  7. * or http://www.netbeans.org/cddl.txt.
  8. *
  9. * When distributing Covered Code, include this CDDL Header Notice in each file
  10. * and include the License file at http://www.netbeans.org/cddl.txt.
  11. * If applicable, add the following below the CDDL Header, with the fields
  12. * enclosed by brackets [] replaced by your own identifying information:
  13. * "Portions Copyrighted [year] [name of copyright owner]"
  14. *
  15. * The Original Software is JSwat. The Initial Developer of the Original
  16. * Software is Nathan L. Fiedler. Portions created by Nathan L. Fiedler
  17. * are Copyright (C) 2006-2009. All Rights Reserved.
  18. *
  19. * Contributor(s): Nathan L. Fiedler.
  20. *
  21. * $Id: CopyAction.java 92 2009-04-12 16:34:06Z nathanfiedler $
  22. */
  23. package com.bluemarsh.jswat.ui.actions;
  24. import java.awt.event.ActionEvent;
  25. import javax.swing.Action;
  26. import javax.swing.KeyStroke;
  27. import javax.swing.text.JTextComponent;
  28. import org.openide.util.Lookup;
  29. import org.openide.util.NbBundle;
  30. /**
  31. * Copies the selected text to the system clipboard.
  32. *
  33. * @author Nathan Fiedler
  34. */
  35. public class CopyAction extends ContextAwareTextAction {
  36. /** silence the compiler warnings */
  37. private static final long serialVersionUID = 1L;
  38. /**
  39. * Creates a new instance of CopyAction.
  40. */
  41. public CopyAction() {
  42. super(NbBundle.getMessage(CopyAction.class, "LBL_CopyAction_Name"));
  43. putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C"));
  44. }
  45. @Override
  46. public void actionPerformed(ActionEvent event) {
  47. JTextComponent target = getText(event);
  48. if (target != null) {
  49. target.copy();
  50. }
  51. }
  52. @Override
  53. public Action createContextAwareInstance(Lookup lookup) {
  54. CopyAction action = new CopyAction();
  55. action.setLookup(lookup);
  56. return action;
  57. }
  58. }