mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-08-20 20:40:44 +02:00
Start integration with new layout.
This commit is contained in:
parent
ad1bb136fd
commit
86e80e324c
@ -61,7 +61,6 @@
|
||||
<filelist dir="${basedir}/src/main/javascript/libraries/moodialog/"
|
||||
files="MooDialog.Fx.js"/>
|
||||
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="EventBus.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="model/IMindmap.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="model/Mindmap.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="model/INodeModel.js"/>
|
||||
@ -158,28 +157,13 @@
|
||||
files="commands/AddRelationshipCommand.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="commands/MoveControlPointCommand.js"/>
|
||||
<!--<filelist dir="${basedir}/src/main/javascript/"-->
|
||||
<!--files="commands/freeMind/DragTopicCommand.js"/>-->
|
||||
<!--<filelist dir="${basedir}/src/main/javascript/"-->
|
||||
<!--files="commands/freeMind/ReconnectTopicCommand.js"/>-->
|
||||
|
||||
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="layout/boards/Board.js"/>
|
||||
<!--<filelist dir="${basedir}/src/main/javascript/"-->
|
||||
<!--files="layout/boards/freemind/Board.js"/>-->
|
||||
<!--<filelist dir="${basedir}/src/main/javascript/"-->
|
||||
<!--files="layout/boards/freemind/Entry.js"/>-->
|
||||
<!--<filelist dir="${basedir}/src/main/javascript/"-->
|
||||
<!--files="layout/boards/freemind/CentralTopicBoard.js"/>-->
|
||||
<!--<filelist dir="${basedir}/src/main/javascript/"-->
|
||||
<!--files="layout/boards/freemind/MainTopicBoard.js"/>-->
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="layout/BaseLayoutManager.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="layout/OriginalLayoutManager.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="layout/FreeMindLayoutManager.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="layout/LayoutManagerFactory.js"/>
|
||||
|
||||
@ -213,6 +197,25 @@
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="widget/Menu.js"/>
|
||||
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/EventBusDispatcher.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="nlayout/ChangeEvent.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/LayoutManager.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/Node.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/RootedTreeSet.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/ChildrenSorterStrategy.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/SymetricSorter.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/GridSorter.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/"
|
||||
files="nlayout/OriginalLayout.js"/>
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="nlayout/EventBus.js"/>
|
||||
|
||||
<filelist dir="${basedir}/src/main/javascript/" files="footer.js"/>
|
||||
</concat>
|
||||
|
||||
|
@ -43,8 +43,6 @@ mindplot.Designer = new Class({
|
||||
this._workspace = new mindplot.Workspace(screenManager, this._model.getZoom());
|
||||
this._readOnly = profile.readOnly ? true : false;
|
||||
|
||||
// Init layout managers ...
|
||||
this._layoutManager = new mindplot.layout.OriginalLayoutManager(this);
|
||||
|
||||
// Register events
|
||||
if (!profile.readOnly) {
|
||||
@ -52,6 +50,14 @@ mindplot.Designer = new Class({
|
||||
}
|
||||
|
||||
this._relPivot = new mindplot.RelationshipPivot(this._workspace, this);
|
||||
|
||||
// Init layout manager ...
|
||||
this._eventBussDispatcher = new mindplot.nlayout.EventBusDispatcher(this.getModel());
|
||||
|
||||
// @todo: To be removed ...
|
||||
this._layoutManager = new mindplot.layout.OriginalLayoutManager(this);
|
||||
|
||||
|
||||
},
|
||||
|
||||
_registerEvents : function() {
|
||||
@ -370,6 +376,9 @@ mindplot.Designer = new Class({
|
||||
// Place the focus on the Central Topic
|
||||
var centralTopic = this.getModel().getCentralTopic();
|
||||
this.goToNode(centralTopic);
|
||||
|
||||
// Finally, sort the map ...
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
|
||||
},
|
||||
|
||||
getMindmap : function() {
|
||||
@ -395,14 +404,16 @@ mindplot.Designer = new Class({
|
||||
var children = nodeModel.getChildren().slice();
|
||||
children = this._layoutManager.prepareNode(nodeGraph, children);
|
||||
|
||||
var workspace = this._workspace;
|
||||
workspace.appendChild(nodeGraph);
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if ($defined(child))
|
||||
this._nodeModelToNodeGraph(child, false);
|
||||
}
|
||||
|
||||
var workspace = this._workspace;
|
||||
workspace.appendChild(nodeGraph);
|
||||
|
||||
return nodeGraph;
|
||||
},
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
mindplot.EventBus = new Class({
|
||||
Extends:Options,
|
||||
Implements:Events,
|
||||
options: {
|
||||
|
||||
},
|
||||
initialize: function(options) {
|
||||
this.setOptions(options);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
mindplot.EventBus.events = {
|
||||
NodeResizeEvent:'NodeResizeEvent',
|
||||
NodeMoveEvent:'NodeMoveEvent',
|
||||
NodeDisconnectEvent:'NodeDisconnectEvent',
|
||||
NodeConnectEvent:'NodeConnectEvent',
|
||||
NodeRepositionateEvent:'NodeRepositionateEvent',
|
||||
NodeShrinkEvent:'NodeShrinkEvent',
|
||||
NodeMouseOverEvent:'NodeMouseOverEvent',
|
||||
NodeMouseOutEvent:'NodeMouseOutEvent'
|
||||
};
|
||||
|
||||
mindplot.EventBus.instance = new mindplot.EventBus();
|
@ -313,7 +313,7 @@ mindplot.Topic = new Class({
|
||||
//Links
|
||||
var links = model.getLinks();
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
this._link = new mindplot.LinkIcon(this,links[i]);
|
||||
this._link = new mindplot.LinkIcon(this, links[i]);
|
||||
result.addIcon(this._link);
|
||||
}
|
||||
|
||||
@ -1074,7 +1074,8 @@ mindplot.Topic = new Class({
|
||||
outgoingLine.removeFromWorkspace(workspace);
|
||||
|
||||
// Remove from workspace.
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent, [targetTopic, this]);
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.ONodeDisconnectEvent, [targetTopic, this]);
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent, this.getModel());
|
||||
|
||||
// Change text based on the current connection ...
|
||||
var model = this.getModel();
|
||||
@ -1121,7 +1122,7 @@ mindplot.Topic = new Class({
|
||||
childModel.connectTo(targetModel);
|
||||
|
||||
// Update topic position based on the state ...
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, [targetTopic, this]);
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.ONodeConnectEvent, [targetTopic, this]);
|
||||
|
||||
// Create a connection line ...
|
||||
var outgoingLine = new mindplot.ConnectionLine(this, targetTopic);
|
||||
@ -1151,6 +1152,12 @@ mindplot.Topic = new Class({
|
||||
|
||||
// Redraw line ...
|
||||
outgoingLine.redraw();
|
||||
|
||||
// Fire connection event ...
|
||||
if (this.isInWorkspace()) {
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:targetTopic.getModel(), childNode: this.getModel()});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
appendChild : function(child) {
|
||||
@ -1185,6 +1192,13 @@ mindplot.Topic = new Class({
|
||||
addToWorkspace : function(workspace) {
|
||||
var elem = this.get2DElement();
|
||||
workspace.appendChild(elem);
|
||||
if (!this.isInWorkspace()) {
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeAdded, this.getModel());
|
||||
|
||||
if (this.getModel().isConnected())
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent, {parentNode:this.getOutgoingConnectedTopic().getModel(), childNode: this.getModel()});
|
||||
|
||||
}
|
||||
this._isInWorkspace = true;
|
||||
this._adjustShapes();
|
||||
},
|
||||
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.commands.freeMind={};
|
||||
|
||||
mindplot.commands.freeMind.DragTopicCommand = mindplot.Command.extend(
|
||||
{
|
||||
initialize: function()
|
||||
{
|
||||
this._modifiedTopics=null;
|
||||
this._id = mindplot.Command._nextUUID();
|
||||
},
|
||||
execute: function(commandContext)
|
||||
{
|
||||
var keys = this._modifiedTopics.keys();
|
||||
for(var i=0; i<keys.length; i++){
|
||||
var id = keys[i];
|
||||
var modTopic = this._modifiedTopics.get(id);
|
||||
var topic = commandContext.findTopics(parseInt(id))[0];
|
||||
|
||||
var position = topic.getPosition();
|
||||
var pos = modTopic.newPos;
|
||||
if(position.x != pos.x || position.y != pos.y){
|
||||
topic.setPosition(pos.clone(), true);
|
||||
}
|
||||
}
|
||||
},
|
||||
undoExecute: function(commandContext)
|
||||
{
|
||||
var keys = this._modifiedTopics.keys();
|
||||
for(var i=0; i<keys.length; i++){
|
||||
var id = keys[i];
|
||||
var modTopic = this._modifiedTopics.get(id);
|
||||
var topic = commandContext.findTopics(parseInt(id))[0];
|
||||
|
||||
var position = topic.getPosition();
|
||||
var pos = modTopic.originalPos;
|
||||
if(position.x != pos.x || position.y != pos.y){
|
||||
topic.setPosition(pos.clone(), true);
|
||||
}
|
||||
}
|
||||
},
|
||||
setModifiedTopics:function(modifiedTopics){
|
||||
this._modifiedTopics = modifiedTopics;
|
||||
}
|
||||
});
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
||||
{
|
||||
initialize: function()
|
||||
{
|
||||
this._modifiedTopics=null;
|
||||
this._id = mindplot.Command._nextUUID();
|
||||
this._node = null;
|
||||
this._targetNode = null;
|
||||
this._pivot = null;
|
||||
this._oldParent = null;
|
||||
},
|
||||
execute: function(commandContext)
|
||||
{
|
||||
var node = commandContext.findTopics(parseInt(this._node))[0];
|
||||
var targetNode = commandContext.findTopics(parseInt(this._targetNode))[0];
|
||||
var keys = this._modifiedTopics.keys();
|
||||
for(var i=0; i<keys.length; i++){
|
||||
var id = keys[i];
|
||||
var modTopic = this._modifiedTopics.get(id);
|
||||
var topic = commandContext.findTopics(parseInt(id))[0];
|
||||
|
||||
var position = topic.getPosition();
|
||||
var pos = modTopic.newPos;
|
||||
if(position.x != pos.x || position.y != pos.y){
|
||||
topic.setPosition(pos.clone(), true);
|
||||
}
|
||||
if(id = this._node){
|
||||
node._originalPosition = modTopic.originalPos;
|
||||
}
|
||||
}
|
||||
var oldParent = this._oldParent!=null?commandContext.findTopics(parseInt(this._oldParent))[0]:null;
|
||||
node.relationship = this._pivot;
|
||||
node._relationship_oldParent = oldParent;
|
||||
node._relationship_index = this._index;
|
||||
commandContext.disconnect(node);
|
||||
var parentNode = targetNode;
|
||||
if(this._pivot != "Child"){
|
||||
parentNode = targetNode.getParent();
|
||||
node._relationship_sibling_node = targetNode;
|
||||
}
|
||||
commandContext.connect(node, parentNode);
|
||||
delete node.relationship;
|
||||
delete node._relationship_oldParent;
|
||||
delete node._relationship_sibling_node;
|
||||
delete node._relationship_index;
|
||||
delete node._originalPosition;
|
||||
},
|
||||
undoExecute: function(commandContext)
|
||||
{
|
||||
var node = commandContext.findTopics(parseInt(this._node))[0];
|
||||
var targetNode = this._oldParent!=null?commandContext.findTopics(parseInt(this._oldParent))[0]:null;
|
||||
|
||||
var keys = this._modifiedTopics.keys();
|
||||
for(var i=0; i<keys.length; i++){
|
||||
var id = keys[i];
|
||||
var modTopic = this._modifiedTopics.get(id);
|
||||
var topic = commandContext.findTopics(parseInt(id))[0];
|
||||
|
||||
var position = topic.getPosition();
|
||||
var pos = modTopic.originalPos;
|
||||
if(position.x != pos.x || position.y != pos.y){
|
||||
topic.setPosition(pos.clone(), true);
|
||||
}
|
||||
if(id = this._node){
|
||||
node._originalPosition = modTopic.newPos;
|
||||
}
|
||||
}
|
||||
var oldParent = commandContext.findTopics(parseInt(this._targetNode))[0];
|
||||
if(this._pivot != "Child"){
|
||||
oldParent = oldParent.getParent();
|
||||
}
|
||||
if(targetNode!=null){
|
||||
node.relationship = "undo";
|
||||
node._relationship_oldParent = oldParent;
|
||||
node._relationship_index = this._index;
|
||||
}
|
||||
commandContext.disconnect(node);
|
||||
if(targetNode!=null){
|
||||
commandContext.connect(node, targetNode);
|
||||
delete node.relationship;
|
||||
delete node._relationship_oldParent;
|
||||
delete node._relationship_index;
|
||||
}
|
||||
delete node._originalPosition;
|
||||
},
|
||||
setModifiedTopics:function(modifiedTopics){
|
||||
this._modifiedTopics = modifiedTopics;
|
||||
},
|
||||
setDraggedTopic:function(node, index){
|
||||
this._node = node.getId();
|
||||
var outgoingConnectedTopic = node.getOutgoingConnectedTopic();
|
||||
this._oldParent = outgoingConnectedTopic!=null?outgoingConnectedTopic.getId():null;
|
||||
this._index = index;
|
||||
},
|
||||
setTargetNode:function(node){
|
||||
this._targetNode = node.getId();
|
||||
},
|
||||
setAs:function(relationship){
|
||||
this._pivot = relationship;
|
||||
}
|
||||
});
|
@ -28,8 +28,8 @@ mindplot.layout.BaseLayoutManager = new Class({
|
||||
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.ONodeDisconnectEvent, this._nodeDisconnectEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeConnectEvent, this._nodeConnectEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRepositionateEvent, this._nodeRepositionateEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
|
||||
},
|
||||
|
@ -1,706 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
mindplot.layout.FreeMindLayoutManager = mindplot.layout.BaseLayoutManager.extend({
|
||||
options:{
|
||||
|
||||
},
|
||||
initialize:function(designer, options){
|
||||
this.parent(designer, options);
|
||||
},
|
||||
_nodeConnectEvent:function(targetNode, node){
|
||||
if($defined(node.relationship)){
|
||||
this._movingNode(targetNode, node);
|
||||
}
|
||||
else if(!this._isCentralTopic(node)){
|
||||
this.parent(targetNode, node);
|
||||
}
|
||||
},
|
||||
_nodeDisconnectEvent:function(targetNode, node){
|
||||
if($defined(node.relationship)){
|
||||
}
|
||||
else{
|
||||
this.parent(targetNode, node);
|
||||
this._updateBoard(targetNode,[]);
|
||||
}
|
||||
},
|
||||
_nodeShrinkEvent:function(node){
|
||||
this._updateBoard(node,[]);
|
||||
},
|
||||
prepareNode:function(node, children){
|
||||
var layoutManagerName = editorProperties.layoutManager;
|
||||
//if last layout used is this one
|
||||
if(typeof layoutManagerName != "undefined" && layoutManagerName == this.getClassName()){
|
||||
var result = children.sort(function(n1, n2){
|
||||
if(n1.getPosition() && n2.getPosition())
|
||||
return n1.getPosition().y>n2.getPosition().y;
|
||||
else
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
//sort childs by order
|
||||
var result = children.sort(function(n1, n2){
|
||||
if(n1.getOrder() && n2.getOrder())
|
||||
return n1.getOrder()>n2.getOrder();
|
||||
else
|
||||
return true;
|
||||
});
|
||||
delete node.getModel()._finalPosition;
|
||||
result = children;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
registerListenersOnNode : function(topic)
|
||||
{
|
||||
var id = topic.getId();
|
||||
// Register node listeners ...
|
||||
var designer = this.getDesigner();
|
||||
topic.addEvent('click', function(event)
|
||||
{
|
||||
designer.onObjectFocusEvent.attempt([topic, event], designer);
|
||||
});
|
||||
|
||||
// Add drag behaviour ...
|
||||
if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE)
|
||||
{
|
||||
topic.addEvent("mousedown",this._reconnectMouseDownListener.bindWithEvent(this,[topic]));
|
||||
}
|
||||
|
||||
},
|
||||
_mousedownListener:function(event,topic){
|
||||
|
||||
var workSpace = this._designer.getWorkSpace();
|
||||
if (workSpace.isWorkspaceEventsEnabled())
|
||||
{
|
||||
// Disable double drag...
|
||||
workSpace.enableWorkspaceEvents(false);
|
||||
|
||||
var id = topic.getId();
|
||||
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++)
|
||||
{
|
||||
topics[i].setMouseEventsEnabled(false);
|
||||
}
|
||||
|
||||
var ev = new Event(event);
|
||||
|
||||
var screen = workSpace.getScreenManager();
|
||||
|
||||
// Set initial position.
|
||||
this._mouseInitialPos = screen.getWorkspaceMousePosition(event);
|
||||
var pos = topic.getPosition();
|
||||
this._mouseInitialPos.x = 0;
|
||||
this._mouseInitialPos.y = pos.y - Math.round(this._mouseInitialPos.y);
|
||||
|
||||
this._isMovingNode=false;
|
||||
|
||||
// Register mouse move listener ...
|
||||
this._mouseMoveListenerInstance = this._mouseMoveListener.bindWithEvent(this,[topic]);
|
||||
screen.addEvent('mousemove', this._mouseMoveListenerInstance);
|
||||
|
||||
// Register mouse up listeners ...
|
||||
this._mouseUpListenerInstance = this._mouseUpListener.bindWithEvent(this,[topic]);
|
||||
screen.addEvent('mouseup', this._mouseUpListenerInstance);
|
||||
|
||||
// Change cursor.
|
||||
window.document.body.style.cursor = 'move';
|
||||
}
|
||||
},
|
||||
_mouseMoveListener:function(event, node){
|
||||
if(!this._isMovingNode){
|
||||
this._isMovingNode=true;
|
||||
var screen = this._designer.getWorkSpace().getScreenManager();
|
||||
var nodePos = node.getPosition().clone();
|
||||
nodePos.x-=this._mouseInitialPos.x;
|
||||
nodePos.y-=this._mouseInitialPos.y;
|
||||
var pos = screen.getWorkspaceMousePosition(event);
|
||||
pos.x = Math.round(pos.x);
|
||||
pos.y = Math.round(pos.y);
|
||||
//if isolated topic
|
||||
if(node.getParent()==null){
|
||||
//If still in same side
|
||||
if(Math.sign(nodePos.x)==Math.sign(pos.x)){
|
||||
var x = nodePos.x - pos.x;
|
||||
var y = nodePos.y - pos.y;
|
||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||
var actualPos = node.getPosition().clone();
|
||||
var newPos = new core.Point(actualPos.x-(delta.x==null?0:delta.x), actualPos.y-delta.y);
|
||||
node.setPosition(newPos, false);
|
||||
this._addToModifiedList(this._modifiedTopics, node.getId(), actualPos, newPos);
|
||||
this._updateChildrenBoards(node, delta, this._modifiedTopics);
|
||||
}else{
|
||||
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
||||
node.setPosition(pos.clone(), false);
|
||||
this._addToModifiedList(this._modifiedTopics, node.getId(), nodePos, pos);
|
||||
}
|
||||
}else{
|
||||
//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];
|
||||
parentBoard._removeEntry(node, entryObj.table, entryObj.index, this._modifiedTopics);
|
||||
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
||||
node.setPosition(pos.clone(), false);
|
||||
if($defined(this._modifiedTopics.set)){
|
||||
var key = node.getId();
|
||||
if(this._modifiedTopics.has(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._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];
|
||||
var childPos = child.getPosition().clone();
|
||||
var oldPos=childPos.clone();
|
||||
childPos.x = newPos.x +(childPos.x - refPos.x)*-1;
|
||||
childPos.y = newPos.y +(childPos.y - refPos.y);
|
||||
this._changeChildrenSide(child, childPos, modifiedTopics);
|
||||
child.setPosition(childPos, false);
|
||||
if($defined(modifiedTopics.set)){
|
||||
var key = node.getId();
|
||||
if(modifiedTopics.has(key)){
|
||||
oldPos = this._modifiedTopics.get(key).originalPos;
|
||||
}
|
||||
this._modifiedTopics.set(key,{originalPos:oldPos, newPos:childPos});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_mouseUpListener:function(event, node){
|
||||
|
||||
var screen = this._designer.getWorkSpace().getScreenManager();
|
||||
// Remove all the events.
|
||||
screen.removeEvent('mousemove', this._mouseMoveListenerInstance);
|
||||
screen.removeEvent('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);
|
||||
|
||||
this._command.setModifiedTopics(this._modifiedTopics);
|
||||
var actionRunner = mindplot.DesignerActionRunner.getInstance();
|
||||
actionRunner.execute(this._command);
|
||||
this._command=null;
|
||||
this._modifiedTopics=null;
|
||||
this._mouseInitialPos=null;
|
||||
|
||||
},
|
||||
getClassName:function(){
|
||||
return mindplot.layout.FreeMindLayoutManager.NAME;
|
||||
},
|
||||
_createMainTopicBoard:function(node){
|
||||
return new mindplot.layout.boards.freemind.MainTopicBoard(node, this);
|
||||
},
|
||||
_createCentralTopicBoard:function(node){
|
||||
return new mindplot.layout.boards.freemind.CentralTopicBoard(node, this);
|
||||
}
|
||||
,
|
||||
_updateParentBoard:function(node, modifiedTopics){
|
||||
this._updateBoard(node.getParent(), modifiedTopics);
|
||||
},
|
||||
_updateBoard:function(node, modifiedTopics){
|
||||
var parent = node;
|
||||
if(!this._isCentralTopic(parent) && parent.getParent()!=null){
|
||||
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);
|
||||
} else {
|
||||
parentBoard.setNodeChildrenMarginTop(parentEntry, 0);
|
||||
parentBoard.setNodeChildrenMarginBottom(parentEntry, 0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
},
|
||||
addHelpers:function(node){
|
||||
if (node.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE)
|
||||
this._addMoveHelper(node);
|
||||
},
|
||||
_addMoveHelper:function(node){
|
||||
var moveShape = new mindplot.ActionIcon(node, mindplot.layout.FreeMindLayoutManager.MOVE_IMAGE_URL);
|
||||
moveShape.setCursor('move');
|
||||
var positionate = function(node){
|
||||
if(node.getId() == this.getNode().getId()){
|
||||
var size = this.getNode().getSize();
|
||||
this.setPosition(size.width/2,0);
|
||||
}
|
||||
}.bind(moveShape);
|
||||
positionate(node);
|
||||
moveShape.setVisibility(false);
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeResizeEvent,positionate);
|
||||
var show = function(node){
|
||||
if(node.getId() == this.getNode().getId()){
|
||||
this.setVisibility(true);
|
||||
}
|
||||
}.bind(moveShape);
|
||||
var hide = function(node){
|
||||
if(node.getId() == this.getNode().getId()){
|
||||
this.setVisibility(false);
|
||||
}
|
||||
}.bind(moveShape);
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMouseOverEvent,show);
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMouseOutEvent,hide);
|
||||
node.addHelper(moveShape);
|
||||
moveShape.addEvent("mousedown",this._mousedownListener.bindWithEvent(this,[node]));
|
||||
|
||||
},
|
||||
needsPrepositioning:function(){
|
||||
return false;
|
||||
},
|
||||
_reconnectMouseDownListener:function(event, topic){
|
||||
var workSpace = this._designer.getWorkSpace();
|
||||
if (workSpace.isWorkspaceEventsEnabled())
|
||||
{
|
||||
// Disable double drag...
|
||||
workSpace.enableWorkspaceEvents(false);
|
||||
|
||||
var id = topic.getId();
|
||||
this._command = new mindplot.commands.freeMind.ReconnectTopicCommand();
|
||||
this._modifiedTopics = new Hash();
|
||||
this._mouseOverListeners = new Hash();
|
||||
this._mouseOutListeners = new Hash();
|
||||
|
||||
if(topic.getParent()!=null){
|
||||
var board = this.getTopicBoardForTopic(topic.getParent());
|
||||
this._currentIndex = board.findNodeEntryIndex(topic).index;
|
||||
}
|
||||
|
||||
var topics = this.getDesigner()._getTopics();
|
||||
// Disable all mouse events.
|
||||
for (var i = 0; i < topics.length; i++)
|
||||
{
|
||||
topics[i].setMouseEventsEnabled(false);
|
||||
if(topics[i].getId()!=topic.getId()){
|
||||
var overListener = this._reconnectMouseOverListener.bindWithEvent(topics[i],[this]);
|
||||
topics[i].addEvent('mouseover',overListener);
|
||||
this._mouseOverListeners.set(topics[i].getId(),overListener);
|
||||
var outListener = this._reconnectMouseOutListener.bindWithEvent(topics[i],[this]);
|
||||
topics[i].addEvent('mouseout',outListener);
|
||||
this._mouseOutListeners.set(topics[i].getId(),outListener);
|
||||
}
|
||||
}
|
||||
this._updateTopicsForReconnect(topic, mindplot.layout.FreeMindLayoutManager.RECONNECT_NODES_OPACITY);
|
||||
var line = topic.getOutgoingLine();
|
||||
if($defined(line)){
|
||||
line.setVisibility(false);
|
||||
}
|
||||
this._createIndicatorShapes();
|
||||
|
||||
var ev = new Event(event);
|
||||
|
||||
var screen = workSpace.getScreenManager();
|
||||
|
||||
this._isMovingNode=false;
|
||||
|
||||
// Register mouse move listener ...
|
||||
this._mouseMoveListenerInstance = this._reconnectMouseMoveListener.bindWithEvent(this,[topic]);
|
||||
screen.addEvent('mousemove', this._mouseMoveListenerInstance);
|
||||
|
||||
// Register mouse up listeners ...
|
||||
this._mouseUpListenerInstance = this._reconnectMouseUpListener.bindWithEvent(this,[topic]);
|
||||
screen.addEvent('mouseup', this._mouseUpListenerInstance);
|
||||
|
||||
// Change cursor.
|
||||
window.document.body.style.cursor = 'move';
|
||||
}
|
||||
},
|
||||
_reconnectMouseMoveListener:function(event, node){
|
||||
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)){
|
||||
var x = nodePos.x - pos.x;
|
||||
var y = nodePos.y - pos.y;
|
||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||
var newPos = new core.Point(nodePos.x-(delta.x==null?0:delta.x), nodePos.y-delta.y);
|
||||
node.setPosition(newPos, false);
|
||||
this._updateChildrenBoards(node, delta, this._modifiedTopics);
|
||||
} else {
|
||||
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
||||
node.setPosition(pos.clone(), false);
|
||||
// entryObj = parentBoard.findNewNodeEntryIndex(entry);
|
||||
// parentBoard._addEntry(entry, entryObj.table, entryObj.index);
|
||||
// parentBoard._updateTable(entryObj.index, entryObj.table, this._modifiedTopics, true);
|
||||
|
||||
}
|
||||
if($defined(this._modifiedTopics.set)){
|
||||
var key = node.getId();
|
||||
if(this._modifiedTopics.has(key)){
|
||||
nodePos = this._modifiedTopics.get(key).originalPos;
|
||||
}
|
||||
this._modifiedTopics.set(key,{originalPos:nodePos, newPos:pos});
|
||||
}
|
||||
this._isMovingNode=false;
|
||||
}
|
||||
event.preventDefault();
|
||||
},
|
||||
_reconnectMouseUpListener:function(event, node){
|
||||
var screen = this._designer.getWorkSpace().getScreenManager();
|
||||
// Remove all the events.
|
||||
screen.removeEvent('mousemove', this._mouseMoveListenerInstance);
|
||||
screen.removeEvent('mouseup', this._mouseUpListenerInstance);
|
||||
delete this._mouseMoveListenerInstance;
|
||||
delete this._mouseUpListenerInstance;
|
||||
|
||||
var topics = this.getDesigner()._getTopics();
|
||||
// Disable all mouse events.
|
||||
for (var i = topics.length-1; i >=0; i--)
|
||||
{
|
||||
topics[i].setMouseEventsEnabled(true);
|
||||
if(topics[i].getId()!=node.getId()){
|
||||
var overListener = this._mouseOverListeners.get(topics[i].getId());
|
||||
topics[i].removeEvent('mouseover',overListener);
|
||||
var outListener = this._mouseOutListeners.get(topics[i].getId());
|
||||
topics[i].removeEvent('mouseout',outListener);
|
||||
}
|
||||
}
|
||||
|
||||
this._restoreTopicsForReconnect(node);
|
||||
|
||||
this._removeIndicatorShapes(node);
|
||||
|
||||
//Check that it has to be relocated
|
||||
if(this._createShape !=null){
|
||||
if(this._createShape == "Child"){
|
||||
if(node.getParent()!=null && node.getParent().getId() == this._targetNode.getId()){
|
||||
var mod = this._modifiedTopics.get(node.getId());
|
||||
if(Math.sign(mod.originalPos.x) == Math.sign(node.getPosition().x))
|
||||
this._createShape = null;
|
||||
}
|
||||
}else if(node.getParent()!=null && this._targetNode.getParent()!= null && node.getParent().getId() == this._targetNode.getParent().getId()){
|
||||
var chkboard = this.getTopicBoardForTopic(this._targetNode.getParent());
|
||||
var mod = this._modifiedTopics.get(node.getId());
|
||||
var chk = chkboard.findNodeEntryIndex(node, mod.originalPos);
|
||||
if(this._createShape == "Sibling_top"){
|
||||
if(chk.table>this._currentIndex+1){
|
||||
var nextEntry = chk.table[this._currentIndex+1];
|
||||
if(nextEntry.getNode().getId() == this._targetNode.getId()){
|
||||
this._createShape = null;
|
||||
}
|
||||
}
|
||||
} else if(this._currentIndex>0){
|
||||
var prevEntry = chk.table[this._currentIndex-1];
|
||||
if(prevEntry.getNode().getId() == this._targetNode.getId()){
|
||||
this._createShape = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this._createShape == null){
|
||||
//cancel everything.
|
||||
var line = node.getOutgoingLine();
|
||||
if($defined(line)){
|
||||
line.setVisibility(true);
|
||||
}
|
||||
core.Utils.animatePosition(this._modifiedTopics, null, this.getDesigner());
|
||||
}else{
|
||||
this._command.setModifiedTopics(this._modifiedTopics);
|
||||
this._command.setDraggedTopic(node, this._currentIndex);
|
||||
this._command.setTargetNode(this._targetNode);
|
||||
this._command.setAs(this._createShape);
|
||||
//todo:Create command
|
||||
var actionRunner = mindplot.DesignerActionRunner.getInstance();
|
||||
actionRunner.execute(this._command);
|
||||
}
|
||||
|
||||
// Change the cursor to the default.
|
||||
window.document.body.style.cursor = 'default';
|
||||
|
||||
this._designer.getWorkSpace().enableWorkspaceEvents(true);
|
||||
|
||||
this._command=null;
|
||||
this._modifiedTopics=null;
|
||||
this._mouseInitialPos=null;
|
||||
this._mouseOverListeners=null;
|
||||
this._mouseOutListeners=null;
|
||||
this._targetNode = null;
|
||||
this._createShape = null;
|
||||
},
|
||||
//function binded to the node with the over event
|
||||
_reconnectMouseOverListener:function(event, layoutManager){
|
||||
var size = this.getSize();
|
||||
var screen = layoutManager.getDesigner().getWorkSpace().getScreenManager();
|
||||
var pos = screen.getWorkspaceMousePosition(event);
|
||||
pos.x = Math.round(pos.x);
|
||||
pos.y = Math.round(pos.y);
|
||||
var nodePos = this.getPosition();
|
||||
//if it is on the child half side, or it is central topic add it as child
|
||||
if(!this.areChildrenShrinked() && (layoutManager._isCentralTopic(this) || this.getParent()==null || ((Math.sign(nodePos.x)>0 && pos.x>nodePos.x) || (Math.sign(nodePos.x)<0 && pos.x<nodePos.x)))){
|
||||
layoutManager._updateIndicatorShapes(this, mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_CHILD, pos);
|
||||
}else{
|
||||
//is a sibling. if mouse in top half sibling goes above this one
|
||||
if(pos.y<nodePos.y){
|
||||
layoutManager._updateIndicatorShapes(this, mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_SIBLING_TOP);
|
||||
}else{
|
||||
//if mouse in bottom half sibling goes below this one
|
||||
layoutManager._updateIndicatorShapes(this, mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_SIBLING_BOTTOM);
|
||||
}
|
||||
}
|
||||
},
|
||||
_createIndicatorShapes:function(){
|
||||
if(!$defined(this._createChildShape) || !$defined(this._createSiblingShape)){
|
||||
var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:30,height:30,strokeColor:'#FF9933'};
|
||||
var rect = new web2d.Rect(0, rectAttributes);
|
||||
rect.setVisibility(false);
|
||||
this._createChildShape = rect;
|
||||
|
||||
rect = new web2d.Rect(0, rectAttributes);
|
||||
rect.setVisibility(false);
|
||||
this._createSiblingShape = rect;
|
||||
}
|
||||
},
|
||||
_updateIndicatorShapes:function(topic, shape, mousePos){
|
||||
if(this._createChildShape.getParent()!=null|| this._createSiblingShape.getParent()!=null){
|
||||
this._createChildShape.getParent().removeChild(this._createChildShape._peer);
|
||||
this._createSiblingShape.getParent().removeChild(this._createSiblingShape._peer);
|
||||
}
|
||||
topic.get2DElement().appendChild(this._createChildShape);
|
||||
topic.get2DElement().appendChild(this._createSiblingShape);
|
||||
var size = topic.getSize();
|
||||
var position = topic.getPosition();
|
||||
if(shape == mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_CHILD){
|
||||
this._createChildShape.setSize(size.width/2, size.height);
|
||||
var sign = mousePos?Math.sign(mousePos.x):Math.sign(position.x);
|
||||
this._createChildShape.setPosition(sign>0?size.width/2:0, 0);
|
||||
this._createChildShape.setVisibility(true);
|
||||
this._createSiblingShape.setVisibility(false);
|
||||
this._createShape = "Child";
|
||||
this._targetNode = topic;
|
||||
} else if(shape == mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_SIBLING_TOP){
|
||||
this._createSiblingShape.setSize(size.width,size.height/2);
|
||||
this._createSiblingShape.setPosition(0,0);
|
||||
this._createSiblingShape.setVisibility(true);
|
||||
this._createChildShape.setVisibility(false);
|
||||
this._createShape = "Sibling_top";
|
||||
this._targetNode = topic;
|
||||
}else if(shape == mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_SIBLING_BOTTOM){
|
||||
this._createSiblingShape.setSize(size.width,size.height/2);
|
||||
this._createSiblingShape.setPosition(0,size.height/2);
|
||||
this._createSiblingShape.setVisibility(true);
|
||||
this._createChildShape.setVisibility(false);
|
||||
this._createShape = "Sibling_bottom";
|
||||
this._targetNode = topic;
|
||||
} else {
|
||||
this._createSiblingShape.setVisibility(false);
|
||||
this._createChildShape.setVisibility(false);
|
||||
this._createShape = null;
|
||||
this._targetNode = null;
|
||||
}
|
||||
},
|
||||
_removeIndicatorShapes:function(node){
|
||||
if(this._createChildShape.getParent()!=null|| this._createSiblingShape.getParent()!=null){
|
||||
this._createChildShape.getParent().removeChild(this._createChildShape._peer);
|
||||
this._createSiblingShape.getParent().removeChild(this._createSiblingShape._peer);
|
||||
}
|
||||
},
|
||||
_reconnectMouseOutListener:function(event, layoutManager){
|
||||
layoutManager._updateIndicatorShapes(this, null);
|
||||
},
|
||||
_updateTopicsForReconnect:function(topic, opacity){
|
||||
topic.setOpacity(opacity);
|
||||
topic.moveToBack();
|
||||
var children = topic._getChildren();
|
||||
for(var k = 0; k<children.length; k++){
|
||||
this._updateTopicsForReconnect(children[k], opacity);
|
||||
}
|
||||
},
|
||||
_restoreTopicsForReconnect:function(topic){
|
||||
var children = topic._getChildren();
|
||||
for(var k = 0; k<children.length; k++){
|
||||
this._restoreTopicsForReconnect(children[k]);
|
||||
}
|
||||
topic.setOpacity(1);
|
||||
topic.moveToFront();
|
||||
},
|
||||
_movingNode:function(targetNode, node){
|
||||
var entry;
|
||||
if(node._relationship_oldParent!=null){
|
||||
var parentBoard = this.getTopicBoardForTopic(node._relationship_oldParent);
|
||||
var entryObj;
|
||||
if(this._isCentralTopic(node._relationship_oldParent)){
|
||||
var oldPos = node._originalPosition;
|
||||
entryObj = parentBoard.findNodeEntryIndex(node,oldPos);
|
||||
}else{
|
||||
entryObj = parentBoard.findNodeEntryIndex(node);
|
||||
}
|
||||
entry = entryObj.table[entryObj.index];
|
||||
parentBoard._removeEntry(node, entryObj.table, entryObj.index, []);
|
||||
}
|
||||
else{
|
||||
//if is an isolated topic, create entry and update margins.
|
||||
entry = new mindplot.layout.boards.freemind.Entry(node, false);
|
||||
var board = this.getTopicBoardForTopic(node);
|
||||
var table = board._getTableForNode(null);
|
||||
if(table.length>0){
|
||||
var firstChild = table[0];
|
||||
var marginTop = entry.getPosition()-(firstChild.getPosition()-firstChild.getTotalMarginTop());
|
||||
board.setNodeChildrenMarginTop(entry,marginTop);
|
||||
var lastChild = table[table.length-1];
|
||||
var marginBottom = (lastChild.getPosition()+lastChild.getTotalMarginBottom())-entry.getPosition();
|
||||
board.setNodeChildrenMarginBottom(entry,marginBottom);
|
||||
} else {
|
||||
board.setNodeChildrenMarginTop(entry, 0);
|
||||
board.setNodeChildrenMarginBottom(entry, 0);
|
||||
}
|
||||
}
|
||||
var targetBoard = this.getTopicBoardForTopic(targetNode);
|
||||
var table = targetBoard._getTableForNode(node);
|
||||
var index;
|
||||
if(node.relationship == 'undo'){
|
||||
index = node._relationship_index;
|
||||
//I need to update all entries because nodes position have been changed by command
|
||||
|
||||
}else{
|
||||
if(node.relationship == "Child"){
|
||||
|
||||
var newNodePos=new core.Point();
|
||||
if(table.length>0){
|
||||
//if no children use the position set by Entry initializer. Otherwise place as last child
|
||||
var lastChild = table[table.length-1];
|
||||
newNodePos.y = lastChild.getPosition()+lastChild.getTotalMarginBottom() + entry.getTotalMarginTop();
|
||||
} else {
|
||||
newNodePos.y = targetNode.getPosition().y;
|
||||
}
|
||||
var parentPos = targetNode.getPosition();
|
||||
var pwidth = targetNode.getSize().width;
|
||||
var width = node.getSize().width;
|
||||
if(this._isCentralTopic(targetNode)){
|
||||
newNodePos.x = Math.sign(node.getPosition().x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2)
|
||||
}
|
||||
else{
|
||||
newNodePos.x = parentPos.x + Math.sign(parentPos.x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2);
|
||||
}
|
||||
|
||||
index = table.length;
|
||||
} else {
|
||||
//moving as sibling of targetNode
|
||||
|
||||
var sibObj = targetBoard.findNodeEntryIndex(node._relationship_sibling_node);
|
||||
var siblingEntry =sibObj.table[sibObj.index];
|
||||
|
||||
var newNodePos=new core.Point();
|
||||
if(node.relationship == "Sibling_top"){
|
||||
if(sibObj.index==0){
|
||||
newNodePos.y = siblingEntry.getPosition();
|
||||
}else{
|
||||
newNodePos.y =siblingEntry.getPosition()-siblingEntry.getTotalMarginTop()+entry.getTotalMarginTop();
|
||||
}
|
||||
index = sibObj.index;
|
||||
}
|
||||
else{
|
||||
newNodePos.y = siblingEntry.getPosition()+siblingEntry.getTotalMarginBottom() + entry.getTotalMarginTop();
|
||||
index = sibObj.index+1;
|
||||
}
|
||||
var parentPos = targetNode.getPosition();
|
||||
var pwidth = targetNode.getSize().width;
|
||||
var width = node.getSize().width;
|
||||
if(this._isCentralTopic(targetNode)){
|
||||
newNodePos.x = Math.sign(node.getPosition().x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2)
|
||||
}
|
||||
else{
|
||||
newNodePos.x = parentPos.x + Math.sign(parentPos.x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2);
|
||||
}
|
||||
}
|
||||
var nodePos = node.getPosition();
|
||||
var x = nodePos.x - newNodePos.x;
|
||||
var y = nodePos.y - newNodePos.y;
|
||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||
entry.setPosition(newNodePos.x, newNodePos.y);
|
||||
this._updateChildrenBoards(node, delta, []);
|
||||
}
|
||||
targetBoard._addEntry(entry, table, index);
|
||||
targetBoard._updateTable(index, table, [], true);
|
||||
this._updateBoard(targetNode,[]);
|
||||
if(node._relationship_oldParent!=null)
|
||||
this._updateBoard(node._relationship_oldParent,[]);
|
||||
|
||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent,[node ]);
|
||||
},
|
||||
_addToModifiedList:function(modifiedTopics, key, originalpos, newPos){
|
||||
if($defined(modifiedTopics.set)){
|
||||
if(modifiedTopics.has(key)){
|
||||
originalpos = modifiedTopics.get(key).originalPos;
|
||||
}
|
||||
modifiedTopics.set(key,{originalPos:originalpos, newPos:newPos});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.layout.FreeMindLayoutManager.NAME ="FreeMindLayoutManager";
|
||||
mindplot.layout.FreeMindLayoutManager.MOVE_IMAGE_URL = "../images/move.png";
|
||||
mindplot.layout.FreeMindLayoutManager.RECONNECT_NODES_OPACITY = 0.4;
|
||||
mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_CHILD = "child";
|
||||
mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_SIBLING_TOP = "top";
|
||||
mindplot.layout.FreeMindLayoutManager.RECONNECT_SHAPE_SIBLING_BOTTOM = "bottom";
|
@ -1,194 +0,0 @@
|
||||
mindplot.layout.boards.freemind = {};
|
||||
|
||||
mindplot.layout.boards.freemind.Board = mindplot.layout.boards.Board.extend({
|
||||
options:{
|
||||
|
||||
},
|
||||
initialize:function(node, layoutManager, options){
|
||||
this.parent(node, layoutManager, options);
|
||||
this._positionTables = this._createTables();
|
||||
},
|
||||
_createTables:function(){
|
||||
$assert(false, "no Board implementation found!")
|
||||
},
|
||||
_getTableForNode:function(node, position){
|
||||
$assert(false, "no Board implementation found!")
|
||||
},
|
||||
removeTopicFromBoard:function(node, modifiedTopics){
|
||||
var pos;
|
||||
if($defined(node._originalPosition))
|
||||
pos = node._originalPosition;
|
||||
var result = this.findNodeEntryIndex(node, pos);
|
||||
$assert(result.index<result.table.length,"node not found. Could not remove");
|
||||
this._removeEntry(node, result.table, result.index, modifiedTopics);
|
||||
},
|
||||
addBranch:function(node,modifiedTopics){
|
||||
var pos = (this._layoutManager._isMovingNode?node.getPosition():node.getModel().getFinalPosition() || node.getPosition());
|
||||
var entry = new mindplot.layout.boards.freemind.Entry(node, !this._layoutManager._isMovingNode);
|
||||
var result = this.findNewNodeEntryIndex(entry);
|
||||
|
||||
// if creating a sibling or child
|
||||
if(!this._layoutManager._isMovingNode && this._layoutManager.getDesigner().filterSelectedTopics().length>0){
|
||||
var selectedNode = this._layoutManager.getDesigner().filterSelectedTopics()[0];
|
||||
if(!$defined(pos)){
|
||||
if(selectedNode.getParent()!= null && node.getParent().getId() == selectedNode.getParent().getId()){
|
||||
//creating a sibling - Lets put the new node below the selected node.
|
||||
var parentBoard = this._layoutManager.getTopicBoardForTopic(selectedNode.getParent());
|
||||
var selectedNodeResult = parentBoard.findNodeEntryIndex(selectedNode);
|
||||
var selectedNodeEntry = selectedNodeResult.table[selectedNodeResult.index];
|
||||
var x = null;
|
||||
if(this._layoutManager._isCentralTopic(selectedNode.getParent())){
|
||||
var nodeX = entry.getNode().getPosition().x;
|
||||
if(Math.sign(nodeX)!=Math.sign(selectedNode.getPosition().x)){
|
||||
x =nodeX *-1;
|
||||
}
|
||||
result.table = selectedNodeResult.table;
|
||||
}
|
||||
entry.setPosition(x, selectedNodeEntry.getPosition()+selectedNodeEntry.getTotalMarginBottom() + entry.getMarginTop());
|
||||
result.index = selectedNodeResult.index+1;
|
||||
} else if(node.getParent().getId() == selectedNode.getId()){
|
||||
//creating a child node - Lest put the new node as the last child.
|
||||
var selectedNodeBoard = this._layoutManager.getTopicBoardForTopic(selectedNode);
|
||||
var table = selectedNodeBoard._getTableForNode(node);
|
||||
if(table.length>0){
|
||||
//if no children use the position set by Entry initializer. Otherwise place as last child
|
||||
var lastChild = table[table.length-1];
|
||||
entry.setPosition(null, lastChild.getPosition()+lastChild.getTotalMarginBottom() + entry.getMarginTop());
|
||||
}
|
||||
result.index = table.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._addEntry(entry, result.table, result.index);
|
||||
if($defined(pos)){
|
||||
if(result.index>0){
|
||||
var prevEntry =result.table[result.index-1];
|
||||
entry.setMarginTop(pos.y-(prevEntry.getPosition() + prevEntry.getTotalMarginBottom()));
|
||||
}
|
||||
else if(result.table.length>1){
|
||||
var nextEntry = result.table[1];
|
||||
nextEntry.setMarginTop((nextEntry.getPosition() - nextEntry.getTotalMarginTop())-pos.y);
|
||||
}
|
||||
}
|
||||
this._updateTable(result.index, result.table,modifiedTopics, false);
|
||||
this._layoutManager._updateParentBoard(node, modifiedTopics);
|
||||
},
|
||||
_removeEntry:function(node, table, index, modifiedTopics){
|
||||
table.splice(index, 1);
|
||||
this._updateTable(index>0?index-1:index, table, modifiedTopics, false);
|
||||
},
|
||||
_addEntry:function(entry, table, index){
|
||||
table.splice(index, 0, entry);
|
||||
},
|
||||
_updateTable:function(index, table, modifiedTopics, updateParents){
|
||||
var i = index;
|
||||
if(index >= table.length){
|
||||
i = table.length -1;
|
||||
}
|
||||
var delta = null;
|
||||
//check from index to 0;
|
||||
if(i>0){
|
||||
var entry = table[i];
|
||||
var prevEntry = table[i-1];
|
||||
|
||||
var margin = entry.getTotalMarginTop() + prevEntry.getTotalMarginBottom();
|
||||
var distance = Math.abs(prevEntry.getPosition() - entry.getPosition());
|
||||
if(distance!=margin){
|
||||
delta = (distance - margin)*Math.sign(prevEntry.getPosition() - entry.getPosition());
|
||||
i--;
|
||||
while(i >= 0){
|
||||
this._updateEntryPos(table[i], new core.Point(null, delta), modifiedTopics, updateParents);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i = index;
|
||||
delta = null;
|
||||
|
||||
//check from index to length
|
||||
if( i<table.length-1){
|
||||
entry = table[i];
|
||||
var nextEntry = table[i+1];
|
||||
var margin = entry.getTotalMarginBottom() + nextEntry.getTotalMarginTop();
|
||||
var distance = Math.abs(entry.getPosition() - nextEntry.getPosition());
|
||||
if(distance!=margin){
|
||||
delta = (distance - margin)*Math.sign(nextEntry.getPosition() - entry.getPosition());
|
||||
i++;
|
||||
while(i<table.length){
|
||||
this._updateEntryPos(table[i], new core.Point(null, delta), modifiedTopics, updateParents);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
updateChildrenPosition:function(node, modifiedTopics){
|
||||
var result = this.findNodeEntryIndex(node);
|
||||
this._updateTable(result.index, result.table, modifiedTopics, false);
|
||||
},
|
||||
findNodeEntryIndex:function(node, position){
|
||||
var table = this._getTableForNode(node, position);
|
||||
|
||||
//search for position
|
||||
var i;
|
||||
for(i = 0; i< table.length ; i++){
|
||||
var entry = table[i];
|
||||
if (entry.getNode().getId() == node.getId()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {index:i, table:table};
|
||||
},
|
||||
findNewNodeEntryIndex:function(entry){
|
||||
var table = this._getTableForNode(entry.getNode());
|
||||
var position = entry.getPosition();
|
||||
//search for position
|
||||
var i;
|
||||
for(i = 0; i< table.length ; i++){
|
||||
var tableEntry = table[i];
|
||||
if (tableEntry.getPosition() > position){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {index:i, table:table};
|
||||
},
|
||||
setNodeMarginTop:function(entry, delta){
|
||||
var marginTop = entry.getMarginTop()-delta.y;
|
||||
entry.setMarginTop(marginTop);
|
||||
},
|
||||
setNodeMarginBottom:function(entry, delta){
|
||||
var marginBottom = entry.getMarginBottom()-delta.y;
|
||||
entry.setMarginBottom(marginBottom);
|
||||
},
|
||||
setNodeChildrenMarginTop:function(entry, delta){
|
||||
entry.setChildrenMarginTop(delta);
|
||||
},
|
||||
setNodeChildrenMarginBottom:function(entry, delta){
|
||||
entry.setChildrenMarginBottom(delta);
|
||||
},
|
||||
updateEntry:function(node, delta, modifiedTopics){
|
||||
var result = this.findNodeEntryIndex(node);
|
||||
if(result.index < result.table.length){
|
||||
var entry = result.table[result.index];
|
||||
if(result.index!=0)
|
||||
this.setNodeMarginTop(entry, delta);
|
||||
this._updateEntryPos(entry, delta, modifiedTopics, false);
|
||||
this._updateTable(result.index, result.table, modifiedTopics, false);
|
||||
this._layoutManager._updateParentBoard(entry.getNode(), modifiedTopics);
|
||||
}
|
||||
},
|
||||
_updateEntryPos:function(entry, delta, modifiedTopics, updateParents){
|
||||
var pos = entry.getNode().getPosition().clone();
|
||||
var newPos = new core.Point(pos.x-(delta.x==null?0:delta.x), pos.y-delta.y);
|
||||
entry.setPosition(newPos.x, newPos.y);
|
||||
this._layoutManager._updateChildrenBoards(entry.getNode(), delta, modifiedTopics);
|
||||
if($defined(modifiedTopics.set)){
|
||||
var key = entry.getId();
|
||||
if(modifiedTopics.has(key)){
|
||||
pos = modifiedTopics.get(key).originalPos;
|
||||
}
|
||||
modifiedTopics.set(key,{originalPos:pos, newPos:newPos});
|
||||
}
|
||||
}
|
||||
});
|
@ -1,27 +0,0 @@
|
||||
mindplot.layout.boards.freemind.CentralTopicBoard = mindplot.layout.boards.freemind.Board.extend({
|
||||
options:{
|
||||
|
||||
},
|
||||
initialize:function(node, layoutManager, options){
|
||||
this.parent(node, layoutManager, options);
|
||||
},
|
||||
_createTables:function(){
|
||||
return [[],[]];
|
||||
},
|
||||
_getTableForNode:function(node, altPosition){
|
||||
var i = 0;
|
||||
var position = node.getPosition();
|
||||
if(typeof altPosition != "undefined" && altPosition!=null)
|
||||
{
|
||||
position = altPosition;
|
||||
}
|
||||
if(!$defined(position)){
|
||||
if(Math.sign(node.getParent().getPosition().x) == -1){
|
||||
i=1;
|
||||
}
|
||||
}
|
||||
else if(Math.sign(position.x)==-1)
|
||||
i=1;
|
||||
return this._positionTables[i];
|
||||
}
|
||||
});
|
@ -1,89 +0,0 @@
|
||||
mindplot.layout.boards.freemind.Entry = new Class({
|
||||
initialize:function(node, useFinalPosition){
|
||||
this._node = node;
|
||||
this._DEFAULT_X_GAP = 30;
|
||||
var pos = node.getModel().getFinalPosition();
|
||||
if(useFinalPosition && $defined(pos)){
|
||||
this.setPosition(pos.x, pos.y);
|
||||
}
|
||||
else{
|
||||
pos = node.getPosition();
|
||||
if(!$defined(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);
|
||||
|
||||
}
|
||||
}
|
||||
this._DEFAULT_GAP = 10;
|
||||
var height = this.getNode().getSize().height;
|
||||
this._minimalMargin = this._DEFAULT_GAP + height/2;
|
||||
this._marginTop = this._minimalMargin;
|
||||
this._marginBottom = this._minimalMargin;
|
||||
this._marginTopChildren=0;
|
||||
this._marginBottomChildren=0;
|
||||
},
|
||||
getNode:function(){
|
||||
return this._node;
|
||||
},
|
||||
getId:function(){
|
||||
return this.getNode().getId();
|
||||
},
|
||||
getPosition:function(){
|
||||
return this._node.getPosition().y;
|
||||
},
|
||||
setPosition:function(x,y){
|
||||
var position = this._node.getPosition().clone();
|
||||
position.y = y;
|
||||
if(null != x){
|
||||
position.x = x;
|
||||
}
|
||||
|
||||
this._node.setPosition(position);
|
||||
},
|
||||
getMarginTop:function(){
|
||||
return this._marginTop;
|
||||
},
|
||||
setMarginTop:function(value){
|
||||
if(value >= this._minimalMargin){
|
||||
this._marginTop = value;
|
||||
}
|
||||
},
|
||||
setMarginBottom:function(value){
|
||||
if(value >= this._minimalMargin){
|
||||
this._marginBottom = value;
|
||||
}
|
||||
},
|
||||
getMarginBottom:function(){
|
||||
return this._marginBottom;
|
||||
},
|
||||
getChildrenMarginTop:function(){
|
||||
return this._marginTopChildren;
|
||||
},
|
||||
setChildrenMarginTop:function(value){
|
||||
if(value >= this._minimalMargin){
|
||||
this._marginTopChildren = value - this._minimalMargin;
|
||||
}else{
|
||||
this._marginTopChildren=0;
|
||||
}
|
||||
},
|
||||
setChildrenMarginBottom:function(value){
|
||||
if(value >= this._minimalMargin){
|
||||
this._marginBottomChildren = value - this._minimalMargin;
|
||||
}else{
|
||||
this._marginBottomChildren=0;
|
||||
}
|
||||
},
|
||||
getChildrenMarginBottom:function(){
|
||||
return this._marginBottomChildren;
|
||||
},
|
||||
getTotalMarginTop:function(){
|
||||
return (this._node.areChildrenShrinked()?0:this._marginTopChildren)+this._marginTop;
|
||||
},
|
||||
getTotalMarginBottom:function(){
|
||||
return (this._node.areChildrenShrinked()?0:this._marginBottomChildren) + this._marginBottom;
|
||||
}
|
||||
});
|
@ -1,14 +0,0 @@
|
||||
mindplot.layout.boards.freemind.MainTopicBoard = mindplot.layout.boards.freemind.Board.extend({
|
||||
options:{
|
||||
|
||||
},
|
||||
initialize:function(node, layoutManager, options){
|
||||
this.parent(node, layoutManager, options);
|
||||
},
|
||||
_createTables:function(){
|
||||
return [[]];
|
||||
},
|
||||
_getTableForNode:function(node){
|
||||
return this._positionTables[0];
|
||||
}
|
||||
});
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.ChangeEvent = new Class({
|
||||
initialize:function(id) {
|
||||
$assert(!isNaN(id), "id can not be null");
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.ChildrenSorterStrategy = new Class({
|
||||
initialize:function() {
|
||||
|
||||
|
41
mindplot/src/main/javascript/nlayout/EventBus.js
Normal file
41
mindplot/src/main/javascript/nlayout/EventBus.js
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.EventBus = new Class({
|
||||
Implements:Events,
|
||||
initialize: function() {
|
||||
}
|
||||
});
|
||||
|
||||
mindplot.EventBus.events = {
|
||||
NodeResizeEvent:'NodeResizeEvent',
|
||||
NodeMoveEvent:'NodeMoveEvent',
|
||||
ONodeDisconnectEvent:'ONodeDisconnectEvent',
|
||||
ONodeConnectEvent:'ONodeConnectEvent',
|
||||
NodeRepositionateEvent:'NodeRepositionateEvent',
|
||||
NodeShrinkEvent:'NodeShrinkEvent',
|
||||
NodeMouseOverEvent:'NodeMouseOverEvent',
|
||||
NodeMouseOutEvent:'NodeMouseOutEvent',
|
||||
|
||||
NodeConnectEvent:'NodeConnectEvent',
|
||||
NodeDisconnectEvent:'NodeDisconnectEvent',
|
||||
NodeAdded:'NodeAdded',
|
||||
NodeRemoved:'NodeRemoved',
|
||||
DoLayout:'DoLayout'
|
||||
};
|
||||
|
||||
mindplot.EventBus.instance = new mindplot.EventBus();
|
86
mindplot/src/main/javascript/nlayout/EventBusDispatcher.js
Normal file
86
mindplot/src/main/javascript/nlayout/EventBusDispatcher.js
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.EventBusDispatcher = new Class({
|
||||
|
||||
initialize:function(designerModel) {
|
||||
$assert(designerModel, "designerModel cannot be null");
|
||||
this.registerBusEvents();
|
||||
|
||||
var size = {width:25,height:25};
|
||||
this._layoutManager = new mindplot.nlayout.LayoutManager(0, size);
|
||||
},
|
||||
|
||||
registerBusEvents:function () {
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeAdded, this._nodeAdded.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRemoved, this._nodeRemoved.bind(this));
|
||||
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));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
|
||||
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.DoLayout, this._doLayout.bind(this));
|
||||
},
|
||||
|
||||
_nodeResizeEvent: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeResizeEvent: Not Implemented yet");
|
||||
},
|
||||
|
||||
_nodeMoveEvent: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeMoveEvent: Not Implemented yet");
|
||||
|
||||
},
|
||||
|
||||
_nodeDisconnectEvent: function(node) {
|
||||
this._layoutManager.disconnectNode(node.getId());
|
||||
},
|
||||
|
||||
_nodeConnectEvent: function(args) {
|
||||
this._layoutManager.connectNode(args.parentNode.getId(), args.childNode.getId(), args.childNode.getOrder());
|
||||
|
||||
},
|
||||
|
||||
_nodeRepositionateEvent: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeRepositionateEvent: Not Implemented yet");
|
||||
|
||||
},
|
||||
|
||||
_nodeShrinkEvent: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeShrinkEvent: Not Implemented yet");
|
||||
},
|
||||
|
||||
_nodeAdded: function(node) {
|
||||
// Centra topic must not be added twice ...
|
||||
if (node.getId() != 0) {
|
||||
this._layoutManager.addNode(node.getId(), {width:10,height:10}, node.getPosition());
|
||||
}
|
||||
},
|
||||
|
||||
_nodeRemoved: function(node) {
|
||||
console.log("mindplot.nlayout.EventBusDispatcher._nodeRemoved: Not Implemented yet");
|
||||
},
|
||||
|
||||
_doLayout: function() {
|
||||
this._layoutManager.layout(true);
|
||||
console.log("---------");
|
||||
this._layoutManager.dump();
|
||||
console.log("---------");
|
||||
|
||||
}
|
||||
|
||||
});
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.GridSorter = new Class({
|
||||
Extends: mindplot.nlayout.SymetricSorter,
|
||||
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.LayoutManager = new Class({
|
||||
Extends: Events,
|
||||
initialize: function(rootNodeId, rootSize) {
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.Node = new Class({
|
||||
initialize:function(id, size, position, sorter) {
|
||||
$assert(typeof id === 'number' && isFinite(id), "id can not be null");
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.OriginalLayout = new Class({
|
||||
initialize: function(treeSet) {
|
||||
this._treeSet = treeSet;
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.RootedTreeSet = new Class({
|
||||
initialize:function() {
|
||||
this._rootNodes = [];
|
||||
@ -19,10 +36,12 @@ mindplot.nlayout.RootedTreeSet = new Class({
|
||||
|
||||
add: function(node) {
|
||||
$assert(node, 'node can not be null');
|
||||
$assert(!this.find(node.getId(), false), 'node already exits with this id. Id:' + node.getId());
|
||||
$assert(!node._children, 'node already added');
|
||||
this._rootNodes.push(this._decodate(node));
|
||||
},
|
||||
|
||||
|
||||
remove: function(nodeId) {
|
||||
$assert($defined(nodeId), 'nodeId can not be null');
|
||||
var node = this.find(nodeId);
|
||||
@ -64,7 +83,8 @@ mindplot.nlayout.RootedTreeSet = new Class({
|
||||
break;
|
||||
}
|
||||
}
|
||||
$assert($defined(validate) ? result : true, 'node could not be found id:' + id);
|
||||
validate = !$defined(validate) ? true : validate;
|
||||
$assert(validate ? result : true, 'node could not be found id:' + id);
|
||||
return result;
|
||||
|
||||
},
|
||||
@ -120,7 +140,7 @@ mindplot.nlayout.RootedTreeSet = new Class({
|
||||
|
||||
plot: function(canvas) {
|
||||
var branches = this._rootNodes;
|
||||
for (var i=0; i<branches.length; i++) {
|
||||
for (var i = 0; i < branches.length; i++) {
|
||||
var branch = branches[i];
|
||||
this._plot(canvas, branch);
|
||||
}
|
||||
@ -128,19 +148,23 @@ mindplot.nlayout.RootedTreeSet = new Class({
|
||||
|
||||
_plot: function(canvas, node, root) {
|
||||
var children = this.getChildren(node);
|
||||
var cx = node.getPosition().x + canvas.width/2 - node.getSize().width/2;
|
||||
var cy = node.getPosition().y + canvas.height/2 - node.getSize().height/2;
|
||||
var cx = node.getPosition().x + canvas.width / 2 - node.getSize().width / 2;
|
||||
var cy = node.getPosition().y + canvas.height / 2 - node.getSize().height / 2;
|
||||
var rect = canvas.rect(cx, cy, node.getSize().width, node.getSize().height);
|
||||
var order = node.getOrder() == null ? "r" : node.getOrder();
|
||||
var text = canvas.text(node.getPosition().x + canvas.width/2, node.getPosition().y + canvas.height/2, node.getId() + "[" + order + "]");
|
||||
var text = canvas.text(node.getPosition().x + canvas.width / 2, node.getPosition().y + canvas.height / 2, node.getId() + "[" + order + "]");
|
||||
text.attr('fill', '#FFF');
|
||||
var fillColor = this._rootNodes.contains(node) ? "#000" : "#c00";
|
||||
rect.attr('fill', fillColor);
|
||||
|
||||
rect.click(function() {console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position: {" + node.getPosition().x + "," + node.getPosition().y + "}, size: {" + node.getSize().width + "," + node.getSize().height + "}");});
|
||||
text.click(function() {console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position: {" + node.getPosition().x + "," + node.getPosition().y + "}, size: {" + node.getSize().width + "," + node.getSize().height + "}");});
|
||||
rect.click(function() {
|
||||
console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position: {" + node.getPosition().x + "," + node.getPosition().y + "}, size: {" + node.getSize().width + "," + node.getSize().height + "}");
|
||||
});
|
||||
text.click(function() {
|
||||
console.log("[id:" + node.getId() + ", order:" + node.getOrder() + ", position: {" + node.getPosition().x + "," + node.getPosition().y + "}, size: {" + node.getSize().width + "," + node.getSize().height + "}");
|
||||
});
|
||||
|
||||
for (var i=0; i<children.length; i++) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
this._plot(canvas, child);
|
||||
}
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.SymetricSorter = new Class({
|
||||
Extends: mindplot.nlayout.ChildrenSorterStrategy,
|
||||
initialize:function() {
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
mindplot.nlayout.TestSuite = new Class({
|
||||
Extends: mindplot.nlayout.ChildrenSorterStrategy,
|
||||
initialize:function() {
|
||||
|
Loading…
Reference in New Issue
Block a user