01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: AbstractConstChangeNotifyMap.java,v 1.14 2005/12/04 13:46:04 jesper Exp $
23: package net.infonode.util.collection.notifymap;
24:
25: import net.infonode.util.ValueChange;
26: import net.infonode.util.collection.map.SingleValueMap;
27: import net.infonode.util.collection.map.base.ConstMap;
28: import net.infonode.util.signal.Signal;
29: import net.infonode.util.signal.SignalHook;
30: import net.infonode.util.signal.SignalListener;
31:
32: abstract public class AbstractConstChangeNotifyMap implements
33: ConstChangeNotifyMap {
34: private Signal changeSignal = new Signal() {
35: protected void firstListenerAdded() {
36: AbstractConstChangeNotifyMap.this .firstListenerAdded();
37: }
38:
39: protected void lastListenerRemoved() {
40: AbstractConstChangeNotifyMap.this .lastListenerRemoved();
41: }
42:
43: protected synchronized void removeListener(int index) {
44: super .removeListener(index);
45: listenerRemoved();
46: }
47:
48: public synchronized void addListener(SignalListener listener) {
49: super .addListener(listener);
50: listenerAdded();
51: }
52: };
53:
54: protected void firstListenerAdded() {
55: }
56:
57: protected void lastListenerRemoved() {
58: }
59:
60: protected void listenerRemoved() {
61: }
62:
63: protected void listenerAdded() {
64: }
65:
66: public SignalHook getChangeSignal() {
67: return changeSignal.getHook();
68: }
69:
70: protected Signal getChangeSignalInternal() {
71: return changeSignal;
72: }
73:
74: protected void fireEntryRemoved(Object key, Object value) {
75: fireEntryChanged(key, value, null);
76: }
77:
78: protected void fireEntryChanged(Object key, Object oldValue,
79: Object newValue) {
80: fireEntriesChanged(new SingleValueMap(key, new ValueChange(
81: oldValue, newValue)));
82: }
83:
84: protected void fireEntriesChanged(ConstMap changes) {
85: if (!changes.isEmpty())
86: changeSignal.emit(changes);
87: }
88:
89: }
|