1
/* This notice must be untouched at all times.
4
The latest version is available at
5
http://www.openjacob.org
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
12
This library is free software; you can redistribute it and/or
13
modify it under the terms of the GNU Lesser General Public
14
License (LGPL) as published by the Free Software Foundation; either
15
version 2.1 of the License, or (at your option) any later version.
17
This library is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
Lesser General Public License for more details.
22
You should have received a copy of the GNU Lesser General Public
23
License along with this library; if not, write to the Free Software
24
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA,
25
or see http://www.gnu.org/copyleft/lesser.html
31
* @author Andreas Herz
34
draw2d.Button=function(/*:draw2d.PaletteWindow*/ palette, /*:int*/ width, /*:int*/ height)
41
this.id = this.generateUId();
47
this.palette = palette;
50
this.setDimension(width,height);
52
this.setDimension(24,24);
55
this.html = this.createHTMLElement();
58
draw2d.Button.prototype.type="Button";
63
draw2d.Button.prototype.dispose=function()
65
//this.id = null; don't dispose the id! This is important for deregistration
66
//this.html = null; don't dispose the id! This is important for deregistration
70
draw2d.Button.prototype.getImageUrl=function()
73
return this.type+".png";
75
return this.type+"_disabled.png";
82
draw2d.Button.prototype.createHTMLElement=function()
84
var item = document.createElement('div');
86
item.style.position="absolute";
87
item.style.left = this.x+"px";
88
item.style.top = this.y+"px";
89
item.style.height = this.width+"px";
90
item.style.width = this.height+"px";
91
item.style.margin = "0px";
92
item.style.padding= "0px";
93
item.style.outline= "none";
95
if(this.getImageUrl()!=null)
96
item.style.backgroundImage="url("+this.getImageUrl()+")";
98
item.style.backgroundImage="";
101
this.omousedown=function(event)
105
oThis.setActive(true);
107
event.cancelBubble = true;
108
event.returnValue = false;
110
this.omouseup=function(event)
114
oThis.setActive(false);
117
event.cancelBubble = true;
118
event.returnValue = false;
121
if (item.addEventListener)
123
item.addEventListener("mousedown", this.omousedown, false);
124
item.addEventListener("mouseup", this.omouseup, false);
126
else if (item.attachEvent)
128
item.attachEvent("onmousedown", this.omousedown);
129
item.attachEvent("onmouseup", this.omouseup);
138
draw2d.Button.prototype.getHTMLElement=function()
141
this.html = this.createHTMLElement();
149
draw2d.Button.prototype.execute=function()
153
draw2d.Button.prototype.setTooltip=function(/*:String*/ tooltipText)
155
this.tooltip = tooltipText;
156
if(this.tooltip!=null)
157
this.html.title=this.tooltip;
165
draw2d.Button.prototype.setActive=function(flag /*:boolean*/)
171
this.html.style.border="2px inset";
173
this.html.style.border="0px";
176
draw2d.Button.prototype.isActive=function()
184
draw2d.Button.prototype.setEnabled=function(flag /*:boolean*/)
187
if(this.getImageUrl()!=null)
188
this.html.style.backgroundImage="url("+this.getImageUrl()+")";
190
this.html.style.backgroundImage="";
196
draw2d.Button.prototype.setDimension=function( w /*:int*/, h /*:int*/)
201
// Falls das Element noch nie gezeichnet wurde, dann braucht aus das HTML nicht
202
// aktualisiert werden
207
this.html.style.width = this.width+"px";
208
this.html.style.height = this.height+"px";
214
draw2d.Button.prototype.setPosition=function(/*:int*/ xPos ,/*:int*/ yPos)
216
this.x = Math.max(0,xPos);
217
this.y = Math.max(0,yPos);
218
// Falls das Element noch nie gezeichnet wurde, dann braucht aus das HTML nicht
219
// aktualisiert werden
224
this.html.style.left = this.x+"px";
225
this.html.style.top = this.y+"px";
231
draw2d.Button.prototype.getWidth=function()
239
draw2d.Button.prototype.getHeight=function()
247
draw2d.Button.prototype.getY=function()
255
draw2d.Button.prototype.getX=function()
263
draw2d.Button.prototype.getPosition=function()
265
return new draw2d.Point(this.x, this.y);
271
draw2d.Button.prototype.getToolPalette=function()
282
draw2d.Button.prototype.generateUId=function()
284
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
285
var string_length = 10;
292
for (var i=0; i<string_length; i++)
294
var rnum = Math.floor(Math.random() * chars.length);
295
id += chars.substring(rnum,rnum+1);
298
elem = document.getElementById(id);