adding FreeMind LayoutManager

This commit is contained in:
Pablo Luna 2011-03-24 18:00:51 +00:00
parent 43ff313635
commit 4dee4a0f18
20 changed files with 630 additions and 81 deletions

View File

@ -19,8 +19,21 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.jstestdriver</groupId>
<artifactId>maven-jstestdriver-plugin</artifactId>
<version>1.2.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<repositories>
<repository>
<id>jstd-maven-plugin google code repo</id>
<url>http://jstd-maven-plugin.googlecode.com/svn/maven2</url>
</repository>
</repositories>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -111,12 +124,28 @@
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/boards/Board.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/boards/freeMindBoards/Board.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/boards/freeMindBoards/Entry.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/boards/freeMindBoards/CentralTopicBoard.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/boards/freeMindBoards/MainTopicBoard.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/BaseLayoutManager.js"/> files="layoutManagers/BaseLayoutManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/OriginalLayoutManager.js"/> files="layoutManagers/OriginalLayoutManager.js"/>
<filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/FreeMindLayoutManager.js"/>
<filelist dir="${basedir}/src/main/javascript/" <filelist dir="${basedir}/src/main/javascript/"
files="layoutManagers/LayoutManagerFactory.js"/> files="layoutManagers/LayoutManagerFactory.js"/>
<filelist dir="${basedir}/src/main/javascript/" files="footer.js"/> <filelist dir="${basedir}/src/main/javascript/" files="footer.js"/>
</concat> </concat>
@ -213,8 +242,14 @@
<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/boards/Board-min.js</include>
<include>layoutManagers/boards/freeMindBoards/Board-min.js</include>
<include>layoutManagers/boards/freeMindBoards/Entry-min.js</include>
<include>layoutManagers/boards/freeMindBoards/CentralTopicBoard-min.js</include>
<include>layoutManagers/boards/freeMindBoards/MainTopicBoard-min.js</include>
<include>layoutManagers/BaseLayoutManager-min.js</include> <include>layoutManagers/BaseLayoutManager-min.js</include>
<include>layoutManagers/OriginalLayoutManager-min.js</include> <include>layoutManagers/OriginalLayoutManager-min.js</include>
<include>layoutManagers/FreeMindLayoutManager-min.js</include>
<include>layoutManagers/LayoutManagerFactory-min.js</include> <include>layoutManagers/LayoutManagerFactory-min.js</include>
<include>footer-min.js</include> <include>footer-min.js</include>
@ -235,6 +270,33 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>com.google.jstestdriver</groupId>
<artifactId>maven-jstestdriver-plugin</artifactId>
<version>1.2.2-SNAPSHOT</version>
<executions>
<execution>
<id>run-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<debug>true</debug>
<config>src/test/resources/jsTestDriver.conf</config>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -25,7 +25,7 @@ mindplot.CentralTopicBoard = function(centralTopic, layoutManager)
this._centralTopic = centralTopic; this._centralTopic = centralTopic;
}; };
objects.extend(mindplot.CentralTopicBoard, mindplot.TopicBoard); objects.extend(mindplot.CentralTopicBoard, mindplot.Board);
mindplot.CentralTopicBoard.prototype._getBoard = function(position) mindplot.CentralTopicBoard.prototype._getBoard = function(position)
{ {

View File

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

View File

@ -192,11 +192,12 @@ mindplot.MainTopic.prototype._updatePositionOnChangeSize = function(oldSize, new
} }
}; };
mindplot.MainTopic.prototype.setPosition = function(point) mindplot.MainTopic.prototype.setPosition = function(point, fireEvent)
{ {
mindplot.MainTopic.superClass.setPosition.call(this, point); mindplot.MainTopic.superClass.setPosition.call(this, point);
// Update board zero entry position... // Update board zero entry position...
if(fireEvent != false)
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent,[this]); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent,[this]);
}; };

View File

@ -24,7 +24,7 @@ mindplot.MainTopicBoard = function(topic, layoutManager)
this._height = 0; this._height = 0;
}; };
objects.extend(mindplot.MainTopicBoard, mindplot.TopicBoard); objects.extend(mindplot.MainTopicBoard, mindplot.Board);
mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT = 18; mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT = 18;

View File

@ -456,7 +456,7 @@ 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 in for OriginalLayoutManager... // Sort children by order to solve adding order in for OriginalLayoutManager...
if (this._layoutManager.getType() == mindplot.layoutManagers.OriginalLayoutManager.NAME && nodeGraph.getTopicType()!=mindplot.NodeModel.CENTRAL_TOPIC_TYPE && children.length > 0) if (this._layoutManager.getClassName() == mindplot.layoutManagers.OriginalLayoutManager.NAME && nodeGraph.getTopicType()!=mindplot.NodeModel.CENTRAL_TOPIC_TYPE && children.length > 0)
{ {
var oldChildren = children; var oldChildren = children;
children = []; children = [];

View File

@ -29,11 +29,11 @@ mindplot.ScreenManager.prototype.setScale = function(scale)
}; };
mindplot.ScreenManager.prototype.addEventListener=function(event, listener){ mindplot.ScreenManager.prototype.addEventListener=function(event, listener){
$(this._divContainer).addListener(event, listener); $(this._divContainer).addEvent(event, listener);
}; };
mindplot.ScreenManager.prototype.removeEventListener=function(event, listener){ mindplot.ScreenManager.prototype.removeEventListener=function(event, listener){
$(this._divContainer).removeListener(event, listener); $(this._divContainer).removeEvent(event, listener);
}; };
mindplot.ScreenManager.prototype.getWorkspaceElementPosition = function(e) mindplot.ScreenManager.prototype.getWorkspaceElementPosition = function(e)

View File

@ -16,12 +16,12 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.TopicBoard = function() mindplot.Board = function()
{ {
this._height = null; this._height = null;
}; };
mindplot.TopicBoard.prototype._removeEntryByOrder = function(order, position) mindplot.Board.prototype._removeEntryByOrder = function(order, position)
{ {
var board = this._getBoard(position); var board = this._getBoard(position);
var entry = board.lookupEntryByOrder(order); var entry = board.lookupEntryByOrder(order);
@ -31,7 +31,7 @@ mindplot.TopicBoard.prototype._removeEntryByOrder = function(order, position)
board.update(entry); board.update(entry);
}; };
mindplot.TopicBoard.prototype.removeTopicFromBoard = function(topic) mindplot.Board.prototype.removeTopicFromBoard = function(topic)
{ {
var position = topic.getPosition(); var position = topic.getPosition();
var order = topic.getOrder(); var order = topic.getOrder();
@ -40,12 +40,12 @@ mindplot.TopicBoard.prototype.removeTopicFromBoard = function(topic)
topic.setOrder(null); topic.setOrder(null);
}; };
mindplot.TopicBoard.prototype.positionateDragTopic = function(dragTopic) mindplot.Board.prototype.positionateDragTopic = function(dragTopic)
{ {
throw "this method must be overrided"; throw "this method must be overrided";
}; };
mindplot.TopicBoard.prototype.getHeight = function() mindplot.Board.prototype.getHeight = function()
{ {
var board = this._getBoard(); var board = this._getBoard();
return board.getHeight(); return board.getHeight();

View File

@ -36,14 +36,14 @@ mindplot.commands.DragTopicCommand = mindplot.Command.extend(
var origParentTopic = topic.getOutgoingConnectedTopic(); var origParentTopic = topic.getOutgoingConnectedTopic();
var origOrder = null; var origOrder = null;
var origPosition = null; var origPosition = null;
if (topic.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE && origParentTopic != null && origParentTopic.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE) // if (topic.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE && origParentTopic != null && origParentTopic.getType() == mindplot.NodeModel.MAIN_TOPIC_TYPE)
{ // {
// In this case, topics are positioned using order ... // In this case, topics are positioned using order ...
origOrder = topic.getOrder(); origOrder = topic.getOrder();
} else // } else
{ // {
origPosition = topic.getPosition().clone(); origPosition = topic.getPosition().clone();
} // }
// Disconnect topic .. // Disconnect topic ..
if (origParentTopic) if (origParentTopic)

View File

@ -1,24 +1,3 @@
/*
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({ mindplot.layoutManagers.BaseLayoutManager = new Class({
options: { options: {
@ -27,15 +6,60 @@ mindplot.layoutManagers.BaseLayoutManager = new Class({
initialize: function(designer, options) { initialize: function(designer, options) {
this.setOptions(options); this.setOptions(options);
this._boards = new Hash();
this._designer = designer; this._designer = designer;
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));
}, },
addNode: function(node) { _nodeResizeEvent:function(node){
},
_nodeMoveEvent:function(node){
//todo: Usar un solo board para todos los nodos. Testear que ande el set margin cuando se mueven los nodos.
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){
},
getTopicBoardForTopic:function(node){
var id = node.getId()
var result = this._boards[id];
if(!result){
result = this.addNode(node);
}
return result;
},
addNode:function(node){
var board = null;
if (this._isCentralTopic(node))
board = this._createCentralTopicBoard(node);
else
board = this._createMainTopicBoard(node);
var id = node.getId();
this._boards[id]=board;
return board;
},
_createMainTopicBoard:function(node){
return new mindplot.layoutManagers.boards.Board(node, this);
},
_createCentralTopicBoard:function(node){
return new mindplot.layoutManagers.boards.Board(node, this);
}, },
getDesigner:function(){ getDesigner:function(){
return this._designer; return this._designer;
}, },
getType:function(){ _isCentralTopic:function(node){
var type = node.getModel().getType();
return type == mindplot.NodeModel.CENTRAL_TOPIC_TYPE;
},
getClassName:function(){
return mindplot.layoutManagers.BaseLayoutManager.NAME; return mindplot.layoutManagers.BaseLayoutManager.NAME;
} }
}); });

View File

@ -0,0 +1,128 @@
mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayoutManager.extend({
options:{
},
initialize:function(designer, options){
this.parent(designer, options);
},
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)
{
designer.onObjectFocusEvent.attempt([topic, event], designer);
});
// Add drag behaviour ...
if (topic.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE)
{
topic.addEventListener("mousedown",this._mousedownListener.bindWithEvent(this,[topic]));
}
/*// Register editor events ...
if (!this._viewMode)
{
this._editor.listenEventOnNode(topic, 'dblclick', true);
}*/
},
_mousedownListener:function(event,topic){
var workSpace = this._designer.getWorkSpace();
if (workSpace.isWorkspaceEventsEnabled())
{
// Disable double drag...
workSpace.enableWorkspaceEvents(false);
var id = topic.getId();
console.log("down on node: "+id);
var topics = this.getDesigner()._getTopics();
// Disable all mouse events.
for (var i = 0; i < topics.length; i++)
{
topics[i].setMouseEventsEnabled(false);
}
var ev = new Event(event);
var screen = workSpace.getScreenManager();
// Set initial position.
// var mousePos = screen.getWorkspaceMousePosition(event);
// Register mouse move listener ...
this._mouseMoveListenerInstance = this._mouseMoveListener.bindWithEvent(this,[topic]);
screen.addEventListener('mousemove', this._mouseMoveListenerInstance);
// Register mouse up listeners ...
this._mouseUpListenerInstance = this._mouseUpListener.bindWithEvent(this,[topic]);
screen.addEventListener('mouseup', this._mouseUpListenerInstance);
// Change cursor.
window.document.body.style.cursor = 'move';
}
},
_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);
event.preventDefault();
},
_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);
screen.removeEventListener('mouseup', this._mouseUpListenerInstance);
delete this._mouseMoveListenerInstance;
delete this._mouseUpListenerInstance;
var topics = this.getDesigner()._getTopics();
// Disable all mouse events.
for (var i = 0; i < topics.length; i++)
{
topics[i].setMouseEventsEnabled(true);
}
// Change the cursor to the default.
window.document.body.style.cursor = 'default';
this._designer.getWorkSpace().enableWorkspaceEvents(true);
// 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;
},
_createMainTopicBoard:function(node){
return new mindplot.layoutManagers.boards.freeMindBoards.MainTopicBoard(node, this);
},
_createCentralTopicBoard:function(node){
return new mindplot.layoutManagers.boards.freeMindBoards.CentralTopicBoard(node, this);
}
});
mindplot.layoutManagers.FreeMindLayoutManager.NAME ="FreeMindLayoutManager";

View File

@ -1,7 +1,7 @@
mindplot.layoutManagers.LayoutManagerFactory = {}; mindplot.layoutManagers.LayoutManagerFactory = {};
mindplot.layoutManagers.LayoutManagerFactory.managers = { mindplot.layoutManagers.LayoutManagerFactory.managers = {
OriginalLayoutManager:mindplot.layoutManagers.OriginalLayoutManager OriginalLayoutManager:mindplot.layoutManagers.OriginalLayoutManager,
// FreeLayoutManager:mindplot.layoutManagers.FreeLayoutManager FreeMindLayoutManager:mindplot.layoutManagers.FreeMindLayoutManager
}; };
mindplot.layoutManagers.LayoutManagerFactory.getManagerByName = function(name){ mindplot.layoutManagers.LayoutManagerFactory.getManagerByName = function(name){
var manager = mindplot.layoutManagers.LayoutManagerFactory.managers[name+"Manager"]; var manager = mindplot.layoutManagers.LayoutManagerFactory.managers[name+"Manager"];

View File

@ -4,7 +4,6 @@ mindplot.layoutManagers.OriginalLayoutManager = mindplot.layoutManagers.BaseLayo
}, },
initialize:function(designer, options){ initialize:function(designer, options){
this.parent(designer, options); this.parent(designer, options);
this._boards = new Hash();
this._dragTopicPositioner = new mindplot.DragTopicPositioner(this); this._dragTopicPositioner = new mindplot.DragTopicPositioner(this);
// Init dragger manager. // Init dragger manager.
var workSpace = this.getDesigner().getWorkSpace(); var workSpace = this.getDesigner().getWorkSpace();
@ -12,27 +11,12 @@ mindplot.layoutManagers.OriginalLayoutManager = mindplot.layoutManagers.BaseLayo
// Add shapes to speed up the loading process ... // Add shapes to speed up the loading process ...
mindplot.DragTopic.initialize(workSpace); 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){ _nodeResizeEvent:function(node){
var size = node.getSize(); var size = node.getSize();
if(!this._isCentralTopic(node)) if(!this._isCentralTopic(node))
this.getTopicBoardForTopic(node).updateChildrenPosition(node,size.height/2); 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){ _NodeRepositionateEvent:function(node){
this.getTopicBoardForTopic(node).repositionate(); this.getTopicBoardForTopic(node).repositionate();
}, },
@ -117,29 +101,13 @@ mindplot.layoutManagers.OriginalLayoutManager = mindplot.layoutManagers.BaseLayo
}*/ }*/
}, },
getTopicBoardForTopic:function(node){ _createMainTopicBoard:function(node){
var id = node.getId() return new mindplot.MainTopicBoard(node, this);
var result = this._boards[id];
if(!result){
result = this.addNode(node);
}
return result;
}, },
addNode:function(node){ _createCentralTopicBoard:function(node){
var boardClass = mindplot.MainTopicBoard; return new mindplot.CentralTopicBoard(node,this);
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){ getClassName:function(){
var type = node.getModel().getType();
return type == mindplot.NodeModel.CENTRAL_TOPIC_TYPE;
},
getType:function(){
return mindplot.layoutManagers.OriginalLayoutManager.NAME; return mindplot.layoutManagers.OriginalLayoutManager.NAME;
} }
}); });

View File

@ -0,0 +1,33 @@
mindplot.layoutManagers.boards={};
mindplot.layoutManagers.boards.Board = new Class({
options: {
},
initialize: function(node, layoutManager, options) {
this.setOptions(options);
this._node = node;
this._layoutManager = layoutManager;
},
getClassName:function(){
return mindplot.layoutManagers.boards.Board.NAME;
},
removeTopicFromBoard:function(node){
core.Utils.assert(false, "no Board implementation found!");
},
addBranch:function(node){
core.Utils.assert(false, "no Board implementation found!");
},
updateChildrenPosition:function(node){
core.Utils.assert(false, "no Board implementation found!");
},
setNodeMarginTop:function(node, delta){
core.Utils.assert(false, "no Board implementation found!");
}
});
mindplot.layoutManagers.boards.Board.NAME ="Board";
mindplot.layoutManagers.boards.Board.implement(new Events);
mindplot.layoutManagers.boards.Board.implement(new Options);

View File

@ -0,0 +1,118 @@
mindplot.layoutManagers.boards.freeMindBoards={};
mindplot.layoutManagers.boards.freeMindBoards.Board = mindplot.layoutManagers.boards.Board.extend({
options:{
},
initialize:function(node, layoutManager, options){
this.parent(node, layoutManager, options);
this._positionTables = this._createTables();
},
_createTables:function(){
core.Utils.assert(false, "no Board implementation found!")
},
_getTableForNode:function(node){
core.Utils.assert(false, "no Board implementation found!")
},
removeTopicFromBoard:function(node){
var table = this._getTableForNode(node);
var position = node.getPosition();
var y = position.y;
//search for position
for(var i = 0; i< table.length ; i++){
var entry = table[i];
if (entry.position == y){
this._removeEntry(node, table, i);
break;
}
}
},
addBranch:function(node){
var result = this.findNodeEntryIndex(node);
this._insertNewEntry(node, result.table, result.index);
},
_insertNewEntry:function(node, table, index){
var entry = new mindplot.layoutManagers.boards.freeMindBoards.Entry(node);
table.splice(index, 0, entry);
this._updateTable(index, table);
},
_removeEntry:function(node, table, index){
table.splice(index, 1);
this._updateTable(index, table);
},
_updateTable:function(index, table){
var i = index;
if(index >= table.length){
i = table.length -1;
}
var modifiedTopics = [];
var delta = null;
//check from index to 0;
if(i>0){
var entry = table[i];
var prevEntry = table[i-1];
var marginTop = entry.getPosition() + entry.getMarginTop();
var marginBottom = prevEntry.getPosition() - prevEntry.getMarginBottom();
if(marginTop>marginBottom){
delta = marginBottom - marginTop;
i--;
while(i >= 0){
this._moveTopic(table[i], delta, modifiedTopics);
i--;
}
}
}
i = index;
delta = null;
//check from index to length
if( i<table.length-1){
entry = table[i];
var nextEntry = table[i+1];
marginBottom = entry.getPosition() - entry.getMarginBottom();
marginTop = nextEntry.getPosition() + nextEntry.getMarginTop();
if(marginTop>marginBottom){
delta = marginTop-marginBottom;
i++;
while(i<table.length){
this._moveTopic(table[i], delta, modifiedTopics);
i++;
}
}
}
},
_moveTopic:function(entry, delta, modifiedTopics){
var pos = entry.getPosition();
pos -= delta;
entry.setPosition(pos);
modifiedTopics.push(entry);
},
updateChildrenPosition:function(node){
var result = this.findNodeEntryIndex(node);
this._updateTable(result.index, result.table);
},
findNodeEntryIndex:function(node){
var table = this._getTableForNode(node);
var position = node.getPosition();
var y = position.y;
//search for position
var i;
for(i = 0; i< table.length ; i++){
var entry = table[i];
if (entry.getPosition() < y){
break;
}
}
return {index:i, table:table};
},
setNodeMarginTop:function(node, delta){
var result = this.findNodeEntryIndex(node);
var entry = result.table[result.index];
var marginTop = entry.getMarginTop()-delta.y;
entry.setMarginTop(marginTop);
}
});

View File

@ -0,0 +1,23 @@
mindplot.layoutManagers.boards.freeMindBoards.CentralTopicBoard = mindplot.layoutManagers.boards.freeMindBoards.Board.extend({
options:{
},
initialize:function(node, layoutManager, options){
this.parent(node, layoutManager, options);
},
_createTables:function(){
return [[],[]];
},
_getTableForNode:function(node){
var i = 0;
var position = node.getPosition();
if(!position){
if(Math.sign(node.getParent().getPosition().x) == -1){
i=1;
}
}
else if(mindplot.util.Shape.isAtRight(position, node.getParent().getPosition()))
i=1;
return this._positionTables[i];
}
});

View File

@ -0,0 +1,43 @@
mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
initialize:function(node){
this._node = node;
this._DEFAULT_X_GAP = 30;
var pos = node.getPosition();
if(!pos){
var parent = node.getParent();
pos = parent.getPosition().clone();
var pwidth = parent.getSize().width;
var width = node.getSize().width;
pos.x = pos.x + Math.sign(pos.x) * (this._DEFAULT_X_GAP + pwidth/2 + width/2);
node.setPosition(pos, false);
}
this._position = pos.y;
var height = node.getSize().height;
this._DEFAULT_GAP = 10;
this._marginTop = this._DEFAULT_GAP + height/2;
this._marginBottom = this._DEFAULT_GAP + height/2;
},
getNode:function(){
return this._node;
},
getPosition:function(){
return this._position;
},
setPosition:function(pos){
var position = this._node.getPosition();
position.y = pos;
this._node.setPosition(position);
this._position = pos;
},
getMarginTop:function(){
return this._marginTop;
},
setMarginTop:function(value){
if(value >= this._DEFAULT_GAP){
this._marginTop = value;
}
},
getMarginBottom:function(){
return this._marginTop;
}
});

View File

@ -0,0 +1,14 @@
mindplot.layoutManagers.boards.freeMindBoards.MainTopicBoard = mindplot.layoutManagers.boards.freeMindBoards.Board.extend({
options:{
},
initialize:function(node, layoutManager, options){
this.parent(node, layoutManager, options);
},
_createTables:function(){
return [[]];
},
_getTableForNode:function(node){
return this._positionTables[0];
}
});

View File

@ -0,0 +1,128 @@
TestCase("Mindplot test",{
setUp:function(){
/*:DOC += <div id="mindplot"></div> */
var mapId = '1';
var mapXml = '<map name="1" version="pela"><topic central="true" text="test" id="1"><topic position="103,-52" order="" id="2"/><topic position="-134,-75" order="" id="3"/><topic position="-126,5" order="" id="4"/><topic position="-115,53" order="" id="5"/><topic position="-136,-35" order="" id="6"/></topic></map>';
var editorProperties = {"zoom":0.7};
var isTryMode = false;
afterMindpotLibraryLoading = function()
{
buildMindmapDesigner();
// Register Events ...
$(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer));
/*// Autosave ...
if (!isTryMode)
{
var autosave = function() {
if (designer.needsSave())
{
designer.save(function()
{
// var monitor = core.Monitor.getInstance();
}, false);
}
};
autosave.periodical(30000);
// To prevent the user from leaving the page with changes ...
window.onbeforeunload = function confirmExit()
{
if (designer.needsSave())
{
designer.save(null, false)
}
}
}*/
};
var buildMindmapDesigner = function()
{
// Initialize message logger ...
var container = $('mindplot');
// Initialize Editor ...
var screenWidth = window.getWidth();
var screenHeight = window.getHeight();
// Positionate node ...
// header - footer
screenHeight = screenHeight - 90 - 61;
// body margin ...
editorProperties.width = screenWidth;
editorProperties.height = screenHeight;
designer = new mindplot.MindmapDesigner(editorProperties, container);
designer.loadFromXML(mapId, mapXml);
/*// Save map on load ....
if (editorProperties.saveOnLoad)
{
var saveOnLoad = function() {
designer.save(function() {
}, false);
}.delay(1000)
}*/
}
afterMindpotLibraryLoading();
},
testWorkspaceBuild:function(){
assertNotNull($('workspace'));
},
testCentralTopicPresent:function(){
var centralTopic = designer.getCentralTopic();
assertNotNull(centralTopic);
var position = centralTopic.getPosition();
assertEquals(0,position.x);
assertEquals(0,position.y);
},
testMouseCreateMainTopic:function(){
var centralTopic = designer.getCentralTopic();
assertNotNull(centralTopic);
var target = designer.getWorkSpace().getScreenManager().getContainer();
var size = designer._getTopics().length;
fireNativeEvent('dblclick',target,new core.Point(50,50));
assertEquals(size+1, designer._getTopics().length);
}
});
var fireNativeEvent = function(type, target, position){
var event;
if(core.UserAgent.isIE()){
event = document.createEventObject();
event.screenX = position.x;
event.screenY = position.y;
target.dispatchEvent(event);
}else{
var eventFamily;
if(type == "click" || type == "mousedown" || type == "mousemove" || type == "mouseout" || type == "mouseover" ||
type == "mouseup" || type == "dblclick")
eventFamily = "MouseEvents";
else if(type == "keydown" || type == "keypress" || type == "keyup" || type=="DOMActivate" || type == "DOMFocusIn" ||
type == "DOMFocusOut")
eventFamily = "UIEvents";
else if(type == "abort" || type == "blur" || type == "change" || type == "error" || type == "focus" || type == "load"
|| type == "reset" || type == "resize" || type == "scroll" || type == "select" || type == "submit" || type == "unload")
eventFamily = "HTMLEvents";
else if(type == "DOMAttrModified" || type == "DOMNodeInserted" || type == "DOMNodeRemoved"
|| type == "DOMCharacterDataModified" || type == "DOMNodeInsertedIntoDocument" || type == "DOMNodeRemovedFromDocument"
|| type == "DOMSubtreeModified")
eventFamily = "MutationEvents";
else
eventFamily = "Events";
event = document.createEvent(eventFamily);
event.initEvent(type,true,false, target, 0, position.x, position.y);
target.fireEvent(type, event);
}
return event;
};

View File

@ -0,0 +1,7 @@
server: http://localhost:9876
load:
- ../../../wise-webapp/src/main/webapp/js/mootools.js
- ../../../core-js/target/classes/core.js
- ../../target/classes/mindplot.svg.js
- javascript/*.js