/* * 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 = " 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 += ""; 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 += ""; 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 += ""; 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 += ""; 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 = '