/*
* XML11 --- An Abstract Windowing Protocol
* Copyright (c) 2004-2005 by The XML11 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information, visit the XML11 Home Page at
* http://www.xml11.org/
*/
/******************************************************************************/
/* AWT Classes */
/******************************************************************************/
var zindex=0;
function java_awt_TextField(id)
{
this._id = id;
this.getText = function()
{
var t = CommonWidgetPeer.getPeer(this._id).getText();
return (new java_lang_String).__init_java_lang_String(t);
}
this.setText = function(l)
{
CommonWidgetPeer.getPeer(this._id).setText(l._str);
}
}
function java_awt_Label(id)
{
this._id = id;
this.setText = function(l)
{
CommonWidgetPeer.getPeer(this._id).setText(l._str);
}
}
function java_awt_Frame(id)
{
this._id = id;
}
function java_awt_Panel(id)
{
this._id = id;
this.__init_java_awt_Panel = function()
{
}
}
function java_awt_Button(id)
{
this._id = id;
this.getText = function()
{
var t = CommonWidgetPeer.getPeer(this._id).getText();
return (new java_lang_String).__init_java_lang_String(t);
}
}
function java_awt_TextArea(id)
{
this._id = id;
this.append = function(l)
{
CommonWidgetPeer.getPeer(this._id).append(l._str);
}
this.setText = function(l)
{
CommonWidgetPeer.getPeer(this._id).setText(l._str);
}
}
function java_awt_List(id)
{
this._id = id;
this.getSelectedItem = function()
{
var item = CommonWidgetPeer.getPeer(this._id).getSelectedItem();
return (new java_lang_String).__init_java_lang_String(item);
}
}
function java_awt_event_ActionEvent()
{
this.id = null;
this.source = null;
this.setID = function(id_)
{
this.id = id_;
this.source = targetMap[id_];
}
this.getSource = function()
{
return this.source;
}
this.getActionCommand = function()
{
var cmd = CommonWidgetPeer.getPeer(this.id).getText();
return (new java_lang_String).__init_java_lang_String(cmd);
}
}
/******************************************************************************/
/* AWT Peer Classes */
/******************************************************************************/
var xml11_root = null;
function getXML11Root()
{
if (xml11_root == null)
xml11_root = document.getElementById("XML11_ROOT");
return xml11_root;
}
// The following function looks for the XML11_ROOT element
// and determines its X-position
function rootXML11PosX()
{
var obj = getXML11Root();
var curleft = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
// The following function looks for the XML11_ROOT element
// and determines its Y-position
function rootXML11PosY()
{
var obj = getXML11Root();
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
/*-----CommonWidgetPeer---------------------------------------------*/
// Maps id to an instance of java_awt_Component
var targetMap = new Object();
// Global property list. For some reason it doesn't work to give
// each widget its own property list
var properties = new Object();
//Maps the widget type to the according class name
var peerTypeClassMap = new Array();
//standard widget mappings
peerTypeClassMap["window"] = "WindowPeer";
peerTypeClassMap["panel"] = "PanelPeer";
peerTypeClassMap["button"] = "ButtonPeer";
peerTypeClassMap["textbox"] = "TextboxPeer";
peerTypeClassMap["label"] = "LabelPeer";
peerTypeClassMap["textarea"] = "TextAreaPeer";
peerTypeClassMap["list"] = "ListPeer";
function CommonWidgetPeer()
{
this.node = null;
this.id = "ELEM_NULL";
this.pid = "ELEM_NULL";
this.xml11Root = null;
this.keyPressedEvents = false;
this.keyReleasedEvents = false;
this.mousePressedEvents = false;
this.mouseReleasedEvents = false;
this.mouseEnteredEvents = false;
this.mouseExitedEvents = false;
this.mouseMovedEvents = false;
this.actionPerformedEvents = false;
this.itemStateChangedEvents = false;
this.setItemStateChangedEvents = function(flag)
{
this.itemStateChangedEvents = flag;
}
this.setActionPerformedEvents = function(flag)
{
this.actionPerformedEvents = flag;
}
this.setKeyPressedEvents = function(flag)
{
this.keyPressedEvents = flag;
}
this.setKeyReleasedEvents = function(flag)
{
this.keyReleasedEvents = flag;
}
this.setMousePressedEvents = function(flag)
{
this.mousePressedEvents = flag;
}
this.setMouseReleasedEvents = function(flag)
{
this.mouseReleasedEvents = flag;
}
this.setMouseEnteredEvents = function(flag)
{
this.mouseEnteredEvents = flag;
}
this.setMouseExitedEvents = function(flag)
{
this.mouseExitedEvents = flag;
}
this.setMouseMovedEvents = function(flag)
{
this.mouseMovedEvents = flag;
}
this.setIDs = function(id_, pid_)
{
this.id = id_;
this.pid = pid_;
}
this.setNode = function(node_)
{
this.node = node_;
}
this.getNode = function()
{
return this.node;
}
this.setProperty = function(name, value)
{
properties[this.id + "." + name] = value;
}
this.getProperty = function(name)
{
return properties[this.id + "." + name];
}
this.getXML11Root = function()
{
if (this.xml11Root == null)
this.xml11Root = document.getElementById("XML11_ROOT");
return this.xml11Root;
}
this.getHTMLtag = function()
{
alert("getHTMLtag: abstract method");
return "";
}
this.getStyle = function()
{
var style = "position: absolute;";
return style;
}
this.setActionListeners = function()
{
//var node = document.getElementById(this.id);
if (this.mousePressedEvents)
this.node.onmousedown = do_onmousedown;
if (this.mouseReleasedEvents)
this.node.onmouseup = do_onmouseup;
if (this.mouseEnteredEvents)
this.node.onmouseover = do_onmouseover;
if (this.mouseExitedEvents)
this.node.onmouseout = do_onmouseout;
if (this.mouseMovedEvents)
this.node.onmousemove = do_onmousemove;
if (this.keyPressedEvents)
this.node.onkeypress = do_onkeydown;
if (this.keyReleasedEvents)
this.node.onkeyup = do_onkeyup;
if (this.itemStateChangedEvents){
this.node.onchange = do_on_itemStateChanged;
}
}
this.getHTML = function()
{
var html = "<";
html += this.getHTMLtag();
html += ' id="' + this.id + '"';
html += ' style="' + this.getStyle() + '"';
html += '/>';
return html;
}
this.create = function()
{
var html = this.getHTML();
if (this.node == null) {
// We have never rendered this widget. Show it for the first time
var new_node = document.createElement("div");
if (this.id == this.pid) {
// Peer has no parent. Create it on the top-level
var root = getXML11Root();
root.appendChild(new_node);
//document.body.appendChild(new_node);
} else {
var parent_node = document.getElementById(this.pid);
parent_node.appendChild(new_node);
}
this.setNode(new_node);
new_node.innerHTML = html;
this.node = document.getElementById (this.id);
this.setActionListeners();
} else {
}
}
this.setVisible = function(flag)
{
if (this.node == null)
return;
if (!flag)
this.node.style.visibility= 'hidden';
else
this.node.style.visibility = 'visible';
}
this.dispose = function()
{
var n = this.node;
var parent = n.parentNode;
parent.removeChild(n);
XMLOB.unregisterObject(this.id);
}
this.setBounds = function(msg)
{
if(msg.left)
this.node.style.left = msg.left + "px";
if(msg.top)
this.node.style.top = msg.top + "px";
if(msg.width)
this.node.style.width = msg.width + "px";
if(msg.height)
this.node.style.height = msg.height + "px";
}
CommonWidgetPeer.getPeer = function(id)
{
return XMLOB.getObject(id);
}
CommonWidgetPeer.getParentPeer = function(peer)
{
if (peer.id == peer.pid) return null;
return XMLOB.getObject(peer.pid);
}
CommonWidgetPeer.createPeer = function(type, id, pid)
{
var peer = null;
//Dynamic mapping of widget type and the according classname to instantiate
if(peerTypeClassMap[type] != null)
{
eval("peer = new " + peerTypeClassMap[type] + "();");
}
else
{
alert("createPeer unknown type: " + type);
return null;
}
peer.setIDs(id, pid);
XMLOB.registerObject(id, peer);
return peer;
}
}
CommonWidgetPeer();
/*-----WindowPeer---------------------------------------------------*/
function WindowPeer()
{
this.getHTMLtag = function()
{
return "div";
}
}
WindowPeer();
WindowPeer.prototype = new CommonWidgetPeer;
/*-----PanelPeer---------------------------------------------------*/
// We need some sort of UUID to create unique URLs when loading
// images.
var uuid = 0;
function PanelPeer()
{
this.col = 0;
this.getHTMLtag = function()
{
return "div";
}
this.getHTML = function()
{
var html = "
';
return html;
}
this.addImage = function()
{
//col = (col + 1)%10;
//this.node.style.backgroundColor = "#"+col+""+col+""+col+""+col+""+col+""+col;
var img_id = "IMG_" + this.id;
var img_node = document.getElementById(img_id);
if (img_node == null) {
// we have never rendered this image
img_node = document.createElement("div");
// --> no effect this.node.style.position = "absolute";
//img_node.style.position = "absolute";
//img_node.style.zIndex = zindex++;
var html = '';
img_node.innerHTML = html;
this.node.appendChild(img_node);
} else {
img_node.src = "/image/" + this.id + '?' + SessionManager.sessionID + '-' + uuid++;
}
// Set the image-property to null to avoid re-loading with the
// next update
this.setProperty("image", null);
}
this.setActionListeners = function()
{
//TODO: Super call possible?
if (this.mousePressedEvents)
this.node.onmousedown = do_onmousedown;
if (this.mouseReleasedEvents)
this.node.onmouseup = do_onmouseup;
if (this.mouseEnteredEvents)
this.node.onmouseover = do_onmouseover;
if (this.mouseExitedEvents)
this.node.onmouseout = do_onmouseout;
if (this.mouseMovedEvents)
this.node.onmousemove = do_onmousemove;
if (this.keyPressedEvents)
this.node.onkeypress = do_onkeydown;
if (this.keyReleasedEvents)
this.node.onkeyup = do_onkeyup;
if (this.actionPerformedEvents)
this.node.onkeyup = do_on_textfield_actionperformed;
}
}
PanelPeer();
PanelPeer.prototype = new CommonWidgetPeer;
/*-----ButtonPeer---------------------------------------------------*/
function ButtonPeer()
{
this.getHTMLtag = function()
{
return "button";
}
this.getHTML = function()
{
var label = this.getProperty("label");
var html = "<";
html += this.getHTMLtag();
html += ' id="' + this.id + '"';
html += ' onclick="do_oncommand(\'' + this.id + "')\"";
html += ' style="' + this.getStyle() + '"';
html += '>';
if (label != null)
html += label;
html += ""+this.getHTMLtag()+">";
return html;
}
this.getText = function()
{
return this.getProperty("label");
}
this.setLabel = function(msg)
{
this.node.innerHTML = msg.label;
this.setProperty("label", msg.label);
}
}
ButtonPeer();
ButtonPeer.prototype = new CommonWidgetPeer;
/*-----TextboxPeer---------------------------------------------------*/
function TextboxPeer()
{
this.getText = function()
{
return this.node.value;
}
this.action_setText = function(msg)
{
this.setText(msg.text);
}
this.setText = function(txt)
{
this.node.value = txt;
}
this.getHTMLtag = function()
{
return "input";
}
this.setActionListeners = function()
{
//TODO: Super call possible?
if (this.mousePressedEvents)
this.node.onmousedown = do_onmousedown;
if (this.mouseReleasedEvents)
this.node.onmouseup = do_onmouseup;
if (this.mouseEnteredEvents)
this.node.onmouseover = do_onmouseover;
if (this.mouseExitedEvents)
this.node.onmouseout = do_onmouseout;
if (this.mouseMovedEvents)
this.node.onmousemove = do_onmousemove;
if (this.keyPressedEvents)
this.node.onkeypress = do_onkeydown;
if (this.keyReleasedEvents)
this.node.onkeyup = do_onkeyup;
if (this.actionPerformedEvents)
this.node.onkeyup = do_on_textfield_actionperformed;
}
this.getHTML = function()
{
var text = this.getProperty("label");
var html = "<";
html += this.getHTMLtag();
html += ' id="' + this.id + '"';
html += ' style="' + this.getStyle() + '"';
html += ' value="';
if (text != null)
html += text;
html += '"';
html += '/>';
return html;
}
this.setEditable = function(msg)
{
if (msg.value == "true")
this.node.readOnly = false;
else
this.node.readOnly = true;
}
}
TextboxPeer();
TextboxPeer.prototype = new CommonWidgetPeer;
/*-----LabelPeer---------------------------------------------------*/
function LabelPeer()
{
this.setText = function(txt)
{
this.setProperty("label", txt);
this.node.innerHTML = txt;
}
this.action_setText = function(msg)
{
this.setText(msg.text);
}
this.getText = function()
{
return this.getProperty("label");
}
this.getHTMLtag = function()
{
return "label";
}
this.getHTML = function()
{
var text = this.getProperty("label");
var html = "<";
html += this.getHTMLtag();
html += ' id="' + this.id + '"';
html += ' style="' + this.getStyle() + '"';
html += '>';
if (text != null)
html += text;
html += "" + this.getHTMLtag() + ">";
return html;
}
this.setAlignment = function(msg)
{
this.node.style.textAlign = msg.alignment;
}
}
LabelPeer();
LabelPeer.prototype = new CommonWidgetPeer;
/*-----TextAreaPeer------------------------------------------------*/
function TextAreaPeer()
{
this.action_setText = function(msg)
{
this.setText(msg.text);
}
this.setText = function(txt)
{
this.node.value = txt;
}
this.append = function(txt)
{
var text = this.node.value;
text += txt;
this.node.value = text;
}
this.getHTMLtag = function()
{
return "textarea";
}
this.getHTML = function()
{
var text = this.getProperty("text");
var html = "<";
html += this.getHTMLtag();
html += ' id="' + this.id + '"';
html += ' style="' + this.getStyle() + '"';
html += '>';
if (text != null)
html += text;
html += "" + this.getHTMLtag() + ">";
return html;
}
this.setEditable = function(msg)
{
if (msg.value == "true")
this.node.readOnly = "readonly";
else
this.node.readOnly = "readonly";
}
}
TextAreaPeer();
TextAreaPeer.prototype = new CommonWidgetPeer;
/*-----ListPeer----------------------------------------------------*/
function ListPeer()
{
this.getHTMLtag = function()
{
return "select";
}
this.getHTML = function()
{
var rows = this.getProperty("rows");
if (rows == null)
rows = 1;
var html = "<";
html += this.getHTMLtag();
html += ' id="' + this.id + '"';
html += ' size="' + 20 + '"';
html += ' style="' + this.getStyle() + '"';
html += '>';
var items = this.getProperty("items");
if (items != null) {
for (var i = 0; i < items.length; i++) {
html += "";
}
}
html += "" + this.getHTMLtag() + ">";
return html;
}
this.getSelectedItem = function()
{
return this.node.value;
}
this.clear = function(msg)
{
this.node.innerHTML = "";
}
this.action_addItem = function(msg)
{
if(msg.index == "-1") /* just append */
{
var opt = new Option();
opt.text = msg.item;
opt.value = msg.item;
this.node.options[this.node.options.length] = opt;
}else
{
log("List doesn't support adding in between yet!");
}
}
this.setItems = function(msg)
{
var items = msg.items;
for(var i = 0; i < items.length; ++i)
{
var opt = new Option();
opt.text = items[i+""];
opt.value = items[i+""];
this.node.options[this.node.options.length] = opt;
}
}
this.setRows = function(msg)
{
}
this.setMultipleMode = function(msg)
{
var mode = msg.value;
if (mode == "false")
this.node.multiple = "";
else
this.node.multiple = "true";
}
}
ListPeer();
ListPeer.prototype = new CommonWidgetPeer;
/*
* XML11 --- An Abstract Windowing Protocol
* Copyright (c) 2004-2005 by The XML11 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information, visit the XML11 Home Page at
* http://www.xml11.org/
*/
var debug_id = "DEBUG";
var debug_width = 30;
var debug_node = null;
function debug_init()
{
debug_node = document.createElement("div");
document.body.appendChild(debug_node);
var html = '';
debug_node.innerHTML = html;
}
function log(msg)
{
if (debug_node == null)
debug_init();
var node = document.getElementById(debug_id);
node.value += msg + '\n';
node.scrollTop = node.scrollHeight;
}
/*
* XML11 --- An Abstract Windowing Protocol
* Copyright (c) 2004-2005 by The XML11 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information, visit the XML11 Home Page at
* http://www.xml11.org/
*/
// We need this global variable. The XMLVM2JS stylesheet
// will generate an assignment, where the class being
// translated will be assigned to remoteClass. This is
// necessary because otherwise the eval() statement would
// have no effect on the global scope (since it is executed
// within the scope of a function()
var remoteClass = null;
var remoteClassName = null;
var app_frame = new Array();
var plugin_frame = new Array();
var classLoaded = new Array();
var global = this;
function ERROR(message)
{
alert("ERROR: " + message);
throw "Fatal Error";
}
//Sends the current value of all widgets to the server
function send_update_to_server()
{
var nodes = document.getElementsByTagName ("textbox");
for (var i = 0; i < nodes.length; i++) {
var msg = new XMLOB_Message("modelManagerObj", "updateValue");
msg.id = nodes[i].getAttribute("id");
msg.value = nodes[i].value;
msg.queue();
}
nodes = document.getElementsByTagName ("textarea");
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].getAttribute ("id") == debug_id)
continue;
var msg = new XMLOB_Message("modelManagerObj", "updateValue");
msg.id = nodes[i].getAttribute("id");
msg.value = nodes[i].value;
msg.queue();
}
nodes = document.getElementsByTagName ("input");
for (var i = 0; i < nodes.length; i++) {
var msg = new XMLOB_Message("modelManagerObj", "updateValue");
msg.id = nodes[i].getAttribute("id");
msg.value = nodes[i].value;
msg.queue();
}
nodes = document.getElementsByTagName ("select");
for (var i = 0; i < nodes.length; i++) {
var msg = new XMLOB_Message("modelManagerObj", "updateValue");
msg.id = nodes[i].getAttribute("id");
msg.value = nodes[i].selectedIndex + "";
msg.queue();
}
}
//TODO all these on_* functions share a lot in common. Factor this
// out to a new class
function do_oncommand (id)
{
if (app_frame.length != 0) {
// We have the code for actionPerformed locally
var action_event = new java_awt_event_ActionEvent();
action_event.setID(id);
app_frame[0].actionPerformed(action_event);
} else {
// We have to send the event to the server
send_update_to_server();
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = id;
msg.type = "clicked";
msg.send();
}
}
function do_on_textfield_actionperformed(e)
{
if (!e)
e = window.event;
//TODO: e.which doesn't seem to work in IE
if (e.keyCode == 13) { //Enter Key
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
send_update_to_server();
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "actionPerformed";
msg.send();
}
}
function do_on_itemStateChanged(e)
{
var node = document.getElementById(this.id);
//have to send current status and change, that selected items are in new-value
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "itemStateChanged";
msg.selectedIndex = node.selectedIndex + "";
msg.send();
}
function do_onmousedown(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
//Sends the current mouse position to the server, before sending
//the click event
calcMousePosition1(e, this.id, false);
//TODO we also need to send the current values of all
// input fields
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "mousePressed";
msg.send();
}
function do_onmouseup(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
//TODO we also need to send the current values of all
// input fields
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "mouseReleased";
msg.send();
}
function do_onmouseover(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
if (mouse_timer != null) {
clearTimeout(mouse_timer);
mouse_timer = null;
}
//TODO we also need to send the current values of all
// input fields
//log("Mouse entered: " + this.id);
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "mouseEntered";
msg.send();
}
function do_onmouseout(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
if (mouse_timer != null) {
clearTimeout(mouse_timer);
mouse_timer = null;
}
//TODO we also need to send the current values of all
// input fields
//log("Mouse exited: " + this.id);
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "mouseExited";
msg.send();
}
var mouse_timer = null;
var mouse_pos_x = 0;
var mouse_pos_y = 0;
var mouse_widget_id = null;
function do_onmousemove(e)
{
calcMousePosition1(e, this.id, true);
if (mouse_timer != null) {
// The user moved mouse within the past half second
// Don't do anything right now, but only reset the timer
clearTimeout(mouse_timer);
}
// Don't do anything just yet, but set a timer. Only when the
// timer goes off, we send the
mouse_timer = setTimeout("timeout()", 500);
}
function timeout()
{
mouse_timer = null;
calcMousePosition2(mouse_pos_x, mouse_pos_y, mouse_widget_id);
}
//TODO: Find a better name for this function
function calcMousePosition1(e, id, _timeout)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
var _mouse_widget_id = id;
var _mouse_pos_x = 0;
var _mouse_pos_y = 0;
if (e.pageX || e.pageY) {
_mouse_pos_x = e.pageX;
_mouse_pos_y = e.pageY;
}
else if (e.clientX || e.clientY) {
_mouse_pos_x = e.clientX + document.body.scrollLeft;
_mouse_pos_y = e.clientY + document.body.scrollTop;
}
if(_timeout == false)
calcMousePosition2(_mouse_pos_x, _mouse_pos_y, _mouse_widget_id);
else
{
mouse_pos_x = _mouse_pos_x;
mouse_pos_y = _mouse_pos_y;
mouse_widget_id = _mouse_widget_id;
}
}
function calcMousePosition2(_mouse_pos_x, _mouse_pos_y, id)
{
var _mouse_widget_id = id;
var peer = CommonWidgetPeer.getPeer(_mouse_widget_id);
while (peer != null) {
_mouse_pos_x -= peer.node.offsetLeft;
_mouse_pos_y -= peer.node.offsetTop;
peer = CommonWidgetPeer.getParentPeer(peer);
}
_mouse_pos_x -= rootXML11PosX();
_mouse_pos_y -= rootXML11PosY();
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = _mouse_widget_id;
msg.type = "mouseMoved";
msg.x = _mouse_pos_x;
msg.y = _mouse_pos_y;
msg.send();
}
function do_onkeydown(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
//log('key down');
return;
}
function do_onkeyup(e)
{
send_update_to_server();
var msg = new XMLOB_Message("eventManagerObj", "raiseEvent");
msg.id = this.id;
msg.type = "keyReleased";
msg.keyCode = e.which;
msg.send();
}
function initXML11(policy)
{
XMLOB.boot(policy);
var sessionManager = new SessionManager();
XMLOB.registerObject("sessionManager", sessionManager);
var errorManager = new ErrorManager();
XMLOB.registerObject("errorManager", errorManager);
var awtManager = new AWTManager();
XMLOB.registerObject("awtManager", awtManager);
var codeManager = new CodeManager();
XMLOB.registerObject("codeManager", codeManager);
}
function requestCode(className)
{
var ret = XMLOB.urllib.getURL('/requestCode/'+className, '', '', '',
[]);
var msg = new Object();
msg.code = ret.responseText
XMLOB.getObject("codeManager").migrateCode(msg);
}
function checkClass(className)
{
/*if(className.indexOf("java.") != -1)
return;*/
/*if(classLoaded[className] != true)
{
//Because object is sub-class of object, we need to put
//this flag here and not at the end of the migrated code
//Otherwise, the check for the superclass would be called
//before this flag can be set.
classLoaded[className] = true;
requestCode(className);
}*/
}
function SessionManager()
{
SessionManager.sessionID = null;
this.setSessionID = function(msg)
{
if (SessionManager.sessionID != null) {
log("Trying to set the session ID a second time.");
throw "setSessionID";
}
SessionManager.sessionID = msg.sessionID;
}
}
function ErrorManager()
{
this.reportError = function(msg)
{
log("error");
log(msg.toJSONString());
throw "ERROR";
}
}
function AWTManager()
{
this.updateModel = function(msg)
{
// XXX
if (msg.type == 'org_xml11_demo_step4_ImagePanel')
// We cannot handle model updates for classes that
// belong to our application.
return;
var cmd = "app_frame[0]." + msg.field + " = new " + msg.type;
cmd += "('" + msg.id + "');";
eval(cmd);
cmd = 'targetMap["' + msg.id + '"] = app_frame[0].' + msg.field + ';';
eval(cmd);
}
this.createWidget = function(msg)
{
var peer = CommonWidgetPeer.createPeer(msg.type, msg.id, msg.pid);
if (msg["itemStateChangedEvents"] == "true")
peer.setItemStateChangedEvents(true);
if (msg["actionPerformedEvents"] == "true")
peer.setActionPerformedEvents(true);
if (msg["keyPressedEvents"] == "true")
peer.setKeyPressedEvents(true);
if (msg["keyReleasedEvents"] == "true")
peer.setKeyReleasedEvents(true);
if (msg["mousePressedEvents"] == "true")
peer.setMousePressedEvents(true);
if (msg["mouseReleasedEvents"] == "true")
peer.setMouseReleasedEvents(true);
if (msg["mouseEnteredEvents"] == "true")
peer.setMouseEnteredEvents(true);
if (msg["mouseExitedEvents"] == "true")
peer.setMouseExitedEvents(true);
if (msg["mouseMovedEvents"] == "true")
peer.setMouseMovedEvents(true);
peer.create();
}
this.updateWidget = function(msg)
{
var id = msg.id;
var peer = CommonWidgetPeer.getPeer(id);
if (msg.property && msg.property.name == "image") {
peer.addImage();
} else if (msg.documentProperty) {
if (msg.documentProperty.name == 'title')
document.title = "XML11 - " + msg.documentProperty.value;
} else if (msg.clear) {
peer.clear();
} else {
log('Unknown property: ' + msg.toJSONString());
}
}
this.deleteWidget = function(msg)
{
var peer = CommonWidgetPeer.getPeer(msg.id);
peer.dispose();
}
}
function CodeManager()
{
this.insertCode = function(code)
{
var myTag = document.createElement("script");
myTag.type="text/javascript";
myTag.text = code;
document.getElementById("XML11_ROOT").appendChild(myTag);
}
this.insertExternalCode = function(externalSrc)
{
var myTag = document.createElement("script");
myTag.type="text/javascript";
myTag.src = externalSrc;
document.getElementById("XML11_ROOT").appendChild(myTag);
}
this.migrateCode = function(msg)
{
if (msg["type"] == "plugin") {
this.insertCode(msg.code);
return;
}
//log("Got migration code:\n");
//log(msg.code);
global.eval(msg.code);
// Create instance of the remote class
var newInstance = new remoteClass;
// Call default constructor
var stmt = "newInstance.__init_" + remoteClassName + "();";
global.eval(stmt);
app_frame.push(newInstance);
}
}/*
* XMLVM --- An XML-based Programming Language
* Copyright (c) 2004-2005 by Arno Puder
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information, visit the XMLVM Home Page at
* http://www.xml11.org/xmlvm/
*/
//---------------------------------------------------------------
// The following classes are a re-implementation of the Java
// classes used by the program being run
//---------------------------------------------------------------
function java_lang_Object()
{
this.__init_java_lang_Object = function()
{
}
}
java_lang_Object();
function java_lang_Thread()
{
this.__init_java_lang_Thread = function()
{
}
}
java_lang_Thread();
function java_lang_Exception()
{
this.__init_java_lang_Exception = function()
{
}
}
java_lang_Exception();
function java_lang_String()
{
this._str = "";
this.__init_java_lang_String = function(str)
{
this._str = str;
return this;
}
java_lang_String.valueOf = function(val)
{
if (val.__init_java_lang_String)
// val is already a string
return val;
return (new java_lang_String).__init_java_lang_String(val);
}
this.equals = function(s)
{
return this._str == s._str;
}
this._length = function()
{
return this._str.length;
}
this.charAt = function(i)
{
return this._str.charCodeAt(i);
}
}
java_lang_String();
function java_lang_StringBuffer()
{
this._str = "";
/*
this.__init_java_lang_StringBuffer = function()
{
this._str = "";
}
*/
this.__init_java_lang_StringBuffer = function(s)
{
if (s)
this._str = s._str;
else
this._str = "";
}
this.toString = function()
{
return (new java_lang_String).__init_java_lang_String(this._str);
}
this.append = function(s)
{
if (s._str == undefined)
this._str = "" + s;
else
this._str += s._str;
return this;
}
}
java_lang_StringBuffer();
function java_lang_StringBuilder()
{
this._str = "";
/*
this.__init_java_lang_StringBuilder = function()
{
this._str = "";
}
*/
this.__init_java_lang_StringBuilder = function(s)
{
if (s)
this._str = s._str;
else
this._str = "";
}
this.toString = function()
{
return (new java_lang_String).__init_java_lang_String(this._str);
}
this.append = function(s)
{
if (s._str == undefined)
this._str = "" + s;
else
this._str += s._str;
return this;
}
}
java_lang_StringBuilder();
function java_io_PrintStream()
{
this.println = function(s)
{
alert("println(): " + s._str);
}
}
java_io_PrintStream();
function java_lang_System()
{
}
java_lang_System.out = new java_io_PrintStream;
function java_lang_Double()
{
java_lang_Double.parseDouble = function(s)
{
return s._str * 1;
}
}
java_lang_Double();
function java_lang_Float()
{
this._float = null;
java_lang_Float.valueOf = function(s)
{
var f = new java_lang_Float;
f._float = s._str * 1; // Make sure we convert the string to a number
return f;
}
java_lang_Float.toString = function(f)
{
// By concatenating "" we make sure we get a string
var s = f + "";
if (s.indexOf(".") < 0)
// Concatenate ".0" for Java compatibility
s += ".0";
return (new java_lang_String).__init_java_lang_String(s);
}
this.floatValue = function()
{
return this._float;
}
}
java_lang_Float();
function java_util_Date()
{
this._date = "";
this.__init_java_util_Date = function()
{
this._date = new Date();
}
}
java_util_Date();
function java_text_SimpleDateFormat()
{
this._format = "";
/*
this.__init_java_text_SimpleDateFormat = function()
{
}
*/
this.__init_java_text_SimpleDateFormat = function(format)
{
if (format) this._format = format;
}
this.format = function(date)
{
return (new java_lang_String).__init_java_lang_String(date._date);
}
}
java_text_SimpleDateFormat();