- Remove getTopicType flag.

This commit is contained in:
Paulo Gustavo Veiga 2012-09-20 09:23:48 -03:00
parent 8a8922f2a6
commit a0ee153ca0
5 changed files with 291 additions and 265 deletions

View File

@ -40,20 +40,11 @@ mindplot.CentralTopic = new Class({
return 11; return 11;
}, },
getTopicType:function () {
return mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE;
},
setCursor:function (type) { setCursor:function (type) {
type = (type == 'move') ? 'default' : type; type = (type == 'move') ? 'default' : type;
this.parent(type); this.parent(type);
}, },
isConnectedToCentralTopic:function () {
return false;
},
_defaultShapeType:function () { _defaultShapeType:function () {
return mindplot.model.TopicShape.ROUNDED_RECT; return mindplot.model.TopicShape.ROUNDED_RECT;
}, },

View File

@ -116,7 +116,6 @@ mindplot.Designer = new Class({
}, },
addEvent:function (type, listener) { addEvent:function (type, listener) {
if (type == mindplot.TopicEvent.EDIT || type == mindplot.TopicEvent.CLICK) { if (type == mindplot.TopicEvent.EDIT || type == mindplot.TopicEvent.CLICK) {
var editor = mindplot.TopicEventDispatcher.getInstance(); var editor = mindplot.TopicEventDispatcher.getInstance();
@ -161,6 +160,48 @@ mindplot.Designer = new Class({
} }
}.bind(this)); }.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) { _buildDragManager:function (workspace) {
@ -362,7 +403,7 @@ mindplot.Designer = new Class({
// Exclude central topic .. // Exclude central topic ..
topics = topics.filter(function (topic) { topics = topics.filter(function (topic) {
return topic.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE return !topic.isCentralTopic();
}); });
this._clipboard = topics.map(function (topic) { this._clipboard = topics.map(function (topic) {
@ -692,7 +733,7 @@ mindplot.Designer = new Class({
}, },
_removeTopic:function (node) { _removeTopic:function (node) {
if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (!node.isCentralTopic()) {
var parent = node._parent; var parent = node._parent;
node.disconnect(this._workspace); node.disconnect(this._workspace);
@ -722,14 +763,14 @@ mindplot.Designer = new Class({
// If there are more than one node selected, // If there are more than one node selected,
$notify($msg('ENTITIES_COULD_NOT_BE_DELETED')); $notify($msg('ENTITIES_COULD_NOT_BE_DELETED'));
return; 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')); $notify($msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED'));
return; return;
} }
// If the central topic has been selected, I must filter ir // If the central topic has been selected, I must filter ir
var topicIds = topics.filter(function (topic) { var topicIds = topics.filter(function (topic) {
return topic.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE return !topic.isCentralTopic();
}).map(function (topic) { }).map(function (topic) {
return topic.getId() return topic.getId()
}); });

View File

@ -228,7 +228,7 @@ mindplot.DesignerKeyboard = new Class({
'right':function () { 'right':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (node.isCentralTopic()) {
this._goToSideChild(designer, node, 'RIGHT'); this._goToSideChild(designer, node, 'RIGHT');
} }
else { else {
@ -248,7 +248,7 @@ mindplot.DesignerKeyboard = new Class({
'left':function () { 'left':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (node.isCentralTopic()) {
this._goToSideChild(designer, node, 'LEFT'); this._goToSideChild(designer, node, 'LEFT');
} }
else { else {
@ -268,7 +268,7 @@ mindplot.DesignerKeyboard = new Class({
'up':function () { 'up':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (!node.isCentralTopic()) {
this._goToBrother(designer, node, 'UP'); this._goToBrother(designer, node, 'UP');
} }
} else { } else {
@ -280,7 +280,7 @@ mindplot.DesignerKeyboard = new Class({
'down':function () { 'down':function () {
var node = model.selectedTopic(); var node = model.selectedTopic();
if (node) { if (node) {
if (node.getTopicType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (!node.isCentralTopic()) {
this._goToBrother(designer, node, 'DOWN'); this._goToBrother(designer, node, 'DOWN');
} }
} else { } else {

View File

@ -1,248 +1,236 @@
/* /*
* Copyright [2011] [wisemapping] * Copyright [2011] [wisemapping]
* *
* Licensed under WiseMapping Public License, Version 1.0 (the "License"). * Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the * It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page; * "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the license at * You may obtain a copy of the license at
* *
* http://www.wisemapping.org/license * http://www.wisemapping.org/license
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
mindplot.MainTopic = new Class({ mindplot.MainTopic = new Class({
Extends:mindplot.Topic, Extends:mindplot.Topic,
initialize:function (model, options) { initialize:function (model, options) {
this.parent(model, options); this.parent(model, options);
}, },
INNER_RECT_ATTRIBUTES:{stroke:'0.5 solid #009900'}, INNER_RECT_ATTRIBUTES:{stroke:'0.5 solid #009900'},
_buildDragShape:function () { _buildDragShape:function () {
var innerShape = this._buildShape(this.INNER_RECT_ATTRIBUTES, this.getShapeType()); var innerShape = this._buildShape(this.INNER_RECT_ATTRIBUTES, this.getShapeType());
var size = this.getSize(); var size = this.getSize();
innerShape.setSize(size.width, size.height); innerShape.setSize(size.width, size.height);
innerShape.setPosition(0, 0); innerShape.setPosition(0, 0);
innerShape.setOpacity(0.5); innerShape.setOpacity(0.5);
innerShape.setCursor('default'); innerShape.setCursor('default');
innerShape.setVisibility(true); innerShape.setVisibility(true);
var brColor = this.getBorderColor(); var brColor = this.getBorderColor();
innerShape.setAttribute("strokeColor", brColor); innerShape.setAttribute("strokeColor", brColor);
var bgColor = this.getBackgroundColor(); var bgColor = this.getBackgroundColor();
innerShape.setAttribute("fillColor", bgColor); innerShape.setAttribute("fillColor", bgColor);
// Create group ... // Create group ...
var groupAttributes = {width:100, height:100, coordSizeWidth:100, coordSizeHeight:100}; var groupAttributes = {width:100, height:100, coordSizeWidth:100, coordSizeHeight:100};
var group = new web2d.Group(groupAttributes); var group = new web2d.Group(groupAttributes);
group.appendChild(innerShape); group.appendChild(innerShape);
// Add Text ... // Add Text ...
if (this.getShapeType() != mindplot.model.TopicShape.IMAGE) { if (this.getShapeType() != mindplot.model.TopicShape.IMAGE) {
var textShape = this._buildTextShape(true); var textShape = this._buildTextShape(true);
var text = this.getText(); var text = this.getText();
textShape.setText(text); textShape.setText(text);
textShape.setOpacity(0.5); textShape.setOpacity(0.5);
group.appendChild(textShape); group.appendChild(textShape);
} }
return group; return group;
}, },
_defaultShapeType:function () { _defaultShapeType:function () {
return mindplot.model.TopicShape.LINE; return mindplot.model.TopicShape.LINE;
}, },
updateTopicShape:function (targetTopic, workspace) { updateTopicShape:function (targetTopic, workspace) {
// Change figure based on the connected topic ... // Change figure based on the connected topic ...
var model = this.getModel(); var model = this.getModel();
var shapeType = model.getShapeType(); var shapeType = model.getShapeType();
if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
if (!$defined(shapeType)) { if (!$defined(shapeType)) {
// Get the real shape type ... // Get the real shape type ...
shapeType = this.getShapeType(); shapeType = this.getShapeType();
this._setShapeType(shapeType, false); this._setShapeType(shapeType, false);
} }
} }
}, },
disconnect:function (workspace) { disconnect:function (workspace) {
this.parent(workspace); this.parent(workspace);
var size = this.getSize(); var size = this.getSize();
var model = this.getModel(); var model = this.getModel();
var shapeType = model.getShapeType(); var shapeType = model.getShapeType();
if (!$defined(shapeType)) { if (!$defined(shapeType)) {
// Change figure ... // Change figure ...
shapeType = this.getShapeType(); shapeType = this.getShapeType();
this._setShapeType(mindplot.model.TopicShape.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);
}, },
getTopicType:function () { _updatePositionOnChangeSize:function (oldSize, newSize) {
return "MainTopic";
}, var xOffset = Math.round((newSize.width - oldSize.width) / 2);
var pos = this.getPosition();
_updatePositionOnChangeSize:function (oldSize, newSize) { if ($defined(pos)) {
if (pos.x > 0) {
var xOffset = Math.round((newSize.width - oldSize.width) / 2); pos.x = pos.x + xOffset;
var pos = this.getPosition(); } else {
if ($defined(pos)) { pos.x = pos.x - xOffset;
if (pos.x > 0) { }
pos.x = pos.x + xOffset; this.setPosition(pos);
} 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();
workoutIncomingConnectionPoint:function (sourcePosition) {
$assert(sourcePosition, 'sourcePoint can not be null'); var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos);
var pos = this.getPosition(); var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight);
var size = this.getSize(); if (this.getShapeType() == mindplot.model.TopicShape.LINE) {
result.y = result.y + (this.getSize().height / 2);
var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); }
var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight);
if (this.getShapeType() == mindplot.model.TopicShape.LINE) { // Move a little the position...
result.y = result.y + (this.getSize().height / 2); var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
} if (this.getPosition().x > 0) {
result.x = result.x + offset;
// Move a little the position... } else {
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; result.x = result.x - offset;
if (this.getPosition().x > 0) { }
result.x = result.x + offset;
} else { result.x = Math.ceil(result.x);
result.x = result.x - offset; result.y = Math.ceil(result.y);
} return result;
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);
workoutOutgoingConnectionPoint:function (targetPosition) { var size = this.getSize();
$assert(targetPosition, 'targetPoint can not be null');
var pos = this.getPosition(); var result;
var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); if (this.getShapeType() == mindplot.model.TopicShape.LINE) {
var size = this.getSize();
result = new core.Point();
var result; var groupPosition = this._elem2d.getPosition();
if (this.getShapeType() == mindplot.model.TopicShape.LINE) { var innerShareSize = this.getInnerShape().getSize();
result = new core.Point(); if (innerShareSize) {
var groupPosition = this._elem2d.getPosition(); var magicCorrectionNumber = 0.3;
var innerShareSize = this.getInnerShape().getSize(); if (!isAtRight) {
result.x = groupPosition.x + innerShareSize.width - magicCorrectionNumber;
if (innerShareSize) { } else {
var magicCorrectionNumber = 0.3; result.x = groupPosition.x + magicCorrectionNumber;
if (!isAtRight) { }
result.x = groupPosition.x + innerShareSize.width - magicCorrectionNumber; result.y = groupPosition.y + innerShareSize.height;
} else { } else {
result.x = groupPosition.x + magicCorrectionNumber; // Hack: When the size has not being defined. This is because the node has not being added.
} // Try to do our best ...
result.y = groupPosition.y + innerShareSize.height; if (!isAtRight) {
} else { result.x = pos.x + (size.width / 2);
// Hack: When the size has not being defined. This is because the node has not being added. } else {
// Try to do our best ... result.x = pos.x - (size.width / 2);
if (!isAtRight) { }
result.x = pos.x + (size.width / 2); result.y = pos.y + (size.height / 2);
} else { }
result.x = pos.x - (size.width / 2);
} } else {
result.y = pos.y + (size.height / 2); result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true);
} }
return result;
} else { },
result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true);
} _getInnerPadding:function () {
return result; var result;
}, var parent = this.getModel().getParent();
if (parent && mindplot.model.INodeModel.MAIN_TOPIC_TYPE == parent.getType()) {
_getInnerPadding:function () { result = 3;
var result; }
var parent = this.getModel().getParent(); else {
if (parent && mindplot.model.INodeModel.MAIN_TOPIC_TYPE == parent.getType()) { result = 4;
result = 3; }
} return result;
else { },
result = 4;
} _defaultText:function () {
return result; var targetTopic = this.getOutgoingConnectedTopic();
}, var result = "";
if ($defined(targetTopic)) {
isConnectedToCentralTopic:function () { if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
var model = this.getModel(); result = $msg('MAIN_TOPIC');
var parent = model.getParent(); } else {
result = $msg('SUB_TOPIC');
return parent && parent.getType() === mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE; }
}, } else {
result = $msg('ISOLATED_TOPIC');
_defaultText:function () { }
var targetTopic = this.getOutgoingConnectedTopic(); return result;
var result = ""; },
if ($defined(targetTopic)) {
if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { _defaultFontStyle:function () {
result = $msg('MAIN_TOPIC'); var targetTopic = this.getOutgoingConnectedTopic();
} else { var result;
result = $msg('SUB_TOPIC'); if ($defined(targetTopic)) {
} if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
} else { result = {
result = $msg('ISOLATED_TOPIC'); font:"Arial",
; size:8,
} style:"normal",
return result; weight:"normal",
}, color:"rgb(82,92,97)"
};
_defaultFontStyle:function () { } else {
var targetTopic = this.getOutgoingConnectedTopic(); result = {
var result; font:"Arial",
if ($defined(targetTopic)) { size:6,
if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { style:"normal",
result = { weight:"normal",
font:"Arial", color:"rgb(82,92,97)"
size:8, };
style:"normal", }
weight:"normal", } else {
color:"rgb(82,92,97)" result = {
}; font:"Verdana",
} else { size:8,
result = { style:"normal",
font:"Arial", weight:"normal",
size:6, color:"rgb(82,92,97)"
style:"normal", };
weight:"normal", }
color:"rgb(82,92,97)" return result;
}; },
}
} else { _defaultBackgroundColor:function () {
result = { return "rgb(224,229,239)";
font:"Verdana", },
size:8,
style:"normal", _defaultBorderColor:function () {
weight:"normal", return 'rgb(2,59,185)';
color:"rgb(82,92,97)" }
};
}
return result;
},
_defaultBackgroundColor:function () {
return "rgb(224,229,239)";
},
_defaultBorderColor:function () {
return 'rgb(2,59,185)';
}
}); });

View File

@ -1216,7 +1216,13 @@ mindplot.Topic = new Class({
} }
} }
return result; return result;
},
isCentralTopic:function () {
return this.getModel().getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE;
} }
}); });