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: * jxmetaCTL.java
021: *
022: * Created on June 10, 2007, 8:49 PM
023: *
024: */
025:
026: package org.openjx.jx;
027:
028: import java.beans.PropertyChangeEvent;
029:
030: import org.openjx.core.JXObject;
031: import org.openjx.core.VirtualMachine;
032:
033: /**
034: * This is the control class for the jxmeta otherwise known as the
035: * JXMeta.
036: * @author Jared Spigner
037: */
038: public class jxmetaCTL extends JXControl {
039:
040: /**
041: * This the constructor for the JXMetaCTL class. It creates a new instance
042: * of jxmetaCTL.
043: *
044: * @param vm points to an instance of the Virtual Machine.
045: */
046: public jxmetaCTL(VirtualMachine vm) {
047: super (vm);
048: }
049:
050: /**
051: * This method is called when the compiler wishes to compile the
052: * component into Java code.
053: *
054: * @param jxObject points to the JXObject in the stack we wish to compile
055: * into Java.
056: *
057: * @return true on success, else false on failure.
058: */
059: public boolean Compile(JXObject jxObject) {
060: if (!this .instantiateObject(jxObject, "org.openjx.jx.JXMeta",
061: new Class[] {}, new Object[] {}))
062: return false;
063:
064: JXMeta jxMeta = (JXMeta) jxObject.getObjectLink();
065:
066: jxMeta.setName(jxObject.getName());
067: jxMeta.setMetaName(jxObject.getProperty("name"));
068: jxMeta.setMetaValue(jxObject.getProperty("value"));
069:
070: final JXObject bindObject = jxObject;
071: final JXMeta bindComponent = jxMeta;
072:
073: /** bind JXObject properties to this JXImage. */
074: jxObject.addPropertyChangeListener(new JXPropertyAdapter() {
075: public void propertyChange(PropertyChangeEvent evt) {
076: if (evt.getPropertyName().equals("value")) {
077: bindComponent.setMetaValue((String) evt
078: .getNewValue());
079: } else if (evt.getPropertyName().equals("name")) {
080: bindComponent.setMetaName((String) evt
081: .getNewValue());
082: }
083: }
084: });
085:
086: /** bind JXImage properties to this JXObject. */
087: jxMeta.addPropertyChangeListener(new JXPropertyAdapter() {
088: public void propertyChange(PropertyChangeEvent evt) {
089: if (evt.getPropertyName().equals("value")) {
090: bindObject.setProperty("value", (String) evt
091: .getNewValue());
092: } else if (evt.getPropertyName().equals("name")) {
093: bindObject.setProperty("name", (String) evt
094: .getNewValue());
095: }
096: }
097: });
098:
099: this .virtualMachine.getJXCompiler().scriptEngine.put(jxMeta
100: .getName(), jxMeta);
101:
102: return true;
103: }
104:
105: /**
106: * This method is called when the interpreter wishes to interpret the
107: * component's script into Java code.
108: *
109: * @param jxObject points to the JXObject in the stack we wish to interpret
110: * into Java.
111: *
112: * @return true on success, else false on failure.
113: */
114: public boolean Interpret(JXObject jxObject) {
115: return true;
116: }
117:
118: }
|