Add Free position integration...

main
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."; throw "method must be implemented.";
}, },
moveTopic: function(topicId, position) {
throw "method must be implemented.";
},
moveControlPoint: function(ctrlPoint, point) { moveControlPoint: function(ctrlPoint, point) {
throw "method must be implemented."; throw "method must be implemented.";
}, },

View File

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

View File

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

View File

@ -16,24 +16,21 @@
* limitations under the License. * limitations under the License.
*/ */
mindplot.DragManager = function(workspace) mindplot.DragManager = new Class({
{ initialize:function(workspace) {
this._workspace = workspace; this._workspace = workspace;
this._listeners = {}; this._listeners = {};
}; },
mindplot.DragManager.prototype.add = function(node) add : function(node) {
{
// Add behaviour ... // Add behaviour ...
var workspace = this._workspace; var workspace = this._workspace;
var screen = workspace.getScreenManager(); var screen = workspace.getScreenManager();
var dragManager = this; var dragManager = this;
var mouseDownListener = function(event) var mouseDownListener = function(event) {
{ if (workspace.isWorkspaceEventsEnabled()) {
if (workspace.isWorkspaceEventsEnabled())
{
// Disable double drag... // Disable double drag...
workspace.enableWorkspaceEvents(false); workspace.enableWorkspaceEvents(false);
@ -59,10 +56,9 @@ mindplot.DragManager.prototype.add = function(node)
} }
}; };
node.addEvent('mousedown', mouseDownListener); node.addEvent('mousedown', mouseDownListener);
}; },
mindplot.DragManager.prototype.remove = function(node) remove : function(node) {
{
var nodes = this._topics; var nodes = this._topics;
var contained = false; var contained = false;
var index = -1; var index = -1;
@ -72,15 +68,13 @@ mindplot.DragManager.prototype.remove = function(node)
index = i; index = i;
} }
} }
}; },
mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dragNode, dragManager) _buildMouseMoveListener : function(workspace, dragNode, dragManager) {
{
var screen = workspace.getScreenManager(); var screen = workspace.getScreenManager();
var result = function(event) { var result = function(event) {
if (!dragNode._isInTheWorkspace) if (!dragNode._isInTheWorkspace) {
{
// Add shadow node to the workspace. // Add shadow node to the workspace.
workspace.appendChild(dragNode); workspace.appendChild(dragNode);
dragNode._isInTheWorkspace = true; dragNode._isInTheWorkspace = true;
@ -91,8 +85,7 @@ mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dra
// Call mouse move listeners ... // Call mouse move listeners ...
var dragListener = dragManager._listeners['dragging']; var dragListener = dragManager._listeners['dragging'];
if ($defined(dragListener)) if ($defined(dragListener)) {
{
dragListener(event, dragNode); dragListener(event, dragNode);
} }
@ -101,10 +94,9 @@ mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dra
}.bind(this); }.bind(this);
dragManager._mouseMoveListener = result; dragManager._mouseMoveListener = result;
return result; return result;
}; },
mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, dragNode, dragManager) _buildMouseUpListener : function(workspace, node, dragNode, dragManager) {
{
var screen = workspace.getScreenManager(); var screen = workspace.getScreenManager();
var result = function(event) { var result = function(event) {
@ -112,8 +104,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
// Remove drag node from the workspace. // Remove drag node from the workspace.
var hasBeenDragged = dragNode._isInTheWorkspace; var hasBeenDragged = dragNode._isInTheWorkspace;
if (dragNode._isInTheWorkspace) if (dragNode._isInTheWorkspace) {
{
dragNode.removeFromWorkspace(workspace); dragNode.removeFromWorkspace(workspace);
} }
@ -129,8 +120,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
var endDragListener = dragManager._listeners['enddragging']; var endDragListener = dragManager._listeners['enddragging'];
endDragListener(event, dragNode); endDragListener(event, dragNode);
if (hasBeenDragged) if (hasBeenDragged) {
{
dragNode._isInTheWorkspace = false; dragNode._isInTheWorkspace = false;
} }
@ -142,7 +132,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
}; };
dragManager._mouseUpListener = result; dragManager._mouseUpListener = result;
return result; return result;
}; },
/** /**
* type: * type:
@ -150,7 +140,7 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node,
* - dragging * - dragging
* - enddragging * - enddragging
*/ */
mindplot.DragManager.prototype. addEvent = function(type, listener) addEvent : function(type, listener) {
{
this._listeners[type] = listener; this._listeners[type] = listener;
}; }
});

View File

@ -25,6 +25,7 @@ mindplot.DragTopic = new Class({
this._order = null; this._order = null;
this._draggedNode = draggedNode; this._draggedNode = draggedNode;
this._position = new core.Point(); this._position = new core.Point();
this._isFreeLayoutEnabled = false;
}, },
setOrder : function(order) { 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() { getInnerShape : function() {
return this._elem2d; return this._elem2d;
}, },
@ -139,15 +144,16 @@ mindplot.DragTopic = new Class({
applyChanges : function(workspace) { applyChanges : function(workspace) {
$assert(workspace, 'workspace can not be null'); $assert(workspace, 'workspace can not be null');
var draggedTopic = this.getDraggedTopic();
var isDragConnected = this.isConnected();
var actionDispatcher = mindplot.ActionDispatcher.getInstance(); var actionDispatcher = mindplot.ActionDispatcher.getInstance();
var draggedTopic = this.getDraggedTopic();
var topicId = draggedTopic.getId(); var topicId = draggedTopic.getId();
var position = this.getPosition();
var dragPosition = this.getPosition(); if (!this.isFreeLayoutOn()) {
var order = null; var order = null;
var parent = null; var parent = null;
var isDragConnected = this.isConnected();
if (isDragConnected) { if (isDragConnected) {
var targetTopic = this.getConnectedToTopic(); var targetTopic = this.getConnectedToTopic();
order = this._order; 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. // 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() { getConnectedToTopic : function() {
@ -166,10 +174,13 @@ mindplot.DragTopic = new Class({
isConnected : function() { isConnected : function() {
return this.getConnectedToTopic() != null; return this.getConnectedToTopic() != null;
},
isFreeLayoutOn: function() {
return this._isFreeLayoutEnabled;
} }
}) });
;
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:6}; mindplot.DragTopic.PIVOT_SIZE = {width:50,height:6};

View File

@ -63,6 +63,19 @@ mindplot.StandaloneActionDispatcher = new Class({
this.execute(command); 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) { moveControlPoint: function(ctrlPoint, point) {
var command = new mindplot.commands.MoveControlPointCommand(ctrlPoint, point); var command = new mindplot.commands.MoveControlPointCommand(ctrlPoint, point);
this.execute(command); this.execute(command);

View File

@ -985,23 +985,24 @@ mindplot.Topic = new Class({
outerShape.setSize(size.width + 4, size.height + 6); outerShape.setSize(size.width + 4, size.height + 6);
innerShape.setSize(parseInt(size.width), parseInt(size.height)); 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) { setSize : function(size) {
var oldSize = this.getSize(); var oldSize = this.getSize();
if (parseInt(oldSize.width) != parseInt(size.width) || parseInt(oldSize.height) != parseInt(size.height)) { if (parseInt(oldSize.width) != parseInt(size.width) || parseInt(oldSize.height) != parseInt(size.height)) {
this._setSize(size); 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) { _updatePositionOnChangeSize : function(oldSize, newSize) {
$assert(false, "this method must be overrited"); $assert(false, "this method must be overwrited.");
}, },
disconnect : function(workspace) { disconnect : function(workspace) {

View File

@ -24,7 +24,6 @@ mindplot.EventBus = new Class({
mindplot.EventBus.events = { mindplot.EventBus.events = {
NodeResizeEvent:'NodeResizeEvent', NodeResizeEvent:'NodeResizeEvent',
NodeMoveEvent:'NodeMoveEvent', NodeMoveEvent:'NodeMoveEvent',
NodeRepositionateEvent:'NodeRepositionateEvent',
NodeShrinkEvent:'NodeShrinkEvent', NodeShrinkEvent:'NodeShrinkEvent',
NodeConnectEvent:'NodeConnectEvent', NodeConnectEvent:'NodeConnectEvent',
NodeDisconnectEvent:'NodeDisconnectEvent', 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.NodeMoveEvent, this._nodeMoveEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeDisconnectEvent, this._nodeDisconnectEvent.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.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.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.DoLayout, this._doLayout.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); this._layoutManager.updateNodeSize(args.node.getId(), args.size);
}, },
_nodeMoveEvent: function(node) { _nodeMoveEvent: function(args) {
console.log("mindplot.layout.EventBusDispatcher._nodeMoveEvent: Not Implemented yet"); this._layoutManager.moveNode(args.node.getId(), args.position);
}, },
_nodeDisconnectEvent: function(node) { _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) { _nodeShrinkEvent: function(node) {
this._layoutManager.updateShrinkState(node.getId(), node.areChildrenShrunken()); this._layoutManager.updateShrinkState(node.getId(), node.areChildrenShrunken());
}, },

View File

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