KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > actions > GoToUserTaskAction


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 package org.netbeans.modules.tasklist.usertasks.actions;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import javax.swing.ImageIcon JavaDoc;
27 import javax.swing.event.ListSelectionEvent JavaDoc;
28 import javax.swing.tree.TreePath JavaDoc;
29 import org.netbeans.modules.tasklist.usertasks.UserTaskTreeTableNode;
30 import org.netbeans.modules.tasklist.usertasks.UserTaskView;
31 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
32 import org.openide.awt.HtmlBrowser;
33 import org.openide.text.Line;
34 import org.openide.util.NbBundle;
35 import org.openide.util.Utilities;
36 import org.openide.util.WeakListeners;
37
38
39 /**
40  * Go to the source code / associated file for a particular
41  * task.
42  *
43  * @author Tor Norbye
44  * @author tl
45  */

46 public class GoToUserTaskAction extends UTViewAction
47         implements PropertyChangeListener JavaDoc {
48     private UserTask last;
49     
50     /**
51      * Constructor.
52      *
53      * @param utv a user task view.
54      */

55     public GoToUserTaskAction(UserTaskView utv) {
56         super(utv, NbBundle.getMessage(GoToUserTaskAction.class,
57                 "LBL_Goto")); // NOI18N
58
putValue(SMALL_ICON, new ImageIcon JavaDoc(Utilities.loadImage(
59                 "org/netbeans/modules/tasklist/usertasks/actions/" + // NOI18N
60
"gotosource.png"))); // NOI18N
61
}
62     
63     public void actionPerformed(ActionEvent JavaDoc e) {
64         UserTask ut = getSingleSelectedTask();
65         if (ut.getLine() != null)
66             ut.getLine().show(Line.SHOW_GOTO);
67         else
68             HtmlBrowser.URLDisplayer.getDefault().showURL(ut.getUrl());
69     }
70
71     public void valueChanged(ListSelectionEvent JavaDoc e) {
72         if (last != null)
73             last.removePropertyChangeListener(this);
74         UserTask ut = getSingleSelectedTask();
75         setEnabled(ut != null &&
76                 (ut.getLine() != null || ut.getUrl() != null));
77         last = ut;
78         if (last != null)
79             last.addPropertyChangeListener(this);
80     }
81
82     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
83         if (evt.getPropertyName() == UserTask.PROP_URL ||
84                 evt.getPropertyName() == UserTask.PROP_LINE_NUMBER ||
85                 evt.getPropertyName() == UserTask.PROP_LINE) {
86             UserTask ut = getSingleSelectedTask();
87             setEnabled(ut != null &&
88                     (ut.getLine() != null || ut.getUrl() != null));
89         }
90     }
91 }
92
Popular Tags