KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > editor > NewTaskEditorAction


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 NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.editor;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.text.BadLocationException JavaDoc;
24 import javax.swing.text.Caret JavaDoc;
25 import javax.swing.text.Document JavaDoc;
26 import javax.swing.text.JTextComponent JavaDoc;
27
28 import org.netbeans.editor.BaseAction;
29 import org.netbeans.editor.BaseDocument;
30 import org.netbeans.editor.Utilities;
31 import org.netbeans.modules.editor.NbEditorUtilities;
32 import org.netbeans.modules.tasklist.usertasks.actions.NewTaskAction;
33 import org.openide.text.Line;
34 import org.openide.util.NbBundle;
35
36
37
38 /**
39  * Editor action, quite equivalent to NewTaskAction,
40  * but plugs into the editor architecture such that it
41  * can be embedded in the editor magin popup menu.
42  *
43  * @author Tor Norbye
44  */

45 public class NewTaskEditorAction extends BaseAction {
46
47     /**
48      * Add a new task tied ot the current line
49      */

50     public static final String JavaDoc NEW_USER_TASK_ACTION = "new-todo-item"; // NOI18N
51

52
53     public NewTaskEditorAction() {
54         super(NEW_USER_TASK_ACTION);
55     }
56
57     static final long serialVersionUID = 8870696224845563315L;
58
59     public void actionPerformed(ActionEvent JavaDoc evt, JTextComponent JavaDoc target) {
60         if (target == null)
61             return;
62
63         BaseDocument doc = (BaseDocument) target.getDocument();
64         Caret JavaDoc caret = target.getCaret();
65
66         /*
67         // check whether the glyph gutter is visible or not
68         if (Utilities.getEditorUI(target) == null || !Utilities.getEditorUI(target).isGlyphGutterVisible()) {
69             target.getToolkit().beep();
70             return;
71         }
72         */

73
74         int line = 0;
75         try {
76             line = Utilities.getLineOffset(doc, caret.getDot());
77         } catch (BadLocationException JavaDoc e) {
78             target.getToolkit().beep();
79             return;
80         }
81
82         Line lineObj = NbEditorUtilities.getLine(
83                 (Document JavaDoc) doc, caret.getDot(), false);
84         NewTaskAction.performAction(lineObj);
85     }
86
87     public String JavaDoc getString(String JavaDoc str) {
88         return NbBundle.getMessage(NewTaskEditorAction.class, str);
89     }
90
91     protected Class JavaDoc getShortDescriptionBundleClass() {
92         return NewTaskEditorAction.class;
93     }
94
95 }
96
Popular Tags