KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > TaskEditorListener


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.core;
21
22 import org.openide.text.Line;
23 import org.openide.text.Annotation;
24 import org.openide.text.Annotatable;
25
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.beans.PropertyChangeEvent JavaDoc;
28
29 /**
30  * Listener which when notified off changes in current task
31  * updates the editor. Registered at the default lookup.
32  *
33  * @todo Create the view lazily so that it isn't shown until I actually
34  * encounter a Task in the user's view
35  *
36  * @author Tor Norbye
37  * @author Petr Kuzel
38  */

39 public final class TaskEditorListener implements TaskViewListener,
40         PropertyChangeListener JavaDoc {
41     /** Annotation showing the current position */
42     transient private Annotation taskMarker = null;
43
44     /** Construct a new TaskEditorListener.
45      */

46     public TaskEditorListener() {
47         deflt = this;
48     }
49
50     private static TaskEditorListener deflt = null;
51
52     static TaskEditorListener getDefault() {
53         return (deflt == null) ? new TaskEditorListener() : deflt;
54     }
55
56     /**
57      * Show the given task. "Showing" means getting the editor to
58      * show the associated file position, and open up an area in the
59      * tasklist view where the details of the task can be fully read.
60      *
61      * @param item task to annotate (subject of <code>item.getLine()</code>)
62      * @param annotation marker to user or <code>null</code> for default one
63      */

64     public void showTask(Task item, Annotation annotation) {
65         hideTask();
66         if (item == null) return;
67
68         Line l = item.getLine();
69         if (l != null) {
70             taskMarker = (annotation != null) ? annotation : new TaskAnnotation(item);
71             taskMarker.attach(l);
72             l.addPropertyChangeListener(this); // detach on line edit
73
TaskListView view = TaskListView.getCurrent();
74
75             // #35917 do not move focus if in sliding mode
76
if (view.getClientProperty("isSliding") == Boolean.TRUE) { // NOi18N
77
l.show(Line.SHOW_SHOW);
78             } else {
79                 l.show(Line.SHOW_GOTO);
80             }
81         }
82
83     }
84
85     /** Called to indicate that a particular task should be hidden.
86      This typically means that the task was deleted so it should
87      no longer have any visual cues. The task referred to is the
88      most recent task passed to showTaskInEditor.
89      */

90     public void hideTask() {
91         if (taskMarker != null) {
92             Annotatable line = taskMarker.getAttachedAnnotatable();
93             line.removePropertyChangeListener(this);
94             taskMarker.detach();
95             taskMarker = null;
96         }
97     }
98
99     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
100         if (Annotatable.PROP_TEXT.equals(evt.getPropertyName())) {
101             hideTask();
102         }
103     }
104
105 }
106
Popular Tags