001: /*
002: * Copyright (C) 2007 Jared Alexander Spigner
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 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: * jspigner@openjx.org
019: *
020: * JXObject.java
021: *
022: * Created June 8, 2007, 11:39 PM
023: *
024: */
025:
026: package org.openjx.core;
027:
028: import java.util.HashMap;
029:
030: import java.beans.PropertyChangeEvent;
031: import java.beans.PropertyChangeSupport;
032: import java.beans.PropertyChangeListener;
033:
034: /**
035: * This class represents a JXObject. JXObjects themselves represent an OpenJX
036: * control or GUI element on the stack in the Virtual Machine.
037: *
038: * @author Jared Spigner
039: */
040: public class JXObject extends JXStack {
041: /** This is the objects tag. */
042: private String objectTAG;
043:
044: /** This is the objects name. */
045: private String objectName;
046:
047: private JXObject objectLast;
048:
049: /** This is the object state (true/open) (false/closed). */
050: private boolean objectState;
051:
052: /** This is the object link. */
053: private Object objectLink;
054:
055: /**
056: * This is the PropertyChangeSupport class used to support bound
057: * properties.
058: */
059: private PropertyChangeSupport propertySupporter;
060:
061: /** This is the list of properties for this object. */
062: private HashMap<String, String> propertyList = new HashMap<String, String>();
063:
064: /** This is a reference to the Virtual Machine. */
065: private VirtualMachine virtualMachine;
066:
067: /**
068: * This is the constructor for the JXObject class. It creates a new
069: * instance of JXObject.
070: *
071: * @param vm points to an instance of the VirtualMachine class.
072: * @param tag is the element type of this object.
073: */
074: public JXObject(VirtualMachine vm, String tag) {
075: super ();
076:
077: this .virtualMachine = vm;
078: this .setObjectLink(null);
079: this .setTAG(tag.toLowerCase());
080: this .setLast(null);
081: this .setState(true);
082:
083: propertySupporter = new PropertyChangeSupport(this );
084: }
085:
086: /**
087: * This method pushes a JXObject onto this object's stack and sets the
088: * frame pointer to it.
089: *
090: * @param obj is the JXObject we want to add to the stack.
091: */
092: public void appendNode(JXObject obj) {
093: this .Push(obj);
094: obj.setLast(this );
095: }
096:
097: /**
098: * This method checks if the object has children.
099: *
100: * @return true if the object has children, else false.
101: */
102: public boolean hasNodes() {
103: if (this .getLength() > 0)
104: return true;
105: else
106: return false;
107: }
108:
109: /**
110: * This method returns the last child on this object's stack.
111: *
112: * @return the last child JXObject on this object's stack.
113: */
114: public JXObject getLast() {
115: return this .objectLast;
116: }
117:
118: /**
119: * This method gets this object's name.
120: *
121: * @return the name of the object.
122: */
123: public String getName() {
124: return this .objectName;
125: }
126:
127: /**
128: * This method returns the object link object.
129: *
130: * @return the object link object.
131: */
132: public Object getObjectLink() {
133: return this .objectLink;
134: }
135:
136: /**
137: * This method gets the value of a property.
138: *
139: * @param property is the name of the property.
140: *
141: * @return the value of the proprty.
142: */
143: public String getProperty(String property) {
144: return this .propertyList.get(property);
145: }
146:
147: /**
148: * This method gets the property list hash map.
149: *
150: * @return the property list hash map.
151: */
152: public HashMap<String, String> getPropertyList() {
153: return this .propertyList;
154: }
155:
156: /**
157: * This method gets this object's stack state (true/open,false/closed).
158: *
159: * @return the state of the object.
160: */
161: public boolean getState() {
162: return this .objectState;
163: }
164:
165: /**
166: * This method gets this object's TAG / Type.
167: *
168: * @return this object's tag.
169: */
170: public String getTAG() {
171: return this .objectTAG;
172: }
173:
174: /**
175: * This method sets this object's frame pointer to point to the given
176: * object.
177: *
178: * @param last is the object we want to set the frame pointer to.
179: */
180: public void setLast(JXObject last) {
181: this .objectLast = last;
182: }
183:
184: /**
185: * This method sets this object's name.
186: *
187: * @param name is the name of the object.
188: */
189: public void setName(String name) {
190: this .objectName = name;
191: }
192:
193: /**
194: * This method sets the object link object.
195: *
196: * @param obj is the object we want to set the object link to.
197: */
198: public void setObjectLink(Object obj) {
199: this .objectLink = obj;
200: }
201:
202: /**
203: * This method sets the value of a property.
204: *
205: * @param property is the property we want to set.
206: * @param newValue is the value we want to set.
207: */
208: public void setProperty(String property, String newValue) {
209: String oldValue = this .propertyList.get(property);
210:
211: this .propertyList.put(property, newValue);
212:
213: this .propertySupporter.firePropertyChange(property, oldValue,
214: newValue);
215: }
216:
217: /**
218: * This method sets the state of this object (true/open, false/closed).
219: *
220: * @param state is the state of this object.
221: */
222: public void setState(boolean state) {
223: this .objectState = state;
224: }
225:
226: /**
227: * This method sets this object's tag or type.
228: *
229: * @param tag is the tags we want to set.
230: */
231: public void setTAG(String tag) {
232: this .objectTAG = tag;
233: }
234:
235: /**
236: * This is a support method for the property change listener.
237: *
238: * @param listener is the listener we want to add.
239: */
240: public void addPropertyChangeListener(
241: PropertyChangeListener listener) {
242: this .propertySupporter.addPropertyChangeListener(listener);
243: }
244:
245: /**
246: * This is a support method for the property change listener.
247: *
248: * @param listener is the listener we want to remove.
249: */
250: public void removePropertyChangeListener(
251: PropertyChangeListener listener) {
252: this.propertySupporter.removePropertyChangeListener(listener);
253: }
254:
255: }
|