01: /*
02: * Copyright 2005 jWic Group (http://www.jwic.de)
03: * $Id: SelectableControl.java,v 1.2 2006/08/09 14:52:40 lordsam Exp $
04: */
05: package de.jwic.controls;
06:
07: import java.util.ArrayList;
08: import java.util.Iterator;
09: import java.util.List;
10:
11: import de.jwic.base.IControlContainer;
12: import de.jwic.events.SelectionEvent;
13: import de.jwic.events.SelectionListener;
14:
15: /**
16: * Implements event handling for controls that can be selected.
17: * @version $Revision: 1.2 $
18: * @author Florian Lippisch
19: */
20: public abstract class SelectableControl extends HTMLElement {
21:
22: private List selectedListeners = null;
23:
24: /**
25: * @param container
26: */
27: public SelectableControl(IControlContainer container) {
28: super (container, null);
29: }
30:
31: /**
32: * @param container
33: * @param name
34: */
35: public SelectableControl(IControlContainer container, String name) {
36: super (container, name);
37: }
38:
39: /**
40: * Register a listener that will be notified when the anchor will be clicked.
41: * @param listener
42: */
43: public void addSelectionListener(SelectionListener listener) {
44: if (selectedListeners == null) {
45: selectedListeners = new ArrayList();
46: }
47: selectedListeners.add(listener);
48: }
49:
50: /**
51: * Called when the button was clicked by the user. If there are SelectionListeners
52: * registerd they are notified.
53: */
54: public void click() {
55: // notify the listeners
56: if (selectedListeners != null) {
57: SelectionEvent se = new SelectionEvent(this );
58: for (Iterator it = selectedListeners.iterator(); it
59: .hasNext();) {
60: SelectionListener osl = (SelectionListener) it.next();
61: osl.objectSelected(se);
62: }
63: }
64:
65: }
66:
67: }
|