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.Rectangle=function(/*int*/ width, /*:int*/ height)
39
this.lineColor = new draw2d.Color(0,0,0);
42
draw2d.Figure.call(this);
45
this.setDimension(width, height);
47
draw2d.Rectangle.prototype = new draw2d.Figure;
49
draw2d.Rectangle.prototype.type="Rectangle";
54
draw2d.Rectangle.prototype.dispose=function()
56
draw2d.Figure.prototype.dispose.call(this);
58
this.lineColor = null;
64
draw2d.Rectangle.prototype.createHTMLElement=function()
66
var item = draw2d.Figure.prototype.createHTMLElement.call(this);
67
item.style.width="auto";
68
item.style.height="auto";
69
item.style.margin="0px";
70
item.style.padding="0px";
71
item.style.border= this.lineStroke+"px solid "+this.lineColor.getHTMLStyle();
72
item.style.fontSize="1px";
73
item.style.lineHeight="1px";
74
item.innerHTML=" ";
75
if(this.bgColor!=null)
76
item.style.backgroundColor=this.bgColor.getHTMLStyle();
84
* @param {draw2d.Color} color The new background color of the rectangle.
86
draw2d.Rectangle.prototype.setBackgroundColor= function(/*:draw2d.Color*/ color)
89
if(this.bgColor!=null)
90
this.html.style.backgroundColor=this.bgColor.getHTMLStyle();
92
this.html.style.backgroundColor="transparent";
96
* The background color of the rectangle.
100
draw2d.Rectangle.prototype.getBackgroundColor=function()
106
* Set the line color of the rectangle. You can hand over <i>null</i> to enforce a transparent line
108
* @param {draw2d.Color} color The new line color of the rectangle
110
draw2d.Rectangle.prototype.setColor= function(/*:draw2d.Color*/ color)
112
this.lineColor = color;
113
if(this.lineColor!=null)
115
this.html.style.border= this.lineStroke+"px solid "+this.lineColor.getHTMLStyle();
119
this.html.style.border= this.lineStroke+"0px";
127
draw2d.Rectangle.prototype.getColor=function()
129
return this.lineColor;
133
* Returns the width of the figure.
136
draw2d.Rectangle.prototype.getWidth=function()
138
return draw2d.Figure.prototype.getWidth.call(this)+2*this.lineStroke;
144
draw2d.Rectangle.prototype.getHeight=function()
146
// add the line stroke to the width
148
return draw2d.Figure.prototype.getHeight.call(this)+2*this.lineStroke;
151
draw2d.Rectangle.prototype.setDimension=function(/*:int*/ w ,/*:int*/ h)
153
// reduce the dimension with the border line stroke
154
// (border goes into the rectangle and not outside the element)
156
return draw2d.Figure.prototype.setDimension.call(this, w-2*this.lineStroke, h-2*this.lineStroke);
162
draw2d.Rectangle.prototype.setLineWidth=function(/*:int*/ w)
164
var diff = w-this.lineStroke;
165
this.setDimension(this.getWidth()-2*diff, this.getHeight()-2*diff);
167
var c = "transparent";
168
if(this.lineColor!=null)
169
c=this.lineColor.getHTMLStyle();
170
this.html.style.border= this.lineStroke+"px solid "+c;
176
draw2d.Rectangle.prototype.getLineWidth=function()
178
return this.lineStroke;