wisemapping-open-source/mindplot/src/main/javascript/NodeGraph.js

162 lines
4.7 KiB
JavaScript
Raw Normal View History

/*
2011-07-28 19:07:01 +02: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 15:50:48 +02:00
initialize:function(nodeModel, options) {
2011-08-05 06:06:56 +02:00
$assert(nodeModel, "model can not be null");
2011-08-20 15:50:48 +02:00
this._options = options;
2011-07-28 19:07:01 +02:00
this._mouseEvents = true;
this.setModel(nodeModel);
this._onFocus = false;
2011-10-04 06:16:29 +02:00
this._event = new Events();
2011-07-28 19:07:01 +02: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 14:27:31 +02:00
$assert(this._elem2d, 'NodeGraph has not been initialized properly');
2011-07-28 19:07:01 +02:00
return this._elem2d;
},
2011-11-14 01:18:34 +01:00
setPosition : function(point, fireEvent) {
throw "Unsupported operation";
2011-07-28 19:07:01 +02:00
},
2011-08-21 17:42:00 +02:00
addEvent : function(type, listener) {
2011-10-04 06:16:29 +02:00
var elem = type.substr(0, 3) == "ont" ? this._event : this.get2DElement();
2011-08-21 17:42:00 +02:00
elem.addEvent(type, listener);
2011-07-28 19:07:01 +02:00
},
2011-10-04 06:16:29 +02: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-14 01:18:34 +01:00
elem.fireEvent(type, this);
2011-10-04 06:16:29 +02:00
},
2011-07-28 19:07:01 +02:00
setMouseEventsEnabled : function(isEnabled) {
this._mouseEvents = isEnabled;
},
isMouseEventsEnabled : function() {
return this._mouseEvents;
},
getSize : function() {
return this._model.getSize();
},
setSize : function(size) {
2011-10-11 00:31:10 +02:00
this._model.setSize(parseInt(size.width), parseInt(size.height));
2011-07-28 19:07:01 +02:00
},
2011-08-05 06:06:56 +02:00
getModel:function() {
$assert(this._model, 'Model has not been initialized yet');
return this._model;
},
2011-07-28 19:07:01 +02: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 06:16:29 +02:00
if (this._onFocus != focus) {
2011-10-04 06:16:29 +02:00
this._onFocus = focus;
var outerShape = this.getOuterShape();
if (focus) {
2011-10-15 03:56:20 +02:00
outerShape.setFill(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES_FOCUS.fillColor);
2011-10-04 06:16:29 +02: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 19:07:01 +02:00
},
isOnFocus : function() {
return this._onFocus;
},
dispose : function(workspace) {
2011-08-20 15:50:48 +02:00
this.setOnFocus(false);
2011-07-28 19:07:01 +02:00
workspace.removeChild(this);
},
createDragNode : function() {
var dragShape = this._buildDragShape();
return new mindplot.DragTopic(dragShape, this);
},
_buildDragShape : function() {
$assert(false, '_buildDragShape must be implemented by all nodes.');
},
getPosition : function() {
var model = this.getModel();
return model.getPosition();
}
});
2011-08-20 15:50:48 +02:00
mindplot.NodeGraph.create = function(nodeModel, options) {
$assert(nodeModel, 'Model can not be null');
2009-06-07 20:59:43 +02:00
var type = nodeModel.getType();
$assert(type, 'Node model type can not be null');
2009-06-07 20:59:43 +02:00
var result;
2011-09-08 15:03:42 +02:00
if (type == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
2011-08-20 15:50:48 +02:00
result = new mindplot.CentralTopic(nodeModel, options);
2009-06-07 20:59:43 +02:00
} else
2011-09-08 15:03:42 +02:00
if (type == mindplot.model.INodeModel.MAIN_TOPIC_TYPE) {
2011-08-20 15:50:48 +02:00
result = new mindplot.MainTopic(nodeModel, options);
2011-07-28 19:07:01 +02:00
} else {
2011-11-14 01:18:34 +01:00
$assert(false, "unsupported node type:" + type);
2011-07-28 19:07:01 +02:00
}
2009-06-07 20:59:43 +02:00
return result;
2011-11-14 01:18:34 +01:00
};