~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/editor/draw2d/LineStartResizeHandle.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
 * @param {draw2d.Workflow} workflow The host canvas for this resize handle
 
34
 * @private
 
35
 * @final
 
36
 */
 
37
draw2d.LineStartResizeHandle=function(/*:draw2d.Workflow*/ workflow)
 
38
{
 
39
  draw2d.Rectangle.call(this);
 
40
  this.setDimension(10,10);
 
41
  this.setBackgroundColor(new  draw2d.Color(0,255,0));
 
42
  this.setWorkflow(workflow);
 
43
  this.setZOrder(10000);
 
44
}
 
45
 
 
46
draw2d.LineStartResizeHandle.prototype = new draw2d.Rectangle;
 
47
/** @private **/
 
48
draw2d.LineStartResizeHandle.prototype.type="LineStartResizeHandle";
 
49
 
 
50
/**
 
51
 * Will be called after a drag and drop action.<br>
 
52
 * Sub classes can override this method to implement additional stuff. Don't forget to call
 
53
 * the super implementation via <code>Figure.prototype.onDragend.call(this);</code>
 
54
 * @private
 
55
 **/
 
56
draw2d.LineStartResizeHandle.prototype.onDragend = function()
 
57
{
 
58
  var line = this.workflow.currentSelection;
 
59
 
 
60
  // A Connection glue at the corresponding port. Reset the position to the origin port
 
61
  // if we doesn't drop the ResizeHandle on a other port.
 
62
  //
 
63
  if(line instanceof draw2d.Connection)
 
64
  {
 
65
     var start  = line.sourceAnchor.getLocation(line.targetAnchor.getReferencePoint());
 
66
     line.setStartPoint(start.x,start.y);
 
67
     this.getWorkflow().showLineResizeHandles(line);
 
68
     line.setRouter(line.oldRouter);
 
69
  }
 
70
  //
 
71
  else
 
72
  {
 
73
     // An non draggable resizeHandle doesn't create a move/resize command.
 
74
     // This happens if the selected figure has set the "nonResizeable" flag.
 
75
     //
 
76
     if(this.command==null)
 
77
        return;
 
78
     var x1 = line.getStartX();
 
79
     var y1 = line.getStartY();
 
80
     var x2 = line.getEndX();
 
81
     var y2 = line.getEndY();
 
82
     this.command.setEndPoints(x1,y1,x2,y2);
 
83
     this.getWorkflow().getCommandStack().execute(this.command);
 
84
     this.command = null;
 
85
  }
 
86
}
 
87
 
 
88
/**
 
89
 * Will be called if the drag and drop action beginns. You can return [false] if you
 
90
 * want avoid the that the figure can be move.
 
91
 * 
 
92
 * 
 
93
 * @param {int} x The x position where the mouse has been clicked in the figure
 
94
 * @param {int} y The y position where the mouse has been clicked in the figure
 
95
 * @type boolean
 
96
 **/
 
97
draw2d.LineStartResizeHandle.prototype.onDragstart = function(/*:int*/ x, /*:int*/ y)
 
98
{
 
99
  // This happens if the selected figure has set the "nonResizeable" flag
 
100
  // In this case the ResizeHandle can't be dragged. => no resize
 
101
  //
 
102
  if(!this.canDrag)
 
103
    return false;
 
104
 
 
105
  var line = this.workflow.currentSelection;
 
106
 
 
107
  if(line instanceof draw2d.Connection)
 
108
  {
 
109
     // DragDrop of a connection doesn't create a undo command at this point. This will be done in
 
110
     // the onDrop method
 
111
     this.command = new draw2d.CommandReconnect(line);
 
112
     line.oldRouter = line.getRouter();
 
113
     line.setRouter(new draw2d.NullConnectionRouter());
 
114
  }
 
115
  else
 
116
  {
 
117
    var x1 = line.getStartX();
 
118
    var y1 = line.getStartY();
 
119
    var x2 = line.getEndX();
 
120
    var y2 = line.getEndY();
 
121
    this.command   = new draw2d.CommandMoveLine(line,x1,y1,x2,y2);
 
122
  }
 
123
  
 
124
  return true;
 
125
}
 
126
 
 
127
/**
 
128
 *
 
129
 * @private
 
130
 **/
 
131
draw2d.LineStartResizeHandle.prototype.onDrag = function()
 
132
{
 
133
  var oldX = this.getX()
 
134
  var oldY = this.getY();
 
135
  draw2d.Rectangle.prototype.onDrag.call(this);
 
136
  var diffX = oldX-this.getX();
 
137
  var diffY = oldY-this.getY();
 
138
 
 
139
  var objPos = this.workflow.currentSelection.getStartPoint();
 
140
 
 
141
  var line = this.workflow.currentSelection;
 
142
  line.setStartPoint(objPos.x-diffX, objPos.y-diffY);
 
143
  line.isMoving = true;
 
144
}
 
145
 
 
146
/**
 
147
 * Resizehandle has ben drop on a InputPort/OutputPort.
 
148
 * @private
 
149
 **/
 
150
draw2d.LineStartResizeHandle.prototype.onDrop = function(/*: draw2d.Port*/ dropTarget)
 
151
{
 
152
  var line = this.workflow.currentSelection;
 
153
  line.isMoving=false;
 
154
 
 
155
  // The ResizeHandle of a Connection has been droped on a Port
 
156
  // This will enforce a ReconnectCommand
 
157
  if(line instanceof draw2d.Connection)
 
158
  {
 
159
     this.command.setNewPorts(dropTarget, line.getTarget());
 
160
     this.getWorkflow().getCommandStack().execute(this.command);
 
161
  }
 
162
  this.command = null;
 
163
}
 
164
 
 
165
/**
 
166
 * @private
 
167
 **/
 
168
draw2d.LineStartResizeHandle.prototype.onKeyDown=function(/*:int*/ keyCode , /*:boolean*/ ctrl)
 
169
{
 
170
  // redirect this to the workflow.
 
171
  //
 
172
  if(this.workflow!=null)
 
173
    this.workflow.onKeyDown(keyCode, ctrl);
 
174
}
 
175
 
 
176
 
 
177
 
 
178
draw2d.LineStartResizeHandle.prototype.fireMoveEvent=function()
 
179
{
 
180
  // a resizeHandle doesn't fire this event.
 
181
  //Normale this set the document dirty. This is not neccessary for a ResizeHandle.
 
182
}
 
183
 
 
184
 
 
185