
function Drawer(codebase) {
    // common parameters
    this.codebase = codebase;
    this.bgcolor = false;

    this.canvas = new Applet();
    this.canvas.codebase = codebase;
    this.canvas.archive = 'drawer.jar';
    this.canvas.code = 'DrawCanvas.class';
    this.canvas.width  = 400;
    this.canvas.height = 300;
    this.canvas.param.instance = (new Date()).getTime();

    this.canvas.param.ifunlicensed = 'ifunlicensed.html';

    this.canvas.param.boxbgcolor = '#E0E0E0';
    this.canvas.param.boxfgcolor = '#000000';
    this.canvas.param.progressbar = 'true';
    this.canvas.param.boxmessage = 'Loading the editor ...';

    this.controlPanel = new Applet();
    this.controlPanel.codebase = codebase;
    this.controlPanel.archive = 'drawer.jar';
    this.controlPanel.code = 'ControlPanel.class';
    this.controlPanel.width  = 400;
    this.controlPanel.height = 80;
    this.controlPanel.param.instance = this.canvas.param.instance;
}

Drawer.prototype.write = function() {

    if (this.bgcolor != false) {
	this.canvas.param.boxbgcolor = this.bgcolor;
	this.canvas.param.bgcolor = this.bgcolor;
	this.controlPanel.param.bgcolor = this.bgcolor;
	this.controlPanel.param.boxbgcolor = this.bgcolor;
    }

    document.write('<table border="1">');

    document.write('<tr><td>');
    this.controlPanel.write();
    document.write('</td></tr>');

    document.write('<tr><td>');
    this.canvas.write();
    document.write('</td></tr>');
    
    document.write('</table>');

}

Drawer.prototype.getControlPanel = function() { 
    return this.controlPanel;
}

Drawer.prototype.getCanvas = function() {
    return this.canvas;
}

Drawer.prototype.createClipartPanel = function() {
    clipartPanel = new Applet();
    clipartPanel.codebase = this.codebase;
    clipartPanel.archive = 'drawer.jar';
    clipartPanel.code = 'ClipartPanel.class';
    clipartPanel.width  = 100;
    clipartPanel.height = 100;
    if (this.bgcolor != false) {
	clipartPanel.param.boxbgcolor = this.bgcolor;
	clipartPanel.param.bgcolor = this.bgcolor;
    }
    return clipartPanel;
}

function Applet() {
    this.width    = false;
    this.height   = false;
    this.code     = false;
    this.codebase = './';
    this.archive  = false;
    this.param    = new Object();
    this.id       = false;
}

Applet.prototype.write = function() {

    var missing_parameter = '';
    
    if (this.code==false) {
    	missing_parameter += ' Applet.code';
    }
    if (this.width==false) {
    	missing_parameter += ' Applet.width';
    }
    if (this.height==false) {
    	missing_parameter += ' Applet.height';
    }
    
    if (missing_parameter.length > 0) {
    	window.alert('Missing parameter(s) :'+missing_parameter);
    	return;
    }
 
    s = '<OBJECT classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"\n';
    if (this.id != false)
    	s += 'id = "'+this.id+'"\n';
    s += 'codebase = "http://java.sun.com/update/1.4.2/jinstall-1_4-windows-i586.cab#Version=1,4,0,0"\n';
    s += 'WIDTH = "'+this.width+'" HEIGHT = "'+this.height+'" >\n';
    s += '<PARAM NAME = CODE VALUE = "'+this.code+'" >\n';
    s += '<PARAM NAME = CODEBASE VALUE = "'+this.codebase+'">\n';
    if (this.archive != false)
    	s += '<PARAM NAME = "ARCHIVE" VALUE="'+this.archive+'">\n';
    s += '<PARAM NAME = "type" VALUE = "application/x-java-applet;version=1.4">\n';
    s += '<PARAM NAME = "scriptable" VALUE = "false">\n';
    for (name in this.param) {
        var value = this.param[name];
	s += '<PARAM NAME="'+name+'" VALUE="'+value+'">';
    }
    s += '<COMMENT><EMBED type = "application/x-java-applet;version=1.4"\n';
    if (this.id != false)
    	s += 'name = "'+this.id+'"\n';
    s += 'CODE = "'+this.code+'"\n';    
    s += 'JAVA_CODEBASE = "'+this.codebase+'"\n';
    if (this.archive != false)
    	s += 'ARCHIVE = "'+this.archive+'"\n';
    s += 'WIDTH="'+this.width+'" HEIGHT="'+this.height+'"\n';
    s += 'scriptable = false\n';
    s += 'pluginspage = "http://java.sun.com/products/plugin/index.html#download"\n';
    for (name in this.param) {
        var value = this.param[name];
	s += name+'="'+value+'"\n';
    }
    s += '><NOEMBED></NOEMBED></EMBED></COMMENT>';
    s += '</OBJECT>';

    document.write(s);

} // end of Applet.write()
