2011-11-29 02:38:22 +01:00
|
|
|
/*
|
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
mindplot.Topic = new Class({
|
|
|
|
Extends:mindplot.NodeGraph,
|
2012-02-02 00:31:40 +01:00
|
|
|
initialize : function(model, options) {
|
|
|
|
this.parent(model, options);
|
2011-11-29 02:38:22 +01:00
|
|
|
this._children = [];
|
|
|
|
this._parent = null;
|
|
|
|
this._relationships = [];
|
|
|
|
this._isInWorkspace = false;
|
2012-03-07 05:13:50 +01:00
|
|
|
this._buildTopicShape();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Position a topic ....
|
|
|
|
var pos = model.getPosition();
|
|
|
|
if (pos != null && model.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
|
|
|
this.setPosition(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register events for the topic ...
|
2012-03-23 12:43:07 +01:00
|
|
|
if (!this.isReadOnly()) {
|
2011-11-29 02:38:22 +01:00
|
|
|
this._registerEvents();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_registerEvents : function() {
|
|
|
|
|
|
|
|
this.setMouseEventsEnabled(true);
|
|
|
|
|
|
|
|
// Prevent click on the topics being propagated ...
|
|
|
|
this.addEvent('click', function(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.addEvent('dblclick', function (event) {
|
2012-03-20 12:56:20 +01:00
|
|
|
this._getTopicEventDispatcher().show(this);
|
2012-03-23 12:43:07 +01:00
|
|
|
event.stopPropagation();
|
2011-11-29 02:38:22 +01:00
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
setShapeType : function(type) {
|
|
|
|
this._setShapeType(type, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
getParent : function() {
|
|
|
|
return this._parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
_setShapeType : function(type, updateModel) {
|
|
|
|
// Remove inner shape figure ...
|
|
|
|
var model = this.getModel();
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
model.setShapeType(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
var oldInnerShape = this.getInnerShape();
|
|
|
|
if (oldInnerShape != null) {
|
|
|
|
|
|
|
|
this._removeInnerShape();
|
|
|
|
|
|
|
|
// Create a new one ...
|
|
|
|
var innerShape = this.getInnerShape();
|
|
|
|
|
|
|
|
// Update figure size ...
|
2012-03-07 05:13:50 +01:00
|
|
|
var size = this.getSize();
|
2011-11-29 02:38:22 +01:00
|
|
|
this.setSize(size, true);
|
|
|
|
|
|
|
|
var group = this.get2DElement();
|
|
|
|
group.appendChild(innerShape);
|
|
|
|
|
|
|
|
// Move text to the front ...
|
|
|
|
var text = this.getTextShape();
|
|
|
|
text.moveToFront();
|
|
|
|
|
|
|
|
//Move iconGroup to front ...
|
|
|
|
var iconGroup = this.getIconGroup();
|
|
|
|
if ($defined(iconGroup)) {
|
|
|
|
iconGroup.moveToFront();
|
|
|
|
}
|
2012-03-08 04:30:27 +01:00
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
//Move connector to front
|
|
|
|
var connector = this.getShrinkConnector();
|
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.moveToFront();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getShapeType : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getShapeType();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
result = this._defaultShapeType();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeInnerShape : function() {
|
|
|
|
var group = this.get2DElement();
|
|
|
|
var innerShape = this.getInnerShape();
|
|
|
|
group.removeChild(innerShape);
|
|
|
|
this._innerShape = null;
|
|
|
|
return innerShape;
|
|
|
|
},
|
|
|
|
|
|
|
|
getInnerShape : function() {
|
|
|
|
if (!$defined(this._innerShape)) {
|
|
|
|
// Create inner box.
|
2012-03-07 05:13:50 +01:00
|
|
|
this._innerShape = this._buildShape(mindplot.Topic.INNER_RECT_ATTRIBUTES, this.getShapeType());
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Update bgcolor ...
|
|
|
|
var bgColor = this.getBackgroundColor();
|
|
|
|
this._setBackgroundColor(bgColor, false);
|
|
|
|
|
|
|
|
// Update border color ...
|
|
|
|
var brColor = this.getBorderColor();
|
|
|
|
this._setBorderColor(brColor, false);
|
|
|
|
|
|
|
|
// Define the pointer ...
|
2012-03-23 12:43:07 +01:00
|
|
|
if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && !this.isReadOnly()) {
|
2011-11-29 02:38:22 +01:00
|
|
|
this._innerShape.setCursor('move');
|
|
|
|
} else {
|
|
|
|
this._innerShape.setCursor('default');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return this._innerShape;
|
|
|
|
},
|
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
_buildShape : function(attributes, shapeType) {
|
|
|
|
$assert(attributes, "attributes can not be null");
|
|
|
|
$assert(shapeType, "shapeType can not be null");
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
var result;
|
|
|
|
if (shapeType == mindplot.model.TopicShape.RECTANGLE) {
|
2011-11-29 02:38:22 +01:00
|
|
|
result = new web2d.Rect(0, attributes);
|
2012-03-07 05:13:50 +01:00
|
|
|
} else if (shapeType == mindplot.model.TopicShape.IMAGE) {
|
|
|
|
var model = this.getModel();
|
|
|
|
var url = model.getImageUrl();
|
|
|
|
var size = model.getImageSize();
|
|
|
|
|
|
|
|
result = new web2d.Image();
|
|
|
|
result.setHref(url);
|
|
|
|
result.setSize(size.width, size.height);
|
|
|
|
|
|
|
|
result.getSize = function() {
|
|
|
|
return model.getImageSize();
|
|
|
|
};
|
|
|
|
|
|
|
|
result.setPosition = function() {
|
|
|
|
};
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
2012-03-07 05:13:50 +01:00
|
|
|
else if (shapeType == mindplot.model.TopicShape.ELLIPSE) {
|
2011-11-29 02:38:22 +01:00
|
|
|
result = new web2d.Rect(0.9, attributes);
|
|
|
|
}
|
2012-03-07 05:13:50 +01:00
|
|
|
else if (shapeType == mindplot.model.TopicShape.ROUNDED_RECT) {
|
2011-11-29 02:38:22 +01:00
|
|
|
result = new web2d.Rect(0.3, attributes);
|
|
|
|
}
|
2012-03-07 05:13:50 +01:00
|
|
|
else if (shapeType == mindplot.model.TopicShape.LINE) {
|
2012-01-21 19:30:39 +01:00
|
|
|
result = new web2d.Line({strokeColor:"#495879",strokeWidth:1});
|
2011-11-29 02:38:22 +01:00
|
|
|
result.setSize = function(width, height) {
|
|
|
|
this.size = {width:width, height:height};
|
|
|
|
result.setFrom(0, height);
|
2012-01-21 19:30:39 +01:00
|
|
|
result.setTo(width, height);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Lines will have the same color of the default connection lines...
|
|
|
|
var stokeColor = mindplot.ConnectionLine.getStrokeColor();
|
|
|
|
result.setStroke(1, 'solid', stokeColor);
|
|
|
|
};
|
|
|
|
|
|
|
|
result.getSize = function() {
|
|
|
|
return this.size;
|
|
|
|
};
|
|
|
|
|
|
|
|
result.setPosition = function() {
|
|
|
|
};
|
|
|
|
|
2012-01-21 22:02:38 +01:00
|
|
|
result.setFill = function() {
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-01-21 22:02:38 +01:00
|
|
|
result.setStroke = function() {
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
2012-03-07 05:13:50 +01:00
|
|
|
$assert(false, "Unsupported figure shapeType:" + shapeType);
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
result.setPosition(0, 0);
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setCursor : function(type) {
|
|
|
|
var innerShape = this.getInnerShape();
|
|
|
|
innerShape.setCursor(type);
|
|
|
|
|
|
|
|
var outerShape = this.getOuterShape();
|
|
|
|
outerShape.setCursor(type);
|
|
|
|
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setCursor(type);
|
|
|
|
},
|
|
|
|
|
|
|
|
getOuterShape : function() {
|
|
|
|
if (!$defined(this._outerShape)) {
|
2012-03-07 05:13:50 +01:00
|
|
|
var rect = this._buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.TopicShape.ROUNDED_RECT);
|
2011-11-29 02:38:22 +01:00
|
|
|
rect.setPosition(-2, -3);
|
|
|
|
rect.setOpacity(0);
|
|
|
|
this._outerShape = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._outerShape;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTextShape : function() {
|
|
|
|
if (!$defined(this._text)) {
|
|
|
|
this._text = this._buildTextShape(false);
|
|
|
|
|
|
|
|
// Set Text ...
|
|
|
|
var text = this.getText();
|
|
|
|
this._setText(text, false);
|
|
|
|
}
|
2012-03-07 05:13:50 +01:00
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
return this._text;
|
|
|
|
},
|
|
|
|
|
|
|
|
getOrBuildIconGroup : function() {
|
|
|
|
if (!$defined(this._iconsGroup)) {
|
|
|
|
this._iconsGroup = this._buildIconGroup();
|
|
|
|
var group = this.get2DElement();
|
|
|
|
group.appendChild(this._iconsGroup.getNativeElement());
|
|
|
|
this._iconsGroup.moveToFront();
|
|
|
|
}
|
|
|
|
return this._iconsGroup;
|
|
|
|
},
|
|
|
|
|
|
|
|
getIconGroup : function() {
|
|
|
|
return this._iconsGroup;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildIconGroup : function() {
|
|
|
|
var textHeight = this.getTextShape().getFontHeight();
|
|
|
|
var result = new mindplot.IconGroup(this.getId(), textHeight);
|
|
|
|
var padding = this._getInnerPadding();
|
|
|
|
result.setPosition(padding, padding);
|
|
|
|
|
2012-02-27 22:17:15 +01:00
|
|
|
// Load topic features ...
|
2011-11-29 02:38:22 +01:00
|
|
|
var model = this.getModel();
|
2012-02-27 22:17:15 +01:00
|
|
|
var featuresModel = model.getFeatures();
|
|
|
|
for (var i = 0; i < featuresModel.length; i++) {
|
|
|
|
var featureModel = featuresModel[i];
|
|
|
|
var icon = mindplot.TopicFeature.createIcon(this, featureModel);
|
|
|
|
result.addIcon(icon, featureModel.getType() == "icon"); // @Todo: Remove hack ...
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-02-27 22:17:15 +01:00
|
|
|
addFeature : function(type, attributes) {
|
2011-11-29 02:38:22 +01:00
|
|
|
var iconGroup = this.getOrBuildIconGroup();
|
2012-02-27 22:17:15 +01:00
|
|
|
this.closeEditors();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
var model = this.getModel();
|
|
|
|
|
2012-02-27 22:17:15 +01:00
|
|
|
// Update model ...
|
|
|
|
var feature = model.createFeature(type, attributes);
|
|
|
|
model.addFeature(feature);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-02-27 22:17:15 +01:00
|
|
|
var result = mindplot.TopicFeature.createIcon(this, feature);
|
|
|
|
iconGroup.addIcon(result, type == "icon"); // @Todo: Remove hack ...
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
this._adjustShapes();
|
2012-02-27 22:17:15 +01:00
|
|
|
return result;
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
2012-02-27 22:17:15 +01:00
|
|
|
findFeatureById : function(id) {
|
2011-11-29 02:38:22 +01:00
|
|
|
var model = this.getModel();
|
2012-02-27 22:17:15 +01:00
|
|
|
return model.findFeatureById(id);
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
2012-02-27 22:17:15 +01:00
|
|
|
removeFeature : function(featureModel) {
|
|
|
|
$assert(featureModel, "featureModel could not be null");
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
//Removing the icon from MODEL
|
|
|
|
var model = this.getModel();
|
2012-02-27 22:17:15 +01:00
|
|
|
model.removeFeature(featureModel);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
//Removing the icon from UI
|
|
|
|
var iconGroup = this.getIconGroup();
|
|
|
|
if ($defined(iconGroup)) {
|
2012-02-27 22:17:15 +01:00
|
|
|
iconGroup.removeIconByModel(featureModel);
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
this._adjustShapes();
|
|
|
|
},
|
|
|
|
|
|
|
|
connectByRelation : function(relationship) {
|
|
|
|
this._relationships.push(relationship);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeRelationship : function(relationship) {
|
|
|
|
this._relationships.erase(relationship);
|
|
|
|
},
|
|
|
|
|
|
|
|
getRelationships : function() {
|
|
|
|
return this._relationships;
|
|
|
|
},
|
|
|
|
|
|
|
|
_buildTextShape : function(readOnly) {
|
|
|
|
var result = new web2d.Text();
|
|
|
|
var family = this.getFontFamily();
|
|
|
|
var size = this.getFontSize();
|
|
|
|
var weight = this.getFontWeight();
|
|
|
|
var style = this.getFontStyle();
|
|
|
|
result.setFont(family, size, style, weight);
|
|
|
|
|
|
|
|
var color = this.getFontColor();
|
|
|
|
result.setColor(color);
|
|
|
|
|
|
|
|
if (!readOnly) {
|
|
|
|
// Propagate mouse events ...
|
|
|
|
if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
|
|
|
result.setCursor('move');
|
|
|
|
} else {
|
|
|
|
result.setCursor('default');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getInnerPadding : function() {
|
|
|
|
throw "this must be implemented";
|
|
|
|
},
|
|
|
|
|
|
|
|
setFontFamily : function(value, updateModel) {
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setFontFamily(value);
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setFontFamily(value);
|
|
|
|
}
|
|
|
|
this._adjustShapes(updateModel);
|
|
|
|
},
|
|
|
|
|
|
|
|
setFontSize : function(value, updateModel) {
|
|
|
|
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setSize(value);
|
|
|
|
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setFontSize(value);
|
|
|
|
}
|
|
|
|
this._adjustShapes(updateModel);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
setFontStyle : function(value, updateModel) {
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setStyle(value);
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setFontStyle(value);
|
|
|
|
}
|
|
|
|
this._adjustShapes(updateModel);
|
|
|
|
},
|
|
|
|
|
|
|
|
setFontWeight : function(value, updateModel) {
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setWeight(value);
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setFontWeight(value);
|
|
|
|
}
|
|
|
|
this._adjustShapes();
|
|
|
|
},
|
|
|
|
|
|
|
|
getFontWeight : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getFontWeight();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
var font = this._defaultFontStyle();
|
|
|
|
result = font.weight;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFontFamily : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getFontFamily();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
var font = this._defaultFontStyle();
|
|
|
|
result = font.font;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFontColor : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getFontColor();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
var font = this._defaultFontStyle();
|
|
|
|
result = font.color;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFontStyle : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getFontStyle();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
var font = this._defaultFontStyle();
|
|
|
|
result = font.style;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFontSize : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getFontSize();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
var font = this._defaultFontStyle();
|
|
|
|
result = font.size;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
setFontColor : function(value, updateModel) {
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setColor(value);
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setFontColor(value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_setText : function(text, updateModel) {
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setText(text == null ? this._defaultText() : text);
|
|
|
|
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setText(text);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setText : function(text) {
|
|
|
|
// Avoid empty nodes ...
|
|
|
|
if (text.trim().length == 0) {
|
|
|
|
text = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._setText(text, true);
|
|
|
|
this._adjustShapes();
|
|
|
|
},
|
|
|
|
|
|
|
|
getText : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getText();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
result = this._defaultText();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
setBackgroundColor : function(color) {
|
|
|
|
this._setBackgroundColor(color, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setBackgroundColor : function(color, updateModel) {
|
|
|
|
var innerShape = this.getInnerShape();
|
|
|
|
innerShape.setFill(color);
|
|
|
|
|
|
|
|
var connector = this.getShrinkConnector();
|
2012-03-08 04:30:27 +01:00
|
|
|
if (connector) {
|
|
|
|
connector.setFill(color);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setBackgroundColor(color);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getBackgroundColor : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getBackgroundColor();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
result = this._defaultBackgroundColor();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
setBorderColor : function(color) {
|
|
|
|
this._setBorderColor(color, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setBorderColor : function(color, updateModel) {
|
|
|
|
var innerShape = this.getInnerShape();
|
|
|
|
innerShape.setAttribute('strokeColor', color);
|
|
|
|
|
|
|
|
var connector = this.getShrinkConnector();
|
2012-03-08 04:30:27 +01:00
|
|
|
if (connector) {
|
|
|
|
connector.setAttribute('strokeColor', color);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
if ($defined(updateModel) && updateModel) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setBorderColor(color);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getBorderColor : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
var result = model.getBorderColor();
|
|
|
|
if (!$defined(result)) {
|
|
|
|
result = this._defaultBorderColor();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
_buildTopicShape : function() {
|
2011-11-29 02:38:22 +01:00
|
|
|
var groupAttributes = {width: 100, height:100,coordSizeWidth:100,coordSizeHeight:100};
|
|
|
|
var group = new web2d.Group(groupAttributes);
|
|
|
|
this._set2DElement(group);
|
|
|
|
|
|
|
|
// Shape must be build based on the model width ...
|
|
|
|
var outerShape = this.getOuterShape();
|
|
|
|
var innerShape = this.getInnerShape();
|
|
|
|
var textShape = this.getTextShape();
|
|
|
|
|
|
|
|
// Add to the group ...
|
|
|
|
group.appendChild(outerShape);
|
|
|
|
group.appendChild(innerShape);
|
|
|
|
group.appendChild(textShape);
|
|
|
|
|
|
|
|
// Update figure size ...
|
|
|
|
var model = this.getModel();
|
2012-02-27 22:17:15 +01:00
|
|
|
if (model.getFeatures().length != 0) {
|
2011-11-29 02:38:22 +01:00
|
|
|
this.getOrBuildIconGroup();
|
|
|
|
}
|
|
|
|
|
2012-03-08 04:30:27 +01:00
|
|
|
var shrinkConnector = this.getShrinkConnector();
|
|
|
|
if ($defined(shrinkConnector)) {
|
2011-11-29 02:38:22 +01:00
|
|
|
shrinkConnector.addToWorkspace(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register listeners ...
|
|
|
|
this._registerDefaultListenersToElement(group, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
_registerDefaultListenersToElement : function(elem, topic) {
|
|
|
|
var mouseOver = function(event) {
|
|
|
|
if (topic.isMouseEventsEnabled()) {
|
|
|
|
topic.handleMouseOver(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
elem.addEvent('mouseover', mouseOver);
|
|
|
|
|
|
|
|
var outout = function(event) {
|
|
|
|
if (topic.isMouseEventsEnabled()) {
|
|
|
|
topic.handleMouseOut(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
elem.addEvent('mouseout', outout);
|
|
|
|
|
|
|
|
// Focus events ...
|
2012-03-20 12:56:20 +01:00
|
|
|
elem.addEvent('mousedown', function(event) {
|
2012-03-23 12:43:07 +01:00
|
|
|
if (!this.isReadOnly()) {
|
|
|
|
// Disable topic selection of readOnly mode ...
|
|
|
|
var value = true;
|
|
|
|
if ((event.meta && Browser.Platform.mac) || (event.control && !Browser.Platform.mac)) {
|
|
|
|
value = !this.isOnFocus();
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
topic.setOnFocus(value);
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
2012-03-20 12:56:20 +01:00
|
|
|
|
|
|
|
var eventDispatcher = this._getTopicEventDispatcher();
|
|
|
|
eventDispatcher.process(mindplot.TopicEvent.CLICK, this);
|
2012-03-23 12:43:07 +01:00
|
|
|
event.stopPropagation();
|
|
|
|
|
2012-03-20 12:56:20 +01:00
|
|
|
}.bind(this));
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
2012-01-12 03:30:26 +01:00
|
|
|
areChildrenShrunken : function() {
|
2011-11-29 02:38:22 +01:00
|
|
|
var model = this.getModel();
|
2012-01-12 03:30:26 +01:00
|
|
|
return model.areChildrenShrunken();
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isCollapsed : function() {
|
|
|
|
var result = false;
|
|
|
|
|
|
|
|
var current = this.getParent();
|
|
|
|
while (current && !result) {
|
2012-01-12 03:30:26 +01:00
|
|
|
result = current.areChildrenShrunken();
|
2011-11-29 02:38:22 +01:00
|
|
|
current = current.getParent();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2012-01-12 03:30:26 +01:00
|
|
|
setChildrenShrunken : function(value) {
|
2011-11-29 02:38:22 +01:00
|
|
|
// Update Model ...
|
|
|
|
var model = this.getModel();
|
2012-01-12 03:30:26 +01:00
|
|
|
model.setChildrenShrunken(value);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Change render base on the state.
|
2012-03-08 00:35:06 +01:00
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
var shrinkConnector = this.getShrinkConnector();
|
2012-03-08 04:30:27 +01:00
|
|
|
if ($defined(shrinkConnector)) {
|
|
|
|
shrinkConnector.changeRender(value);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-08 00:35:06 +01:00
|
|
|
// Do some fancy animation ....
|
|
|
|
var elements = this._flatten2DElements(this);
|
|
|
|
var fade = new mindplot.util.FadeEffect(elements, !value);
|
|
|
|
fade.addEvent('complete', function() {
|
|
|
|
|
|
|
|
});
|
|
|
|
fade.start();
|
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeShrinkEvent, model);
|
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getShrinkConnector : function() {
|
|
|
|
var result = this._connector;
|
|
|
|
if (this._connector == null) {
|
|
|
|
this._connector = new mindplot.ShirinkConnector(this);
|
|
|
|
this._connector.setVisibility(false);
|
|
|
|
result = this._connector;
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleMouseOver : function() {
|
|
|
|
var outerShape = this.getOuterShape();
|
|
|
|
outerShape.setOpacity(1);
|
|
|
|
},
|
|
|
|
|
2012-02-28 02:47:10 +01:00
|
|
|
handleMouseOut : function() {
|
2011-11-29 02:38:22 +01:00
|
|
|
var outerShape = this.getOuterShape();
|
|
|
|
if (!this.isOnFocus()) {
|
|
|
|
outerShape.setOpacity(0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showTextEditor : function(text) {
|
2012-03-20 12:56:20 +01:00
|
|
|
this._getTopicEventDispatcher().show(this, {text:text});
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
showNoteEditor : function() {
|
|
|
|
|
|
|
|
var topicId = this.getId();
|
|
|
|
var model = this.getModel();
|
|
|
|
var editorModel = {
|
|
|
|
getValue : function() {
|
2012-02-27 22:17:15 +01:00
|
|
|
var notes = model.findFeatureByType(mindplot.TopicFeature.Note.id);
|
2011-11-29 02:38:22 +01:00
|
|
|
var result;
|
|
|
|
if (notes.length > 0)
|
|
|
|
result = notes[0].getText();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue : function(value) {
|
|
|
|
var dispatcher = mindplot.ActionDispatcher.getInstance();
|
2012-02-27 22:17:15 +01:00
|
|
|
var notes = model.findFeatureByType(mindplot.TopicFeature.Note.id);
|
2011-11-29 02:38:22 +01:00
|
|
|
if (!$defined(value)) {
|
2012-02-27 22:17:15 +01:00
|
|
|
var featureId = notes[0].getId();
|
|
|
|
dispatcher.removeFeatureFromTopic(topicId, featureId);
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-02-27 22:17:15 +01:00
|
|
|
if (notes.length > 0) {
|
|
|
|
dispatcher.changeFeatureToTopic(topicId, notes[0].getId(), {text:value});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dispatcher.addFeatureToTopic(topicId, mindplot.TopicFeature.Note.id, {text:value});
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var editor = new mindplot.widget.NoteEditor(editorModel);
|
|
|
|
this.closeEditors();
|
|
|
|
editor.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
showLinkEditor : function() {
|
|
|
|
|
|
|
|
var topicId = this.getId();
|
|
|
|
var model = this.getModel();
|
|
|
|
var editorModel = {
|
|
|
|
getValue : function() {
|
2012-02-27 22:17:15 +01:00
|
|
|
var links = model.findFeatureByType(mindplot.TopicFeature.Link.id);
|
2011-11-29 02:38:22 +01:00
|
|
|
var result;
|
|
|
|
if (links.length > 0)
|
|
|
|
result = links[0].getUrl();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
setValue : function(value) {
|
|
|
|
var dispatcher = mindplot.ActionDispatcher.getInstance();
|
2012-02-27 22:17:15 +01:00
|
|
|
var links = model.findFeatureByType(mindplot.TopicFeature.Link.id);
|
2011-11-29 02:38:22 +01:00
|
|
|
if (!$defined(value)) {
|
2012-02-27 22:17:15 +01:00
|
|
|
var featureId = links[0].getId();
|
|
|
|
dispatcher.removeFeatureFromTopic(topicId, featureId);
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-02-27 22:17:15 +01:00
|
|
|
if (links.length > 0) {
|
|
|
|
dispatcher.changeFeatureToTopic(topicId, links[0].getId(), {url:value});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dispatcher.addFeatureToTopic(topicId, mindplot.TopicFeature.Link.id, {url:value});
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.closeEditors();
|
|
|
|
var editor = new mindplot.widget.LinkEditor(editorModel);
|
|
|
|
editor.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
closeEditors : function() {
|
2012-03-20 12:56:20 +01:00
|
|
|
this._getTopicEventDispatcher().close(true);
|
2012-03-08 03:51:37 +01:00
|
|
|
},
|
|
|
|
|
2012-03-20 12:56:20 +01:00
|
|
|
_getTopicEventDispatcher : function() {
|
|
|
|
return mindplot.TopicEventDispatcher.getInstance();
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Point: references the center of the rect shape.!!!
|
|
|
|
*/
|
|
|
|
setPosition : function(point) {
|
|
|
|
$assert(point, "position can not be null");
|
2012-01-21 19:30:39 +01:00
|
|
|
point.x = Math.ceil(point.x);
|
|
|
|
point.y = Math.ceil(point.y);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Update model's position ...
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setPosition(point.x, point.y);
|
2012-01-21 19:30:39 +01:00
|
|
|
|
2012-01-14 14:45:39 +01:00
|
|
|
// Elements are positioned in the center.
|
|
|
|
// All topic element must be positioned based on the innerShape.
|
|
|
|
var size = this.getSize();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-01-21 19:30:39 +01:00
|
|
|
var cx = point.x - (size.width / 2);
|
|
|
|
var cy = point.y - (size.height / 2);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-01-14 14:45:39 +01:00
|
|
|
// Update visual position.
|
|
|
|
this._elem2d.setPosition(cx, cy);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-01-14 14:45:39 +01:00
|
|
|
// Update connection lines ...
|
|
|
|
this._updateConnectionLines();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-01-14 14:45:39 +01:00
|
|
|
// Check object state.
|
|
|
|
this.invariant();
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getOutgoingLine : function() {
|
|
|
|
return this._outgoingLine;
|
|
|
|
},
|
|
|
|
|
|
|
|
getIncomingLines : function() {
|
|
|
|
var result = [];
|
2012-03-07 05:13:50 +01:00
|
|
|
var children = this.getChildren();
|
2011-11-29 02:38:22 +01:00
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
var node = children[i];
|
|
|
|
var line = node.getOutgoingLine();
|
|
|
|
if ($defined(line)) {
|
|
|
|
result.push(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
getOutgoingConnectedTopic : function() {
|
|
|
|
var result = null;
|
|
|
|
var line = this.getOutgoingLine();
|
|
|
|
if ($defined(line)) {
|
|
|
|
result = line.getTargetTopic();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateConnectionLines : function() {
|
|
|
|
// Update this to parent line ...
|
|
|
|
var outgoingLine = this.getOutgoingLine();
|
|
|
|
if ($defined(outgoingLine)) {
|
|
|
|
outgoingLine.redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update all the incoming lines ...
|
|
|
|
var incomingLines = this.getIncomingLines();
|
|
|
|
for (var i = 0; i < incomingLines.length; i++) {
|
|
|
|
incomingLines[i].redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update relationship lines
|
|
|
|
for (var j = 0; j < this._relationships.length; j++) {
|
|
|
|
this._relationships[j].redraw();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setBranchVisibility : function(value) {
|
|
|
|
var current = this;
|
|
|
|
var parent = this;
|
|
|
|
while (parent != null && parent.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
|
|
|
current = parent;
|
|
|
|
parent = current.getParent();
|
|
|
|
}
|
|
|
|
current.setVisibility(value);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setVisibility : function(value) {
|
|
|
|
this._setTopicVisibility(value);
|
|
|
|
|
|
|
|
// Hide all children...
|
|
|
|
this._setChildrenVisibility(value);
|
|
|
|
|
|
|
|
this._setRelationshipLinesVisibility(value);
|
|
|
|
},
|
|
|
|
|
|
|
|
moveToBack : function() {
|
|
|
|
|
|
|
|
// Update relationship lines
|
|
|
|
for (var j = 0; j < this._relationships.length; j++) {
|
|
|
|
this._relationships[j].moveToBack();
|
|
|
|
}
|
|
|
|
var connector = this.getShrinkConnector();
|
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.moveToBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.get2DElement().moveToBack();
|
|
|
|
},
|
|
|
|
|
|
|
|
moveToFront : function() {
|
|
|
|
|
|
|
|
this.get2DElement().moveToFront();
|
|
|
|
var connector = this.getShrinkConnector();
|
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.moveToFront();
|
|
|
|
}
|
|
|
|
// Update relationship lines
|
|
|
|
for (var j = 0; j < this._relationships.length; j++) {
|
|
|
|
this._relationships[j].moveToFront();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
isVisible : function() {
|
|
|
|
var elem = this.get2DElement();
|
|
|
|
return elem.isVisible();
|
|
|
|
},
|
|
|
|
|
|
|
|
_setRelationshipLinesVisibility : function(value) {
|
|
|
|
this._relationships.forEach(function(relationship) {
|
|
|
|
relationship.setVisibility(value);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setTopicVisibility : function(value) {
|
|
|
|
var elem = this.get2DElement();
|
|
|
|
elem.setVisibility(value);
|
|
|
|
|
|
|
|
if (this.getIncomingLines().length > 0) {
|
|
|
|
var connector = this.getShrinkConnector();
|
2012-03-08 04:30:27 +01:00
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.setVisibility(value);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var textShape = this.getTextShape();
|
2012-03-07 05:13:50 +01:00
|
|
|
textShape.setVisibility(this.getShapeType() != mindplot.model.TopicShape.IMAGE ? value : false);
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
setOpacity : function(opacity) {
|
|
|
|
var elem = this.get2DElement();
|
|
|
|
elem.setOpacity(opacity);
|
|
|
|
|
2012-03-08 04:30:27 +01:00
|
|
|
var connector = this.getShrinkConnector();
|
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.setOpacity(opacity);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
var textShape = this.getTextShape();
|
|
|
|
textShape.setOpacity(opacity);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setChildrenVisibility : function(isVisible) {
|
|
|
|
|
|
|
|
// Hide all children.
|
2012-03-07 05:13:50 +01:00
|
|
|
var children = this.getChildren();
|
2011-11-29 02:38:22 +01:00
|
|
|
var model = this.getModel();
|
|
|
|
|
2012-01-12 03:30:26 +01:00
|
|
|
isVisible = isVisible ? !model.areChildrenShrunken() : isVisible;
|
2011-11-29 02:38:22 +01:00
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
var child = children[i];
|
|
|
|
child.setVisibility(isVisible);
|
|
|
|
|
|
|
|
var outgoingLine = child.getOutgoingLine();
|
|
|
|
outgoingLine.setVisibility(isVisible);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
invariant : function() {
|
|
|
|
var line = this._outgoingLine;
|
|
|
|
var model = this.getModel();
|
|
|
|
var isConnected = model.isConnected();
|
|
|
|
|
|
|
|
// Check consistency...
|
|
|
|
if ((isConnected && !line) || (!isConnected && line)) {
|
|
|
|
// $assert(false,'Illegal state exception.');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-01-21 19:30:39 +01:00
|
|
|
setSize : function(size, force) {
|
2011-11-29 02:38:22 +01:00
|
|
|
$assert(size, "size can not be null");
|
|
|
|
$assert($defined(size.width), "size seem not to be a valid element");
|
2012-01-21 19:30:39 +01:00
|
|
|
size = {width:Math.ceil(size.width),height: Math.ceil(size.height)};
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-01-18 05:26:39 +01:00
|
|
|
var oldSize = this.getSize();
|
2012-01-21 19:47:21 +01:00
|
|
|
var hasSizeChanged = oldSize.width != size.width || oldSize.height != size.height;
|
|
|
|
if (hasSizeChanged || force) {
|
2012-01-21 19:30:39 +01:00
|
|
|
mindplot.NodeGraph.prototype.setSize.call(this, size);
|
2012-01-18 05:26:39 +01:00
|
|
|
|
2012-01-21 19:30:39 +01:00
|
|
|
var outerShape = this.getOuterShape();
|
|
|
|
var innerShape = this.getInnerShape();
|
2012-01-18 05:26:39 +01:00
|
|
|
|
2012-01-21 19:30:39 +01:00
|
|
|
outerShape.setSize(size.width + 4, size.height + 6);
|
|
|
|
innerShape.setSize(size.width, size.height);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-01-21 19:30:39 +01:00
|
|
|
// Update the figure position(ej: central topic must be centered) and children position.
|
|
|
|
this._updatePositionOnChangeSize(oldSize, size);
|
|
|
|
|
2012-01-21 19:47:21 +01:00
|
|
|
if (hasSizeChanged) {
|
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent, {node:this.getModel(),size:size});
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-28 02:47:10 +01:00
|
|
|
_updatePositionOnChangeSize : function() {
|
2012-01-18 05:26:39 +01:00
|
|
|
$assert(false, "this method must be overwrited.");
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
disconnect : function(workspace) {
|
|
|
|
var outgoingLine = this.getOutgoingLine();
|
|
|
|
if ($defined(outgoingLine)) {
|
|
|
|
$assert(workspace, 'workspace can not be null');
|
|
|
|
|
|
|
|
this._outgoingLine = null;
|
|
|
|
|
|
|
|
// Disconnect nodes ...
|
|
|
|
var targetTopic = outgoingLine.getTargetTopic();
|
|
|
|
targetTopic.removeChild(this);
|
|
|
|
|
|
|
|
// Update model ...
|
|
|
|
var childModel = this.getModel();
|
|
|
|
childModel.disconnect();
|
|
|
|
|
|
|
|
this._parent = null;
|
|
|
|
|
|
|
|
// Remove graphical element from the workspace...
|
|
|
|
outgoingLine.removeFromWorkspace(workspace);
|
|
|
|
|
|
|
|
// Remove from workspace.
|
2012-01-10 03:50:52 +01:00
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent, this.getModel());
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Change text based on the current connection ...
|
|
|
|
var model = this.getModel();
|
|
|
|
if (!model.getText()) {
|
|
|
|
var text = this.getText();
|
|
|
|
this._setText(text, false);
|
|
|
|
}
|
|
|
|
if (!model.getFontSize()) {
|
|
|
|
var size = this.getFontSize();
|
|
|
|
this.setFontSize(size, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide connection line?.
|
2012-03-07 05:13:50 +01:00
|
|
|
if (targetTopic.getChildren().length == 0) {
|
2011-11-29 02:38:22 +01:00
|
|
|
var connector = targetTopic.getShrinkConnector();
|
2012-03-08 04:30:27 +01:00
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.setVisibility(false);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getOrder : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
return model.getOrder();
|
|
|
|
},
|
|
|
|
|
|
|
|
setOrder : function(value) {
|
|
|
|
var model = this.getModel();
|
|
|
|
model.setOrder(value);
|
|
|
|
},
|
|
|
|
|
|
|
|
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');
|
|
|
|
$assert(workspace, 'Workspace can not be null');
|
|
|
|
|
|
|
|
// Connect Graphical Nodes ...
|
|
|
|
targetTopic.appendChild(this);
|
|
|
|
this._parent = targetTopic;
|
|
|
|
|
|
|
|
// Update model ...
|
|
|
|
var targetModel = targetTopic.getModel();
|
|
|
|
var childModel = this.getModel();
|
|
|
|
childModel.connectTo(targetModel);
|
|
|
|
|
|
|
|
// Create a connection line ...
|
|
|
|
var outgoingLine = new mindplot.ConnectionLine(this, targetTopic);
|
2012-03-07 05:13:50 +01:00
|
|
|
if ($defined(isVisible)) {
|
2011-11-29 02:38:22 +01:00
|
|
|
outgoingLine.setVisibility(isVisible);
|
2012-03-07 05:13:50 +01:00
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
this._outgoingLine = outgoingLine;
|
|
|
|
workspace.appendChild(outgoingLine);
|
|
|
|
|
|
|
|
// Update figure is necessary.
|
|
|
|
this.updateTopicShape(targetTopic);
|
|
|
|
|
|
|
|
// Change text based on the current connection ...
|
|
|
|
var model = this.getModel();
|
|
|
|
if (!model.getText()) {
|
|
|
|
var text = this.getText();
|
|
|
|
this._setText(text, false);
|
|
|
|
}
|
|
|
|
if (!model.getFontSize()) {
|
|
|
|
var size = this.getFontSize();
|
|
|
|
this.setFontSize(size, false);
|
|
|
|
}
|
2012-01-21 22:02:38 +01:00
|
|
|
this.getTextShape();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Display connection node...
|
|
|
|
var connector = targetTopic.getShrinkConnector();
|
2012-03-08 04:30:27 +01:00
|
|
|
if ($defined(connector)) {
|
|
|
|
connector.setVisibility(true);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Redraw line ...
|
|
|
|
outgoingLine.redraw();
|
2012-01-10 03:50:52 +01:00
|
|
|
|
|
|
|
// Fire connection event ...
|
|
|
|
if (this.isInWorkspace()) {
|
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:targetTopic.getModel(), childNode: this.getModel()});
|
|
|
|
}
|
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
appendChild : function(child) {
|
2012-03-07 05:13:50 +01:00
|
|
|
var children = this.getChildren();
|
2011-11-29 02:38:22 +01:00
|
|
|
children.push(child);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeChild : function(child) {
|
2012-03-07 05:13:50 +01:00
|
|
|
var children = this.getChildren();
|
2011-11-29 02:38:22 +01:00
|
|
|
children.erase(child);
|
|
|
|
},
|
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
getChildren : function() {
|
2011-11-29 02:38:22 +01:00
|
|
|
var result = this._children;
|
|
|
|
if (!$defined(result)) {
|
|
|
|
this._children = [];
|
|
|
|
result = this._children;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeFromWorkspace : function(workspace) {
|
|
|
|
var elem2d = this.get2DElement();
|
|
|
|
workspace.removeChild(elem2d);
|
|
|
|
var line = this.getOutgoingLine();
|
|
|
|
if ($defined(line)) {
|
|
|
|
workspace.removeChild(line);
|
|
|
|
}
|
|
|
|
this._isInWorkspace = false;
|
2012-01-11 22:41:09 +01:00
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRemoved, this.getModel());
|
2011-11-29 02:38:22 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
addToWorkspace : function(workspace) {
|
|
|
|
var elem = this.get2DElement();
|
|
|
|
workspace.appendChild(elem);
|
2012-01-10 03:50:52 +01:00
|
|
|
if (!this.isInWorkspace()) {
|
2012-01-21 22:02:38 +01:00
|
|
|
if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeAdded, this.getModel());
|
|
|
|
}
|
2012-01-10 03:50:52 +01:00
|
|
|
|
|
|
|
if (this.getModel().isConnected())
|
|
|
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:this.getOutgoingConnectedTopic().getModel(), childNode: this.getModel()});
|
|
|
|
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
this._isInWorkspace = true;
|
|
|
|
this._adjustShapes();
|
|
|
|
},
|
|
|
|
|
|
|
|
isInWorkspace : function() {
|
|
|
|
return this._isInWorkspace;
|
|
|
|
},
|
|
|
|
|
2012-01-31 00:17:47 +01:00
|
|
|
createDragNode : function(layoutManager) {
|
|
|
|
var result = this.parent(layoutManager);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
// Is the node already connected ?
|
|
|
|
var targetTopic = this.getOutgoingConnectedTopic();
|
|
|
|
if ($defined(targetTopic)) {
|
|
|
|
result.connectTo(targetTopic);
|
2012-01-21 13:37:01 +01:00
|
|
|
result.setVisibility(false);
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// If a drag node is create for it, let's hide the editor.
|
2012-03-20 12:56:20 +01:00
|
|
|
this._getTopicEventDispatcher().close();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
_adjustShapes : function() {
|
|
|
|
if (this._isInWorkspace) {
|
2012-03-07 05:13:50 +01:00
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
var textShape = this.getTextShape();
|
2012-03-07 05:13:50 +01:00
|
|
|
if (this.getShapeType() != mindplot.model.TopicShape.IMAGE) {
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
var textWidth = textShape.getWidth();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
var textHeight = textShape.getHeight();
|
|
|
|
textHeight = textHeight != 0 ? textHeight : 20;
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
var topicPadding = this._getInnerPadding();
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
// Adjust the icon size to the size of the text ...
|
|
|
|
var iconGroup = this.getOrBuildIconGroup();
|
|
|
|
var fontHeight = this.getTextShape().getFontHeight();
|
|
|
|
iconGroup.setPosition(topicPadding, topicPadding);
|
|
|
|
iconGroup.seIconSize(fontHeight, fontHeight);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
// Add a extra padding between the text and the icons
|
|
|
|
var iconsWidth = iconGroup.getSize().width;
|
|
|
|
if (iconsWidth != 0) {
|
|
|
|
|
|
|
|
iconsWidth = iconsWidth + (textHeight / 4);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
var height = textHeight + (topicPadding * 2);
|
|
|
|
var width = textWidth + iconsWidth + (topicPadding * 2);
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
this.setSize({width:width,height:height});
|
2011-11-29 02:38:22 +01:00
|
|
|
|
2012-03-07 05:13:50 +01:00
|
|
|
// Position node ...
|
|
|
|
textShape.setPosition(topicPadding + iconsWidth, topicPadding);
|
|
|
|
} else {
|
|
|
|
// In case of images, the size if fixed ...
|
|
|
|
var size = this.getModel().getImageSize();
|
|
|
|
this.setSize(size);
|
|
|
|
}
|
2011-11-29 02:38:22 +01:00
|
|
|
}
|
2012-03-08 00:35:06 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
_flatten2DElements : function(topic) {
|
|
|
|
var result = [];
|
|
|
|
|
|
|
|
var children = topic.getChildren();
|
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
|
|
|
|
|
|
var child = children[i];
|
|
|
|
result.push(child);
|
|
|
|
result.push(child.getOutgoingLine());
|
|
|
|
|
|
|
|
var relationships = child.getRelationships();
|
|
|
|
result = result.concat(relationships);
|
|
|
|
|
2012-03-08 04:11:54 +01:00
|
|
|
var innerChilds = this._flatten2DElements(child);
|
2012-03-08 00:35:06 +01:00
|
|
|
result = result.concat(innerChilds);
|
|
|
|
}
|
|
|
|
return result;
|
2012-01-12 01:12:22 +01:00
|
|
|
}
|
2012-01-14 13:58:06 +01:00
|
|
|
|
2011-11-29 02:38:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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.INNER_RECT_ATTRIBUTES = {stroke:'2 solid'};
|
2011-12-01 22:07:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|