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: * jxpageCTL.java
021: *
022: * Created on June 8, 2007, 12:55 AM
023: *
024: */
025:
026: package org.openjx.jx;
027:
028: import javax.swing.JComponent;
029: import javax.swing.JPanel;
030:
031: import org.openjx.core.JXObject;
032: import org.openjx.core.VirtualMachine;
033:
034: /**
035: * This is the control class for the jxpage otherwise known as the
036: * JPanel.
037: *
038: * @author Jared Spigner
039: */
040: public class jxpageCTL extends JXControl {
041:
042: /**
043: * This is the constructor for the jxpageCTL class. It creates a new
044: * instance of jxpageCTL.
045: *
046: * @param vm points to an instance of the Virtual Machine.
047: */
048: public jxpageCTL(VirtualMachine vm) {
049: super (vm);
050: }
051:
052: /**
053: * This method is called when the compiler wishes to compile the
054: * component into Java code.
055: *
056: * @param jxObject points to the JXObject in the stack we wish to compile
057: * into Java.
058: *
059: * @return true on success, else false on failure.
060: */
061: public boolean Compile(JXObject jxObject) {
062: if (!this .instantiateObject(jxObject, "javax.swing.JPanel",
063: new Class[] {}, new Object[] {}))
064: return false;
065:
066: JPanel jPanel = (JPanel) jxObject.getObjectLink();
067: jPanel.setLayout(null);
068:
069: jxcomponentCTL jxcomponent = new jxcomponentCTL(
070: this .virtualMachine);
071: if (!jxcomponent.Compile(jxObject))
072: return false;
073:
074: for (int i = 0; i < jxObject.getLength(); i++) {
075: JXObject tmpObject = jxObject.getElement(i);
076:
077: if (tmpObject.getTAG() != "jxscript") {
078: ((JPanel) jxObject.getObjectLink())
079: .add((JComponent) tmpObject.getObjectLink());
080: }
081: }
082:
083: this .virtualMachine.getJXCompiler().scriptEngine.put(jPanel
084: .getName(), jPanel);
085:
086: return true;
087: }
088:
089: /**
090: * This method is called when the interpreter wishes to interpret the
091: * component's script into Java code.
092: *
093: * @param jxObject points to the JXObject in the stack we wish to interpret
094: * into Java.
095: *
096: * @return true on success, else false on failure.
097: */
098: public boolean Interpret(JXObject jxObject) {
099: jxcomponentCTL jxcomponent = new jxcomponentCTL(
100: this .virtualMachine);
101: if (!jxcomponent.Interpret(jxObject))
102: return false;
103:
104: String myScript;
105:
106: if (jxObject.getProperty("onResize") != null) {
107: myScript = jxObject.getName() + ".addComponentListener("
108: + "function(event,methodName){"
109: + "if(methodName=='componentResized'){"
110: + jxObject.getProperty("onResize") + "}" + "}"
111: + ");";
112:
113: return this .virtualMachine.getJXInterpreter()
114: .executeScript(myScript);
115: }
116:
117: return true;
118: }
119:
120: }
|