001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2003 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.wrapping;
019:
020: import java.util.*;
021:
022: import net.ar.webonswing.*;
023: import net.ar.webonswing.managers.contributors.*;
024: import net.ar.webonswing.visitor.*;
025:
026: public abstract class AbstractVisualComponent implements
027: VisualComponent {
028: protected String theName;
029: protected ComponentContributor theContributor;
030: protected List theChilds;
031: protected VisualComponent theParent;
032:
033: public AbstractVisualComponent() {
034: theChilds = new Vector();
035: }
036:
037: public void addChild(VisualComponent aChild) {
038: theChilds.add(aChild);
039: aChild.setParent(this );
040: }
041:
042: public void removeChild(VisualComponent aChild) {
043: theChilds.remove(aChild);
044: aChild.setParent(null);
045: }
046:
047: public String getName() {
048: return theName;
049: }
050:
051: public void setName(String string) {
052: theName = string;
053: }
054:
055: public boolean equals(Object obj) {
056: if (obj instanceof VisualComponent) {
057: VisualComponent theOtherComponent = (VisualComponent) obj;
058: return theOtherComponent.getName().equals(getName());
059: } else
060: return false;
061: }
062:
063: public ComponentContributor getContributor() {
064: return theContributor;
065: }
066:
067: public void setContributor(ComponentContributor contributor) {
068: theContributor = contributor;
069: }
070:
071: public List getChilds() {
072: return theChilds;
073: }
074:
075: public int getChildCount() {
076: return theChilds.size();
077: }
078:
079: public void setChilds(List list) {
080: theChilds = list;
081: }
082:
083: public VisualComponent getChildAt(int aPosition) {
084: return (VisualComponent) theChilds.get(aPosition);
085: }
086:
087: public VisualComponent getParent() {
088: return theParent;
089: }
090:
091: public void setParent(VisualComponent id) {
092: theParent = id;
093: }
094:
095: public VisualComponent findComponent(String aComponentName) {
096: return WosFramework.getComponentNameManager()
097: .findComponentWithNameIn(aComponentName, this );
098: }
099:
100: public VisualComponent getTopParent() {
101: VisualComponent theComponent = this ;
102:
103: while (theComponent.getParent() != null)
104: theComponent = theComponent.getParent();
105:
106: return theComponent;
107: }
108:
109: public void accept(Visitor aVisitor) {
110: ComponentVisitor theComponentVisitor = ((ComponentVisitor) aVisitor);
111:
112: theComponentVisitor.visitComponentBegin(this );
113:
114: for (int i = 0; i < theChilds.size(); i++)
115: ((VisualComponent) theChilds.get(i)).accept(aVisitor);
116:
117: theComponentVisitor.visitComponentEnd(this);
118: }
119: }
|