From 1fefb929dafe9de46e68b56d014b8c8195cd6f50 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 27 Feb 2012 22:47:10 -0300 Subject: [PATCH] Fix change shape bug. --- mindplot/src/main/javascript/CentralTopic.js | 2 +- .../src/main/javascript/ConnectionLine.js | 2 +- mindplot/src/main/javascript/Designer.js | 6 ++--- mindplot/src/main/javascript/MainTopic.js | 12 ++++----- mindplot/src/main/javascript/Topic.js | 17 ++++++------- mindplot/src/main/javascript/TopicEditor.js | 25 +++++++++++++++++++ .../src/main/javascript/model/INodeModel.js | 14 ++++++++--- 7 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 mindplot/src/main/javascript/TopicEditor.js diff --git a/mindplot/src/main/javascript/CentralTopic.js b/mindplot/src/main/javascript/CentralTopic.js index ed793c4e..3bd61009 100644 --- a/mindplot/src/main/javascript/CentralTopic.js +++ b/mindplot/src/main/javascript/CentralTopic.js @@ -55,7 +55,7 @@ mindplot.CentralTopic = new Class({ _defaultShapeType : function() { - return mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT; + return mindplot.model.TopicShape.ROUNDED_RECT; }, diff --git a/mindplot/src/main/javascript/ConnectionLine.js b/mindplot/src/main/javascript/ConnectionLine.js index b4f2f3a4..e5ab6570 100644 --- a/mindplot/src/main/javascript/ConnectionLine.js +++ b/mindplot/src/main/javascript/ConnectionLine.js @@ -123,7 +123,7 @@ mindplot.ConnectionLine = new Class({ var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; var targetTopicSize = targetTopic.getSize(); var y; - if (targetTopic.getShapeType() == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { + if (targetTopic.getShapeType() == mindplot.model.TopicShape.LINE) { y = targetTopicSize.height; } else { y = targetTopicSize.height / 2; diff --git a/mindplot/src/main/javascript/Designer.js b/mindplot/src/main/javascript/Designer.js index 84b3ed40..76217500 100644 --- a/mindplot/src/main/javascript/Designer.js +++ b/mindplot/src/main/javascript/Designer.js @@ -656,7 +656,7 @@ mindplot.Designer = new Class({ changeBackgroundColor : function(color) { var validateFunc = function(topic) { - return topic.getShapeType() != mindplot.model.INodeModel.SHAPE_TYPE_LINE + return topic.getShapeType() != mindplot.model.TopicShape.LINE; }; var validateError = 'Color can not be set to line topics.'; @@ -668,7 +668,7 @@ mindplot.Designer = new Class({ changeBorderColor : function(color) { var validateFunc = function(topic) { - return topic.getShapeType() != mindplot.model.INodeModel.SHAPE_TYPE_LINE + return topic.getShapeType() != mindplot.model.TopicShape.LINE ; }; var validateError = 'Color can not be set to line topics.'; var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); @@ -686,7 +686,7 @@ mindplot.Designer = new Class({ changeTopicShape : function(shape) { var validateFunc = function(topic) { - return !(topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.INodeModel.SHAPE_TYPE_LINE) + return !(topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.model.TopicShape.LINE) }; var validateError = 'Central Topic shape can not be changed to line figure.'; diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index ca2aaeb0..57e6e9af 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -56,7 +56,7 @@ mindplot.MainTopic = new Class({ _defaultShapeType : function() { - return mindplot.model.INodeModel.SHAPE_TYPE_LINE; + return mindplot.model.TopicShape.LINE; }, updateTopicShape : function(targetTopic, workspace) { @@ -81,7 +81,7 @@ mindplot.MainTopic = new Class({ if (!$defined(shapeType)) { // Change figure ... shapeType = this.getShapeType(); - this._setShapeType(mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT, false); + this._setShapeType(mindplot.model.TopicShape.ROUNDED_RECT, false); } var innerShape = this.getInnerShape(); innerShape.setVisibility(true); @@ -112,7 +112,7 @@ mindplot.MainTopic = new Class({ var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); - if (this.getShapeType() == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { + if (this.getShapeType() == mindplot.model.TopicShape.LINE) { result.y = result.y + (this.getSize().height / 2); } @@ -133,14 +133,15 @@ mindplot.MainTopic = new Class({ 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.INodeModel.SHAPE_TYPE_LINE) { + if (this.getShapeType() == mindplot.model.TopicShape.LINE) { result = new core.Point(); var groupPosition = this._elem2d.getPosition(); var innerShareSize = this.getInnerShape().getSize(); - var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); if (innerShareSize) { var magicCorrectionNumber = 0.3; @@ -153,7 +154,6 @@ mindplot.MainTopic = new Class({ } else { // Hack: When the size has not being defined. This is because the node has not being added. // Try to do our best ... - var size = this.getSize(); if (!isAtRight) { result.x = pos.x + (size.width / 2); } else { diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index cc9c2a41..9e62422d 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -55,7 +55,7 @@ mindplot.Topic = new Class({ event.stopPropagation(true); }.bind(this)); - this._textEditor.addEvent('input', function(event, text) { + this._textEditor.addEvent('input', function() { var textShape = this.getTextShape(); // var oldText = textShape.getText(); @@ -162,16 +162,16 @@ mindplot.Topic = new Class({ type = this.getShapeType(); } - if (type == mindplot.model.INodeModel.SHAPE_TYPE_RECT) { + if (type == mindplot.model.TopicShape.RECTANGLE) { result = new web2d.Rect(0, attributes); } - else if (type == mindplot.model.INodeModel.SHAPE_TYPE_ELIPSE) { + else if (type == mindplot.model.TopicShape.ELIPSE) { result = new web2d.Rect(0.9, attributes); } - else if (type == mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT) { + else if (type == mindplot.model.TopicShape.ROUNDED_RECT) { result = new web2d.Rect(0.3, attributes); } - else if (type == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { + else if (type == mindplot.model.TopicShape.LINE) { result = new web2d.Line({strokeColor:"#495879",strokeWidth:1}); result.setSize = function(width, height) { this.size = {width:width, height:height}; @@ -220,7 +220,7 @@ mindplot.Topic = new Class({ getOuterShape : function() { if (!$defined(this._outerShape)) { - var rect = this.buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT); + var rect = this.buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.TopicShape.ROUNDED_RECT); rect.setPosition(-2, -3); rect.setOpacity(0); this._outerShape = rect; @@ -596,7 +596,6 @@ mindplot.Topic = new Class({ }, isCollapsed : function() { - var model = this.getModel(); var result = false; var current = this.getParent(); @@ -637,7 +636,7 @@ mindplot.Topic = new Class({ outerShape.setOpacity(1); }, - handleMouseOut : function(event) { + handleMouseOut : function() { var outerShape = this.getOuterShape(); if (!this.isOnFocus()) { outerShape.setOpacity(0); @@ -936,7 +935,7 @@ mindplot.Topic = new Class({ } }, - _updatePositionOnChangeSize : function(oldSize, newSize) { + _updatePositionOnChangeSize : function() { $assert(false, "this method must be overwrited."); }, diff --git a/mindplot/src/main/javascript/TopicEditor.js b/mindplot/src/main/javascript/TopicEditor.js new file mode 100644 index 00000000..18181919 --- /dev/null +++ b/mindplot/src/main/javascript/TopicEditor.js @@ -0,0 +1,25 @@ +/* + * 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.TopicEditor = new Class({ + Extends: Events, + initialize:function(topic) { + this._topic = topic; + } +}); + diff --git a/mindplot/src/main/javascript/model/INodeModel.js b/mindplot/src/main/javascript/model/INodeModel.js index 85a30414..78883e86 100644 --- a/mindplot/src/main/javascript/model/INodeModel.js +++ b/mindplot/src/main/javascript/model/INodeModel.js @@ -289,13 +289,19 @@ mindplot.model.INodeModel = new Class({ } }); +mindplot.model.TopicShape = +{ + RECTANGLE : 'rectagle', + ROUNDED_RECT : 'rounded rectagle', + ELIPSE : 'elipse', + LINE : 'line', + IMAGE : 'image' +}; + + mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic'; mindplot.model.INodeModel.MAIN_TOPIC_TYPE = 'MainTopic'; -mindplot.model.INodeModel.SHAPE_TYPE_RECT = 'rectagle'; -mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT = 'rounded rectagle'; -mindplot.model.INodeModel.SHAPE_TYPE_ELIPSE = 'elipse'; -mindplot.model.INodeModel.SHAPE_TYPE_LINE = 'line'; mindplot.model.INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220;