working on Freemind layout algorithm
This commit is contained in:
@@ -5,10 +5,14 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
initialize:function(designer, options){
|
||||
this.parent(designer, options);
|
||||
},
|
||||
_nodeConnectEvent:function(targetNode, node){
|
||||
if(!this._isCentralTopic(node)){
|
||||
this.parent(targetNode, node);
|
||||
}
|
||||
},
|
||||
registerListenersOnNode : function(topic)
|
||||
{
|
||||
var id = topic.getId();
|
||||
console.log("registering on node: "+id);
|
||||
// Register node listeners ...
|
||||
var designer = this.getDesigner();
|
||||
topic.addEventListener('onfocus', function(event)
|
||||
@@ -22,11 +26,11 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
topic.addEventListener("mousedown",this._mousedownListener.bindWithEvent(this,[topic]));
|
||||
}
|
||||
|
||||
/*// Register editor events ...
|
||||
if (!this._viewMode)
|
||||
// Register editor events ...
|
||||
if (!this.getDesigner()._viewMode)
|
||||
{
|
||||
this._editor.listenEventOnNode(topic, 'dblclick', true);
|
||||
}*/
|
||||
this.getDesigner()._editor.listenEventOnNode(topic, 'dblclick', true);
|
||||
}
|
||||
|
||||
},
|
||||
_mousedownListener:function(event,topic){
|
||||
@@ -38,7 +42,9 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
workSpace.enableWorkspaceEvents(false);
|
||||
|
||||
var id = topic.getId();
|
||||
console.log("down on node: "+id);
|
||||
this._command = new mindplot.commands.freeMind.DragTopicCommand();
|
||||
this._modifiedTopics = new Hash();
|
||||
|
||||
var topics = this.getDesigner()._getTopics();
|
||||
// Disable all mouse events.
|
||||
for (var i = 0; i < topics.length; i++)
|
||||
@@ -53,6 +59,8 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
// Set initial position.
|
||||
// var mousePos = screen.getWorkspaceMousePosition(event);
|
||||
|
||||
this._isMovingNode=false;
|
||||
|
||||
// Register mouse move listener ...
|
||||
this._mouseMoveListenerInstance = this._mouseMoveListener.bindWithEvent(this,[topic]);
|
||||
screen.addEventListener('mousemove', this._mouseMoveListenerInstance);
|
||||
@@ -66,22 +74,70 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
}
|
||||
},
|
||||
_mouseMoveListener:function(event, node){
|
||||
var screen = this._designer.getWorkSpace().getScreenManager();
|
||||
var nodePos = node.getPosition();
|
||||
var pos = screen.getWorkspaceMousePosition(event);
|
||||
var x = nodePos.x - pos.x;
|
||||
var y = nodePos.y - pos.y;
|
||||
var delta = new core.Point(x, y);
|
||||
var board = this.getTopicBoardForTopic(node.getParent());
|
||||
board.setNodeMarginTop(node, delta);
|
||||
//update children position
|
||||
this._updateNodePos(node, delta);
|
||||
if(!this._isMovingNode){
|
||||
this._isMovingNode=true;
|
||||
var screen = this._designer.getWorkSpace().getScreenManager();
|
||||
var nodePos = node.getPosition().clone();
|
||||
var pos = screen.getWorkspaceMousePosition(event);
|
||||
pos.x = Math.round(pos.x);
|
||||
pos.y = Math.round(pos.y);
|
||||
//If still in same side
|
||||
if(Math.sign(nodePos.x)==Math.sign(pos.x) || (Math.sign(nodePos.x)!=Math.sign(pos.x) && !this._isCentralTopic(node.getParent()))){
|
||||
var x = nodePos.x - pos.x;
|
||||
var y = nodePos.y - pos.y;
|
||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||
var board = this.getTopicBoardForTopic(node.getParent());
|
||||
board.updateEntry(node, delta, this._modifiedTopics);
|
||||
} else {
|
||||
var parentBoard = this.getTopicBoardForTopic(node.getParent());
|
||||
var entryObj = parentBoard.findNodeEntryIndex(node);
|
||||
var entry = entryObj.table[entryObj.index];
|
||||
//.removeTopicFromBoard(node,this._modifiedTopics);
|
||||
parentBoard._removeEntry(node, entryObj.table, entryObj.index, this._modifiedTopics);
|
||||
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
||||
node.setPosition(pos.clone(), false);
|
||||
if(this._modifiedTopics.set){
|
||||
var key = node.getId();
|
||||
if(this._modifiedTopics.hasKey(key)){
|
||||
nodePos = this._modifiedTopics.get(key).originalPos;
|
||||
}
|
||||
this._modifiedTopics.set(key,{originalPos:nodePos, newPos:pos});
|
||||
}
|
||||
entryObj = parentBoard.findNewNodeEntryIndex(entry);
|
||||
parentBoard._addEntry(entry, entryObj.table, entryObj.index);
|
||||
parentBoard._updateTable(entryObj.index, entryObj.table, this._modifiedTopics, true);
|
||||
//this.getTopicBoardForTopic(node.getParent()).addBranch(node,this._modifiedTopics);
|
||||
|
||||
}
|
||||
this._isMovingNode=false;
|
||||
}
|
||||
event.preventDefault();
|
||||
},
|
||||
_changeChildrenSide:function(node, newPos, modifiedTopics){
|
||||
var children = node._getChildren();
|
||||
if(children.length>0){
|
||||
var refPos = node.getPosition();
|
||||
for( var i = 0 ; i< children.length ; i++){
|
||||
var child = children[i];
|
||||
this._changeChildrenSide(child);
|
||||
var childPos = child.getPosition();
|
||||
var oldPos=childPos.clone();
|
||||
childPos.x = newPos.x +(childPos.x - refPos.x)*-1;
|
||||
childPos.y = newPos.y +(childPos.y - refPos.y);
|
||||
child.setPosition(childPos, false);
|
||||
if(modifiedTopics.set){
|
||||
var key = node.getId();
|
||||
if(modifiedTopics.hasKey(key)){
|
||||
childPos = this._modifiedTopics.get(key).originalPos;
|
||||
}
|
||||
this._modifiedTopics.set(key,{originalPos:oldPos, newPos:childPos});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_mouseUpListener:function(event, node){
|
||||
var id = node.getId();
|
||||
console.log("up on node: "+id);
|
||||
|
||||
|
||||
var screen = this._designer.getWorkSpace().getScreenManager();
|
||||
// Remove all the events.
|
||||
screen.removeEventListener('mousemove', this._mouseMoveListenerInstance);
|
||||
@@ -101,19 +157,16 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
|
||||
this._designer.getWorkSpace().enableWorkspaceEvents(true);
|
||||
|
||||
this._command.setModifiedTopics(this._modifiedTopics);
|
||||
var actionRunner = mindplot.DesignerActionRunner.getInstance();
|
||||
actionRunner.execute(this._command);
|
||||
this._command=null;
|
||||
this._modifiedTopics=null;
|
||||
|
||||
// var topicId = draggedTopic.getId();
|
||||
// var command = new mindplot.commands.DragTopicCommand(topicId);
|
||||
|
||||
},
|
||||
_updateNodePos:function(node, delta){
|
||||
var pos = node.getPosition();
|
||||
node.setPosition(new core.Point(pos.x-delta.x, pos.y-delta.y));
|
||||
/*var children = node._getChildren();
|
||||
for (var i = 0; i < children.length; i++)
|
||||
{
|
||||
this._updateNodePos(children[i],delta);
|
||||
}*/
|
||||
},
|
||||
getClassName:function(){
|
||||
return mindplot.layoutManagers.FreeMindLayoutManager.NAME;
|
||||
},
|
||||
@@ -122,6 +175,33 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
},
|
||||
_createCentralTopicBoard:function(node){
|
||||
return new mindplot.layoutManagers.boards.freeMindBoards.CentralTopicBoard(node, this);
|
||||
},
|
||||
_updateParentBoard:function(node, modifiedTopics){
|
||||
var parent = node.getParent();
|
||||
if(!this._isCentralTopic(parent)){
|
||||
var parentBoard = this.getTopicBoardForTopic(parent.getParent());
|
||||
var result = parentBoard.findNodeEntryIndex(parent);
|
||||
var parentEntry = result.table[result.index];
|
||||
var board = this.getTopicBoardForTopic(parent);
|
||||
var table = board._getTableForNode(null);
|
||||
if(table.length>0){
|
||||
var firstChild = table[0];
|
||||
var marginTop = parentEntry.getPosition()-(firstChild.getPosition()-firstChild.getTotalMarginTop());
|
||||
parentBoard.setNodeChildrenMarginTop(parentEntry,marginTop);
|
||||
var lastChild = table[table.length-1];
|
||||
var marginBottom = (lastChild.getPosition()+lastChild.getTotalMarginBottom())-parentEntry.getPosition();
|
||||
parentBoard.setNodeChildrenMarginBottom(parentEntry,marginBottom);
|
||||
parentBoard._updateTable(result.index, result.table, modifiedTopics, false);
|
||||
}
|
||||
this._updateParentBoard(parent, modifiedTopics);
|
||||
}
|
||||
},
|
||||
_updateChildrenBoards:function(node, delta, modifiedTopics){
|
||||
var board = this.getTopicBoardForTopic(node);
|
||||
var topics = board._getTableForNode(null);
|
||||
for(var i=0; i<topics.length; i++){
|
||||
board._updateEntryPos(topics[i],delta, modifiedTopics, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user