1 19 20 package org.netbeans.modules.tasklist.editor; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.text.BadLocationException ; 24 import javax.swing.text.Caret ; 25 import javax.swing.text.Document ; 26 import javax.swing.text.JTextComponent ; 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 45 public class NewTaskEditorAction extends BaseAction { 46 47 50 public static final String NEW_USER_TASK_ACTION = "new-todo-item"; 52 53 public NewTaskEditorAction() { 54 super(NEW_USER_TASK_ACTION); 55 } 56 57 static final long serialVersionUID = 8870696224845563315L; 58 59 public void actionPerformed(ActionEvent evt, JTextComponent target) { 60 if (target == null) 61 return; 62 63 BaseDocument doc = (BaseDocument) target.getDocument(); 64 Caret caret = target.getCaret(); 65 66 73 74 int line = 0; 75 try { 76 line = Utilities.getLineOffset(doc, caret.getDot()); 77 } catch (BadLocationException e) { 78 target.getToolkit().beep(); 79 return; 80 } 81 82 Line lineObj = NbEditorUtilities.getLine( 83 (Document ) doc, caret.getDot(), false); 84 NewTaskAction.performAction(lineObj); 85 } 86 87 public String getString(String str) { 88 return NbBundle.getMessage(NewTaskEditorAction.class, str); 89 } 90 91 protected Class getShortDescriptionBundleClass() { 92 return NewTaskEditorAction.class; 93 } 94 95 } 96 | Popular Tags |