01: package net.sf.memoranda;
02:
03: import java.util.Collection;
04: import java.util.Vector;
05:
06: public class CurrentNote {
07:
08: private static Note currentNote = null;
09: private static Vector noteListeners = new Vector();
10:
11: public static Note get() {
12: return currentNote;
13: }
14:
15: public static void set(Note note, boolean toSaveCurrentNote) {
16: noteChanged(note, toSaveCurrentNote);
17: currentNote = note;
18: }
19:
20: public static void reset() {
21: // set toSave to true to mimic status quo behaviour only. the appropriate setting could be false
22: set(null, true);
23: }
24:
25: public static void addNoteListener(NoteListener nl) {
26: noteListeners.add(nl);
27: }
28:
29: public static Collection getChangeListeners() {
30: return noteListeners;
31: }
32:
33: private static void noteChanged(Note note, boolean toSaveCurrentNote) {
34: for (int i = 0; i < noteListeners.size(); i++) {
35: ((NoteListener) noteListeners.get(i)).noteChange(note,
36: toSaveCurrentNote);
37: }
38: }
39: }
|