162 lines
5.6 KiB
JavaScript
Raw Normal View History

2011-07-26 15:07:53 -03:00
/*
2011-07-27 21:01:54 -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.layout.OriginalLayoutManager = new Class({
Extends:mindplot.layout.BaseLayoutManager,
2011-03-17 15:51:40 +00:00
options:{
},
2011-07-26 15:07:53 -03:00
initialize:function(designer, options) {
2011-03-17 15:51:40 +00:00
this.parent(designer, options);
this._dragTopicPositioner = new mindplot.DragTopicPositioner(this);
// Init drag manager.
2011-03-17 15:51:40 +00:00
var workSpace = this.getDesigner().getWorkSpace();
this._dragger = this._buildDragManager(workSpace);
// Add shapes to speed up the loading process ...
mindplot.DragTopic.init(workSpace);
2011-03-17 15:51:40 +00:00
},
2011-07-26 15:07:53 -03:00
prepareNode:function(node, children) {
2011-04-12 13:59:03 +01:00
// Sort children by order to solve adding order in for OriginalLayoutManager...
2011-04-15 12:59:21 +01:00
var nodesByOrder = new Hash();
2011-07-26 15:07:53 -03:00
var maxOrder = 0;
2011-04-12 13:59:03 +01:00
var result = [];
2011-07-26 15:07:53 -03:00
if (children.length > 0) {
for (var i = 0; i < children.length; i++) {
2011-04-12 13:59:03 +01:00
var child = children[i];
var order = child.getOrder();
if (!$defined(order)) {
2011-04-16 15:52:21 +01:00
order = ++maxOrder;
child.setOrder(order);
2011-04-15 12:59:21 +01:00
}
2011-07-26 15:07:53 -03:00
if (nodesByOrder.has(order)) {
if (Math.sign(child.getPosition().x) == Math.sign(nodesByOrder.get(order).getPosition().x)) {
2011-04-16 15:52:21 +01:00
//duplicated order. Change order to next available.
order = ++maxOrder;
child.setOrder(order);
}
2011-07-26 15:07:53 -03:00
} else {
2011-04-15 12:59:21 +01:00
nodesByOrder.set(order, child);
2011-07-26 15:07:53 -03:00
if (order > maxOrder)
maxOrder = order;
2011-04-12 13:59:03 +01:00
}
2011-04-15 12:59:21 +01:00
result[order] = child;
2011-04-12 13:59:03 +01:00
}
}
2011-07-26 15:07:53 -03:00
nodesByOrder = null;
return node.getTopicType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE ? result : children;
2011-04-12 13:59:03 +01:00
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
_nodeResizeEvent:function(node) {
2011-03-17 15:51:40 +00:00
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
_nodeRepositionateEvent:function(node) {
2011-03-17 15:51:40 +00:00
this.getTopicBoardForTopic(node).repositionate();
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
getDragTopicPositioner : function() {
2011-03-17 15:51:40 +00:00
return this._dragTopicPositioner;
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
_buildDragManager: function(workspace) {
2011-03-17 15:51:40 +00:00
// Init dragger manager.
var dragger = new mindplot.DragManager(workspace);
var topics = this.getDesigner()._getTopics();
var dragTopicPositioner = this.getDragTopicPositioner();
2011-07-26 15:07:53 -03:00
dragger.addEventListener('startdragging', function(event, node) {
2011-03-17 15:51:40 +00:00
// Enable all mouse events.
2011-07-26 15:07:53 -03:00
for (var i = 0; i < topics.length; i++) {
2011-03-17 15:51:40 +00:00
topics[i].setMouseEventsEnabled(false);
}
});
2011-07-26 15:07:53 -03:00
dragger.addEventListener('dragging', function(event, dragTopic) {
2011-03-17 15:51:40 +00:00
// Update the state and connections of the topic ...
dragTopicPositioner.positionateDragTopic(dragTopic);
});
2011-07-26 15:07:53 -03:00
dragger.addEventListener('enddragging', function(event, dragTopic) {
2011-03-17 15:51:40 +00:00
// Enable all mouse events.
2011-07-26 15:07:53 -03:00
for (var i = 0; i < topics.length; i++) {
2011-03-17 15:51:40 +00:00
topics[i].setMouseEventsEnabled(true);
}
// Topic must be positioned in the real board postion.
2011-07-26 15:07:53 -03:00
if (dragTopic._isInTheWorkspace) {
2011-03-17 15:51:40 +00:00
var draggedTopic = dragTopic.getDraggedTopic();
// Hide topic during draw ...
draggedTopic.setBranchVisibility(false);
var parentNode = draggedTopic.getParent();
dragTopic.updateDraggedTopic(workspace);
// Make all node visible ...
draggedTopic.setVisibility(true);
2011-07-26 15:07:53 -03:00
if (parentNode != null) {
2011-03-17 15:51:40 +00:00
parentNode.setBranchVisibility(true);
}
}
});
return dragger;
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
registerListenersOnNode : function(topic) {
2011-03-17 15:51:40 +00:00
// Register node listeners ...
var designer = this.getDesigner();
topic.addEventListener('click', function(event) {
2011-08-05 01:06:56 -03:00
designer.onObjectFocusEvent(topic, event);
// Prevent click on the topics being propagated ...
event.stopPropagation();
2011-03-17 15:51:40 +00:00
});
// Add drag behaviour ...
if (topic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) {
2011-03-17 15:51:40 +00:00
// Central Topic doesn't support to be dragged
var dragger = this._dragger;
dragger.add(topic);
}
2011-03-29 17:06:59 +01:00
// Register editor events ...
if (!$defined(this.getDesigner()._viewMode) || ($defined(this.getDesigner()._viewMode) && !this.getDesigner()._viewMode)) {
2011-03-29 17:06:59 +01:00
this.getDesigner()._editor.listenEventOnNode(topic, 'dblclick', true);
}
2011-03-17 15:51:40 +00:00
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
_createMainTopicBoard:function(node) {
2011-03-24 18:00:51 +00:00
return new mindplot.MainTopicBoard(node, this);
2011-03-17 15:51:40 +00:00
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
_createCentralTopicBoard:function(node) {
return new mindplot.CentralTopicBoard(node, this);
2011-03-17 16:28:19 +00:00
},
2011-08-05 01:06:56 -03:00
2011-07-26 15:07:53 -03:00
getClassName:function() {
2011-07-27 21:01:54 -03:00
return mindplot.layout.OriginalLayoutManager.NAME;
2011-03-17 15:51:40 +00:00
}
2011-03-17 16:28:19 +00:00
});
2011-07-27 21:01:54 -03:00
mindplot.layout.OriginalLayoutManager.NAME = "OriginalLayoutManager";