- Add support for copy and paste.

This commit is contained in:
Paulo Gustavo Veiga
2012-07-08 18:41:35 -03:00
parent a5acdc7bb7
commit 8175eea928
25 changed files with 446 additions and 326 deletions

View File

@@ -19,7 +19,7 @@
mindplot.Topic = new Class({
Extends:mindplot.NodeGraph,
initialize : function(model, options) {
initialize:function (model, options) {
this.parent(model, options);
this._children = [];
this._parent = null;
@@ -39,12 +39,12 @@ mindplot.Topic = new Class({
}
},
_registerEvents : function() {
_registerEvents:function () {
this.setMouseEventsEnabled(true);
// Prevent click on the topics being propagated ...
this.addEvent('click', function(event) {
this.addEvent('click', function (event) {
event.stopPropagation();
});
@@ -54,15 +54,15 @@ mindplot.Topic = new Class({
}.bind(this));
},
setShapeType : function(type) {
setShapeType:function (type) {
this._setShapeType(type, true);
},
getParent : function() {
getParent:function () {
return this._parent;
},
_setShapeType : function(type, updateModel) {
_setShapeType:function (type, updateModel) {
// Remove inner shape figure ...
var model = this.getModel();
if ($defined(updateModel) && updateModel) {
@@ -103,7 +103,7 @@ mindplot.Topic = new Class({
},
getShapeType : function() {
getShapeType:function () {
var model = this.getModel();
var result = model.getShapeType();
if (!$defined(result)) {
@@ -112,7 +112,7 @@ mindplot.Topic = new Class({
return result;
},
_removeInnerShape : function() {
_removeInnerShape:function () {
var group = this.get2DElement();
var innerShape = this.getInnerShape();
group.removeChild(innerShape);
@@ -120,7 +120,7 @@ mindplot.Topic = new Class({
return innerShape;
},
getInnerShape : function() {
getInnerShape:function () {
if (!$defined(this._innerShape)) {
// Create inner box.
this._innerShape = this._buildShape(mindplot.Topic.INNER_RECT_ATTRIBUTES, this.getShapeType());
@@ -144,7 +144,7 @@ mindplot.Topic = new Class({
return this._innerShape;
},
_buildShape : function(attributes, shapeType) {
_buildShape:function (attributes, shapeType) {
$assert(attributes, "attributes can not be null");
$assert(shapeType, "shapeType can not be null");
@@ -160,11 +160,11 @@ mindplot.Topic = new Class({
result.setHref(url);
result.setSize(size.width, size.height);
result.getSize = function() {
result.getSize = function () {
return model.getImageSize();
};
result.setPosition = function() {
result.setPosition = function () {
};
}
else if (shapeType == mindplot.model.TopicShape.ELLIPSE) {
@@ -174,8 +174,8 @@ mindplot.Topic = new Class({
result = new web2d.Rect(0.3, attributes);
}
else if (shapeType == mindplot.model.TopicShape.LINE) {
result = new web2d.Line({strokeColor:"#495879",strokeWidth:1});
result.setSize = function(width, height) {
result = new web2d.Line({strokeColor:"#495879", strokeWidth:1});
result.setSize = function (width, height) {
this.size = {width:width, height:height};
result.setFrom(0, height);
result.setTo(width, height);
@@ -185,18 +185,18 @@ mindplot.Topic = new Class({
result.setStroke(1, 'solid', stokeColor);
};
result.getSize = function() {
result.getSize = function () {
return this.size;
};
result.setPosition = function() {
result.setPosition = function () {
};
result.setFill = function() {
result.setFill = function () {
};
result.setStroke = function() {
result.setStroke = function () {
};
}
@@ -208,7 +208,7 @@ mindplot.Topic = new Class({
},
setCursor : function(type) {
setCursor:function (type) {
var innerShape = this.getInnerShape();
innerShape.setCursor(type);
@@ -219,7 +219,7 @@ mindplot.Topic = new Class({
textShape.setCursor(type);
},
getOuterShape : function() {
getOuterShape:function () {
if (!$defined(this._outerShape)) {
var rect = this._buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.TopicShape.ROUNDED_RECT);
rect.setPosition(-2, -3);
@@ -230,7 +230,7 @@ mindplot.Topic = new Class({
return this._outerShape;
},
getTextShape : function() {
getTextShape:function () {
if (!$defined(this._text)) {
this._text = this._buildTextShape(false);
@@ -242,7 +242,7 @@ mindplot.Topic = new Class({
return this._text;
},
getOrBuildIconGroup : function() {
getOrBuildIconGroup:function () {
if (!$defined(this._iconsGroup)) {
this._iconsGroup = this._buildIconGroup();
var group = this.get2DElement();
@@ -252,11 +252,11 @@ mindplot.Topic = new Class({
return this._iconsGroup;
},
getIconGroup : function() {
getIconGroup:function () {
return this._iconsGroup;
},
_buildIconGroup : function() {
_buildIconGroup:function () {
var textHeight = this.getTextShape().getFontHeight();
var result = new mindplot.IconGroup(this.getId(), textHeight);
var padding = this._getInnerPadding();
@@ -274,7 +274,7 @@ mindplot.Topic = new Class({
return result;
},
addFeature : function(type, attributes) {
addFeature:function (type, attributes) {
var iconGroup = this.getOrBuildIconGroup();
this.closeEditors();
@@ -291,12 +291,12 @@ mindplot.Topic = new Class({
return result;
},
findFeatureById : function(id) {
findFeatureById:function (id) {
var model = this.getModel();
return model.findFeatureById(id);
},
removeFeature : function(featureModel) {
removeFeature:function (featureModel) {
$assert(featureModel, "featureModel could not be null");
//Removing the icon from MODEL
@@ -311,19 +311,19 @@ mindplot.Topic = new Class({
this._adjustShapes();
},
addRelationship : function(relationship) {
addRelationship:function (relationship) {
this._relationships.push(relationship);
},
deleteRelationship : function(relationship) {
deleteRelationship:function (relationship) {
this._relationships.erase(relationship);
},
getRelationships : function() {
getRelationships:function () {
return this._relationships;
},
_buildTextShape : function(readOnly) {
_buildTextShape:function (readOnly) {
var result = new web2d.Text();
var family = this.getFontFamily();
var size = this.getFontSize();
@@ -346,11 +346,11 @@ mindplot.Topic = new Class({
return result;
},
_getInnerPadding : function() {
_getInnerPadding:function () {
throw "this must be implemented";
},
setFontFamily : function(value, updateModel) {
setFontFamily:function (value, updateModel) {
var textShape = this.getTextShape();
textShape.setFontFamily(value);
if ($defined(updateModel) && updateModel) {
@@ -360,7 +360,7 @@ mindplot.Topic = new Class({
this._adjustShapes(updateModel);
},
setFontSize : function(value, updateModel) {
setFontSize:function (value, updateModel) {
var textShape = this.getTextShape();
textShape.setSize(value);
@@ -373,7 +373,7 @@ mindplot.Topic = new Class({
},
setFontStyle : function(value, updateModel) {
setFontStyle:function (value, updateModel) {
var textShape = this.getTextShape();
textShape.setStyle(value);
if ($defined(updateModel) && updateModel) {
@@ -383,7 +383,7 @@ mindplot.Topic = new Class({
this._adjustShapes(updateModel);
},
setFontWeight : function(value, updateModel) {
setFontWeight:function (value, updateModel) {
var textShape = this.getTextShape();
textShape.setWeight(value);
if ($defined(updateModel) && updateModel) {
@@ -393,7 +393,7 @@ mindplot.Topic = new Class({
this._adjustShapes();
},
getFontWeight : function() {
getFontWeight:function () {
var model = this.getModel();
var result = model.getFontWeight();
if (!$defined(result)) {
@@ -403,7 +403,7 @@ mindplot.Topic = new Class({
return result;
},
getFontFamily : function() {
getFontFamily:function () {
var model = this.getModel();
var result = model.getFontFamily();
if (!$defined(result)) {
@@ -413,7 +413,7 @@ mindplot.Topic = new Class({
return result;
},
getFontColor : function() {
getFontColor:function () {
var model = this.getModel();
var result = model.getFontColor();
if (!$defined(result)) {
@@ -423,7 +423,7 @@ mindplot.Topic = new Class({
return result;
},
getFontStyle : function() {
getFontStyle:function () {
var model = this.getModel();
var result = model.getFontStyle();
if (!$defined(result)) {
@@ -433,7 +433,7 @@ mindplot.Topic = new Class({
return result;
},
getFontSize : function() {
getFontSize:function () {
var model = this.getModel();
var result = model.getFontSize();
if (!$defined(result)) {
@@ -443,7 +443,7 @@ mindplot.Topic = new Class({
return result;
},
setFontColor : function(value, updateModel) {
setFontColor:function (value, updateModel) {
var textShape = this.getTextShape();
textShape.setColor(value);
if ($defined(updateModel) && updateModel) {
@@ -452,7 +452,7 @@ mindplot.Topic = new Class({
}
},
_setText : function(text, updateModel) {
_setText:function (text, updateModel) {
var textShape = this.getTextShape();
textShape.setText(text == null ? this._defaultText() : text);
@@ -462,7 +462,7 @@ mindplot.Topic = new Class({
}
},
setText : function(text) {
setText:function (text) {
// Avoid empty nodes ...
if (text.trim().length == 0) {
text = null;
@@ -472,7 +472,7 @@ mindplot.Topic = new Class({
this._adjustShapes();
},
getText : function() {
getText:function () {
var model = this.getModel();
var result = model.getText();
if (!$defined(result)) {
@@ -481,11 +481,11 @@ mindplot.Topic = new Class({
return result;
},
setBackgroundColor : function(color) {
setBackgroundColor:function (color) {
this._setBackgroundColor(color, true);
},
_setBackgroundColor : function(color, updateModel) {
_setBackgroundColor:function (color, updateModel) {
var innerShape = this.getInnerShape();
innerShape.setFill(color);
@@ -500,7 +500,7 @@ mindplot.Topic = new Class({
}
},
getBackgroundColor : function() {
getBackgroundColor:function () {
var model = this.getModel();
var result = model.getBackgroundColor();
if (!$defined(result)) {
@@ -509,11 +509,11 @@ mindplot.Topic = new Class({
return result;
},
setBorderColor : function(color) {
setBorderColor:function (color) {
this._setBorderColor(color, true);
},
_setBorderColor : function(color, updateModel) {
_setBorderColor:function (color, updateModel) {
var innerShape = this.getInnerShape();
innerShape.setAttribute('strokeColor', color);
@@ -528,7 +528,7 @@ mindplot.Topic = new Class({
}
},
getBorderColor : function() {
getBorderColor:function () {
var model = this.getModel();
var result = model.getBorderColor();
if (!$defined(result)) {
@@ -537,8 +537,8 @@ mindplot.Topic = new Class({
return result;
},
_buildTopicShape : function() {
var groupAttributes = {width: 100, height:100,coordSizeWidth:100,coordSizeHeight:100};
_buildTopicShape:function () {
var groupAttributes = {width:100, height:100, coordSizeWidth:100, coordSizeHeight:100};
var group = new web2d.Group(groupAttributes);
this._set2DElement(group);
@@ -567,15 +567,15 @@ mindplot.Topic = new Class({
this._registerDefaultListenersToElement(group, this);
},
_registerDefaultListenersToElement : function(elem, topic) {
var mouseOver = function(event) {
_registerDefaultListenersToElement:function (elem, topic) {
var mouseOver = function (event) {
if (topic.isMouseEventsEnabled()) {
topic.handleMouseOver(event);
}
};
elem.addEvent('mouseover', mouseOver);
var outout = function(event) {
var outout = function (event) {
if (topic.isMouseEventsEnabled()) {
topic.handleMouseOut(event);
}
@@ -583,7 +583,7 @@ mindplot.Topic = new Class({
elem.addEvent('mouseout', outout);
// Focus events ...
elem.addEvent('mousedown', function(event) {
elem.addEvent('mousedown', function (event) {
if (!this.isReadOnly()) {
// Disable topic selection of readOnly mode ...
var value = true;
@@ -602,12 +602,12 @@ mindplot.Topic = new Class({
}.bind(this));
},
areChildrenShrunken : function() {
areChildrenShrunken:function () {
var model = this.getModel();
return model.areChildrenShrunken();
},
isCollapsed : function() {
isCollapsed:function () {
var result = false;
var current = this.getParent();
@@ -618,7 +618,7 @@ mindplot.Topic = new Class({
return result;
},
setChildrenShrunken : function(value) {
setChildrenShrunken:function (value) {
// Update Model ...
var model = this.getModel();
model.setChildrenShrunken(value);
@@ -632,7 +632,7 @@ mindplot.Topic = new Class({
// Do some fancy animation ....
var elements = this._flatten2DElements(this);
var fade = new mindplot.util.FadeEffect(elements, !value);
fade.addEvent('complete', function() {
fade.addEvent('complete', function () {
});
fade.start();
@@ -640,7 +640,7 @@ mindplot.Topic = new Class({
},
getShrinkConnector : function() {
getShrinkConnector:function () {
var result = this._connector;
if (this._connector == null) {
this._connector = new mindplot.ShirinkConnector(this);
@@ -651,28 +651,28 @@ mindplot.Topic = new Class({
return result;
},
handleMouseOver : function() {
handleMouseOver:function () {
var outerShape = this.getOuterShape();
outerShape.setOpacity(1);
},
handleMouseOut : function() {
handleMouseOut:function () {
var outerShape = this.getOuterShape();
if (!this.isOnFocus()) {
outerShape.setOpacity(0);
}
},
showTextEditor : function(text) {
showTextEditor:function (text) {
this._getTopicEventDispatcher().show(this, {text:text});
},
showNoteEditor : function() {
showNoteEditor:function () {
var topicId = this.getId();
var model = this.getModel();
var editorModel = {
getValue : function() {
getValue:function () {
var notes = model.findFeatureByType(mindplot.TopicFeature.Note.id);
var result;
if (notes.length > 0)
@@ -681,7 +681,7 @@ mindplot.Topic = new Class({
return result;
},
setValue : function(value) {
setValue:function (value) {
var dispatcher = mindplot.ActionDispatcher.getInstance();
var notes = model.findFeatureByType(mindplot.TopicFeature.Note.id);
if (!$defined(value)) {
@@ -703,12 +703,12 @@ mindplot.Topic = new Class({
editor.show();
},
showLinkEditor : function() {
showLinkEditor:function () {
var topicId = this.getId();
var model = this.getModel();
var editorModel = {
getValue : function() {
getValue:function () {
var links = model.findFeatureByType(mindplot.TopicFeature.Link.id);
var result;
if (links.length > 0)
@@ -717,7 +717,7 @@ mindplot.Topic = new Class({
return result;
},
setValue : function(value) {
setValue:function (value) {
var dispatcher = mindplot.ActionDispatcher.getInstance();
var links = model.findFeatureByType(mindplot.TopicFeature.Link.id);
if (!$defined(value)) {
@@ -740,18 +740,18 @@ mindplot.Topic = new Class({
editor.show();
},
closeEditors : function() {
closeEditors:function () {
this._getTopicEventDispatcher().close(true);
},
_getTopicEventDispatcher : function() {
_getTopicEventDispatcher:function () {
return mindplot.TopicEventDispatcher.getInstance();
},
/**
* Point: references the center of the rect shape.!!!
*/
setPosition : function(point) {
setPosition:function (point) {
$assert(point, "position can not be null");
point.x = Math.ceil(point.x);
point.y = Math.ceil(point.y);
@@ -777,11 +777,11 @@ mindplot.Topic = new Class({
this.invariant();
},
getOutgoingLine : function() {
getOutgoingLine:function () {
return this._outgoingLine;
},
getIncomingLines : function() {
getIncomingLines:function () {
var result = [];
var children = this.getChildren();
for (var i = 0; i < children.length; i++) {
@@ -794,7 +794,7 @@ mindplot.Topic = new Class({
return result;
},
getOutgoingConnectedTopic : function() {
getOutgoingConnectedTopic:function () {
var result = null;
var line = this.getOutgoingLine();
if ($defined(line)) {
@@ -803,7 +803,7 @@ mindplot.Topic = new Class({
return result;
},
_updateConnectionLines : function() {
_updateConnectionLines:function () {
// Update this to parent line ...
var outgoingLine = this.getOutgoingLine();
if ($defined(outgoingLine)) {
@@ -822,7 +822,7 @@ mindplot.Topic = new Class({
}
},
setBranchVisibility : function(value) {
setBranchVisibility:function (value) {
var current = this;
var parent = this;
while (parent != null && parent.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
@@ -833,7 +833,7 @@ mindplot.Topic = new Class({
},
setVisibility : function(value) {
setVisibility:function (value) {
this._setTopicVisibility(value);
// Hide all children...
@@ -842,7 +842,7 @@ mindplot.Topic = new Class({
this._setRelationshipLinesVisibility(value);
},
moveToBack : function() {
moveToBack:function () {
// Update relationship lines
for (var j = 0; j < this._relationships.length; j++) {
@@ -856,7 +856,7 @@ mindplot.Topic = new Class({
this.get2DElement().moveToBack();
},
moveToFront : function() {
moveToFront:function () {
this.get2DElement().moveToFront();
var connector = this.getShrinkConnector();
@@ -869,18 +869,18 @@ mindplot.Topic = new Class({
}
},
isVisible : function() {
isVisible:function () {
var elem = this.get2DElement();
return elem.isVisible();
},
_setRelationshipLinesVisibility : function(value) {
this._relationships.forEach(function(relationship) {
_setRelationshipLinesVisibility:function (value) {
this._relationships.forEach(function (relationship) {
relationship.setVisibility(value);
});
},
_setTopicVisibility : function(value) {
_setTopicVisibility:function (value) {
var elem = this.get2DElement();
elem.setVisibility(value);
@@ -895,7 +895,7 @@ mindplot.Topic = new Class({
textShape.setVisibility(this.getShapeType() != mindplot.model.TopicShape.IMAGE ? value : false);
},
setOpacity : function(opacity) {
setOpacity:function (opacity) {
var elem = this.get2DElement();
elem.setOpacity(opacity);
@@ -907,7 +907,7 @@ mindplot.Topic = new Class({
textShape.setOpacity(opacity);
},
_setChildrenVisibility : function(isVisible) {
_setChildrenVisibility:function (isVisible) {
// Hide all children.
var children = this.getChildren();
@@ -924,7 +924,7 @@ mindplot.Topic = new Class({
},
invariant : function() {
invariant:function () {
var line = this._outgoingLine;
var model = this.getModel();
var isConnected = model.isConnected();
@@ -936,10 +936,10 @@ mindplot.Topic = new Class({
},
setSize : function(size, force) {
setSize:function (size, force) {
$assert(size, "size can not be null");
$assert($defined(size.width), "size seem not to be a valid element");
size = {width:Math.ceil(size.width),height: Math.ceil(size.height)};
size = {width:Math.ceil(size.width), height:Math.ceil(size.height)};
var oldSize = this.getSize();
var hasSizeChanged = oldSize.width != size.width || oldSize.height != size.height;
@@ -956,16 +956,16 @@ mindplot.Topic = new Class({
this._updatePositionOnChangeSize(oldSize, size);
if (hasSizeChanged) {
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent, {node:this.getModel(),size:size});
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent, {node:this.getModel(), size:size});
}
}
},
_updatePositionOnChangeSize : function() {
_updatePositionOnChangeSize:function () {
$assert(false, "this method must be overwrited.");
},
disconnect : function(workspace) {
disconnect:function (workspace) {
var outgoingLine = this.getOutgoingLine();
if ($defined(outgoingLine)) {
$assert(workspace, 'workspace can not be null');
@@ -1009,17 +1009,17 @@ mindplot.Topic = new Class({
}
},
getOrder : function() {
getOrder:function () {
var model = this.getModel();
return model.getOrder();
},
setOrder : function(value) {
setOrder:function (value) {
var model = this.getModel();
model.setOrder(value);
},
connectTo : function(targetTopic, workspace, isVisible) {
connectTo:function (targetTopic, workspace, isVisible) {
$assert(!this._outgoingLine, 'Could not connect an already connected node');
$assert(targetTopic != this, 'Cilcular connection are not allowed');
$assert(targetTopic, 'Parent Graph can not be null');
@@ -1068,22 +1068,22 @@ mindplot.Topic = new Class({
// Fire connection event ...
if (this.isInWorkspace()) {
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:targetTopic.getModel(), childNode: this.getModel()});
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:targetTopic.getModel(), childNode:this.getModel()});
}
},
appendChild : function(child) {
appendChild:function (child) {
var children = this.getChildren();
children.push(child);
},
removeChild : function(child) {
removeChild:function (child) {
var children = this.getChildren();
children.erase(child);
},
getChildren : function() {
getChildren:function () {
var result = this._children;
if (!$defined(result)) {
this._children = [];
@@ -1092,7 +1092,7 @@ mindplot.Topic = new Class({
return result;
},
removeFromWorkspace : function(workspace) {
removeFromWorkspace:function (workspace) {
var elem2d = this.get2DElement();
workspace.removeChild(elem2d);
var line = this.getOutgoingLine();
@@ -1103,7 +1103,7 @@ mindplot.Topic = new Class({
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRemoved, this.getModel());
},
addToWorkspace : function(workspace) {
addToWorkspace:function (workspace) {
var elem = this.get2DElement();
workspace.appendChild(elem);
if (!this.isInWorkspace()) {
@@ -1112,18 +1112,18 @@ mindplot.Topic = new Class({
}
if (this.getModel().isConnected())
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:this.getOutgoingConnectedTopic().getModel(), childNode: this.getModel()});
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:this.getOutgoingConnectedTopic().getModel(), childNode:this.getModel()});
}
}
this._isInWorkspace = true;
this._adjustShapes();
},
isInWorkspace : function() {
isInWorkspace:function () {
return this._isInWorkspace;
},
createDragNode : function(layoutManager) {
createDragNode:function (layoutManager) {
var result = this.parent(layoutManager);
// Is the node already connected ?
@@ -1139,7 +1139,7 @@ mindplot.Topic = new Class({
return result;
},
_adjustShapes : function() {
_adjustShapes:function () {
if (this._isInWorkspace) {
var textShape = this.getTextShape();
@@ -1168,7 +1168,7 @@ mindplot.Topic = new Class({
var height = textHeight + (topicPadding * 2);
var width = textWidth + iconsWidth + (topicPadding * 2);
this.setSize({width:width,height:height});
this.setSize({width:width, height:height});
// Position node ...
textShape.setPosition(topicPadding + iconsWidth, topicPadding);
@@ -1180,7 +1180,7 @@ mindplot.Topic = new Class({
}
},
_flatten2DElements : function(topic) {
_flatten2DElements:function (topic) {
var result = [];
var children = topic.getChildren();
@@ -1203,8 +1203,8 @@ mindplot.Topic = new Class({
mindplot.Topic.CONNECTOR_WIDTH = 6;
mindplot.Topic.OUTER_SHAPE_ATTRIBUTES = {fillColor:'rgb(252,235,192)',stroke:'1 dot rgb(241,163,39)',x:0,y:0};
mindplot.Topic.OUTER_SHAPE_ATTRIBUTES_FOCUS = {fillColor:'rgb(244,184,45)',x:0,y:0};
mindplot.Topic.OUTER_SHAPE_ATTRIBUTES = {fillColor:'rgb(252,235,192)', stroke:'1 dot rgb(241,163,39)', x:0, y:0};
mindplot.Topic.OUTER_SHAPE_ATTRIBUTES_FOCUS = {fillColor:'rgb(244,184,45)', x:0, y:0};
mindplot.Topic.INNER_RECT_ATTRIBUTES = {stroke:'2 solid'};