-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMyInputPort.js
124 lines (115 loc) · 3.4 KB
/
MyInputPort.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
MyInputPort=function(_385b){
//InputPort.call(this,_385b);
var aPort = this;
var fff = function(e) {
aPort.ctrlKey = e.ctrlKey;
}
var fff2 = function(e) {
aPort.haveDragged = true;
}
Port.call(this,_385b);
this.setZOrderBaseIndex = 104;
this.setBackgroundColor(new Color(115,115,245));
this.setColor(null);
this.setDimension(10,10);
this.setCoronaWidth(5);
this.haveDragged = false;
this.clonePort = false;
if(this.html.addEventListener) {
this.html.addEventListener("mouseup", fff,false);
this.html.addEventListener("mousemove", fff,false);
} else {
if(this.html.attachEvent){
this.html.attachEvent("onmouseup",fff);
this.html.attachEvent("onmousemove",fff);
}
}
};
MyInputPort.prototype=new Port;
MyInputPort.prototype.type="MyInputPort";
MyInputPort.prototype.toJSON = function() {
var js = new Object;
var js_conns = new Array;
var conns = this.getConnections();
for(var k = 0; k<conns.length; k++) {
if (conns[k].getSource() == this) {
js_conns.push(conns[k].toJSON());
}
}
js['connections'] = js_conns;
js['x'] = this.getX();
js['y'] = this.getY();
js['id'] = this.getId();
return js;
}
MyInputPort.prototype.onDoubleClick=function(){
if(!this.annotation) {
this.getParent().addAnnotation(this, "Port description", this.getX(), this.getY());
this.annotation.doEdit();
this.bgFlash();
} else {
this.annotation.bgFlash();
}
}
MyInputPort.prototype.onDrag=function(){
this.haveDragged = true;
Rectangle.prototype.onDrag.call(this);
this.parentNode.workflow.showConnectionLine(this.parentNode.x+this.x+this.width/2,this.parentNode.y+this.y+this.height/2,this.parentNode.x+this.originX,this.parentNode.y+this.originY);
this.predragX = this.originX;
this.predragY = this.originY;
}
MyInputPort.prototype.onDragend=function(){
var myX = this.getX();
var myY = this.getY();
if (this.haveDragged) {
// weird bug in the lib ?
myX += this.width/2;
myY += this.height/2;
this.haveDragged = false;
} else {
this.predragX = myX;
this.predragY = myY;
}
var fig = this.getParent();
if (myX > -20 && myY > -20 &&
myX < fig.width+20 && myY < fig.height+20) {
if(this.ctrlKey) {
var fig = this.getParent();
var aPort = new MyInputPort();
aPort.setWorkflow(fig.getWorkflow());
fig.addPort(aPort, myX, myY);
Port.prototype.paint.call(aPort);
} else {
this.setPosition(myX, myY);
if(this.annotation) {
var newdx = myX - this.predragX;
var newdy = myY - this.predragY;
this.annotation.DX += newdx;
this.annotation.DY += newdy;
this.annotation.setPosition(this.annotation.getX() + newdx, this.annotation.getY() + newdy);
}
//this.setOrigin(myX+10, myY+10);
}
}
Port.prototype.onDragend.call(this);
}
MyInputPort.prototype.onDrop=function(port){
if(port.getMaxFanOut&&port.getMaxFanOut()<=port.getFanOut()){
return;
}
if(this.parentNode.id==port.parentNode.id){
}else{
var _385d=new CommandConnect(this.parentNode.workflow,port,this);
_385d.setConnection(new ContextmenuConnection());
this.parentNode.workflow.getCommandStack().execute(_385d);
}
};
MyInputPort.prototype.getContextMenu=function(){
var menu=new Menu();
var oThis=this;
menu.appendMenuItem(new MenuItem("Delete port",null,function(){
workflow.commandStack.execute(new CommandDelete(oThis));
//oThis.getParent().removePort(oThis);
}));
return menu;
};