1 18 package org.apache.batik.dom.events; 19 20 import org.apache.batik.dom.util.HashTable; 21 import org.w3c.dom.DOMException ; 22 import org.w3c.dom.events.Event ; 23 24 30 public class DocumentEventSupport { 31 32 35 public static final String EVENT_TYPE = "Events"; 36 37 40 public static final String MUTATION_EVENT_TYPE = "MutationEvents"; 41 42 45 public static final String MOUSE_EVENT_TYPE = "MouseEvents"; 46 47 50 public static final String UI_EVENT_TYPE = "UIEvents"; 51 52 55 public static final String KEY_EVENT_TYPE = "KeyEvents"; 56 57 60 protected HashTable eventFactories = new HashTable(); 61 { 62 eventFactories.put(EVENT_TYPE.toLowerCase(), 63 new SimpleEventFactory()); 64 eventFactories.put(MUTATION_EVENT_TYPE.toLowerCase(), 65 new MutationEventFactory()); 66 eventFactories.put(MOUSE_EVENT_TYPE.toLowerCase(), 67 new MouseEventFactory()); 68 eventFactories.put(KEY_EVENT_TYPE.toLowerCase(), 69 new KeyEventFactory()); 70 eventFactories.put(UI_EVENT_TYPE.toLowerCase(), 71 new UIEventFactory()); 72 } 73 74 103 public Event createEvent(String eventType) 104 throws DOMException { 105 EventFactory ef = (EventFactory)eventFactories.get(eventType.toLowerCase()); 106 if (ef == null) { 107 throw new DOMException (DOMException.NOT_SUPPORTED_ERR, 108 "Bad event type: " + eventType); 109 } 110 return ef.createEvent(); 111 } 112 113 116 public void registerEventFactory(String eventType, 117 EventFactory factory) { 118 eventFactories.put(eventType.toLowerCase(), factory); 119 } 120 121 122 125 public interface EventFactory { 126 129 Event createEvent(); 130 } 131 132 135 protected static class SimpleEventFactory implements EventFactory { 136 139 public Event createEvent() { 140 return new DOMEvent(); 141 } 142 } 143 144 147 protected static class MutationEventFactory implements EventFactory { 148 151 public Event createEvent() { 152 return new DOMMutationEvent(); 153 } 154 } 155 156 159 protected static class MouseEventFactory implements EventFactory { 160 163 public Event createEvent() { 164 return new DOMMouseEvent(); 165 } 166 } 167 168 171 protected static class KeyEventFactory implements EventFactory { 172 175 public Event createEvent() { 176 return new DOMKeyEvent(); 177 } 178 } 179 180 183 protected static class UIEventFactory implements EventFactory { 184 187 public Event createEvent() { 188 return new DOMUIEvent(); 189 } 190 } 191 } 192 | Popular Tags |