~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/editor/draw2d/Rectangle.js

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This notice must be untouched at all times.
 
2
 
 
3
Open-jACOB Draw2D
 
4
The latest version is available at
 
5
http://www.openjacob.org
 
6
 
 
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
 
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
 
9
 
 
10
LICENSE: LGPL
 
11
 
 
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.
 
16
 
 
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.
 
21
 
 
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
 
26
*/
 
27
 
 
28
/**
 
29
 * 
 
30
 * @version 0.9.14
 
31
 * @author Andreas Herz
 
32
 * @constructor
 
33
 */
 
34
draw2d.Rectangle=function(/*int*/ width, /*:int*/ height)
 
35
{
 
36
  /** @private **/
 
37
  this.bgColor = null;
 
38
  /** @private **/
 
39
  this.lineColor = new  draw2d.Color(0,0,0);
 
40
  /** @private **/
 
41
  this.lineStroke=1;
 
42
  draw2d.Figure.call(this);
 
43
 
 
44
  if(width && height)
 
45
    this.setDimension(width, height);
 
46
}
 
47
draw2d.Rectangle.prototype = new draw2d.Figure;
 
48
/** @private **/
 
49
draw2d.Rectangle.prototype.type="Rectangle";
 
50
 
 
51
/**
 
52
 * @private
 
53
 **/
 
54
draw2d.Rectangle.prototype.dispose=function()
 
55
{
 
56
  draw2d.Figure.prototype.dispose.call(this);
 
57
  this.bgColor=null;
 
58
  this.lineColor = null;
 
59
}
 
60
 
 
61
/**
 
62
 * @private
 
63
 **/
 
64
draw2d.Rectangle.prototype.createHTMLElement=function()
 
65
{
 
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="&nbsp";
 
75
    if(this.bgColor!=null)
 
76
      item.style.backgroundColor=this.bgColor.getHTMLStyle();
 
77
 
 
78
    return item;
 
79
}
 
80
 
 
81
 
 
82
/**
 
83
 *
 
84
 * @param {draw2d.Color} color The new background color of the rectangle.
 
85
 **/
 
86
draw2d.Rectangle.prototype.setBackgroundColor= function(/*:draw2d.Color*/ color)
 
87
{
 
88
  this.bgColor = color;
 
89
  if(this.bgColor!=null)
 
90
    this.html.style.backgroundColor=this.bgColor.getHTMLStyle();
 
91
  else
 
92
    this.html.style.backgroundColor="transparent";
 
93
}
 
94
 
 
95
/**
 
96
 * The background color of the rectangle.
 
97
 *
 
98
 * @type draw2d.Color
 
99
 **/
 
100
draw2d.Rectangle.prototype.getBackgroundColor=function()
 
101
{
 
102
  return this.bgColor;
 
103
}
 
104
 
 
105
/**
 
106
 * Set the line color of the rectangle. You can hand over <i>null</i> to enforce a transparent line
 
107
 *
 
108
 * @param {draw2d.Color} color The new line color of the rectangle
 
109
 **/
 
110
draw2d.Rectangle.prototype.setColor= function(/*:draw2d.Color*/ color)
 
111
{
 
112
  this.lineColor = color;
 
113
  if(this.lineColor!=null)
 
114
  {
 
115
    this.html.style.border= this.lineStroke+"px solid "+this.lineColor.getHTMLStyle();
 
116
  }
 
117
  else
 
118
  {
 
119
    this.html.style.border= this.lineStroke+"0px";
 
120
  }
 
121
}
 
122
 
 
123
/**
 
124
 *
 
125
 * @type draw2d.Color
 
126
 **/
 
127
draw2d.Rectangle.prototype.getColor=function()
 
128
{
 
129
  return this.lineColor;
 
130
}
 
131
 
 
132
/**
 
133
 * Returns the width of the figure.
 
134
 * @type int
 
135
 **/
 
136
draw2d.Rectangle.prototype.getWidth=function()
 
137
{
 
138
  return draw2d.Figure.prototype.getWidth.call(this)+2*this.lineStroke;
 
139
}
 
140
 
 
141
/**
 
142
 * @type int
 
143
 **/
 
144
draw2d.Rectangle.prototype.getHeight=function()
 
145
{
 
146
  // add the line stroke to the width
 
147
  //
 
148
  return draw2d.Figure.prototype.getHeight.call(this)+2*this.lineStroke;
 
149
}
 
150
 
 
151
draw2d.Rectangle.prototype.setDimension=function(/*:int*/ w ,/*:int*/ h)
 
152
{
 
153
  // reduce the dimension with the border line stroke
 
154
  // (border goes into the rectangle and not outside the element)
 
155
  //
 
156
  return draw2d.Figure.prototype.setDimension.call(this, w-2*this.lineStroke, h-2*this.lineStroke);
 
157
}
 
158
 
 
159
/**
 
160
 *
 
161
 **/
 
162
draw2d.Rectangle.prototype.setLineWidth=function(/*:int*/ w)
 
163
{
 
164
  var diff =  w-this.lineStroke;
 
165
  this.setDimension(this.getWidth()-2*diff, this.getHeight()-2*diff);
 
166
  this.lineStroke=w;
 
167
  var c = "transparent";
 
168
  if(this.lineColor!=null)
 
169
    c=this.lineColor.getHTMLStyle();
 
170
  this.html.style.border= this.lineStroke+"px solid "+c;
 
171
}
 
172
 
 
173
/**
 
174
 * @type int
 
175
 **/
 
176
draw2d.Rectangle.prototype.getLineWidth=function()
 
177
{
 
178
  return this.lineStroke;
 
179
}