/* * 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.Topic = function() { mindplot.Topic.superClass.initialize.call(this); }; objects.extend(mindplot.Topic, mindplot.NodeGraph); mindplot.Topic.prototype.initialize = function() { this._children = []; this._parent = null; this._lastIconId = -1; this._relationships = []; this._isInWorkspace = false; this._helpers = []; this._buildShape(); this.setMouseEventsEnabled(true); // Positionate topic .... var model = this.getModel(); var pos = model.getPosition(); if (pos != null && model.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { this.setPosition(pos); } }; mindplot.Topic.prototype.setShapeType = function(type) { this._setShapeType(type, true); }; mindplot.Topic.prototype.getParent = function() { return this._parent; }; mindplot.Topic.prototype._setShapeType = function(type, updateModel) { // Remove inner shape figure ... var model = this.getModel(); if (updateModel) { model.setShapeType(type); } var innerShape = this.getInnerShape(); if (innerShape != null) { var dispatcherByEventType = innerShape._dispatcherByEventType; // Remove old shape ... this._removeInnerShape(); // Create a new one ... innerShape = this.getInnerShape(); //Let's register all the events. The first one is the default one. The others will be copied. //this._registerDefaultListenersToElement(innerShape, this); var dispatcher = dispatcherByEventType['mousedown']; if(dispatcher) { for(var i = 1; i 0) { var connector = this.getShrinkConnector(); connector.setVisibility(value); } var textShape = this.getTextShape(); textShape.setVisibility(value); }; mindplot.Topic.prototype.setOpacity = function(opacity){ var elem = this.get2DElement(); elem.setOpacity(opacity); this.getShrinkConnector().setOpacity(opacity); var textShape = this .getTextShape(); textShape.setOpacity(opacity); }; mindplot.Topic.prototype._setChildrenVisibility = function(isVisible) { // Hide all children. var children = this._getChildren(); var model = this.getModel(); isVisible = isVisible ? !model.areChildrenShrinked() : isVisible; for (var i = 0; i < children.length; i++) { var child = children[i]; child.setVisibility(isVisible); var outgoingLine = child.getOutgoingLine(); outgoingLine.setVisibility(isVisible); } } mindplot.Topic.prototype.invariant = function() { var line = this._outgoingLine; var model = this.getModel(); var isConnected = model.isConnected(); // Check consitency... if ((isConnected && !line) || (!isConnected && line)) { // core.assert(false,'Illegal state exception.'); } }; /** * type: * onfocus */ mindplot.Topic.prototype.addEventListener = function(type, listener) { // Translate to web 2d events ... if (type == 'onfocus') { type = 'mousedown'; } /* var textShape = this.getTextShape(); textShape.addEventListener(type, listener); var outerShape = this.getOuterShape(); outerShape.addEventListener(type, listener); var innerShape = this.getInnerShape(); innerShape.addEventListener(type, listener);*/ var shape = this.get2DElement(); shape.addEventListener(type, listener); }; mindplot.Topic.prototype.removeEventListener = function(type, listener) { // Translate to web 2d events ... if (type == 'onfocus') { type = 'mousedown'; } /*var textShape = this.getTextShape(); textShape.removeEventListener(type, listener); var outerShape = this.getOuterShape(); outerShape.removeEventListener(type, listener); var innerShape = this.getInnerShape(); innerShape.removeEventListener(type, listener);*/ var shape = this.get2DElement(); shape.removeEventListener(type, listener); }; mindplot.Topic.prototype._setSize = function(size) { core.assert(size, "size can not be null"); core.assert(core.Utils.isDefined(size.width), "size seem not to be a valid element"); mindplot.Topic.superClass.setSize.call(this, size); var outerShape = this.getOuterShape(); var innerShape = this.getInnerShape(); var connector = this.getShrinkConnector(); outerShape.setSize(size.width + 4, size.height + 6); innerShape.setSize(size.width, size.height); }; mindplot.Topic.prototype.setSize = function(size, force, updatePosition) { var oldSize = this.getSize(); if (oldSize.width != size.width || oldSize.height != size.height || force) { this._setSize(size); // Update the figure position(ej: central topic must be centered) and children position. this._updatePositionOnChangeSize(oldSize, size, updatePosition); mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeResizeEvent,[this]); } }; mindplot.Topic.prototype._updatePositionOnChangeSize = function(oldSize, newSize, updatePosition) { core.assert(false, "this method must be overided"); }; mindplot.Topic.prototype.disconnect = function(workspace) { var outgoingLine = this.getOutgoingLine(); if (outgoingLine) { core.assert(workspace, 'workspace can not be null'); this._outgoingLine = null; // Disconnect nodes ... var targetTopic = outgoingLine.getTargetTopic(); targetTopic._removeChild(this); // Update model ... var childModel = this.getModel(); childModel.disconnect(); this._parent = null; // Remove graphical element from the workspace... outgoingLine.removeFromWorkspace(workspace); // Remove from workspace. mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeDisconnectEvent,[targetTopic, this]); // Change text based on the current connection ... var model = this.getModel(); if (!model.getText()) { var text = this.getText(); this._setText(text, false); } if (!model.getFontSize()) { var size = this.getFontSize(); this.setFontSize(size, false); } // Hide connection line?. if (targetTopic._getChildren().length == 0) { var connector = targetTopic.getShrinkConnector(); connector.setVisibility(false); } } }; mindplot.Topic.prototype.getOrder = function() { var model = this.getModel(); return model.getOrder(); }; mindplot.Topic.prototype.moveToFront = function() { var elem2d = this.get2DElement(); elem2d.moveToFront(); }; mindplot.Topic.prototype.setOrder = function(value) { var model = this.getModel(); model.setOrder(value); }; mindplot.Topic.prototype.connectTo = function(targetTopic, workspace, isVisible) { core.assert(!this._outgoingLine, 'Could not connect an already connected node'); core.assert(targetTopic != this, 'Cilcular connection are not allowed'); core.assert(targetTopic, 'Parent Graph can not be null'); core.assert(workspace, 'Workspace can not be null'); // Connect Graphical Nodes ... targetTopic._appendChild(this); this._parent = targetTopic; // Update model ... var targetModel = targetTopic.getModel(); var childModel = this.getModel(); childModel.connectTo(targetModel); // Update topic position based on the state ... mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeConnectEvent,[targetTopic, this]); // Create a connection line ... var outgoingLine = new mindplot.ConnectionLine(this, targetTopic); if(core.Utils.isDefined(isVisible)) outgoingLine.setVisibility(isVisible); this._outgoingLine = outgoingLine; workspace.appendChild(outgoingLine); // Update figure is necessary. this.updateTopicShape(targetTopic); // Change text based on the current connection ... var model = this.getModel(); if (!model.getText()) { var text = this.getText(); this._setText(text, false); } if (!model.getFontSize()) { var size = this.getFontSize(); this.setFontSize(size, false); } var textShape = this.getTextShape(); // Display connection node... var connector = targetTopic.getShrinkConnector(); connector.setVisibility(true); // Redraw line ... outgoingLine.redraw(); }; mindplot.Topic.prototype._appendChild = function(child) { var children = this._getChildren(); children.push(child); }; mindplot.Topic.prototype._removeChild = function(child) { var children = this._getChildren(); children.remove(child); }; mindplot.Topic.prototype._getChildren = function() { var result = this._children; if (!result) { this._children = []; result = this._children; } return result; }; mindplot.Topic.prototype.removeFromWorkspace = function(workspace) { var elem2d = this.get2DElement(); workspace.removeChild(elem2d); var line = this.getOutgoingLine(); if (line) { workspace.removeChild(line); } this._isInWorkspace=false; }; mindplot.Topic.prototype.addToWorkspace = function(workspace) { var elem = this.get2DElement(); workspace.appendChild(elem); this._isInWorkspace=true; }; mindplot.Topic.prototype.isInWorkspace = function(){ return this._isInWorkspace; }; mindplot.Topic.prototype.createDragNode = function() { var dragNode = mindplot.Topic.superClass.createDragNode.call(this); // Is the node already connected ? var targetTopic = this.getOutgoingConnectedTopic(); if (targetTopic) { dragNode.connectTo(targetTopic); } return dragNode; }; mindplot.Topic.prototype.updateNode = function(updatePosition) { if(this.isInWorkspace()){ var textShape = this.getTextShape(); var sizeWidth = textShape.getWidth(); var sizeHeight = textShape.getHeight(); var font = textShape.getFont(); var iconOffset = this.getIconOffset(); var height = sizeHeight + this._offset; var width = sizeWidth + this._offset*2 + iconOffset; var pos = this._offset /2; if(this.getShapeType()==mindplot.NodeModel.SHAPE_TYPE_ELIPSE){ var factor = 0.25; height = (width*factor