01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.uiimpl;
14:
15: import java.util.Vector;
16: import java.util.EventObject;
17:
18: import com.ibm.richtext.uiimpl.resources.MenuData;
19:
20: public abstract class MItem {
21:
22: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
23: private Vector fListeners = new Vector(2);
24: private EventObject fEvent = new EventObject(this );
25:
26: public abstract void setEnabled(boolean enabled);
27:
28: public abstract void setState(boolean checked);
29:
30: public final void addListener(EventListener listener) {
31:
32: fListeners.addElement(listener);
33: }
34:
35: public final void removeListener(EventListener listener) {
36:
37: fListeners.removeElement(listener);
38: }
39:
40: protected void handleSelected() {
41:
42: int length = fListeners.size();
43: for (int i = 0; i < length; i++) {
44: EventListener l = (EventListener) fListeners.elementAt(i);
45: l.eventOccurred(fEvent);
46: }
47: }
48:
49: // factory stuff
50:
51: /**
52: * Clients should synchronize on LOCK while setting and using
53: * global factory.
54: */
55: public static final Object LOCK = new Object();
56:
57: public static interface ItemFactory {
58:
59: public MItem createItem(MenuData menuData);
60:
61: public MItem createCheckboxItem(MenuData menuData);
62:
63: public void createSeparator();
64: }
65:
66: private static ItemFactory fgFactory;
67:
68: public static MItem createItem(MenuData menuData) {
69:
70: return fgFactory.createItem(menuData);
71: }
72:
73: public static MItem createCheckboxItem(MenuData menuData) {
74:
75: return fgFactory.createCheckboxItem(menuData);
76: }
77:
78: public static void setItemFactory(ItemFactory factory) {
79:
80: fgFactory = factory;
81: }
82:
83: public static ItemFactory getItemFactory() {
84:
85: return fgFactory;
86: }
87: }
|