From 51bc3e563a4f224effe84dbb87f1d12df77e33ec Mon Sep 17 00:00:00 2001 From: Paulo Veiga Date: Wed, 11 Jan 2012 21:12:22 -0300 Subject: [PATCH] Keyboard actions for adding is working with the new layout... --- mindplot/src/main/javascript/CentralTopic.js | 25 ------- mindplot/src/main/javascript/Designer.js | 75 +++++++++++++++---- .../main/javascript/DragTopicPositioner.js | 15 ++-- mindplot/src/main/javascript/MainTopic.js | 66 +++++----------- mindplot/src/main/javascript/Topic.js | 32 +++++--- .../layout/OriginalLayoutManager.js | 60 --------------- .../src/main/javascript/model/INodeModel.js | 2 + mindplot/src/main/javascript/widget/Menu.js | 1 - 8 files changed, 110 insertions(+), 166 deletions(-) diff --git a/mindplot/src/main/javascript/CentralTopic.js b/mindplot/src/main/javascript/CentralTopic.js index 5f6d6cdc..a8714464 100644 --- a/mindplot/src/main/javascript/CentralTopic.js +++ b/mindplot/src/main/javascript/CentralTopic.js @@ -53,31 +53,6 @@ mindplot.CentralTopic = new Class({ return false; }, - createChildModel : function(prepositionate) { - // Create a new node ... - var model = this.getModel(); - var mindmap = model.getMindmap(); - var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); - - if (prepositionate) { - if (!$defined(this.___siblingDirection)) { - this.___siblingDirection = 1; - } - - // Position following taking into account this internal flag ... - if (this.___siblingDirection == 1) { - - childModel.setPosition(150, 0); - } else { - childModel.setPosition(-150, 0); - } - this.___siblingDirection = -this.___siblingDirection; - } - // Create a new node ... - childModel.setOrder(0); - - return childModel; - }, _defaultShapeType : function() { return mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT; diff --git a/mindplot/src/main/javascript/Designer.js b/mindplot/src/main/javascript/Designer.js index 73bcbe56..43af2941 100644 --- a/mindplot/src/main/javascript/Designer.js +++ b/mindplot/src/main/javascript/Designer.js @@ -43,21 +43,20 @@ mindplot.Designer = new Class({ this._workspace = new mindplot.Workspace(screenManager, this._model.getZoom()); this._readOnly = profile.readOnly ? true : false; - // Register events if (!profile.readOnly) { this._registerEvents(); + + // Init drag related classes ... + this._dragTopicPositioner = new mindplot.DragTopicPositioner(this.getModel(), this._workspace); + this._dragger = this._buildDragManager(this._workspace); + mindplot.DragTopic.init(this._workspace); } 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() { @@ -123,6 +122,51 @@ mindplot.Designer = new Class({ }, + _buildDragManager: function(workspace) { + // Init dragger manager. + var dragger = new mindplot.DragManager(workspace); + var topics = this.getModel().getTopics(); + + var dragTopicPositioner = this._dragTopicPositioner; + + dragger.addEvent('startdragging', function(event, node) { + // Enable all mouse events. + for (var i = 0; i < topics.length; i++) { + topics[i].setMouseEventsEnabled(false); + } + }); + + dragger.addEvent('dragging', function(event, dragTopic) { + // Update the state and connections of the topic ... + dragTopicPositioner.positionateDragTopic(dragTopic); + }); + + dragger.addEvent('enddragging', function(event, dragTopic) { + // Enable all mouse events. + for (var i = 0; i < topics.length; i++) { + topics[i].setMouseEventsEnabled(true); + } + // Topic must be positioned in the real board postion. + if (dragTopic._isInTheWorkspace) { + var draggedTopic = dragTopic.getDraggedTopic(); + + // Hide topic during draw ... + draggedTopic.setBranchVisibility(false); + var parentNode = draggedTopic.getParent(); + dragTopic.updateDraggedTopic(workspace); + + + // Make all node visible ... + draggedTopic.setVisibility(true); + if (parentNode != null) { + parentNode.setBranchVisibility(true); + } + } + }); + + return dragger; + }, + setViewPort : function(size) { this._workspace.setViewPort(size); var model = this.getModel(); @@ -134,20 +178,24 @@ mindplot.Designer = new Class({ // Create node graph ... var topic = mindplot.NodeGraph.create(model); - this._layoutManager.addHelpers(topic); // Append it to the workspace ... this.getModel().addTopic(topic); // Add Topic events ... if (!this._readOnly) { - // Add drag behaviour ... - this._layoutManager.registerListenersOnNode(topic); - // If a node had gained focus, clean the rest of the nodes ... topic.addEvent('mousedown', function(event) { this.onObjectFocusEvent(topic, event); }.bind(this)); + + // Register node listeners ... + if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + + // Central Topic doesn't support to be dragged + var dragger = this._dragger; + dragger.add(topic); + } } // Connect Topic ... @@ -282,7 +330,7 @@ mindplot.Designer = new Class({ // Add new node ... var parentTopic = nodes[0]; var parentTopicId = parentTopic.getId(); - var childModel = parentTopic.createChildModel(this._layoutManager.needsPrepositioning()); + var childModel = parentTopic.createChildModel(); // Execute event ... this._actionDispatcher.addTopic(childModel, parentTopicId, true); @@ -310,7 +358,7 @@ mindplot.Designer = new Class({ } else { var parentTopic = topic.getOutgoingConnectedTopic(); - var siblingModel = topic.createSiblingModel(this._layoutManager.needsPrepositioning()); + var siblingModel = topic.createSiblingModel(); var parentTopicId = parentTopic.getId(); this._actionDispatcher.addTopic(siblingModel, parentTopicId, true); @@ -401,8 +449,7 @@ mindplot.Designer = new Class({ if (isVisible) nodeGraph.setVisibility(isVisible); - var children = nodeModel.getChildren().slice(); - children = this._layoutManager.prepareNode(nodeGraph, children); + var children = nodeModel.getChildren(); var workspace = this._workspace; workspace.appendChild(nodeGraph); diff --git a/mindplot/src/main/javascript/DragTopicPositioner.js b/mindplot/src/main/javascript/DragTopicPositioner.js index 09547192..8842b42f 100644 --- a/mindplot/src/main/javascript/DragTopicPositioner.js +++ b/mindplot/src/main/javascript/DragTopicPositioner.js @@ -17,11 +17,13 @@ */ mindplot.DragTopicPositioner = new Class({ - initialize:function(layoutManager) { - $assert(layoutManager, 'layoutManager can not be null'); - this._layoutManager = layoutManager; - this._topics = layoutManager.getDesigner().getModel().getTopics(); - this._workspace = layoutManager.getDesigner().getWorkSpace(); + initialize:function(designerModel, workspace) { + $assert(designerModel, 'designerModel can not be null'); + $assert(workspace, 'workspace can not be null'); + + // this._layoutManager = layoutManager; + this._designerModel = designerModel; + this._workspace = workspace; }, positionateDragTopic : function(dragTopic) { @@ -71,8 +73,7 @@ mindplot.DragTopicPositioner = new Class({ // Finally, connect nodes ... if (!dragTopic.isConnected()) { var centalTopic = topics[0]; - if ($defined(mainTopicToMainTopicConnection)) - { + if ($defined(mainTopicToMainTopicConnection)) { dragTopic.connectTo(mainTopicToMainTopicConnection); } else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) { dragTopic.connectTo(centalTopic); diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index 0db26dde..a4c8c463 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -24,49 +24,6 @@ mindplot.MainTopic = new Class({ INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid #009900'}, - createSiblingModel : function(positionate) { - var result = null; - var parentTopic = this.getOutgoingConnectedTopic(); - if (parentTopic != null) { - // Create a new node ... - var model = this.getModel(); - var mindmap = model.getMindmap(); - result = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); - - // Positionate following taking into account the sibling position. - if (positionate && parentTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { - var pos = this.getPosition(); - result.setPosition(pos.x, pos.y); - } - - // Create a new node ... - var order = this.getOrder() + 1; - result.setOrder(order); - } - return result; - }, - - createChildModel : function(prepositionate) { - // Create a new node ... - var model = this.getModel(); - var mindmap = model.getMindmap(); - var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); - - // Get the hights model order position ... - var children = this._getChildren(); - var order = -1; - for (var i = 0; i < children.length; i++) { - var child = children[i]; - if (child.getOrder() > order) { - order = child.getOrder(); - } - } - // Create a new node ... - childModel.setOrder(order + 1); - return childModel; - }, - - _buildDragShape : function() { var innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES); var size = this.getSize(); @@ -113,9 +70,6 @@ mindplot.MainTopic = new Class({ this._setShapeType(shapeType, false); } } - this._helpers.forEach(function(helper) { - helper.moveToFront(); - }); }, disconnect : function(workspace) { @@ -274,9 +228,25 @@ mindplot.MainTopic = new Class({ _defaultBorderColor : function() { return '#023BB9'; }, - addSibling : function() { - var order = this.getOrder(); + + // @todo: Removed !!! + createSiblingModel : function() { + var result = null; + var parentTopic = this.getOutgoingConnectedTopic(); + if (parentTopic != null) { + // Create a new node ... + var model = this.getModel(); + var mindmap = model.getMindmap(); + result = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); + + // Create a new node ... + var order = this.getOrder() + 1; + result.setOrder(order); + result.setPosition(10,10); + } + return result; } + }); mindplot.MainTopic.DEFAULT_MAIN_TOPIC_HEIGHT = 18; diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index 7c692a5b..783819a3 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -27,7 +27,6 @@ mindplot.Topic = new Class({ this._parent = null; this._relationships = []; this._isInWorkspace = false; - this._helpers = []; this._buildShape(); // Position a topic .... @@ -144,12 +143,6 @@ mindplot.Topic = new Class({ if ($defined(connector)) { connector.moveToFront(); } - - //Move helpers to front - this._helpers.forEach(function(helper) { - helper.moveToFront(); - }); - } }, @@ -1257,11 +1250,28 @@ mindplot.Topic = new Class({ } }, - addHelper : function(helper) { - helper.addToGroup(this.get2DElement()); - this._helpers.push(helper); - } + // @Todo: this don't seems to be a nice way... Order should be infered automatically ... + createChildModel : function() { + // Create a new node ... + var model = this.getModel(); + var mindmap = model.getMindmap(); + var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE); + // Get the hights model order position ... + var children = this._getChildren(); + var order = -1; + for (var i = 0; i < children.length; i++) { + var child = children[i]; + if (child.getOrder() > order) { + order = child.getOrder(); + } + } + // Create a new node ... + childModel.setOrder(order + 1); + childModel.setPosition(10, 10); + + return childModel; + } }); diff --git a/mindplot/src/main/javascript/layout/OriginalLayoutManager.js b/mindplot/src/main/javascript/layout/OriginalLayoutManager.js index 752ef6f4..b7041f9d 100644 --- a/mindplot/src/main/javascript/layout/OriginalLayoutManager.js +++ b/mindplot/src/main/javascript/layout/OriginalLayoutManager.js @@ -23,14 +23,7 @@ mindplot.layout.OriginalLayoutManager = new Class({ }, initialize:function(designer, options) { this.parent(designer, options); - this._dragTopicPositioner = new mindplot.DragTopicPositioner(this); - // Init drag manager. - var workSpace = this.getDesigner().getWorkSpace(); - this._dragger = this._buildDragManager(workSpace); - - // Add shapes to speed up the loading process ... - mindplot.DragTopic.init(workSpace); }, prepareNode:function(node, children) { @@ -77,60 +70,7 @@ mindplot.layout.OriginalLayoutManager = new Class({ return this._dragTopicPositioner; }, - _buildDragManager: function(workspace) { - // Init dragger manager. - var dragger = new mindplot.DragManager(workspace); - var topics = this.getDesigner().getModel().getTopics(); - var dragTopicPositioner = this.getDragTopicPositioner(); - - dragger.addEvent('startdragging', function(event, node) { - // Enable all mouse events. - for (var i = 0; i < topics.length; i++) { - topics[i].setMouseEventsEnabled(false); - } - }); - - dragger.addEvent('dragging', function(event, dragTopic) { - // Update the state and connections of the topic ... - dragTopicPositioner.positionateDragTopic(dragTopic); - }); - - dragger.addEvent('enddragging', function(event, dragTopic) { - // Enable all mouse events. - for (var i = 0; i < topics.length; i++) { - topics[i].setMouseEventsEnabled(true); - } - // Topic must be positioned in the real board postion. - if (dragTopic._isInTheWorkspace) { - var draggedTopic = dragTopic.getDraggedTopic(); - - // Hide topic during draw ... - draggedTopic.setBranchVisibility(false); - var parentNode = draggedTopic.getParent(); - dragTopic.updateDraggedTopic(workspace); - - - // Make all node visible ... - draggedTopic.setVisibility(true); - if (parentNode != null) { - parentNode.setBranchVisibility(true); - } - } - }); - - return dragger; - }, - - registerListenersOnNode : function(topic) { - // Register node listeners ... - if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { - - // Central Topic doesn't support to be dragged - var dragger = this._dragger; - dragger.add(topic); - } - }, _createMainTopicBoard:function(node) { return new mindplot.layout.boards.original.MainTopicBoard(node, this); diff --git a/mindplot/src/main/javascript/model/INodeModel.js b/mindplot/src/main/javascript/model/INodeModel.js index 591017dd..42944be2 100644 --- a/mindplot/src/main/javascript/model/INodeModel.js +++ b/mindplot/src/main/javascript/model/INodeModel.js @@ -55,6 +55,8 @@ mindplot.model.INodeModel = new Class({ }, setPosition : function(x, y) { + $assert(!isNaN(parseInt(x)), "x position is not valid:" + x); + $assert(!isNaN(parseInt(y)), "x position is not valid:" + y); this.putProperty('position', '{x:' + parseInt(x) + ',y:' + parseInt(y) + '}'); }, diff --git a/mindplot/src/main/javascript/widget/Menu.js b/mindplot/src/main/javascript/widget/Menu.js index d297018a..f63533c9 100644 --- a/mindplot/src/main/javascript/widget/Menu.js +++ b/mindplot/src/main/javascript/widget/Menu.js @@ -367,7 +367,6 @@ mindplot.widget.Menu = new Class({ var disable = false; if (button.isTopicAction() && button.isRelAction()) { disable = rels.length == 0 && topics.length == 0; - console.log(disable); } else if (!button.isTopicAction() && !button.isRelAction()) { disable = false; }