PageRenderTime 26ms CodeModel.GetById 23ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): MPL-2.0-no-copyleft-exception
 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
24package com.bluemarsh.jswat.ui.actions;
25
26import java.awt.event.ActionEvent;
27import javax.swing.Action;
28import javax.swing.KeyStroke;
29import javax.swing.text.JTextComponent;
30import org.openide.util.Lookup;
31import org.openide.util.NbBundle;
32
33/**
34 * Copies the selected text to the system clipboard.
35 *
36 * @author Nathan Fiedler
37 */
38public class CopyAction extends ContextAwareTextAction {
39    /** silence the compiler warnings */
40    private static final long serialVersionUID = 1L;
41
42    /**
43     * Creates a new instance of CopyAction.
44     */
45    public CopyAction() {
46        super(NbBundle.getMessage(CopyAction.class, "LBL_CopyAction_Name"));
47        putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C"));
48    }
49
50    @Override
51    public void actionPerformed(ActionEvent event) {
52        JTextComponent target = getText(event);
53        if (target != null) {
54            target.copy();
55        }
56    }
57
58    @Override
59    public Action createContextAwareInstance(Lookup lookup) {
60        CopyAction action = new CopyAction();
61        action.setLookup(lookup);
62        return action;
63    }
64}