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

@ -16,24 +16,21 @@
* limitations under the License.
*/
mindplot.DragManager = function(workspace)
{
mindplot.DragManager = new Class({
initialize:function(workspace) {
this._workspace = workspace;
this._listeners = {};
};
},
mindplot.DragManager.prototype.add = function(node)
{
add : function(node) {
// Add behaviour ...
var workspace = this._workspace;
var screen = workspace.getScreenManager();
var dragManager = this;
var mouseDownListener = function(event)
{
if (workspace.isWorkspaceEventsEnabled())
{
var mouseDownListener = function(event) {
if (workspace.isWorkspaceEventsEnabled()) {
// Disable double drag...
workspace.enableWorkspaceEvents(false);
@ -59,10 +56,9 @@ mindplot.DragManager.prototype.add = function(node)
}
};
node.addEvent('mousedown', mouseDownListener);
};
},
mindplot.DragManager.prototype.remove = function(node)
{
remove : function(node) {
var nodes = this._topics;
var contained = false;
var index = -1;
@ -72,15 +68,13 @@ mindplot.DragManager.prototype.remove = function(node)
index = i;
}
}
};
},
mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dragNode, dragManager)
{
_buildMouseMoveListener : function(workspace, dragNode, dragManager) {
var screen = workspace.getScreenManager();
var result = function(event) {
if (!dragNode._isInTheWorkspace)
{
if (!dragNode._isInTheWorkspace) {
// Add shadow node to the workspace.
workspace.appendChild(dragNode);
dragNode._isInTheWorkspace = true;
@ -91,8 +85,7 @@ mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dra
// Call mouse move listeners ...
var dragListener = dragManager._listeners['dragging'];
if ($defined(dragListener))
{
if ($defined(dragListener)) {
dragListener(event, dragNode);
}
@ -101,10 +94,9 @@ mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dra
}.bind(this);
dragManager._mouseMoveListener = result;
return result;
};
},
mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, dragNode, dragManager)
{
_buildMouseUpListener : function(workspace, node, dragNode, dragManager) {
var screen = workspace.getScreenManager();
var result = function(event) {
@ -112,8 +104,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
// Remove drag node from the workspace.
var hasBeenDragged = dragNode._isInTheWorkspace;
if (dragNode._isInTheWorkspace)
{
if (dragNode._isInTheWorkspace) {
dragNode.removeFromWorkspace(workspace);
}
@ -129,8 +120,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
var endDragListener = dragManager._listeners['enddragging'];
endDragListener(event, dragNode);
if (hasBeenDragged)
{
if (hasBeenDragged) {
dragNode._isInTheWorkspace = false;
}
@ -142,7 +132,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
};
dragManager._mouseUpListener = result;
return result;
};
},
/**
* type:
@ -150,7 +140,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
* - dragging
* - enddragging
*/
mindplot.DragManager.prototype. addEvent = function(type, listener)
{
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,15 +144,16 @@ 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();
if (!this.isFreeLayoutOn()) {
var order = null;
var parent = null;
var isDragConnected = this.isConnected();
if (isDragConnected) {
var targetTopic = this.getConnectedToTopic();
order = this._order;
@ -155,8 +161,10 @@ mindplot.DragTopic = new Class({
}
// If the node is not connected, position based on the original drag topic position.
actionDispatcher.dragTopic(topicId, dragPosition, order, parent);
actionDispatcher.dragTopic(topicId, position, order, parent);
} else {
actionDispatcher.moveTopic(topicId, position);
}
},
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");