wisemapping-open-source/mindplot/src/main/javascript/MainTopicBoard.js

142 lines
4.5 KiB
JavaScript
Raw Normal View History

/*
* Copyright [2011] [wisemapping]
*
2011-01-24 01:03:12 +01:00
* 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.
*/
2011-03-17 16:51:40 +01:00
mindplot.MainTopicBoard = function(topic, layoutManager)
2009-06-07 20:59:43 +02:00
{
2011-03-17 16:51:40 +01:00
this._layoutManager = layoutManager;
2009-06-07 20:59:43 +02:00
this._topic = topic;
this._board = null;
this._height = 0;
};
2011-03-24 19:00:51 +01:00
objects.extend(mindplot.MainTopicBoard, mindplot.Board);
2009-06-07 20:59:43 +02:00
mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT = 18;
mindplot.MainTopicBoard.prototype._getBoard = function()
{
if (!this._board)
{
var topic = this._topic;
2011-03-17 16:51:40 +01:00
this._board = new mindplot.FixedDistanceBoard(mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT, topic, this._layoutManager);
2009-06-07 20:59:43 +02:00
}
return this._board;
};
mindplot.MainTopicBoard.prototype.updateReferencePoint = function(position)
{
this._board.updateReferencePoint(position);
};
mindplot.MainTopicBoard.prototype.updateChildrenPosition = function(topic)
{
var board = this._getBoard();
board.updateReferencePoint();
};
mindplot.MainTopicBoard.prototype.positionateDragTopic = function(dragTopic)
{
core.assert(dragTopic != null, 'dragTopic can not be null');
core.assert(dragTopic.isDragTopic, 'dragTopic must be DragTopic instance');
// This node is a main topic node. Position
var dragPos = dragTopic.getPosition();
var board = this._getBoard();
// Look for entry ...
var entry = board.lookupEntryByPosition(dragPos);
// Calculate 'y' position base on the entry ...
var yCoord;
if (!entry.isAvailable() && entry.getTopic() != dragTopic.getDraggedTopic())
{
yCoord = entry.getLowerLimit();
} else
{
yCoord = entry.workoutEntryYCenter();
}
// Update board position.
var targetTopic = dragTopic.getConnectedToTopic();
var xCoord = this._workoutXBorderDistance(targetTopic);
// Add the size of the pivot to the distance ...
var halfPivotWidth = mindplot.DragTopic.PIVOT_SIZE.width / 2;
xCoord = xCoord + ((dragPos.x > 0) ? halfPivotWidth : -halfPivotWidth);
var pivotPos = new core.Point(xCoord, yCoord);
dragTopic.setBoardPosition(pivotPos);
var order = entry.getOrder();
dragTopic.setOrder(order);
};
/**
* This x distance does't take into account the size of the shape.
*/
mindplot.MainTopicBoard.prototype._workoutXBorderDistance = function(topic)
{
core.assert(topic, 'topic can not be null');
var board = this._getBoard();
return board.workoutXBorderDistance(topic);
};
mindplot.MainTopicBoard.prototype.addBranch = function(topic)
{
var order = topic.getOrder();
core.assert(core.Utils.isDefined(order), "Order must be defined");
// If the entry is not available, I must swap the the entries...
var board = this._getBoard();
var entry = board.lookupEntryByOrder(order);
if (!entry.isAvailable())
{
board.freeEntry(entry);
}
// Add the topic to the board ...
board.addTopic(order, topic);
// Repositionate all the parent topics ...
var currentTopic = this._topic;
if (currentTopic.getOutgoingConnectedTopic())
{
var parentTopic = currentTopic.getOutgoingConnectedTopic();
2011-03-17 16:51:40 +01:00
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent,[parentTopic]);
2009-06-07 20:59:43 +02:00
}
};
mindplot.MainTopicBoard.prototype.repositionate = function()
{
var board = this._getBoard();
board.repositionate();
};
mindplot.MainTopicBoard.prototype.removeTopicFromBoard = function(topic)
{
var board = this._getBoard();
board.removeTopic(topic);
// Repositionate all the parent topics ...
var parentTopic = this._topic;
if (parentTopic.getOutgoingConnectedTopic())
{
var connectedTopic = parentTopic.getOutgoingConnectedTopic();
2011-03-17 16:51:40 +01:00
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent,[connectedTopic]);
2009-06-07 20:59:43 +02:00
}
};