001: package org.swingml;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005: import java.util.*;
006: import java.util.List;
007:
008: import org.swingml.model.*;
009: import org.swingml.registry.*;
010:
011: /**
012: * @author CrossLogic
013: */
014: public abstract class AbstractSwingMLModel implements WindowListener {
015:
016: private List children;
017: private Container container;
018: private Long guid = null;
019: private String id;
020: private String layout;
021: private List listeners;
022: private String name;
023: private AbstractSwingMLModel parent;
024:
025: public AbstractSwingMLModel() {
026: super ();
027: }
028:
029: public void addChild(Object aChild) {
030: this .getChildren().add(aChild);
031: }
032:
033: public void addListener(Object aListener) {
034: this .getListeners().add(aListener);
035: }
036:
037: public List getChildren() {
038: if (this .children == null) {
039: this .children = new Vector();
040: }
041: return this .children;
042: }
043:
044: public Container getContainer() {
045: return container;
046: }
047:
048: public Long getGuid() {
049: return this .guid;
050: }
051:
052: public String getId() {
053: // trim the id, if it exists
054: return id != null ? id.trim() : null;
055: }
056:
057: public String getLayout() {
058: return this .layout;
059: }
060:
061: public List getListeners() {
062: if (this .listeners == null) {
063: this .listeners = new Vector();
064: }
065: return listeners;
066: }
067:
068: public String getName() {
069: return this .name;
070: }
071:
072: public AbstractSwingMLModel getParent() {
073: return this .parent;
074: }
075:
076: public boolean hasChildren() {
077: return getChildren() != null && getChildren().size() > 0;
078: }
079:
080: public boolean hasListeners() {
081: return getListeners() != null && getListeners().size() > 0;
082: }
083:
084: public boolean hasListenersFor(String event) {
085: boolean result = false;
086: if (hasListeners()) {
087: Iterator schmiterator = getListeners().iterator();
088: while (schmiterator.hasNext()) {
089: ListenerModel listener = (ListenerModel) schmiterator
090: .next();
091: if (listener.getEvent().equals(event)) {
092: result = true;
093: break;
094: }
095: }
096: }
097:
098: return result;
099: }
100:
101: public void removeChild(Object aChild) {
102: if (aChild != null) {
103: this .getChildren().remove(aChild);
104: }
105: }
106:
107: public void setContainer(Container aContainer) {
108: this .container = aContainer;
109: }
110:
111: public void setGuid(Long guid) {
112: this .guid = guid;
113: }
114:
115: public void setId(String id) {
116: this .id = id;
117: }
118:
119: public void setLayout(String aLayout) {
120: this .layout = aLayout;
121: }
122:
123: public void setName(String aName) {
124: this .name = aName;
125: }
126:
127: public void setParent(AbstractSwingMLModel aParent) {
128: this .parent = aParent;
129: }
130:
131: public void unregister(Container aContainer) {
132: SwingMLModelToContainerRegistry.unregister(aContainer);
133: Component[] childComponents = aContainer.getComponents();
134: for (int i = 0; i < childComponents.length; i++) {
135: Component child = childComponents[i];
136: if (child instanceof Container) {
137: unregister((Container) child);
138: }
139: }
140: }
141:
142: abstract void validate();
143:
144: public void windowActivated(WindowEvent e) {
145: }
146:
147: /**
148: * This is called when hitting the X to close a window
149: */
150: public void windowClosed(WindowEvent e) {
151: unregister(this .getContainer());
152: }
153:
154: /**
155: * This is called when programattically closing a window
156: */
157: public void windowClosing(WindowEvent e) {
158: Window window = (Window) this .container;
159: window.dispose();
160: }
161:
162: public void windowDeactivated(WindowEvent e) {
163: }
164:
165: public void windowDeiconified(WindowEvent e) {
166: }
167:
168: public void windowIconified(WindowEvent e) {
169: }
170:
171: public void windowOpened(WindowEvent e) {
172: }
173: }
|