Add support for shink on collapsed nodes.

This commit is contained in:
Paulo Veiga 2012-01-11 23:30:26 -03:00
parent 51bc3e563a
commit ef2902d724
20 changed files with 76 additions and 87 deletions

View File

@ -394,7 +394,7 @@ mindplot.Designer = new Class({
getMindmapProperties : function() {
return {zoom:this.getModel().getZoom(), layoutManager:this._layoutManager.getClassName()};
return {zoom:this.getModel().getZoom()};
},
loadMap : function(mindmapModel) {

View File

@ -39,8 +39,8 @@ mindplot.DesignerKeyboard = new Class({
var node = model.selectedTopic();
if (node) {
var model = topic.getModel();
var isShrink = !model.areChildrenShrinked();
topic.setChildrenShrinked(isShrink);
var isShrink = !model.areChildrenShrunken();
topic.setChildrenShrunken(isShrink);
}
}.bind(this),
@ -141,7 +141,7 @@ mindplot.DesignerKeyboard = new Class({
if (node.getPosition().x < 0) {
this._goToParent(designer, node);
}
else if (!node.areChildrenShrinked()) {
else if (!node.areChildrenShrunken()) {
this._goToChild(designer, node);
}
}
@ -161,7 +161,7 @@ mindplot.DesignerKeyboard = new Class({
if (node.getPosition().x > 0) {
this._goToParent(designer, node);
}
else if (!node.areChildrenShrinked()) {
else if (!node.areChildrenShrunken()) {
this._goToChild(designer, node);
}
}

View File

@ -60,7 +60,7 @@ mindplot.DragTopic = new Class({
$assert(targetTopic, 'parent can not be null');
var result = true;
if (!targetTopic.areChildrenShrinked() && !targetTopic.isCollapsed()) {
if (!targetTopic.areChildrenShrunken() && !targetTopic.isCollapsed()) {
// Dragged node can not be connected to himself.
if (targetTopic == this._draggedNode) {
result = false;

View File

@ -19,14 +19,14 @@
mindplot.ShirinkConnector = new Class({
initialize: function(topic) {
var elipse = new web2d.Elipse(mindplot.Topic.prototype.INNER_RECT_ATTRIBUTES);
this._elipse = elipse;
elipse.setFill('rgb(62,118,179)');
var ellipse = new web2d.Elipse(mindplot.Topic.prototype.INNER_RECT_ATTRIBUTES);
this._ellipse = ellipse;
ellipse.setFill('rgb(62,118,179)');
elipse.setSize(mindplot.Topic.CONNECTOR_WIDTH, mindplot.Topic.CONNECTOR_WIDTH);
elipse.addEvent('click', function(event) {
ellipse.setSize(mindplot.Topic.CONNECTOR_WIDTH, mindplot.Topic.CONNECTOR_WIDTH);
ellipse.addEvent('click', function(event) {
var model = topic.getModel();
var collapse = !model.areChildrenShrinked();
var collapse = !model.areChildrenShrunken();
var topicId = topic.getId();
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
@ -36,34 +36,35 @@ mindplot.ShirinkConnector = new Class({
});
elipse.addEvent('mousedown', function(event) {
ellipse.addEvent('mousedown', function(event) {
// Avoid node creation ...
event.stopPropagation();
});
elipse.addEvent('dblclick', function(event) {
ellipse.addEvent('dblclick', function(event) {
// Avoid node creation ...
event.stopPropagation();
});
elipse.addEvent('mouseover', function(event) {
ellipse.addEvent('mouseover', function(event) {
elipse.setFill('rgb(153, 0, 255)');
ellipse.setFill('rgb(153, 0, 255)');
});
elipse.addEvent('mouseout', function(event) {
ellipse.addEvent('mouseout', function(event) {
var color = topic.getBackgroundColor();
this.setFill(color);
}.bind(this));
elipse.setCursor('default');
ellipse.setCursor('default');
this._fillColor = '#f7f7f7';
var model = topic.getModel();
this.changeRender(model.areChildrenShrinked());
this.changeRender(model.areChildrenShrunken());
},
changeRender: function(isShrink) {
var elipse = this._elipse;
var elipse = this._ellipse;
if (isShrink) {
elipse.setStroke('2', 'solid');
} else {
@ -72,36 +73,35 @@ mindplot.ShirinkConnector = new Class({
},
setVisibility: function(value) {
this._elipse.setVisibility(value);
this._ellipse.setVisibility(value);
},
setOpacity: function(opacity) {
this._elipse.setOpacity(opacity);
this._ellipse.setOpacity(opacity);
},
setFill: function(color) {
this._fillColor = color;
this._elipse.setFill(color);
this._ellipse.setFill(color);
},
setAttribute: function(name, value) {
this._elipse.setAttribute(name, value);
this._ellipse.setAttribute(name, value);
},
addToWorkspace: function(group) {
group.appendChild(this._elipse);
group.appendChild(this._ellipse);
},
setPosition: function(x, y) {
this._elipse.setPosition(x, y);
this._ellipse.setPosition(x, y);
},
moveToBack: function() {
this._elipse.moveToBack();
this._ellipse.moveToBack();
},
moveToFront: function() {
this._elipse.moveToFront();
this._ellipse.moveToFront();
}
});

View File

@ -220,7 +220,7 @@ mindplot.StandaloneActionDispatcher = new Class({
$assert(topicsIds, "topicsIds can not be null");
var commandFunc = function(topic, isShrink) {
topic.setChildrenShrinked(isShrink);
topic.setChildrenShrunken(isShrink);
return !isShrink;
};

View File

@ -696,9 +696,9 @@ mindplot.Topic = new Class({
elem.addEvent('mousedown', mouseDown);
},
areChildrenShrinked : function() {
areChildrenShrunken : function() {
var model = this.getModel();
return model.areChildrenShrinked();
return model.areChildrenShrunken();
},
isCollapsed : function() {
@ -707,16 +707,16 @@ mindplot.Topic = new Class({
var current = this.getParent();
while (current && !result) {
result = current.areChildrenShrinked();
result = current.areChildrenShrunken();
current = current.getParent();
}
return result;
},
setChildrenShrinked : function(value) {
setChildrenShrunken : function(value) {
// Update Model ...
var model = this.getModel();
model.setChildrenShrinked(value);
model.setChildrenShrunken(value);
// Change render base on the state.
var shrinkConnector = this.getShrinkConnector();
@ -724,7 +724,7 @@ mindplot.Topic = new Class({
// Hide children ...
core.Utils.setChildrenVisibilityAnimated(this, !value);
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeShrinkEvent, [this]);
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeShrinkEvent, this.getModel());
},
getShrinkConnector : function() {
@ -741,7 +741,6 @@ mindplot.Topic = new Class({
handleMouseOver : function() {
var outerShape = this.getOuterShape();
outerShape.setOpacity(1);
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOverEvent, [this]);
},
handleMouseOut : function(event) {
@ -749,7 +748,6 @@ mindplot.Topic = new Class({
if (!this.isOnFocus()) {
outerShape.setOpacity(0);
}
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent, [this]);
},
showTextEditor : function(text) {
@ -993,7 +991,7 @@ mindplot.Topic = new Class({
var children = this._getChildren();
var model = this.getModel();
isVisible = isVisible ? !model.areChildrenShrinked() : isVisible;
isVisible = isVisible ? !model.areChildrenShrunken() : isVisible;
for (var i = 0; i < children.length; i++) {
var child = children[i];
child.setVisibility(isVisible);
@ -1067,7 +1065,6 @@ mindplot.Topic = new Class({
outgoingLine.removeFromWorkspace(workspace);
// Remove from workspace.
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.ONodeDisconnectEvent, [targetTopic, this]);
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent, this.getModel());
// Change text based on the current connection ...
@ -1114,9 +1111,6 @@ mindplot.Topic = new Class({
var childModel = this.getModel();
childModel.connectTo(targetModel);
// Update topic position based on the state ...
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.ONodeConnectEvent, [targetTopic, this]);
// Create a connection line ...
var outgoingLine = new mindplot.ConnectionLine(this, targetTopic);
if ($defined(isVisible))

View File

@ -67,7 +67,7 @@ mindplot.XMLMindmapSerializer_Beta = new Class({
parentTopic.setAttribute('shape', shape);
}
if (topic.areChildrenShrinked()) {
if (topic.areChildrenShrunken()) {
parentTopic.setAttribute('shrink', true);
}
@ -204,7 +204,7 @@ mindplot.XMLMindmapSerializer_Beta = new Class({
var isShrink = domElem.getAttribute('shrink');
if ($defined(isShrink)) {
topic.setChildrenShrinked(isShrink);
topic.setChildrenShrunken(isShrink);
}
var fontStyle = domElem.getAttribute('fontStyle');

View File

@ -85,7 +85,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
parentTopic.setAttribute('shape', shape);
}
if (topic.areChildrenShrinked()) {
if (topic.areChildrenShrunken()) {
parentTopic.setAttribute('shrink', true);
}
@ -270,7 +270,7 @@ mindplot.XMLMindmapSerializer_Pela = new Class({
var isShrink = domElem.getAttribute('shrink');
if ($defined(isShrink)) {
topic.setChildrenShrinked(isShrink);
topic.setChildrenShrunken(isShrink);
}
var fontStyle = domElem.getAttribute('fontStyle');

View File

@ -27,11 +27,11 @@ mindplot.layout.BaseLayoutManager = new Class({
this._createBoard();
this._designer = designer;
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeResizeEvent, this._nodeResizeEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMoveEvent, this._nodeMoveEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeDisconnectEvent, this._nodeDisconnectEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeConnectEvent, this._nodeConnectEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRepositionateEvent, this._nodeRepositionateEvent.bind(this));
mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeMoveEvent, this._nodeMoveEvent.bind(this));
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeDisconnectEvent, this._nodeDisconnectEvent.bind(this));
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.ONodeConnectEvent, this._nodeConnectEvent.bind(this));
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeRepositionateEvent, this._nodeRepositionateEvent.bind(this));
// mindplot.EventBus.instance.addEvent(mindplot.EventBus.events.NodeShrinkEvent, this._nodeShrinkEvent.bind(this));
},
_nodeResizeEvent:function(node) {

View File

@ -131,7 +131,7 @@ mindplot.layout.boards.original.FixedDistanceBoard = new Class({
var entries = this._entries;
var height = 0;
var model = this._topic.getModel();
if (entries.length >= 1 && !model.areChildrenShrinked()) {
if (entries.length >= 1 && !model.areChildrenShrunken()) {
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (e && e.getTopic()) {

View File

@ -163,25 +163,12 @@ mindplot.model.INodeModel = new Class({
this.putProperty('backgroundColor', color);
},
areChildrenShrinked : function() {
return this.getProperty('childrenShrinked');
areChildrenShrunken : function() {
return this.getProperty('shrunken');
},
setChildrenShrinked : function(value) {
this.putProperty('childrenShrinked', value);
},
setFinalPosition : function(x, y) {
$assert(x, "x coordinate must be defined");
$assert(y, "y coordinate must be defined");
this.putProperty('finalPosition', '{x:' + parseInt(x) + ',y:' + parseInt(y) + '}');
},
getFinalPosition : function() {
var value = this.getProperty('finalPosition');
return eval("(" + value + ")");
setChildrenShrunken : function(value) {
this.putProperty('shrunken', value);
},
isNodeModel : function() {

View File

@ -26,7 +26,7 @@ mindplot.model.NodeModel = new Class({
this.parent(mindmap);
this.setId(id);
this.setType(type);
this.areChildrenShrinked(false);
this.areChildrenShrunken(false);
this.setSize(50, 20);
this._children = [];

View File

@ -29,7 +29,7 @@ mindplot.nlayout.AbstractBasicSorter = new Class({
var result;
var children = treeSet.getChildren(node);
if (children.length == 0) {
if (children.length == 0 || node.areChildrenShrunken()) {
result = height;
} else {
var childrenHeight = 0;

View File

@ -33,7 +33,7 @@ mindplot.nlayout.BalancedSorter = new Class({
var result;
var children = treeSet.getChildren(node);
if (children.length == 0) {
if (children.length == 0 || node.areChildrenShrunken()) {
result = height;
} else {
var childrenHeight = 0;

View File

@ -24,13 +24,8 @@ mindplot.EventBus = new Class({
mindplot.EventBus.events = {
NodeResizeEvent:'NodeResizeEvent',
NodeMoveEvent:'NodeMoveEvent',
ONodeDisconnectEvent:'ONodeDisconnectEvent',
ONodeConnectEvent:'ONodeConnectEvent',
NodeRepositionateEvent:'NodeRepositionateEvent',
NodeShrinkEvent:'NodeShrinkEvent',
NodeMouseOverEvent:'NodeMouseOverEvent',
NodeMouseOutEvent:'NodeMouseOutEvent',
NodeConnectEvent:'NodeConnectEvent',
NodeDisconnectEvent:'NodeDisconnectEvent',
NodeAdded:'NodeAdded',

View File

@ -70,7 +70,7 @@ mindplot.nlayout.EventBusDispatcher = new Class({
},
_nodeShrinkEvent: function(node) {
console.log("mindplot.nlayout.EventBusDispatcher._nodeShrinkEvent: Not Implemented yet");
this._layoutManager.updateShrinkState(node.getId(), node.areChildrenShrunken());
},
_nodeAdded: function(node) {

View File

@ -30,15 +30,19 @@ mindplot.nlayout.LayoutManager = new Class({
},
updateNodeSize: function(id, size) {
$assert($defined(id), "id can not be null");
var node = this._treeSet.find(id);
node.setSize(size);
console.log("Size:"+size.width);
// Todo: This must be completed ...
},
updateShirkState: function(id, isShrink) {
// @Todo: finish...
updateShrinkState: function(id, value) {
$assert($defined(id), "id can not be null");
var node = this._treeSet.find(id);
node.setShrunken(value);
},
find: function(id) {
@ -101,7 +105,7 @@ mindplot.nlayout.LayoutManager = new Class({
size = size || {width:200,height:200};
var squaresize = 10;
var canvas = Raphael(containerId, size.width, size.height);
canvas.drawGrid(0, 0, size.width, size.height, size.width/squaresize, size.height/squaresize);
canvas.drawGrid(0, 0, size.width, size.height, size.width / squaresize, size.height / squaresize);
this._treeSet.plot(canvas);
},

View File

@ -28,15 +28,24 @@ mindplot.nlayout.Node = new Class({
this.setSize(size);
this.setPosition(position);
this.setShrunken(false);
},
getId:function() {
return this._id;
},
setShrunken: function(value) {
this._setProperty('shrink', value);
},
areChildrenShrunken: function() {
return this._getProperty('shrink');
},
setOrder: function(order) {
$assert(typeof order === 'number' && isFinite(order), "Order can not be null. Value:" + order);
this._setProperty('order', order, false);
this._setProperty('order', order);
},
resetPositionState : function() {

View File

@ -130,6 +130,6 @@ mindplot.nlayout.SymmetricSorter = new Class({
});
mindplot.nlayout.SymmetricSorter.INTERNODE_VERTICAL_PADDING = 5;
mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING = 5;
mindplot.nlayout.SymmetricSorter.INTERNODE_HORIZONTAL_PADDING = 30;

View File

@ -61,7 +61,7 @@ TestCase("Model Migration Tests",{
assertEquals(position1.x, position2.x);
assertEquals(position1.y, position2.y);
}
assertEquals(node1.areChildrenShrinked(), node2.areChildrenShrinked());
assertEquals(node1.areChildrenShrunken(), node2.areChildrenShrunken());
assertEquals(node1.getType(), node2.getType());
assertEquals(node1.getText(), node2.getText());
assertEquals(node1.isConnected(), node2.isConnected());