From a0ee153ca0ba029efeff9cf414813e0fa8531188 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 20 Sep 2012 09:23:48 -0300 Subject: [PATCH 1/4] - Remove getTopicType flag. --- mindplot/src/main/javascript/CentralTopic.js | 9 - mindplot/src/main/javascript/Designer.js | 51 +- .../src/main/javascript/DesignerKeyboard.js | 8 +- mindplot/src/main/javascript/MainTopic.js | 482 +++++++++--------- mindplot/src/main/javascript/Topic.js | 6 + 5 files changed, 291 insertions(+), 265 deletions(-) diff --git a/mindplot/src/main/javascript/CentralTopic.js b/mindplot/src/main/javascript/CentralTopic.js index 4ac5040d..e08458c2 100644 --- a/mindplot/src/main/javascript/CentralTopic.js +++ b/mindplot/src/main/javascript/CentralTopic.js @@ -40,20 +40,11 @@ mindplot.CentralTopic = new Class({ return 11; }, - getTopicType:function () { - return mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE; - }, - setCursor:function (type) { type = (type == 'move') ? 'default' : type; this.parent(type); }, - isConnectedToCentralTopic:function () { - return false; - }, - - _defaultShapeType:function () { return mindplot.model.TopicShape.ROUNDED_RECT; }, diff --git a/mindplot/src/main/javascript/Designer.js b/mindplot/src/main/javascript/Designer.js index c8c54296..c071f51b 100644 --- a/mindplot/src/main/javascript/Designer.js +++ b/mindplot/src/main/javascript/Designer.js @@ -116,7 +116,6 @@ mindplot.Designer = new Class({ }, - addEvent:function (type, listener) { if (type == mindplot.TopicEvent.EDIT || type == mindplot.TopicEvent.CLICK) { var editor = mindplot.TopicEventDispatcher.getInstance(); @@ -161,6 +160,48 @@ mindplot.Designer = new Class({ } }.bind(this)); + // Register mouse drag and drop event ... + function noopHandler(evt) { + evt.stopPropagation(); + evt.preventDefault(); + } + + // Enable drag events ... + Element.NativeEvents.dragenter = 2; + Element.NativeEvents.dragexit = 2; + Element.NativeEvents.dragover = 2; + Element.NativeEvents.drop = 2; + + screenManager.addEvent('dragenter', noopHandler); + screenManager.addEvent('dragexit', noopHandler); + screenManager.addEvent('dragover', noopHandler); + screenManager.addEvent('drop', function (evt) { + evt.stopPropagation(); + evt.preventDefault(); +// + var files = evt.event.dataTransfer.files; + console.log(event); + + var count = files.length; + + // Only call the handler if 1 or more files was dropped. + if (count > 0) { + + var model = this.getMindmap().createNode(); + model.setImageSize(80, 43); + model.setMetadata("{'media':'video,'url':'http://www.youtube.com/watch?v=P3FrXftyuzw&feature=g-vrec&context=G2b4ab69RVAAAAAAAAAA'}"); + model.setImageUrl("images/logo-small.png"); + model.setShapeType(mindplot.model.TopicShape.IMAGE); + + var position = screenManager.getWorkspaceMousePosition(evt); + model.setPosition(position.x, position.y); + model.setPosition(100, 100); + + this._actionDispatcher.addTopics([model]); + } + }.bind(this)); + + }, _buildDragManager:function (workspace) { @@ -362,7 +403,7 @@ mindplot.Designer = new Class({ // Exclude central topic .. topics = topics.filter(function (topic) { - return topic.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE + return !topic.isCentralTopic(); }); this._clipboard = topics.map(function (topic) { @@ -692,7 +733,7 @@ mindplot.Designer = new Class({ }, _removeTopic:function (node) { - if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!node.isCentralTopic()) { var parent = node._parent; node.disconnect(this._workspace); @@ -722,14 +763,14 @@ mindplot.Designer = new Class({ // If there are more than one node selected, $notify($msg('ENTITIES_COULD_NOT_BE_DELETED')); return; - } else if (topics.length == 1 && topics[0].getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + } else if (topics.length == 1 && topics[0].isCentralTopic()) { $notify($msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED')); return; } // If the central topic has been selected, I must filter ir var topicIds = topics.filter(function (topic) { - return topic.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE + return !topic.isCentralTopic(); }).map(function (topic) { return topic.getId() }); diff --git a/mindplot/src/main/javascript/DesignerKeyboard.js b/mindplot/src/main/javascript/DesignerKeyboard.js index df992657..eefd8d09 100644 --- a/mindplot/src/main/javascript/DesignerKeyboard.js +++ b/mindplot/src/main/javascript/DesignerKeyboard.js @@ -228,7 +228,7 @@ mindplot.DesignerKeyboard = new Class({ 'right':function () { var node = model.selectedTopic(); if (node) { - if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (node.isCentralTopic()) { this._goToSideChild(designer, node, 'RIGHT'); } else { @@ -248,7 +248,7 @@ mindplot.DesignerKeyboard = new Class({ 'left':function () { var node = model.selectedTopic(); if (node) { - if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (node.isCentralTopic()) { this._goToSideChild(designer, node, 'LEFT'); } else { @@ -268,7 +268,7 @@ mindplot.DesignerKeyboard = new Class({ 'up':function () { var node = model.selectedTopic(); if (node) { - if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!node.isCentralTopic()) { this._goToBrother(designer, node, 'UP'); } } else { @@ -280,7 +280,7 @@ mindplot.DesignerKeyboard = new Class({ 'down':function () { var node = model.selectedTopic(); if (node) { - if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!node.isCentralTopic()) { this._goToBrother(designer, node, 'DOWN'); } } else { diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index f92920c7..86e6833a 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -1,248 +1,236 @@ -/* - * 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.MainTopic = new Class({ - Extends:mindplot.Topic, - initialize:function (model, options) { - this.parent(model, options); - }, - - INNER_RECT_ATTRIBUTES:{stroke:'0.5 solid #009900'}, - - _buildDragShape:function () { - var innerShape = this._buildShape(this.INNER_RECT_ATTRIBUTES, this.getShapeType()); - var size = this.getSize(); - innerShape.setSize(size.width, size.height); - innerShape.setPosition(0, 0); - innerShape.setOpacity(0.5); - innerShape.setCursor('default'); - innerShape.setVisibility(true); - - var brColor = this.getBorderColor(); - innerShape.setAttribute("strokeColor", brColor); - - var bgColor = this.getBackgroundColor(); - innerShape.setAttribute("fillColor", bgColor); - - // Create group ... - var groupAttributes = {width:100, height:100, coordSizeWidth:100, coordSizeHeight:100}; - var group = new web2d.Group(groupAttributes); - group.appendChild(innerShape); - - // Add Text ... - if (this.getShapeType() != mindplot.model.TopicShape.IMAGE) { - var textShape = this._buildTextShape(true); - var text = this.getText(); - textShape.setText(text); - textShape.setOpacity(0.5); - group.appendChild(textShape); - } - return group; - }, - - - _defaultShapeType:function () { - return mindplot.model.TopicShape.LINE; - }, - - updateTopicShape:function (targetTopic, workspace) { - // Change figure based on the connected topic ... - var model = this.getModel(); - var shapeType = model.getShapeType(); - if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { - if (!$defined(shapeType)) { - // Get the real shape type ... - shapeType = this.getShapeType(); - this._setShapeType(shapeType, false); - } - } - }, - - disconnect:function (workspace) { - this.parent(workspace); - var size = this.getSize(); - - var model = this.getModel(); - var shapeType = model.getShapeType(); - if (!$defined(shapeType)) { - // Change figure ... - shapeType = this.getShapeType(); - this._setShapeType(mindplot.model.TopicShape.ROUNDED_RECT, false); - } - var innerShape = this.getInnerShape(); - innerShape.setVisibility(true); - }, - - getTopicType:function () { - return "MainTopic"; - }, - - _updatePositionOnChangeSize:function (oldSize, newSize) { - - var xOffset = Math.round((newSize.width - oldSize.width) / 2); - var pos = this.getPosition(); - if ($defined(pos)) { - if (pos.x > 0) { - pos.x = pos.x + xOffset; - } else { - pos.x = pos.x - xOffset; - } - this.setPosition(pos); - } - }, - - workoutIncomingConnectionPoint:function (sourcePosition) { - $assert(sourcePosition, 'sourcePoint can not be null'); - var pos = this.getPosition(); - var size = this.getSize(); - - var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); - var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); - if (this.getShapeType() == mindplot.model.TopicShape.LINE) { - result.y = result.y + (this.getSize().height / 2); - } - - // Move a little the position... - var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; - if (this.getPosition().x > 0) { - result.x = result.x + offset; - } else { - result.x = result.x - offset; - } - - result.x = Math.ceil(result.x); - result.y = Math.ceil(result.y); - return result; - - }, - - workoutOutgoingConnectionPoint:function (targetPosition) { - $assert(targetPosition, 'targetPoint can not be null'); - var pos = this.getPosition(); - var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); - var size = this.getSize(); - - var result; - if (this.getShapeType() == mindplot.model.TopicShape.LINE) { - - result = new core.Point(); - var groupPosition = this._elem2d.getPosition(); - var innerShareSize = this.getInnerShape().getSize(); - - if (innerShareSize) { - var magicCorrectionNumber = 0.3; - if (!isAtRight) { - result.x = groupPosition.x + innerShareSize.width - magicCorrectionNumber; - } else { - result.x = groupPosition.x + magicCorrectionNumber; - } - result.y = groupPosition.y + innerShareSize.height; - } else { - // Hack: When the size has not being defined. This is because the node has not being added. - // Try to do our best ... - if (!isAtRight) { - result.x = pos.x + (size.width / 2); - } else { - result.x = pos.x - (size.width / 2); - } - result.y = pos.y + (size.height / 2); - } - - } else { - result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); - } - return result; - }, - - _getInnerPadding:function () { - var result; - var parent = this.getModel().getParent(); - if (parent && mindplot.model.INodeModel.MAIN_TOPIC_TYPE == parent.getType()) { - result = 3; - } - else { - result = 4; - } - return result; - }, - - isConnectedToCentralTopic:function () { - var model = this.getModel(); - var parent = model.getParent(); - - return parent && parent.getType() === mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE; - }, - - _defaultText:function () { - var targetTopic = this.getOutgoingConnectedTopic(); - var result = ""; - if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { - result = $msg('MAIN_TOPIC'); - } else { - result = $msg('SUB_TOPIC'); - } - } else { - result = $msg('ISOLATED_TOPIC'); - ; - } - return result; - }, - - _defaultFontStyle:function () { - var targetTopic = this.getOutgoingConnectedTopic(); - var result; - if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { - result = { - font:"Arial", - size:8, - style:"normal", - weight:"normal", - color:"rgb(82,92,97)" - }; - } else { - result = { - font:"Arial", - size:6, - style:"normal", - weight:"normal", - color:"rgb(82,92,97)" - }; - } - } else { - result = { - font:"Verdana", - size:8, - style:"normal", - weight:"normal", - color:"rgb(82,92,97)" - }; - } - return result; - }, - - _defaultBackgroundColor:function () { - return "rgb(224,229,239)"; - }, - - _defaultBorderColor:function () { - return 'rgb(2,59,185)'; - } - +/* + * 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.MainTopic = new Class({ + Extends:mindplot.Topic, + initialize:function (model, options) { + this.parent(model, options); + }, + + INNER_RECT_ATTRIBUTES:{stroke:'0.5 solid #009900'}, + + _buildDragShape:function () { + var innerShape = this._buildShape(this.INNER_RECT_ATTRIBUTES, this.getShapeType()); + var size = this.getSize(); + innerShape.setSize(size.width, size.height); + innerShape.setPosition(0, 0); + innerShape.setOpacity(0.5); + innerShape.setCursor('default'); + innerShape.setVisibility(true); + + var brColor = this.getBorderColor(); + innerShape.setAttribute("strokeColor", brColor); + + var bgColor = this.getBackgroundColor(); + innerShape.setAttribute("fillColor", bgColor); + + // Create group ... + var groupAttributes = {width:100, height:100, coordSizeWidth:100, coordSizeHeight:100}; + var group = new web2d.Group(groupAttributes); + group.appendChild(innerShape); + + // Add Text ... + if (this.getShapeType() != mindplot.model.TopicShape.IMAGE) { + var textShape = this._buildTextShape(true); + var text = this.getText(); + textShape.setText(text); + textShape.setOpacity(0.5); + group.appendChild(textShape); + } + return group; + }, + + + _defaultShapeType:function () { + return mindplot.model.TopicShape.LINE; + }, + + updateTopicShape:function (targetTopic, workspace) { + // Change figure based on the connected topic ... + var model = this.getModel(); + var shapeType = model.getShapeType(); + if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!$defined(shapeType)) { + // Get the real shape type ... + shapeType = this.getShapeType(); + this._setShapeType(shapeType, false); + } + } + }, + + disconnect:function (workspace) { + this.parent(workspace); + var size = this.getSize(); + + var model = this.getModel(); + var shapeType = model.getShapeType(); + if (!$defined(shapeType)) { + // Change figure ... + shapeType = this.getShapeType(); + this._setShapeType(mindplot.model.TopicShape.ROUNDED_RECT, false); + } + var innerShape = this.getInnerShape(); + innerShape.setVisibility(true); + }, + + _updatePositionOnChangeSize:function (oldSize, newSize) { + + var xOffset = Math.round((newSize.width - oldSize.width) / 2); + var pos = this.getPosition(); + if ($defined(pos)) { + if (pos.x > 0) { + pos.x = pos.x + xOffset; + } else { + pos.x = pos.x - xOffset; + } + this.setPosition(pos); + } + }, + + workoutIncomingConnectionPoint:function (sourcePosition) { + $assert(sourcePosition, 'sourcePoint can not be null'); + var pos = this.getPosition(); + var size = this.getSize(); + + var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); + var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); + if (this.getShapeType() == mindplot.model.TopicShape.LINE) { + result.y = result.y + (this.getSize().height / 2); + } + + // Move a little the position... + var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; + if (this.getPosition().x > 0) { + result.x = result.x + offset; + } else { + result.x = result.x - offset; + } + + result.x = Math.ceil(result.x); + result.y = Math.ceil(result.y); + return result; + + }, + + workoutOutgoingConnectionPoint:function (targetPosition) { + $assert(targetPosition, 'targetPoint can not be null'); + var pos = this.getPosition(); + var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); + var size = this.getSize(); + + var result; + if (this.getShapeType() == mindplot.model.TopicShape.LINE) { + + result = new core.Point(); + var groupPosition = this._elem2d.getPosition(); + var innerShareSize = this.getInnerShape().getSize(); + + if (innerShareSize) { + var magicCorrectionNumber = 0.3; + if (!isAtRight) { + result.x = groupPosition.x + innerShareSize.width - magicCorrectionNumber; + } else { + result.x = groupPosition.x + magicCorrectionNumber; + } + result.y = groupPosition.y + innerShareSize.height; + } else { + // Hack: When the size has not being defined. This is because the node has not being added. + // Try to do our best ... + if (!isAtRight) { + result.x = pos.x + (size.width / 2); + } else { + result.x = pos.x - (size.width / 2); + } + result.y = pos.y + (size.height / 2); + } + + } else { + result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); + } + return result; + }, + + _getInnerPadding:function () { + var result; + var parent = this.getModel().getParent(); + if (parent && mindplot.model.INodeModel.MAIN_TOPIC_TYPE == parent.getType()) { + result = 3; + } + else { + result = 4; + } + return result; + }, + + _defaultText:function () { + var targetTopic = this.getOutgoingConnectedTopic(); + var result = ""; + if ($defined(targetTopic)) { + if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + result = $msg('MAIN_TOPIC'); + } else { + result = $msg('SUB_TOPIC'); + } + } else { + result = $msg('ISOLATED_TOPIC'); + } + return result; + }, + + _defaultFontStyle:function () { + var targetTopic = this.getOutgoingConnectedTopic(); + var result; + if ($defined(targetTopic)) { + if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + result = { + font:"Arial", + size:8, + style:"normal", + weight:"normal", + color:"rgb(82,92,97)" + }; + } else { + result = { + font:"Arial", + size:6, + style:"normal", + weight:"normal", + color:"rgb(82,92,97)" + }; + } + } else { + result = { + font:"Verdana", + size:8, + style:"normal", + weight:"normal", + color:"rgb(82,92,97)" + }; + } + return result; + }, + + _defaultBackgroundColor:function () { + return "rgb(224,229,239)"; + }, + + _defaultBorderColor:function () { + return 'rgb(2,59,185)'; + } + }); \ No newline at end of file diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index 17d4c29e..fc9317e6 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -1216,7 +1216,13 @@ mindplot.Topic = new Class({ } } return result; + }, + + isCentralTopic:function () { + return this.getModel().getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE; } + + }); From 7bbcd824886f77def6ce18efb47b179d872c8686 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 20 Sep 2012 19:00:31 -0300 Subject: [PATCH 2/4] - Remove CENTRAL_NODE flag. --- mindplot/src/main/javascript/MainTopic.js | 8 ++++---- mindplot/src/main/javascript/Topic.js | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index 86e6833a..87401ebd 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -64,7 +64,7 @@ mindplot.MainTopic = new Class({ // Change figure based on the connected topic ... var model = this.getModel(); var shapeType = model.getShapeType(); - if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!targetTopic.isCentralTopic()) { if (!$defined(shapeType)) { // Get the real shape type ... shapeType = this.getShapeType(); @@ -168,7 +168,7 @@ mindplot.MainTopic = new Class({ _getInnerPadding:function () { var result; var parent = this.getModel().getParent(); - if (parent && mindplot.model.INodeModel.MAIN_TOPIC_TYPE == parent.getType()) { + if (parent && !parent.isCentralTopic()) { result = 3; } else { @@ -181,7 +181,7 @@ mindplot.MainTopic = new Class({ var targetTopic = this.getOutgoingConnectedTopic(); var result = ""; if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (targetTopic.isCentralTopic()) { result = $msg('MAIN_TOPIC'); } else { result = $msg('SUB_TOPIC'); @@ -196,7 +196,7 @@ mindplot.MainTopic = new Class({ var targetTopic = this.getOutgoingConnectedTopic(); var result; if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (targetTopic.isCentralTopic()) { result = { font:"Arial", size:8, diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index fc9317e6..e47ab269 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -29,7 +29,7 @@ mindplot.Topic = new Class({ // Position a topic .... var pos = model.getPosition(); - if (pos != null && model.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (pos != null && this.isCentralTopic()) { this.setPosition(pos); } @@ -134,7 +134,7 @@ mindplot.Topic = new Class({ this._setBorderColor(brColor, false); // Define the pointer ... - if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && !this.isReadOnly()) { + if (!this.isCentralTopic() && !this.isReadOnly()) { this._innerShape.setCursor('move'); } else { this._innerShape.setCursor('default'); @@ -340,7 +340,7 @@ mindplot.Topic = new Class({ if (!readOnly) { // Propagate mouse events ... - if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!this.isCentralTopic()) { result.setCursor('move'); } else { result.setCursor('default'); @@ -829,7 +829,7 @@ mindplot.Topic = new Class({ setBranchVisibility:function (value) { var current = this; var parent = this; - while (parent != null && parent.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + while (parent != null && !parent.isCentralTopic()) { current = parent; parent = current.getParent(); } @@ -1111,7 +1111,7 @@ mindplot.Topic = new Class({ var elem = this.get2DElement(); workspace.appendChild(elem); if (!this.isInWorkspace()) { - if (this.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + if (!this.isCentralTopic()) { mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeAdded, this.getModel()); } From d2f9749d61614049a515f0b7796fd1f92169ca9e Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 21 Sep 2012 09:22:41 -0300 Subject: [PATCH 3/4] - Refactor node properties to topics. --- mindplot/pom.xml | 1 + mindplot/src/main/javascript/CentralTopic.js | 31 ----- mindplot/src/main/javascript/MainTopic.js | 73 ---------- mindplot/src/main/javascript/Topic.js | 28 ++-- mindplot/src/main/javascript/TopicStyle.js | 132 +++++++++++++++++++ 5 files changed, 145 insertions(+), 120 deletions(-) create mode 100644 mindplot/src/main/javascript/TopicStyle.js diff --git a/mindplot/pom.xml b/mindplot/pom.xml index 53144cd4..99273e1c 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -140,6 +140,7 @@ Workspace.js ShrinkConnector.js DesignerKeyboard.js + TopicStyle.js NodeGraph.js Topic.js CentralTopic.js diff --git a/mindplot/src/main/javascript/CentralTopic.js b/mindplot/src/main/javascript/CentralTopic.js index e08458c2..f2fba1bf 100644 --- a/mindplot/src/main/javascript/CentralTopic.js +++ b/mindplot/src/main/javascript/CentralTopic.js @@ -36,20 +36,11 @@ mindplot.CentralTopic = new Class({ return this.getPosition(); }, - _getInnerPadding:function () { - return 11; - }, - setCursor:function (type) { type = (type == 'move') ? 'default' : type; this.parent(type); }, - _defaultShapeType:function () { - return mindplot.model.TopicShape.ROUNDED_RECT; - }, - - updateTopicShape:function () { }, @@ -61,28 +52,6 @@ mindplot.CentralTopic = new Class({ this.setPosition(zeroPoint); }, - _defaultText:function () { - return $msg('CENTRAL_TOPIC'); - }, - - _defaultBackgroundColor:function () { - return "rgb(80,157,192)"; - }, - - _defaultBorderColor:function () { - return "rgb(57,113,177)"; - }, - - _defaultFontStyle:function () { - return { - font:"Verdana", - size:10, - style:"normal", - weight:"bold", - color:"#ffffff" - }; - }, - getShrinkConnector:function () { return null; }, diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index 87401ebd..e1bb2a7c 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -55,11 +55,6 @@ mindplot.MainTopic = new Class({ return group; }, - - _defaultShapeType:function () { - return mindplot.model.TopicShape.LINE; - }, - updateTopicShape:function (targetTopic, workspace) { // Change figure based on the connected topic ... var model = this.getModel(); @@ -163,74 +158,6 @@ mindplot.MainTopic = new Class({ result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); } return result; - }, - - _getInnerPadding:function () { - var result; - var parent = this.getModel().getParent(); - if (parent && !parent.isCentralTopic()) { - result = 3; - } - else { - result = 4; - } - return result; - }, - - _defaultText:function () { - var targetTopic = this.getOutgoingConnectedTopic(); - var result = ""; - if ($defined(targetTopic)) { - if (targetTopic.isCentralTopic()) { - result = $msg('MAIN_TOPIC'); - } else { - result = $msg('SUB_TOPIC'); - } - } else { - result = $msg('ISOLATED_TOPIC'); - } - return result; - }, - - _defaultFontStyle:function () { - var targetTopic = this.getOutgoingConnectedTopic(); - var result; - if ($defined(targetTopic)) { - if (targetTopic.isCentralTopic()) { - result = { - font:"Arial", - size:8, - style:"normal", - weight:"normal", - color:"rgb(82,92,97)" - }; - } else { - result = { - font:"Arial", - size:6, - style:"normal", - weight:"normal", - color:"rgb(82,92,97)" - }; - } - } else { - result = { - font:"Verdana", - size:8, - style:"normal", - weight:"normal", - color:"rgb(82,92,97)" - }; - } - return result; - }, - - _defaultBackgroundColor:function () { - return "rgb(224,229,239)"; - }, - - _defaultBorderColor:function () { - return 'rgb(2,59,185)'; } }); \ No newline at end of file diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index e47ab269..d8d8d992 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -107,7 +107,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getShapeType(); if (!$defined(result)) { - result = this._defaultShapeType(); + result = mindplot.TopicStyle.defaultShapeType(this); } return result; }, @@ -259,7 +259,7 @@ mindplot.Topic = new Class({ _buildIconGroup:function () { var textHeight = this.getTextShape().getFontHeight(); var result = new mindplot.IconGroup(this.getId(), textHeight); - var padding = this._getInnerPadding(); + var padding = mindplot.TopicStyle.getInnerPadding(this); result.setPosition(padding, padding); // Load topic features ... @@ -350,10 +350,6 @@ mindplot.Topic = new Class({ return result; }, - _getInnerPadding:function () { - throw "this must be implemented"; - }, - setFontFamily:function (value, updateModel) { var textShape = this.getTextShape(); textShape.setFontFamily(value); @@ -401,7 +397,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getFontWeight(); if (!$defined(result)) { - var font = this._defaultFontStyle(); + var font = mindplot.TopicStyle.defaultFontStyle(this); result = font.weight; } return result; @@ -411,7 +407,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getFontFamily(); if (!$defined(result)) { - var font = this._defaultFontStyle(); + var font = mindplot.TopicStyle.defaultFontStyle(this); result = font.font; } return result; @@ -421,7 +417,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getFontColor(); if (!$defined(result)) { - var font = this._defaultFontStyle(); + var font = mindplot.TopicStyle.defaultFontStyle(this); result = font.color; } return result; @@ -431,7 +427,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getFontStyle(); if (!$defined(result)) { - var font = this._defaultFontStyle(); + var font = mindplot.TopicStyle.defaultFontStyle(this); result = font.style; } return result; @@ -441,7 +437,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getFontSize(); if (!$defined(result)) { - var font = this._defaultFontStyle(); + var font = mindplot.TopicStyle.defaultFontStyle(this); result = font.size; } return result; @@ -458,7 +454,7 @@ mindplot.Topic = new Class({ _setText:function (text, updateModel) { var textShape = this.getTextShape(); - textShape.setText(text == null ? this._defaultText() : text); + textShape.setText(text == null ? mindplot.TopicStyle.defaultText(this) : text); if ($defined(updateModel) && updateModel) { var model = this.getModel(); @@ -480,7 +476,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getText(); if (!$defined(result)) { - result = this._defaultText(); + result = mindplot.TopicStyle.defaultText(this); } return result; }, @@ -508,7 +504,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getBackgroundColor(); if (!$defined(result)) { - result = this._defaultBackgroundColor(); + result = mindplot.TopicStyle.defaultBackgroundColor(this); } return result; }, @@ -536,7 +532,7 @@ mindplot.Topic = new Class({ var model = this.getModel(); var result = model.getBorderColor(); if (!$defined(result)) { - result = this._defaultBorderColor(); + result = mindplot.TopicStyle.defaultBorderColor(this); } return result; }, @@ -1154,7 +1150,7 @@ mindplot.Topic = new Class({ var textHeight = textShape.getHeight(); textHeight = textHeight != 0 ? textHeight : 20; - var topicPadding = this._getInnerPadding(); + var topicPadding = mindplot.TopicStyle.getInnerPadding(this); // Adjust the icon size to the size of the text ... var iconGroup = this.getOrBuildIconGroup(); diff --git a/mindplot/src/main/javascript/TopicStyle.js b/mindplot/src/main/javascript/TopicStyle.js new file mode 100644 index 00000000..43bb7b8f --- /dev/null +++ b/mindplot/src/main/javascript/TopicStyle.js @@ -0,0 +1,132 @@ +/* + * 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.TopicStyle = new Class({ + Static:{ + _getStyles:function (topic) { + $assert(topic, "topic can not be null"); + + var result; + if (topic.isCentralTopic()) { + result = mindplot.TopicStyle.STYLES.CENTRAL_TOPIC; + } else { + var targetTopic = topic.getOutgoingConnectedTopic(); + if ($defined(targetTopic)) { + if (targetTopic.isCentralTopic()) { + result = mindplot.TopicStyle.STYLES.MAIN_TOPIC; + } else { + result = mindplot.TopicStyle.STYLES.SUB_TOPIC; + } + } else { + result = mindplot.TopicStyle.STYLES.ISOLATED_TOPIC; + } + } + return result; + }, + + defaultText:function (topic) { + var msgKey = this._getStyles(topic).msgKey; + return $msg(msgKey); + }, + + defaultFontStyle:function (topic) { + return this._getStyles(topic).fontStyle; + }, + + defaultBackgroundColor:function (topic) { + return this._getStyles(topic).backgroundColor; + }, + + defaultBorderColor:function (topic) { + return this._getStyles(topic).borderColor; + }, + + getInnerPadding:function (topic) { + return this._getStyles(topic).innerPadding; + }, + + defaultShapeType:function (topic) { + return this._getStyles(topic).shapeType; + } + + } +}); + +mindplot.TopicStyle.STYLES = +{ + CENTRAL_TOPIC:{ + borderColor:'rgb(57,113,177)', + backgroundColor:'rgb(80,157,192)', + fontStyle:{ + font:"Verdana", + size:10, + style:"normal", + weight:"bold", + color:"#ffffff" + }, + msgKey:'CENTRAL_TOPIC', + innerPadding:11, + shapeType:mindplot.model.TopicShape.ROUNDED_RECT + }, + + MAIN_TOPIC:{ + borderColor:'rgb(2,59,185)', + backgroundColor:'rgb(224,229,239)', + fontStyle:{ + font:"Arial", + size:8, + style:"normal", + weight:"normal", + color:"rgb(82,92,97)" + }, + msgKey:'MAIN_TOPIC', + innerPadding:3, + shapeType:mindplot.model.TopicShape.LINE + + }, + + SUB_TOPIC:{ + borderColor:'rgb(2,59,185)', + backgroundColor:'rgb(224,229,239)', + fontStyle:{ + font:"Arial", + size:6, + style:"normal", + weight:"normal", + color:"rgb(82,92,97)" + }, + msgKey:'SUB_TOPIC', + innerPadding:3, + shapeType:mindplot.model.TopicShape.LINE + }, + + ISOLATED_TOPIC:{ + borderColor:'rgb(2,59,185)', + backgroundColor:'rgb(224,229,239)', + fontStyle:{ + font:"Verdana", + size:8, + style:"normal", + weight:"normal", + color:"rgb(82,92,97)" + }, + msgKey:'ISOLATED_TOPIC', + innerPadding:4, + shapeType:mindplot.model.TopicShape.LINE + } +}; + From 155ec74dea7eb94acaaa57351fd219b771990148 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 24 Sep 2012 13:11:11 -0300 Subject: [PATCH 4/4] - Add more info to detect errors. --- mindplot/src/main/javascript/StandaloneActionDispatcher.js | 5 ++++- .../com/wisemapping/importer/freemind/FreemindImporter.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mindplot/src/main/javascript/StandaloneActionDispatcher.js b/mindplot/src/main/javascript/StandaloneActionDispatcher.js index b28dcea8..05dd2136 100644 --- a/mindplot/src/main/javascript/StandaloneActionDispatcher.js +++ b/mindplot/src/main/javascript/StandaloneActionDispatcher.js @@ -242,9 +242,12 @@ mindplot.CommandContext = new Class({ } var designerTopics = this._designer.getModel().getTopics(); - return designerTopics.filter(function (topic) { + var result = designerTopics.filter(function (topic) { return topicsIds.contains(topic.getId()); }); + + $assert(result.length == topicsIds.length, "Could not find topic. Result:" + result + ", Filtered:" + topicsIds + ", Current Topics: " + designerTopics); + return result; }, deleteTopic:function (topic) { diff --git a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java index e030ec2a..eb096107 100755 --- a/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java +++ b/wise-webapp/src/main/java/com/wisemapping/importer/freemind/FreemindImporter.java @@ -341,7 +341,7 @@ public class FreemindImporter * 3 -> 2 * 4 -> 4 */ - private int calcFirstLevelOrder(@NotNull List freeChilden, @NotNull Node freeChild) { + private int calcFirstLevelOrder(@NotNull List freeChilden, @Nullable Node freeChild) { final List nodes = new ArrayList(); int result;