1 19 package org.openide.filesystems; 20 21 import java.util.List ; 22 import org.openide.util.Exceptions; 23 24 25 29 class FCLSupport { 30 enum Op {DATA_CREATED, FOLDER_CREATED, FILE_CHANGED, FILE_DELETED, FILE_RENAMED, ATTR_CHANGED} 31 32 33 ListenerList<FileChangeListener> listeners; 34 35 38 synchronized final void addFileChangeListener(FileChangeListener fcl) { 39 if (listeners == null) { 40 listeners = new ListenerList<FileChangeListener>(); 41 } 42 43 listeners.add(fcl); 44 } 45 46 49 synchronized final void removeFileChangeListener(FileChangeListener fcl) { 50 if (listeners != null) { 51 listeners.remove(fcl); 52 } 53 } 54 55 final void dispatchEvent(FileEvent fe, Op operation) { 56 List <FileChangeListener> fcls; 57 58 synchronized (this) { 59 if (listeners == null) { 60 return; 61 } 62 63 fcls = listeners.getAllListeners(); 64 } 65 66 for (FileChangeListener l : fcls) { 67 dispatchEvent(l, fe, operation); 68 } 69 } 70 71 final static void dispatchEvent(FileChangeListener fcl, FileEvent fe, Op operation) { 72 try { 73 switch (operation) { 74 case DATA_CREATED: 75 fcl.fileDataCreated(fe); 76 break; 77 case FOLDER_CREATED: 78 fcl.fileFolderCreated(fe); 79 break; 80 case FILE_CHANGED: 81 fcl.fileChanged(fe); 82 break; 83 case FILE_DELETED: 84 fcl.fileDeleted(fe); 85 break; 86 case FILE_RENAMED: 87 fcl.fileRenamed((FileRenameEvent) fe); 88 break; 89 case ATTR_CHANGED: 90 fcl.fileAttributeChanged((FileAttributeEvent) fe); 91 break; 92 default: 93 throw new AssertionError (operation); 94 } 95 } catch (RuntimeException x) { 96 Exceptions.printStackTrace(x); 97 } 98 } 99 100 102 synchronized final boolean hasListeners() { 103 return listeners != null && listeners.hasListeners(); 104 } 105 } 106 | Popular Tags |