refactoring minplot layout

This commit is contained in:
Pablo Luna 2011-03-17 15:51:40 +00:00
parent 7acfd763fa
commit 741ddef314
17 changed files with 278 additions and 181 deletions

View File

@ -38,6 +38,7 @@
<!-- Generated for debug --> <!-- Generated for debug -->
<concat destfile="${basedir}/target/tmp/mindplot.js" append="false"> <concat destfile="${basedir}/target/tmp/mindplot.js" append="false">
<filelist dir="${basedir}/src/main/javascript/" files="header.js"/> <filelist dir="${basedir}/src/main/javascript/" files="header.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="EventBus.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="Mindmap.js"/> <filelist dir="${basedir}/src/main/javascript/" files="Mindmap.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="NodeModel.js"/> <filelist dir="${basedir}/src/main/javascript/" files="NodeModel.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="RelationshipModel.js"/> <filelist dir="${basedir}/src/main/javascript/" files="RelationshipModel.js"/>
@ -85,6 +86,7 @@
<filelist dir="${basedir}/src/main/javascript/" files="DesignerActionRunner.js"/> <filelist dir="${basedir}/src/main/javascript/" files="DesignerActionRunner.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="DesignerUndoManager.js"/> <filelist dir="${basedir}/src/main/javascript/" files="DesignerUndoManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="ControlPoint.js"/> <filelist dir="${basedir}/src/main/javascript/" files="ControlPoint.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="EditorOptions.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="commands/GenericFunctionCommand.js"/> files="commands/GenericFunctionCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
@ -109,6 +111,12 @@
files="commands/AddRelationshipCommand.js"/> files="commands/AddRelationshipCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="commands/MoveControlPointCommand.js"/> files="commands/MoveControlPointCommand.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/BaseLayoutManager.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/OriginalLayoutManager.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/LayoutManagerFactory.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="footer.js"/> <filelist dir="${basedir}/src/main/javascript/" files="footer.js"/>
</concat> </concat>
@ -142,6 +150,7 @@
<output>${basedir}/target/tmp/mindplot-min.js</output> <output>${basedir}/target/tmp/mindplot-min.js</output>
<includes> <includes>
<include>header-min.js</include> <include>header-min.js</include>
<include>EventBus-min.js</include>
<include>Mindmap-min.js</include> <include>Mindmap-min.js</include>
<include>NodeModel-min.js</include> <include>NodeModel-min.js</include>
<include>RelationshipModel-min.js</include> <include>RelationshipModel-min.js</include>
@ -185,6 +194,7 @@
<include>IconModel-min.js</include> <include>IconModel-min.js</include>
<include>LinkModel-min.js</include> <include>LinkModel-min.js</include>
<include>NoteModel-min.js</include> <include>NoteModel-min.js</include>
<include>EditorOptions-min.js</include>
<include>Command-min.js</include> <include>Command-min.js</include>
<include>DesignerActionRunner-min.js</include> <include>DesignerActionRunner-min.js</include>
@ -203,6 +213,10 @@
<include>commands/AddRelationshipCommand-min.js</include> <include>commands/AddRelationshipCommand-min.js</include>
<include>commands/MoveControlPointCommand-min.js</include> <include>commands/MoveControlPointCommand-min.js</include>
<include>layoutManagers/BaseLayoutManager-min.js</include>
<include>layoutManagers/OriginalLayoutManager-min.js</include>
<include>layoutManagers/LayoutManagerFactory-min.js</include>
<include>footer-min.js</include> <include>footer-min.js</include>
</includes> </includes>

View File

@ -20,8 +20,7 @@ mindplot.CentralTopic = function(model)
{ {
core.assert(model, "Model can not be null"); core.assert(model, "Model can not be null");
this.setModel(model); this.setModel(model);
var topicBoard = new mindplot.CentralTopicBoard(this); mindplot.CentralTopic.superClass.initialize.call(this);
mindplot.CentralTopic.superClass.initialize.call(this, topicBoard);
this.__onLoad = true; this.__onLoad = true;
}; };
@ -93,20 +92,6 @@ mindplot.CentralTopic.prototype._updatePositionOnChangeSize = function(oldSize,
// Center main topic ... // Center main topic ...
var zeroPoint = new core.Point(0, 0); var zeroPoint = new core.Point(0, 0);
this.setPosition(zeroPoint); 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() mindplot.CentralTopic.prototype._defaultText = function()

View File

@ -16,9 +16,10 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.CentralTopicBoard = function(centralTopic) mindplot.CentralTopicBoard = function(centralTopic, layoutManager)
{ {
var point = new core.Point(0, 0); var point = new core.Point(0, 0);
this._layoutManager = layoutManager;
this._rightBoard = new mindplot.VariableDistanceBoard(50, point); this._rightBoard = new mindplot.VariableDistanceBoard(50, point);
this._leftBoard = new mindplot.VariableDistanceBoard(50, point); this._leftBoard = new mindplot.VariableDistanceBoard(50, point);
this._centralTopic = centralTopic; this._centralTopic = centralTopic;
@ -36,7 +37,6 @@ mindplot.CentralTopicBoard.prototype._updateHeight = function()
}; };
mindplot.CentralTopicBoard.prototype.positionateDragTopic = function(dragTopic) mindplot.CentralTopicBoard.prototype.positionateDragTopic = function(dragTopic)
{ {
core.assert(dragTopic != null, 'dragTopic can not be null'); core.assert(dragTopic != null, 'dragTopic can not be null');

View File

@ -85,9 +85,7 @@ mindplot.DragTopic.prototype.canBeConnectedTo = function(targetTopic)
var targetTopicModel = targetTopic.getModel(); var targetTopicModel = targetTopic.getModel();
var childTopicModel = draggedNode.getModel(); var childTopicModel = draggedNode.getModel();
var targetTopicBoard = targetTopic.getTopicBoard(); result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18);
var height = targetTopicBoard.getHeight();
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, height);
} }
} else } else
{ {

View File

@ -16,13 +16,12 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.DragTopicPositioner = function(workspace, topics) mindplot.DragTopicPositioner = function(layoutManager)
{ {
core.assert(workspace, 'workspace can not be null'); core.assert(layoutManager, 'layoutManager can not be null');
core.assert(topics, 'topics can not be null'); this._layoutManager = layoutManager;
this._topics = layoutManager.getDesigner()._getTopics();
this._workspace = workspace; this._workspace = layoutManager.getDesigner().getWorkSpace();
this._topics = topics;
}; };
mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic) mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic)
@ -38,7 +37,7 @@ mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic
if (dragTopic.isConnected()) if (dragTopic.isConnected())
{ {
var targetTopic = dragTopic.getConnectedToTopic(); var targetTopic = dragTopic.getConnectedToTopic();
var topicBoard = targetTopic.getTopicBoard(); var topicBoard = this._layoutManager.getTopicBoardForTopic(targetTopic);
topicBoard.positionateDragTopic(dragTopic); topicBoard.positionateDragTopic(dragTopic);
} }
}; };

View File

@ -0,0 +1,5 @@
mindplot.EditorOptions =
{
LayoutManager:"OriginalLayout"
// NodeLayoutManager:"FreeLayout"
};

View File

@ -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();

View File

@ -16,9 +16,10 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.FixedDistanceBoard = function(defaultHeight, topic) mindplot.FixedDistanceBoard = function(defaultHeight, topic, layoutManager)
{ {
this._topic = topic; this._topic = topic;
this._layoutManager = layoutManager;
var reference = topic.getPosition(); var reference = topic.getPosition();
mindplot.FixedDistanceBoard.superClass.initialize.call(this, defaultHeight, reference); mindplot.FixedDistanceBoard.superClass.initialize.call(this, defaultHeight, reference);
this._height = defaultHeight; this._height = defaultHeight;
@ -161,7 +162,7 @@ mindplot.FixedDistanceBoard.prototype.repositionate = function()
if (e && e.getTopic()) if (e && e.getTopic())
{ {
var topic = e.getTopic(); var topic = e.getTopic();
var topicBoard = topic.getTopicBoard(); var topicBoard = this._layoutManager.getTopicBoardForTopic(topic);
var topicBoardHeight = topicBoard.getHeight(); var topicBoardHeight = topicBoard.getHeight();
@ -184,7 +185,7 @@ mindplot.FixedDistanceBoard.prototype.repositionate = function()
var parentTopic = topic.getParent(); var parentTopic = topic.getParent();
if (parentTopic != null) if (parentTopic != null)
{ {
var board = parentTopic.getTopicBoard(); var board = this._layoutManager.getTopicBoardForTopic(parentTopic);
board.repositionate(); board.repositionate();
} }
} }
@ -218,7 +219,7 @@ mindplot.FixedDistanceBoard.prototype.repositionate = function()
e.setLowerLimit(lowerLimit); e.setLowerLimit(lowerLimit);
// Update entry ... // Update entry ...
var topicBoard = currentTopic.getTopicBoard(); var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic);
var topicBoardHeight = topicBoard.getHeight(); var topicBoardHeight = topicBoard.getHeight();
upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE;

View File

@ -190,13 +190,6 @@ mindplot.MainTopic.prototype._updatePositionOnChangeSize = function(oldSize, new
pos.x = pos.x - xOffset; pos.x = pos.x - xOffset;
} }
this.setPosition(pos); 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); mindplot.MainTopic.superClass.setPosition.call(this, point);
// Update board zero entry position... // Update board zero entry position...
var topicBoard = this.getTopicBoard(); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent,[this]);
topicBoard.updateChildrenPosition(this);
}; };
mindplot.MainTopic.prototype.workoutIncomingConnectionPoint = function(sourcePosition) mindplot.MainTopic.prototype.workoutIncomingConnectionPoint = function(sourcePosition)

View File

@ -16,8 +16,9 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.MainTopicBoard = function(topic) mindplot.MainTopicBoard = function(topic, layoutManager)
{ {
this._layoutManager = layoutManager;
this._topic = topic; this._topic = topic;
this._board = null; this._board = null;
this._height = 0; this._height = 0;
@ -32,7 +33,7 @@ mindplot.MainTopicBoard.prototype._getBoard = function()
if (!this._board) if (!this._board)
{ {
var topic = this._topic; 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; return this._board;
}; };
@ -116,8 +117,7 @@ mindplot.MainTopicBoard.prototype.addBranch = function(topic)
if (currentTopic.getOutgoingConnectedTopic()) if (currentTopic.getOutgoingConnectedTopic())
{ {
var parentTopic = currentTopic.getOutgoingConnectedTopic(); var parentTopic = currentTopic.getOutgoingConnectedTopic();
var parentTopicBoard = parentTopic.getTopicBoard(); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent,[parentTopic]);
parentTopicBoard.repositionate();
} }
}; };
@ -137,7 +137,6 @@ mindplot.MainTopicBoard.prototype.removeTopicFromBoard = function(topic)
if (parentTopic.getOutgoingConnectedTopic()) if (parentTopic.getOutgoingConnectedTopic())
{ {
var connectedTopic = parentTopic.getOutgoingConnectedTopic(); var connectedTopic = parentTopic.getOutgoingConnectedTopic();
var topicBoard = connectedTopic.getTopicBoard(); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent,[connectedTopic]);
topicBoard.repositionate();
} }
}; };

View File

@ -40,28 +40,17 @@ mindplot.MindmapDesigner = function(profile, divElement)
// Init layout managers ... // Init layout managers ...
this._topics = []; 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.. // Register handlers..
this._registerEvents(); 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._relationships={};
this._events = {}; this._events = {};
}; };
mindplot.MindmapDesigner.prototype.getDragTopicPositioner = function()
{
return this._dragTopicPositioner;
};
mindplot.MindmapDesigner.prototype._getTopics = function() mindplot.MindmapDesigner.prototype._getTopics = function()
{ {
return this._topics; 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() mindplot.MindmapDesigner.prototype._registerEvents = function()
{ {
var mindmapDesigner = this; var mindmapDesigner = this;
@ -199,7 +132,7 @@ mindplot.MindmapDesigner.prototype._buildNodeGraph = function(model)
topics.push(topic); topics.push(topic);
// Add Topic events ... // Add Topic events ...
this._registerListenersOnNode(topic); this._layoutManager.registerListenersOnNode(topic);
// Connect Topic ... // Connect Topic ...
var isConnected = model.isConnected(); 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() mindplot.MindmapDesigner.prototype.zoomOut = function()
{ {
var scale = this._zoom * 1.2; var scale = this._zoom * 1.2;
@ -548,25 +455,6 @@ mindplot.MindmapDesigner.prototype._nodeModelToNodeGraph = function(nodeModel, i
var children = nodeModel.getChildren().slice(); 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++) for (var i = 0; i < children.length; i++)
{ {
var child = children[i]; var child = children[i];

View File

@ -23,9 +23,8 @@ mindplot.Topic = function()
objects.extend(mindplot.Topic, mindplot.NodeGraph); 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._children = [];
this._parent = null; this._parent = null;
@ -33,14 +32,13 @@ mindplot.Topic.prototype.initialize = function(topicBoard)
this._relationships = []; this._relationships = [];
this._isInWorkspace = false; this._isInWorkspace = false;
this._topicBoard = topicBoard;
this._buildShape(); this._buildShape();
this.setMouseEventsEnabled(true); this.setMouseEventsEnabled(true);
// Positionate topic .... // Positionate topic ....
var model = this.getModel(); var model = this.getModel();
var pos = model.getPosition(); var pos = model.getPosition();
if (pos != null) if (pos != null && model.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
{ {
this.setPosition(pos); 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. // Update the figure position(ej: central topic must be centered) and children position.
this._updatePositionOnChangeSize(oldSize, size); 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); outgoingLine.removeFromWorkspace(workspace);
// Remove from workspace. // Remove from workspace.
var topicBoard = targetTopic.getTopicBoard(); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent,[targetTopic, this]);
topicBoard.removeTopicFromBoard(this);
// Change text based on the current connection ... // Change text based on the current connection ...
var model = this.getModel(); var model = this.getModel();
@ -1215,8 +1215,7 @@ mindplot.Topic.prototype.connectTo = function(targetTopic, workspace, isVisible)
var textShape = this.getTextShape(); var textShape = this.getTextShape();
// Update topic position based on the state ... // Update topic position based on the state ...
var targetTopicBoard = targetTopic.getTopicBoard(); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent,[targetTopic, this]);
targetTopicBoard.addBranch(this);
// Display connection node... // Display connection node...
var connector = targetTopic.getShrinkConnector(); var connector = targetTopic.getShrinkConnector();
@ -1272,11 +1271,6 @@ mindplot.Topic.prototype.isInWorkspace = function(){
return this._isInWorkspace; return this._isInWorkspace;
}; };
mindplot.Topic.prototype.getTopicBoard = function()
{
return this._topicBoard;
};
mindplot.Topic.prototype.createDragNode = function() mindplot.Topic.prototype.createDragNode = function()
{ {
var dragNode = mindplot.Topic.superClass.createDragNode.call(this); var dragNode = mindplot.Topic.superClass.createDragNode.call(this);

View File

@ -76,15 +76,15 @@ mindplot.XMLMindmapSerializer_Pela.prototype._topicToXML = function(document, to
} else } else
{ {
var parent = topic.getParent(); 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(); var pos = topic.getPosition();
parentTopic.setAttribute("position", pos.x + ',' + pos.y); parentTopic.setAttribute("position", pos.x + ',' + pos.y);
} else // } else
{ // {
var order = topic.getOrder(); var order = topic.getOrder();
parentTopic.setAttribute("order", order); parentTopic.setAttribute("order", order);
} // }
} }
var text = topic.getText(); var text = topic.getText();

View File

@ -25,3 +25,4 @@
var mindplot = {}; var mindplot = {};
mindplot.util = {}; mindplot.util = {};
mindplot.commands = {}; mindplot.commands = {};
mindplot.layoutManagers = {};

View File

@ -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);

View File

@ -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"];
}
};

View File

@ -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;
}
});