Add Free position integration...

This commit is contained in:
Paulo Veiga 2012-01-18 01:26:39 -03:00
parent aa169f5f49
commit f0eb293211
11 changed files with 194 additions and 186 deletions

View File

@ -51,6 +51,10 @@ mindplot.ActionDispatcher = new Class({
throw "method must be implemented.";
},
moveTopic: function(topicId, position) {
throw "method must be implemented.";
},
moveControlPoint: function(ctrlPoint, point) {
throw "method must be implemented.";
},

View File

@ -129,8 +129,11 @@ mindplot.Designer = new Class({
});
dragger.addEvent('dragging', function(event, dragTopic) {
// Update the state and connections of the topic ...
dragConnector.update(dragTopic);
dragTopic.updateFreeLayout(event);
if (!dragTopic.isFreeLayoutOn(event)) {
// The node is being drag. Is the connection still valid ?
dragConnector.checkConnection(dragTopic);
}
});
dragger.addEvent('enddragging', function(event, dragTopic) {
@ -147,7 +150,6 @@ mindplot.Designer = new Class({
var parentNode = draggedTopic.getParent();
dragTopic.applyChanges(workspace);
// Make all node visible ...
draggedTopic.setVisibility(true);
if (parentNode != null) {

View File

@ -26,12 +26,7 @@ mindplot.DragConnector = new Class({
this._workspace = workspace;
},
update : function(dragTopic) {
// Topic can be connected ?
this._checkConnection(dragTopic);
},
_checkConnection : function(dragTopic) {
checkConnection : function(dragTopic) {
var topics = this._designerModel.getTopics();
// Must be disconnected from their current connection ?.

View File

@ -1,156 +1,146 @@
/*
* 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.
* 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.DragManager = function(workspace)
{
this._workspace = workspace;
this._listeners = {};
mindplot.DragManager = new Class({
initialize:function(workspace) {
this._workspace = workspace;
this._listeners = {};
};
},
mindplot.DragManager.prototype.add = function(node)
{
// Add behaviour ...
var workspace = this._workspace;
var screen = workspace.getScreenManager();
var dragManager = this;
add : function(node) {
// Add behaviour ...
var workspace = this._workspace;
var screen = workspace.getScreenManager();
var dragManager = this;
var mouseDownListener = function(event)
{
if (workspace.isWorkspaceEventsEnabled())
{
// Disable double drag...
workspace.enableWorkspaceEvents(false);
var mouseDownListener = function(event) {
if (workspace.isWorkspaceEventsEnabled()) {
// Disable double drag...
workspace.enableWorkspaceEvents(false);
// Set initial position.
var dragNode = node.createDragNode();
var mousePos = screen.getWorkspaceMousePosition(event);
dragNode.setPosition(mousePos.x, mousePos.y);
// Set initial position.
var dragNode = node.createDragNode();
var mousePos = screen.getWorkspaceMousePosition(event);
dragNode.setPosition(mousePos.x, mousePos.y);
// Register mouse move listener ...
var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager);
screen.addEvent('mousemove', mouseMoveListener);
// Register mouse move listener ...
var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager);
screen.addEvent('mousemove', mouseMoveListener);
// Register mouse up listeners ...
var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager);
screen.addEvent('mouseup', mouseUpListener);
// Register mouse up listeners ...
var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager);
screen.addEvent('mouseup', mouseUpListener);
// Execute Listeners ..
var startDragListener = dragManager._listeners['startdragging'];
startDragListener(event, node);
// Execute Listeners ..
var startDragListener = dragManager._listeners['startdragging'];
startDragListener(event, node);
// Change cursor.
window.document.body.style.cursor = 'move';
// Change cursor.
window.document.body.style.cursor = 'move';
}
};
node.addEvent('mousedown', mouseDownListener);
},
remove : function(node) {
var nodes = this._topics;
var contained = false;
var index = -1;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] == node) {
contained = true;
index = i;
}
}
};
node.addEvent('mousedown', mouseDownListener);
};
},
mindplot.DragManager.prototype.remove = function(node)
{
var nodes = this._topics;
var contained = false;
var index = -1;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] == node) {
contained = true;
index = i;
}
_buildMouseMoveListener : function(workspace, dragNode, dragManager) {
var screen = workspace.getScreenManager();
var result = function(event) {
if (!dragNode._isInTheWorkspace) {
// Add shadow node to the workspace.
workspace.appendChild(dragNode);
dragNode._isInTheWorkspace = true;
}
var pos = screen.getWorkspaceMousePosition(event);
dragNode.setPosition(pos.x, pos.y);
// Call mouse move listeners ...
var dragListener = dragManager._listeners['dragging'];
if ($defined(dragListener)) {
dragListener(event, dragNode);
}
event.preventDefault();
}.bind(this);
dragManager._mouseMoveListener = result;
return result;
},
_buildMouseUpListener : function(workspace, node, dragNode, dragManager) {
var screen = workspace.getScreenManager();
var result = function(event) {
$assert(dragNode.isDragTopic, 'dragNode must be an DragTopic');
// Remove drag node from the workspace.
var hasBeenDragged = dragNode._isInTheWorkspace;
if (dragNode._isInTheWorkspace) {
dragNode.removeFromWorkspace(workspace);
}
// Remove all the events.
screen.removeEvent('mousemove', dragManager._mouseMoveListener);
screen.removeEvent('mouseup', dragManager._mouseUpListener);
// Help GC
dragManager._mouseMoveListener = null;
dragManager._mouseUpListener = null;
// Execute Listeners only if the node has been moved.
var endDragListener = dragManager._listeners['enddragging'];
endDragListener(event, dragNode);
if (hasBeenDragged) {
dragNode._isInTheWorkspace = false;
}
// Change the cursor to the default.
window.document.body.style.cursor = 'default';
workspace.enableWorkspaceEvents(true);
};
dragManager._mouseUpListener = result;
return result;
},
/**
* type:
* - startdragging.
* - dragging
* - enddragging
*/
addEvent : function(type, listener) {
this._listeners[type] = listener;
}
};
mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dragNode, dragManager)
{
var screen = workspace.getScreenManager();
var result = function(event) {
if (!dragNode._isInTheWorkspace)
{
// Add shadow node to the workspace.
workspace.appendChild(dragNode);
dragNode._isInTheWorkspace = true;
}
var pos = screen.getWorkspaceMousePosition(event);
dragNode.setPosition(pos.x, pos.y);
// Call mouse move listeners ...
var dragListener = dragManager._listeners['dragging'];
if ($defined(dragListener))
{
dragListener(event, dragNode);
}
event.preventDefault();
}.bind(this);
dragManager._mouseMoveListener = result;
return result;
};
mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, dragNode, dragManager)
{
var screen = workspace.getScreenManager();
var result = function(event) {
$assert(dragNode.isDragTopic, 'dragNode must be an DragTopic');
// Remove drag node from the workspace.
var hasBeenDragged = dragNode._isInTheWorkspace;
if (dragNode._isInTheWorkspace)
{
dragNode.removeFromWorkspace(workspace);
}
// Remove all the events.
screen.removeEvent('mousemove', dragManager._mouseMoveListener);
screen.removeEvent('mouseup', dragManager._mouseUpListener);
// Help GC
dragManager._mouseMoveListener = null;
dragManager._mouseUpListener = null;
// Execute Listeners only if the node has been moved.
var endDragListener = dragManager._listeners['enddragging'];
endDragListener(event, dragNode);
if (hasBeenDragged)
{
dragNode._isInTheWorkspace = false;
}
// Change the cursor to the default.
window.document.body.style.cursor = 'default';
workspace.enableWorkspaceEvents(true);
};
dragManager._mouseUpListener = result;
return result;
};
/**
* type:
* - startdragging.
* - dragging
* - enddragging
*/
mindplot.DragManager.prototype. addEvent = function(type, listener)
{
this._listeners[type] = listener;
};
});

View File

@ -25,6 +25,7 @@ mindplot.DragTopic = new Class({
this._order = null;
this._draggedNode = draggedNode;
this._position = new core.Point();
this._isFreeLayoutEnabled = false;
},
setOrder : function(order) {
@ -57,6 +58,10 @@ mindplot.DragTopic = new Class({
}
},
updateFreeLayout: function(event) {
this._isFreeLayoutEnabled = (event.meta && Browser.Platform.mac) || (event.control && !Browser.Platform.mac);
},
getInnerShape : function() {
return this._elem2d;
},
@ -139,24 +144,27 @@ mindplot.DragTopic = new Class({
applyChanges : function(workspace) {
$assert(workspace, 'workspace can not be null');
var draggedTopic = this.getDraggedTopic();
var isDragConnected = this.isConnected();
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
var draggedTopic = this.getDraggedTopic();
var topicId = draggedTopic.getId();
var position = this.getPosition();
var dragPosition = this.getPosition();
var order = null;
var parent = null;
if (isDragConnected) {
var targetTopic = this.getConnectedToTopic();
order = this._order;
parent = targetTopic;
if (!this.isFreeLayoutOn()) {
var order = null;
var parent = null;
var isDragConnected = this.isConnected();
if (isDragConnected) {
var targetTopic = this.getConnectedToTopic();
order = this._order;
parent = targetTopic;
}
// If the node is not connected, position based on the original drag topic position.
actionDispatcher.dragTopic(topicId, position, order, parent);
} else {
actionDispatcher.moveTopic(topicId, position);
}
// If the node is not connected, position based on the original drag topic position.
actionDispatcher.dragTopic(topicId, dragPosition, order, parent);
},
getConnectedToTopic : function() {
@ -166,10 +174,13 @@ mindplot.DragTopic = new Class({
isConnected : function() {
return this.getConnectedToTopic() != null;
},
isFreeLayoutOn: function() {
return this._isFreeLayoutEnabled;
}
})
;
});
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:6};

View File

@ -63,6 +63,19 @@ mindplot.StandaloneActionDispatcher = new Class({
this.execute(command);
},
moveTopic: function(topicId, position) {
$assert($defined(topicId), "topicsId can not be null");
$assert($defined(position), "position can not be null");
var commandFunc = function(topic, value) {
var result = topic.getPosition();
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, {node:topic.getModel(),position:value});
return result;
};
var command = new mindplot.commands.GenericFunctionCommand(commandFunc, topicId, position);
this._actionRunner.execute(command);
},
moveControlPoint: function(ctrlPoint, point) {
var command = new mindplot.commands.MoveControlPointCommand(ctrlPoint, point);
this.execute(command);

View File

@ -985,23 +985,24 @@ mindplot.Topic = new Class({
outerShape.setSize(size.width + 4, size.height + 6);
innerShape.setSize(parseInt(size.width), parseInt(size.height));
// Update the figure position(ej: central topic must be centered) and children position.
var oldSize = this.getSize();
this._updatePositionOnChangeSize(oldSize, size);
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent, {node:this.getModel(),size:size});
},
setSize : function(size) {
var oldSize = this.getSize();
if (parseInt(oldSize.width) != parseInt(size.width) || parseInt(oldSize.height) != parseInt(size.height)) {
this._setSize(size);
// Update the figure position(ej: central topic must be centered) and children position.
this._updatePositionOnChangeSize(oldSize, size);
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent, {node:this.getModel(),size:size});
}
},
_updatePositionOnChangeSize : function(oldSize, newSize) {
$assert(false, "this method must be overrited");
$assert(false, "this method must be overwrited.");
},
disconnect : function(workspace) {

View File

@ -24,7 +24,6 @@ mindplot.EventBus = new Class({
mindplot.EventBus.events = {
NodeResizeEvent:'NodeResizeEvent',
NodeMoveEvent:'NodeMoveEvent',
NodeRepositionateEvent:'NodeRepositionateEvent',
NodeShrinkEvent:'NodeShrinkEvent',
NodeConnectEvent:'NodeConnectEvent',
NodeDisconnectEvent:'NodeDisconnectEvent',

View File

@ -39,7 +39,6 @@ mindplot.layout.EventBusDispatcher = new Class({
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));
},
@ -48,9 +47,8 @@ mindplot.layout.EventBusDispatcher = new Class({
this._layoutManager.updateNodeSize(args.node.getId(), args.size);
},
_nodeMoveEvent: function(node) {
console.log("mindplot.layout.EventBusDispatcher._nodeMoveEvent: Not Implemented yet");
_nodeMoveEvent: function(args) {
this._layoutManager.moveNode(args.node.getId(), args.position);
},
_nodeDisconnectEvent: function(node) {
@ -62,11 +60,6 @@ mindplot.layout.EventBusDispatcher = new Class({
},
_nodeRepositionateEvent: function(node) {
console.log("mindplot.layout.EventBusDispatcher._nodeRepositionateEvent: Not Implemented yet");
},
_nodeShrinkEvent: function(node) {
this._layoutManager.updateShrinkState(node.getId(), node.areChildrenShrunken());
},

View File

@ -51,7 +51,7 @@ mindplot.layout.LayoutManager = new Class({
return this._treeSet.find(id);
},
move: function(id, position) {
moveNode: function(id, position) {
$assert($defined(id), "id cannot be null");
$assert($defined(position), "position cannot be null");
$assert($defined(position.x), "x can not be null");

View File

@ -168,8 +168,8 @@ mindplot.layout.Node = new Class({
},
getVertex: function() {
var a = {x: this.getPosition().x - this.getSize().width/2, y:this.getPosition().y - this.getSize().height/2};
var b = {x: this.getPosition().x + this.getSize().width/2, y:this.getPosition().y + this.getSize().height/2};
var a = {x: this.getPosition().x - this.getSize().width / 2, y:this.getPosition().y - this.getSize().height / 2};
var b = {x: this.getPosition().x + this.getSize().width / 2, y:this.getPosition().y + this.getSize().height / 2};
return {a:a, b:b};
},