More classes migrated to Mootools 1.3.

This commit is contained in:
Paulo Veiga 2011-07-27 08:25:10 -03:00
parent 9759ee12cb
commit f60755fd8e
21 changed files with 2334 additions and 2584 deletions

View File

@ -1,34 +1,33 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.Beta2PelaMigrator = function(betaSerializer){ mindplot.Beta2PelaMigrator = new Class({
this._betaSerializer=betaSerializer; initialize : function(betaSerializer) {
this._pelaSerializer = new mindplot.XMLMindmapSerializer_Pela(); this._betaSerializer = betaSerializer;
}; this._pelaSerializer = new mindplot.XMLMindmapSerializer_Pela();
},
mindplot.Beta2PelaMigrator.prototype.toXML = function(mindmap) toXML : function(mindmap) {
{ return this._pelaSerializer.toXML(mindmap);
return this._pelaSerializer.toXML(mindmap); },
};
loadFromDom : function(dom) {
mindplot.Beta2PelaMigrator.prototype.loadFromDom = function(dom) var mindmap = this._betaSerializer.loadFromDom(dom);
{ mindmap.setVersion(mindplot.ModelCodeName.PELA);
var mindmap = this._betaSerializer.loadFromDom(dom); return mindmap;
mindmap.setVersion(mindplot.ModelCodeName.PELA); }
return mindmap; });
};

View File

@ -58,72 +58,75 @@ mindplot.Board = new Class({
/** /**
* --------------------------------------- * ---------------------------------------
*/ */
mindplot.BidirectionalArray = function() { mindplot.BidirectionalArray = new Class({
this._leftElem = [];
this._rightElem = [];
};
mindplot.BidirectionalArray.prototype.get = function(index, sign) { initialize: function() {
core.assert(core.Utils.isDefined(index), 'Illegal argument, index must be passed.'); this._leftElem = [];
if (core.Utils.isDefined(sign)) { this._rightElem = [];
core.assert(index >= 0, 'Illegal absIndex value'); },
index = index * sign;
}
var result = null; get :function(index, sign) {
if (index >= 0 && index < this._rightElem.length) { core.assert(core.Utils.isDefined(index), 'Illegal argument, index must be passed.');
result = this._rightElem[index]; if (core.Utils.isDefined(sign)) {
} else if (index < 0 && Math.abs(index) < this._leftElem.length) { core.assert(index >= 0, 'Illegal absIndex value');
result = this._leftElem[Math.abs(index)]; index = index * sign;
}
return result;
};
mindplot.BidirectionalArray.prototype.set = function(index, elem) {
core.assert(core.Utils.isDefined(index), 'Illegal index value');
var array = (index >= 0) ? this._rightElem : this._leftElem;
array[Math.abs(index)] = elem;
};
mindplot.BidirectionalArray.prototype.length = function(index) {
core.assert(core.Utils.isDefined(index), 'Illegal index value');
return (index >= 0) ? this._rightElem.length : this._leftElem.length;
};
mindplot.BidirectionalArray.prototype.upperLength = function() {
return this.length(1);
};
mindplot.BidirectionalArray.prototype.lowerLength = function() {
return this.length(-1);
};
mindplot.BidirectionalArray.prototype.inspect = function() {
var result = '{';
var lenght = this._leftElem.length;
for (var i = 0; i < lenght; i++) {
var entry = this._leftElem[lenght - i - 1];
if (entry != null) {
if (i != 0) {
result += ', ';
}
result += entry.inspect();
} }
}
lenght = this._rightElem.length; var result = null;
for (var i = 0; i < lenght; i++) { if (index >= 0 && index < this._rightElem.length) {
var entry = this._rightElem[i]; result = this._rightElem[index];
if (entry != null) { } else if (index < 0 && Math.abs(index) < this._leftElem.length) {
if (i != 0) { result = this._leftElem[Math.abs(index)];
result += ', ';
}
result += entry.inspect();
} }
return result;
},
set : function(index, elem) {
core.assert(core.Utils.isDefined(index), 'Illegal index value');
var array = (index >= 0) ? this._rightElem : this._leftElem;
array[Math.abs(index)] = elem;
},
length : function(index) {
core.assert(core.Utils.isDefined(index), 'Illegal index value');
return (index >= 0) ? this._rightElem.length : this._leftElem.length;
},
upperLength : function() {
return this.length(1);
},
lowerLength : function() {
return this.length(-1);
},
inspect : function() {
var result = '{';
var lenght = this._leftElem.length;
for (var i = 0; i < lenght; i++) {
var entry = this._leftElem[lenght - i - 1];
if (entry != null) {
if (i != 0) {
result += ', ';
}
result += entry.inspect();
}
}
lenght = this._rightElem.length;
for (var i = 0; i < lenght; i++) {
var entry = this._rightElem[i];
if (entry != null) {
if (i != 0) {
result += ', ';
}
result += entry.inspect();
}
}
result += '}';
return result;
} }
result += '}'; });
return result;
};

View File

@ -1,160 +1,141 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.BoardEntry = function(lowerLimit, upperLimit, order) mindplot.BoardEntry = new Class({
{ initialize:function(lowerLimit, upperLimit, order) {
if (core.Utils.isDefined(lowerLimit) && core.Utils.isDefined(upperLimit)) if (core.Utils.isDefined(lowerLimit) && core.Utils.isDefined(upperLimit)) {
{ core.assert(lowerLimit < upperLimit, 'lowerLimit can not be greater that upperLimit');
core.assert(lowerLimit < upperLimit, 'lowerLimit can not be greater that upperLimit'); }
} this._upperLimit = upperLimit;
this._upperLimit = upperLimit; this._lowerLimit = lowerLimit;
this._lowerLimit = lowerLimit; this._order = order;
this._order = order; this._topic = null;
this._topic = null; this._xPos = null;
this._xPos = null; },
};
mindplot.BoardEntry.prototype.getUpperLimit = function()
{
return this._upperLimit;
};
mindplot.BoardEntry.prototype.setXPosition = function(xPosition)
{
this._xPos = xPosition;
};
mindplot.BoardEntry.prototype.workoutEntryYCenter = function()
{
return this._lowerLimit + ((this._upperLimit - this._lowerLimit) / 2);
};
mindplot.BoardEntry.prototype.setUpperLimit = function(value)
{
core.assert(core.Utils.isDefined(value), "upper limit can not be null");
core.assert(!isNaN(value), "illegal value");
this._upperLimit = value;
};
mindplot.BoardEntry.prototype.isCoordinateIn = function(coord)
{
return this._lowerLimit <= coord && coord < this._upperLimit;
};
mindplot.BoardEntry.prototype.getLowerLimit = function()
{
return this._lowerLimit;
};
mindplot.BoardEntry.prototype.setLowerLimit = function(value)
{
core.assert(core.Utils.isDefined(value), "upper limit can not be null");
core.assert(!isNaN(value), "illegal value");
this._lowerLimit = value;
};
mindplot.BoardEntry.prototype.setOrder = function(value)
{
this._order = value;
};
mindplot.BoardEntry.prototype.getWidth = function()
{
return Math.abs(this._upperLimit - this._lowerLimit);
};
mindplot.BoardEntry.prototype.getTopic = function() getUpperLimit : function() {
{ return this._upperLimit;
return this._topic; },
};
setXPosition : function(xPosition) {
this._xPos = xPosition;
},
workoutEntryYCenter : function() {
return this._lowerLimit + ((this._upperLimit - this._lowerLimit) / 2);
},
setUpperLimit : function(value) {
core.assert(core.Utils.isDefined(value), "upper limit can not be null");
core.assert(!isNaN(value), "illegal value");
this._upperLimit = value;
},
isCoordinateIn : function(coord) {
return this._lowerLimit <= coord && coord < this._upperLimit;
},
getLowerLimit : function() {
return this._lowerLimit;
},
setLowerLimit : function(value) {
core.assert(core.Utils.isDefined(value), "upper limit can not be null");
core.assert(!isNaN(value), "illegal value");
this._lowerLimit = value;
},
setOrder : function(value) {
this._order = value;
},
getWidth : function() {
return Math.abs(this._upperLimit - this._lowerLimit);
},
mindplot.BoardEntry.prototype.removeTopic = function() getTopic : function() {
{ return this._topic;
core.assert(!this.isAvailable(), "Entry doesn't have a topic."); },
var topic = this.getTopic();
this.setTopic(null);
topic.setOrder(null);
};
mindplot.BoardEntry.prototype.update = function() removeTopic : function() {
{ core.assert(!this.isAvailable(), "Entry doesn't have a topic.");
var topic = this.getTopic(); var topic = this.getTopic();
this.setTopic(topic); this.setTopic(null);
}; topic.setOrder(null);
},
mindplot.BoardEntry.prototype.setTopic = function(topic, updatePosition)
{
if (!core.Utils.isDefined(updatePosition) || (core.Utils.isDefined(updatePosition) && !updatePosition))
{
updatePosition = true;
}
this._topic = topic; update : function() {
if (core.Utils.isDefined(topic)) var topic = this.getTopic();
{ this.setTopic(topic);
// Fixed positioning. Only for main topic ... },
var position = null;
var topicPosition = topic.getPosition();
// Must update position base on the border limits? setTopic : function(topic, updatePosition) {
if (core.Utils.isDefined(this._xPos)) if (!core.Utils.isDefined(updatePosition) || (core.Utils.isDefined(updatePosition) && !updatePosition)) {
{ updatePosition = true;
position = new core.Point();
// Update x position ...
var topicSize = topic.getSize();
var halfTopicWidh = parseInt(topicSize.width / 2);
halfTopicWidh = (this._xPos > 0) ? halfTopicWidh:-halfTopicWidh;
position.x = this._xPos + halfTopicWidh;
position.y = this.workoutEntryYCenter();
} else {
// Central topic
this._height = topic.getSize().height;
var xPos = topicPosition.x;
var yPos = this.workoutEntryYCenter();
position = new core.Point(xPos, yPos);
} }
// @todo: No esta de mas... this._topic = topic;
topic.setPosition(position); if (core.Utils.isDefined(topic)) {
topic.setOrder(this._order); // Fixed positioning. Only for main topic ...
var position = null;
var topicPosition = topic.getPosition();
// Must update position base on the border limits?
if (core.Utils.isDefined(this._xPos)) {
position = new core.Point();
// Update x position ...
var topicSize = topic.getSize();
var halfTopicWidh = parseInt(topicSize.width / 2);
halfTopicWidh = (this._xPos > 0) ? halfTopicWidh : -halfTopicWidh;
position.x = this._xPos + halfTopicWidh;
position.y = this.workoutEntryYCenter();
} else {
// Central topic
this._height = topic.getSize().height;
var xPos = topicPosition.x;
var yPos = this.workoutEntryYCenter();
position = new core.Point(xPos, yPos);
}
// @todo: No esta de mas...
topic.setPosition(position);
topic.setOrder(this._order);
}
else {
this._height = this._defaultWidth;
}
},
isAvailable : function() {
return !core.Utils.isDefined(this._topic);
},
getOrder : function() {
return this._order;
},
inspect : function() {
return '(order: ' + this._order + ', lowerLimit:' + this._lowerLimit + ', upperLimit: ' + this._upperLimit + ', available:' + this.isAvailable() + ')';
} }
else });
{
this._height = this._defaultWidth;
}
};
mindplot.BoardEntry.prototype.isAvailable = function()
{
return !core.Utils.isDefined(this._topic);
};
mindplot.BoardEntry.prototype.getOrder = function()
{
return this._order;
};
mindplot.BoardEntry.prototype.inspect = function()
{
return '(order: ' + this._order + ', lowerLimit:' + this._lowerLimit + ', upperLimit: ' + this._upperLimit + ', available:' + this.isAvailable() + ')';
};

View File

@ -1,117 +1,119 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.BubbleTip = function(divContainer){ mindplot.BubbleTip = new Class({
this.initialize(divContainer); initialize : function(divContainer) {
}; this.options = {
mindplot.BubbleTip.prototype.initialize=function(divContainer){ panel:null,
this.options={ container:null,
panel:null, divContainer:divContainer,
container:null, content:null,
divContainer:divContainer, onShowComplete:Class.empty,
content:null, onHideComplete:Class.empty,
onShowComplete:Class.empty, width:null,
onHideComplete:Class.empty, height:null,
width:null, form:null
height:null, };
form:null if ($chk(this.options.form))
};
if($chk(this.options.form))
this.scanElements(this.options.form); this.scanElements(this.options.form);
this.buildBubble(); this.buildBubble();
this._isMouseOver=false; this._isMouseOver = false;
this._open=false; this._open = false;
}; },
mindplot.BubbleTip.prototype.scanElements=function(form){ scanElements : function(form) {
$$($(form).getElements('a')).each(function(el) { $$($(form).getElements('a')).each(function(el) {
if (el.href && el.hasClass('bubble') && !el.onclick) { if (el.href && el.hasClass('bubble') && !el.onclick) {
el.addEvent('mouseover',this.click.bindWithEvent(this,el)); el.addEvent('mouseover', this.click.bindWithEvent(this, el));
} }
}, this); }, this);
}; },
mindplot.BubbleTip.prototype.buildBubble=function(){ buildBubble : function() {
var opts = this.options; var opts = this.options;
var panel = new Element('div').addClass('bubbleContainer'); var panel = new Element('div').addClass('bubbleContainer');
if($chk(opts.height)) if ($chk(opts.height))
panel.setStyle('height', opts.height); panel.setStyle('height', opts.height);
if($chk(opts.width)) if ($chk(opts.width))
panel.setStyle('width', opts.width); panel.setStyle('width', opts.width);
this.center = new Element('div').addClass('bubblePart').addClass('bubbleCenterBlue'); this.center = new Element('div').addClass('bubblePart').addClass('bubbleCenterBlue');
this.center.inject(panel); this.center.inject(panel);
if(!$chk(opts.divContainer)) if (!$chk(opts.divContainer)) {
{ opts.divContainer = document.body;
opts.divContainer=document.body;
} }
panel.injectTop(opts.divContainer); panel.injectTop(opts.divContainer);
opts.panel = $(panel); opts.panel = $(panel);
opts.panel.setStyle('opacity',0); opts.panel.setStyle('opacity', 0);
opts.panel.addEvent('mouseover',function(){this._isMouseOver=true;}.bind(this)); opts.panel.addEvent('mouseover', function() {
opts.panel.addEvent('mouseleave',function(event){this.close(event);}.bindWithEvent(this));//this.close.bindWithEvent(this) this._isMouseOver = true;
}.bind(this));
opts.panel.addEvent('mouseleave', function(event) {
this.close(event);
}.bindWithEvent(this));//this.close.bindWithEvent(this)
}; },
mindplot.BubbleTip.prototype.click= function(event, el) { click : function(event, el) {
return this.open(event, el); return this.open(event, el);
}; },
mindplot.BubbleTip.prototype.open= function(event, content, source){ open : function(event, content, source) {
this._isMouseOver=true; this._isMouseOver = true;
this._evt = new Event(event); this._evt = new Event(event);
this.doOpen.delay(500, this,[content,source]); this.doOpen.delay(500, this, [content,source]);
}; },
mindplot.BubbleTip.prototype.doOpen= function(content, source){ doOpen : function(content, source) {
if($chk(this._isMouseOver) &&!$chk(this._open) && !$chk(this._opening)) if ($chk(this._isMouseOver) && !$chk(this._open) && !$chk(this._opening)) {
{ this._opening = true;
this._opening=true;
var container = new Element('div'); var container = new Element('div');
$(content).inject(container); $(content).inject(container);
this.options.content=content; this.options.content = content;
this.options.container=container; this.options.container = container;
$(this.options.container).inject(this.center); $(this.options.container).inject(this.center);
this.init(this._evt,source); this.init(this._evt, source);
$(this.options.panel).effect('opacity',{duration:500, onComplete:function(){this._open=true; this._opening = false;}.bind(this)}).start(0,100); $(this.options.panel).effect('opacity', {duration:500, onComplete:function() {
this._open = true;
this._opening = false;
}.bind(this)}).start(0, 100);
} }
}; },
mindplot.BubbleTip.prototype.updatePosition=function(event){ updatePosition : function(event) {
this._evt = new Event(event); this._evt = new Event(event);
}; },
mindplot.BubbleTip.prototype.close=function(event){ close : function(event) {
this._isMouseOver=false; this._isMouseOver = false;
this.doClose.delay(50,this,new Event(event)); this.doClose.delay(50, this, new Event(event));
}; },
mindplot.BubbleTip.prototype.doClose=function(event){ doClose : function(event) {
if(!$chk(this._isMouseOver) && $chk(this._opening)) if (!$chk(this._isMouseOver) && $chk(this._opening))
this.doClose.delay(500,this,this._evt); this.doClose.delay(500, this, this._evt);
if(!$chk(this._isMouseOver) && $chk(this._open)) if (!$chk(this._isMouseOver) && $chk(this._open)) {
{
this.forceClose(); this.forceClose();
} }
}; },
mindplot.BubbleTip.prototype.forceClose=function(){ forceClose : function() {
this.options.panel.effect('opacity',{duration:100, onComplete:function(){ this.options.panel.effect('opacity', {duration:100, onComplete:function() {
this._open=false; this._open = false;
$(this.options.panel).setStyles({left:0,top:0}); $(this.options.panel).setStyles({left:0,top:0});
$(this.options.container).remove(); $(this.options.container).remove();
}.bind(this)}).start(100,0); }.bind(this)}).start(100, 0);
}; },
mindplot.BubbleTip.prototype.init=function(event,source){ init : function(event, source) {
var opts = this.options; var opts = this.options;
var coordinates = $(opts.panel).getCoordinates(); var coordinates = $(opts.panel).getCoordinates();
var panelHeight = coordinates.height; //not total height, but close enough var panelHeight = coordinates.height; //not total height, but close enough
@ -126,32 +128,32 @@ mindplot.BubbleTip.prototype.init=function(event,source){
var width = $(this.center).getCoordinates().width; var width = $(this.center).getCoordinates().width;
var invert = !(offset.y > panelHeight); //hint goes on the bottom var invert = !(offset.y > panelHeight); //hint goes on the bottom
var invertX = (screenWidth-offset.x > panelWidth); // hint goes on the right var invertX = (screenWidth - offset.x > panelWidth); // hint goes on the right
$(this.options.panel).remove(); $(this.options.panel).remove();
this.buildBubble(); this.buildBubble();
$(this.options.container).inject(this.center); $(this.options.container).inject(this.center);
var height = $(this.center).getCoordinates().height; var height = $(this.center).getCoordinates().height;
$(opts.panel).setStyles({width:width,height:height}); $(opts.panel).setStyles({width:width,height:height});
this.moveTopic(offset, $(opts.panel).getCoordinates().height, $(opts.panel).getCoordinates().width, invert, invertX); this.moveTopic(offset, $(opts.panel).getCoordinates().height, $(opts.panel).getCoordinates().width, invert, invertX);
}; },
mindplot.BubbleTip.prototype.moveTopic=function(offset, panelHeight, panelWidth, invert, invertX){ moveTopic : function(offset, panelHeight, panelWidth, invert, invertX) {
var f = 1, fX=1; var f = 1, fX = 1;
if($chk(invert)) if ($chk(invert))
f=0; f = 0;
if($chk(invertX)) if ($chk(invertX))
fX=0; fX = 0;
var opts = this.options; var opts = this.options;
$(opts.panel).setStyles({left:offset.x - (panelWidth*fX), top:offset.y - (panelHeight*f)}); $(opts.panel).setStyles({left:offset.x - (panelWidth * fX), top:offset.y - (panelHeight * f)});
}; }
mindplot.BubbleTip.getInstance = function(divContainer) });
{
mindplot.BubbleTip.getInstance = function(divContainer) {
var result = mindplot.BubbleTip.instance; var result = mindplot.BubbleTip.instance;
if(!core.Utils.isDefined(result)) if (!core.Utils.isDefined(result)) {
{
mindplot.BubbleTip.instance = new mindplot.BubbleTip(divContainer); mindplot.BubbleTip.instance = new mindplot.BubbleTip(divContainer);
result = mindplot.BubbleTip.instance; result = mindplot.BubbleTip.instance;
} }
return result; return result;
}; }

View File

@ -1,225 +1,209 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.ConnectionLine = function(sourceNode, targetNode, lineType) mindplot.ConnectionLine = new Class({
{ initialize:function(sourceNode, targetNode, lineType) {
core.assert(targetNode, 'parentNode node can not be null'); core.assert(targetNode, 'parentNode node can not be null');
core.assert(sourceNode, 'childNode node can not be null'); core.assert(sourceNode, 'childNode node can not be null');
core.assert(sourceNode != targetNode, 'Cilcular connection'); core.assert(sourceNode != targetNode, 'Cilcular connection');
this._targetTopic = targetNode; this._targetTopic = targetNode;
this._sourceTopic = sourceNode; this._sourceTopic = sourceNode;
var strokeColor = mindplot.ConnectionLine.getStrokeColor(); var strokeColor = mindplot.ConnectionLine.getStrokeColor();
var line; var line;
if (targetNode.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) if (targetNode.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) {
{ line = this._createLine(lineType, mindplot.ConnectionLine.CURVED);
line = this._createLine(lineType,mindplot.ConnectionLine.CURVED); // line = new web2d.Line();
// line = new web2d.Line(); if (line.getType() == "CurvedLine") {
if(line.getType()=="CurvedLine"){ var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); line.setSrcControlPoint(ctrlPoints[0]);
line.setSrcControlPoint(ctrlPoints[0]); line.setDestControlPoint(ctrlPoints[1]);
line.setDestControlPoint(ctrlPoints[1]); }
line.setStroke(1, 'solid', strokeColor);
} else {
line = this._createLine(lineType, mindplot.ConnectionLine.SIMPLE_CURVED);
if (line.getType() == "CurvedLine") {
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
line.setSrcControlPoint(ctrlPoints[0]);
line.setDestControlPoint(ctrlPoints[1]);
}
// line = new web2d.PolyLine();
line.setStroke(1, 'solid', strokeColor);
} }
line.setStroke(1, 'solid', strokeColor);
} else this._line2d = line;
{ },
line = this._createLine(lineType,mindplot.ConnectionLine.SIMPLE_CURVED);
if(line.getType()=="CurvedLine"){ _getCtrlPoints : function(sourceNode, targetNode) {
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition());
line.setSrcControlPoint(ctrlPoints[0]); var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition());
line.setDestControlPoint(ctrlPoints[1]); var deltaX = (srcPos.x - destPos.x) / 3;
return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)];
},
_createLine : function(lineType, defaultStyle) {
if (!core.Utils.isDefined(lineType)) {
lineType = defaultStyle;
} }
// line = new web2d.PolyLine(); lineType = parseInt(lineType);
line.setStroke(1, 'solid', strokeColor); this._lineType = lineType;
var line = null;
switch (lineType) {
case mindplot.ConnectionLine.POLYLINE:
line = new web2d.PolyLine();
break;
case mindplot.ConnectionLine.CURVED:
line = new web2d.CurvedLine();
break;
case mindplot.ConnectionLine.SIMPLE_CURVED:
line = new web2d.CurvedLine();
line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
break;
default:
line = new web2d.Line();
break;
}
return line;
},
setVisibility : function(value) {
this._line2d.setVisibility(value);
},
isVisible : function() {
return this._line2d.isVisible();
},
setOpacity : function(opacity) {
this._line2d.setOpacity(opacity);
},
redraw : function() {
var line2d = this._line2d;
var sourceTopic = this._sourceTopic;
var sourcePosition = sourceTopic.getPosition();
var targetTopic = this._targetTopic;
var targetPosition = targetTopic.getPosition();
var sPos,tPos;
sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition, false);
tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition, false);
line2d.setFrom(tPos.x, tPos.y);
line2d.setTo(sPos.x, sPos.y);
if (line2d.getType() == "CurvedLine") {
var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic);
line2d.setSrcControlPoint(ctrlPoints[0]);
line2d.setDestControlPoint(ctrlPoints[1]);
}
// line2d.moveToBack();
// Add connector ...
this._positionateConnector(targetTopic);
},
_positionateConnector : function(targetTopic) {
var targetPosition = targetTopic.getPosition();
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
var targetTopicSize = targetTopic.getSize();
var y;
if (targetTopic.getShapeType() == mindplot.NodeModel.SHAPE_TYPE_LINE) {
y = targetTopicSize.height;
} else {
y = targetTopicSize.height / 2;
}
y = y - offset;
var connector = targetTopic.getShrinkConnector();
if (Math.sign(targetPosition.x) > 0) {
var x = targetTopicSize.width;
connector.setPosition(x, y);
}
else {
var x = -mindplot.Topic.CONNECTOR_WIDTH;
connector.setPosition(x, y);
}
},
setStroke : function(color, style, opacity) {
var line2d = this._line2d;
this._line2d.setStroke(null, null, color, opacity);
},
addToWorkspace : function(workspace) {
workspace.appendChild(this._line2d);
this._line2d.moveToBack();
},
removeFromWorkspace : function(workspace) {
workspace.removeChild(this._line2d);
},
getTargetTopic : function() {
return this._targetTopic;
},
getSourceTopic : function() {
return this._sourceTopic;
},
getLineType : function() {
return this._lineType;
},
getLine : function() {
return this._line2d;
},
getModel : function() {
return this._model;
},
setModel : function(model) {
this._model = model;
},
getType : function() {
return "ConnectionLine";
},
getId : function() {
return this._model.getId();
},
moveToBack : function() {
this._line2d.moveToBack();
},
moveToFront : function() {
this._line2d.moveToFront();
} }
});
this._line2d = line; mindplot.ConnectionLine.getStrokeColor = function() {
};
mindplot.ConnectionLine.prototype._getCtrlPoints = function(sourceNode, targetNode){
var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition());
var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition());
var deltaX = (srcPos.x -destPos.x)/3;
return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)];
};
mindplot.ConnectionLine.prototype._createLine = function(lineType, defaultStyle){
if(!core.Utils.isDefined(lineType)){
lineType = defaultStyle;
}
lineType = parseInt(lineType);
this._lineType = lineType;
var line = null;
switch(lineType){
case mindplot.ConnectionLine.POLYLINE:
line = new web2d.PolyLine();
break;
case mindplot.ConnectionLine.CURVED:
line = new web2d.CurvedLine();
break;
case mindplot.ConnectionLine.SIMPLE_CURVED:
line = new web2d.CurvedLine();
line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
break;
default:
line = new web2d.Line();
break;
}
return line;
};
mindplot.ConnectionLine.getStrokeColor = function()
{
return '#495879'; return '#495879';
}; };
mindplot.ConnectionLine.prototype.setVisibility = function(value) mindplot.ConnectionLine.SIMPLE = 0;
{ mindplot.ConnectionLine.POLYLINE = 1;
this._line2d.setVisibility(value); mindplot.ConnectionLine.CURVED = 2;
}; mindplot.ConnectionLine.SIMPLE_CURVED = 3;
mindplot.ConnectionLine.prototype.isVisible = function()
{
return this._line2d.isVisible();
};
mindplot.ConnectionLine.prototype.setOpacity = function(opacity){
this._line2d.setOpacity(opacity);
};
mindplot.ConnectionLine.prototype.redraw = function()
{
var line2d = this._line2d;
var sourceTopic = this._sourceTopic;
var sourcePosition = sourceTopic.getPosition();
var targetTopic = this._targetTopic;
var targetPosition = targetTopic.getPosition();
var sPos,tPos;
sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition, false);
tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition, false);
line2d.setFrom(tPos.x, tPos.y);
line2d.setTo(sPos.x, sPos.y);
if(line2d.getType()=="CurvedLine"){
var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic);
line2d.setSrcControlPoint(ctrlPoints[0]);
line2d.setDestControlPoint(ctrlPoints[1]);
}
// line2d.moveToBack();
// Add connector ...
this._positionateConnector(targetTopic);
};
mindplot.ConnectionLine.prototype._positionateConnector = function(targetTopic)
{
var targetPosition = targetTopic.getPosition();
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
var targetTopicSize = targetTopic.getSize();
var y;
if (targetTopic.getShapeType() == mindplot.NodeModel.SHAPE_TYPE_LINE)
{
y = targetTopicSize.height;
} else
{
y = targetTopicSize.height / 2;
}
y = y - offset;
var connector = targetTopic.getShrinkConnector();
if (Math.sign(targetPosition.x) > 0)
{
var x = targetTopicSize.width;
connector.setPosition(x, y);
}
else
{
var x = -mindplot.Topic.CONNECTOR_WIDTH;
connector.setPosition(x, y);
}
};
mindplot.ConnectionLine.prototype.setStroke = function(color, style, opacity)
{
var line2d = this._line2d;
this._line2d.setStroke(null, null, color, opacity);
};
mindplot.ConnectionLine.prototype.addToWorkspace = function(workspace)
{
workspace.appendChild(this._line2d);
this._line2d.moveToBack();
};
mindplot.ConnectionLine.prototype.removeFromWorkspace = function(workspace)
{
workspace.removeChild(this._line2d);
};
mindplot.ConnectionLine.prototype.getTargetTopic = function()
{
return this._targetTopic;
};
mindplot.ConnectionLine.prototype.getSourceTopic = function()
{
return this._sourceTopic;
};
mindplot.ConnectionLine.prototype.getLineType = function(){
return this._lineType;
};
mindplot.ConnectionLine.prototype.getLine = function(){
return this._line2d;
};
mindplot.ConnectionLine.prototype.getModel = function(){
return this._model;
};
mindplot.ConnectionLine.prototype.setModel = function(model){
this._model = model;
};
mindplot.ConnectionLine.prototype.getType = function(){
return "ConnectionLine";
};
mindplot.ConnectionLine.prototype.getId = function(){
return this._model.getId();
};
mindplot.ConnectionLine.prototype.moveToBack = function(){
this._line2d.moveToBack();
};
mindplot.ConnectionLine.prototype.moveToFront = function(){
this._line2d.moveToFront();
};
mindplot.ConnectionLine.SIMPLE=0;
mindplot.ConnectionLine.POLYLINE=1;
mindplot.ConnectionLine.CURVED=2;
mindplot.ConnectionLine.SIMPLE_CURVED=3;

View File

@ -1,170 +1,173 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.ControlPoint = function() mindplot.ControlPoint = new Class({
{ initialize:function() {
this._controlPointsController= [new web2d.Elipse({width:6, height:6, stroke:'1 solid #6589de',fillColor:'gray', visibility:false}), this._controlPointsController = [new web2d.Elipse({width:6, height:6, stroke:'1 solid #6589de',fillColor:'gray', visibility:false}),
new web2d.Elipse({width:6, height:6, stroke:'1 solid #6589de',fillColor:'gray', visibility:false})]; new web2d.Elipse({width:6, height:6, stroke:'1 solid #6589de',fillColor:'gray', visibility:false})];
this._controlLines=[new web2d.Line({strokeColor:"#6589de", strokeWidth:1, opacity:0.3}), this._controlLines = [new web2d.Line({strokeColor:"#6589de", strokeWidth:1, opacity:0.3}),
new web2d.Line({strokeColor:"#6589de", strokeWidth:1, opacity:0.3})]; new web2d.Line({strokeColor:"#6589de", strokeWidth:1, opacity:0.3})];
this._isBinded=false;
this._controlPointsController[0].addEventListener('mousedown',this._mouseDown.bindWithEvent(this, mindplot.ControlPoint.FROM));
this._controlPointsController[0].addEventListener('click',this._mouseClick.bindWithEvent(this));
this._controlPointsController[0].addEventListener('dblclick',this._mouseClick.bindWithEvent(this));
this._controlPointsController[1].addEventListener('mousedown',this._mouseDown.bindWithEvent(this,mindplot.ControlPoint.TO));
this._controlPointsController[1].addEventListener('click',this._mouseClick.bindWithEvent(this));
this._controlPointsController[1].addEventListener('dblclick',this._mouseClick.bindWithEvent(this));
};
mindplot.ControlPoint.prototype.setSide= function(side) { this._isBinded = false;
this._side = side; this._controlPointsController[0].addEventListener('mousedown', this._mouseDown.bindWithEvent(this, mindplot.ControlPoint.FROM));
}; this._controlPointsController[0].addEventListener('click', this._mouseClick.bindWithEvent(this));
this._controlPointsController[0].addEventListener('dblclick', this._mouseClick.bindWithEvent(this));
this._controlPointsController[1].addEventListener('mousedown', this._mouseDown.bindWithEvent(this, mindplot.ControlPoint.TO));
this._controlPointsController[1].addEventListener('click', this._mouseClick.bindWithEvent(this));
this._controlPointsController[1].addEventListener('dblclick', this._mouseClick.bindWithEvent(this));
},
mindplot.ControlPoint.prototype.setLine= function(line) {
if(core.Utils.isDefined(this._line)){
this._removeLine();
}
this._line= line;
this._createControlPoint();
this._endPoint = [];
this._orignalCtrlPoint = [];
this._orignalCtrlPoint[0] = this._controls[0].clone();
this._orignalCtrlPoint[1] = this._controls[1].clone();
this._endPoint[0] = this._line.getLine().getFrom().clone();
this._endPoint[1] = this._line.getLine().getTo().clone();
};
mindplot.ControlPoint.prototype.redraw = function(){ setSide : function(side) {
if(core.Utils.isDefined(this._line)) this._side = side;
},
setLine : function(line) {
if (core.Utils.isDefined(this._line)) {
this._removeLine();
}
this._line = line;
this._createControlPoint(); this._createControlPoint();
}; this._endPoint = [];
this._orignalCtrlPoint = [];
this._orignalCtrlPoint[0] = this._controls[0].clone();
this._orignalCtrlPoint[1] = this._controls[1].clone();
this._endPoint[0] = this._line.getLine().getFrom().clone();
this._endPoint[1] = this._line.getLine().getTo().clone();
},
mindplot.ControlPoint.prototype._createControlPoint = function() { redraw : function() {
this._controls= this._line.getLine().getControlPoints(); if (core.Utils.isDefined(this._line))
var pos = this._line.getLine().getFrom(); this._createControlPoint();
this._controlPointsController[0].setPosition(this._controls[mindplot.ControlPoint.FROM].x+pos.x, this._controls[mindplot.ControlPoint.FROM].y+pos.y-3); },
this._controlLines[0].setFrom(pos.x, pos.y);
this._controlLines[0].setTo(this._controls[mindplot.ControlPoint.FROM].x+pos.x+3, this._controls[mindplot.ControlPoint.FROM].y+pos.y);
pos = this._line.getLine().getTo();
this._controlLines[1].setFrom(pos.x, pos.y);
this._controlLines[1].setTo(this._controls[mindplot.ControlPoint.TO].x+pos.x+3, this._controls[mindplot.ControlPoint.TO].y+pos.y);
this._controlPointsController[1].setPosition(this._controls[mindplot.ControlPoint.TO].x+pos.x, this._controls[mindplot.ControlPoint.TO].y+pos.y-3);
}; _createControlPoint : function() {
this._controls = this._line.getLine().getControlPoints();
var pos = this._line.getLine().getFrom();
this._controlPointsController[0].setPosition(this._controls[mindplot.ControlPoint.FROM].x + pos.x, this._controls[mindplot.ControlPoint.FROM].y + pos.y - 3);
this._controlLines[0].setFrom(pos.x, pos.y);
this._controlLines[0].setTo(this._controls[mindplot.ControlPoint.FROM].x + pos.x + 3, this._controls[mindplot.ControlPoint.FROM].y + pos.y);
pos = this._line.getLine().getTo();
this._controlLines[1].setFrom(pos.x, pos.y);
this._controlLines[1].setTo(this._controls[mindplot.ControlPoint.TO].x + pos.x + 3, this._controls[mindplot.ControlPoint.TO].y + pos.y);
this._controlPointsController[1].setPosition(this._controls[mindplot.ControlPoint.TO].x + pos.x, this._controls[mindplot.ControlPoint.TO].y + pos.y - 3);
mindplot.ControlPoint.prototype._removeLine= function() { },
};
mindplot.ControlPoint.prototype._mouseDown = function(event, point) { _removeLine : function() {
if(!this._isBinded){
this._isBinded=true; },
this._mouseMoveFunction = this._mouseMove.bindWithEvent(this,point);
this._workspace.getScreenManager().addEventListener('mousemove',this._mouseMoveFunction); _mouseDown : function(event, point) {
this._mouseUpFunction = this._mouseUp.bindWithEvent(this,point); if (!this._isBinded) {
this._workspace.getScreenManager().addEventListener('mouseup',this._mouseUpFunction); this._isBinded = true;
this._mouseMoveFunction = this._mouseMove.bindWithEvent(this, point);
this._workspace.getScreenManager().addEventListener('mousemove', this._mouseMoveFunction);
this._mouseUpFunction = this._mouseUp.bindWithEvent(this, point);
this._workspace.getScreenManager().addEventListener('mouseup', this._mouseUpFunction);
}
event.preventDefault();
event.stop();
return false;
},
_mouseMove : function(event, point) {
var screen = this._workspace.getScreenManager();
var pos = screen.getWorkspaceMousePosition(event);
var topic = null;
if (point == 0) {
var cords = core.Utils.calculateRelationShipPointCoordinates(this._line.getSourceTopic(), pos);
this._line.setFrom(cords.x, cords.y);
this._line.setSrcControlPoint(new core.Point(pos.x - cords.x, pos.y - cords.y));
} else {
var cords = core.Utils.calculateRelationShipPointCoordinates(this._line.getTargetTopic(), pos);
this._line.setTo(cords.x, cords.y);
this._line.setDestControlPoint(new core.Point(pos.x - cords.x, pos.y - cords.y));
}
this._controls[point].x = (pos.x - cords.x);
this._controls[point].y = (pos.y - cords.y);
this._controlPointsController[point].setPosition(pos.x - 5, pos.y - 3);
this._controlLines[point].setFrom(cords.x, cords.y);
this._controlLines[point].setTo(pos.x - 2, pos.y);
this._line.getLine().updateLine(point);
/*event.preventDefault();
event.stop();
return false;*/
},
_mouseUp : function(event, point) {
this._workspace.getScreenManager().removeEventListener('mousemove', this._mouseMoveFunction);
this._workspace.getScreenManager().removeEventListener('mouseup', this._mouseUpFunction);
var command = new mindplot.commands.MoveControlPointCommand(this, point);
designer._actionRunner.execute(command); //todo:Uggly!! designer is global!!
this._isBinded = false;
/*event.preventDefault();
event.stop();
return false;*/
},
_mouseClick : function(event) {
event.preventDefault();
event.stop();
return false;
},
setVisibility : function(visible) {
if (visible) {
this._controlLines[0].moveToFront();
this._controlLines[1].moveToFront();
this._controlPointsController[0].moveToFront();
this._controlPointsController[1].moveToFront();
}
this._controlPointsController[0].setVisibility(visible);
this._controlPointsController[1].setVisibility(visible);
this._controlLines[0].setVisibility(visible);
this._controlLines[1].setVisibility(visible);
},
addToWorkspace : function(workspace) {
this._workspace = workspace;
workspace.appendChild(this._controlPointsController[0]);
workspace.appendChild(this._controlPointsController[1]);
workspace.appendChild(this._controlLines[0]);
workspace.appendChild(this._controlLines[1]);
},
removeFromWorkspace : function(workspace) {
this._workspace = null;
workspace.removeChild(this._controlPointsController[0]);
workspace.removeChild(this._controlPointsController[1]);
workspace.removeChild(this._controlLines[0]);
workspace.removeChild(this._controlLines[1]);
},
getControlPoint : function(index) {
return this._controls[index];
},
getOriginalEndPoint : function(index) {
return this._endPoint[index];
},
getOriginalCtrlPoint : function(index) {
return this._orignalCtrlPoint[index];
} }
event.preventDefault(); });
event.stop();
return false;
};
mindplot.ControlPoint.prototype._mouseMove = function(event, point) {
var screen = this._workspace.getScreenManager();
var pos = screen.getWorkspaceMousePosition(event);
var topic = null;
if(point==0){
var cords = core.Utils.calculateRelationShipPointCoordinates(this._line.getSourceTopic(),pos);
this._line.setFrom(cords.x, cords.y);
this._line.setSrcControlPoint(new core.Point(pos.x - cords.x,pos.y - cords.y));
}else{
var cords = core.Utils.calculateRelationShipPointCoordinates(this._line.getTargetTopic(),pos);
this._line.setTo(cords.x, cords.y);
this._line.setDestControlPoint(new core.Point(pos.x - cords.x,pos.y - cords.y));
}
this._controls[point].x=(pos.x - cords.x);
this._controls[point].y=(pos.y - cords.y);
this._controlPointsController[point].setPosition(pos.x-5,pos.y-3);
this._controlLines[point].setFrom(cords.x, cords.y);
this._controlLines[point].setTo(pos.x-2,pos.y);
this._line.getLine().updateLine(point);
/*event.preventDefault();
event.stop();
return false;*/
};
mindplot.ControlPoint.prototype._mouseUp = function(event, point) {
this._workspace.getScreenManager().removeEventListener('mousemove',this._mouseMoveFunction);
this._workspace.getScreenManager().removeEventListener('mouseup',this._mouseUpFunction);
var command = new mindplot.commands.MoveControlPointCommand(this,point);
designer._actionRunner.execute(command); //todo:Uggly!! designer is global!!
this._isBinded=false;
/*event.preventDefault();
event.stop();
return false;*/
};
mindplot.ControlPoint.prototype._mouseClick = function(event){
event.preventDefault();
event.stop();
return false;
};
mindplot.ControlPoint.prototype.setVisibility = function(visible){
if(visible){
this._controlLines[0].moveToFront();
this._controlLines[1].moveToFront();
this._controlPointsController[0].moveToFront();
this._controlPointsController[1].moveToFront();
}
this._controlPointsController[0].setVisibility(visible);
this._controlPointsController[1].setVisibility(visible);
this._controlLines[0].setVisibility(visible);
this._controlLines[1].setVisibility(visible);
};
mindplot.ControlPoint.prototype.addToWorkspace = function(workspace){
this._workspace = workspace;
workspace.appendChild(this._controlPointsController[0]);
workspace.appendChild(this._controlPointsController[1]);
workspace.appendChild(this._controlLines[0]);
workspace.appendChild(this._controlLines[1]);
};
mindplot.ControlPoint.prototype.removeFromWorkspace = function(workspace){
this._workspace = null;
workspace.removeChild(this._controlPointsController[0]);
workspace.removeChild(this._controlPointsController[1]);
workspace.removeChild(this._controlLines[0]);
workspace.removeChild(this._controlLines[1]);
};
mindplot.ControlPoint.prototype.getControlPoint = function(index){
return this._controls[index];
};
mindplot.ControlPoint.prototype.getOriginalEndPoint = function(index){
return this._endPoint[index];
};
mindplot.ControlPoint.prototype.getOriginalCtrlPoint = function(index){
return this._orignalCtrlPoint[index];
};
mindplot.ControlPoint.FROM = 0; mindplot.ControlPoint.FROM = 0;
mindplot.ControlPoint.TO = 1; mindplot.ControlPoint.TO = 1;

View File

@ -1,24 +1,29 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.DesignerActionRunner = new Class({ mindplot.DesignerActionRunner = new Class({
execute:function(command) initialize: function(designer) {
{ this._designer = designer;
this._undoManager = new mindplot.DesignerUndoManager();
this._context = new mindplot.CommandContext(this._designer);
},
execute:function(command) {
core.assert(command, "command can not be null"); core.assert(command, "command can not be null");
// Execute action ... // Execute action ...
command.execute(this._context); command.execute(this._context);
@ -30,22 +35,16 @@ mindplot.DesignerActionRunner = new Class({
var event = this._undoManager._buildEvent(); var event = this._undoManager._buildEvent();
this._designer._fireEvent("change", event); this._designer._fireEvent("change", event);
}, },
initialize: function(designer)
{ undo: function() {
this._designer = designer;
this._undoManager = new mindplot.DesignerUndoManager();
this._context = new mindplot.CommandContext(this._designer);
},
undo: function()
{
this._undoManager.execUndo(this._context); this._undoManager.execUndo(this._context);
// Fire event // Fire event
var event = this._undoManager._buildEvent(); var event = this._undoManager._buildEvent();
this._designer._fireEvent("change", event); this._designer._fireEvent("change", event);
}, },
redo: function()
{ redo: function() {
this._undoManager.execRedo(this._context); this._undoManager.execRedo(this._context);
// Fire event // Fire event
@ -53,33 +52,28 @@ mindplot.DesignerActionRunner = new Class({
this._designer._fireEvent("change", event); this._designer._fireEvent("change", event);
}, },
markAsChangeBase: function()
{ markAsChangeBase: function() {
return this._undoManager.markAsChangeBase(); return this._undoManager.markAsChangeBase();
}, },
hasBeenChanged: function() hasBeenChanged: function() {
{
return this._undoManager.hasBeenChanged(); return this._undoManager.hasBeenChanged();
} }
}); });
mindplot.CommandContext = new Class({ mindplot.CommandContext = new Class({
initialize: function(designer) initialize: function(designer) {
{
this._designer = designer; this._designer = designer;
}, },
findTopics:function(topicsIds) findTopics:function(topicsIds) {
{
var designerTopics = this._designer._topics; var designerTopics = this._designer._topics;
if (!(topicsIds instanceof Array)) if (!(topicsIds instanceof Array)) {
{
topicsIds = [topicsIds]; topicsIds = [topicsIds];
} }
var result = designerTopics.filter(function(topic) { var result = designerTopics.filter(function(topic) {
var found = false; var found = false;
if (topic != null) if (topic != null) {
{
var topicId = topic.getId(); var topicId = topic.getId();
found = topicsIds.contains(topicId); found = topicsIds.contains(topicId);
} }
@ -88,32 +82,27 @@ mindplot.CommandContext = new Class({
}); });
return result; return result;
}, },
deleteTopic:function(topic) deleteTopic:function(topic) {
{
this._designer._removeNode(topic); this._designer._removeNode(topic);
}, },
createTopic:function(model, isVisible) createTopic:function(model, isVisible) {
{
core.assert(model, "model can not be null"); core.assert(model, "model can not be null");
var topic = this._designer._nodeModelToNodeGraph(model, isVisible); var topic = this._designer._nodeModelToNodeGraph(model, isVisible);
return topic; return topic;
}, },
createModel:function() createModel:function() {
{
var mindmap = this._designer.getMindmap(); var mindmap = this._designer.getMindmap();
var model = mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE); var model = mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE);
return model; return model;
}, },
connect:function(childTopic, parentTopic, isVisible) connect:function(childTopic, parentTopic, isVisible) {
{
childTopic.connectTo(parentTopic, this._designer._workspace, isVisible); childTopic.connectTo(parentTopic, this._designer._workspace, isVisible);
} , } ,
disconnect:function(topic) disconnect:function(topic) {
{
topic.disconnect(this._designer._workspace); topic.disconnect(this._designer._workspace);
}, },
createRelationship:function(model){ createRelationship:function(model) {
core.assert(model, "model cannot be null"); core.assert(model, "model cannot be null");
var relationship = this._designer.createRelationship(model); var relationship = this._designer.createRelationship(model);
return relationship; return relationship;
@ -121,27 +110,25 @@ mindplot.CommandContext = new Class({
removeRelationship:function(model) { removeRelationship:function(model) {
this._designer.removeRelationship(model); this._designer.removeRelationship(model);
}, },
findRelationships:function(lineIds){ findRelationships:function(lineIds) {
var result = []; var result = [];
lineIds.forEach(function(lineId, index){ lineIds.forEach(function(lineId, index) {
var line = this._designer._relationships[lineId]; var line = this._designer._relationships[lineId];
if(core.Utils.isDefined(line)){ if (core.Utils.isDefined(line)) {
result.push(line); result.push(line);
} }
}.bind(this)); }.bind(this));
return result; return result;
}, },
getSelectedRelationshipLines:function(){ getSelectedRelationshipLines:function() {
return this._designer.getSelectedRelationshipLines(); return this._designer.getSelectedRelationshipLines();
} }
}); });
mindplot.DesignerActionRunner.setInstance = function(actionRunner) mindplot.DesignerActionRunner.setInstance = function(actionRunner) {
{
mindplot.DesignerActionRunner._instance = actionRunner; mindplot.DesignerActionRunner._instance = actionRunner;
}; };
mindplot.DesignerActionRunner.getInstance = function() mindplot.DesignerActionRunner.getInstance = function() {
{
return mindplot.DesignerActionRunner._instance; return mindplot.DesignerActionRunner._instance;
}; };

View File

@ -1,92 +1,83 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.DesignerUndoManager = new Class({ mindplot.DesignerUndoManager = new Class({
initialize: function() initialize: function() {
{
this._undoQueue = []; this._undoQueue = [];
this._redoQueue = []; this._redoQueue = [];
this._baseId = 0; this._baseId = 0;
}, },
enqueue:function(command)
{ enqueue:function(command) {
core.assert(command, "Command can not be null"); core.assert(command, "Command can not be null");
var length = this._undoQueue.length; var length = this._undoQueue.length;
if (command.discartDuplicated && length > 0) if (command.discartDuplicated && length > 0) {
{
// Skip duplicated events ... // Skip duplicated events ...
var lastItem = this._undoQueue[length - 1]; var lastItem = this._undoQueue[length - 1];
if (lastItem.discartDuplicated != command.discartDuplicated) if (lastItem.discartDuplicated != command.discartDuplicated) {
{
this._undoQueue.push(command); this._undoQueue.push(command);
} }
} else } else {
{
this._undoQueue.push(command); this._undoQueue.push(command);
} }
this._redoQueue = []; this._redoQueue = [];
}, },
execUndo: function(commandContext)
{ execUndo: function(commandContext) {
if (this._undoQueue.length > 0) if (this._undoQueue.length > 0) {
{
var command = this._undoQueue.pop(); var command = this._undoQueue.pop();
this._redoQueue.push(command); this._redoQueue.push(command);
command.undoExecute(commandContext); command.undoExecute(commandContext);
} }
}, },
execRedo: function(commandContext)
{ execRedo: function(commandContext) {
if (this._redoQueue.length > 0) if (this._redoQueue.length > 0) {
{
var command = this._redoQueue.pop(); var command = this._redoQueue.pop();
this._undoQueue.push(command); this._undoQueue.push(command);
command.execute(commandContext); command.execute(commandContext);
} }
}, },
_buildEvent: function()
{ _buildEvent: function() {
return {undoSteps: this._undoQueue.length, redoSteps:this._redoQueue.length}; return {undoSteps: this._undoQueue.length, redoSteps:this._redoQueue.length};
}, },
markAsChangeBase: function()
{ markAsChangeBase: function() {
var undoLenght = this._undoQueue.length; var undoLenght = this._undoQueue.length;
if (undoLenght > 0) if (undoLenght > 0) {
{
var command = this._undoQueue[undoLenght - 1]; var command = this._undoQueue[undoLenght - 1];
this._baseId = command.getId(); this._baseId = command.getId();
} else } else {
{
this._baseId = 0; this._baseId = 0;
} }
}, },
hasBeenChanged: function()
{ hasBeenChanged: function() {
var result = true; var result = true;
var undoLenght = this._undoQueue.length; var undoLenght = this._undoQueue.length;
if (undoLenght == 0 && this._baseId == 0) if (undoLenght == 0 && this._baseId == 0) {
{
result = false; result = false;
} else if(undoLenght>0) } else if (undoLenght > 0) {
{
var command = this._undoQueue[undoLenght - 1]; var command = this._undoQueue[undoLenght - 1];
result = (this._baseId != command.getId()); result = (this._baseId != command.getId());
} }
return result; return result;
}}); }
});

View File

@ -20,7 +20,6 @@ mindplot.DragManager = function(workspace)
{ {
this._workspace = workspace; this._workspace = workspace;
this._listeners = {}; this._listeners = {};
var dragManager = this;
}; };
mindplot.DragManager.prototype.add = function(node) mindplot.DragManager.prototype.add = function(node)

View File

@ -1,253 +1,227 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.DragPivot = function() mindplot.DragPivot = new Class({
{ initialize:function() {
this._position = new core.Point(); this._position = new core.Point();
this._size = mindplot.DragTopic.PIVOT_SIZE; this._size = mindplot.DragTopic.PIVOT_SIZE;
this._line = null; this._line = null;
this._straightLine = this._buildStraightLine(); this._straightLine = this._buildStraightLine();
this._curvedLine = this._buildCurvedLine(); this._curvedLine = this._buildCurvedLine();
this._dragPivot = this._buildRect(); this._dragPivot = this._buildRect();
this._connectRect = this._buildRect(); this._connectRect = this._buildRect();
this._targetTopic = null; this._targetTopic = null;
}; },
mindplot.DragPivot.prototype.getTargetTopic = function() getTargetTopic : function() {
{ return this._targetTopic;
return this._targetTopic; },
};
mindplot.DragPivot.prototype._buildStraightLine = function() _buildStraightLine : function() {
{ var line = new web2d.CurvedLine();
var line = new web2d.CurvedLine(); line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
line.setStyle(web2d.CurvedLine.SIMPLE_LINE); line.setStroke(1, 'solid', '#CC0033');
line.setStroke(1, 'solid', '#CC0033'); line.setOpacity(0.4);
line.setOpacity(0.4); line.setVisibility(false);
line.setVisibility(false); return line;
return line; },
};
mindplot.DragPivot.prototype._buildCurvedLine = function() _buildCurvedLine : function() {
{ var line = new web2d.CurvedLine();
var line = new web2d.CurvedLine(); line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
line.setStyle(web2d.CurvedLine.SIMPLE_LINE); line.setStroke(1, 'solid', '#CC0033');
line.setStroke(1, 'solid', '#CC0033'); line.setOpacity(0.4);
line.setOpacity(0.4); line.setVisibility(false);
line.setVisibility(false); return line;
return line; },
};
mindplot.DragPivot.prototype._redraw = function(pivotPosition) _redraw : function(pivotPosition) {
{ // Update line position.
// Update line position. core.assert(this.getTargetTopic(), 'Illegal invocation. Target node can not be null');
core.assert(this.getTargetTopic(), 'Illegal invocation. Target node can not be null');
var pivotRect = this._getPivotRect(); var pivotRect = this._getPivotRect();
var currentPivotPosition = pivotRect.getPosition(); var currentPivotPosition = pivotRect.getPosition();
// Pivot position has not changed. In this case, position change is not required. // Pivot position has not changed. In this case, position change is not required.
var targetTopic = this.getTargetTopic(); var targetTopic = this.getTargetTopic();
if (currentPivotPosition.x != pivotPosition.x || currentPivotPosition.y != pivotPosition.y) if (currentPivotPosition.x != pivotPosition.x || currentPivotPosition.y != pivotPosition.y) {
{ var position = this._position;
var position = this._position; var fromPoint = targetTopic.workoutIncomingConnectionPoint(position);
var fromPoint = targetTopic.workoutIncomingConnectionPoint(position);
// Calculate pivot connection point ... // Calculate pivot connection point ...
var size = this._size; var size = this._size;
var targetPosition = targetTopic.getPosition(); var targetPosition = targetTopic.getPosition();
var line = this._line; var line = this._line;
// Update Line position. // Update Line position.
var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, position); var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, position);
var pivotPoint = mindplot.util.Shape.calculateRectConnectionPoint(position, size, isAtRight); var pivotPoint = mindplot.util.Shape.calculateRectConnectionPoint(position, size, isAtRight);
line.setFrom(pivotPoint.x, pivotPoint.y); line.setFrom(pivotPoint.x, pivotPoint.y);
// Update rect position // Update rect position
pivotRect.setPosition(pivotPosition.x, pivotPosition.y); pivotRect.setPosition(pivotPosition.x, pivotPosition.y);
// Display elements if it's required... // Display elements if it's required...
if (!pivotRect.isVisible()) if (!pivotRect.isVisible()) {
{ // Make line visible only when the position has been already changed.
// Make line visible only when the position has been already changed. // This solve several strange effects ;)
// This solve several strange effects ;) var targetPoint = targetTopic.workoutIncomingConnectionPoint(pivotPoint);
var targetPoint = targetTopic.workoutIncomingConnectionPoint(pivotPoint); line.setTo(targetPoint.x, targetPoint.y);
line.setTo(targetPoint.x, targetPoint.y);
this.setVisibility(true); this.setVisibility(true);
}
} }
},
setPosition : function(point) {
this._position = point;
// Update visual position.
var size = this.getSize();
var cx = point.x - (parseInt(size.width) / 2);
var cy = point.y - (parseInt(size.height) / 2);
// Update line ...
if (this.getTargetTopic()) {
var pivotPosition = {x:cx,y:cy};
this._redraw(pivotPosition);
}
},
getPosition : function() {
return this._position;
},
_buildRect : function() {
var size = this._size;
var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'};
var rect = new web2d.Rect(0, rectAttributes);
rect.setVisibility(false);
return rect;
},
_buildConnectRect : function() {
var size = this._size;
var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'};
var result = new web2d.Rect(0, rectAttributes);
return result;
},
_getPivotRect : function() {
return this._dragPivot;
},
getSize : function() {
var elem2d = this._getPivotRect();
return elem2d.getSize();
},
setVisibility : function(value) {
var pivotRect = this._getPivotRect();
pivotRect.setVisibility(value);
var connectRect = this._connectRect;
connectRect.setVisibility(value);
if (core.Utils.isDefined(this._line)) {
this._line.setVisibility(value);
}
},
addToWorkspace : function(workspace) {
var pivotRect = this._getPivotRect();
workspace.appendChild(pivotRect);
var connectToRect = this._connectRect;
workspace.appendChild(connectToRect);
// Add a hidden straight line ...
var straighLine = this._straightLine;
straighLine.setVisibility(false);
workspace.appendChild(straighLine);
straighLine.moveToBack();
// Add a hidden curved line ...
var curvedLine = this._curvedLine;
curvedLine.setVisibility(false);
workspace.appendChild(curvedLine);
curvedLine.moveToBack();
// Add a connect rect ...
var connectRect = this._connectRect;
connectRect.setVisibility(false);
workspace.appendChild(connectRect);
connectRect.moveToBack();
},
removeFromWorkspace : function(workspace) {
var shape = this._getPivotRect();
workspace.removeChild(shape);
var connectToRect = this._connectRect;
workspace.removeChild(connectToRect);
if (core.Utils.isDefined(this._straightLine)) {
workspace.removeChild(this._straightLine);
}
if (core.Utils.isDefined(this._curvedLine)) {
workspace.removeChild(this._curvedLine);
}
},
connectTo : function(targetTopic) {
core.assert(!this._outgoingLine, 'Could not connect an already connected node');
core.assert(targetTopic != this, 'Cilcular connection are not allowed');
core.assert(targetTopic, 'parent can not be null');
this._targetTopic = targetTopic;
if (targetTopic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) {
this._line = this._straightLine;
} else {
this._line = this._curvedLine;
}
// Connected to Rect ...
var connectRect = this._connectRect;
var targetSize = targetTopic.getSize();
var width = targetSize.width;
var height = targetSize.height;
connectRect.setSize(width, height);
var targetPosition = targetTopic.getPosition();
var cx = Math.ceil(targetPosition.x - (width / 2));
var cy = Math.ceil(targetPosition.y - (height / 2));
connectRect.setPosition(cx, cy);
// Change elements position ...
var pivotRect = this._getPivotRect();
pivotRect.moveToFront();
},
disconnect : function(workspace) {
core.assert(workspace, 'workspace can not be null.');
core.assert(this._targetTopic, 'There are not connected topic.');
this.setVisibility(false);
this._targetTopic = null;
this._line = null;
} }
}; });
mindplot.DragPivot.prototype.setPosition = function(point)
{
this._position = point;
// Update visual position.
var pivotRect = this._getPivotRect();
var size = this.getSize();
var cx = point.x - (parseInt(size.width) / 2);
var cy = point.y - (parseInt(size.height) / 2);
// Update line ...
if (this.getTargetTopic())
{
var pivotPosition = {x:cx,y:cy};
this._redraw(pivotPosition);
}
};
mindplot.DragPivot.prototype.getPosition = function()
{
return this._position;
};
mindplot.DragPivot.prototype._buildRect = function()
{
var size = this._size;
var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'};
var rect = new web2d.Rect(0, rectAttributes);
rect.setVisibility(false);
return rect;
};
mindplot.DragPivot.prototype._buildConnectRect = function()
{
var size = this._size;
var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'};
var result = new web2d.Rect(0, rectAttributes);
return result;
};
mindplot.DragPivot.prototype._getPivotRect = function()
{
return this._dragPivot;
};
mindplot.DragPivot.prototype.getSize = function()
{
var elem2d = this._getPivotRect();
return elem2d.getSize();
};
mindplot.DragPivot.prototype.setVisibility = function(value)
{
var pivotRect = this._getPivotRect();
pivotRect.setVisibility(value);
var connectRect = this._connectRect;
connectRect.setVisibility(value);
if (core.Utils.isDefined(this._line))
{
this._line.setVisibility(value);
}
};
mindplot.DragPivot.prototype.addToWorkspace = function(workspace)
{
var pivotRect = this._getPivotRect();
workspace.appendChild(pivotRect);
var connectToRect = this._connectRect;
workspace.appendChild(connectToRect);
// Add a hidden straight line ...
var straighLine = this._straightLine;
straighLine.setVisibility(false);
workspace.appendChild(straighLine);
straighLine.moveToBack();
// Add a hidden curved line ...
var curvedLine = this._curvedLine;
curvedLine.setVisibility(false);
workspace.appendChild(curvedLine);
curvedLine.moveToBack();
// Add a connect rect ...
var connectRect = this._connectRect;
connectRect.setVisibility(false);
workspace.appendChild(connectRect);
connectRect.moveToBack();
};
mindplot.DragPivot.prototype.removeFromWorkspace = function(workspace)
{
var shape = this._getPivotRect();
workspace.removeChild(shape);
var connectToRect = this._connectRect;
workspace.removeChild(connectToRect);
if (core.Utils.isDefined(this._straightLine))
{
workspace.removeChild(this._straightLine);
}
if (core.Utils.isDefined(this._curvedLine))
{
workspace.removeChild(this._curvedLine);
}
};
mindplot.DragPivot.prototype.connectTo = function(targetTopic)
{
core.assert(!this._outgoingLine, 'Could not connect an already connected node');
core.assert(targetTopic != this, 'Cilcular connection are not allowed');
core.assert(targetTopic, 'parent can not be null');
this._targetTopic = targetTopic;
if (targetTopic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
{
this._line = this._straightLine;
} else
{
this._line = this._curvedLine;
}
// Show pivot ...
var line = this._line;
// Connected to Rect ...
var connectRect = this._connectRect;
var targetSize = targetTopic.getSize();
var width = targetSize.width;
var height = targetSize.height;
connectRect.setSize(width, height);
var targetPosition = targetTopic.getPosition();
var cx = Math.ceil(targetPosition.x - (width / 2));
var cy = Math.ceil(targetPosition.y - (height / 2));
connectRect.setPosition(cx, cy);
// Change elements position ...
var pivotRect = this._getPivotRect();
pivotRect.moveToFront();
};
mindplot.DragPivot.prototype.disconnect = function(workspace)
{
core.assert(workspace, 'workspace can not be null.');
core.assert(this._targetTopic, 'There are not connected topic.');
this.setVisibility(false);
this._targetTopic = null;
this._line = null;
};

View File

@ -1,131 +1,115 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.DragTopicPositioner = function(layoutManager) mindplot.DragTopicPositioner = new Class({
{ initialize:function(layoutManager) {
core.assert(layoutManager, 'layoutManager can not be null'); core.assert(layoutManager, 'layoutManager can not be null');
this._layoutManager = layoutManager; this._layoutManager = layoutManager;
this._topics = layoutManager.getDesigner()._getTopics(); this._topics = layoutManager.getDesigner()._getTopics();
this._workspace = layoutManager.getDesigner().getWorkSpace(); this._workspace = layoutManager.getDesigner().getWorkSpace();
}; },
mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic) positionateDragTopic : function(dragTopic) {
{ // Workout the real position of the element on the board.
// Workout the real position of the element on the board. var dragTopicPosition = dragTopic.getPosition();
var dragTopicPosition = dragTopic.getPosition(); var draggedTopic = dragTopic.getDraggedTopic();
var draggedTopic = dragTopic.getDraggedTopic();
// Topic can be connected ? // Topic can be connected ?
this._checkDragTopicConnection(dragTopic); this._checkDragTopicConnection(dragTopic);
// Position topic in the board // Position topic in the board
if (dragTopic.isConnected()) if (dragTopic.isConnected()) {
{ var targetTopic = dragTopic.getConnectedToTopic();
var targetTopic = dragTopic.getConnectedToTopic(); var topicBoard = this._layoutManager.getTopicBoardForTopic(targetTopic);
var topicBoard = this._layoutManager.getTopicBoardForTopic(targetTopic); topicBoard.positionateDragTopic(dragTopic);
topicBoard.positionateDragTopic(dragTopic); }
},
_checkDragTopicConnection : function(dragTopic) {
var topics = this._topics;
// Must be disconnected from their current connection ?.
var mainTopicToMainTopicConnection = this._lookUpForMainTopicToMainTopicConnection(dragTopic);
var currentConnection = dragTopic.getConnectedToTopic();
if (core.Utils.isDefined(currentConnection)) {
// MainTopic->MainTopicConnection.
if (currentConnection.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE) {
if (mainTopicToMainTopicConnection != currentConnection) {
dragTopic.disconnect(this._workspace);
}
}
else if (currentConnection.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) {
// Distance if greater that the allowed.
var dragXPosition = dragTopic.getPosition().x;
var currentXPosition = currentConnection.getPosition().x;
if (core.Utils.isDefined(mainTopicToMainTopicConnection)) {
// I have to change the current connection to a main topic.
dragTopic.disconnect(this._workspace);
} else
if (Math.abs(dragXPosition - currentXPosition) > mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) {
dragTopic.disconnect(this._workspace);
}
}
}
// Finally, connect nodes ...
if (!dragTopic.isConnected()) {
var centalTopic = topics[0];
if (core.Utils.isDefined(mainTopicToMainTopicConnection)) {
dragTopic.connectTo(mainTopicToMainTopicConnection);
} else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) {
dragTopic.connectTo(centalTopic);
}
}
},
_lookUpForMainTopicToMainTopicConnection : function(dragTopic) {
var topics = this._topics;
var result = null;
var clouserDistance = -1;
var draggedNode = dragTopic.getDraggedTopic();
var distance = null;
// Check MainTopic->MainTopic connection...
for (var i = 0; i < topics.length; i++) {
var targetTopic = topics[i];
var position = dragTopic.getPosition();
if (targetTopic.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode) {
var canBeConnected = dragTopic.canBeConnectedTo(targetTopic);
if (canBeConnected) {
var targetPosition = targetTopic.getPosition();
var fix = position.y > targetPosition.y;
var gap = 0;
if (targetTopic._getChildren().length > 0) {
gap = Math.abs(targetPosition.y - targetTopic._getChildren()[0].getPosition().y)
}
var yDistance = Math.abs(position.y - fix * gap - targetPosition.y);
if (distance == null || yDistance < distance) {
result = targetTopic;
distance = yDistance;
}
}
}
}
return result;
} }
}; });
mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE = 400; mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE = 400;
mindplot.DragTopicPositioner.prototype._checkDragTopicConnection = function(dragTopic)
{
var topics = this._topics;
// Must be disconnected from their current connection ?.
var mainTopicToMainTopicConnection = this._lookUpForMainTopicToMainTopicConnection(dragTopic);
var currentConnection = dragTopic.getConnectedToTopic();
if (core.Utils.isDefined(currentConnection))
{
// MainTopic->MainTopicConnection.
if (currentConnection.getType()==mindplot.NodeModel.MAIN_TOPIC_TYPE)
{
if(mainTopicToMainTopicConnection != currentConnection)
{
dragTopic.disconnect(this._workspace);
}
}
else if (currentConnection.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
{
// Distance if greater that the allowed.
var dragXPosition = dragTopic.getPosition().x;
var currentXPosition = currentConnection.getPosition().x;
if(core.Utils.isDefined(mainTopicToMainTopicConnection))
{
// I have to change the current connection to a main topic.
dragTopic.disconnect(this._workspace);
}else
if (Math.abs(dragXPosition-currentXPosition) > mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE)
{
dragTopic.disconnect(this._workspace);
}
}
}
// Finally, connect nodes ...
if (!dragTopic.isConnected())
{
var centalTopic = topics[0];
if (core.Utils.isDefined(mainTopicToMainTopicConnection))
{
dragTopic.connectTo(mainTopicToMainTopicConnection);
} else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE)
{
dragTopic.connectTo(centalTopic);
}
}
};
mindplot.DragTopicPositioner.prototype._lookUpForMainTopicToMainTopicConnection = function(dragTopic)
{
var topics = this._topics;
var result = null;
var clouserDistance = -1;
var draggedNode = dragTopic.getDraggedTopic();
var distance = null;
// Check MainTopic->MainTopic connection...
for (var i = 0; i < topics.length; i++)
{
var targetTopic = topics[i];
var position = dragTopic.getPosition();
if (targetTopic.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode)
{
var canBeConnected = dragTopic.canBeConnectedTo(targetTopic);
if (canBeConnected)
{
var targetPosition = targetTopic.getPosition();
var fix = position.y>targetPosition.y;
var gap = 0;
if(targetTopic._getChildren().length>0){
gap = Math.abs(targetPosition.y - targetTopic._getChildren()[0].getPosition().y)
}
var yDistance = Math.abs(position.y -fix*gap - targetPosition.y);
if(distance==null || yDistance<distance)
{
result = targetTopic;
distance = yDistance;
}
}
}
}
return result;
};

View File

@ -4,5 +4,4 @@ mindplot.EditorOptions =
// LayoutManager:"FreeMindLayout", // LayoutManager:"FreeMindLayout",
textEditor:"TextEditor" textEditor:"TextEditor"
// textEditor:"RichTextEditor" // textEditor:"RichTextEditor"
}; };

View File

@ -1,41 +1,39 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.EditorProperties = function() mindplot.EditorProperties = new Class({
{ initialize:function() {
this._zoom = 0; this._zoom = 0;
this._position = 0; this._position = 0;
}; },
mindplot.EditorProperties.prototype.setZoom = function(zoom) setZoom : function(zoom) {
{ this._zoom = zoom;
this._zoom = zoom; },
};
mindplot.EditorProperties.prototype.getZoom = function() getZoom : function() {
{ return this._zoom;
return this._zoom; },
};
mindplot.EditorProperties.prototype.asProperties = function() asProperties : function() {
{ return "zoom=" + this._zoom + "\n";
return "zoom=" + this._zoom + "\n"; }
}; });

View File

@ -1,17 +1,16 @@
mindplot.EventBus = new Class({ mindplot.EventBus = new Class({
Extends:Options,
Implements:Events,
options: { options: {
}, },
initialize: function(options) { initialize: function(options) {
this.setOptions(options); this.setOptions(options);
} }
}); });
mindplot.EventBus.implement(new Events);
mindplot.EventBus.implement(new Options);
mindplot.EventBus.events ={ mindplot.EventBus.events = {
NodeResizeEvent:'NodeResizeEvent', NodeResizeEvent:'NodeResizeEvent',
NodeMoveEvent:'NodeMoveEvent', NodeMoveEvent:'NodeMoveEvent',
NodeDisconnectEvent:'NodeDisconnectEvent', NodeDisconnectEvent:'NodeDisconnectEvent',

View File

@ -1,324 +1,287 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/
mindplot.FixedDistanceBoard = function(defaultHeight, topic, layoutManager)
{
this._topic = topic;
this._layoutManager = layoutManager;
var reference = topic.getPosition();
mindplot.FixedDistanceBoard.superClass.initialize.call(this, defaultHeight, reference);
this._height = defaultHeight;
this._entries = [];
};
objects.extend(mindplot.FixedDistanceBoard, mindplot.Board);
mindplot.FixedDistanceBoard.prototype.getHeight = function()
{
return this._height;
};
mindplot.FixedDistanceBoard.prototype.lookupEntryByOrder = function(order)
{
var result = null;
var entries = this._entries;
if (order < entries.length)
{
result = entries[order];
}
if (result == null)
{
var defaultHeight = this._defaultWidth;
var reference = this.getReferencePoint();
if (entries.length == 0)
{
var yReference = reference.y;
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
} else
{
var entriesLenght = entries.length;
var lastEntry = entries[entriesLenght - 1];
var lowerLimit = lastEntry.getUpperLimit();
var upperLimit = lowerLimit + defaultHeight;
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1);
}
}
return result;
};
mindplot.FixedDistanceBoard.prototype.createBoardEntry = function(lowerLimit, upperLimit, order)
{
var result = new mindplot.BoardEntry(lowerLimit, upperLimit, order);
var xPos = this.workoutXBorderDistance();
result.setXPosition(xPos);
return result;
};
mindplot.FixedDistanceBoard.prototype.updateReferencePoint = function()
{
var entries = this._entries;
var parentTopic = this.getTopic();
var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition());
var referencePoint = this.getReferencePoint();
var yOffset = parentPosition.y - referencePoint.y;
for (var i = 0; i < entries.length; i++)
{
var entry = entries[i];
if(core.Utils.isDefined(entry)){
var upperLimit = entry.getUpperLimit() + yOffset;
var lowerLimit = entry.getLowerLimit() + yOffset;
entry.setUpperLimit(upperLimit);
entry.setLowerLimit(lowerLimit);
// Fix x position ...
var xPos = this.workoutXBorderDistance();
entry.setXPosition(xPos);
entry.update();
}
}
this._referencePoint = parentPosition.clone();
};
mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60;
/**
* This x distance doesn't take into account the size of the shape.
*/ */
mindplot.FixedDistanceBoard.prototype.workoutXBorderDistance = function()
{
var topic = this.getTopic();
var topicPosition = topic.getPosition(); mindplot.FixedDistanceBoard = new Class({
var topicSize = topic.getSize(); Extends:mindplot.Board,
var halfTargetWidth = topicSize.width / 2; initialize:function(defaultHeight, topic, layoutManager) {
var result; this._topic = topic;
if (topicPosition.x >= 0) this._layoutManager = layoutManager;
{ var reference = topic.getPosition();
// It's at right. this.parent(defaultHeight, reference);
result = topicPosition.x + halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE; this._height = defaultHeight;
} else this._entries = [];
{ },
result = topicPosition.x - (halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE);
}
return result;
};
mindplot.FixedDistanceBoard.prototype.getTopic = function() getHeight : function() {
{ return this._height;
return this._topic; },
};
mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6; lookupEntryByOrder : function(order) {
var result = null;
mindplot.FixedDistanceBoard.prototype.freeEntry = function(entry) var entries = this._entries;
{ if (order < entries.length) {
var newEntries = []; result = entries[order];
var entries = this._entries;
var order = 0;
for (var i = 0; i < entries.length; i++)
{
var e = entries[i];
if (e == entry)
{
order++;
} }
newEntries[order] = e;
order++;
}
this._entries = newEntries;
};
mindplot.FixedDistanceBoard.prototype.repositionate = function() if (result == null) {
{ var defaultHeight = this._defaultWidth;
// Workout width and update topic height.
var entries = this._entries;
var height = 0;
var model = this._topic.getModel();
if (entries.length >= 1 && !model.areChildrenShrinked())
{
for (var i = 0; i < entries.length; i++)
{
var e = entries[i];
if (e && e.getTopic())
{
var topic = e.getTopic();
var topicBoard = this._layoutManager.getTopicBoardForTopic(topic);
var topicBoardHeight = topicBoard.getHeight();
height += topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
}
}
}
else {
var topic = this._topic;
height = topic.getSize().height + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
}
var oldHeight = this._height;
this._height = height;
// I must update all the parent nodes first...
if (oldHeight != this._height)
{
var topic = this._topic;
var parentTopic = topic.getParent();
if (parentTopic != null)
{
var board = this._layoutManager.getTopicBoardForTopic(parentTopic);
board.repositionate();
}
}
// @todo: Esto hace backtraking. Hay que cambiar la implementacion del set position de
// forma tal que no se mande a hacer el update de todos los hijos.
// Workout center the new topic center...
var refence = this.getReferencePoint();
var lowerLimit;
if (entries.length > 0)
{
var l = 0;
for(l=0; l<entries.length; l++){
if(core.Utils.isDefined(entries[l]))
break;
}
var topic = entries[l].getTopic();
var firstNodeHeight = topic.getSize().height;
lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1;
}
var upperLimit = null;
// Start moving all the elements ...
var newEntries = [];
var order = 0;
for (var i = 0; i < entries.length; i++)
{
var e = entries[i];
if (e && e.getTopic())
{
var currentTopic = e.getTopic();
e.setLowerLimit(lowerLimit);
// Update entry ...
var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic);
var topicBoardHeight = topicBoard.getHeight();
upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
e.setUpperLimit(upperLimit);
lowerLimit = upperLimit;
e.setOrder(order);
currentTopic.setOrder(order);
e.update();
newEntries[order] = e;
order++;
}
}
this._entries = newEntries;
};
mindplot.FixedDistanceBoard.prototype.removeTopic = function(topic)
{
var order = topic.getOrder();
var entry = this.lookupEntryByOrder(order);
core.assert(!entry.isAvailable(), "Illegal state");
entry.setTopic(null);
topic.setOrder(null);
this._entries.erase(entry);
// Repositionate all elements ...
this.repositionate();
};
mindplot.FixedDistanceBoard.prototype.addTopic = function(order, topic)
{
// If the entry is not available, I must swap the the entries...
var entry = this.lookupEntryByOrder(order);
if (!entry.isAvailable())
{
this.freeEntry(entry);
// Create a dummy entry ...
// Puaj, do something with this...
entry = this.createBoardEntry(-1, 0, order);
this._entries[order] = entry;
}
this._entries[order] = entry;
// Add to the board ...
entry.setTopic(topic, false);
// Repositionate all elements ...
this.repositionate();
};
mindplot.FixedDistanceBoard.prototype.lookupEntryByPosition = function(pos)
{
core.assert(core.Utils.isDefined(pos), 'position can not be null');
var entries = this._entries;
var result = null;
for (var i = 0; i < entries.length; i++)
{
var entry = entries[i];
if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit())
{
result = entry;
}
}
if (result == null)
{
var defaultHeight = this._defaultWidth;
if (entries.length == 0)
{
var reference = this.getReferencePoint(); var reference = this.getReferencePoint();
var yReference = reference.y; if (entries.length == 0) {
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); var yReference = reference.y;
} else result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
{ } else {
var firstEntry = entries[0];
if (pos.y < firstEntry.getLowerLimit())
{
var upperLimit = firstEntry.getLowerLimit();
var lowerLimit = upperLimit - defaultHeight;
result = this.createBoardEntry(lowerLimit, upperLimit, 0);
} else
{
var entriesLenght = entries.length; var entriesLenght = entries.length;
var lastEntry = entries[entriesLenght - 1]; var lastEntry = entries[entriesLenght - 1];
var lowerLimit = lastEntry.getUpperLimit(); var lowerLimit = lastEntry.getUpperLimit();
var upperLimit = lowerLimit + defaultHeight; var upperLimit = lowerLimit + defaultHeight;
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght); result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1);
} }
} }
} return result;
},
createBoardEntry : function(lowerLimit, upperLimit, order) {
var result = new mindplot.BoardEntry(lowerLimit, upperLimit, order);
var xPos = this.workoutXBorderDistance();
result.setXPosition(xPos);
return result;
},
updateReferencePoint : function() {
var entries = this._entries;
var parentTopic = this.getTopic();
var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition());
var referencePoint = this.getReferencePoint();
var yOffset = parentPosition.y - referencePoint.y;
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (core.Utils.isDefined(entry)) {
var upperLimit = entry.getUpperLimit() + yOffset;
var lowerLimit = entry.getLowerLimit() + yOffset;
entry.setUpperLimit(upperLimit);
entry.setLowerLimit(lowerLimit);
// Fix x position ...
var xPos = this.workoutXBorderDistance();
entry.setXPosition(xPos);
entry.update();
}
}
this._referencePoint = parentPosition.clone();
},
/**
* This x distance doesn't take into account the size of the shape.
*/
workoutXBorderDistance : function() {
var topic = this.getTopic();
var topicPosition = topic.getPosition();
var topicSize = topic.getSize();
var halfTargetWidth = topicSize.width / 2;
var result;
if (topicPosition.x >= 0) {
// It's at right.
result = topicPosition.x + halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE;
} else {
result = topicPosition.x - (halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE);
}
return result;
},
getTopic : function() {
return this._topic;
},
freeEntry : function(entry) {
var newEntries = [];
var entries = this._entries;
var order = 0;
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (e == entry) {
order++;
}
newEntries[order] = e;
order++;
}
this._entries = newEntries;
},
repositionate : function() {
// Workout width and update topic height.
var entries = this._entries;
var height = 0;
var model = this._topic.getModel();
if (entries.length >= 1 && !model.areChildrenShrinked()) {
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (e && e.getTopic()) {
var topic = e.getTopic();
var topicBoard = this._layoutManager.getTopicBoardForTopic(topic);
var topicBoardHeight = topicBoard.getHeight();
height += topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
}
}
}
else {
var topic = this._topic;
height = topic.getSize().height + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
}
var oldHeight = this._height;
this._height = height;
// I must update all the parent nodes first...
if (oldHeight != this._height) {
var topic = this._topic;
var parentTopic = topic.getParent();
if (parentTopic != null) {
var board = this._layoutManager.getTopicBoardForTopic(parentTopic);
board.repositionate();
}
}
// @todo: Esto hace backtraking. Hay que cambiar la implementacion del set position de
// forma tal que no se mande a hacer el update de todos los hijos.
// Workout center the new topic center...
var refence = this.getReferencePoint();
var lowerLimit;
if (entries.length > 0) {
var l = 0;
for (l = 0; l < entries.length; l++) {
if (core.Utils.isDefined(entries[l]))
break;
}
var topic = entries[l].getTopic();
var firstNodeHeight = topic.getSize().height;
lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1;
}
var upperLimit = null;
// Start moving all the elements ...
var newEntries = [];
var order = 0;
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (e && e.getTopic()) {
var currentTopic = e.getTopic();
e.setLowerLimit(lowerLimit);
// Update entry ...
var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic);
var topicBoardHeight = topicBoard.getHeight();
upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
e.setUpperLimit(upperLimit);
lowerLimit = upperLimit;
e.setOrder(order);
currentTopic.setOrder(order);
e.update();
newEntries[order] = e;
order++;
}
}
this._entries = newEntries;
},
removeTopic : function(topic) {
var order = topic.getOrder();
var entry = this.lookupEntryByOrder(order);
core.assert(!entry.isAvailable(), "Illegal state");
entry.setTopic(null);
topic.setOrder(null);
this._entries.erase(entry);
// Repositionate all elements ...
this.repositionate();
},
addTopic : function(order, topic) {
// If the entry is not available, I must swap the the entries...
var entry = this.lookupEntryByOrder(order);
if (!entry.isAvailable()) {
this.freeEntry(entry);
// Create a dummy entry ...
// Puaj, do something with this...
entry = this.createBoardEntry(-1, 0, order);
this._entries[order] = entry;
}
this._entries[order] = entry;
// Add to the board ...
entry.setTopic(topic, false);
// Repositionate all elements ...
this.repositionate();
},
lookupEntryByPosition : function(pos) {
core.assert(core.Utils.isDefined(pos), 'position can not be null');
var entries = this._entries;
var result = null;
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit()) {
result = entry;
}
}
if (result == null) {
var defaultHeight = this._defaultWidth;
if (entries.length == 0) {
var reference = this.getReferencePoint();
var yReference = reference.y;
result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0);
} else {
var firstEntry = entries[0];
if (pos.y < firstEntry.getLowerLimit()) {
var upperLimit = firstEntry.getLowerLimit();
var lowerLimit = upperLimit - defaultHeight;
result = this.createBoardEntry(lowerLimit, upperLimit, 0);
} else {
var entriesLenght = entries.length;
var lastEntry = entries[entriesLenght - 1];
var lowerLimit = lastEntry.getUpperLimit();
var upperLimit = lowerLimit + defaultHeight;
result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght);
}
}
}
return result;
}
})
;
mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6;
mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60;
return result;
};

View File

@ -1,41 +1,43 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.Icon = function(url){ mindplot.Icon = new Class({
this._image = new web2d.Image(); initialize:function(url) {
this._image.setHref(url); this._image = new web2d.Image();
this._image.setSize(12,12); this._image.setHref(url);
}; this._image.setSize(12, 12);
},
mindplot.Icon.prototype.getImage= function(){ getImage : function() {
return this._image; return this._image;
}; },
mindplot.Icon.prototype.setGroup= function(group){ setGroup : function(group) {
this._group=group; this._group = group;
}; },
mindplot.Icon.prototype.getGroup= function() { getGroup : function() {
return this._group; return this._group;
}; },
mindplot.Icon.prototype.getSize=function(){ getSize : function() {
return this._image.getSize(); return this._image.getSize();
}; }
});

View File

@ -1,198 +1,195 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.IconGroup = function(topic) { mindplot.IconGroup = new Class({
var offset = topic.getOffset(); initialize : function(topic) {
this.options = { var offset = topic.getOffset();
width:0,
height:0,
x:offset.x / 2,
y:offset.y,
icons:[],
topic:topic,
nativeElem:new web2d.Group({width: 2, height:2,x: offset, y:offset, coordSizeWidth:1,coordSizeHeight:1})
};
this.updateIconGroupPosition();
this.registerListeners();
};
mindplot.IconGroup.prototype.setPosition = function(x, y) { this.options = {
this.options.x = x; width:0,
this.options.y = y; height:0,
this.options.nativeElem.setPosition(x, y); x:offset.x / 2,
}; y:offset.y,
icons:[],
topic:topic,
nativeElem:new web2d.Group({width: 2, height:2,x: offset, y:offset, coordSizeWidth:1,coordSizeHeight:1})
};
this.updateIconGroupPosition();
this.registerListeners();
},
mindplot.IconGroup.prototype.getPosition = function() { setPosition : function(x, y) {
return {x:this.options.x, y:this.options.y}; this.options.x = x;
}; this.options.y = y;
this.options.nativeElem.setPosition(x, y);
},
mindplot.IconGroup.prototype.setSize = function(width, height) { getPosition : function() {
this.options.width = width; return {x:this.options.x, y:this.options.y};
this.options.height = height; },
this.options.nativeElem.setSize(width, height);
this.options.nativeElem.setCoordSize(width, height);
};
mindplot.IconGroup.prototype.getSize = function() setSize : function(width, height) {
{ this.options.width = width;
return {width:this.options.width, height:this.options.height}; this.options.height = height;
}; this.options.nativeElem.setSize(width, height);
this.options.nativeElem.setCoordSize(width, height);
},
mindplot.IconGroup.prototype.addIcon = function(icon) { getSize : function() {
icon.setGroup(this); return {width:this.options.width, height:this.options.height};
var newIcon = icon.getImage(); },
var nativeElem = this.options.nativeElem;
var iconSize = newIcon.getSize();
var size = nativeElem.getSize();
newIcon.setPosition(size.width, 0);
this.options.icons.extend([icon]);
nativeElem.appendChild(newIcon); addIcon : function(icon) {
icon.setGroup(this);
var newIcon = icon.getImage();
var nativeElem = this.options.nativeElem;
var iconSize = newIcon.getSize();
var size = nativeElem.getSize();
newIcon.setPosition(size.width, 0);
this.options.icons.extend([icon]);
size.width = size.width + iconSize.width; nativeElem.appendChild(newIcon);
if (iconSize.height > size.height)
{ size.width = size.width + iconSize.width;
size.height = iconSize.height; if (iconSize.height > size.height) {
size.height = iconSize.height;
}
nativeElem.setCoordSize(size.width, size.height);
nativeElem.setSize(size.width, size.height);
this.options.width = size.width;
this.options.height = size.height;
},
getIcons : function() {
return this.options.icons;
},
removeIcon : function(url) {
this._removeIcon(this.getIcon(url));
},
removeImageIcon : function(icon) {
var imgIcon = this.getImageIcon(icon);
this._removeIcon(imgIcon);
},
getIcon : function(url) {
var result = null;
this.options.icons.each(function(el, index) {
var nativeImage = el.getImage();
if (nativeImage.getHref() == url) {
result = el;
}
}, this);
return result;
},
getImageIcon : function(icon) {
var result = null;
this.options.icons.each(function(el, index) {
if (result == null && $chk(el.getModel().isIconModel) && el.getId() == icon.getId() && el.getUiId() == icon.getUiId()) {
result = el;
}
}, this);
return result;
},
findIconFromModel : function(iconModel) {
var result = null;
this.options.icons.each(function(el, index) {
var elModel = el.getModel();
if (result == null && $chk(elModel.isIconModel) && elModel.getId() == iconModel.getId()) {
result = el;
}
}, this);
if (result == null) {
throw "Icon can no be found.";
}
return result;
},
_removeIcon : function(icon) {
var nativeImage = icon.getImage();
this.options.icons.erase(icon);
var iconSize = nativeImage.getSize();
var size = this.options.nativeElem.getSize();
var position = nativeImage.getPosition();
var childs = this.options.nativeElem.removeChild(nativeImage);
this.options.icons.each(function(icon, index) {
var img = icon.getImage();
var pos = img.getPosition();
if (pos.x > position.x) {
img.setPosition(pos.x - iconSize.width, 0);
}
}.bind(this));
size.width = size.width - iconSize.width;
this.setSize(size.width, size.height);
},
getNativeElement : function() {
return this.options.nativeElem;
},
moveToFront : function() {
this.options.nativeElem.moveToFront();
},
registerListeners : function() {
this.options.nativeElem.addEventListener('click', function(event) {
// Avoid node creation ...
if (core.Utils.isDefined(event.stopPropagation)) {
event.stopPropagation(true);
} else {
event.cancelBubble = true;
}
});
this.options.nativeElem.addEventListener('dblclick', function(event) {
// Avoid node creation ...
if (core.Utils.isDefined(event.stopPropagation)) {
event.stopPropagation(true);
} else {
event.cancelBubble = true;
}
});
},
getTopic : function() {
return this.options.topic;
},
updateIconGroupPosition : function() {
var offsets = this._calculateOffsets();
this.setPosition(offsets.x, offsets.y);
},
_calculateOffsets : function() {
var offset = this.options.topic.getOffset();
var text = this.options.topic.getTextShape();
var sizeHeight = text.getHtmlFontSize();
var yOffset = offset;
var shape = this.options.topic.getShapeType();
yOffset = text.getPosition().y + (sizeHeight - 18) / 2 + 1;
return {x:offset, y:yOffset};
} }
});
nativeElem.setCoordSize(size.width, size.height);
nativeElem.setSize(size.width, size.height);
this.options.width = size.width;
this.options.height = size.height;
};
mindplot.IconGroup.prototype.getIcons = function() {
return this.options.icons;
};
mindplot.IconGroup.prototype.removeIcon = function(url) {
this._removeIcon(this.getIcon(url));
};
mindplot.IconGroup.prototype.removeImageIcon = function(icon) {
var imgIcon = this.getImageIcon(icon);
this._removeIcon(imgIcon);
};
mindplot.IconGroup.prototype.getIcon = function(url) {
var result = null;
this.options.icons.each(function(el, index) {
var nativeImage = el.getImage();
if (nativeImage.getHref() == url)
{
result = el;
}
}, this);
return result;
};
mindplot.IconGroup.prototype.getImageIcon=function(icon){
var result = null;
this.options.icons.each(function(el,index){
if(result == null && $chk(el.getModel().isIconModel) && el.getId()==icon.getId() && el.getUiId() == icon.getUiId())
{
result = el;
}
},this);
return result;
};
mindplot.IconGroup.prototype.findIconFromModel=function(iconModel){
var result = null;
this.options.icons.each(function(el,index){
var elModel = el.getModel();
if(result == null && $chk(elModel.isIconModel) && elModel.getId()==iconModel.getId())
{
result = el;
}
},this);
if(result==null)
{
throw "Icon can no be found.";
}
return result;
};
mindplot.IconGroup.prototype._removeIcon = function(icon) {
var nativeImage = icon.getImage();
this.options.icons.erase(icon);
var iconSize = nativeImage.getSize();
var size = this.options.nativeElem.getSize();
var position = nativeImage.getPosition();
var childs = this.options.nativeElem.removeChild(nativeImage);
this.options.icons.each(function(icon,index){
var img = icon.getImage();
var pos = img.getPosition();
if(pos.x > position.x){
img.setPosition(pos.x-iconSize.width, 0);
}
}.bind(this));
size.width = size.width - iconSize.width;
this.setSize(size.width, size.height);
};
mindplot.IconGroup.prototype.getNativeElement = function() {
return this.options.nativeElem;
};
mindplot.IconGroup.prototype.moveToFront = function() {
this.options.nativeElem.moveToFront();
}
mindplot.IconGroup.prototype.registerListeners = function() {
this.options.nativeElem.addEventListener('click', function(event) {
// Avoid node creation ...
if (core.Utils.isDefined(event.stopPropagation))
{
event.stopPropagation(true);
} else
{
event.cancelBubble = true;
}
});
this.options.nativeElem.addEventListener('dblclick', function(event)
{
// Avoid node creation ...
if (core.Utils.isDefined(event.stopPropagation))
{
event.stopPropagation(true);
} else
{
event.cancelBubble = true;
}
});
};
mindplot.IconGroup.prototype.getTopic = function() {
return this.options.topic;
};
mindplot.IconGroup.prototype.updateIconGroupPosition = function() {
var offsets = this._calculateOffsets();
this.setPosition(offsets.x, offsets.y);
};
mindplot.IconGroup.prototype._calculateOffsets = function() {
var offset = this.options.topic.getOffset();
var text = this.options.topic.getTextShape();
var sizeHeight = text.getHtmlFontSize();
var yOffset = offset;
var shape = this.options.topic.getShapeType();
yOffset = text.getPosition().y + (sizeHeight - 18)/2 + 1;
return {x:offset, y:yOffset};
};

View File

@ -1,205 +1,179 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.Mindmap = function() mindplot.Mindmap = new Class({
{ initialize : function() {
this._branches = []; this._branches = [];
this._name = null; this._description = null;
this._description = null; this._version = null;
this._version=null; this._relationships = [];
this._relationships=[]; },
};
mindplot.Mindmap.prototype.getCentralTopic = function() getCentralTopic : function() {
{ return this._branches[0];
return this._branches[0]; },
};
mindplot.Mindmap.prototype.getDescription = function() getDescription : function() {
{ return this._description;
return this._description; },
};
mindplot.Mindmap.prototype.getId = function() getId : function() {
{ return this._iconType;
return this._iconType; },
};
mindplot.Mindmap.prototype.setId = function(id) setId : function(id) {
{ this._iconType = id;
this._iconType = id; },
};
mindplot.Mindmap.prototype.getVersion = function() getVersion : function() {
{ return this._version;
return this._version; },
};
mindplot.Mindmap.prototype.setVersion = function(version) setVersion : function(version) {
{ this._version = version;
this._version = version; },
};
addBranch : function(nodeModel) {
core.assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects');
if (this._branches.length == 0) {
core.assert(nodeModel.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic");
nodeModel.setPosition(0, 0);
} else {
core.assert(nodeModel.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic");
}
this._branches.push(nodeModel);
},
mindplot.Mindmap.prototype.addBranch = function(nodeModel) getBranches : function() {
{ return this._branches;
core.assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects'); },
if (this._branches.length == 0)
{
core.assert(nodeModel.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic");
nodeModel.setPosition(0, 0);
} else
{
core.assert(nodeModel.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic");
}
this._branches.push(nodeModel); getRelationships : function() {
}; return this._relationships;
},
mindplot.Mindmap.prototype.getBranches = function() connect : function(parent, child) {
{ // Child already has a parent ?
return this._branches; var branches = this.getBranches();
}; core.assert(!child.getParent(), 'Child model seems to be already connected');
mindplot.Mindmap.prototype.getRelationships = function() { // Connect node...
return this._relationships; parent._appendChild(child);
};
mindplot.Mindmap.prototype.connect = function(parent, child) // Remove from the branch ...
{ branches.erase(child);
// Child already has a parent ? },
var branches = this.getBranches();
core.assert(!child.getParent(), 'Child model seems to be already connected');
// Connect node... disconnect : function(child) {
parent._appendChild(child); var parent = child.getParent();
core.assert(child, 'Child can not be null.');
core.assert(parent, 'Child model seems to be already connected');
// Remove from the branch ... parent._removeChild(child);
branches.erase(child);
};
mindplot.Mindmap.prototype.disconnect = function(child) var branches = this.getBranches();
{ branches.push(child);
var parent = child.getParent();
core.assert(child, 'Child can not be null.');
core.assert(parent, 'Child model seems to be already connected');
parent._removeChild(child); },
var branches = this.getBranches(); hasAlreadyAdded : function(node) {
branches.push(child); var result = false;
}; // Check in not connected nodes.
var branches = this._branches;
for (var i = 0; i < branches.length; i++) {
result = branches[i]._isChildNode(node);
if (result) {
break;
}
}
},
mindplot.Mindmap.prototype.hasAlreadyAdded = function(node) createNode : function(type, id) {
{ core.assert(type, "node type can not be null");
var result = false; return this._createNode(type, id);
},
// Check in not connected nodes. _createNode : function(type, id) {
var branches = this._branches; core.assert(type, 'Node type must be specified.');
for (var i = 0; i < branches.length; i++) var result = new mindplot.NodeModel(type, this, id);
{ return result;
result = branches[i]._isChildNode(node); },
if (result)
{ createRelationship : function(fromNode, toNode) {
break; core.assert(fromNode, 'from node cannot be null');
core.assert(toNode, 'to node cannot be null');
return new mindplot.RelationshipModel(fromNode, toNode);
},
addRelationship : function(relationship) {
this._relationships.push(relationship);
},
removeRelationship : function(relationship) {
this._relationships.erase(relationship);
},
inspect : function() {
var result = '';
result = '{ ';
var branches = this.getBranches();
for (var i = 0; i < branches.length; i++) {
var node = branches[i];
if (i != 0) {
result = result + ', ';
}
result = result + this._toString(node);
}
result = result + ' } ';
return result;
},
_toString : function(node) {
var result = node.inspect();
var children = node.getChildren();
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (i == 0) {
result = result + '-> {';
} else {
result = result + ', ';
}
result = result + this._toString(child);
if (i == children.length - 1) {
result = result + '}';
}
}
return result;
} }
} }
}; );
mindplot.Mindmap.prototype.createNode = function(type, id)
{
core.assert(type, "node type can not be null");
return this._createNode(type, id);
};
mindplot.Mindmap.prototype._createNode = function(type, id)
{
core.assert(type, 'Node type must be specified.');
var result = new mindplot.NodeModel(type, this, id);
return result;
};
mindplot.Mindmap.prototype.createRelationship = function(fromNode, toNode){
core.assert(fromNode, 'from node cannot be null');
core.assert(toNode, 'to node cannot be null');
return new mindplot.RelationshipModel(fromNode, toNode);
};
mindplot.Mindmap.prototype.addRelationship = function(relationship) {
this._relationships.push(relationship);
};
mindplot.Mindmap.prototype.removeRelationship = function(relationship) {
this._relationships.erase(relationship);
};
mindplot.Mindmap.prototype.inspect = function()
{
var result = '';
result = '{ ';
var branches = this.getBranches();
for (var i = 0; i < branches.length; i++)
{
var node = branches[i];
if (i != 0)
{
result = result + ', ';
}
result = result + this._toString(node);
}
result = result + ' } ';
return result;
};
mindplot.Mindmap.prototype._toString = function(node)
{
var result = node.inspect();
var children = node.getChildren();
for (var i = 0; i < children.length; i++)
{
var child = children[i];
if (i == 0)
{
result = result + '-> {';
} else
{
result = result + ', ';
}
result = result + this._toString(child);
if (i == children.length - 1)
{
result = result + '}';
}
}
return result;
};

View File

@ -1,525 +1,432 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.NodeModel = function(type, mindmap, id) mindplot.NodeModel = new Class({
{ initialize:function(type, mindmap, id) {
core.assert(type, 'Node type can not be null'); core.assert(type, 'Node type can not be null');
core.assert(mindmap, 'mindmap can not be null'); core.assert(mindmap, 'mindmap can not be null');
this._order = null; this._order = null;
this._type = type; this._type = type;
this._children = []; this._children = [];
this._icons = []; this._icons = [];
this._links = []; this._links = [];
this._notes = []; this._notes = [];
this._size = {width:50,height:20}; this._size = {width:50,height:20};
this._position = null; this._position = null;
if(core.Utils.isDefined(id)){ if (core.Utils.isDefined(id)) {
if(!core.Utils.isDefined(mindplot.NodeModel._uuid) || id>mindplot.NodeModel._uuid){ if (!core.Utils.isDefined(mindplot.NodeModel._uuid) || id > mindplot.NodeModel._uuid) {
mindplot.NodeModel._uuid = id;
}
this._id = id;
} else {
this._id = mindplot.NodeModel._nextUUID();
}
this._mindmap = mindmap;
this._text = null;
this._shapeType = null;
this._fontFamily = null;
this._fontSize = null;
this._fontStyle = null;
this._fontWeight = null;
this._fontColor = null;
this._borderColor = null;
this._backgroundColor = null;
this._areChildrenShrinked = false;
},
clone : function() {
var result = new mindplot.NodeModel(this._type, this._mindmap);
result._order = this._order;
result._type = this._type;
result._children = this._children.map(function(item, index) {
var model = item.clone();
model._parent = result;
return model;
});
result._icons = this._icons;
result._links = this._links;
result._notes = this._notes;
result._size = this._size;
result._position = this._position;
result._id = this._id;
result._mindmap = this._mindmap;
result._text = this._text;
result._shapeType = this._shapeType;
result._fontFamily = this._fontFamily;
result._fontSize = this._fontSize;
result._fontStyle = this._fontStyle;
result._fontWeight = this._fontWeight;
result._fontColor = this._fontColor;
result._borderColor = this._borderColor;
result._backgroundColor = this._backgroundColor;
result._areChildrenShrinked = this._areChildrenShrinked;
return result;
},
areChildrenShrinked : function() {
return this._areChildrenShrinked;
},
setChildrenShrinked : function(value) {
this._areChildrenShrinked = value;
},
getId : function() {
return this._id;
},
setId : function(id) {
this._id = id;
if (mindplot.NodeModel._uuid < id) {
mindplot.NodeModel._uuid = id; mindplot.NodeModel._uuid = id;
} }
this._id = id; },
} else {
this._id = mindplot.NodeModel._nextUUID();
}
this._mindmap = mindmap;
this._text = null;
this._shapeType = null;
this._fontFamily = null;
this._fontSize = null;
this._fontStyle = null;
this._fontWeight = null;
this._fontColor = null;
this._borderColor = null;
this._backgroundColor = null;
this._areChildrenShrinked = false;
};
mindplot.NodeModel.prototype.clone = function() getType : function() {
{ return this._type;
var result = new mindplot.NodeModel(this._type, this._mindmap); },
result._order = this._order;
result._type = this._type;
result._children = this._children.map(function(item,index)
{
var model = item.clone();
model._parent = result;
return model;
});
setText : function(text) {
this._text = text;
},
result._icons = this._icons; getText : function() {
result._links = this._links; return this._text;
result._notes = this._notes; },
result._size = this._size;
result._position = this._position;
result._id = this._id;
result._mindmap = this._mindmap;
result._text = this._text;
result._shapeType = this._shapeType;
result._fontFamily = this._fontFamily;
result._fontSize = this._fontSize;
result._fontStyle = this._fontStyle;
result._fontWeight = this._fontWeight;
result._fontColor = this._fontColor;
result._borderColor = this._borderColor;
result._backgroundColor = this._backgroundColor;
result._areChildrenShrinked = this._areChildrenShrinked;
return result;
};
mindplot.NodeModel.prototype.areChildrenShrinked = function() isNodeModel : function() {
{ return true;
return this._areChildrenShrinked; },
};
mindplot.NodeModel.prototype.setChildrenShrinked = function(value) isConnected : function() {
{ return this._parent != null;
this._areChildrenShrinked = value; },
};
mindplot.NodeModel.prototype.getId = function() createLink : function(url) {
{ core.assert(url, 'Link URL must be specified.');
return this._id; return new mindplot.LinkModel(url, this);
}; },
addLink : function(link) {
core.assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links');
this._links.push(link);
},
mindplot.NodeModel.prototype.setId = function(id) _removeLink : function(link) {
{ core.assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links');
this._id = id; this._links.erase(link);
if(mindplot.NodeModel._uuid<id){ },
mindplot.NodeModel._uuid = id;
}
};
mindplot.NodeModel.prototype.getType = function() createNote : function(text) {
{ core.assert(text != null, 'note text must be specified.');
return this._type; return new mindplot.NoteModel(text, this);
}; },
mindplot.NodeModel.prototype.setText = function(text) addNote : function(note) {
{ core.assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
this._text = text; this._notes.push(note);
}; },
mindplot.NodeModel.prototype.getText = function() _removeNote : function(note) {
{ core.assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
return this._text; this._notes.erase(note);
}; },
mindplot.NodeModel.prototype.isNodeModel = function() createIcon : function(iconType) {
{ core.assert(iconType, 'IconType must be specified.');
return true; return new mindplot.IconModel(iconType, this);
}; },
mindplot.NodeModel.prototype.isConnected = function() addIcon : function(icon) {
{ core.assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
return this._parent != null; this._icons.push(icon);
}; },
mindplot.NodeModel.prototype.createLink = function(url) _removeIcon : function(icon) {
{ core.assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
core.assert(url, 'Link URL must be specified.'); this._icons.erase(icon);
return new mindplot.LinkModel(url, this); },
};
mindplot.NodeModel.prototype.addLink = function(link) removeLastIcon : function() {
{ this._icons.pop();
core.assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links'); },
this._links.push(link);
};
mindplot.NodeModel.prototype._removeLink = function(link) _appendChild : function(child) {
{ core.assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
core.assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links'); this._children.push(child);
this._links.erase(link); child._parent = this;
}; },
mindplot.NodeModel.prototype.createNote = function(text) _removeChild : function(child) {
{ core.assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.');
core.assert(text!=null, 'note text must be specified.'); this._children.erase(child);
return new mindplot.NoteModel(text, this); child._parent = null;
}; },
mindplot.NodeModel.prototype.addNote = function(note) setPosition : function(x, y) {
{ core.assert(core.Utils.isDefined(x), "x coordinate must be defined");
core.assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); core.assert(core.Utils.isDefined(y), "y coordinate must be defined");
this._notes.push(note);
};
mindplot.NodeModel.prototype._removeNote = function(note) if (!core.Utils.isDefined(this._position)) {
{ this._position = new core.Point();
core.assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
this._notes.erase(note);
};
mindplot.NodeModel.prototype.createIcon = function(iconType)
{
core.assert(iconType, 'IconType must be specified.');
return new mindplot.IconModel(iconType, this);
};
mindplot.NodeModel.prototype.addIcon = function(icon)
{
core.assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.push(icon);
};
mindplot.NodeModel.prototype._removeIcon = function(icon)
{
core.assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.erase(icon);
};
mindplot.NodeModel.prototype.removeLastIcon = function()
{
this._icons.pop();
};
mindplot.NodeModel.prototype._appendChild = function(child)
{
core.assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object');
this._children.push(child);
child._parent = this;
};
mindplot.NodeModel.prototype._removeChild = function(child)
{
core.assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.');
this._children.erase(child);
child._parent = null;
};
mindplot.NodeModel.prototype.setPosition = function(x, y)
{
core.assert(core.Utils.isDefined(x), "x coordinate must be defined");
core.assert(core.Utils.isDefined(y), "y coordinate must be defined");
if (!core.Utils.isDefined(this._position))
{
this._position = new core.Point();
}
this._position.x = parseInt(x);
this._position.y = parseInt(y);
};
mindplot.NodeModel.prototype.getPosition = function()
{
return this._position;
};
mindplot.NodeModel.prototype.setFinalPosition = function(x, y)
{
core.assert(core.Utils.isDefined(x), "x coordinate must be defined");
core.assert(core.Utils.isDefined(y), "y coordinate must be defined");
if (!core.Utils.isDefined(this._finalPosition))
{
this._finalPosition = new core.Point();
}
this._finalPosition.x = parseInt(x);
this._finalPosition.y = parseInt(y);
};
mindplot.NodeModel.prototype.getFinalPosition = function()
{
return this._finalPosition;
};
mindplot.NodeModel.prototype.setSize = function(width, height)
{
this._size.width = width;
this._size.height = height;
};
mindplot.NodeModel.prototype.getSize = function()
{
return {width:this._size.width,height:this._size.height};
};
mindplot.NodeModel.prototype.getChildren = function()
{
return this._children;
};
mindplot.NodeModel.prototype.getIcons = function()
{
return this._icons;
};
mindplot.NodeModel.prototype.getLinks = function()
{
return this._links;
};
mindplot.NodeModel.prototype.getNotes = function()
{
return this._notes;
};
mindplot.NodeModel.prototype.getParent = function()
{
return this._parent;
};
mindplot.NodeModel.prototype.getMindmap = function()
{
return this._mindmap;
};
mindplot.NodeModel.prototype.setParent = function(parent)
{
core.assert(parent != this, 'The same node can not be parent and child if itself.');
this._parent = parent;
};
mindplot.NodeModel.prototype.canBeConnected = function(sourceModel, sourcePosition, targetTopicHeight)
{
core.assert(sourceModel != this, 'The same node can not be parent and child if itself.');
core.assert(sourcePosition, 'childPosition can not be null.');
core.assert(core.Utils.isDefined(targetTopicHeight), 'childrenWidth can not be null.');
// Only can be connected if the node is in the left or rigth.
var targetModel = this;
var mindmap = targetModel.getMindmap();
var targetPosition = targetModel.getPosition();
var result = false;
if (sourceModel.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE)
{
// Finally, check current node ubication.
var targetTopicSize = targetModel.getSize();
var yDistance = Math.abs(sourcePosition.y - targetPosition.y);
var gap = 35 + targetTopicHeight / 2;
if(targetModel.getChildren().length>0){
gap += Math.abs(targetPosition.y - targetModel.getChildren()[0].getPosition().y);
} }
this._position.x = parseInt(x);
this._position.y = parseInt(y);
},
if (yDistance <= gap) getPosition : function() {
{ return this._position;
// Circular connection ? },
if (!sourceModel._isChildNode(this))
{
var toleranceDistance = (targetTopicSize.width / 2) + targetTopicHeight;
var xDistance = sourcePosition.x - targetPosition.x; setFinalPosition : function(x, y) {
var isTargetAtRightFromCentral = targetPosition.x >= 0; core.assert(core.Utils.isDefined(x), "x coordinate must be defined");
core.assert(core.Utils.isDefined(y), "y coordinate must be defined");
if (isTargetAtRightFromCentral) if (!core.Utils.isDefined(this._finalPosition)) {
{ this._finalPosition = new core.Point();
if (xDistance >= -targetTopicSize.width/2 && xDistance <= mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE /2 + (targetTopicSize.width / 2)) }
{ this._finalPosition.x = parseInt(x);
result = true; this._finalPosition.y = parseInt(y);
} },
} else getFinalPosition : function() {
{ return this._finalPosition;
if (xDistance <= targetTopicSize.width/2 && Math.abs(xDistance) <= mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE /2 + (targetTopicSize.width / 2)) },
{
result = true; setSize : function(width, height) {
this._size.width = width;
this._size.height = height;
},
getSize : function() {
return {width:this._size.width,height:this._size.height};
},
getChildren : function() {
return this._children;
},
getIcons : function() {
return this._icons;
},
getLinks : function() {
return this._links;
},
getNotes : function() {
return this._notes;
},
getParent : function() {
return this._parent;
},
getMindmap : function() {
return this._mindmap;
},
setParent : function(parent) {
core.assert(parent != this, 'The same node can not be parent and child if itself.');
this._parent = parent;
},
canBeConnected : function(sourceModel, sourcePosition, targetTopicHeight) {
core.assert(sourceModel != this, 'The same node can not be parent and child if itself.');
core.assert(sourcePosition, 'childPosition can not be null.');
core.assert(core.Utils.isDefined(targetTopicHeight), 'childrenWidth can not be null.');
// Only can be connected if the node is in the left or rigth.
var targetModel = this;
var mindmap = targetModel.getMindmap();
var targetPosition = targetModel.getPosition();
var result = false;
if (sourceModel.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE) {
// Finally, check current node ubication.
var targetTopicSize = targetModel.getSize();
var yDistance = Math.abs(sourcePosition.y - targetPosition.y);
var gap = 35 + targetTopicHeight / 2;
if (targetModel.getChildren().length > 0) {
gap += Math.abs(targetPosition.y - targetModel.getChildren()[0].getPosition().y);
}
if (yDistance <= gap) {
// Circular connection ?
if (!sourceModel._isChildNode(this)) {
var toleranceDistance = (targetTopicSize.width / 2) + targetTopicHeight;
var xDistance = sourcePosition.x - targetPosition.x;
var isTargetAtRightFromCentral = targetPosition.x >= 0;
if (isTargetAtRightFromCentral) {
if (xDistance >= -targetTopicSize.width / 2 && xDistance <= mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) {
result = true;
}
} else {
if (xDistance <= targetTopicSize.width / 2 && Math.abs(xDistance) <= mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) {
result = true;
}
} }
} }
} }
} else {
throw "No implemented yet";
} }
} else return result;
{ },
throw "No implemented yet";
}
return result;
};
mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220; _isChildNode : function(node) {
var result = false;
mindplot.NodeModel.prototype._isChildNode = function(node) if (node == this) {
{ result = true;
var result = false; } else {
if (node == this) var children = this.getChildren();
{ for (var i = 0; i < children.length; i++) {
result = true; var child = children[i];
} else result = child._isChildNode(node);
{ if (result) {
var children = this.getChildren(); break;
for (var i = 0; i < children.length; i++) }
{
var child = children[i];
result = child._isChildNode(node);
if (result)
{
break;
} }
} }
} return result;
return result;
}; },
mindplot.NodeModel.prototype.connectTo = function(parent) connectTo : function(parent) {
{ var mindmap = this.getMindmap();
var mindmap = this.getMindmap(); mindmap.connect(parent, this);
mindmap.connect(parent, this); this._parent = parent;
this._parent = parent; },
};
mindplot.NodeModel.prototype.disconnect = function() disconnect : function() {
{ var mindmap = this.getMindmap();
var mindmap = this.getMindmap();
mindmap.disconnect(this);
};
mindplot.NodeModel.prototype.getOrder = function()
{
return this._order;
};
mindplot.NodeModel.prototype.getShapeType = function()
{
return this._shapeType;
};
mindplot.NodeModel.prototype.setShapeType = function(type)
{
this._shapeType = type;
};
mindplot.NodeModel.prototype.setOrder = function(value)
{
this._order = value;
};
mindplot.NodeModel.prototype.setFontFamily = function(value)
{
this._fontFamily = value;
};
mindplot.NodeModel.prototype.getOrder = function()
{
return this._order;
};
mindplot.NodeModel.prototype.getFontFamily = function()
{
return this._fontFamily;
};
mindplot.NodeModel.prototype.setFontStyle = function(value)
{
this._fontStyle = value;
};
mindplot.NodeModel.prototype.getFontStyle = function()
{
return this._fontStyle;
};
mindplot.NodeModel.prototype.setFontWeight = function(value)
{
this._fontWeight = value;
};
mindplot.NodeModel.prototype.getFontWeight = function()
{
return this._fontWeight;
};
mindplot.NodeModel.prototype.setFontColor = function(value)
{
this._fontColor = value;
};
mindplot.NodeModel.prototype.getFontColor = function()
{
return this._fontColor;
};
mindplot.NodeModel.prototype.setFontSize = function(value)
{
this._fontSize = value;
};
mindplot.NodeModel.prototype.getFontSize = function()
{
return this._fontSize;
};
mindplot.NodeModel.prototype.getBorderColor = function()
{
return this._borderColor;
};
mindplot.NodeModel.prototype.setBorderColor = function(color)
{
this._borderColor = color;
};
mindplot.NodeModel.prototype.getBackgroundColor = function()
{
return this._backgroundColor;
};
mindplot.NodeModel.prototype.setBackgroundColor = function(color)
{
this._backgroundColor = color;
};
mindplot.NodeModel.prototype.deleteNode = function()
{
var mindmap = this._mindmap;
// if it has children nodes, Their must be disconnected.
var lenght = this._children;
for (var i = 0; i < lenght; i++)
{
var child = this._children[i];
mindmap.disconnect(child);
}
var parent = this._parent;
if (core.Utils.isDefined(parent))
{
// if it is connected, I must remove it from the parent..
mindmap.disconnect(this); mindmap.disconnect(this);
},
getOrder : function() {
return this._order;
},
getShapeType : function() {
return this._shapeType;
},
setShapeType : function(type) {
this._shapeType = type;
},
setOrder : function(value) {
this._order = value;
},
setFontFamily : function(value) {
this._fontFamily = value;
},
getOrder : function() {
return this._order;
},
getFontFamily : function() {
return this._fontFamily;
},
setFontStyle : function(value) {
this._fontStyle = value;
},
getFontStyle : function() {
return this._fontStyle;
},
setFontWeight : function(value) {
this._fontWeight = value;
},
getFontWeight : function() {
return this._fontWeight;
},
setFontColor : function(value) {
this._fontColor = value;
},
getFontColor : function() {
return this._fontColor;
},
setFontSize : function(value) {
this._fontSize = value;
},
getFontSize : function() {
return this._fontSize;
},
getBorderColor : function() {
return this._borderColor;
},
setBorderColor : function(color) {
this._borderColor = color;
},
getBackgroundColor : function() {
return this._backgroundColor;
},
setBackgroundColor : function(color) {
this._backgroundColor = color;
},
deleteNode : function() {
var mindmap = this._mindmap;
// if it has children nodes, Their must be disconnected.
var lenght = this._children;
for (var i = 0; i < lenght; i++) {
var child = this._children[i];
mindmap.disconnect(child);
}
var parent = this._parent;
if (core.Utils.isDefined(parent)) {
// if it is connected, I must remove it from the parent..
mindmap.disconnect(this);
}
// It's an isolated node. It must be a hole branch ...
var branches = mindmap.getBranches();
branches.erase(this);
},
inspect : function() {
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
} }
});
// It's an isolated node. It must be a hole branch ...
var branches = mindmap.getBranches();
branches.erase(this);
};
/**
* @todo: This method must be implemented.
*/
mindplot.NodeModel._nextUUID = function()
{
if (!core.Utils.isDefined(this._uuid))
{
this._uuid = 0;
}
this._uuid = this._uuid + 1;
return this._uuid;
};
mindplot.NodeModel.prototype.inspect = function()
{
return '(type:' + this.getType() + ' , id: ' + this.getId() + ')';
};
mindplot.NodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic'; mindplot.NodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic';
mindplot.NodeModel.MAIN_TOPIC_TYPE = 'MainTopic'; mindplot.NodeModel.MAIN_TOPIC_TYPE = 'MainTopic';
@ -530,4 +437,17 @@ mindplot.NodeModel.SHAPE_TYPE_ROUNDED_RECT = 'rounded rectagle';
mindplot.NodeModel.SHAPE_TYPE_ELIPSE = 'elipse'; mindplot.NodeModel.SHAPE_TYPE_ELIPSE = 'elipse';
mindplot.NodeModel.SHAPE_TYPE_LINE = 'line'; mindplot.NodeModel.SHAPE_TYPE_LINE = 'line';
mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220;
/**
* @todo: This method must be implemented.
*/
mindplot.NodeModel._nextUUID = function() {
if (!core.Utils.isDefined(this._uuid)) {
this._uuid = 0;
}
this._uuid = this._uuid + 1;
return this._uuid;
}

View File

@ -1,165 +1,159 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.Note = function(textModel, topic, designer) { mindplot.Note = new Class({
var divContainer=designer.getWorkSpace().getScreenManager().getContainer(); Extends: mindplot.Icon,
var bubbleTip = mindplot.BubbleTip.getInstance(divContainer); initialize : function(textModel, topic, designer) {
mindplot.Icon.call(this, mindplot.Note.IMAGE_URL); var divContainer = designer.getWorkSpace().getScreenManager().getContainer();
this._noteModel = textModel; var bubbleTip = mindplot.BubbleTip.getInstance(divContainer);
this._topic = topic; mindplot.Icon.call(this, mindplot.Note.IMAGE_URL);
this._designer = designer; this._noteModel = textModel;
var image = this.getImage(); this._topic = topic;
var imgContainer = new Element('div').setStyles({textAlign:'center'}); this._designer = designer;
this._textElem = new Element('div').setStyles({'max-height':100,'max-width':300, 'overflow':'auto'}); var image = this.getImage();
var text = unescape(textModel.getText()); var imgContainer = new Element('div').setStyles({textAlign:'center'});
text = text.replace(/\n/ig,"<br/>"); this._textElem = new Element('div').setStyles({'max-height':100,'max-width':300, 'overflow':'auto'});
text = text.replace(/<script/ig, "&lt;script"); var text = unescape(textModel.getText());
text = text.replace(/<\/script/ig, "&lt;\/script"); text = text.replace(/\n/ig, "<br/>");
this._textElem.innerHTML = text;
this._text=textModel.getText();
this._textElem.inject(imgContainer);
var container = new Element('div');
imgContainer.inject(container);
if(!core.Utils.isDefined(designer._viewMode)|| (core.Utils.isDefined(designer._viewMode) && !designer._viewMode)){
var buttonContainer = new Element('div').setStyles({paddingTop:5, textAlign:'center'});
var editBtn = new Element('input', {type:'button', value:'Edit','class':'btn-primary'}).addClass('button').inject(buttonContainer);
var removeBtn = new Element('input', {type:'button', value:'Remove','class':'btn-primary'}).addClass('button').inject(buttonContainer);
editBtn.setStyle("margin-right", "3px");
removeBtn.setStyle("margin-left", "3px");
removeBtn.addEvent('click', function(event) {
var command = new mindplot.commands.RemoveNoteFromTopicCommand(this._topic.getId());
designer._actionRunner.execute(command);
bubbleTip.forceClose();
}.bindWithEvent(this));
var okButtonId = 'okNoteButtonId';
editBtn.addEvent('click', function(event) {
var topic = this._topic;
var designer = this._designer;
var note = this;
var msg = new Element('div');
var textarea = new Element('div').inject(msg);
textarea.innerHTML = "Text"
var formElem = new Element('form', {'action': 'none', 'id':'noteFormId'});
var text = textModel.getText();
text = unescape(text);
var textInput = new Element('textarea', {'value':text}).setStyles({'width':280, 'height':50});
textInput.inject(formElem);
formElem.inject(msg)
var okFunction = function(e) {
var result = true;
var text = textInput.value;
text = escape(text);
note._noteModel.setText(text);
return result;
};
formElem.addEvent('submit', function(e)
{
$(okButtonId).fireEvent('click', e);
e = new Event(e);
e.stop();
});
var dialog = mindplot.Note.buildDialog(designer, okFunction, okButtonId);
dialog.adopt(msg).show();
}.bindWithEvent(this));
buttonContainer.inject(container);
}
var note = this;
image.addEventListener('mouseover', function(event) {
var text = textModel.getText();
text = unescape(text);
text = text.replace(/\n/ig,"<br/>");
text = text.replace(/<script/ig, "&lt;script"); text = text.replace(/<script/ig, "&lt;script");
text = text.replace(/<\/script/ig, "&lt;\/script"); text = text.replace(/<\/script/ig, "&lt;\/script");
this._textElem.innerHTML = text; this._textElem.innerHTML = text;
this._text = textModel.getText();
bubbleTip.open(event, container, note); this._textElem.inject(imgContainer);
}.bind(this));
image.addEventListener('mousemove', function(event) {
bubbleTip.updatePosition(event);
});
image.addEventListener('mouseout', function(event) {
bubbleTip.close(event);
});
};
objects.extend(mindplot.Note, mindplot.Icon); var container = new Element('div');
mindplot.Note.prototype.initialize = function() { imgContainer.inject(container);
}; if (!core.Utils.isDefined(designer._viewMode) || (core.Utils.isDefined(designer._viewMode) && !designer._viewMode)) {
var buttonContainer = new Element('div').setStyles({paddingTop:5, textAlign:'center'});
var editBtn = new Element('input', {type:'button', value:'Edit','class':'btn-primary'}).addClass('button').inject(buttonContainer);
var removeBtn = new Element('input', {type:'button', value:'Remove','class':'btn-primary'}).addClass('button').inject(buttonContainer);
mindplot.Note.prototype.getText=function(){ editBtn.setStyle("margin-right", "3px");
return this._text; removeBtn.setStyle("margin-left", "3px");
};
mindplot.Note.prototype.getModel=function(){ removeBtn.addEvent('click', function(event) {
return this._noteModel; var command = new mindplot.commands.RemoveNoteFromTopicCommand(this._topic.getId());
}; designer._actionRunner.execute(command);
bubbleTip.forceClose();
}.bindWithEvent(this));
mindplot.Note.buildDialog = function(designer, okFunction, okButtonId) { var okButtonId = 'okNoteButtonId';
var windoo = new Windoo({ editBtn.addEvent('click', function(event) {
title: 'Write note', var topic = this._topic;
theme: Windoo.Themes.wise, var designer = this._designer;
modal:true, var note = this;
buttons:{'menu':false, 'close':false, 'minimize':false, 'roll':false, 'maximize':false},
destroyOnClose:true,
height:130
});
var cancel = new Element('input', {'type': 'button', 'class':'btn-primary', 'value': 'Cancel','class':'btn-primary'}).setStyle('margin-right', "5px"); var msg = new Element('div');
cancel.setStyle('margin-left', "5px"); var textarea = new Element('div').inject(msg);
cancel.addEvent('click', function(event) { textarea.innerHTML = "Text";
$(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer));
windoo.close();
}.bindWithEvent(this));
var ok = new Element('input', {'type': 'button', 'class':'btn-primary', 'value': 'Ok','class':'btn-primary','id':okButtonId}).setStyle('marginRight', 10); var formElem = new Element('form', {'action': 'none', 'id':'noteFormId'});
ok.addEvent('click', function(event) { var text = textModel.getText();
var couldBeUpdated = okFunction.attempt(); text = unescape(text);
if (couldBeUpdated) var textInput = new Element('textarea', {'value':text}).setStyles({'width':280, 'height':50});
{ textInput.inject(formElem);
formElem.inject(msg);
var okFunction = function(e) {
var result = true;
var text = textInput.value;
text = escape(text);
note._noteModel.setText(text);
return result;
};
formElem.addEvent('submit', function(e) {
$(okButtonId).fireEvent('click', e);
e = new Event(e);
e.stop();
});
var dialog = mindplot.Note.buildDialog(designer, okFunction, okButtonId);
dialog.adopt(msg).show();
}.bindWithEvent(this));
buttonContainer.inject(container);
}
var note = this;
image.addEventListener('mouseover', function(event) {
var text = textModel.getText();
text = unescape(text);
text = text.replace(/\n/ig, "<br/>");
text = text.replace(/<script/ig, "&lt;script");
text = text.replace(/<\/script/ig, "&lt;\/script");
this._textElem.innerHTML = text;
bubbleTip.open(event, container, note);
}.bind(this));
image.addEventListener('mousemove', function(event) {
bubbleTip.updatePosition(event);
});
image.addEventListener('mouseout', function(event) {
bubbleTip.close(event);
});
},
getText: function() {
return this._text;
},
getModel : function() {
return this._noteModel;
},
buildDialog : function(designer, okFunction, okButtonId) {
var windoo = new Windoo({
title: 'Write note',
theme: Windoo.Themes.wise,
modal:true,
buttons:{'menu':false, 'close':false, 'minimize':false, 'roll':false, 'maximize':false},
destroyOnClose:true,
height:130
});
var cancel = new Element('input', {'type': 'button', 'class':'btn-primary', 'value': 'Cancel','class':'btn-primary'}).setStyle('margin-right', "5px");
cancel.setStyle('margin-left', "5px");
cancel.addEvent('click', function(event) {
$(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer)); $(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer));
windoo.close(); windoo.close();
} }.bindWithEvent(this));
}.bindWithEvent(this));
var panel = new Element('div', {'styles': {'padding-top': 10, 'text-align': 'right'}}).adopt(ok, cancel); var ok = new Element('input', {'type': 'button', 'class':'btn-primary', 'value': 'Ok','class':'btn-primary','id':okButtonId}).setStyle('marginRight', 10);
ok.addEvent('click', function(event) {
var couldBeUpdated = okFunction.attempt();
if (couldBeUpdated) {
$(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer));
windoo.close();
}
}.bindWithEvent(this));
windoo.addPanel(panel); var panel = new Element('div', {'styles': {'padding-top': 10, 'text-align': 'right'}}).adopt(ok, cancel);
$(document).removeEvents('keydown');
return windoo; windoo.addPanel(panel);
}; $(document).removeEvents('keydown');
return windoo;
}
});
mindplot.Note.IMAGE_URL = "../images/note.png"; mindplot.Note.IMAGE_URL = "../images/note.png";

View File

@ -1,45 +1,42 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.NoteModel = function(text, topic) mindplot.NoteModel = new Class({
{ initialize : function(text, topic) {
core.assert(text!=null, 'note text can not be null'); core.assert(text != null, 'note text can not be null');
core.assert(topic, 'mindmap can not be null'); core.assert(topic, 'mindmap can not be null');
this._text = text; this._text = text;
this._topic = topic; this._topic = topic;
}; },
mindplot.NoteModel.prototype.getText = function() getText:function() {
{ return this._text;
return this._text; },
};
mindplot.NoteModel.prototype.setText = function(text) setText : function(text) {
{ this._text = text;
this._text=text; },
};
mindplot.NoteModel.prototype.getTopic = function() getTopic : function() {
{ return this._topic;
return this._topic; },
};
mindplot.NoteModel.prototype.isNoteModel = function() isNoteModel : function() {
{ return true;
return true; }
}; });