KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > providers > AnnotationProvider


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.masterfs.providers;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.masterfs.MasterFileSystem;
24
25 /** Can provide status and actions for FileObjects. Register it
26  * in META-INF/services/org.netbeans.modules.masterfs.providers.AnnotationProvider
27  * file.
28  *
29  * @author Jaroslav Tulach
30  */

31 public abstract class AnnotationProvider extends Object JavaDoc {
32     /** listeners */
33     private org.openide.filesystems.FileStatusListener listener;
34     /** lock for modification of listeners */
35     private static Object JavaDoc LOCK = new Object JavaDoc ();
36     
37     
38     /** Annotate the name of a file cluster.
39     * @param name the name suggested by default
40     * @param files an immutable set of {@link FileObject}s belonging to this filesystem
41     * @return the annotated name or null if this provider does not know how to annotate these files
42     */

43     public abstract String JavaDoc annotateName (String JavaDoc name, java.util.Set JavaDoc files);
44
45     /** Annotate the icon of a file cluster.
46      * <p>Please do <em>not</em> modify the original; create a derivative icon image,
47      * using a weak-reference cache if necessary.
48     * @param icon the icon suggested by default
49     * @param iconType an icon type from {@link java.beans.BeanInfo}
50     * @param files an immutable set of {@link FileObject}s belonging to this filesystem
51     * @return the annotated icon or null if some other provider shall anotate the icon
52     */

53     public abstract java.awt.Image JavaDoc annotateIcon (java.awt.Image JavaDoc icon, int iconType, java.util.Set JavaDoc files);
54     
55     /** Annotate a name such that the returned value contains HTML markup.
56      * The return value less the html content should typically be the same
57      * as the return value from <code>annotateName()</code>. This is used,
58      * for example, by VCS filesystems to de&euml;phasize the status information
59      * included in the file name by using a light grey font color.
60      * <p>
61      * For consistency with <code>Node.getHtmlDisplayName()</code>,
62      * filesystems that proxy other filesystems (and so must implement
63      * this interface to supply HTML annotations) should return null if
64      * the filesystem they proxy does not provide an implementation of
65      * HTMLStatus.
66      *
67      * @see org.openide.awt.HtmlRenderer
68      * @see <a HREF="@org-openide-loaders@/org/openide/loaders/DataNode.html#getHtmlDisplayName()"><code>DataNode.getHtmlDisplayName()</code></a>
69      * @see org.openide.nodes.Node#getHtmlDisplayName
70      **/

71     public abstract String JavaDoc annotateNameHtml (String JavaDoc name, java.util.Set JavaDoc files);
72
73     /** Provides actions that should be added to given set of files.
74      * @return null or array of actions for these files.
75      */

76     public abstract javax.swing.Action JavaDoc[] actions (java.util.Set JavaDoc files);
77     
78     //
79
// Listener support
80
//
81

82
83     /** Registers FileStatusListener to receive events.
84     * The implementation registers the listener only when getStatus () is
85     * overriden to return a special value.
86     *
87     * @param listener The listener to register.
88     */

89     public final void addFileStatusListener (
90         org.openide.filesystems.FileStatusListener listener
91     ) throws java.util.TooManyListenersException JavaDoc {
92         synchronized (LOCK) {
93             if (this.listener != null) {
94                 throw new java.util.TooManyListenersException JavaDoc ();
95             }
96             this.listener = listener;
97         }
98     }
99
100     /** Removes FileStatusListener from the list of listeners.
101      *@param listener The listener to remove.
102      */

103     public final void removeFileStatusListener (
104         org.openide.filesystems.FileStatusListener listener
105     ) {
106         synchronized (LOCK) {
107             if (this.listener == listener) {
108                 this.listener = null;
109             }
110         }
111     }
112
113     /** Notifies all registered listeners about change of status of some files.
114     *
115     * @param event The event to be fired
116     */

117     protected final void fireFileStatusChanged(org.openide.filesystems.FileStatusEvent event) {
118         org.openide.filesystems.FileStatusListener l;
119         synchronized (LOCK) {
120             l = this.listener;
121         }
122         if (l != null) {
123             /* FileUtil.toFileObject(file) may return instance of FileObject from
124              * SystemFileSystem (e.g. for locking files)
125              */

126             if (event.getSource() instanceof MasterFileSystem) {
127                 l.annotationChanged (event);
128             }
129         }
130     }
131     
132     public abstract InterceptionListener getInterceptionListener();
133 }
134
Popular Tags