KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > filesystems > FileStatusEvent


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.openide.filesystems;
20
21 import java.util.EventObject JavaDoc;
22
23
24 /** Event describing a change in annotation of files.
25 *
26 * @author Jaroslav Tulach
27 */

28 public final class FileStatusEvent extends EventObject JavaDoc {
29     static final long serialVersionUID = -6428208118782405291L;
30
31     /** changed files */
32     private java.util.Set JavaDoc files;
33
34     /** icon changed? */
35     private boolean icon;
36
37     /** name changed? */
38     private boolean name;
39
40     /** Creates new FileStatusEvent
41     * @param fs filesystem that causes the event
42     * @param files set of FileObjects that has been changed
43     * @param icon has icon changed?
44     * @param name has name changed?
45     */

46     public FileStatusEvent(FileSystem fs, java.util.Set JavaDoc files, boolean icon, boolean name) {
47         super(fs);
48         this.files = files;
49         this.icon = icon;
50         this.name = name;
51     }
52
53     /** Creates new FileStatusEvent
54     * @param fs filesystem that causes the event
55     * @param file file object that has been changed
56     * @param icon has icon changed?
57     * @param name has name changed?
58     */

59     public FileStatusEvent(FileSystem fs, FileObject file, boolean icon, boolean name) {
60         this(fs, java.util.Collections.singleton(file), icon, name);
61     }
62
63     /** Creates new FileStatusEvent. This does not specify the
64     * file that changed annotation, assuming that everyone should update
65     * its annotation. Please notice that this can be time consuming
66     * and should be fired only when really necessary.
67     *
68     * @param fs filesystem that causes the event
69     * @param icon has icon changed?
70     * @param name has name changed?
71     */

72     public FileStatusEvent(FileSystem fs, boolean icon, boolean name) {
73         this(fs, (java.util.Set JavaDoc) null, icon, name);
74     }
75
76     /** Getter for filesystem that caused the change.
77     * @return filesystem
78     */

79     public FileSystem getFileSystem() {
80         return (FileSystem) getSource();
81     }
82
83     /** Is the change change of name?
84     */

85     public boolean isNameChange() {
86         return name;
87     }
88
89     /** Do the files changed their icons?
90     */

91     public boolean isIconChange() {
92         return icon;
93     }
94
95     /** Check whether the given file has been changed.
96     * @param file file to check
97     * @return true if the file has been affected by the change
98     */

99     public boolean hasChanged(FileObject file) {
100         if (files == null) {
101             // all files on source filesystem are said to change
102
try {
103                 return file.getFileSystem() == getSource();
104             } catch (FileStateInvalidException ex) {
105                 // invalid files should not be changed
106
return false;
107             }
108         } else {
109             // specified set of files, so check it
110
return files.contains(file);
111         }
112     }
113 }
114
Popular Tags