diff --git a/mindplot/pom.xml b/mindplot/pom.xml
index ed34db57..76286f05 100644
--- a/mindplot/pom.xml
+++ b/mindplot/pom.xml
@@ -38,6 +38,7 @@
+
@@ -85,6 +86,7 @@
+
+
+
+
@@ -142,6 +150,7 @@
header-min.js
+ EventBus-min.js
Mindmap-min.js
NodeModel-min.js
RelationshipModel-min.js
@@ -185,6 +194,7 @@
IconModel-min.js
LinkModel-min.js
NoteModel-min.js
+ EditorOptions-min.js
Command-min.js
DesignerActionRunner-min.js
@@ -203,6 +213,10 @@
commands/AddRelationshipCommand-min.js
commands/MoveControlPointCommand-min.js
+ layoutManagers/BaseLayoutManager-min.js
+ layoutManagers/OriginalLayoutManager-min.js
+ layoutManagers/LayoutManagerFactory-min.js
+
footer-min.js
diff --git a/mindplot/src/main/javascript/CentralTopic.js b/mindplot/src/main/javascript/CentralTopic.js
index 1465624b..628f5802 100644
--- a/mindplot/src/main/javascript/CentralTopic.js
+++ b/mindplot/src/main/javascript/CentralTopic.js
@@ -20,8 +20,7 @@ mindplot.CentralTopic = function(model)
{
core.assert(model, "Model can not be null");
this.setModel(model);
- var topicBoard = new mindplot.CentralTopicBoard(this);
- mindplot.CentralTopic.superClass.initialize.call(this, topicBoard);
+ mindplot.CentralTopic.superClass.initialize.call(this);
this.__onLoad = true;
};
@@ -93,20 +92,6 @@ mindplot.CentralTopic.prototype._updatePositionOnChangeSize = function(oldSize,
// Center main topic ...
var zeroPoint = new core.Point(0, 0);
this.setPosition(zeroPoint);
-
- // Update children position based on the new figure size ...
- var xOffset = newSize.width - oldSize.width;
- xOffset = Math.round(xOffset / 2);
-
- if (!this.__onLoad)
- {
- // HACK: on load ignore changes of position in order to avoid adding
- // several times the central topic distance to all the child nodes...
-
- var topicBoard = this.getTopicBoard();
- topicBoard.updateChildrenPosition(this, xOffset);
- this.__onLoad = false;
- }
};
mindplot.CentralTopic.prototype._defaultText = function()
diff --git a/mindplot/src/main/javascript/CentralTopicBoard.js b/mindplot/src/main/javascript/CentralTopicBoard.js
index 56024ea7..a0a42956 100644
--- a/mindplot/src/main/javascript/CentralTopicBoard.js
+++ b/mindplot/src/main/javascript/CentralTopicBoard.js
@@ -16,9 +16,10 @@
* limitations under the License.
*/
-mindplot.CentralTopicBoard = function(centralTopic)
+mindplot.CentralTopicBoard = function(centralTopic, layoutManager)
{
var point = new core.Point(0, 0);
+ this._layoutManager = layoutManager;
this._rightBoard = new mindplot.VariableDistanceBoard(50, point);
this._leftBoard = new mindplot.VariableDistanceBoard(50, point);
this._centralTopic = centralTopic;
@@ -36,7 +37,6 @@ mindplot.CentralTopicBoard.prototype._updateHeight = function()
};
-
mindplot.CentralTopicBoard.prototype.positionateDragTopic = function(dragTopic)
{
core.assert(dragTopic != null, 'dragTopic can not be null');
diff --git a/mindplot/src/main/javascript/DragTopic.js b/mindplot/src/main/javascript/DragTopic.js
index b301e724..6181ee53 100644
--- a/mindplot/src/main/javascript/DragTopic.js
+++ b/mindplot/src/main/javascript/DragTopic.js
@@ -85,9 +85,7 @@ mindplot.DragTopic.prototype.canBeConnectedTo = function(targetTopic)
var targetTopicModel = targetTopic.getModel();
var childTopicModel = draggedNode.getModel();
- var targetTopicBoard = targetTopic.getTopicBoard();
- var height = targetTopicBoard.getHeight();
- result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, height);
+ result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18);
}
} else
{
diff --git a/mindplot/src/main/javascript/DragTopicPositioner.js b/mindplot/src/main/javascript/DragTopicPositioner.js
index 463e507f..44cf0da8 100644
--- a/mindplot/src/main/javascript/DragTopicPositioner.js
+++ b/mindplot/src/main/javascript/DragTopicPositioner.js
@@ -16,13 +16,12 @@
* limitations under the License.
*/
-mindplot.DragTopicPositioner = function(workspace, topics)
+mindplot.DragTopicPositioner = function(layoutManager)
{
- core.assert(workspace, 'workspace can not be null');
- core.assert(topics, 'topics can not be null');
-
- this._workspace = workspace;
- this._topics = topics;
+ core.assert(layoutManager, 'layoutManager can not be null');
+ this._layoutManager = layoutManager;
+ this._topics = layoutManager.getDesigner()._getTopics();
+ this._workspace = layoutManager.getDesigner().getWorkSpace();
};
mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic)
@@ -38,7 +37,7 @@ mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic
if (dragTopic.isConnected())
{
var targetTopic = dragTopic.getConnectedToTopic();
- var topicBoard = targetTopic.getTopicBoard();
+ var topicBoard = this._layoutManager.getTopicBoardForTopic(targetTopic);
topicBoard.positionateDragTopic(dragTopic);
}
};
diff --git a/mindplot/src/main/javascript/EditorOptions.js b/mindplot/src/main/javascript/EditorOptions.js
new file mode 100644
index 00000000..96244c5f
--- /dev/null
+++ b/mindplot/src/main/javascript/EditorOptions.js
@@ -0,0 +1,5 @@
+mindplot.EditorOptions =
+{
+ LayoutManager:"OriginalLayout"
+// NodeLayoutManager:"FreeLayout"
+};
\ No newline at end of file
diff --git a/mindplot/src/main/javascript/EventBus.js b/mindplot/src/main/javascript/EventBus.js
new file mode 100644
index 00000000..10684fff
--- /dev/null
+++ b/mindplot/src/main/javascript/EventBus.js
@@ -0,0 +1,22 @@
+mindplot.EventBus = new Class({
+ options: {
+
+ },
+
+ initialize: function(options) {
+ this.setOptions(options);
+ }
+
+});
+mindplot.EventBus.implement(new Events);
+mindplot.EventBus.implement(new Options);
+
+mindplot.EventBus.events ={
+ NodeResizeEvent:'NodeResizeEvent',
+ NodeMoveEvent:'NodeMoveEvent',
+ NodeDisconnectEvent:'NodeDisconnectEvent',
+ NodeConnectEvent:'NodeConnectEvent',
+ NodeRepositionateEvent:'NodeRepositionateEvent'
+};
+
+mindplot.EventBus.instance = new mindplot.EventBus();
\ No newline at end of file
diff --git a/mindplot/src/main/javascript/FixedDistanceBoard.js b/mindplot/src/main/javascript/FixedDistanceBoard.js
index db7927c1..f7055a32 100644
--- a/mindplot/src/main/javascript/FixedDistanceBoard.js
+++ b/mindplot/src/main/javascript/FixedDistanceBoard.js
@@ -16,9 +16,10 @@
* limitations under the License.
*/
-mindplot.FixedDistanceBoard = function(defaultHeight, topic)
+mindplot.FixedDistanceBoard = function(defaultHeight, topic, layoutManager)
{
this._topic = topic;
+ this._layoutManager = layoutManager;
var reference = topic.getPosition();
mindplot.FixedDistanceBoard.superClass.initialize.call(this, defaultHeight, reference);
this._height = defaultHeight;
@@ -161,7 +162,7 @@ mindplot.FixedDistanceBoard.prototype.repositionate = function()
if (e && e.getTopic())
{
var topic = e.getTopic();
- var topicBoard = topic.getTopicBoard();
+ var topicBoard = this._layoutManager.getTopicBoardForTopic(topic);
var topicBoardHeight = topicBoard.getHeight();
@@ -184,7 +185,7 @@ mindplot.FixedDistanceBoard.prototype.repositionate = function()
var parentTopic = topic.getParent();
if (parentTopic != null)
{
- var board = parentTopic.getTopicBoard();
+ var board = this._layoutManager.getTopicBoardForTopic(parentTopic);
board.repositionate();
}
}
@@ -218,7 +219,7 @@ mindplot.FixedDistanceBoard.prototype.repositionate = function()
e.setLowerLimit(lowerLimit);
// Update entry ...
- var topicBoard = currentTopic.getTopicBoard();
+ var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic);
var topicBoardHeight = topicBoard.getHeight();
upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;
diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js
index df8a2829..aa30a8b0 100644
--- a/mindplot/src/main/javascript/MainTopic.js
+++ b/mindplot/src/main/javascript/MainTopic.js
@@ -190,13 +190,6 @@ mindplot.MainTopic.prototype._updatePositionOnChangeSize = function(oldSize, new
pos.x = pos.x - xOffset;
}
this.setPosition(pos);
-
- // If height has changed, I must repositionate all elements ...
- if (oldSize.height != newSize.height)
- {
- var topicBoard = this.getTopicBoard();
- // topicBoard.repositionate();
- }
}
};
@@ -205,8 +198,7 @@ mindplot.MainTopic.prototype.setPosition = function(point)
mindplot.MainTopic.superClass.setPosition.call(this, point);
// Update board zero entry position...
- var topicBoard = this.getTopicBoard();
- topicBoard.updateChildrenPosition(this);
+ mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent,[this]);
};
mindplot.MainTopic.prototype.workoutIncomingConnectionPoint = function(sourcePosition)
diff --git a/mindplot/src/main/javascript/MainTopicBoard.js b/mindplot/src/main/javascript/MainTopicBoard.js
index 96d397e0..9a8d69b3 100644
--- a/mindplot/src/main/javascript/MainTopicBoard.js
+++ b/mindplot/src/main/javascript/MainTopicBoard.js
@@ -16,8 +16,9 @@
* limitations under the License.
*/
-mindplot.MainTopicBoard = function(topic)
+mindplot.MainTopicBoard = function(topic, layoutManager)
{
+ this._layoutManager = layoutManager;
this._topic = topic;
this._board = null;
this._height = 0;
@@ -32,7 +33,7 @@ mindplot.MainTopicBoard.prototype._getBoard = function()
if (!this._board)
{
var topic = this._topic;
- this._board = new mindplot.FixedDistanceBoard(mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT, topic);
+ this._board = new mindplot.FixedDistanceBoard(mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT, topic, this._layoutManager);
}
return this._board;
};
@@ -116,8 +117,7 @@ mindplot.MainTopicBoard.prototype.addBranch = function(topic)
if (currentTopic.getOutgoingConnectedTopic())
{
var parentTopic = currentTopic.getOutgoingConnectedTopic();
- var parentTopicBoard = parentTopic.getTopicBoard();
- parentTopicBoard.repositionate();
+ mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent,[parentTopic]);
}
};
@@ -137,7 +137,6 @@ mindplot.MainTopicBoard.prototype.removeTopicFromBoard = function(topic)
if (parentTopic.getOutgoingConnectedTopic())
{
var connectedTopic = parentTopic.getOutgoingConnectedTopic();
- var topicBoard = connectedTopic.getTopicBoard();
- topicBoard.repositionate();
+ mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent,[connectedTopic]);
}
};
\ No newline at end of file
diff --git a/mindplot/src/main/javascript/MindmapDesigner.js b/mindplot/src/main/javascript/MindmapDesigner.js
index 7c909656..227a0135 100644
--- a/mindplot/src/main/javascript/MindmapDesigner.js
+++ b/mindplot/src/main/javascript/MindmapDesigner.js
@@ -40,28 +40,17 @@ mindplot.MindmapDesigner = function(profile, divElement)
// Init layout managers ...
this._topics = [];
- this._dragTopicPositioner = new mindplot.DragTopicPositioner(this._workspace, this._topics);
+ var layoutManagerClass = mindplot.layoutManagers.LayoutManagerFactory.getManagerByName(mindplot.EditorOptions.LayoutManager);
+ this._layoutManager = new layoutManagerClass(this);
// Register handlers..
this._registerEvents();
- // Init dragger manager.
- this._dragger = this._buildDragManager(workspace);
-
- // Add shapes to speed up the loading process ...
- mindplot.DragTopic.initialize(workspace);
-
this._relationships={};
this._events = {};
};
-
-mindplot.MindmapDesigner.prototype.getDragTopicPositioner = function()
-{
- return this._dragTopicPositioner;
-};
-
mindplot.MindmapDesigner.prototype._getTopics = function()
{
return this._topics;
@@ -90,62 +79,6 @@ mindplot.MindmapDesigner.prototype._fireEvent = function(eventType, event)
}
}
-mindplot.MindmapDesigner.prototype._buildDragManager = function(workspace)
-{
- // Init dragger manager.
- var dragger = new mindplot.DragManager(workspace);
- var screen = workspace.getScreenManager();
- var topics = this._getTopics();
-
- var dragTopicPositioner = this.getDragTopicPositioner();
- var mindmapDesigner = this;
- var elem = this;
-
- dragger.addEventListener('startdragging', function(event, node)
- {
- // Enable all mouse events.
- for (var i = 0; i < topics.length; i++)
- {
- topics[i].setMouseEventsEnabled(false);
- }
- });
-
- dragger.addEventListener('dragging', function(event, dragTopic)
- {
- // Update the state and connections of the topic ...
- dragTopicPositioner.positionateDragTopic(dragTopic);
- });
-
- dragger.addEventListener('enddragging', function(event, dragTopic)
- {
- // Enable all mouse events.
- for (var i = 0; i < topics.length; i++)
- {
- topics[i].setMouseEventsEnabled(true);
- }
- // Topic must be positioned in the real board postion.
- if (dragTopic._isInTheWorkspace)
- {
- 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);
- if (parentNode != null)
- {
- parentNode.setBranchVisibility(true);
- }
- }
- });
-
- return dragger;
-};
-
mindplot.MindmapDesigner.prototype._registerEvents = function()
{
var mindmapDesigner = this;
@@ -199,7 +132,7 @@ mindplot.MindmapDesigner.prototype._buildNodeGraph = function(model)
topics.push(topic);
// Add Topic events ...
- this._registerListenersOnNode(topic);
+ this._layoutManager.registerListenersOnNode(topic);
// Connect Topic ...
var isConnected = model.isConnected();
@@ -246,32 +179,6 @@ mindplot.MindmapDesigner.prototype.onObjectFocusEvent = function(currentObject,
}
};
-mindplot.MindmapDesigner.prototype._registerListenersOnNode = function(topic)
-{
- // Register node listeners ...
- var elem = this;
- var topics = this._topics;
- topic.addEventListener('onfocus', function(event)
- {
- elem.onObjectFocusEvent.attempt([topic, event], elem);
- });
-
- // Add drag behaviour ...
- if (topic.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
- {
-
- // Central Topic doesn't support to be dragged
- var dragger = this._dragger;
- dragger.add(topic);
- }
-
- // Register editor events ...
- if (!this._viewMode)
- {
- this._editor.listenEventOnNode(topic, 'dblclick', true);
- }
-
-};
mindplot.MindmapDesigner.prototype.zoomOut = function()
{
var scale = this._zoom * 1.2;
@@ -548,25 +455,6 @@ mindplot.MindmapDesigner.prototype._nodeModelToNodeGraph = function(nodeModel, i
var children = nodeModel.getChildren().slice();
- // Sort children by order to solve adding order ...
- if (nodeGraph.getTopicType()!=mindplot.NodeModel.CENTRAL_TOPIC_TYPE && children.length > 0)
- {
- var oldChildren = children;
- children = [];
- for (var i = 0; i < oldChildren.length; i++)
- {
- var child = oldChildren[i];
- var order = child.getOrder();
- if (order != null)
- {
- children[order] = child;
- } else
- {
- children.push(child);
- }
- }
- }
-
for (var i = 0; i < children.length; i++)
{
var child = children[i];
diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js
index 84f69a3b..fd37b5b8 100644
--- a/mindplot/src/main/javascript/Topic.js
+++ b/mindplot/src/main/javascript/Topic.js
@@ -23,9 +23,8 @@ mindplot.Topic = function()
objects.extend(mindplot.Topic, mindplot.NodeGraph);
-mindplot.Topic.prototype.initialize = function(topicBoard)
+mindplot.Topic.prototype.initialize = function()
{
- core.assert(core.Utils.isDefined(topicBoard), 'topic board can not be null.');
this._children = [];
this._parent = null;
@@ -33,14 +32,13 @@ mindplot.Topic.prototype.initialize = function(topicBoard)
this._relationships = [];
this._isInWorkspace = false;
- this._topicBoard = topicBoard;
this._buildShape();
this.setMouseEventsEnabled(true);
// Positionate topic ....
var model = this.getModel();
var pos = model.getPosition();
- if (pos != null)
+ if (pos != null && model.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
{
this.setPosition(pos);
}
@@ -1103,6 +1101,9 @@ mindplot.Topic.prototype.setSize = function(size, force)
// Update the figure position(ej: central topic must be centered) and children position.
this._updatePositionOnChangeSize(oldSize, size);
+
+ mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent,[this]);
+
}
};
@@ -1131,8 +1132,7 @@ mindplot.Topic.prototype.disconnect = function(workspace)
outgoingLine.removeFromWorkspace(workspace);
// Remove from workspace.
- var topicBoard = targetTopic.getTopicBoard();
- topicBoard.removeTopicFromBoard(this);
+ mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent,[targetTopic, this]);
// Change text based on the current connection ...
var model = this.getModel();
@@ -1215,8 +1215,7 @@ mindplot.Topic.prototype.connectTo = function(targetTopic, workspace, isVisible)
var textShape = this.getTextShape();
// Update topic position based on the state ...
- var targetTopicBoard = targetTopic.getTopicBoard();
- targetTopicBoard.addBranch(this);
+ mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent,[targetTopic, this]);
// Display connection node...
var connector = targetTopic.getShrinkConnector();
@@ -1272,11 +1271,6 @@ mindplot.Topic.prototype.isInWorkspace = function(){
return this._isInWorkspace;
};
-mindplot.Topic.prototype.getTopicBoard = function()
-{
- return this._topicBoard;
-};
-
mindplot.Topic.prototype.createDragNode = function()
{
var dragNode = mindplot.Topic.superClass.createDragNode.call(this);
diff --git a/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js b/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js
index 2bf2026e..a3e4b17c 100644
--- a/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js
+++ b/mindplot/src/main/javascript/XMLMindmapSerializer_Pela.js
@@ -76,15 +76,15 @@ mindplot.XMLMindmapSerializer_Pela.prototype._topicToXML = function(document, to
} else
{
var parent = topic.getParent();
- if (parent == null || parent.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
- {
+// if (parent == null || parent.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
+// {
var pos = topic.getPosition();
parentTopic.setAttribute("position", pos.x + ',' + pos.y);
- } else
- {
+// } else
+// {
var order = topic.getOrder();
parentTopic.setAttribute("order", order);
- }
+// }
}
var text = topic.getText();
diff --git a/mindplot/src/main/javascript/header.js b/mindplot/src/main/javascript/header.js
index 65bec801..f31b84c6 100644
--- a/mindplot/src/main/javascript/header.js
+++ b/mindplot/src/main/javascript/header.js
@@ -24,4 +24,5 @@
var mindplot = {};
mindplot.util = {};
-mindplot.commands = {};
\ No newline at end of file
+mindplot.commands = {};
+mindplot.layoutManagers = {};
\ No newline at end of file
diff --git a/mindplot/src/main/javascript/layoutManagers/BaseLayoutManager.js b/mindplot/src/main/javascript/layoutManagers/BaseLayoutManager.js
new file mode 100644
index 00000000..6fe32ce7
--- /dev/null
+++ b/mindplot/src/main/javascript/layoutManagers/BaseLayoutManager.js
@@ -0,0 +1,41 @@
+/*
+Class: BaseLayoutManager
+ Base class for LayoutManagers
+
+Arguments:
+ element - the knob container
+ knob - the handle
+ options - see Options below
+
+Options:
+ steps - the number of steps for your slider.
+ mode - either 'horizontal' or 'vertical'. defaults to horizontal.
+ offset - relative offset for knob position. default to 0.
+
+Events:
+ onChange - a function to fire when the value changes.
+ onComplete - a function to fire when you're done dragging.
+ onTick - optionally, you can alter the onTick behavior, for example displaying an effect of the knob moving to the desired position.
+ Passes as parameter the new position.
+*/
+
+mindplot.layoutManagers.BaseLayoutManager = new Class({
+
+ options: {
+
+ },
+
+ initialize: function(designer, options) {
+ this.setOptions(options);
+ this._designer = designer;
+ },
+ addNode: function(node) {
+
+ },
+ getDesigner:function(){
+ return this._designer;
+ }
+});
+
+mindplot.layoutManagers.BaseLayoutManager.implement(new Events);
+mindplot.layoutManagers.BaseLayoutManager.implement(new Options);
\ No newline at end of file
diff --git a/mindplot/src/main/javascript/layoutManagers/LayoutManagerFactory.js b/mindplot/src/main/javascript/layoutManagers/LayoutManagerFactory.js
new file mode 100644
index 00000000..3eb20f22
--- /dev/null
+++ b/mindplot/src/main/javascript/layoutManagers/LayoutManagerFactory.js
@@ -0,0 +1,16 @@
+mindplot.layoutManagers.LayoutManagerFactory = {};
+mindplot.layoutManagers.LayoutManagerFactory.managers = {
+ OriginalLayoutManager:mindplot.layoutManagers.OriginalLayoutManager
+// FreeLayoutManager:mindplot.layoutManagers.FreeLayoutManager
+};
+mindplot.layoutManagers.LayoutManagerFactory.getManagerByName = function(name){
+ var manager = mindplot.layoutManagers.LayoutManagerFactory.managers[name+"Manager"];
+ if(manager){
+ return manager;
+ }
+ else{
+ return mindplot.layoutManagers.LayoutManagerFactory.managers["OriginalLayoutManager"];
+ }
+};
+
+
diff --git a/mindplot/src/main/javascript/layoutManagers/OriginalLayoutManager.js b/mindplot/src/main/javascript/layoutManagers/OriginalLayoutManager.js
new file mode 100644
index 00000000..7a53baac
--- /dev/null
+++ b/mindplot/src/main/javascript/layoutManagers/OriginalLayoutManager.js
@@ -0,0 +1,142 @@
+mindplot.layoutManagers.OriginalLayoutManager = mindplot.layoutManagers.BaseLayoutManager.extend({
+ options:{
+
+ },
+ initialize:function(designer, options){
+ this.parent(designer, options);
+ this._boards = new Hash();
+ this._dragTopicPositioner = new mindplot.DragTopicPositioner(this);
+ // Init dragger manager.
+ var workSpace = this.getDesigner().getWorkSpace();
+ this._dragger = this._buildDragManager(workSpace);
+
+ // Add shapes to speed up the loading process ...
+ mindplot.DragTopic.initialize(workSpace);
+
+ mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeResizeEvent,this._nodeResizeEvent.bind(this));
+ mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMoveEvent,this._nodeMoveEvent.bind(this));
+ mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeDisconnectEvent,this._nodeDisconnectEvent.bind(this));
+ mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeConnectEvent,this._nodeConnectEvent.bind(this));
+ mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRepositionateEvent,this._NodeRepositionateEvent.bind(this));
+ },
+ _nodeResizeEvent:function(node){
+ var size = node.getSize();
+ if(!this._isCentralTopic(node))
+ this.getTopicBoardForTopic(node).updateChildrenPosition(node,size.height/2);
+ },
+ _nodeMoveEvent:function(node){
+ this.getTopicBoardForTopic(node).updateChildrenPosition(node);
+ },
+ _nodeDisconnectEvent:function(targetNode, node){
+ this.getTopicBoardForTopic(targetNode).removeTopicFromBoard(node);
+ },
+ _nodeConnectEvent:function(targetNode, node){
+ this.getTopicBoardForTopic(targetNode).addBranch(node);
+ },
+ _NodeRepositionateEvent:function(node){
+ this.getTopicBoardForTopic(node).repositionate();
+ },
+ getDragTopicPositioner : function()
+ {
+ return this._dragTopicPositioner;
+ },
+ _buildDragManager: function(workspace)
+ {
+ // Init dragger manager.
+ var dragger = new mindplot.DragManager(workspace);
+ var topics = this.getDesigner()._getTopics();
+
+ var dragTopicPositioner = this.getDragTopicPositioner();
+
+ dragger.addEventListener('startdragging', function(event, node)
+ {
+ // Enable all mouse events.
+ for (var i = 0; i < topics.length; i++)
+ {
+ topics[i].setMouseEventsEnabled(false);
+ }
+ });
+
+ dragger.addEventListener('dragging', function(event, dragTopic)
+ {
+ // Update the state and connections of the topic ...
+ dragTopicPositioner.positionateDragTopic(dragTopic);
+ });
+
+ dragger.addEventListener('enddragging', function(event, dragTopic)
+ {
+ // Enable all mouse events.
+ for (var i = 0; i < topics.length; i++)
+ {
+ topics[i].setMouseEventsEnabled(true);
+ }
+ // Topic must be positioned in the real board postion.
+ if (dragTopic._isInTheWorkspace)
+ {
+ 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);
+ if (parentNode != null)
+ {
+ parentNode.setBranchVisibility(true);
+ }
+ }
+ });
+
+ return dragger;
+ },
+ registerListenersOnNode : function(topic)
+ {
+ // Register node listeners ...
+ var designer = this.getDesigner();
+ topic.addEventListener('onfocus', function(event)
+ {
+ designer.onObjectFocusEvent.attempt([topic, event], designer);
+ });
+
+ // Add drag behaviour ...
+ if (topic.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
+ {
+
+ // Central Topic doesn't support to be dragged
+ var dragger = this._dragger;
+ dragger.add(topic);
+ }
+
+ /*// Register editor events ...
+ if (!this._viewMode)
+ {
+ this._editor.listenEventOnNode(topic, 'dblclick', true);
+ }*/
+
+ },
+ getTopicBoardForTopic:function(node){
+ var id = node.getId()
+ var result = this._boards[id];
+ if(!result){
+ result = this.addNode(node);
+ }
+ return result;
+ },
+ addNode:function(node){
+ var boardClass = mindplot.MainTopicBoard;
+ if (this._isCentralTopic(node))
+ boardClass = mindplot.CentralTopicBoard;
+ var board = new boardClass(node, this);
+ var id = node.getId();
+ this._boards[id]=board;
+ this.parent();
+ return board;
+ },
+ _isCentralTopic:function(node){
+ var type = node.getModel().getType();
+ return type == mindplot.NodeModel.CENTRAL_TOPIC_TYPE;
+ }
+});
\ No newline at end of file