Fix change shape bug.

This commit is contained in:
Paulo Gustavo Veiga 2012-02-27 22:47:10 -03:00
parent e67b2ba50b
commit 1fefb929da
7 changed files with 54 additions and 24 deletions

View File

@ -55,7 +55,7 @@ mindplot.CentralTopic = new Class({
_defaultShapeType : function() { _defaultShapeType : function() {
return mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT; return mindplot.model.TopicShape.ROUNDED_RECT;
}, },

View File

@ -123,7 +123,7 @@ mindplot.ConnectionLine = new Class({
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
var targetTopicSize = targetTopic.getSize(); var targetTopicSize = targetTopic.getSize();
var y; var y;
if (targetTopic.getShapeType() == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { if (targetTopic.getShapeType() == mindplot.model.TopicShape.LINE) {
y = targetTopicSize.height; y = targetTopicSize.height;
} else { } else {
y = targetTopicSize.height / 2; y = targetTopicSize.height / 2;

View File

@ -656,7 +656,7 @@ mindplot.Designer = new Class({
changeBackgroundColor : function(color) { changeBackgroundColor : function(color) {
var validateFunc = function(topic) { 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 validateError = 'Color can not be set to line topics.';
@ -668,7 +668,7 @@ mindplot.Designer = new Class({
changeBorderColor : function(color) { changeBorderColor : function(color) {
var validateFunc = function(topic) { 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 validateError = 'Color can not be set to line topics.';
var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); var topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError);
@ -686,7 +686,7 @@ mindplot.Designer = new Class({
changeTopicShape : function(shape) { changeTopicShape : function(shape) {
var validateFunc = function(topic) { 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.'; var validateError = 'Central Topic shape can not be changed to line figure.';

View File

@ -56,7 +56,7 @@ mindplot.MainTopic = new Class({
_defaultShapeType : function() { _defaultShapeType : function() {
return mindplot.model.INodeModel.SHAPE_TYPE_LINE; return mindplot.model.TopicShape.LINE;
}, },
updateTopicShape : function(targetTopic, workspace) { updateTopicShape : function(targetTopic, workspace) {
@ -81,7 +81,7 @@ mindplot.MainTopic = new Class({
if (!$defined(shapeType)) { if (!$defined(shapeType)) {
// Change figure ... // Change figure ...
shapeType = this.getShapeType(); 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(); var innerShape = this.getInnerShape();
innerShape.setVisibility(true); innerShape.setVisibility(true);
@ -112,7 +112,7 @@ mindplot.MainTopic = new Class({
var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos);
var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); 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); result.y = result.y + (this.getSize().height / 2);
} }
@ -133,14 +133,15 @@ mindplot.MainTopic = new Class({
workoutOutgoingConnectionPoint : function(targetPosition) { workoutOutgoingConnectionPoint : function(targetPosition) {
$assert(targetPosition, 'targetPoint can not be null'); $assert(targetPosition, 'targetPoint can not be null');
var pos = this.getPosition(); var pos = this.getPosition();
var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos);
var size = this.getSize();
var result; var result;
if (this.getShapeType() == mindplot.model.INodeModel.SHAPE_TYPE_LINE) { if (this.getShapeType() == mindplot.model.TopicShape.LINE) {
result = new core.Point(); result = new core.Point();
var groupPosition = this._elem2d.getPosition(); var groupPosition = this._elem2d.getPosition();
var innerShareSize = this.getInnerShape().getSize(); var innerShareSize = this.getInnerShape().getSize();
var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos);
if (innerShareSize) { if (innerShareSize) {
var magicCorrectionNumber = 0.3; var magicCorrectionNumber = 0.3;
@ -153,7 +154,6 @@ mindplot.MainTopic = new Class({
} else { } else {
// Hack: When the size has not being defined. This is because the node has not being added. // Hack: When the size has not being defined. This is because the node has not being added.
// Try to do our best ... // Try to do our best ...
var size = this.getSize();
if (!isAtRight) { if (!isAtRight) {
result.x = pos.x + (size.width / 2); result.x = pos.x + (size.width / 2);
} else { } else {

View File

@ -55,7 +55,7 @@ mindplot.Topic = new Class({
event.stopPropagation(true); event.stopPropagation(true);
}.bind(this)); }.bind(this));
this._textEditor.addEvent('input', function(event, text) { this._textEditor.addEvent('input', function() {
var textShape = this.getTextShape(); var textShape = this.getTextShape();
// var oldText = textShape.getText(); // var oldText = textShape.getText();
@ -162,16 +162,16 @@ mindplot.Topic = new Class({
type = this.getShapeType(); type = this.getShapeType();
} }
if (type == mindplot.model.INodeModel.SHAPE_TYPE_RECT) { if (type == mindplot.model.TopicShape.RECTANGLE) {
result = new web2d.Rect(0, attributes); 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); 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); 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 = new web2d.Line({strokeColor:"#495879",strokeWidth:1});
result.setSize = function(width, height) { result.setSize = function(width, height) {
this.size = {width:width, height:height}; this.size = {width:width, height:height};
@ -220,7 +220,7 @@ mindplot.Topic = new Class({
getOuterShape : function() { getOuterShape : function() {
if (!$defined(this._outerShape)) { 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.setPosition(-2, -3);
rect.setOpacity(0); rect.setOpacity(0);
this._outerShape = rect; this._outerShape = rect;
@ -596,7 +596,6 @@ mindplot.Topic = new Class({
}, },
isCollapsed : function() { isCollapsed : function() {
var model = this.getModel();
var result = false; var result = false;
var current = this.getParent(); var current = this.getParent();
@ -637,7 +636,7 @@ mindplot.Topic = new Class({
outerShape.setOpacity(1); outerShape.setOpacity(1);
}, },
handleMouseOut : function(event) { handleMouseOut : function() {
var outerShape = this.getOuterShape(); var outerShape = this.getOuterShape();
if (!this.isOnFocus()) { if (!this.isOnFocus()) {
outerShape.setOpacity(0); outerShape.setOpacity(0);
@ -936,7 +935,7 @@ mindplot.Topic = new Class({
} }
}, },
_updatePositionOnChangeSize : function(oldSize, newSize) { _updatePositionOnChangeSize : function() {
$assert(false, "this method must be overwrited."); $assert(false, "this method must be overwrited.");
}, },

View File

@ -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;
}
});

View File

@ -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.CENTRAL_TOPIC_TYPE = 'CentralTopic';
mindplot.model.INodeModel.MAIN_TOPIC_TYPE = 'MainTopic'; 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; mindplot.model.INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220;