2010-12-22 19:34:24 -03:00
|
|
|
/*
|
2011-07-28 14:07:01 -03: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.NodeGraph = new Class({
|
2011-08-20 10:50:48 -03:00
|
|
|
initialize:function(nodeModel, options) {
|
2011-08-05 01:06:56 -03:00
|
|
|
$assert(nodeModel, "model can not be null");
|
2011-08-20 10:50:48 -03:00
|
|
|
|
|
|
|
this._options = options;
|
2011-07-28 14:07:01 -03:00
|
|
|
this._mouseEvents = true;
|
|
|
|
this.setModel(nodeModel);
|
|
|
|
this._onFocus = false;
|
2011-10-04 01:16:29 -03:00
|
|
|
this._event = new Events();
|
2012-03-07 01:13:50 -03:00
|
|
|
this._size = {width:50,height:20};
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
getType : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
return model.getType();
|
|
|
|
},
|
|
|
|
|
|
|
|
setId : function(id) {
|
|
|
|
this.getModel().setId(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
_set2DElement : function(elem2d) {
|
|
|
|
this._elem2d = elem2d;
|
|
|
|
},
|
|
|
|
|
|
|
|
get2DElement : function() {
|
2011-08-15 09:27:31 -03:00
|
|
|
$assert(this._elem2d, 'NodeGraph has not been initialized properly');
|
2011-07-28 14:07:01 -03:00
|
|
|
return this._elem2d;
|
|
|
|
},
|
|
|
|
|
2011-11-13 21:18:34 -03:00
|
|
|
setPosition : function(point, fireEvent) {
|
|
|
|
throw "Unsupported operation";
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
2011-08-21 12:42:00 -03:00
|
|
|
addEvent : function(type, listener) {
|
2011-10-04 01:16:29 -03:00
|
|
|
var elem = type.substr(0, 3) == "ont" ? this._event : this.get2DElement();
|
2011-08-21 12:42:00 -03:00
|
|
|
elem.addEvent(type, listener);
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
2011-10-04 01:16:29 -03:00
|
|
|
removeEvent : function(type, listener) {
|
|
|
|
var elem = type.substr(0, 3) == "ont" ? this._event : this.get2DElement();
|
|
|
|
elem.removeEvent(type, listener);
|
|
|
|
},
|
|
|
|
|
|
|
|
fireEvent: function(type) {
|
|
|
|
var elem = type.substr(0, 3) == "ont" ? this._event : this.get2DElement();
|
2011-11-13 21:18:34 -03:00
|
|
|
elem.fireEvent(type, this);
|
2011-10-04 01:16:29 -03:00
|
|
|
},
|
|
|
|
|
2011-07-28 14:07:01 -03:00
|
|
|
setMouseEventsEnabled : function(isEnabled) {
|
|
|
|
this._mouseEvents = isEnabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
isMouseEventsEnabled : function() {
|
|
|
|
return this._mouseEvents;
|
|
|
|
},
|
|
|
|
|
|
|
|
getSize : function() {
|
2012-03-07 01:13:50 -03:00
|
|
|
return this._size;
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
setSize : function(size) {
|
2012-03-07 01:13:50 -03:00
|
|
|
this._size.width = parseInt(size.width);
|
|
|
|
this._size.height = parseInt(size.height);
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
2011-08-05 01:06:56 -03:00
|
|
|
getModel:function() {
|
|
|
|
$assert(this._model, 'Model has not been initialized yet');
|
|
|
|
return this._model;
|
|
|
|
},
|
2011-07-28 14:07:01 -03:00
|
|
|
|
|
|
|
setModel : function(model) {
|
|
|
|
$assert(model, 'Model can not be null');
|
|
|
|
this._model = model;
|
|
|
|
},
|
|
|
|
|
|
|
|
getId : function() {
|
|
|
|
return this._model.getId();
|
|
|
|
},
|
|
|
|
|
|
|
|
setOnFocus : function(focus) {
|
2011-10-04 01:16:29 -03:00
|
|
|
if (this._onFocus != focus) {
|
2011-08-19 13:38:37 -03:00
|
|
|
|
2011-10-04 01:16:29 -03:00
|
|
|
this._onFocus = focus;
|
|
|
|
var outerShape = this.getOuterShape();
|
|
|
|
if (focus) {
|
2011-10-14 22:56:20 -03:00
|
|
|
outerShape.setFill(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES_FOCUS.fillColor);
|
2011-10-04 01:16:29 -03:00
|
|
|
outerShape.setOpacity(1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
outerShape.setFill(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES.fillColor);
|
|
|
|
outerShape.setOpacity(0);
|
|
|
|
}
|
|
|
|
this.setCursor('move');
|
|
|
|
|
|
|
|
// In any case, always try to hide the editor ...
|
|
|
|
this.closeEditors();
|
|
|
|
|
|
|
|
// Fire event ...
|
|
|
|
this.fireEvent(focus ? 'ontfocus' : 'ontblur');
|
|
|
|
|
|
|
|
}
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
isOnFocus : function() {
|
|
|
|
return this._onFocus;
|
|
|
|
},
|
|
|
|
|
|
|
|
dispose : function(workspace) {
|
2011-08-20 10:50:48 -03:00
|
|
|
this.setOnFocus(false);
|
2011-07-28 14:07:01 -03:00
|
|
|
workspace.removeChild(this);
|
|
|
|
},
|
|
|
|
|
2012-01-30 20:17:47 -03:00
|
|
|
createDragNode : function(layoutManager) {
|
2011-07-28 14:07:01 -03:00
|
|
|
var dragShape = this._buildDragShape();
|
2012-01-30 20:17:47 -03:00
|
|
|
return new mindplot.DragTopic(dragShape, this, layoutManager);
|
2011-07-28 14:07:01 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
_buildDragShape : function() {
|
|
|
|
$assert(false, '_buildDragShape must be implemented by all nodes.');
|
|
|
|
},
|
|
|
|
|
|
|
|
getPosition : function() {
|
|
|
|
var model = this.getModel();
|
|
|
|
return model.getPosition();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-08-20 10:50:48 -03:00
|
|
|
mindplot.NodeGraph.create = function(nodeModel, options) {
|
2011-07-27 14:33:02 -03:00
|
|
|
$assert(nodeModel, 'Model can not be null');
|
2009-06-07 18:59:43 +00:00
|
|
|
|
|
|
|
var type = nodeModel.getType();
|
2011-07-27 14:33:02 -03:00
|
|
|
$assert(type, 'Node model type can not be null');
|
2009-06-07 18:59:43 +00:00
|
|
|
|
|
|
|
var result;
|
2011-09-08 10:03:42 -03:00
|
|
|
if (type == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
|
2011-08-20 10:50:48 -03:00
|
|
|
result = new mindplot.CentralTopic(nodeModel, options);
|
2009-06-07 18:59:43 +00:00
|
|
|
} else
|
2011-09-08 10:03:42 -03:00
|
|
|
if (type == mindplot.model.INodeModel.MAIN_TOPIC_TYPE) {
|
2011-08-20 10:50:48 -03:00
|
|
|
result = new mindplot.MainTopic(nodeModel, options);
|
2011-07-28 14:07:01 -03:00
|
|
|
} else {
|
2011-11-13 21:18:34 -03:00
|
|
|
$assert(false, "unsupported node type:" + type);
|
2011-07-28 14:07:01 -03:00
|
|
|
}
|
2009-06-07 18:59:43 +00:00
|
|
|
|
|
|
|
return result;
|
2011-11-13 21:18:34 -03:00
|
|
|
};
|