KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > annotations > UTAnnotation


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.usertasks.annotations;
21
22 import org.openide.text.Annotation;
23 import org.netbeans.modules.tasklist.usertasks.model.UserTask;
24 import org.netbeans.modules.tasklist.usertasks.*;
25
26 /**
27  * Annotation which shows tasks in the editor
28  *
29  * @author tl
30  */

31 public class UTAnnotation extends Annotation {
32     protected UserTask task = null;
33     private boolean highlight = false;
34     private UserTaskView view;
35     private boolean done;
36
37     /**
38      * Construct a new TaskAnnotation which shows both a gutter
39      * icon and a line highlight.
40      */

41     public UTAnnotation(UserTask task) {
42         this(task, true);
43     }
44
45     /**
46      * Construct a new TaskAnnotation.
47      * @param task The task to show the annotation for
48      * @param highlight When true, show a highlight for the task,
49      * not just a gutter icon.
50      */

51     public UTAnnotation(UserTask task, boolean highlight) {
52         this.done = task.isDone();
53         this.task = task;
54         this.highlight = highlight;
55     }
56
57     /**
58      * Constructs annotation that is capable to locate
59      * task in other tasks views (implementing TaskSelector).
60      *
61      * @param task
62      * @param view
63      */

64     public UTAnnotation(UserTask task, UserTaskView view) {
65         this.task = task;
66         this.view = view;
67         highlight = true;
68     }
69
70     /**
71      * Changes the icon depending on the done attribute.
72      *
73      * @param done the task was done
74      */

75     public void setDone(boolean done) {
76         if (this.done != done) {
77             String JavaDoc old = getAnnotationType();
78             this.done = done;
79             firePropertyChange(PROP_ANNOTATION_TYPE, old, getAnnotationType());
80         }
81     }
82     
83     /**
84      * Highlights the task/removes the highlighting.
85      *
86      * @param highlight true = highlight
87      */

88     public void setHighlight(boolean highlight) {
89         if (this.highlight != highlight) {
90             String JavaDoc old = getAnnotationType();
91             this.highlight = highlight;
92             firePropertyChange(PROP_ANNOTATION_TYPE, old, getAnnotationType());
93         }
94     }
95     
96     public String JavaDoc getAnnotationType () {
97         if (!done) {
98             if (!highlight) {
99                 return "org-netbeans-modules-tasklist-usertasks-UTNoHighlight"; // NOI18N
100
} else {
101                 return "org-netbeans-modules-tasklist-usertasks-UT"; // NOI18N
102
}
103         } else {
104             if (!highlight)
105                 return "org-netbeans-modules-tasklist-usertasks-UTDoneNoHighlight"; // NOI18N
106
else
107                 return "org-netbeans-modules-tasklist-usertasks-UTDone"; // NOI18N
108
}
109     }
110     
111     public String JavaDoc getShortDescription () {
112         // Use details summary, if available
113
showTask();
114
115         if (task.getDetails().length() > 0) {
116             return task.getSummary() + "\n\n" + task.getDetails(); // NOI18N
117
} else {
118             return task.getSummary();
119         }
120     }
121
122     /** Show the task for this annotation in its view */
123     protected void showTask() {
124         if (view != null) view.select(task);
125     }
126
127     /** Return the task associated with this annotation */
128     public UserTask getTask() {
129         return task;
130     }
131 }
132
Popular Tags