From 7d9af403fea1f5e493732f1b2f19e1596121f879 Mon Sep 17 00:00:00 2001 From: Paulo Veiga Date: Tue, 9 Aug 2011 01:45:24 -0300 Subject: [PATCH] Add a new color picker... --- core-js/pom.xml | 3 +- core-js/src/main/javascript/Functions.js | 26 + core-js/src/main/javascript/Utils.js | 27 - mindplot/pom.xml | 4 +- .../javascript/widget/ColorPalettePanel.js | 140 + .../javascript/widget/ColorPickerPanel.js | 4 +- .../src/main/javascript/widget/IconPanel.js | 11 +- mindplot/src/main/javascript/widget/Menu.js | 36 +- .../main/javascript/widget/ToolbarPanel.js | 35 +- .../main/javascript/widget/colorPalette.css | 74 + .../main/javascript/widget/colorPalette.html | 401 + .../src/test/javascript/static/palette.html | 41 + web2d/pom.xml | 1 + wise-doc/src/main/webapp/css/bubble.css | 242 - wise-doc/src/main/webapp/css/editor.css | 7 +- wise-doc/src/main/webapp/html/editor.html | 5 - wise-doc/src/main/webapp/js/mindplot.svg.js | 10435 ++++++++-------- 17 files changed, 5958 insertions(+), 5534 deletions(-) create mode 100644 core-js/src/main/javascript/Functions.js create mode 100644 mindplot/src/main/javascript/widget/ColorPalettePanel.js create mode 100644 mindplot/src/main/javascript/widget/colorPalette.css create mode 100644 mindplot/src/main/javascript/widget/colorPalette.html create mode 100644 mindplot/src/test/javascript/static/palette.html delete mode 100644 wise-doc/src/main/webapp/css/bubble.css diff --git a/core-js/pom.xml b/core-js/pom.xml index d9008d1b..eb5e4d9d 100644 --- a/core-js/pom.xml +++ b/core-js/pom.xml @@ -50,7 +50,7 @@ ${basedir}/target/tmp/header-min.js ${basedir}/target/tmp/ColorPicker-min.js - ${basedir}/target/tmp/Loader-min.js + ${basedir}/target/tmp/Functions-min.js ${basedir}/target/tmp/log4js-min.js ${basedir}/target/tmp/Monitor-min.js ${basedir}/target/tmp/Point-min.js @@ -64,6 +64,7 @@ true false + true diff --git a/core-js/src/main/javascript/Functions.js b/core-js/src/main/javascript/Functions.js new file mode 100644 index 00000000..28d4b462 --- /dev/null +++ b/core-js/src/main/javascript/Functions.js @@ -0,0 +1,26 @@ +/* + Function: $defined + Returns true if the passed in value/object is defined, that means is not null or undefined. + + Arguments: + obj - object to inspect + */ + +$defined = function(obj) { + return (obj != undefined); +}; + + +$assert = function(assert, message) { + if (!$defined(assert) || !assert) { + var stack; + try { + null.eval(); + } catch(e) { + stack = e; + } + wLogger.error(message + "," + stack); +// core.Logger.logError(message + "," + stack); + + } +}; \ No newline at end of file diff --git a/core-js/src/main/javascript/Utils.js b/core-js/src/main/javascript/Utils.js index 56567599..5dc897d8 100644 --- a/core-js/src/main/javascript/Utils.js +++ b/core-js/src/main/javascript/Utils.js @@ -24,18 +24,6 @@ core.Utils = } }; -/* - Function: $defined - Returns true if the passed in value/object is defined, that means is not null or undefined. - - Arguments: - obj - object to inspect - */ -function $defined(obj) { - return (obj != undefined); -} -; - /** * http://kevlindev.com/tutorials/javascript/inheritance/index.htm * A function used to extend one class with another @@ -58,21 +46,6 @@ objects.extend = function(subClass, baseClass) { subClass.superClass = baseClass.prototype; }; -$assert = function(assert, message) { - if (!$defined(assert) || !assert) { - var stack; - try { - null.eval(); - } catch(e) { - stack = e; - } - wLogger.error(message + "," + stack); -// core.Logger.logError(message + "," + stack); - } - -}; - - Math.sign = function(value) { return (value >= 0) ? 1 : -1; }; diff --git a/mindplot/pom.xml b/mindplot/pom.xml index 61dd3e21..e455fafd 100644 --- a/mindplot/pom.xml +++ b/mindplot/pom.xml @@ -176,6 +176,8 @@ files="widget/ToolbarItem.js"/> + DragTopic-min.js DragManager-min.js DragPivot-min.js - TopicBoard-min.js CentralTopicBoard-min.js MainTopicBoard-min.js ConnectionLine-min.js @@ -324,6 +325,7 @@ true false + true diff --git a/mindplot/src/main/javascript/widget/ColorPalettePanel.js b/mindplot/src/main/javascript/widget/ColorPalettePanel.js new file mode 100644 index 00000000..4ca0b2ff --- /dev/null +++ b/mindplot/src/main/javascript/widget/ColorPalettePanel.js @@ -0,0 +1,140 @@ +/* + * 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.widget.ColorPalettePanel = new Class({ + Extends: mindplot.widget.ToolbarItem, + + initialize : function(buttonId, model, baseUrl) { + this.parent(buttonId, model); + $assert(baseUrl, "baseUrl can not be null"); + + this.getButtonElem().addEvent('click', function() { + // Is the panel being displayed ? + if (this.isVisible()) { + this.hide(); + } else { + this.show(); + } + + }.bind(this)); + this._baseUrl = baseUrl; + }, + + _load : function() { + + if (!mindplot.widget.ColorPalettePanel._panelContent) { + + // Load all the CSS styles ... + Asset.css(this._baseUrl + '/colorPalette.css', {id: 'colorPaletteStyle', title: 'colorPalette'}); + + // Load panel html fragment ... + var result; + var request = new Request({ + url: this._baseUrl + '/colorPalette.html', + method: 'get', + async: false, + onRequest: function() { + console.log("loading ..."); + }, + onSuccess: function(responseText) { + result = responseText; + }, + onFailure: function() { + result = '
Sorry, your request failed :(
'; + } + }); + request.send(); + mindplot.widget.ColorPalettePanel._panelContent = result; + + } + return mindplot.widget.ColorPalettePanel._panelContent; + }, + + _init : function() { + if (!this._panelContent) { + var buttonElem = this.getButtonElem(); + + // Add panel content .. + var panelElem = this.buildPanel(); + panelElem.setStyle('display', 'none'); + panelElem.inject(buttonElem); + + // Register on toolbar elements ... + var colorCells = panelElem.getElements('div[class=palette-colorswatch]'); + var model = this.getModel(); + colorCells.forEach(function(elem) { + elem.addEvent('click', function() { + var color = elem.getStyle("background-color"); + model.setValue(color); + }); + }); + this._panelId = panelElem.id; + this._panelContent = true; + } + + }, + + buildPanel: function() { + var content = new Element("div", {'class':'toolbarPanel','id': this._buttonId + 'colorPalette'}); + content.innerHTML = this._load(); + return content; + }, + + _getPanelElem : function () { + this._init(); + return $(this._panelId); + }, + + show : function() { + if (!this.isVisible()) { + + this.parent(); + var panelElem = this._getPanelElem(); + + // Clear selected cell based on the color ... + var tdCells = panelElem.getElements("td[class='palette-cell palette-cell-selected']"); + tdCells.forEach(function(elem) { + elem.className = 'palette-cell'; + }); + + // Mark the cell as selected ... + var colorCells = panelElem.getElements('div[class=palette-colorswatch]'); + var model = this.getModel(); + colorCells.forEach(function(elem) { + var color = elem.getStyle("background-color"); + if (model.getValue() == color) { + elem.parentNode.className = 'palette-cell palette-cell-selected'; + } + }); + + // Finally, display the dialog ... + panelElem.setStyle('display', 'block'); + } + }, + + hide : function() { + if (this.isVisible()) { + this.parent(); + this._getPanelElem().setStyle('display', 'none'); + } + }, + + isVisible : function() { + return this._getPanelElem().getStyle('display') == 'block'; + } +}); \ No newline at end of file diff --git a/mindplot/src/main/javascript/widget/ColorPickerPanel.js b/mindplot/src/main/javascript/widget/ColorPickerPanel.js index d55f9171..7cc9b668 100644 --- a/mindplot/src/main/javascript/widget/ColorPickerPanel.js +++ b/mindplot/src/main/javascript/widget/ColorPickerPanel.js @@ -16,7 +16,7 @@ * limitations under the License. */ -mindplot.widget.ColorPicker = new Class({ +mindplot.widget.ColorPickerPanel = new Class({ Extends: mindplot.widget.ToolbarItem, initialize : function(buttonId, model) { this.parent(buttonId, model); @@ -29,7 +29,7 @@ mindplot.widget.ColorPicker = new Class({ }.bind(this), onChange: function(color) { this.getModel().setValue(color.hex); - }, + }.bind(this), onComplete: function() { this.hide(); }.bind(this) diff --git a/mindplot/src/main/javascript/widget/IconPanel.js b/mindplot/src/main/javascript/widget/IconPanel.js index 810556a0..bfb4fe9a 100644 --- a/mindplot/src/main/javascript/widget/IconPanel.js +++ b/mindplot/src/main/javascript/widget/IconPanel.js @@ -39,16 +39,17 @@ mindplot.widget.IconPanel = new Class({ var buttonElem = this.getButtonElem(); var coord = buttonElem.getCoordinates(); - var top = buttonElem.getTop() + coord.height + 2; - var left = buttonElem.getLeft(); + var top = buttonElem.getTop() + coord.height + 7; + var left = buttonElem.getLeft() - 6; panel.setStyles({ width:this.options.initialWidth, - height:0,position:'absolute', + height:0, + position:'absolute', top:top, left:left, - background:'#e5e5e5', - border:'1px solid #BBB4D6', + background:'#ffffff', + 'border-color':'#CCC #666 #666 #CCC;', zIndex:20, overflow:'hidden'} ); diff --git a/mindplot/src/main/javascript/widget/Menu.js b/mindplot/src/main/javascript/widget/Menu.js index a781685f..34db3b57 100644 --- a/mindplot/src/main/javascript/widget/Menu.js +++ b/mindplot/src/main/javascript/widget/Menu.js @@ -20,6 +20,8 @@ mindplot.widget.Menu = new Class({ initialize : function(designer, containerId) { $assert(designer, "designer can not be null"); $assert(containerId, "containerId can not be null"); + // @Todo: Remove hardcode ... + var baseUrl = "/mindplot/src/main/javascript/widget"; // Init variables ... this._designer = designer; @@ -29,18 +31,19 @@ mindplot.widget.Menu = new Class({ // Stop event propagation ... $(this._containerId).addEvent('click', function(event) { event.stopPropagation(); + return false; }); $(this._containerId).addEvent('dblclick', function(event) { event.stopPropagation(); + return false; }); // Create panels ... var fontFamilyModel = { getValue: function() { var nodes = designer.getSelectedNodes(); - var length = nodes.length; - if (length == 1) { + if (nodes.length == 1) { return nodes[0].getFontFamily(); } }, @@ -55,8 +58,7 @@ mindplot.widget.Menu = new Class({ var fontSizeModel = { getValue: function() { var nodes = designer.getSelectedNodes(); - var length = nodes.length; - if (length == 1) { + if (nodes.length == 1) { return nodes[0].getFontSize(); } }, @@ -69,8 +71,7 @@ mindplot.widget.Menu = new Class({ var topicShapeModel = { getValue: function() { var nodes = designer.getSelectedNodes(); - var length = nodes.length; - if (length == 1) { + if (nodes.length == 1) { return nodes[0].getShapeType(); } }, @@ -95,38 +96,47 @@ mindplot.widget.Menu = new Class({ var topicColorModel = { getValue : function() { + var nodes = designer.getSelectedNodes(); + if (nodes.length == 1) { + return nodes[0].getBackgroundColor(); + } return null; }, setValue : function (hex) { designer.setBackColor2SelectedNode(hex); } }; - this._toolbarElems.push(new mindplot.widget.ColorPicker('topicColor', topicColorModel)); + this._toolbarElems.push(new mindplot.widget.ColorPalettePanel('topicColor', topicColorModel, baseUrl)); // Border color item ... var borderColorModel = { getValue : function() { - return null; + var nodes = designer.getSelectedNodes(); + if (nodes.length == 1) { + return nodes[0].getBorderColor(); + } }, setValue : function (hex) { designer.setBorderColor2SelectedNode(hex); } }; - this._toolbarElems.push(new mindplot.widget.ColorPicker('topicBorder', borderColorModel)); + this._toolbarElems.push(new mindplot.widget.ColorPalettePanel('topicBorder', borderColorModel, baseUrl)); // Font color item ... var fontColorModel = { getValue : function() { - return null; + var nodes = designer.getSelectedNodes(); + if (nodes.length == 1) { + return nodes[0].getFontColor(); + } }, setValue : function (hex) { designer.setFontColor2SelectedNode(hex); } }; - var fontColorPicker = new mindplot.widget.ColorPicker('fontColor', fontColorModel); - this._toolbarElems.push(fontColorPicker); + this._toolbarElems.push(new mindplot.widget.ColorPalettePanel('fontColor', fontColorModel, baseUrl)); // Register on close events ... this._toolbarElems.forEach(function(elem) { @@ -198,8 +208,6 @@ mindplot.widget.Menu = new Class({ } }); - - }, clear : function() { diff --git a/mindplot/src/main/javascript/widget/ToolbarPanel.js b/mindplot/src/main/javascript/widget/ToolbarPanel.js index 6d33460f..d0c2f787 100644 --- a/mindplot/src/main/javascript/widget/ToolbarPanel.js +++ b/mindplot/src/main/javascript/widget/ToolbarPanel.js @@ -41,6 +41,7 @@ mindplot.widget.ToolbarPanel = new Class({ elem.addEvent('click', function(event) { var value = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id; this.getModel().setValue(value); + event.stopPropagation(); this.hide(); }.bind(this)); }.bind(this)); @@ -54,31 +55,31 @@ mindplot.widget.ToolbarPanel = new Class({ } else { this.show(); } - }.bind(this)); return panelElem.id; }, show : function() { - this.parent(); - - var menuElems = $(this._panelId).getElements('div'); - var value = this.getModel().getValue(); - menuElems.forEach(function(elem) { - var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id; - if (elemValue == value) - elem.className = "toolbarPanelLinkSelectedLink"; - else - elem.className = "toolbarPanelLink"; - }); - $(this._panelId).setStyle('display', 'block'); - + if (!this.isVisible()) { + this.parent(); + var menuElems = $(this._panelId).getElements('div'); + var value = this.getModel().getValue(); + menuElems.forEach(function(elem) { + var elemValue = $defined(elem.getAttribute('model')) ? elem.getAttribute('model') : elem.id; + if (elemValue == value) + elem.className = "toolbarPanelLinkSelectedLink"; + else + elem.className = "toolbarPanelLink"; + }); + $(this._panelId).setStyle('display', 'block'); + } }, hide : function() { - this.parent(); - $(this._panelId).setStyle('display', 'none'); - + if (this.isVisible()) { + this.parent(); + $(this._panelId).setStyle('display', 'none'); + } }, isVisible : function() { diff --git a/mindplot/src/main/javascript/widget/colorPalette.css b/mindplot/src/main/javascript/widget/colorPalette.css new file mode 100644 index 00000000..28a8e170 --- /dev/null +++ b/mindplot/src/main/javascript/widget/colorPalette.css @@ -0,0 +1,74 @@ +.palette-panel { + /*background: white;*/ + /*border-color: #CCC #666 #666 #CCC;*/ + /*border-style: solid;*/ + /*border-width: 1px;*/ + cursor: default; + font: normal 13px Arial, sans-serif; + margin: 0; + outline: none; + padding: 4px 0; + z-index: 20000; + -webkit-user-select: none; +} + +.palette { + cursor: default; + outline: none; +} + +.palette-table { + border: 1px solid #666; + border-collapse: collapse; + margin: 5px; +} + +tbody { + display: table-row-group; + vertical-align: middle; + border-color: inherit; +} + +.palette-table { + border-collapse: collapse; +} + +tr { + display: table-row; + vertical-align: inherit; + border-color: inherit; +} + +.palette-cell { + border: 0; + border-right: 1px solid #666; + cursor: pointer; + height: 18px; + margin: 0; + text-align: center; + vertical-align: middle; + width: 18px; +} + +.palette-cell .palette-colorswatch { + border: none; + font-size: x-small; + height: 18px; + position: relative; + width: 18px; +} + +.palette-cell-selected .palette-colorswatch { + background: url(//ssl.gstatic.com/editor/editortoolbar.png) no-repeat -368px 0; + border: 1px solid #333; + color: white; + font-weight: bold; + height: 16px; + width: 16px; +} + +.palette-colorswatch:hover { + border: 1px solid white; + height: 16px; + width: 16px; +} \ No newline at end of file diff --git a/mindplot/src/main/javascript/widget/colorPalette.html b/mindplot/src/main/javascript/widget/colorPalette.html new file mode 100644 index 00000000..0b9a6791 --- /dev/null +++ b/mindplot/src/main/javascript/widget/colorPalette.html @@ -0,0 +1,401 @@ + diff --git a/mindplot/src/test/javascript/static/palette.html b/mindplot/src/test/javascript/static/palette.html new file mode 100644 index 00000000..e58a815d --- /dev/null +++ b/mindplot/src/test/javascript/static/palette.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + +
+ The button +
+ + + + \ No newline at end of file diff --git a/web2d/pom.xml b/web2d/pom.xml index 11dbe453..f58cc9bd 100644 --- a/web2d/pom.xml +++ b/web2d/pom.xml @@ -86,6 +86,7 @@ true false + true diff --git a/wise-doc/src/main/webapp/css/bubble.css b/wise-doc/src/main/webapp/css/bubble.css deleted file mode 100644 index ecdf537c..00000000 --- a/wise-doc/src/main/webapp/css/bubble.css +++ /dev/null @@ -1,242 +0,0 @@ -.bubbleContainer { - position: absolute; - z-index: 50; - opacity: 0; - width: auto; - overflow: hidden; - padding: 20px; - -moz-border-radius: 5px; - border-radius: 5px; - background-color: #BCCCE1; - -moz-box-shadow: 5px 5px 5px #888; - -webkit-box-shadow: 5px 5px 5px #888; - box-shadow: 5px 5px 5px #888; - border: 1px solid black; -} - -.bublePartContainer { - clear: both; -} - -.bubblePart { - float: left; -} - -.bubbleLeft { - background: transparent url(../images/bubbleTip_left.png) top left; - width: 12px; - height: 4px; -} - -.bubbleCenter { - background-color: #362d2e; - text-align: center; - z-index: 60; -} - -.bubbleRight { - background: transparent url(../images/bubbleTip_right.png) top left; - width: 23px; - height: 4px; -} - -.bubbleTopLeft { - background: transparent url(../images/bubbleTip_corner_top_left.png) top left; - width: 12px; - height: 12px; -} - -.bubbleHintTopLeft { - background: transparent url(../images/bubbleTip_pico_corner_top_left.png) top left; - width: 12px; - height: 57px; -} - -.bubbleTopRight { - background: transparent url(../images/bubbleTip_corner_top_right.png) top left; - width: 23px; - height: 12px; -} - -.bubbleHintTopRight { - background: transparent url(../images/bubbleTip_pico_corner_top_right.png) top left; - width: 23px; - height: 57px; -} - -.bubbleTop { - background: transparent url(../images/bubbleTip_top.png) top left; - height: 12px; - width: 4px; -} - -.bubbleHintTop { - background: transparent url(../images/bubbleTip_pico_top.png) top left; - height: 57px; - width: 4px; -} - -.bubbleBottomLeft { - background: transparent url(../images/bubbleTip_corner_bottom_left.png) top left; - width: 12px; - height: 26px; -} - -.bubbleHintBottomLeft { - background: transparent url(../images/bubbleTip_pico_corner_bottom_left.png) top left; - width: 12px; - height: 62px; -} - -.bubbleBottomRight { - background: transparent url(../images/bubbleTip_corner_bottom_right.png) top left; - width: 23px; - height: 26px; -} - -.bubbleHintBottomRight { - background: transparent url(../images/bubbleTip_pico_corner_bottom_right.png) top left; - width: 23px; - height: 62px; -} - -.bubbleBottom { - background: transparent url(../images/bubbleTip_bottom.png) top left; - height: 26px; - width: 4px; -} - -.bubbleHintBottom { - background: transparent url(../images/bubbleTip_pico_bottom.png) top left; - height: 62px; - width: 4px; -} - -.bubbleBottomHint { - background: transparent url(../images/bubbleTip_bottom_pico.png) top left; - width: 58px; - height: 62px; -} - -.bubbleTopHint { - background: transparent url(../images/bubbleTip_top_pico.png) top left; - width: 58px; - height: 57px; -} - -.bubbleLeftBlue { - background: transparent url(../images/bubbleTip_left_blue.gif) top left; - width: 12px; - height: 4px; -} - -.bubbleCenterBlue { - background-color: #BCCCE1; - z-index: 60; - overflow: hidden; -} - -.bubbleRightBlue { - background: transparent url(../images/bubbleTip_right_blue.gif) top left; - width: 23px; - height: 3px; -} - -.bubbleTopLeftBlue { - background: transparent url(../images/bubbleTip_corner_top_left_blue.gif) top left; - width: 12px; - height: 18px; -} - -.bubbleHintTopLeftBlue { - background: transparent url(../images/bubbleTip_pico_corner_top_left_blue.gif) top left; - width: 13px; - height: 61px; -} - -.bubbleTopRightBlue { - background: transparent url(../images/bubbleTip_corner_top_right_blue.gif) top left; - width: 23px; - height: 18px; -} - -.bubbleHintTopRightBlue { - background: transparent url(../images/bubbleTip_pico_corner_top_right_blue.gif) top left; - width: 23px; - height: 61px; -} - -.bubbleTopBlue { - background: transparent url(../images/bubbleTip_top_blue.gif) top left; - height: 18px; - width: 3px; -} - -.bubbleHintTopBlue { - background: transparent url(../images/bubbleTip_pico_top_blue.gif) top left; - height: 61px; - width: 3px; -} - -.bubbleBottomLeftBlue { - background: transparent url(../images/bubbleTip_corner_bottom_left_blue.gif) top left; - width: 13px; - height: 32px; -} - -.bubbleHintBottomLeftBlue { - background: transparent url(../images/bubbleTip_pico_corner_bottom_left_blue.gif) top left; - width: 12px; - height: 62px; -} - -.bubbleBottomRightBlue { - background: transparent url(../images/bubbleTip_corner_bottom_right_blue.gif) top left; - width: 23px; - height: 32px; -} - -.bubbleHintBottomRightBlue { - background: transparent url(../images/bubbleTip_pico_corner_bottom_right_blue.gif) top left; - width: 23px; - height: 62px; -} - -.bubbleBottomBlue { - background: transparent url(../images/bubbleTip_bottom_blue.gif) top left; - height: 32px; - width: 3px; -} - -.bubbleHintBottomBlue { - background: transparent url(../images/bubbleTip_pico_bottom_blue.gif) top left; - height: 62px; - width: 3px; -} - -.bubbleBottomHintBlue { - background: transparent url(../images/bubbleTip_bottom_pico_blue.png) top left; - width: 58px; - height: 62px; -} - -.bubbleTopHintBlue { - background: transparent url(../images/bubbleTip_top_pico_blue.png) top left; - width: 58px; - height: 61px; -} - -.btn-primary { - background: #3399CC; - border: 1px solid #006699; - color: #FFFFFF; - font-family: arial, helvetica, sans-serif; - font-size: 72%; - font-style: normal; - font-variant: normal; - font-weight: normal; - line-height: normal; - overflow: visible; - padding: 2px 8px 1px; - vertical-align: middle; -} \ No newline at end of file diff --git a/wise-doc/src/main/webapp/css/editor.css b/wise-doc/src/main/webapp/css/editor.css index 86a0670d..2d538d79 100644 --- a/wise-doc/src/main/webapp/css/editor.css +++ b/wise-doc/src/main/webapp/css/editor.css @@ -400,8 +400,11 @@ div#fontColor { .toolbarPanel { color: black; - border: 1px solid #bbb4d6; - background: #E5E5E5; + border-color: #CCC #666 #666 #CCC; + border-style: solid; + border-width: 1px; + background: white; + padding: 2px; display: none; position: absolute; z-index: 4; diff --git a/wise-doc/src/main/webapp/html/editor.html b/wise-doc/src/main/webapp/html/editor.html index 941a8f3e..9cb4ab3d 100644 --- a/wise-doc/src/main/webapp/html/editor.html +++ b/wise-doc/src/main/webapp/html/editor.html @@ -10,7 +10,6 @@ WiseMapping - Editor - @@ -21,10 +20,6 @@ - - - - diff --git a/wise-doc/src/main/webapp/js/mindplot.svg.js b/wise-doc/src/main/webapp/js/mindplot.svg.js index 43ee16bf..21e65feb 100644 --- a/wise-doc/src/main/webapp/js/mindplot.svg.js +++ b/wise-doc/src/main/webapp/js/mindplot.svg.js @@ -1100,636 +1100,636 @@ mindplot.EventBus.events = { NodeMouseOutEvent:'NodeMouseOutEvent' }; -mindplot.EventBus.instance = new mindplot.EventBus();/* - * 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.model = {}; -mindplot.model.Mindmap = new Class({ - initialize : function() { - this._branches = []; - this._description = null; - this._version = null; - this._relationships = []; - }, - - getCentralTopic : function() { - return this._branches[0]; - }, - - getDescription : function() { - return this._description; - }, - - getId : function() { - return this._iconType; - }, - - - setId : function(id) { - this._iconType = id; - }, - - getVersion : function() { - return this._version; - }, - - - setVersion : function(version) { - this._version = version; - }, - - addBranch : function(nodeModel) { - $assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects'); - if (this._branches.length == 0) { - $assert(nodeModel.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic"); - nodeModel.setPosition(0, 0); - } else { - $assert(nodeModel.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic"); - } - - this._branches.push(nodeModel); - }, - - getBranches : function() { - return this._branches; - }, - - getRelationships : function() { - return this._relationships; - }, - - connect : function(parent, child) { - // Child already has a parent ? - var branches = this.getBranches(); - $assert(!child.getParent(), 'Child model seems to be already connected'); - - // Connect node... - parent._appendChild(child); - - // Remove from the branch ... - branches.erase(child); - }, - - disconnect : function(child) { - var parent = child.getParent(); - $assert(child, 'Child can not be null.'); - $assert(parent, 'Child model seems to be already connected'); - - parent._removeChild(child); - - var branches = this.getBranches(); - branches.push(child); - - }, - - hasAlreadyAdded : function(node) { - var result = false; - - // Check in not connected nodes. - var branches = this._branches; - for (var i = 0; i < branches.length; i++) { - result = branches[i]._isChildNode(node); - if (result) { - break; - } - } - }, - - createNode : function(type, id) { - $assert(type, "node type can not be null"); - return this._createNode(type, id); - }, - - _createNode : function(type, id) { - $assert(type, 'Node type must be specified.'); - var result = new mindplot.model.NodeModel(type, this, id); - return result; - }, - - createRelationship : function(fromNode, toNode) { - $assert(fromNode, 'from node cannot be null'); - $assert(toNode, 'to node cannot be null'); - - return new mindplot.model.RelationshipModel(fromNode, toNode); - }, - - addRelationship : function(relationship) { - this._relationships.push(relationship); - }, - - removeRelationship : function(relationship) { - this._relationships.erase(relationship); - }, - - inspect : function() { - var result = ''; - result = '{ '; - - var branches = this.getBranches(); - for (var i = 0; i < branches.length; i++) { - var node = branches[i]; - if (i != 0) { - result = result + ', '; - } - - result = result + this._toString(node); - } - - result = result + ' } '; - - return result; - }, - - _toString : function(node) { - var result = node.inspect(); - var children = node.getChildren(); - - for (var i = 0; i < children.length; i++) { - var child = children[i]; - - if (i == 0) { - result = result + '-> {'; - } else { - result = result + ', '; - } - - result = result + this._toString(child); - - if (i == children.length - 1) { - result = result + '}'; - } - } - - return result; - } - } -);/* - * 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.model.NodeModel = new Class({ - initialize:function(type, mindmap, id) { - $assert(type, 'Node type can not be null'); - $assert(mindmap, 'mindmap can not be null'); - - this._order = null; - this._type = type; - this._children = []; - this._icons = []; - this._links = []; - this._notes = []; - this._size = {width:50,height:20}; - this._position = null; - if ($defined(id)) { - if (!$defined(mindplot.model.NodeModel._uuid) || id > mindplot.model.NodeModel._uuid) { - mindplot.model.NodeModel._uuid = id; - } - this._id = id; - } else { - this._id = mindplot.model.NodeModel._nextUUID(); - } - this._mindmap = mindmap; - this._text = null; - this._shapeType = null; - this._fontFamily = null; - this._fontSize = null; - this._fontStyle = null; - this._fontWeight = null; - this._fontColor = null; - this._borderColor = null; - this._backgroundColor = null; - this._areChildrenShrinked = false; - }, - - clone : function() { - var result = new mindplot.model.NodeModel(this._type, this._mindmap); - result._order = this._order; - result._type = this._type; - result._children = this._children.map(function(item, index) { - var model = item.clone(); - model._parent = result; - return model; - }); - - - result._icons = this._icons; - result._links = this._links; - result._notes = this._notes; - result._size = this._size; - result._position = this._position; - result._id = this._id; - result._mindmap = this._mindmap; - result._text = this._text; - result._shapeType = this._shapeType; - result._fontFamily = this._fontFamily; - result._fontSize = this._fontSize; - result._fontStyle = this._fontStyle; - result._fontWeight = this._fontWeight; - result._fontColor = this._fontColor; - result._borderColor = this._borderColor; - result._backgroundColor = this._backgroundColor; - result._areChildrenShrinked = this._areChildrenShrinked; - return result; - }, - - areChildrenShrinked : function() { - return this._areChildrenShrinked; - }, - - setChildrenShrinked : function(value) { - this._areChildrenShrinked = value; - }, - - getId : function() { - return this._id; - }, - - - setId : function(id) { - this._id = id; - if (mindplot.model.NodeModel._uuid < id) { - mindplot.model.NodeModel._uuid = id; - } - }, - - getType : function() { - return this._type; - }, - - setText : function(text) { - this._text = text; - }, - - getText : function() { - return this._text; - }, - - isNodeModel : function() { - return true; - }, - - isConnected : function() { - return this._parent != null; - }, - - createLink : function(url) { - $assert(url, 'Link URL must be specified.'); - return new mindplot.model.LinkModel(url, this); - }, - - addLink : function(link) { - $assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links'); - this._links.push(link); - }, - - _removeLink : function(link) { - $assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links'); - this._links.erase(link); - }, - - createNote : function(text) { - $assert(text != null, 'note text must be specified.'); - return new mindplot.model.NoteModel(text, this); - }, - - addNote : function(note) { - $assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); - this._notes.push(note); - }, - - _removeNote : function(note) { - $assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); - this._notes.erase(note); - }, - - createIcon : function(iconType) { - $assert(iconType, 'IconType must be specified.'); - return new mindplot.model.IconModel(iconType, this); - }, - - addIcon : function(icon) { - $assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons'); - this._icons.push(icon); - }, - - _removeIcon : function(icon) { - $assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons'); - this._icons.erase(icon); - }, - - removeLastIcon : function() { - this._icons.pop(); - }, - - _appendChild : function(child) { - $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object'); - this._children.push(child); - child._parent = this; - }, - - _removeChild : function(child) { - $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.'); - this._children.erase(child); - child._parent = null; - }, - - setPosition : function(x, y) { - $assert(x, "x coordinate must be defined"); - $assert(y, "y coordinate must be defined"); - - if (!$defined(this._position)) { - this._position = new core.Point(); - } - this._position.x = parseInt(x); - this._position.y = parseInt(y); - }, - - getPosition : function() { - return this._position; - }, - - setFinalPosition : function(x, y) { - $assert(x, "x coordinate must be defined"); - $assert(y, "y coordinate must be defined"); - - if (!$defined(this._finalPosition)) { - this._finalPosition = new core.Point(); - } - this._finalPosition.x = parseInt(x); - this._finalPosition.y = parseInt(y); - }, - - getFinalPosition : function() { - return this._finalPosition; - }, - - setSize : function(width, height) { - this._size.width = width; - this._size.height = height; - }, - - getSize : function() { - return {width:this._size.width,height:this._size.height}; - }, - - getChildren : function() { - return this._children; - }, - - getIcons : function() { - return this._icons; - }, - - getLinks : function() { - return this._links; - }, - - getNotes : function() { - return this._notes; - }, - - getParent : function() { - return this._parent; - }, - - getMindmap : function() { - return this._mindmap; - }, - - setParent : function(parent) { - $assert(parent != this, 'The same node can not be parent and child if itself.'); - this._parent = parent; - }, - - canBeConnected : function(sourceModel, sourcePosition, targetTopicHeight) { - $assert(sourceModel != this, 'The same node can not be parent and child if itself.'); - $assert(sourcePosition, 'childPosition can not be null.'); - $assert(targetTopicHeight, 'childrenWidth can not be null.'); - - // Only can be connected if the node is in the left or rigth. - var targetModel = this; - var mindmap = targetModel.getMindmap(); - var targetPosition = targetModel.getPosition(); - var result = false; - - if (sourceModel.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { - // Finally, check current node ubication. - var targetTopicSize = targetModel.getSize(); - var yDistance = Math.abs(sourcePosition.y - targetPosition.y); - var gap = 35 + targetTopicHeight / 2; - if (targetModel.getChildren().length > 0) { - gap += Math.abs(targetPosition.y - targetModel.getChildren()[0].getPosition().y); - } - - if (yDistance <= gap) { - // Circular connection ? - if (!sourceModel._isChildNode(this)) { - var toleranceDistance = (targetTopicSize.width / 2) + targetTopicHeight; - - var xDistance = sourcePosition.x - targetPosition.x; - var isTargetAtRightFromCentral = targetPosition.x >= 0; - - if (isTargetAtRightFromCentral) { - if (xDistance >= -targetTopicSize.width / 2 && xDistance <= mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) { - result = true; - } - - } else { - if (xDistance <= targetTopicSize.width / 2 && Math.abs(xDistance) <= mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) { - result = true; - } - } - } - } - } else { - throw "No implemented yet"; - } - return result; - }, - - _isChildNode : function(node) { - var result = false; - if (node == this) { - result = true; - } else { - var children = this.getChildren(); - for (var i = 0; i < children.length; i++) { - var child = children[i]; - result = child._isChildNode(node); - if (result) { - break; - } - } - } - return result; - - }, - - connectTo : function(parent) { - var mindmap = this.getMindmap(); - mindmap.connect(parent, this); - this._parent = parent; - }, - - disconnect : function() { - var mindmap = this.getMindmap(); - mindmap.disconnect(this); - }, - - getOrder : function() { - return this._order; - }, - - getShapeType : function() { - return this._shapeType; - }, - - setShapeType : function(type) { - this._shapeType = type; - }, - - setOrder : function(value) { - this._order = value; - }, - - setFontFamily : function(value) { - this._fontFamily = value; - }, - - getOrder : function() { - return this._order; - }, - - getFontFamily : function() { - return this._fontFamily; - }, - - setFontStyle : function(value) { - this._fontStyle = value; - }, - - getFontStyle : function() { - return this._fontStyle; - }, - - setFontWeight : function(value) { - this._fontWeight = value; - }, - - getFontWeight : function() { - return this._fontWeight; - }, - - setFontColor : function(value) { - this._fontColor = value; - }, - - getFontColor : function() { - return this._fontColor; - }, - - setFontSize : function(value) { - this._fontSize = value; - }, - - getFontSize : function() { - return this._fontSize; - }, - - getBorderColor : function() { - return this._borderColor; - }, - - setBorderColor : function(color) { - this._borderColor = color; - }, - - getBackgroundColor : function() { - return this._backgroundColor; - }, - - setBackgroundColor : function(color) { - this._backgroundColor = color; - }, - - deleteNode : function() { - var mindmap = this._mindmap; - - // if it has children nodes, Their must be disconnected. - var lenght = this._children; - for (var i = 0; i < lenght; i++) { - var child = this._children[i]; - mindmap.disconnect(child); - } - - var parent = this._parent; - if ($defined(parent)) { - // if it is connected, I must remove it from the parent.. - mindmap.disconnect(this); - } - - // It's an isolated node. It must be a hole branch ... - var branches = mindmap.getBranches(); - branches.erase(this); - - }, - - inspect : function() { - return '(type:' + this.getType() + ' , id: ' + this.getId() + ')'; - } -}); - -mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic'; -mindplot.model.NodeModel.MAIN_TOPIC_TYPE = 'MainTopic'; -mindplot.model.NodeModel.DRAGGED_TOPIC_TYPE = 'DraggedTopic'; - -mindplot.model.NodeModel.SHAPE_TYPE_RECT = 'rectagle'; -mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT = 'rounded rectagle'; -mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE = 'elipse'; -mindplot.model.NodeModel.SHAPE_TYPE_LINE = 'line'; - -mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220; - -/** - * @todo: This method must be implemented. - */ -mindplot.model.NodeModel._nextUUID = function() { - if (!$defined(this._uuid)) { - this._uuid = 0; - } - - this._uuid = this._uuid + 1; - return this._uuid; -} - +mindplot.EventBus.instance = new mindplot.EventBus();/* + * 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.model = {}; +mindplot.model.Mindmap = new Class({ + initialize : function() { + this._branches = []; + this._description = null; + this._version = null; + this._relationships = []; + }, + + getCentralTopic : function() { + return this._branches[0]; + }, + + getDescription : function() { + return this._description; + }, + + getId : function() { + return this._iconType; + }, + + + setId : function(id) { + this._iconType = id; + }, + + getVersion : function() { + return this._version; + }, + + + setVersion : function(version) { + this._version = version; + }, + + addBranch : function(nodeModel) { + $assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects'); + if (this._branches.length == 0) { + $assert(nodeModel.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE, "First element must be the central topic"); + nodeModel.setPosition(0, 0); + } else { + $assert(nodeModel.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE, "Mindmaps only have one cental topic"); + } + + this._branches.push(nodeModel); + }, + + getBranches : function() { + return this._branches; + }, + + getRelationships : function() { + return this._relationships; + }, + + connect : function(parent, child) { + // Child already has a parent ? + var branches = this.getBranches(); + $assert(!child.getParent(), 'Child model seems to be already connected'); + + // Connect node... + parent._appendChild(child); + + // Remove from the branch ... + branches.erase(child); + }, + + disconnect : function(child) { + var parent = child.getParent(); + $assert(child, 'Child can not be null.'); + $assert(parent, 'Child model seems to be already connected'); + + parent._removeChild(child); + + var branches = this.getBranches(); + branches.push(child); + + }, + + hasAlreadyAdded : function(node) { + var result = false; + + // Check in not connected nodes. + var branches = this._branches; + for (var i = 0; i < branches.length; i++) { + result = branches[i]._isChildNode(node); + if (result) { + break; + } + } + }, + + createNode : function(type, id) { + $assert(type, "node type can not be null"); + return this._createNode(type, id); + }, + + _createNode : function(type, id) { + $assert(type, 'Node type must be specified.'); + var result = new mindplot.model.NodeModel(type, this, id); + return result; + }, + + createRelationship : function(fromNode, toNode) { + $assert(fromNode, 'from node cannot be null'); + $assert(toNode, 'to node cannot be null'); + + return new mindplot.model.RelationshipModel(fromNode, toNode); + }, + + addRelationship : function(relationship) { + this._relationships.push(relationship); + }, + + removeRelationship : function(relationship) { + this._relationships.erase(relationship); + }, + + inspect : function() { + var result = ''; + result = '{ '; + + var branches = this.getBranches(); + for (var i = 0; i < branches.length; i++) { + var node = branches[i]; + if (i != 0) { + result = result + ', '; + } + + result = result + this._toString(node); + } + + result = result + ' } '; + + return result; + }, + + _toString : function(node) { + var result = node.inspect(); + var children = node.getChildren(); + + for (var i = 0; i < children.length; i++) { + var child = children[i]; + + if (i == 0) { + result = result + '-> {'; + } else { + result = result + ', '; + } + + result = result + this._toString(child); + + if (i == children.length - 1) { + result = result + '}'; + } + } + + return result; + } + } +);/* + * 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.model.NodeModel = new Class({ + initialize:function(type, mindmap, id) { + $assert(type, 'Node type can not be null'); + $assert(mindmap, 'mindmap can not be null'); + + this._order = null; + this._type = type; + this._children = []; + this._icons = []; + this._links = []; + this._notes = []; + this._size = {width:50,height:20}; + this._position = null; + if ($defined(id)) { + if (!$defined(mindplot.model.NodeModel._uuid) || id > mindplot.model.NodeModel._uuid) { + mindplot.model.NodeModel._uuid = id; + } + this._id = id; + } else { + this._id = mindplot.model.NodeModel._nextUUID(); + } + this._mindmap = mindmap; + this._text = null; + this._shapeType = null; + this._fontFamily = null; + this._fontSize = null; + this._fontStyle = null; + this._fontWeight = null; + this._fontColor = null; + this._borderColor = null; + this._backgroundColor = null; + this._areChildrenShrinked = false; + }, + + clone : function() { + var result = new mindplot.model.NodeModel(this._type, this._mindmap); + result._order = this._order; + result._type = this._type; + result._children = this._children.map(function(item, index) { + var model = item.clone(); + model._parent = result; + return model; + }); + + + result._icons = this._icons; + result._links = this._links; + result._notes = this._notes; + result._size = this._size; + result._position = this._position; + result._id = this._id; + result._mindmap = this._mindmap; + result._text = this._text; + result._shapeType = this._shapeType; + result._fontFamily = this._fontFamily; + result._fontSize = this._fontSize; + result._fontStyle = this._fontStyle; + result._fontWeight = this._fontWeight; + result._fontColor = this._fontColor; + result._borderColor = this._borderColor; + result._backgroundColor = this._backgroundColor; + result._areChildrenShrinked = this._areChildrenShrinked; + return result; + }, + + areChildrenShrinked : function() { + return this._areChildrenShrinked; + }, + + setChildrenShrinked : function(value) { + this._areChildrenShrinked = value; + }, + + getId : function() { + return this._id; + }, + + + setId : function(id) { + this._id = id; + if (mindplot.model.NodeModel._uuid < id) { + mindplot.model.NodeModel._uuid = id; + } + }, + + getType : function() { + return this._type; + }, + + setText : function(text) { + this._text = text; + }, + + getText : function() { + return this._text; + }, + + isNodeModel : function() { + return true; + }, + + isConnected : function() { + return this._parent != null; + }, + + createLink : function(url) { + $assert(url, 'Link URL must be specified.'); + return new mindplot.model.LinkModel(url, this); + }, + + addLink : function(link) { + $assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links'); + this._links.push(link); + }, + + _removeLink : function(link) { + $assert(link && link.isLinkModel(), 'Only LinkModel can be appended to Mindmap object as links'); + this._links.erase(link); + }, + + createNote : function(text) { + $assert(text != null, 'note text must be specified.'); + return new mindplot.model.NoteModel(text, this); + }, + + addNote : function(note) { + $assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); + this._notes.push(note); + }, + + _removeNote : function(note) { + $assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); + this._notes.erase(note); + }, + + createIcon : function(iconType) { + $assert(iconType, 'IconType must be specified.'); + return new mindplot.model.IconModel(iconType, this); + }, + + addIcon : function(icon) { + $assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons'); + this._icons.push(icon); + }, + + _removeIcon : function(icon) { + $assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons'); + this._icons.erase(icon); + }, + + removeLastIcon : function() { + this._icons.pop(); + }, + + _appendChild : function(child) { + $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object'); + this._children.push(child); + child._parent = this; + }, + + _removeChild : function(child) { + $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.'); + this._children.erase(child); + child._parent = null; + }, + + setPosition : function(x, y) { + $assert(x, "x coordinate must be defined"); + $assert(y, "y coordinate must be defined"); + + if (!$defined(this._position)) { + this._position = new core.Point(); + } + this._position.x = parseInt(x); + this._position.y = parseInt(y); + }, + + getPosition : function() { + return this._position; + }, + + setFinalPosition : function(x, y) { + $assert(x, "x coordinate must be defined"); + $assert(y, "y coordinate must be defined"); + + if (!$defined(this._finalPosition)) { + this._finalPosition = new core.Point(); + } + this._finalPosition.x = parseInt(x); + this._finalPosition.y = parseInt(y); + }, + + getFinalPosition : function() { + return this._finalPosition; + }, + + setSize : function(width, height) { + this._size.width = width; + this._size.height = height; + }, + + getSize : function() { + return {width:this._size.width,height:this._size.height}; + }, + + getChildren : function() { + return this._children; + }, + + getIcons : function() { + return this._icons; + }, + + getLinks : function() { + return this._links; + }, + + getNotes : function() { + return this._notes; + }, + + getParent : function() { + return this._parent; + }, + + getMindmap : function() { + return this._mindmap; + }, + + setParent : function(parent) { + $assert(parent != this, 'The same node can not be parent and child if itself.'); + this._parent = parent; + }, + + canBeConnected : function(sourceModel, sourcePosition, targetTopicHeight) { + $assert(sourceModel != this, 'The same node can not be parent and child if itself.'); + $assert(sourcePosition, 'childPosition can not be null.'); + $assert(targetTopicHeight, 'childrenWidth can not be null.'); + + // Only can be connected if the node is in the left or rigth. + var targetModel = this; + var mindmap = targetModel.getMindmap(); + var targetPosition = targetModel.getPosition(); + var result = false; + + if (sourceModel.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { + // Finally, check current node ubication. + var targetTopicSize = targetModel.getSize(); + var yDistance = Math.abs(sourcePosition.y - targetPosition.y); + var gap = 35 + targetTopicHeight / 2; + if (targetModel.getChildren().length > 0) { + gap += Math.abs(targetPosition.y - targetModel.getChildren()[0].getPosition().y); + } + + if (yDistance <= gap) { + // Circular connection ? + if (!sourceModel._isChildNode(this)) { + var toleranceDistance = (targetTopicSize.width / 2) + targetTopicHeight; + + var xDistance = sourcePosition.x - targetPosition.x; + var isTargetAtRightFromCentral = targetPosition.x >= 0; + + if (isTargetAtRightFromCentral) { + if (xDistance >= -targetTopicSize.width / 2 && xDistance <= mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) { + result = true; + } + + } else { + if (xDistance <= targetTopicSize.width / 2 && Math.abs(xDistance) <= mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) { + result = true; + } + } + } + } + } else { + throw "No implemented yet"; + } + return result; + }, + + _isChildNode : function(node) { + var result = false; + if (node == this) { + result = true; + } else { + var children = this.getChildren(); + for (var i = 0; i < children.length; i++) { + var child = children[i]; + result = child._isChildNode(node); + if (result) { + break; + } + } + } + return result; + + }, + + connectTo : function(parent) { + var mindmap = this.getMindmap(); + mindmap.connect(parent, this); + this._parent = parent; + }, + + disconnect : function() { + var mindmap = this.getMindmap(); + mindmap.disconnect(this); + }, + + getOrder : function() { + return this._order; + }, + + getShapeType : function() { + return this._shapeType; + }, + + setShapeType : function(type) { + this._shapeType = type; + }, + + setOrder : function(value) { + this._order = value; + }, + + setFontFamily : function(value) { + this._fontFamily = value; + }, + + getOrder : function() { + return this._order; + }, + + getFontFamily : function() { + return this._fontFamily; + }, + + setFontStyle : function(value) { + this._fontStyle = value; + }, + + getFontStyle : function() { + return this._fontStyle; + }, + + setFontWeight : function(value) { + this._fontWeight = value; + }, + + getFontWeight : function() { + return this._fontWeight; + }, + + setFontColor : function(value) { + this._fontColor = value; + }, + + getFontColor : function() { + return this._fontColor; + }, + + setFontSize : function(value) { + this._fontSize = value; + }, + + getFontSize : function() { + return this._fontSize; + }, + + getBorderColor : function() { + return this._borderColor; + }, + + setBorderColor : function(color) { + this._borderColor = color; + }, + + getBackgroundColor : function() { + return this._backgroundColor; + }, + + setBackgroundColor : function(color) { + this._backgroundColor = color; + }, + + deleteNode : function() { + var mindmap = this._mindmap; + + // if it has children nodes, Their must be disconnected. + var lenght = this._children; + for (var i = 0; i < lenght; i++) { + var child = this._children[i]; + mindmap.disconnect(child); + } + + var parent = this._parent; + if ($defined(parent)) { + // if it is connected, I must remove it from the parent.. + mindmap.disconnect(this); + } + + // It's an isolated node. It must be a hole branch ... + var branches = mindmap.getBranches(); + branches.erase(this); + + }, + + inspect : function() { + return '(type:' + this.getType() + ' , id: ' + this.getId() + ')'; + } +}); + +mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE = 'CentralTopic'; +mindplot.model.NodeModel.MAIN_TOPIC_TYPE = 'MainTopic'; +mindplot.model.NodeModel.DRAGGED_TOPIC_TYPE = 'DraggedTopic'; + +mindplot.model.NodeModel.SHAPE_TYPE_RECT = 'rectagle'; +mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT = 'rounded rectagle'; +mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE = 'elipse'; +mindplot.model.NodeModel.SHAPE_TYPE_LINE = 'line'; + +mindplot.model.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220; + +/** + * @todo: This method must be implemented. + */ +mindplot.model.NodeModel._nextUUID = function() { + if (!$defined(this._uuid)) { + this._uuid = 0; + } + + this._uuid = this._uuid + 1; + return this._uuid; +} + /* * Copyright [2011] [wisemapping] * @@ -2474,8 +2474,7 @@ mindplot.MindmapDesigner = new Class({ return topic.getShapeType() != mindplot.model.NodeModel.SHAPE_TYPE_LINE }; var validateError = 'Color can not be setted to line topics.'; - var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); - ; + var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);; var topicsIds = validSelectedObjects.nodes; if (topicsIds.length > 0) { @@ -3029,347 +3028,347 @@ mindplot.MindmapDesigner = new Class({ } } ); -/* - * 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.ScreenManager = new Class({ - initialize:function(width, height, divElement) { - $assert(divElement, "can not be null"); - this._divContainer = divElement; - this._offset = {x:0,y:0}; - }, - - setScale : function(scale) { - $assert(scale, 'Screen scale can not be null'); - this._workspaceScale = scale; - }, - - addEventListener : function(event, listener) { - $(this._divContainer).addEvent(event, listener); - }, - - removeEventListener : function(event, listener) { - $(this._divContainer).removeEvent(event, listener); - }, - - getWorkspaceElementPosition : function(e) { - // Retrive current element position. - var elementPosition = e.getPosition(); - var x = elementPosition.x; - var y = elementPosition.y; - - // Add workspace offset. - x = x - this._offset.x; - y = y - this._offset.y; - - // Scale coordinate in order to be relative to the workspace. That's coordSize/size; - x = x / this._workspaceScale; - y = y / this._workspaceScale; - - // Subtract div position. - /* var containerElem = this.getContainer(); - var containerPosition = core.Utils.workOutDivElementPosition(containerElem); - x = x + containerPosition.x; - y = y + containerPosition.y;*/ - - // Remove decimal part.. - return {x:x,y:y}; - }, - - getWorkspaceIconPosition : function(e) { - // Retrieve current icon position. - var image = e.getImage(); - var elementPosition = image.getPosition(); - var imageSize = e.getSize(); - - //Add group offset - var iconGroup = e.getGroup(); - var group = iconGroup.getNativeElement(); - var coordOrigin = group.getCoordOrigin(); - var groupSize = group.getSize(); - var coordSize = group.getCoordSize(); - - var scale = {x:coordSize.width / parseInt(groupSize.width), y:coordSize.height / parseInt(groupSize.height)}; - - var x = (elementPosition.x - coordOrigin.x - (parseInt(imageSize.width) / 2)) / scale.x; - var y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y; - - //Retrieve iconGroup Position - var groupPosition = iconGroup.getPosition(); - x = x + groupPosition.x; - y = y + groupPosition.y; - - //Retrieve topic Position - var topic = iconGroup.getTopic(); - var topicPosition = this.getWorkspaceElementPosition(topic); - topicPosition.x = topicPosition.x - (parseInt(topic.getSize().width) / 2); - - - // Remove decimal part.. - return {x:x + topicPosition.x,y:y + topicPosition.y}; - }, - - getWorkspaceMousePosition : function(e) { - // Retrive current mouse position. - var mousePosition = this._getMousePosition(e); - var x = mousePosition.x; - var y = mousePosition.y; - - // Subtract div position. - var containerElem = this.getContainer(); - var containerPosition = core.Utils.workOutDivElementPosition(containerElem); - x = x - containerPosition.x; - y = y - containerPosition.y; - - // Scale coordinate in order to be relative to the workspace. That's coordSize/size; - x = x * this._workspaceScale; - y = y * this._workspaceScale; - - // Add workspace offset. - x = x + this._offset.x; - y = y + this._offset.y; - - // Remove decimal part.. - return new core.Point(x, y); - }, - - /** - * http://www.howtocreate.co.uk/tutorials/javascript/eventinfo - */ - _getMousePosition : function(event) { - return core.Utils.getMousePosition(event); - }, - - getContainer : function() { - return this._divContainer; - }, - - setOffset : function(x, y) { - this._offset.x = x; - this._offset.y = y; - }}); -/* - * 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.Workspace = new Class({ - initialize: function(profile, screenManager, zoom) { - // Create a suitable container ... - $assert(screenManager, 'Div container can not be null'); - this._zoom = zoom; - this._screenManager = screenManager; - this._screenWidth = profile.width; - this._screenHeight = profile.height; - - // Initalize web2d workspace. - var workspace = this._createWorkspace(profile); - this._workspace = workspace; - - var screenContainer = screenManager.getContainer(); - // Fix the height of the container .... - screenContainer.style.height = this._screenHeight + "px"; - - // Append to the workspace... - workspace.addItAsChildTo(screenContainer); - this.setZoom(zoom, true); - - // Register drag events ... - this._registerDragEvents(); - - this._eventsEnabled = true; - - }, - - _updateScreenManager: function() { - var zoom = this._zoom; - this._screenManager.setScale(zoom); - - var coordOriginX = -((this._screenWidth * this._zoom) / 2); - var coordOriginY = -((this._screenHeight * this._zoom) / 2); - this._screenManager.setOffset(coordOriginX, coordOriginY); - }, - - _createWorkspace: function(profile) { - // Initialize workspace ... - var coordOriginX = -(this._screenWidth / 2); - var coordOriginY = -(this._screenHeight / 2); - - var workspaceProfile = { - width: this._screenWidth + "px", - height: this._screenHeight + "px", - coordSizeWidth:this._screenWidth, - coordSizeHeight:this._screenHeight, - coordOriginX:coordOriginX, - coordOriginY:coordOriginY, - fillColor:'transparent', - strokeWidth:0 - }; - web2d.peer.Toolkit.init(); - return new web2d.Workspace(workspaceProfile); - }, - - appendChild: function(shape) { - if ($defined(shape.addToWorkspace)) { - shape.addToWorkspace(this); - } else { - this._workspace.appendChild(shape); - } - }, - - removeChild: function(shape) { - // Element is a node, not a web2d element? - if ($defined(shape.removeFromWorkspace)) { - shape.removeFromWorkspace(this); - } else { - this._workspace.removeChild(shape); - } - }, - - addEventListener: function(type, listener) { - this._workspace.addEventListener(type, listener); - }, - - removeEventListener: function(type, listener) { - this._workspace.removeEventListener(type, listener); - }, - - getSize: function() { - return this._workspace.getCoordSize(); - }, - - setZoom: function(zoom, center) { - this._zoom = zoom; - var workspace = this._workspace; - - // Update coord scale... - var coordWidth = zoom * this._screenWidth; - var coordHeight = zoom * this._screenHeight; - workspace.setCoordSize(coordWidth, coordHeight); - - // Center topic.... - var coordOriginX; - var coordOriginY; - if (center) { - coordOriginX = -(coordWidth / 2); - coordOriginY = -(coordHeight / 2); - } else { - var coordOrigin = workspace.getCoordOrigin(); - coordOriginX = coordOrigin.x; - coordOriginY = coordOrigin.y; - } - - workspace.setCoordOrigin(coordOriginX, coordOriginY); - - // Update screen. - this._screenManager.setOffset(coordOriginX, coordOriginY); - this._screenManager.setScale(zoom); - }, - - getScreenManager: function() { - return this._screenManager; - }, - - enableWorkspaceEvents: function(value) { - this._eventsEnabled = value; - }, - - isWorkspaceEventsEnabled: function() { - return this._eventsEnabled; - }, - - dumpNativeChart: function() { - var workspace = this._workspace; - return workspace.dumpNativeChart(); - }, - _registerDragEvents: function() { - var workspace = this._workspace; - var screenManager = this._screenManager; - this._dragging = true; - var mWorkspace = this; - var mouseDownListener = function(event) { - if (!$defined(workspace.mouseMoveListener)) { - if (mWorkspace.isWorkspaceEventsEnabled()) { - mWorkspace.enableWorkspaceEvents(false); - - var mouseDownPosition = screenManager.getWorkspaceMousePosition(event); - var originalCoordOrigin = workspace.getCoordOrigin(); - - workspace.mouseMoveListener = function(event) { - - var currentMousePosition = screenManager.getWorkspaceMousePosition(event); - - var offsetX = currentMousePosition.x - mouseDownPosition.x; - var coordOriginX = -offsetX + originalCoordOrigin.x; - - var offsetY = currentMousePosition.y - mouseDownPosition.y; - var coordOriginY = -offsetY + originalCoordOrigin.y; - - workspace.setCoordOrigin(coordOriginX, coordOriginY); - - // Change cursor. - if (core.UserAgent.isMozillaFamily()) { - window.document.body.style.cursor = "-moz-grabbing"; - } else { - window.document.body.style.cursor = "move"; - } - event.preventDefault(); - }.bindWithEvent(this); - screenManager.addEventListener('mousemove', workspace.mouseMoveListener); - - // Register mouse up listeners ... - workspace.mouseUpListener = function(event) { - - screenManager.removeEventListener('mousemove', workspace.mouseMoveListener); - screenManager.removeEventListener('mouseup', workspace.mouseUpListener); - workspace.mouseUpListener = null; - workspace.mouseMoveListener = null; - window.document.body.style.cursor = 'default'; - - // Update screen manager offset. - var coordOrigin = workspace.getCoordOrigin(); - screenManager.setOffset(coordOrigin.x, coordOrigin.y); - mWorkspace.enableWorkspaceEvents(true); - }, - screenManager.addEventListener('mouseup', workspace.mouseUpListener); - } - } else { - workspace.mouseUpListener(); - } - }; - screenManager.addEventListener('mousedown', mouseDownListener); - } -}); - - +/* + * 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.ScreenManager = new Class({ + initialize:function(width, height, divElement) { + $assert(divElement, "can not be null"); + this._divContainer = divElement; + this._offset = {x:0,y:0}; + }, + + setScale : function(scale) { + $assert(scale, 'Screen scale can not be null'); + this._workspaceScale = scale; + }, + + addEventListener : function(event, listener) { + $(this._divContainer).addEvent(event, listener); + }, + + removeEventListener : function(event, listener) { + $(this._divContainer).removeEvent(event, listener); + }, + + getWorkspaceElementPosition : function(e) { + // Retrive current element position. + var elementPosition = e.getPosition(); + var x = elementPosition.x; + var y = elementPosition.y; + + // Add workspace offset. + x = x - this._offset.x; + y = y - this._offset.y; + + // Scale coordinate in order to be relative to the workspace. That's coordSize/size; + x = x / this._workspaceScale; + y = y / this._workspaceScale; + + // Subtract div position. + /* var containerElem = this.getContainer(); + var containerPosition = core.Utils.workOutDivElementPosition(containerElem); + x = x + containerPosition.x; + y = y + containerPosition.y;*/ + + // Remove decimal part.. + return {x:x,y:y}; + }, + + getWorkspaceIconPosition : function(e) { + // Retrieve current icon position. + var image = e.getImage(); + var elementPosition = image.getPosition(); + var imageSize = e.getSize(); + + //Add group offset + var iconGroup = e.getGroup(); + var group = iconGroup.getNativeElement(); + var coordOrigin = group.getCoordOrigin(); + var groupSize = group.getSize(); + var coordSize = group.getCoordSize(); + + var scale = {x:coordSize.width / parseInt(groupSize.width), y:coordSize.height / parseInt(groupSize.height)}; + + var x = (elementPosition.x - coordOrigin.x - (parseInt(imageSize.width) / 2)) / scale.x; + var y = (elementPosition.y - coordOrigin.y - (parseInt(imageSize.height) / 2)) / scale.y; + + //Retrieve iconGroup Position + var groupPosition = iconGroup.getPosition(); + x = x + groupPosition.x; + y = y + groupPosition.y; + + //Retrieve topic Position + var topic = iconGroup.getTopic(); + var topicPosition = this.getWorkspaceElementPosition(topic); + topicPosition.x = topicPosition.x - (parseInt(topic.getSize().width) / 2); + + + // Remove decimal part.. + return {x:x + topicPosition.x,y:y + topicPosition.y}; + }, + + getWorkspaceMousePosition : function(e) { + // Retrive current mouse position. + var mousePosition = this._getMousePosition(e); + var x = mousePosition.x; + var y = mousePosition.y; + + // Subtract div position. + var containerElem = this.getContainer(); + var containerPosition = core.Utils.workOutDivElementPosition(containerElem); + x = x - containerPosition.x; + y = y - containerPosition.y; + + // Scale coordinate in order to be relative to the workspace. That's coordSize/size; + x = x * this._workspaceScale; + y = y * this._workspaceScale; + + // Add workspace offset. + x = x + this._offset.x; + y = y + this._offset.y; + + // Remove decimal part.. + return new core.Point(x, y); + }, + + /** + * http://www.howtocreate.co.uk/tutorials/javascript/eventinfo + */ + _getMousePosition : function(event) { + return core.Utils.getMousePosition(event); + }, + + getContainer : function() { + return this._divContainer; + }, + + setOffset : function(x, y) { + this._offset.x = x; + this._offset.y = y; + }}); +/* + * 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.Workspace = new Class({ + initialize: function(profile, screenManager, zoom) { + // Create a suitable container ... + $assert(screenManager, 'Div container can not be null'); + this._zoom = zoom; + this._screenManager = screenManager; + this._screenWidth = profile.width; + this._screenHeight = profile.height; + + // Initalize web2d workspace. + var workspace = this._createWorkspace(profile); + this._workspace = workspace; + + var screenContainer = screenManager.getContainer(); + // Fix the height of the container .... + screenContainer.style.height = this._screenHeight + "px"; + + // Append to the workspace... + workspace.addItAsChildTo(screenContainer); + this.setZoom(zoom, true); + + // Register drag events ... + this._registerDragEvents(); + + this._eventsEnabled = true; + + }, + + _updateScreenManager: function() { + var zoom = this._zoom; + this._screenManager.setScale(zoom); + + var coordOriginX = -((this._screenWidth * this._zoom) / 2); + var coordOriginY = -((this._screenHeight * this._zoom) / 2); + this._screenManager.setOffset(coordOriginX, coordOriginY); + }, + + _createWorkspace: function(profile) { + // Initialize workspace ... + var coordOriginX = -(this._screenWidth / 2); + var coordOriginY = -(this._screenHeight / 2); + + var workspaceProfile = { + width: this._screenWidth + "px", + height: this._screenHeight + "px", + coordSizeWidth:this._screenWidth, + coordSizeHeight:this._screenHeight, + coordOriginX:coordOriginX, + coordOriginY:coordOriginY, + fillColor:'transparent', + strokeWidth:0 + }; + web2d.peer.Toolkit.init(); + return new web2d.Workspace(workspaceProfile); + }, + + appendChild: function(shape) { + if ($defined(shape.addToWorkspace)) { + shape.addToWorkspace(this); + } else { + this._workspace.appendChild(shape); + } + }, + + removeChild: function(shape) { + // Element is a node, not a web2d element? + if ($defined(shape.removeFromWorkspace)) { + shape.removeFromWorkspace(this); + } else { + this._workspace.removeChild(shape); + } + }, + + addEventListener: function(type, listener) { + this._workspace.addEventListener(type, listener); + }, + + removeEventListener: function(type, listener) { + this._workspace.removeEventListener(type, listener); + }, + + getSize: function() { + return this._workspace.getCoordSize(); + }, + + setZoom: function(zoom, center) { + this._zoom = zoom; + var workspace = this._workspace; + + // Update coord scale... + var coordWidth = zoom * this._screenWidth; + var coordHeight = zoom * this._screenHeight; + workspace.setCoordSize(coordWidth, coordHeight); + + // Center topic.... + var coordOriginX; + var coordOriginY; + if (center) { + coordOriginX = -(coordWidth / 2); + coordOriginY = -(coordHeight / 2); + } else { + var coordOrigin = workspace.getCoordOrigin(); + coordOriginX = coordOrigin.x; + coordOriginY = coordOrigin.y; + } + + workspace.setCoordOrigin(coordOriginX, coordOriginY); + + // Update screen. + this._screenManager.setOffset(coordOriginX, coordOriginY); + this._screenManager.setScale(zoom); + }, + + getScreenManager: function() { + return this._screenManager; + }, + + enableWorkspaceEvents: function(value) { + this._eventsEnabled = value; + }, + + isWorkspaceEventsEnabled: function() { + return this._eventsEnabled; + }, + + dumpNativeChart: function() { + var workspace = this._workspace; + return workspace.dumpNativeChart(); + }, + _registerDragEvents: function() { + var workspace = this._workspace; + var screenManager = this._screenManager; + this._dragging = true; + var mWorkspace = this; + var mouseDownListener = function(event) { + if (!$defined(workspace.mouseMoveListener)) { + if (mWorkspace.isWorkspaceEventsEnabled()) { + mWorkspace.enableWorkspaceEvents(false); + + var mouseDownPosition = screenManager.getWorkspaceMousePosition(event); + var originalCoordOrigin = workspace.getCoordOrigin(); + + workspace.mouseMoveListener = function(event) { + + var currentMousePosition = screenManager.getWorkspaceMousePosition(event); + + var offsetX = currentMousePosition.x - mouseDownPosition.x; + var coordOriginX = -offsetX + originalCoordOrigin.x; + + var offsetY = currentMousePosition.y - mouseDownPosition.y; + var coordOriginY = -offsetY + originalCoordOrigin.y; + + workspace.setCoordOrigin(coordOriginX, coordOriginY); + + // Change cursor. + if (core.UserAgent.isMozillaFamily()) { + window.document.body.style.cursor = "-moz-grabbing"; + } else { + window.document.body.style.cursor = "move"; + } + event.preventDefault(); + }.bindWithEvent(this); + screenManager.addEventListener('mousemove', workspace.mouseMoveListener); + + // Register mouse up listeners ... + workspace.mouseUpListener = function(event) { + + screenManager.removeEventListener('mousemove', workspace.mouseMoveListener); + screenManager.removeEventListener('mouseup', workspace.mouseUpListener); + workspace.mouseUpListener = null; + workspace.mouseMoveListener = null; + window.document.body.style.cursor = 'default'; + + // Update screen manager offset. + var coordOrigin = workspace.getCoordOrigin(); + screenManager.setOffset(coordOrigin.x, coordOrigin.y); + mWorkspace.enableWorkspaceEvents(true); + }, + screenManager.addEventListener('mouseup', workspace.mouseUpListener); + } + } else { + workspace.mouseUpListener(); + } + }; + screenManager.addEventListener('mousedown', mouseDownListener); + } +}); + + /* * Copyright [2011] [wisemapping] * @@ -3486,2995 +3485,2995 @@ mindplot.ShirinkConnector = new Class({ moveToFront: function() { this._elipse.moveToFront(); } -});/* - * 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.NodeGraph = new Class({ - initialize:function(nodeModel) { - $assert(nodeModel,"model can not be null"); - this._mouseEvents = true; - this.setModel(nodeModel); - this._onFocus = false; - }, - - getType : function() { - var model = this.getModel(); - return model.getType(); - }, - - setId : function(id) { - this.getModel().setId(id); - }, - - _set2DElement : function(elem2d) { - this._elem2d = elem2d; - }, - - get2DElement : function() { - $assert(this._elem2d, 'NodeGraph has not been initialized propertly'); - return this._elem2d; - }, - - setPosition : function(point) { - // Elements are positioned in the center. - var size = this._model.getSize(); - this._elem2d.setPosition(point.x - (size.width / 2), point.y - (size.height / 2)); - this._model.setPosition(point.x, point.y); - }, - - addEventListener : function(type, listener) { - var elem = this.get2DElement(); - elem.addEventListener(type, listener); - }, - - isNodeGraph : function() { - return true; - }, - - setMouseEventsEnabled : function(isEnabled) { - this._mouseEvents = isEnabled; - }, - - isMouseEventsEnabled : function() { - return this._mouseEvents; - }, - - getSize : function() { - return this._model.getSize(); - }, - - setSize : function(size) { - this._model.setSize(size.width, size.height); - }, - - getModel - : - function() { - $assert(this._model, 'Model has not been initialized yet'); - return this._model; - } - , - - setModel : function(model) { - $assert(model, 'Model can not be null'); - this._model = model; - }, - - getId : function() { - return this._model.getId(); - }, - - setOnFocus : function(focus) { - this._onFocus = focus; - var outerShape = this.getOuterShape(); - if (focus) { - outerShape.setFill('#c7d8ff'); - outerShape.setOpacity(1); - - } else { - // @todo: node must not know about the topic. - - outerShape.setFill(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES.fillColor); - outerShape.setOpacity(0); - } - this.setCursor('move'); - }, - - isOnFocus : function() { - return this._onFocus; - }, - - dispose : function(workspace) { - workspace.removeChild(this); - }, - - createDragNode : function() { - var dragShape = this._buildDragShape(); - return new mindplot.DragTopic(dragShape, this); - }, - - _buildDragShape : function() { - $assert(false, '_buildDragShape must be implemented by all nodes.'); - }, - - getPosition : function() { - var model = this.getModel(); - return model.getPosition(); - } -}); - -mindplot.NodeGraph.create = function(nodeModel) { - $assert(nodeModel, 'Model can not be null'); - - var type = nodeModel.getType(); - $assert(type, 'Node model type can not be null'); - - var result; - if (type == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - result = new mindplot.CentralTopic(nodeModel); - } else - if (type == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { - result = new mindplot.MainTopic(nodeModel); - } else { - assert(false, "unsupported node type:" + type); - } - - return result; -}/* - * 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 = new Class({ - Extends:mindplot.NodeGraph, - initialize : function(model) { - this.parent(model); - this._children = []; - this._parent = null; - 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.model.NodeModel.CENTRAL_TOPIC_TYPE) { - this.setPosition(pos); - } - }, - - setShapeType : function(type) { - this._setShapeType(type, true); - - }, - - getParent : function() { - return this._parent; - }, - - _setShapeType : function(type, updateModel) { - // Remove inner shape figure ... - var model = this.getModel(); - if ($defined(updateModel) && 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 ($defined(dispatcher)) { - for (var i = 1; i < dispatcher._listeners.length; i++) { - innerShape.addEventListener('mousedown', dispatcher._listeners[i]); - } - } - - // Update figure size ... - var size = model.getSize(); - this.setSize(size, true); - - var group = this.get2DElement(); - group.appendChild(innerShape); - - // Move text to the front ... - var text = this.getTextShape(); - text.moveToFront(); - - //Move iconGroup to front ... - var iconGroup = this.getIconGroup(); - if ($defined(iconGroup)) { - iconGroup.moveToFront(); - } - //Move connector to front - var connector = this.getShrinkConnector(); - if ($defined(connector)) { - connector.moveToFront(); - } - - //Move helpers to front - this._helpers.forEach(function(helper) { - helper.moveToFront(); - }); - - } - - }, - - getShapeType : function() { - var model = this.getModel(); - var result = model.getShapeType(); - if (!$defined(result)) { - result = this._defaultShapeType(); - } - return result; - }, - - _removeInnerShape : function() { - var group = this.get2DElement(); - var innerShape = this.getInnerShape(); - group.removeChild(innerShape); - this._innerShape = null; - }, - - getInnerShape : function() { - if (!$defined(this._innerShape)) { - // Create inner box. - this._innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES); - - // Update bgcolor ... - var bgColor = this.getBackgroundColor(); - this._setBackgroundColor(bgColor, false); - - // Update border color ... - var brColor = this.getBorderColor(); - this._setBorderColor(brColor, false); - - // Define the pointer ... - if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - this._innerShape.setCursor('move'); - } else { - this._innerShape.setCursor('default'); - } - - } - return this._innerShape; - }, - - - buildShape : function(attributes, type) { - var result; - if (!$defined(type)) { - type = this.getShapeType(); - } - - if (type == mindplot.model.NodeModel.SHAPE_TYPE_RECT) { - result = new web2d.Rect(0, attributes); - } - else if (type == mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE) { - result = new web2d.Elipse(attributes); - } - else if (type == mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT) { - result = new web2d.Rect(0.3, attributes); - } - else if (type == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { - result = new web2d.Line({strokeColor:"#495879",strokeWidth:1, strokeOpacity:1}); - result.setSize = function(width, height) { - this.size = {width:width, height:height}; - result.setFrom(-1, height); - result.setTo(width + 1, height); - - // Lines will have the same color of the default connection lines... - var stokeColor = mindplot.ConnectionLine.getStrokeColor(); - result.setStroke(1, 'solid', stokeColor); - }; - - result.getSize = function() { - return this.size; - }; - - result.setPosition = function() { - }; - - var setStrokeFunction = result.setStroke; - result.setFill = function(color) { - - }; - - result.setStroke = function(color) { - - }; - } - else { - $assert(false, "Unsupported figure type:" + type); - } - - result.setPosition(0, 0); - return result; - }, - - - setCursor : function(type) { - var innerShape = this.getInnerShape(); - innerShape.setCursor(type); - - var outerShape = this.getOuterShape(); - outerShape.setCursor(type); - - var textShape = this.getTextShape(); - textShape.setCursor(type); - }, - - getOuterShape : function() { - if (!$defined(this._outerShape)) { - var rect = this.buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT); - rect.setPosition(-2, -3); - rect.setOpacity(0); - this._outerShape = rect; - } - - return this._outerShape; - }, - - getTextShape : function() { - if (!$defined(this._text)) { - var model = this.getModel(); - this._text = this._buildTextShape(); - - // Set Text ... - var text = this.getText(); - this._setText(text, false); - } - return this._text; - }, - - getOrBuildIconGroup : function() { - if (!$defined(this._icon)) { - this._icon = this._buildIconGroup(); - var group = this.get2DElement(); - group.appendChild(this._icon.getNativeElement()); - this._icon.moveToFront(); - } - return this._icon; - }, - - getIconGroup : function() { - return this._icon; - }, - - _buildIconGroup : function(disableEventsListeners) { - var result = new mindplot.IconGroup(this); - var model = this.getModel(); - - //Icons - var icons = model.getIcons(); - for (var i = 0; i < icons.length; i++) { - // Update model identifier ... - var iconModel = icons[i]; - var icon = new mindplot.ImageIcon(iconModel, this, designer); - result.addIcon(icon); - } - - //Links - var links = model.getLinks(); - for (var i = 0; i < links.length; i++) { - this._hasLink = true; - this._link = new mindplot.LinkIcon(links[i], this, designer); - result.addIcon(this._link); - } - - //Notes - var notes = model.getNotes(); - for (var i = 0; i < notes.length; i++) { - this._hasNote = true; - this._note = new mindplot.Note(notes[i], this, designer); - result.addIcon(this._note); - } - - return result; - }, - - addLink : function(url, designer) { - var iconGroup = this.getOrBuildIconGroup(); - var model = this.getModel(); - var linkModel = model.createLink(url); - model.addLink(linkModel); - this._link = new mindplot.LinkIcon(linkModel, this, designer); - iconGroup.addIcon(this._link); - this._hasLink = true; - }, - - addNote : function(text, designer) { - var iconGroup = this.getOrBuildIconGroup(); - var model = this.getModel(); - text = escape(text); - var noteModel = model.createNote(text) - model.addNote(noteModel); - this._note = new mindplot.Note(noteModel, this, designer); - iconGroup.addIcon(this._note); - this._hasNote = true; - }, - - addIcon : function(iconType, designer) { - var iconGroup = this.getOrBuildIconGroup(); - var model = this.getModel(); - - // Update model ... - var iconModel = model.createIcon(iconType); - model.addIcon(iconModel); - - var imageIcon = new mindplot.ImageIcon(iconModel, this, designer); - iconGroup.addIcon(imageIcon); - - return imageIcon; - }, - - removeIcon : function(iconModel) { - - //Removing the icon from MODEL - var model = this.getModel(); - model._removeIcon(iconModel); - - //Removing the icon from UI - var iconGroup = this.getIconGroup(); - if ($defined(iconGroup)) { - var imgIcon = iconGroup.findIconFromModel(iconModel); - iconGroup.removeImageIcon(imgIcon); - if (iconGroup.getIcons().length == 0) { - this.get2DElement().removeChild(iconGroup.getNativeElement()); - this._icon = null; - } - this.updateNode(); - } - }, - - removeLink : function() { - var model = this.getModel(); - var links = model.getLinks(); - model._removeLink(links[0]); - var iconGroup = this.getIconGroup(); - if ($defined(iconGroup)) { - iconGroup.removeIcon(mindplot.LinkIcon.IMAGE_URL); - if (iconGroup.getIcons().length == 0) { - this.get2DElement().removeChild(iconGroup.getNativeElement()); - this._icon = null; - } - this.updateNode.delay(0, this); - } - this._link = null; - this._hasLink = false; - }, - - removeNote : function() { - var model = this.getModel(); - var notes = model.getNotes(); - model._removeNote(notes[0]); - var iconGroup = this.getIconGroup(); - if ($defined(iconGroup)) { - iconGroup.removeIcon(mindplot.Note.IMAGE_URL); - if (iconGroup.getIcons().length == 0) { - this.get2DElement().removeChild(iconGroup.getNativeElement()); - this._icon = null; - } - } - /*var elem = this; - var executor = function(editor) - { - return function() - { - elem.updateNode(); - }; - }; - - setTimeout(executor(this), 0);*/ - core.Executor.instance.delay(this.updateNode, 0, this); - this._note = null; - this._hasNote = false; - }, - - addRelationship : function(relationship) { - this._relationships.push(relationship); - }, - - removeRelationship : function(relationship) { - this._relationships.erase(relationship); - }, - - getRelationships : function() { - return this._relationships; - }, - - _buildTextShape : function(disableEventsListeners) { - var result = new web2d.Text(); - var font = {}; - - var family = this.getFontFamily(); - var size = this.getFontSize(); - var weight = this.getFontWeight(); - var style = this.getFontStyle(); - result.setFont(family, size, style, weight); - - var color = this.getFontColor(); - result.setColor(color); - - if (!disableEventsListeners) { - // Propagate mouse events ... - var topic = this; - result.addEventListener('mousedown', function(event) { - var eventDispatcher = topic.getInnerShape()._dispatcherByEventType['mousedown']; - if ($defined(eventDispatcher)) { - eventDispatcher.eventListener(event); - } - }); - - if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - result.setCursor('move'); - } else { - result.setCursor('default'); - } - } - - // Positionate node ... - this._offset = this.getOffset(); - var iconOffset = this.getIconOffset(); - result.setPosition(iconOffset + this._offset, this._offset / 2); - return result; - }, - - getIconOffset : function() { - var iconGroup = this.getIconGroup(); - var size = 0; - if ($defined(iconGroup)) { - size = iconGroup.getSize().width; - } - return size; - }, - - getOffset : function(value, updateModel) { - var offset = 18; - - if (mindplot.model.NodeModel.MAIN_TOPIC_TYPE == this.getType()) { - var parent = this.getModel().getParent(); - if (parent && mindplot.model.NodeModel.MAIN_TOPIC_TYPE == parent.getType()) { - offset = 6; - } - else { - offset = 8; - } - } - return offset; - }, - - setFontFamily : function(value, updateModel) { - var textShape = this.getTextShape(); - textShape.setFontFamily(value); - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setFontFamily(value); - } - /*var elem = this; - var executor = function(editor) - { - return function() - { - elem.updateNode(updateModel); - }; - }; - - setTimeout(executor(this), 0);*/ - core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); - }, - - setFontSize : function(value, updateModel) { - var textShape = this.getTextShape(); - textShape.setSize(value); - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setFontSize(value); - } - /*var elem = this; - var executor = function(editor) - { - return function() - { - elem.updateNode(updateModel); - }; - }; - - setTimeout(executor(this), 0);*/ - core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); - - }, - - setFontStyle : function(value, updateModel) { - var textShape = this.getTextShape(); - textShape.setStyle(value); - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setFontStyle(value); - } - /*var elem = this; - var executor = function(editor) - { - return function() - { - elem.updateNode(updateModel); - }; - }; - - setTimeout(executor(this), 0);*/ - core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); - }, - - setFontWeight : function(value, updateModel) { - var textShape = this.getTextShape(); - textShape.setWeight(value); - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setFontWeight(value); - } - }, - - getFontWeight : function() { - var model = this.getModel(); - var result = model.getFontWeight(); - if (!$defined(result)) { - var font = this._defaultFontStyle(); - result = font.weight; - } - return result; - }, - - getFontFamily : function() { - var model = this.getModel(); - var result = model.getFontFamily(); - if (!$defined(result)) { - var font = this._defaultFontStyle(); - result = font.font; - } - return result; - }, - - getFontColor : function() { - var model = this.getModel(); - var result = model.getFontColor(); - if (!$defined(result)) { - var font = this._defaultFontStyle(); - result = font.color; - } - return result; - }, - - getFontStyle : function() { - var model = this.getModel(); - var result = model.getFontStyle(); - if (!$defined(result)) { - var font = this._defaultFontStyle(); - result = font.style; - } - return result; - }, - - getFontSize : function() { - var model = this.getModel(); - var result = model.getFontSize(); - if (!$defined(result)) { - var font = this._defaultFontStyle(); - result = font.size; - } - return result; - }, - - setFontColor : function(value, updateModel) { - var textShape = this.getTextShape(); - textShape.setColor(value); - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setFontColor(value); - } - }, - - _setText : function(text, updateModel) { - var textShape = this.getTextShape(); - textShape.setText(text); - /*var elem = this; - var executor = function(editor) - { - return function() - { - elem.updateNode(updateModel); - }; - }; - - setTimeout(executor(this), 0);*/ - core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); - - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setText(text); - } - }, - - setText : function(text) { - this._setText(text, true); - }, - - getText : function() { - var model = this.getModel(); - var result = model.getText(); - if (!$defined(result)) { - result = this._defaultText(); - } - return result; - }, - - setBackgroundColor : function(color) { - this._setBackgroundColor(color, true); - }, - - _setBackgroundColor : function(color, updateModel) { - var innerShape = this.getInnerShape(); - innerShape.setFill(color); - - var connector = this.getShrinkConnector(); - connector.setFill(color); - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setBackgroundColor(color); - } - }, - - getBackgroundColor : function() { - var model = this.getModel(); - var result = model.getBackgroundColor(); - if (!$defined(result)) { - result = this._defaultBackgroundColor(); - } - return result; - }, - - setBorderColor : function(color) { - this._setBorderColor(color, true); - }, - - _setBorderColor : function(color, updateModel) { - var innerShape = this.getInnerShape(); - innerShape.setAttribute('strokeColor', color); - - var connector = this.getShrinkConnector(); - connector.setAttribute('strokeColor', color); - - - if ($defined(updateModel) && updateModel) { - var model = this.getModel(); - model.setBorderColor(color); - } - }, - - getBorderColor : function() { - var model = this.getModel(); - var result = model.getBorderColor(); - if (!$defined(result)) { - result = this._defaultBorderColor(); - } - return result; - }, - - _buildShape : function() { - var groupAttributes = {width: 100, height:100,coordSizeWidth:100,coordSizeHeight:100}; - var group = new web2d.Group(groupAttributes); - group._peer._native.virtualRef = this; - this._set2DElement(group); - - // Shape must be build based on the model width ... - var outerShape = this.getOuterShape(); - var innerShape = this.getInnerShape(); - var textShape = this.getTextShape(); - var shrinkConnector = this.getShrinkConnector(); - - // Update figure size ... - var model = this.getModel(); - var size = model.getSize(); - this._setSize(size); - - // Add to the group ... - group.appendChild(outerShape); - group.appendChild(innerShape); - group.appendChild(textShape); - - if (model.getLinks().length != 0 || model.getNotes().length != 0 || model.getIcons().length != 0) { - iconGroup = this.getOrBuildIconGroup(); - } - - if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - shrinkConnector.addToWorkspace(group); - } - - // Register listeners ... - this._registerDefaultListenersToElement(group, this); -// this._registerDefaultListenersToElement(innerShape, this); -// this._registerDefaultListenersToElement(textShape, this); - - }, - - _registerDefaultListenersToElement : function(elem, topic) { - var mouseOver = function(event) { - if (topic.isMouseEventsEnabled()) { - topic.handleMouseOver(event); - } - }; - elem.addEventListener('mouseover', mouseOver); - - var outout = function(event) { - if (topic.isMouseEventsEnabled()) { - topic.handleMouseOut(event); - } - }; - elem.addEventListener('mouseout', outout); - - // Focus events ... - var mouseDown = function(event) { - topic.setOnFocus(true); - }; - elem.addEventListener('mousedown', mouseDown); - }, - - areChildrenShrinked : function() { - var model = this.getModel(); - return model.areChildrenShrinked(); - }, - - isCollapsed : function() { - var model = this.getModel(); - var result = false; - - var current = this.getParent(); - while (current && !result) { - result = current.areChildrenShrinked(); - current = current.getParent(); - } - return result; - }, - - setChildrenShrinked : function(value) { - // Update Model ... - var model = this.getModel(); - model.setChildrenShrinked(value); - - // Change render base on the state. - var shrinkConnector = this.getShrinkConnector(); - shrinkConnector.changeRender(value); - - // Hide children ... - core.Utils.setChildrenVisibilityAnimated(this, !value); - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeShrinkEvent, [this]); - }, - - getShrinkConnector : function() { - var result = this._connector; - if (this._connector == null) { - this._connector = new mindplot.ShirinkConnector(this); - this._connector.setVisibility(false); - result = this._connector; - - } - return result; - }, - - handleMouseOver : function(event) { - var outerShape = this.getOuterShape(); - outerShape.setOpacity(1); - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOverEvent, [this]); - }, - - handleMouseOut : function(event) { - var outerShape = this.getOuterShape(); - if (!this.isOnFocus()) { - outerShape.setOpacity(0); - } - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent, [this]); - }, - - /** - * Point: references the center of the rect shape.!!! - */ - setPosition : function(point) { - // Elements are positioned in the center. - // All topic element must be positioned based on the innerShape. - var size = this.getSize(); - - var cx = Math.round(point.x - (size.width / 2)); - var cy = Math.round(point.y - (size.height / 2)); - - // Update visual position. - this._elem2d.setPosition(cx, cy); - - // Update model's position ... - var model = this.getModel(); - model.setPosition(point.x, point.y); - - // Update connection lines ... - this._updateConnectionLines(); - - // Check object state. - this.invariant(); - }, - - getOutgoingLine : function() { - return this._outgoingLine; - }, - - getIncomingLines : function() { - var result = []; - var children = this._getChildren(); - for (var i = 0; i < children.length; i++) { - var node = children[i]; - var line = node.getOutgoingLine(); - if ($defined(line)) { - result.push(line); - } - } - return result; - }, - - getOutgoingConnectedTopic : function() { - var result = null; - var line = this.getOutgoingLine(); - if ($defined(line)) { - result = line.getTargetTopic(); - } - return result; - }, - - - _updateConnectionLines : function() { - // Update this to parent line ... - var outgoingLine = this.getOutgoingLine(); - if ($defined(outgoingLine)) { - outgoingLine.redraw(); - } - - // Update all the incoming lines ... - var incomingLines = this.getIncomingLines(); - for (var i = 0; i < incomingLines.length; i++) { - incomingLines[i].redraw(); - } - - // Update relationship lines - for (var j = 0; j < this._relationships.length; j++) { - this._relationships[j].redraw(); - } - }, - - setBranchVisibility : function(value) { - var current = this; - var parent = this; - while (parent != null && parent.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - current = parent; - parent = current.getParent(); - } - current.setVisibility(value); - }, - - - setVisibility : function(value) { - this._setTopicVisibility(value); - - // Hide all children... - this._setChildrenVisibility(value); - - this._setRelationshipLinesVisibility(value); - }, - - moveToBack : function() { -// this._helpers.forEach(function(helper, index){ -// helper.moveToBack(); -// }); - // Update relationship lines - for (var j = 0; j < this._relationships.length; j++) { - this._relationships[j].moveToBack(); - } - var connector = this.getShrinkConnector(); - if ($defined(connector)) { - connector.moveToBack(); - } - - this.get2DElement().moveToBack(); - - - }, - - moveToFront : function() { - - this.get2DElement().moveToFront(); - var connector = this.getShrinkConnector(); - if ($defined(connector)) { - connector.moveToFront(); - } - // Update relationship lines - for (var j = 0; j < this._relationships.length; j++) { - this._relationships[j].moveToFront(); - } - }, - - isVisible : function() { - var elem = this.get2DElement(); - return elem.isVisible(); - }, - - _setRelationshipLinesVisibility : function(value) { - //var relationships = designer.findRelationShipsByTopicId(this.getId()); - this._relationships.forEach(function(relationship, index) { - relationship.setVisibility(value); - }); - }, - - _setTopicVisibility : function(value) { - var elem = this.get2DElement(); - elem.setVisibility(value); - - if (this.getIncomingLines().length > 0) { - var connector = this.getShrinkConnector(); - connector.setVisibility(value); - } - - var textShape = this.getTextShape(); - textShape.setVisibility(value); - - }, - - setOpacity : function(opacity) { - var elem = this.get2DElement(); - elem.setOpacity(opacity); - - this.getShrinkConnector().setOpacity(opacity); - - var textShape = this.getTextShape(); - textShape.setOpacity(opacity); - }, - - _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); - } - - }, - - invariant : function() { - var line = this._outgoingLine; - var model = this.getModel(); - var isConnected = model.isConnected(); - - // Check consitency... - if ((isConnected && !line) || (!isConnected && line)) { - // $assert(false,'Illegal state exception.'); - } - }, - - /** - * type: - * onfocus - */ - 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); - }, - - 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); - }, - - - _setSize : function(size) { - $assert(size, "size can not be null"); - $assert($defined(size.width), "size seem not to be a valid element"); - - mindplot.NodeGraph.prototype.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); - }, - - 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]); - - } - }, - - _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { - $assert(false, "this method must be overided"); - }, - - disconnect : function(workspace) { - var outgoingLine = this.getOutgoingLine(); - if ($defined(outgoingLine)) { - $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); - } - - } - }, - - getOrder : function() { - var model = this.getModel(); - return model.getOrder(); - }, - - setOrder : function(value) { - var model = this.getModel(); - model.setOrder(value); - }, - - connectTo : function(targetTopic, workspace, isVisible) { - $assert(!this._outgoingLine, 'Could not connect an already connected node'); - $assert(targetTopic != this, 'Cilcular connection are not allowed'); - $assert(targetTopic, 'Parent Graph can not be null'); - $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 ($defined(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(); - }, - - _appendChild : function(child) { - var children = this._getChildren(); - children.push(child); - }, - - _removeChild : function(child) { - var children = this._getChildren(); - children.erase(child); - }, - - _getChildren : function() { - var result = this._children; - if (!$defined(result)) { - this._children = []; - result = this._children; - } - return result; - }, - - removeFromWorkspace : function(workspace) { - var elem2d = this.get2DElement(); - workspace.removeChild(elem2d); - var line = this.getOutgoingLine(); - if ($defined(line)) { - workspace.removeChild(line); - } - this._isInWorkspace = false; - }, - - addToWorkspace : function(workspace) { - var elem = this.get2DElement(); - workspace.appendChild(elem); - this._isInWorkspace = true; - }, - - isInWorkspace : function() { - return this._isInWorkspace; - }, - - createDragNode : function() { - var dragNode = mindplot.NodeGraph.prototype.createDragNode.call(this); - - // Is the node already connected ? - var targetTopic = this.getOutgoingConnectedTopic(); - if ($defined(targetTopic)) { - dragNode.connectTo(targetTopic); - } - return dragNode; - }, - - 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 + 2; - var pos = this._offset / 2 - 1; - if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE) { - var factor = 0.25; - height = (width * factor < height ? height : width * factor); - pos = (height - sizeHeight + 3) / 2; - } - - var newSize = {width:width,height:height}; - this.setSize(newSize, false, updatePosition); - - // Positionate node ... - textShape.setPosition(iconOffset + this._offset + 2, pos); - textShape.setTextSize(sizeWidth, sizeHeight); - var iconGroup = this.getIconGroup(); - if ($defined(iconGroup)) - iconGroup.updateIconGroupPosition(); - } - }, - - INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid'}, - - addHelper : function(helper) { - helper.addToGroup(this.get2DElement()); - this._helpers.push(helper); - } -}); - - -mindplot.Topic.CONNECTOR_WIDTH = 6; -mindplot.Topic.OUTER_SHAPE_ATTRIBUTES = {fillColor:'#dbe2e6',stroke:'1 solid #77555a',x:0,y:0}; - -/* - * 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.CentralTopic = new Class({ - - Extends:mindplot.Topic, - initialize: function(model) { - this.parent(model); - }, - - workoutIncomingConnectionPoint : function(sourcePosition) { - return this.getPosition(); - }, - - getTopicType : function() { - return mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE; - }, - - setCursor : function(type) { - type = (type == 'move') ? 'default' : type; - mindplot.Topic.prototype.setCursor.call(this, type); - }, - - isConnectedToCentralTopic : function() { - return false; - }, - - createChildModel : function(prepositionate) { - // Create a new node ... - var model = this.getModel(); - var mindmap = model.getMindmap(); - var childModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); - - if (prepositionate) { - if (!$defined(this.___siblingDirection)) { - this.___siblingDirection = 1; - } - - // Position following taking into account this internal flag ... - if (this.___siblingDirection == 1) { - - childModel.setPosition(150, 0); - } else { - childModel.setPosition(-150, 0); - } - this.___siblingDirection = -this.___siblingDirection; - } - // Create a new node ... - childModel.setOrder(0); - - return childModel; - }, - - _defaultShapeType : function() { - return mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT; - }, - - - updateTopicShape : function() { - - }, - - _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { - - // Center main topic ... - var zeroPoint = new core.Point(0, 0); - this.setPosition(zeroPoint); - }, - - _defaultText : function() { - return "Central Topic"; - }, - - _defaultBackgroundColor : function() { - return "#f7f7f7"; - }, - - _defaultBorderColor : function() { - return "#023BB9"; - }, - - _defaultFontStyle : function() { - return { - font:"Verdana", - size: 10, - style:"normal", - weight:"bold", - color:"#023BB9" - }; - } -});/* - * 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.MainTopic = new Class({ - Extends: mindplot.Topic, - initialize : function(model) { - this.parent(model); - }, - - INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid #009900'}, - - createSiblingModel : function(positionate) { - var siblingModel = null; - var parentTopic = this.getOutgoingConnectedTopic(); - if (parentTopic != null) { - // Create a new node ... - var model = this.getModel(); - var mindmap = model.getMindmap(); - siblingModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); - - // Positionate following taking into account the sibling positon. - if (positionate && parentTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - var pos = this.getPosition(); - siblingModel.setPosition(pos.x, pos.y); - } - - // Create a new node ... - var order = this.getOrder() + 1; - siblingModel.setOrder(order); - } - return siblingModel; - }, - - createChildModel : function(prepositionate) { - // Create a new node ... - var model = this.getModel(); - var mindmap = model.getMindmap(); - var childModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); - - // Get the hights model order position ... - var children = this._getChildren(); - var order = -1; - for (var i = 0; i < children.length; i++) { - var child = children[i]; - if (child.getOrder() > order) { - order = child.getOrder(); - } - } - // Create a new node ... - childModel.setOrder(order + 1); - return childModel; - }, - - - _buildDragShape : function() { - var innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES); - var size = this.getSize(); - innerShape.setSize(size.width, size.height); - innerShape.setPosition(0, 0); - innerShape.setOpacity(0.5); - innerShape.setCursor('default'); - innerShape.setVisibility(true); - - var brColor = this.getBorderColor(); - innerShape.setAttribute("strokeColor", brColor); - - var bgColor = this.getBackgroundColor(); - innerShape.setAttribute("fillColor", bgColor); - - // Create group ... - var groupAttributes = {width: 100, height:100,coordSizeWidth:100,coordSizeHeight:100}; - var group = new web2d.Group(groupAttributes); - group.appendChild(innerShape); - - // Add Text ... - var textShape = this._buildTextShape(true); - var text = this.getText(); - textShape.setText(text); - textShape.setOpacity(0.5); - group.appendChild(textShape); - - return group; - }, - - - _defaultShapeType : function() { - return mindplot.model.NodeModel.SHAPE_TYPE_LINE; - }, - - updateTopicShape : function(targetTopic, workspace) { - // Change figure based on the connected topic ... - var model = this.getModel(); - var shapeType = model.getShapeType(); - if (targetTopic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - if (!$defined(shapeType)) { - // Get the real shape type ... - shapeType = this.getShapeType(); - this._setShapeType(shapeType, false); - } - } - this._helpers.forEach(function(helper) { - helper.moveToFront(); - }); - }, - - disconnect : function(workspace) { - mindplot.Topic.prototype.disconnect.call(this, workspace); - var size = this.getSize(); - - var model = this.getModel(); - var shapeType = model.getShapeType(); - if (!$defined(shapeType)) { - // Change figure ... - shapeType = this.getShapeType(); - this._setShapeType(mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT, false); - } - var innerShape = this.getInnerShape(); - innerShape.setVisibility(true); - }, - - getTopicType : function() { - return "MainTopic"; - }, - - _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { - - if (updatePosition == false && this.getModel().getFinalPosition()) { - this.setPosition(this.getModel().getFinalPosition(), false); - } - else { - var xOffset = Math.round((newSize.width - oldSize.width) / 2); - var pos = this.getPosition(); - if ($defined(pos)) { - if (pos.x > 0) { - pos.x = pos.x + xOffset; - } else { - pos.x = pos.x - xOffset; - } - this.setPosition(pos); - } - } - }, - - setPosition : function(point, fireEvent) { - mindplot.Topic.prototype.setPosition.call(this, point); - - // Update board zero entry position... - if (fireEvent != false) - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, [this]); - }, - - workoutIncomingConnectionPoint : function(sourcePosition) { - $assert(sourcePosition, 'sourcePoint can not be null'); - var pos = this.getPosition(); - var size = this.getSize(); - - var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); - var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); - if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { - result.y = result.y + (this.getSize().height / 2); - } - - // Move a little the position... - var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; - if (this.getPosition().x > 0) { - result.x = result.x + offset; - } else { - result.x = result.x - offset; - } - - 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 size = this.getSize(); - - var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); - var result; - if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { -// if (!this.isConnectedToCentralTopic()) -// { - result = new core.Point(); - if (!isAtRight) { - result.x = pos.x + (size.width / 2); - } else { - result.x = pos.x - (size.width / 2); - } - result.y = pos.y + (size.height / 2); - /*} else - { - // In this case, connetion line is not used as shape figure. - result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); - result.y = pos.y + (size.height / 2); - */ - /*if(result.y>0){ - result.y+=1; - }*/ - /* - - // Correction factor ... - if (!isAtRight) - { - result.x = result.x + 2; - } else - { - result.x = result.x - 2; - } - - }*/ - } else { - result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); - } - result.x = Math.ceil(result.x); - result.y = Math.ceil(result.y); - return result; - }, - - - isConnectedToCentralTopic : function() { - var model = this.getModel(); - var parent = model.getParent(); - - return parent && parent.getType() === mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE; - }, - - _defaultText : function() { - var targetTopic = this.getOutgoingConnectedTopic(); - var result = ""; - if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - result = "Main Topic"; - } else { - result = "Sub Topic"; - } - } else { - result = "Isolated Topic"; - } - return result; - }, - - _defaultFontStyle : function() { - var targetTopic = this.getOutgoingConnectedTopic(); - var result; - if ($defined(targetTopic)) { - if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - result = { - font:"Arial", - size: 8, - style:"normal", - weight:"normal", - color:"#525c61" - }; - } else { - result = { - font:"Arial", - size: 6, - style:"normal", - weight:"normal", - color:"#525c61" - }; - } - } else { - result = { - font:"Verdana", - size: 8, - style:"normal", - weight:"normal", - color:"#525c61" - }; - } - return result; - }, - - _defaultBackgroundColor : function() { - return "#E0E5EF"; - }, - - _defaultBorderColor : function() { - return '#023BB9'; - }, - addSibling : function() { - var order = this.getOrder(); - } -}); -/* -* 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.DragTopic = function(dragShape, draggedNode) -{ - $assert(dragShape, 'Rect can not be null.'); - $assert(draggedNode, 'draggedNode can not be null.'); - - this._elem2d = dragShape; - this._order = null; - this._draggedNode = draggedNode; - this._position = new core.Point(); -}; - -mindplot.DragTopic.initialize = function(workspace) -{ - var pivot = mindplot.DragTopic.__getDragPivot(); - workspace.appendChild(pivot); -}; - -mindplot.DragTopic.prototype.setOrder = function(order) -{ - this._order = order; -}; - -mindplot.DragTopic.prototype.setPosition = function(x, y) -{ - this._position.setValue(x, y); - - // Elements are positioned in the center. - // All topic element must be positioned based on the innerShape. - var draggedNode = this._draggedNode; - var size = draggedNode.getSize(); - - var cx = Math.ceil(x - (size.width / 2)); - var cy = Math.ceil(y - (size.height / 2)); - - // Update visual position. - this._elem2d.setPosition(cx, cy); -}; - -mindplot.DragTopic.prototype.getInnerShape = function() -{ - return this._elem2d; -}; - -mindplot.DragTopic.prototype.disconnect = function(workspace) -{ - // Clear connection line ... - var dragPivot = this._getDragPivot(); - dragPivot.disconnect(workspace); -}; - -mindplot.DragTopic.prototype.canBeConnectedTo = function(targetTopic) -{ - $assert(targetTopic, 'parent can not be null'); - - var result = true; - if (!targetTopic.areChildrenShrinked() && !targetTopic.isCollapsed()) - { - // Dragged node can not be connected to himself. - if (targetTopic == this._draggedNode) - { - result = false; - } else - { - var draggedNode = this.getDraggedTopic(); - var topicPosition = this.getPosition(); - - var targetTopicModel = targetTopic.getModel(); - var childTopicModel = draggedNode.getModel(); - - result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18); - } - } else - { - result = false; - } - return result; -}; - -mindplot.DragTopic.prototype.connectTo = function(parent) -{ - $assert(parent, 'Parent connection node can not be null.'); - - var dragPivot = this._getDragPivot(); - dragPivot.connectTo(parent); -}; - -mindplot.DragTopic.prototype.getDraggedTopic = function() -{ - return this._draggedNode; -}; - - -mindplot.DragTopic.prototype.removeFromWorkspace = function(workspace) -{ - // Remove drag shadow. - workspace.removeChild(this._elem2d); - - // Remove pivot shape. To improve performace it will not be removed. Only the visilility will be changed. - var dragPivot = this._getDragPivot(); - dragPivot.setVisibility(false); -}; - -mindplot.DragTopic.prototype.addToWorkspace = function(workspace) -{ - workspace.appendChild(this._elem2d); - var dragPivot = this._getDragPivot(); - - dragPivot.addToWorkspace(workspace); - dragPivot.setVisibility(true); -}; - -mindplot.DragTopic.prototype._getDragPivot = function() -{ - return mindplot.DragTopic.__getDragPivot(); -}; - -mindplot.DragTopic.__getDragPivot = function() -{ - var result = mindplot.DragTopic._dragPivot; - if (!$defined(result)) - { - result = new mindplot.DragPivot(); - mindplot.DragTopic._dragPivot = result; - } - return result; -}; - - -mindplot.DragTopic.prototype.getPosition = function() -{ - return this._position; -}; - -mindplot.DragTopic.prototype.isDragTopic = function() -{ - return true; -}; - -mindplot.DragTopic.prototype.updateDraggedTopic = function(workspace) -{ - $assert(workspace, 'workspace can not be null'); - - var dragPivot = this._getDragPivot(); - var draggedTopic = this.getDraggedTopic(); - - var isDragConnected = this.isConnected(); - var actionRunner = mindplot.DesignerActionRunner.getInstance(); - var topicId = draggedTopic.getId(); - var command = new mindplot.commands.DragTopicCommand(topicId); - - if (isDragConnected) - { - - var targetTopic = this.getConnectedToTopic(); - if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) - { - // Update topic position ... - var dragPivotPosition = dragPivot.getPosition(); - - // Must position the dragged topic taking into account the current node size. - var pivotSize = dragPivot.getSize(); - var draggedTopicSize = draggedTopic.getSize(); - var xOffset = draggedTopicSize.width - pivotSize.width; - xOffset = Math.round(xOffset / 2); - - if (dragPivotPosition.x > 0) - { - dragPivotPosition.x = parseInt(dragPivotPosition.x) + xOffset; - } - else - { - dragPivotPosition.x = parseInt(dragPivotPosition.x) - xOffset; - } - // Set new position ... - command.setPosition(dragPivotPosition); - - } else - { - // Main topic connections can be positioned only with the order ... - command.setOrder(this._order); - } - - // Set new parent topic .. - command.setParetTopic(targetTopic); - } else { - - // If the node is not connected, positionate based on the original drag topic position. - var dragPosition = this.getPosition(); - command = new mindplot.commands.DragTopicCommand(topicId, dragPosition); - command.setPosition(dragPosition); - } - actionRunner.execute(command); -}; - -mindplot.DragTopic.prototype.setBoardPosition = function(point) -{ - $assert(point, 'point can not be null'); - var dragPivot = this._getDragPivot(); - dragPivot.setPosition(point); -}; - - -mindplot.DragTopic.prototype.getBoardPosition = function(point) -{ - $assert(point, 'point can not be null'); - var dragPivot = this._getDragPivot(); - return dragPivot.getPosition(); -}; - -mindplot.DragTopic.prototype.getConnectedToTopic = function() -{ - var dragPivot = this._getDragPivot(); - return dragPivot.getTargetTopic(); -}; - -mindplot.DragTopic.prototype.isConnected = function() -{ - return this.getConnectedToTopic() != null; -}; - -mindplot.DragTopic.PIVOT_SIZE = {width:50,height:10}; -/* -* 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.DragManager = function(workspace) -{ - this._workspace = workspace; - this._listeners = {}; -}; - -mindplot.DragManager.prototype.add = function(node) -{ - // Add behaviour ... - var workspace = this._workspace; - var screen = workspace.getScreenManager(); - var dragManager = this; - - var mouseDownListener = function(event) - { - if (workspace.isWorkspaceEventsEnabled()) - { - // Disable double drag... - workspace.enableWorkspaceEvents(false); - - // Set initial position. - var dragNode = node.createDragNode(); - var mousePos = screen.getWorkspaceMousePosition(event); - dragNode.setPosition(mousePos.x, mousePos.y); - - // Register mouse move listener ... - var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager); - screen.addEventListener('mousemove', mouseMoveListener); - - // Register mouse up listeners ... - var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager); - screen.addEventListener('mouseup', mouseUpListener); - - // Execute Listeners .. - var startDragListener = dragManager._listeners['startdragging']; - startDragListener(event, node); - - // Change cursor. - window.document.body.style.cursor = 'move'; - } - }; - dragManager._mouseDownListener = mouseDownListener; - - node.addEventListener('mousedown', mouseDownListener); -}; - -mindplot.DragManager.prototype.remove = function(node) -{ - var nodes = this._topics; - var contained = false; - var index = -1; - for (var i = 0; i < nodes.length; i++) { - if (nodes[i] == node) { - contained = true; - index = i; - } - } - if (contained) - { - elem = new Array(); - } -}; - -mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dragNode, dragManager) -{ - var screen = workspace.getScreenManager(); - var result = function(event) { - - if (!dragNode._isInTheWorkspace) - { - // Add shadow node to the workspace. - workspace.appendChild(dragNode); - dragNode._isInTheWorkspace = true; - } - - var pos = screen.getWorkspaceMousePosition(event); - dragNode.setPosition(pos.x, pos.y); - - // Call mouse move listeners ... - var dragListener = dragManager._listeners['dragging']; - if ($defined(dragListener)) - { - dragListener(event, dragNode); - } - - event.preventDefault(); - }.bindWithEvent(this); - dragManager._mouseMoveListener = result; - return result; -}; - -mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, dragNode, dragManager) -{ - var screen = workspace.getScreenManager(); - var result = function(event) { - - $assert(dragNode.isDragTopic, 'dragNode must be an DragTopic'); - - // Remove drag node from the workspace. - var hasBeenDragged = dragNode._isInTheWorkspace; - if (dragNode._isInTheWorkspace) - { - dragNode.removeFromWorkspace(workspace); - } - - // Remove all the events. - screen.removeEventListener('mousemove', dragManager._mouseMoveListener); - screen.removeEventListener('mouseup', dragManager._mouseUpListener); - - // Help GC - dragManager._mouseMoveListener = null; - dragManager._mouseUpListener = null; - - // Execute Listeners only if the node has been moved. - var endDragListener = dragManager._listeners['enddragging']; - endDragListener(event, dragNode); - - if (hasBeenDragged) - { - dragNode._isInTheWorkspace = false; - } - - // Change the cursor to the default. - window.document.body.style.cursor = 'default'; - - workspace.enableWorkspaceEvents(true); - - }; - dragManager._mouseUpListener = result; - return result; -}; - -/** - * type: - * - startdragging. - * - dragging - * - enddragging - */ -mindplot.DragManager.prototype. addEventListener = function(type, listener) -{ - this._listeners[type] = listener; -}; - -mindplot.DragManager.DRAG_PRECISION_IN_SEG = 100; -/* - * 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.DragPivot = new Class({ - initialize:function() { - this._position = new core.Point(); - this._size = mindplot.DragTopic.PIVOT_SIZE; - this._line = null; - - this._straightLine = this._buildStraightLine(); - this._curvedLine = this._buildCurvedLine(); - this._dragPivot = this._buildRect(); - this._connectRect = this._buildRect(); - this._targetTopic = null; - }, - - getTargetTopic : function() { - return this._targetTopic; - }, - - _buildStraightLine : function() { - var line = new web2d.CurvedLine(); - line.setStyle(web2d.CurvedLine.SIMPLE_LINE); - line.setStroke(1, 'solid', '#CC0033'); - line.setOpacity(0.4); - line.setVisibility(false); - return line; - }, - - _buildCurvedLine : function() { - var line = new web2d.CurvedLine(); - line.setStyle(web2d.CurvedLine.SIMPLE_LINE); - line.setStroke(1, 'solid', '#CC0033'); - line.setOpacity(0.4); - line.setVisibility(false); - return line; - }, - - _redraw : function(pivotPosition) { - // Update line position. - $assert(this.getTargetTopic(), 'Illegal invocation. Target node can not be null'); - - var pivotRect = this._getPivotRect(); - var currentPivotPosition = pivotRect.getPosition(); - - // Pivot position has not changed. In this case, position change is not required. - var targetTopic = this.getTargetTopic(); - if (currentPivotPosition.x != pivotPosition.x || currentPivotPosition.y != pivotPosition.y) { - var position = this._position; - var fromPoint = targetTopic.workoutIncomingConnectionPoint(position); - - // Calculate pivot connection point ... - var size = this._size; - var targetPosition = targetTopic.getPosition(); - var line = this._line; - - // Update Line position. - var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, position); - var pivotPoint = mindplot.util.Shape.calculateRectConnectionPoint(position, size, isAtRight); - line.setFrom(pivotPoint.x, pivotPoint.y); - - // Update rect position - pivotRect.setPosition(pivotPosition.x, pivotPosition.y); - - // Display elements if it's required... - if (!pivotRect.isVisible()) { - // Make line visible only when the position has been already changed. - // This solve several strange effects ;) - var targetPoint = targetTopic.workoutIncomingConnectionPoint(pivotPoint); - line.setTo(targetPoint.x, targetPoint.y); - - this.setVisibility(true); - } - } - }, - - setPosition : function(point) { - this._position = point; - - // Update visual position. - var size = this.getSize(); - - var cx = point.x - (parseInt(size.width) / 2); - var cy = point.y - (parseInt(size.height) / 2); - - // Update line ... - if (this.getTargetTopic()) { - var pivotPosition = {x:cx,y:cy}; - this._redraw(pivotPosition); - } - }, - - getPosition : function() { - return this._position; - }, - - _buildRect : function() { - var size = this._size; - var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'}; - var rect = new web2d.Rect(0, rectAttributes); - rect.setVisibility(false); - return rect; - }, - - _buildConnectRect : function() { - var size = this._size; - var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'}; - var result = new web2d.Rect(0, rectAttributes); - return result; - }, - - _getPivotRect : function() { - return this._dragPivot; - }, - - getSize : function() { - var elem2d = this._getPivotRect(); - return elem2d.getSize(); - }, - - setVisibility : function(value) { - var pivotRect = this._getPivotRect(); - pivotRect.setVisibility(value); - - var connectRect = this._connectRect; - connectRect.setVisibility(value); - if ($defined(this._line)) { - this._line.setVisibility(value); - } - }, - - addToWorkspace : function(workspace) { - var pivotRect = this._getPivotRect(); - workspace.appendChild(pivotRect); - - var connectToRect = this._connectRect; - workspace.appendChild(connectToRect); - - // Add a hidden straight line ... - var straighLine = this._straightLine; - straighLine.setVisibility(false); - workspace.appendChild(straighLine); - straighLine.moveToBack(); - - // Add a hidden curved line ... - var curvedLine = this._curvedLine; - curvedLine.setVisibility(false); - workspace.appendChild(curvedLine); - curvedLine.moveToBack(); - - // Add a connect rect ... - var connectRect = this._connectRect; - connectRect.setVisibility(false); - workspace.appendChild(connectRect); - connectRect.moveToBack(); - }, - - removeFromWorkspace : function(workspace) { - var shape = this._getPivotRect(); - workspace.removeChild(shape); - - var connectToRect = this._connectRect; - workspace.removeChild(connectToRect); - - if ($defined(this._straightLine)) { - workspace.removeChild(this._straightLine); - } - - if ($defined(this._curvedLine)) { - workspace.removeChild(this._curvedLine); - } - }, - - connectTo : function(targetTopic) { - $assert(!this._outgoingLine, 'Could not connect an already connected node'); - $assert(targetTopic != this, 'Cilcular connection are not allowed'); - $assert(targetTopic, 'parent can not be null'); - - this._targetTopic = targetTopic; - if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - this._line = this._straightLine; - } else { - this._line = this._curvedLine; - } - - // Connected to Rect ... - var connectRect = this._connectRect; - var targetSize = targetTopic.getSize(); - var width = targetSize.width; - var height = targetSize.height; - connectRect.setSize(width, height); - - var targetPosition = targetTopic.getPosition(); - var cx = Math.ceil(targetPosition.x - (width / 2)); - var cy = Math.ceil(targetPosition.y - (height / 2)); - connectRect.setPosition(cx, cy); - - // Change elements position ... - var pivotRect = this._getPivotRect(); - pivotRect.moveToFront(); - - }, - - disconnect : function(workspace) { - $assert(workspace, 'workspace can not be null.'); - $assert(this._targetTopic, 'There are not connected topic.'); - - this.setVisibility(false); - this._targetTopic = null; - this._line = null; - } -}); -/* - * 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.Board = new Class({ - initialize : function(defaultHeight, referencePoint) { - $assert(referencePoint, "referencePoint can not be null"); - this._defaultWidth = defaultHeight; - this._entries = new mindplot.BidirectionalArray(); - this._referencePoint = referencePoint; - }, - - getReferencePoint : function() { - return this._referencePoint; - }, - - _removeEntryByOrder : function(order, position) { - var board = this._getBoard(position); - var entry = board.lookupEntryByOrder(order); - - $assert(!entry.isAvailable(), 'Entry must not be available in order to be removed.Entry Order:' + order); - entry.removeTopic(); - board.update(entry); - }, - - removeTopicFromBoard : function(topic) { - var position = topic.getPosition(); - var order = topic.getOrder(); - - this._removeEntryByOrder(order, position); - topic.setOrder(null); - }, - - positionateDragTopic :function(dragTopic) { - throw "this method must be overrided"; - }, - - getHeight: function() { - var board = this._getBoard(); - return board.getHeight(); - } -}); - -/** - * --------------------------------------- - */ -mindplot.BidirectionalArray = new Class({ - - initialize: function() { - this._leftElem = []; - this._rightElem = []; - }, - - get :function(index, sign) { - $assert(index, 'Illegal argument, index must be passed.'); - if ($defined(sign)) { - $assert(index >= 0, 'Illegal absIndex value'); - index = index * sign; - } - - var result = null; - if (index >= 0 && index < this._rightElem.length) { - result = this._rightElem[index]; - } else if (index < 0 && Math.abs(index) < this._leftElem.length) { - result = this._leftElem[Math.abs(index)]; - } - return result; - }, - - set : function(index, elem) { - $assert(index, 'Illegal index value'); - - var array = (index >= 0) ? this._rightElem : this._leftElem; - array[Math.abs(index)] = elem; - }, - - length : function(index) { - $assert(index, 'Illegal index value'); - return (index >= 0) ? this._rightElem.length : this._leftElem.length; - }, - - upperLength : function() { - return this.length(1); - }, - - lowerLength : function() { - return this.length(-1); - }, - - inspect : function() { - var result = '{'; - var lenght = this._leftElem.length; - for (var i = 0; i < lenght; i++) { - var entry = this._leftElem[lenght - i - 1]; - if (entry != null) { - if (i != 0) { - result += ', '; - } - result += entry.inspect(); - } - } - - lenght = this._rightElem.length; - for (var i = 0; i < lenght; i++) { - var entry = this._rightElem[i]; - if (entry != null) { - if (i != 0) { - result += ', '; - } - result += entry.inspect(); - } - } - result += '}'; - - return result; - - } -});/* - * 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.CentralTopicBoard = new Class({ - Extends: mindplot.Board, - initialize:function(centralTopic, layoutManager) { - var point = new core.Point(0, 0); - this._layoutManager = layoutManager; - this._rightBoard = new mindplot.VariableDistanceBoard(50, point); - this._leftBoard = new mindplot.VariableDistanceBoard(50, point); - this._centralTopic = centralTopic; - }, - - _getBoard : function(position) { - return (position.x >= 0) ? this._rightBoard : this._leftBoard; - }, - - positionateDragTopic : function(dragTopic) { - $assert(dragTopic != null, 'dragTopic can not be null'); - $assert(dragTopic.isDragTopic, 'dragTopic must be DragTopic instance'); - - // This node is a main topic node. Position - var dragPos = dragTopic.getPosition(); - var board = this._getBoard(dragPos); - - // 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(); - } - - - // MainTopic can not be positioned over the drag topic ... - var centralTopic = this._centralTopic; - var centralTopicSize = centralTopic.getSize(); - var halfWidth = (centralTopicSize.width / 2); - if (Math.abs(dragPos.x) < halfWidth + 60) { - var distance = halfWidth + 60; - dragPos.x = (dragPos.x > 0) ? distance : -distance; - } - - // Update board position. - var pivotPos = new core.Point(dragPos.x, yCoord); - dragTopic.setBoardPosition(pivotPos); - }, - - - addBranch : function(topic) { - // Update topic position ... - var position = topic.getPosition(); - - var order = topic.getOrder(); - var board = this._getBoard(position); - var entry = null; - if (order != null) { - entry = board.lookupEntryByOrder(order); - } else { - entry = board.lookupEntryByPosition(position); - } - - // If the entry is not available, I must swap the the entries... - if (!entry.isAvailable()) { - board.freeEntry(entry); - } - - // Add it to the board ... - entry.setTopic(topic); - board.update(entry); - }, - - updateChildrenPosition : function(topic, xOffset, modifiedTopics) { - var board = this._rightBoard; - var oldReferencePosition = board.getReferencePoint(); - var newReferencePosition = new core.Point(oldReferencePosition.x + xOffset, oldReferencePosition.y); - board.updateReferencePoint(newReferencePosition); - - board = this._leftBoard; - oldReferencePosition = board.getReferencePoint(); - newReferencePosition = new core.Point(oldReferencePosition.x - xOffset, oldReferencePosition.y); - board.updateReferencePoint(newReferencePosition); - }, - - repositionate : function() { - //@todo: implement .. - } -});/* - * 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.MainTopicBoard = new Class({ - Extends:mindplot.Board, - initialize:function(topic, layoutManager) { - this._layoutManager = layoutManager; - this._topic = topic; - this._board = null; - this._height = 0; - }, - - - _getBoard: function() { - if (!$defined(this._board)) { - var topic = this._topic; - this._board = new mindplot.FixedDistanceBoard(mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT, topic, this._layoutManager); - } - return this._board; - }, - - updateReferencePoint : function(position) { - this._board.updateReferencePoint(position); - }, - - updateChildrenPosition : function(topic) { - var board = this._getBoard(); - board.updateReferencePoint(); - }, - - positionateDragTopic : function(dragTopic) { - $assert(dragTopic != null, 'dragTopic can not be null'); - $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 doesn't take into account the size of the shape. - */ - _workoutXBorderDistance : function(topic) { - $assert(topic, 'topic can not be null'); - var board = this._getBoard(); - return board.workoutXBorderDistance(topic); - }, - - addBranch : function(topic) { - var order = topic.getOrder(); - $assert(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(); - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent, [parentTopic]); - } - }, - - repositionate : function() { - var board = this._getBoard(); - board.repositionate(); - }, - - 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(); - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent, [connectedTopic]); - } - } -}); - -mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT = 18; -/* - * 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.ConnectionLine = new Class({ - initialize:function(sourceNode, targetNode, lineType) { - $assert(targetNode, 'parentNode node can not be null'); - $assert(sourceNode, 'childNode node can not be null'); - $assert(sourceNode != targetNode, 'Cilcular connection'); - - this._targetTopic = targetNode; - this._sourceTopic = sourceNode; - - var strokeColor = mindplot.ConnectionLine.getStrokeColor(); - var line; - if (targetNode.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - line = this._createLine(lineType, mindplot.ConnectionLine.CURVED); - // line = new web2d.Line(); - if (line.getType() == "CurvedLine") { - var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); - line.setSrcControlPoint(ctrlPoints[0]); - line.setDestControlPoint(ctrlPoints[1]); - } - line.setStroke(1, 'solid', strokeColor); - } else { - line = this._createLine(lineType, mindplot.ConnectionLine.SIMPLE_CURVED); - if (line.getType() == "CurvedLine") { - var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); - line.setSrcControlPoint(ctrlPoints[0]); - line.setDestControlPoint(ctrlPoints[1]); - } - // line = new web2d.PolyLine(); - line.setStroke(1, 'solid', strokeColor); - } - - this._line2d = line; - }, - - _getCtrlPoints : function(sourceNode, targetNode) { - var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition()); - var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition()); - var deltaX = (srcPos.x - destPos.x) / 3; - return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)]; - }, - - _createLine : function(lineType, defaultStyle) { - if (!$defined(lineType)) { - lineType = defaultStyle; - } - lineType = parseInt(lineType); - this._lineType = lineType; - var line = null; - switch (lineType) { - case mindplot.ConnectionLine.POLYLINE: - line = new web2d.PolyLine(); - break; - case mindplot.ConnectionLine.CURVED: - line = new web2d.CurvedLine(); - break; - case mindplot.ConnectionLine.SIMPLE_CURVED: - line = new web2d.CurvedLine(); - line.setStyle(web2d.CurvedLine.SIMPLE_LINE); - break; - default: - line = new web2d.Line(); - break; - } - return line; - }, - - setVisibility : function(value) { - this._line2d.setVisibility(value); - }, - - isVisible : function() { - return this._line2d.isVisible(); - }, - - setOpacity : function(opacity) { - this._line2d.setOpacity(opacity); - }, - - redraw : function() { - var line2d = this._line2d; - var sourceTopic = this._sourceTopic; - var sourcePosition = sourceTopic.getPosition(); - - var targetTopic = this._targetTopic; - var targetPosition = targetTopic.getPosition(); - - var sPos,tPos; - sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition, false); - tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition, false); - - line2d.setFrom(tPos.x, tPos.y); - line2d.setTo(sPos.x, sPos.y); - - if (line2d.getType() == "CurvedLine") { - var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic); - line2d.setSrcControlPoint(ctrlPoints[0]); - line2d.setDestControlPoint(ctrlPoints[1]); - } -// line2d.moveToBack(); - - // Add connector ... - this._positionateConnector(targetTopic); - - }, - - _positionateConnector : function(targetTopic) { - var targetPosition = targetTopic.getPosition(); - var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; - var targetTopicSize = targetTopic.getSize(); - var y; - if (targetTopic.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { - y = targetTopicSize.height; - } else { - y = targetTopicSize.height / 2; - } - y = y - offset; - - var connector = targetTopic.getShrinkConnector(); - if (Math.sign(targetPosition.x) > 0) { - var x = targetTopicSize.width; - connector.setPosition(x, y); - } - else { - var x = -mindplot.Topic.CONNECTOR_WIDTH; - connector.setPosition(x, y); - } - }, - - setStroke : function(color, style, opacity) { - var line2d = this._line2d; - this._line2d.setStroke(null, null, color, opacity); - }, - - addToWorkspace : function(workspace) { - workspace.appendChild(this._line2d); - this._line2d.moveToBack(); - }, - - removeFromWorkspace : function(workspace) { - workspace.removeChild(this._line2d); - }, - - getTargetTopic : function() { - return this._targetTopic; - }, - - getSourceTopic : function() { - return this._sourceTopic; - }, - - getLineType : function() { - return this._lineType; - }, - - getLine : function() { - return this._line2d; - }, - - getModel : function() { - return this._model; - }, - - setModel : function(model) { - this._model = model; - }, - - getType : function() { - return "ConnectionLine"; - }, - - getId : function() { - return this._model.getId(); - }, - - moveToBack : function() { - this._line2d.moveToBack(); - }, - - moveToFront : function() { - this._line2d.moveToFront(); - } -}); - -mindplot.ConnectionLine.getStrokeColor = function() { - return '#495879'; -}; - -mindplot.ConnectionLine.SIMPLE = 0; -mindplot.ConnectionLine.POLYLINE = 1; -mindplot.ConnectionLine.CURVED = 2; +});/* + * 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.NodeGraph = new Class({ + initialize:function(nodeModel) { + $assert(nodeModel,"model can not be null"); + this._mouseEvents = true; + this.setModel(nodeModel); + this._onFocus = false; + }, + + getType : function() { + var model = this.getModel(); + return model.getType(); + }, + + setId : function(id) { + this.getModel().setId(id); + }, + + _set2DElement : function(elem2d) { + this._elem2d = elem2d; + }, + + get2DElement : function() { + $assert(this._elem2d, 'NodeGraph has not been initialized propertly'); + return this._elem2d; + }, + + setPosition : function(point) { + // Elements are positioned in the center. + var size = this._model.getSize(); + this._elem2d.setPosition(point.x - (size.width / 2), point.y - (size.height / 2)); + this._model.setPosition(point.x, point.y); + }, + + addEventListener : function(type, listener) { + var elem = this.get2DElement(); + elem.addEventListener(type, listener); + }, + + isNodeGraph : function() { + return true; + }, + + setMouseEventsEnabled : function(isEnabled) { + this._mouseEvents = isEnabled; + }, + + isMouseEventsEnabled : function() { + return this._mouseEvents; + }, + + getSize : function() { + return this._model.getSize(); + }, + + setSize : function(size) { + this._model.setSize(size.width, size.height); + }, + + getModel + : + function() { + $assert(this._model, 'Model has not been initialized yet'); + return this._model; + } + , + + setModel : function(model) { + $assert(model, 'Model can not be null'); + this._model = model; + }, + + getId : function() { + return this._model.getId(); + }, + + setOnFocus : function(focus) { + this._onFocus = focus; + var outerShape = this.getOuterShape(); + if (focus) { + outerShape.setFill('#c7d8ff'); + outerShape.setOpacity(1); + + } else { + // @todo: node must not know about the topic. + + outerShape.setFill(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES.fillColor); + outerShape.setOpacity(0); + } + this.setCursor('move'); + }, + + isOnFocus : function() { + return this._onFocus; + }, + + dispose : function(workspace) { + workspace.removeChild(this); + }, + + createDragNode : function() { + var dragShape = this._buildDragShape(); + return new mindplot.DragTopic(dragShape, this); + }, + + _buildDragShape : function() { + $assert(false, '_buildDragShape must be implemented by all nodes.'); + }, + + getPosition : function() { + var model = this.getModel(); + return model.getPosition(); + } +}); + +mindplot.NodeGraph.create = function(nodeModel) { + $assert(nodeModel, 'Model can not be null'); + + var type = nodeModel.getType(); + $assert(type, 'Node model type can not be null'); + + var result; + if (type == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + result = new mindplot.CentralTopic(nodeModel); + } else + if (type == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { + result = new mindplot.MainTopic(nodeModel); + } else { + assert(false, "unsupported node type:" + type); + } + + return result; +}/* + * 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 = new Class({ + Extends:mindplot.NodeGraph, + initialize : function(model) { + this.parent(model); + this._children = []; + this._parent = null; + 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.model.NodeModel.CENTRAL_TOPIC_TYPE) { + this.setPosition(pos); + } + }, + + setShapeType : function(type) { + this._setShapeType(type, true); + + }, + + getParent : function() { + return this._parent; + }, + + _setShapeType : function(type, updateModel) { + // Remove inner shape figure ... + var model = this.getModel(); + if ($defined(updateModel) && 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 ($defined(dispatcher)) { + for (var i = 1; i < dispatcher._listeners.length; i++) { + innerShape.addEventListener('mousedown', dispatcher._listeners[i]); + } + } + + // Update figure size ... + var size = model.getSize(); + this.setSize(size, true); + + var group = this.get2DElement(); + group.appendChild(innerShape); + + // Move text to the front ... + var text = this.getTextShape(); + text.moveToFront(); + + //Move iconGroup to front ... + var iconGroup = this.getIconGroup(); + if ($defined(iconGroup)) { + iconGroup.moveToFront(); + } + //Move connector to front + var connector = this.getShrinkConnector(); + if ($defined(connector)) { + connector.moveToFront(); + } + + //Move helpers to front + this._helpers.forEach(function(helper) { + helper.moveToFront(); + }); + + } + + }, + + getShapeType : function() { + var model = this.getModel(); + var result = model.getShapeType(); + if (!$defined(result)) { + result = this._defaultShapeType(); + } + return result; + }, + + _removeInnerShape : function() { + var group = this.get2DElement(); + var innerShape = this.getInnerShape(); + group.removeChild(innerShape); + this._innerShape = null; + }, + + getInnerShape : function() { + if (!$defined(this._innerShape)) { + // Create inner box. + this._innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES); + + // Update bgcolor ... + var bgColor = this.getBackgroundColor(); + this._setBackgroundColor(bgColor, false); + + // Update border color ... + var brColor = this.getBorderColor(); + this._setBorderColor(brColor, false); + + // Define the pointer ... + if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + this._innerShape.setCursor('move'); + } else { + this._innerShape.setCursor('default'); + } + + } + return this._innerShape; + }, + + + buildShape : function(attributes, type) { + var result; + if (!$defined(type)) { + type = this.getShapeType(); + } + + if (type == mindplot.model.NodeModel.SHAPE_TYPE_RECT) { + result = new web2d.Rect(0, attributes); + } + else if (type == mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE) { + result = new web2d.Elipse(attributes); + } + else if (type == mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT) { + result = new web2d.Rect(0.3, attributes); + } + else if (type == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { + result = new web2d.Line({strokeColor:"#495879",strokeWidth:1, strokeOpacity:1}); + result.setSize = function(width, height) { + this.size = {width:width, height:height}; + result.setFrom(-1, height); + result.setTo(width + 1, height); + + // Lines will have the same color of the default connection lines... + var stokeColor = mindplot.ConnectionLine.getStrokeColor(); + result.setStroke(1, 'solid', stokeColor); + }; + + result.getSize = function() { + return this.size; + }; + + result.setPosition = function() { + }; + + var setStrokeFunction = result.setStroke; + result.setFill = function(color) { + + }; + + result.setStroke = function(color) { + + }; + } + else { + $assert(false, "Unsupported figure type:" + type); + } + + result.setPosition(0, 0); + return result; + }, + + + setCursor : function(type) { + var innerShape = this.getInnerShape(); + innerShape.setCursor(type); + + var outerShape = this.getOuterShape(); + outerShape.setCursor(type); + + var textShape = this.getTextShape(); + textShape.setCursor(type); + }, + + getOuterShape : function() { + if (!$defined(this._outerShape)) { + var rect = this.buildShape(mindplot.Topic.OUTER_SHAPE_ATTRIBUTES, mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT); + rect.setPosition(-2, -3); + rect.setOpacity(0); + this._outerShape = rect; + } + + return this._outerShape; + }, + + getTextShape : function() { + if (!$defined(this._text)) { + var model = this.getModel(); + this._text = this._buildTextShape(); + + // Set Text ... + var text = this.getText(); + this._setText(text, false); + } + return this._text; + }, + + getOrBuildIconGroup : function() { + if (!$defined(this._icon)) { + this._icon = this._buildIconGroup(); + var group = this.get2DElement(); + group.appendChild(this._icon.getNativeElement()); + this._icon.moveToFront(); + } + return this._icon; + }, + + getIconGroup : function() { + return this._icon; + }, + + _buildIconGroup : function(disableEventsListeners) { + var result = new mindplot.IconGroup(this); + var model = this.getModel(); + + //Icons + var icons = model.getIcons(); + for (var i = 0; i < icons.length; i++) { + // Update model identifier ... + var iconModel = icons[i]; + var icon = new mindplot.ImageIcon(iconModel, this, designer); + result.addIcon(icon); + } + + //Links + var links = model.getLinks(); + for (var i = 0; i < links.length; i++) { + this._hasLink = true; + this._link = new mindplot.LinkIcon(links[i], this, designer); + result.addIcon(this._link); + } + + //Notes + var notes = model.getNotes(); + for (var i = 0; i < notes.length; i++) { + this._hasNote = true; + this._note = new mindplot.Note(notes[i], this, designer); + result.addIcon(this._note); + } + + return result; + }, + + addLink : function(url, designer) { + var iconGroup = this.getOrBuildIconGroup(); + var model = this.getModel(); + var linkModel = model.createLink(url); + model.addLink(linkModel); + this._link = new mindplot.LinkIcon(linkModel, this, designer); + iconGroup.addIcon(this._link); + this._hasLink = true; + }, + + addNote : function(text, designer) { + var iconGroup = this.getOrBuildIconGroup(); + var model = this.getModel(); + text = escape(text); + var noteModel = model.createNote(text) + model.addNote(noteModel); + this._note = new mindplot.Note(noteModel, this, designer); + iconGroup.addIcon(this._note); + this._hasNote = true; + }, + + addIcon : function(iconType, designer) { + var iconGroup = this.getOrBuildIconGroup(); + var model = this.getModel(); + + // Update model ... + var iconModel = model.createIcon(iconType); + model.addIcon(iconModel); + + var imageIcon = new mindplot.ImageIcon(iconModel, this, designer); + iconGroup.addIcon(imageIcon); + + return imageIcon; + }, + + removeIcon : function(iconModel) { + + //Removing the icon from MODEL + var model = this.getModel(); + model._removeIcon(iconModel); + + //Removing the icon from UI + var iconGroup = this.getIconGroup(); + if ($defined(iconGroup)) { + var imgIcon = iconGroup.findIconFromModel(iconModel); + iconGroup.removeImageIcon(imgIcon); + if (iconGroup.getIcons().length == 0) { + this.get2DElement().removeChild(iconGroup.getNativeElement()); + this._icon = null; + } + this.updateNode(); + } + }, + + removeLink : function() { + var model = this.getModel(); + var links = model.getLinks(); + model._removeLink(links[0]); + var iconGroup = this.getIconGroup(); + if ($defined(iconGroup)) { + iconGroup.removeIcon(mindplot.LinkIcon.IMAGE_URL); + if (iconGroup.getIcons().length == 0) { + this.get2DElement().removeChild(iconGroup.getNativeElement()); + this._icon = null; + } + this.updateNode.delay(0, this); + } + this._link = null; + this._hasLink = false; + }, + + removeNote : function() { + var model = this.getModel(); + var notes = model.getNotes(); + model._removeNote(notes[0]); + var iconGroup = this.getIconGroup(); + if ($defined(iconGroup)) { + iconGroup.removeIcon(mindplot.Note.IMAGE_URL); + if (iconGroup.getIcons().length == 0) { + this.get2DElement().removeChild(iconGroup.getNativeElement()); + this._icon = null; + } + } + /*var elem = this; + var executor = function(editor) + { + return function() + { + elem.updateNode(); + }; + }; + + setTimeout(executor(this), 0);*/ + core.Executor.instance.delay(this.updateNode, 0, this); + this._note = null; + this._hasNote = false; + }, + + addRelationship : function(relationship) { + this._relationships.push(relationship); + }, + + removeRelationship : function(relationship) { + this._relationships.erase(relationship); + }, + + getRelationships : function() { + return this._relationships; + }, + + _buildTextShape : function(disableEventsListeners) { + var result = new web2d.Text(); + var font = {}; + + var family = this.getFontFamily(); + var size = this.getFontSize(); + var weight = this.getFontWeight(); + var style = this.getFontStyle(); + result.setFont(family, size, style, weight); + + var color = this.getFontColor(); + result.setColor(color); + + if (!disableEventsListeners) { + // Propagate mouse events ... + var topic = this; + result.addEventListener('mousedown', function(event) { + var eventDispatcher = topic.getInnerShape()._dispatcherByEventType['mousedown']; + if ($defined(eventDispatcher)) { + eventDispatcher.eventListener(event); + } + }); + + if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + result.setCursor('move'); + } else { + result.setCursor('default'); + } + } + + // Positionate node ... + this._offset = this.getOffset(); + var iconOffset = this.getIconOffset(); + result.setPosition(iconOffset + this._offset, this._offset / 2); + return result; + }, + + getIconOffset : function() { + var iconGroup = this.getIconGroup(); + var size = 0; + if ($defined(iconGroup)) { + size = iconGroup.getSize().width; + } + return size; + }, + + getOffset : function(value, updateModel) { + var offset = 18; + + if (mindplot.model.NodeModel.MAIN_TOPIC_TYPE == this.getType()) { + var parent = this.getModel().getParent(); + if (parent && mindplot.model.NodeModel.MAIN_TOPIC_TYPE == parent.getType()) { + offset = 6; + } + else { + offset = 8; + } + } + return offset; + }, + + setFontFamily : function(value, updateModel) { + var textShape = this.getTextShape(); + textShape.setFontFamily(value); + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setFontFamily(value); + } + /*var elem = this; + var executor = function(editor) + { + return function() + { + elem.updateNode(updateModel); + }; + }; + + setTimeout(executor(this), 0);*/ + core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); + }, + + setFontSize : function(value, updateModel) { + var textShape = this.getTextShape(); + textShape.setSize(value); + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setFontSize(value); + } + /*var elem = this; + var executor = function(editor) + { + return function() + { + elem.updateNode(updateModel); + }; + }; + + setTimeout(executor(this), 0);*/ + core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); + + }, + + setFontStyle : function(value, updateModel) { + var textShape = this.getTextShape(); + textShape.setStyle(value); + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setFontStyle(value); + } + /*var elem = this; + var executor = function(editor) + { + return function() + { + elem.updateNode(updateModel); + }; + }; + + setTimeout(executor(this), 0);*/ + core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); + }, + + setFontWeight : function(value, updateModel) { + var textShape = this.getTextShape(); + textShape.setWeight(value); + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setFontWeight(value); + } + }, + + getFontWeight : function() { + var model = this.getModel(); + var result = model.getFontWeight(); + if (!$defined(result)) { + var font = this._defaultFontStyle(); + result = font.weight; + } + return result; + }, + + getFontFamily : function() { + var model = this.getModel(); + var result = model.getFontFamily(); + if (!$defined(result)) { + var font = this._defaultFontStyle(); + result = font.font; + } + return result; + }, + + getFontColor : function() { + var model = this.getModel(); + var result = model.getFontColor(); + if (!$defined(result)) { + var font = this._defaultFontStyle(); + result = font.color; + } + return result; + }, + + getFontStyle : function() { + var model = this.getModel(); + var result = model.getFontStyle(); + if (!$defined(result)) { + var font = this._defaultFontStyle(); + result = font.style; + } + return result; + }, + + getFontSize : function() { + var model = this.getModel(); + var result = model.getFontSize(); + if (!$defined(result)) { + var font = this._defaultFontStyle(); + result = font.size; + } + return result; + }, + + setFontColor : function(value, updateModel) { + var textShape = this.getTextShape(); + textShape.setColor(value); + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setFontColor(value); + } + }, + + _setText : function(text, updateModel) { + var textShape = this.getTextShape(); + textShape.setText(text); + /*var elem = this; + var executor = function(editor) + { + return function() + { + elem.updateNode(updateModel); + }; + }; + + setTimeout(executor(this), 0);*/ + core.Executor.instance.delay(this.updateNode, 0, this, [updateModel]); + + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setText(text); + } + }, + + setText : function(text) { + this._setText(text, true); + }, + + getText : function() { + var model = this.getModel(); + var result = model.getText(); + if (!$defined(result)) { + result = this._defaultText(); + } + return result; + }, + + setBackgroundColor : function(color) { + this._setBackgroundColor(color, true); + }, + + _setBackgroundColor : function(color, updateModel) { + var innerShape = this.getInnerShape(); + innerShape.setFill(color); + + var connector = this.getShrinkConnector(); + connector.setFill(color); + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setBackgroundColor(color); + } + }, + + getBackgroundColor : function() { + var model = this.getModel(); + var result = model.getBackgroundColor(); + if (!$defined(result)) { + result = this._defaultBackgroundColor(); + } + return result; + }, + + setBorderColor : function(color) { + this._setBorderColor(color, true); + }, + + _setBorderColor : function(color, updateModel) { + var innerShape = this.getInnerShape(); + innerShape.setAttribute('strokeColor', color); + + var connector = this.getShrinkConnector(); + connector.setAttribute('strokeColor', color); + + + if ($defined(updateModel) && updateModel) { + var model = this.getModel(); + model.setBorderColor(color); + } + }, + + getBorderColor : function() { + var model = this.getModel(); + var result = model.getBorderColor(); + if (!$defined(result)) { + result = this._defaultBorderColor(); + } + return result; + }, + + _buildShape : function() { + var groupAttributes = {width: 100, height:100,coordSizeWidth:100,coordSizeHeight:100}; + var group = new web2d.Group(groupAttributes); + group._peer._native.virtualRef = this; + this._set2DElement(group); + + // Shape must be build based on the model width ... + var outerShape = this.getOuterShape(); + var innerShape = this.getInnerShape(); + var textShape = this.getTextShape(); + var shrinkConnector = this.getShrinkConnector(); + + // Update figure size ... + var model = this.getModel(); + var size = model.getSize(); + this._setSize(size); + + // Add to the group ... + group.appendChild(outerShape); + group.appendChild(innerShape); + group.appendChild(textShape); + + if (model.getLinks().length != 0 || model.getNotes().length != 0 || model.getIcons().length != 0) { + iconGroup = this.getOrBuildIconGroup(); + } + + if (this.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + shrinkConnector.addToWorkspace(group); + } + + // Register listeners ... + this._registerDefaultListenersToElement(group, this); +// this._registerDefaultListenersToElement(innerShape, this); +// this._registerDefaultListenersToElement(textShape, this); + + }, + + _registerDefaultListenersToElement : function(elem, topic) { + var mouseOver = function(event) { + if (topic.isMouseEventsEnabled()) { + topic.handleMouseOver(event); + } + }; + elem.addEventListener('mouseover', mouseOver); + + var outout = function(event) { + if (topic.isMouseEventsEnabled()) { + topic.handleMouseOut(event); + } + }; + elem.addEventListener('mouseout', outout); + + // Focus events ... + var mouseDown = function(event) { + topic.setOnFocus(true); + }; + elem.addEventListener('mousedown', mouseDown); + }, + + areChildrenShrinked : function() { + var model = this.getModel(); + return model.areChildrenShrinked(); + }, + + isCollapsed : function() { + var model = this.getModel(); + var result = false; + + var current = this.getParent(); + while (current && !result) { + result = current.areChildrenShrinked(); + current = current.getParent(); + } + return result; + }, + + setChildrenShrinked : function(value) { + // Update Model ... + var model = this.getModel(); + model.setChildrenShrinked(value); + + // Change render base on the state. + var shrinkConnector = this.getShrinkConnector(); + shrinkConnector.changeRender(value); + + // Hide children ... + core.Utils.setChildrenVisibilityAnimated(this, !value); + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeShrinkEvent, [this]); + }, + + getShrinkConnector : function() { + var result = this._connector; + if (this._connector == null) { + this._connector = new mindplot.ShirinkConnector(this); + this._connector.setVisibility(false); + result = this._connector; + + } + return result; + }, + + handleMouseOver : function(event) { + var outerShape = this.getOuterShape(); + outerShape.setOpacity(1); + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOverEvent, [this]); + }, + + handleMouseOut : function(event) { + var outerShape = this.getOuterShape(); + if (!this.isOnFocus()) { + outerShape.setOpacity(0); + } + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent, [this]); + }, + + /** + * Point: references the center of the rect shape.!!! + */ + setPosition : function(point) { + // Elements are positioned in the center. + // All topic element must be positioned based on the innerShape. + var size = this.getSize(); + + var cx = Math.round(point.x - (size.width / 2)); + var cy = Math.round(point.y - (size.height / 2)); + + // Update visual position. + this._elem2d.setPosition(cx, cy); + + // Update model's position ... + var model = this.getModel(); + model.setPosition(point.x, point.y); + + // Update connection lines ... + this._updateConnectionLines(); + + // Check object state. + this.invariant(); + }, + + getOutgoingLine : function() { + return this._outgoingLine; + }, + + getIncomingLines : function() { + var result = []; + var children = this._getChildren(); + for (var i = 0; i < children.length; i++) { + var node = children[i]; + var line = node.getOutgoingLine(); + if ($defined(line)) { + result.push(line); + } + } + return result; + }, + + getOutgoingConnectedTopic : function() { + var result = null; + var line = this.getOutgoingLine(); + if ($defined(line)) { + result = line.getTargetTopic(); + } + return result; + }, + + + _updateConnectionLines : function() { + // Update this to parent line ... + var outgoingLine = this.getOutgoingLine(); + if ($defined(outgoingLine)) { + outgoingLine.redraw(); + } + + // Update all the incoming lines ... + var incomingLines = this.getIncomingLines(); + for (var i = 0; i < incomingLines.length; i++) { + incomingLines[i].redraw(); + } + + // Update relationship lines + for (var j = 0; j < this._relationships.length; j++) { + this._relationships[j].redraw(); + } + }, + + setBranchVisibility : function(value) { + var current = this; + var parent = this; + while (parent != null && parent.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + current = parent; + parent = current.getParent(); + } + current.setVisibility(value); + }, + + + setVisibility : function(value) { + this._setTopicVisibility(value); + + // Hide all children... + this._setChildrenVisibility(value); + + this._setRelationshipLinesVisibility(value); + }, + + moveToBack : function() { +// this._helpers.forEach(function(helper, index){ +// helper.moveToBack(); +// }); + // Update relationship lines + for (var j = 0; j < this._relationships.length; j++) { + this._relationships[j].moveToBack(); + } + var connector = this.getShrinkConnector(); + if ($defined(connector)) { + connector.moveToBack(); + } + + this.get2DElement().moveToBack(); + + + }, + + moveToFront : function() { + + this.get2DElement().moveToFront(); + var connector = this.getShrinkConnector(); + if ($defined(connector)) { + connector.moveToFront(); + } + // Update relationship lines + for (var j = 0; j < this._relationships.length; j++) { + this._relationships[j].moveToFront(); + } + }, + + isVisible : function() { + var elem = this.get2DElement(); + return elem.isVisible(); + }, + + _setRelationshipLinesVisibility : function(value) { + //var relationships = designer.findRelationShipsByTopicId(this.getId()); + this._relationships.forEach(function(relationship, index) { + relationship.setVisibility(value); + }); + }, + + _setTopicVisibility : function(value) { + var elem = this.get2DElement(); + elem.setVisibility(value); + + if (this.getIncomingLines().length > 0) { + var connector = this.getShrinkConnector(); + connector.setVisibility(value); + } + + var textShape = this.getTextShape(); + textShape.setVisibility(value); + + }, + + setOpacity : function(opacity) { + var elem = this.get2DElement(); + elem.setOpacity(opacity); + + this.getShrinkConnector().setOpacity(opacity); + + var textShape = this.getTextShape(); + textShape.setOpacity(opacity); + }, + + _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); + } + + }, + + invariant : function() { + var line = this._outgoingLine; + var model = this.getModel(); + var isConnected = model.isConnected(); + + // Check consitency... + if ((isConnected && !line) || (!isConnected && line)) { + // $assert(false,'Illegal state exception.'); + } + }, + + /** + * type: + * onfocus + */ + 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); + }, + + 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); + }, + + + _setSize : function(size) { + $assert(size, "size can not be null"); + $assert($defined(size.width), "size seem not to be a valid element"); + + mindplot.NodeGraph.prototype.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); + }, + + 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]); + + } + }, + + _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { + $assert(false, "this method must be overided"); + }, + + disconnect : function(workspace) { + var outgoingLine = this.getOutgoingLine(); + if ($defined(outgoingLine)) { + $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); + } + + } + }, + + getOrder : function() { + var model = this.getModel(); + return model.getOrder(); + }, + + setOrder : function(value) { + var model = this.getModel(); + model.setOrder(value); + }, + + connectTo : function(targetTopic, workspace, isVisible) { + $assert(!this._outgoingLine, 'Could not connect an already connected node'); + $assert(targetTopic != this, 'Cilcular connection are not allowed'); + $assert(targetTopic, 'Parent Graph can not be null'); + $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 ($defined(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(); + }, + + _appendChild : function(child) { + var children = this._getChildren(); + children.push(child); + }, + + _removeChild : function(child) { + var children = this._getChildren(); + children.erase(child); + }, + + _getChildren : function() { + var result = this._children; + if (!$defined(result)) { + this._children = []; + result = this._children; + } + return result; + }, + + removeFromWorkspace : function(workspace) { + var elem2d = this.get2DElement(); + workspace.removeChild(elem2d); + var line = this.getOutgoingLine(); + if ($defined(line)) { + workspace.removeChild(line); + } + this._isInWorkspace = false; + }, + + addToWorkspace : function(workspace) { + var elem = this.get2DElement(); + workspace.appendChild(elem); + this._isInWorkspace = true; + }, + + isInWorkspace : function() { + return this._isInWorkspace; + }, + + createDragNode : function() { + var dragNode = mindplot.NodeGraph.prototype.createDragNode.call(this); + + // Is the node already connected ? + var targetTopic = this.getOutgoingConnectedTopic(); + if ($defined(targetTopic)) { + dragNode.connectTo(targetTopic); + } + return dragNode; + }, + + 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 + 2; + var pos = this._offset / 2 - 1; + if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_ELIPSE) { + var factor = 0.25; + height = (width * factor < height ? height : width * factor); + pos = (height - sizeHeight + 3) / 2; + } + + var newSize = {width:width,height:height}; + this.setSize(newSize, false, updatePosition); + + // Positionate node ... + textShape.setPosition(iconOffset + this._offset + 2, pos); + textShape.setTextSize(sizeWidth, sizeHeight); + var iconGroup = this.getIconGroup(); + if ($defined(iconGroup)) + iconGroup.updateIconGroupPosition(); + } + }, + + INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid'}, + + addHelper : function(helper) { + helper.addToGroup(this.get2DElement()); + this._helpers.push(helper); + } +}); + + +mindplot.Topic.CONNECTOR_WIDTH = 6; +mindplot.Topic.OUTER_SHAPE_ATTRIBUTES = {fillColor:'#dbe2e6',stroke:'1 solid #77555a',x:0,y:0}; + +/* + * 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.CentralTopic = new Class({ + + Extends:mindplot.Topic, + initialize: function(model) { + this.parent(model); + }, + + workoutIncomingConnectionPoint : function(sourcePosition) { + return this.getPosition(); + }, + + getTopicType : function() { + return mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE; + }, + + setCursor : function(type) { + type = (type == 'move') ? 'default' : type; + mindplot.Topic.prototype.setCursor.call(this, type); + }, + + isConnectedToCentralTopic : function() { + return false; + }, + + createChildModel : function(prepositionate) { + // Create a new node ... + var model = this.getModel(); + var mindmap = model.getMindmap(); + var childModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); + + if (prepositionate) { + if (!$defined(this.___siblingDirection)) { + this.___siblingDirection = 1; + } + + // Position following taking into account this internal flag ... + if (this.___siblingDirection == 1) { + + childModel.setPosition(150, 0); + } else { + childModel.setPosition(-150, 0); + } + this.___siblingDirection = -this.___siblingDirection; + } + // Create a new node ... + childModel.setOrder(0); + + return childModel; + }, + + _defaultShapeType : function() { + return mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT; + }, + + + updateTopicShape : function() { + + }, + + _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { + + // Center main topic ... + var zeroPoint = new core.Point(0, 0); + this.setPosition(zeroPoint); + }, + + _defaultText : function() { + return "Central Topic"; + }, + + _defaultBackgroundColor : function() { + return "#f7f7f7"; + }, + + _defaultBorderColor : function() { + return "#023BB9"; + }, + + _defaultFontStyle : function() { + return { + font:"Verdana", + size: 10, + style:"normal", + weight:"bold", + color:"#023BB9" + }; + } +});/* + * 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.MainTopic = new Class({ + Extends: mindplot.Topic, + initialize : function(model) { + this.parent(model); + }, + + INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid #009900'}, + + createSiblingModel : function(positionate) { + var siblingModel = null; + var parentTopic = this.getOutgoingConnectedTopic(); + if (parentTopic != null) { + // Create a new node ... + var model = this.getModel(); + var mindmap = model.getMindmap(); + siblingModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); + + // Positionate following taking into account the sibling positon. + if (positionate && parentTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + var pos = this.getPosition(); + siblingModel.setPosition(pos.x, pos.y); + } + + // Create a new node ... + var order = this.getOrder() + 1; + siblingModel.setOrder(order); + } + return siblingModel; + }, + + createChildModel : function(prepositionate) { + // Create a new node ... + var model = this.getModel(); + var mindmap = model.getMindmap(); + var childModel = mindmap.createNode(mindplot.model.NodeModel.MAIN_TOPIC_TYPE); + + // Get the hights model order position ... + var children = this._getChildren(); + var order = -1; + for (var i = 0; i < children.length; i++) { + var child = children[i]; + if (child.getOrder() > order) { + order = child.getOrder(); + } + } + // Create a new node ... + childModel.setOrder(order + 1); + return childModel; + }, + + + _buildDragShape : function() { + var innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES); + var size = this.getSize(); + innerShape.setSize(size.width, size.height); + innerShape.setPosition(0, 0); + innerShape.setOpacity(0.5); + innerShape.setCursor('default'); + innerShape.setVisibility(true); + + var brColor = this.getBorderColor(); + innerShape.setAttribute("strokeColor", brColor); + + var bgColor = this.getBackgroundColor(); + innerShape.setAttribute("fillColor", bgColor); + + // Create group ... + var groupAttributes = {width: 100, height:100,coordSizeWidth:100,coordSizeHeight:100}; + var group = new web2d.Group(groupAttributes); + group.appendChild(innerShape); + + // Add Text ... + var textShape = this._buildTextShape(true); + var text = this.getText(); + textShape.setText(text); + textShape.setOpacity(0.5); + group.appendChild(textShape); + + return group; + }, + + + _defaultShapeType : function() { + return mindplot.model.NodeModel.SHAPE_TYPE_LINE; + }, + + updateTopicShape : function(targetTopic, workspace) { + // Change figure based on the connected topic ... + var model = this.getModel(); + var shapeType = model.getShapeType(); + if (targetTopic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + if (!$defined(shapeType)) { + // Get the real shape type ... + shapeType = this.getShapeType(); + this._setShapeType(shapeType, false); + } + } + this._helpers.forEach(function(helper) { + helper.moveToFront(); + }); + }, + + disconnect : function(workspace) { + mindplot.Topic.prototype.disconnect.call(this, workspace); + var size = this.getSize(); + + var model = this.getModel(); + var shapeType = model.getShapeType(); + if (!$defined(shapeType)) { + // Change figure ... + shapeType = this.getShapeType(); + this._setShapeType(mindplot.model.NodeModel.SHAPE_TYPE_ROUNDED_RECT, false); + } + var innerShape = this.getInnerShape(); + innerShape.setVisibility(true); + }, + + getTopicType : function() { + return "MainTopic"; + }, + + _updatePositionOnChangeSize : function(oldSize, newSize, updatePosition) { + + if (updatePosition == false && this.getModel().getFinalPosition()) { + this.setPosition(this.getModel().getFinalPosition(), false); + } + else { + var xOffset = Math.round((newSize.width - oldSize.width) / 2); + var pos = this.getPosition(); + if ($defined(pos)) { + if (pos.x > 0) { + pos.x = pos.x + xOffset; + } else { + pos.x = pos.x - xOffset; + } + this.setPosition(pos); + } + } + }, + + setPosition : function(point, fireEvent) { + mindplot.Topic.prototype.setPosition.call(this, point); + + // Update board zero entry position... + if (fireEvent != false) + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMoveEvent, [this]); + }, + + workoutIncomingConnectionPoint : function(sourcePosition) { + $assert(sourcePosition, 'sourcePoint can not be null'); + var pos = this.getPosition(); + var size = this.getSize(); + + var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos); + var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight); + if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { + result.y = result.y + (this.getSize().height / 2); + } + + // Move a little the position... + var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; + if (this.getPosition().x > 0) { + result.x = result.x + offset; + } else { + result.x = result.x - offset; + } + + 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 size = this.getSize(); + + var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, pos); + var result; + if (this.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { +// if (!this.isConnectedToCentralTopic()) +// { + result = new core.Point(); + if (!isAtRight) { + result.x = pos.x + (size.width / 2); + } else { + result.x = pos.x - (size.width / 2); + } + result.y = pos.y + (size.height / 2); + /*} else + { + // In this case, connetion line is not used as shape figure. + result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); + result.y = pos.y + (size.height / 2); + */ + /*if(result.y>0){ + result.y+=1; + }*/ + /* + + // Correction factor ... + if (!isAtRight) + { + result.x = result.x + 2; + } else + { + result.x = result.x - 2; + } + + }*/ + } else { + result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); + } + result.x = Math.ceil(result.x); + result.y = Math.ceil(result.y); + return result; + }, + + + isConnectedToCentralTopic : function() { + var model = this.getModel(); + var parent = model.getParent(); + + return parent && parent.getType() === mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE; + }, + + _defaultText : function() { + var targetTopic = this.getOutgoingConnectedTopic(); + var result = ""; + if ($defined(targetTopic)) { + if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + result = "Main Topic"; + } else { + result = "Sub Topic"; + } + } else { + result = "Isolated Topic"; + } + return result; + }, + + _defaultFontStyle : function() { + var targetTopic = this.getOutgoingConnectedTopic(); + var result; + if ($defined(targetTopic)) { + if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + result = { + font:"Arial", + size: 8, + style:"normal", + weight:"normal", + color:"#525c61" + }; + } else { + result = { + font:"Arial", + size: 6, + style:"normal", + weight:"normal", + color:"#525c61" + }; + } + } else { + result = { + font:"Verdana", + size: 8, + style:"normal", + weight:"normal", + color:"#525c61" + }; + } + return result; + }, + + _defaultBackgroundColor : function() { + return "#E0E5EF"; + }, + + _defaultBorderColor : function() { + return '#023BB9'; + }, + addSibling : function() { + var order = this.getOrder(); + } +}); +/* +* 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.DragTopic = function(dragShape, draggedNode) +{ + $assert(dragShape, 'Rect can not be null.'); + $assert(draggedNode, 'draggedNode can not be null.'); + + this._elem2d = dragShape; + this._order = null; + this._draggedNode = draggedNode; + this._position = new core.Point(); +}; + +mindplot.DragTopic.initialize = function(workspace) +{ + var pivot = mindplot.DragTopic.__getDragPivot(); + workspace.appendChild(pivot); +}; + +mindplot.DragTopic.prototype.setOrder = function(order) +{ + this._order = order; +}; + +mindplot.DragTopic.prototype.setPosition = function(x, y) +{ + this._position.setValue(x, y); + + // Elements are positioned in the center. + // All topic element must be positioned based on the innerShape. + var draggedNode = this._draggedNode; + var size = draggedNode.getSize(); + + var cx = Math.ceil(x - (size.width / 2)); + var cy = Math.ceil(y - (size.height / 2)); + + // Update visual position. + this._elem2d.setPosition(cx, cy); +}; + +mindplot.DragTopic.prototype.getInnerShape = function() +{ + return this._elem2d; +}; + +mindplot.DragTopic.prototype.disconnect = function(workspace) +{ + // Clear connection line ... + var dragPivot = this._getDragPivot(); + dragPivot.disconnect(workspace); +}; + +mindplot.DragTopic.prototype.canBeConnectedTo = function(targetTopic) +{ + $assert(targetTopic, 'parent can not be null'); + + var result = true; + if (!targetTopic.areChildrenShrinked() && !targetTopic.isCollapsed()) + { + // Dragged node can not be connected to himself. + if (targetTopic == this._draggedNode) + { + result = false; + } else + { + var draggedNode = this.getDraggedTopic(); + var topicPosition = this.getPosition(); + + var targetTopicModel = targetTopic.getModel(); + var childTopicModel = draggedNode.getModel(); + + result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18); + } + } else + { + result = false; + } + return result; +}; + +mindplot.DragTopic.prototype.connectTo = function(parent) +{ + $assert(parent, 'Parent connection node can not be null.'); + + var dragPivot = this._getDragPivot(); + dragPivot.connectTo(parent); +}; + +mindplot.DragTopic.prototype.getDraggedTopic = function() +{ + return this._draggedNode; +}; + + +mindplot.DragTopic.prototype.removeFromWorkspace = function(workspace) +{ + // Remove drag shadow. + workspace.removeChild(this._elem2d); + + // Remove pivot shape. To improve performace it will not be removed. Only the visilility will be changed. + var dragPivot = this._getDragPivot(); + dragPivot.setVisibility(false); +}; + +mindplot.DragTopic.prototype.addToWorkspace = function(workspace) +{ + workspace.appendChild(this._elem2d); + var dragPivot = this._getDragPivot(); + + dragPivot.addToWorkspace(workspace); + dragPivot.setVisibility(true); +}; + +mindplot.DragTopic.prototype._getDragPivot = function() +{ + return mindplot.DragTopic.__getDragPivot(); +}; + +mindplot.DragTopic.__getDragPivot = function() +{ + var result = mindplot.DragTopic._dragPivot; + if (!$defined(result)) + { + result = new mindplot.DragPivot(); + mindplot.DragTopic._dragPivot = result; + } + return result; +}; + + +mindplot.DragTopic.prototype.getPosition = function() +{ + return this._position; +}; + +mindplot.DragTopic.prototype.isDragTopic = function() +{ + return true; +}; + +mindplot.DragTopic.prototype.updateDraggedTopic = function(workspace) +{ + $assert(workspace, 'workspace can not be null'); + + var dragPivot = this._getDragPivot(); + var draggedTopic = this.getDraggedTopic(); + + var isDragConnected = this.isConnected(); + var actionRunner = mindplot.DesignerActionRunner.getInstance(); + var topicId = draggedTopic.getId(); + var command = new mindplot.commands.DragTopicCommand(topicId); + + if (isDragConnected) + { + + var targetTopic = this.getConnectedToTopic(); + if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) + { + // Update topic position ... + var dragPivotPosition = dragPivot.getPosition(); + + // Must position the dragged topic taking into account the current node size. + var pivotSize = dragPivot.getSize(); + var draggedTopicSize = draggedTopic.getSize(); + var xOffset = draggedTopicSize.width - pivotSize.width; + xOffset = Math.round(xOffset / 2); + + if (dragPivotPosition.x > 0) + { + dragPivotPosition.x = parseInt(dragPivotPosition.x) + xOffset; + } + else + { + dragPivotPosition.x = parseInt(dragPivotPosition.x) - xOffset; + } + // Set new position ... + command.setPosition(dragPivotPosition); + + } else + { + // Main topic connections can be positioned only with the order ... + command.setOrder(this._order); + } + + // Set new parent topic .. + command.setParetTopic(targetTopic); + } else { + + // If the node is not connected, positionate based on the original drag topic position. + var dragPosition = this.getPosition(); + command = new mindplot.commands.DragTopicCommand(topicId, dragPosition); + command.setPosition(dragPosition); + } + actionRunner.execute(command); +}; + +mindplot.DragTopic.prototype.setBoardPosition = function(point) +{ + $assert(point, 'point can not be null'); + var dragPivot = this._getDragPivot(); + dragPivot.setPosition(point); +}; + + +mindplot.DragTopic.prototype.getBoardPosition = function(point) +{ + $assert(point, 'point can not be null'); + var dragPivot = this._getDragPivot(); + return dragPivot.getPosition(); +}; + +mindplot.DragTopic.prototype.getConnectedToTopic = function() +{ + var dragPivot = this._getDragPivot(); + return dragPivot.getTargetTopic(); +}; + +mindplot.DragTopic.prototype.isConnected = function() +{ + return this.getConnectedToTopic() != null; +}; + +mindplot.DragTopic.PIVOT_SIZE = {width:50,height:10}; +/* +* 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.DragManager = function(workspace) +{ + this._workspace = workspace; + this._listeners = {}; +}; + +mindplot.DragManager.prototype.add = function(node) +{ + // Add behaviour ... + var workspace = this._workspace; + var screen = workspace.getScreenManager(); + var dragManager = this; + + var mouseDownListener = function(event) + { + if (workspace.isWorkspaceEventsEnabled()) + { + // Disable double drag... + workspace.enableWorkspaceEvents(false); + + // Set initial position. + var dragNode = node.createDragNode(); + var mousePos = screen.getWorkspaceMousePosition(event); + dragNode.setPosition(mousePos.x, mousePos.y); + + // Register mouse move listener ... + var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager); + screen.addEventListener('mousemove', mouseMoveListener); + + // Register mouse up listeners ... + var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager); + screen.addEventListener('mouseup', mouseUpListener); + + // Execute Listeners .. + var startDragListener = dragManager._listeners['startdragging']; + startDragListener(event, node); + + // Change cursor. + window.document.body.style.cursor = 'move'; + } + }; + dragManager._mouseDownListener = mouseDownListener; + + node.addEventListener('mousedown', mouseDownListener); +}; + +mindplot.DragManager.prototype.remove = function(node) +{ + var nodes = this._topics; + var contained = false; + var index = -1; + for (var i = 0; i < nodes.length; i++) { + if (nodes[i] == node) { + contained = true; + index = i; + } + } + if (contained) + { + elem = new Array(); + } +}; + +mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dragNode, dragManager) +{ + var screen = workspace.getScreenManager(); + var result = function(event) { + + if (!dragNode._isInTheWorkspace) + { + // Add shadow node to the workspace. + workspace.appendChild(dragNode); + dragNode._isInTheWorkspace = true; + } + + var pos = screen.getWorkspaceMousePosition(event); + dragNode.setPosition(pos.x, pos.y); + + // Call mouse move listeners ... + var dragListener = dragManager._listeners['dragging']; + if ($defined(dragListener)) + { + dragListener(event, dragNode); + } + + event.preventDefault(); + }.bindWithEvent(this); + dragManager._mouseMoveListener = result; + return result; +}; + +mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, dragNode, dragManager) +{ + var screen = workspace.getScreenManager(); + var result = function(event) { + + $assert(dragNode.isDragTopic, 'dragNode must be an DragTopic'); + + // Remove drag node from the workspace. + var hasBeenDragged = dragNode._isInTheWorkspace; + if (dragNode._isInTheWorkspace) + { + dragNode.removeFromWorkspace(workspace); + } + + // Remove all the events. + screen.removeEventListener('mousemove', dragManager._mouseMoveListener); + screen.removeEventListener('mouseup', dragManager._mouseUpListener); + + // Help GC + dragManager._mouseMoveListener = null; + dragManager._mouseUpListener = null; + + // Execute Listeners only if the node has been moved. + var endDragListener = dragManager._listeners['enddragging']; + endDragListener(event, dragNode); + + if (hasBeenDragged) + { + dragNode._isInTheWorkspace = false; + } + + // Change the cursor to the default. + window.document.body.style.cursor = 'default'; + + workspace.enableWorkspaceEvents(true); + + }; + dragManager._mouseUpListener = result; + return result; +}; + +/** + * type: + * - startdragging. + * - dragging + * - enddragging + */ +mindplot.DragManager.prototype. addEventListener = function(type, listener) +{ + this._listeners[type] = listener; +}; + +mindplot.DragManager.DRAG_PRECISION_IN_SEG = 100; +/* + * 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.DragPivot = new Class({ + initialize:function() { + this._position = new core.Point(); + this._size = mindplot.DragTopic.PIVOT_SIZE; + this._line = null; + + this._straightLine = this._buildStraightLine(); + this._curvedLine = this._buildCurvedLine(); + this._dragPivot = this._buildRect(); + this._connectRect = this._buildRect(); + this._targetTopic = null; + }, + + getTargetTopic : function() { + return this._targetTopic; + }, + + _buildStraightLine : function() { + var line = new web2d.CurvedLine(); + line.setStyle(web2d.CurvedLine.SIMPLE_LINE); + line.setStroke(1, 'solid', '#CC0033'); + line.setOpacity(0.4); + line.setVisibility(false); + return line; + }, + + _buildCurvedLine : function() { + var line = new web2d.CurvedLine(); + line.setStyle(web2d.CurvedLine.SIMPLE_LINE); + line.setStroke(1, 'solid', '#CC0033'); + line.setOpacity(0.4); + line.setVisibility(false); + return line; + }, + + _redraw : function(pivotPosition) { + // Update line position. + $assert(this.getTargetTopic(), 'Illegal invocation. Target node can not be null'); + + var pivotRect = this._getPivotRect(); + var currentPivotPosition = pivotRect.getPosition(); + + // Pivot position has not changed. In this case, position change is not required. + var targetTopic = this.getTargetTopic(); + if (currentPivotPosition.x != pivotPosition.x || currentPivotPosition.y != pivotPosition.y) { + var position = this._position; + var fromPoint = targetTopic.workoutIncomingConnectionPoint(position); + + // Calculate pivot connection point ... + var size = this._size; + var targetPosition = targetTopic.getPosition(); + var line = this._line; + + // Update Line position. + var isAtRight = mindplot.util.Shape.isAtRight(targetPosition, position); + var pivotPoint = mindplot.util.Shape.calculateRectConnectionPoint(position, size, isAtRight); + line.setFrom(pivotPoint.x, pivotPoint.y); + + // Update rect position + pivotRect.setPosition(pivotPosition.x, pivotPosition.y); + + // Display elements if it's required... + if (!pivotRect.isVisible()) { + // Make line visible only when the position has been already changed. + // This solve several strange effects ;) + var targetPoint = targetTopic.workoutIncomingConnectionPoint(pivotPoint); + line.setTo(targetPoint.x, targetPoint.y); + + this.setVisibility(true); + } + } + }, + + setPosition : function(point) { + this._position = point; + + // Update visual position. + var size = this.getSize(); + + var cx = point.x - (parseInt(size.width) / 2); + var cy = point.y - (parseInt(size.height) / 2); + + // Update line ... + if (this.getTargetTopic()) { + var pivotPosition = {x:cx,y:cy}; + this._redraw(pivotPosition); + } + }, + + getPosition : function() { + return this._position; + }, + + _buildRect : function() { + var size = this._size; + var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'}; + var rect = new web2d.Rect(0, rectAttributes); + rect.setVisibility(false); + return rect; + }, + + _buildConnectRect : function() { + var size = this._size; + var rectAttributes = {fillColor:'#CC0033',opacity:0.4,width:size.width,height:size.height,strokeColor:'#FF9933'}; + var result = new web2d.Rect(0, rectAttributes); + return result; + }, + + _getPivotRect : function() { + return this._dragPivot; + }, + + getSize : function() { + var elem2d = this._getPivotRect(); + return elem2d.getSize(); + }, + + setVisibility : function(value) { + var pivotRect = this._getPivotRect(); + pivotRect.setVisibility(value); + + var connectRect = this._connectRect; + connectRect.setVisibility(value); + if ($defined(this._line)) { + this._line.setVisibility(value); + } + }, + + addToWorkspace : function(workspace) { + var pivotRect = this._getPivotRect(); + workspace.appendChild(pivotRect); + + var connectToRect = this._connectRect; + workspace.appendChild(connectToRect); + + // Add a hidden straight line ... + var straighLine = this._straightLine; + straighLine.setVisibility(false); + workspace.appendChild(straighLine); + straighLine.moveToBack(); + + // Add a hidden curved line ... + var curvedLine = this._curvedLine; + curvedLine.setVisibility(false); + workspace.appendChild(curvedLine); + curvedLine.moveToBack(); + + // Add a connect rect ... + var connectRect = this._connectRect; + connectRect.setVisibility(false); + workspace.appendChild(connectRect); + connectRect.moveToBack(); + }, + + removeFromWorkspace : function(workspace) { + var shape = this._getPivotRect(); + workspace.removeChild(shape); + + var connectToRect = this._connectRect; + workspace.removeChild(connectToRect); + + if ($defined(this._straightLine)) { + workspace.removeChild(this._straightLine); + } + + if ($defined(this._curvedLine)) { + workspace.removeChild(this._curvedLine); + } + }, + + connectTo : function(targetTopic) { + $assert(!this._outgoingLine, 'Could not connect an already connected node'); + $assert(targetTopic != this, 'Cilcular connection are not allowed'); + $assert(targetTopic, 'parent can not be null'); + + this._targetTopic = targetTopic; + if (targetTopic.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + this._line = this._straightLine; + } else { + this._line = this._curvedLine; + } + + // Connected to Rect ... + var connectRect = this._connectRect; + var targetSize = targetTopic.getSize(); + var width = targetSize.width; + var height = targetSize.height; + connectRect.setSize(width, height); + + var targetPosition = targetTopic.getPosition(); + var cx = Math.ceil(targetPosition.x - (width / 2)); + var cy = Math.ceil(targetPosition.y - (height / 2)); + connectRect.setPosition(cx, cy); + + // Change elements position ... + var pivotRect = this._getPivotRect(); + pivotRect.moveToFront(); + + }, + + disconnect : function(workspace) { + $assert(workspace, 'workspace can not be null.'); + $assert(this._targetTopic, 'There are not connected topic.'); + + this.setVisibility(false); + this._targetTopic = null; + this._line = null; + } +}); +/* + * 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.Board = new Class({ + initialize : function(defaultHeight, referencePoint) { + $assert(referencePoint, "referencePoint can not be null"); + this._defaultWidth = defaultHeight; + this._entries = new mindplot.BidirectionalArray(); + this._referencePoint = referencePoint; + }, + + getReferencePoint : function() { + return this._referencePoint; + }, + + _removeEntryByOrder : function(order, position) { + var board = this._getBoard(position); + var entry = board.lookupEntryByOrder(order); + + $assert(!entry.isAvailable(), 'Entry must not be available in order to be removed.Entry Order:' + order); + entry.removeTopic(); + board.update(entry); + }, + + removeTopicFromBoard : function(topic) { + var position = topic.getPosition(); + var order = topic.getOrder(); + + this._removeEntryByOrder(order, position); + topic.setOrder(null); + }, + + positionateDragTopic :function(dragTopic) { + throw "this method must be overrided"; + }, + + getHeight: function() { + var board = this._getBoard(); + return board.getHeight(); + } +}); + +/** + * --------------------------------------- + */ +mindplot.BidirectionalArray = new Class({ + + initialize: function() { + this._leftElem = []; + this._rightElem = []; + }, + + get :function(index, sign) { + $assert(index, 'Illegal argument, index must be passed.'); + if ($defined(sign)) { + $assert(index >= 0, 'Illegal absIndex value'); + index = index * sign; + } + + var result = null; + if (index >= 0 && index < this._rightElem.length) { + result = this._rightElem[index]; + } else if (index < 0 && Math.abs(index) < this._leftElem.length) { + result = this._leftElem[Math.abs(index)]; + } + return result; + }, + + set : function(index, elem) { + $assert(index, 'Illegal index value'); + + var array = (index >= 0) ? this._rightElem : this._leftElem; + array[Math.abs(index)] = elem; + }, + + length : function(index) { + $assert(index, 'Illegal index value'); + return (index >= 0) ? this._rightElem.length : this._leftElem.length; + }, + + upperLength : function() { + return this.length(1); + }, + + lowerLength : function() { + return this.length(-1); + }, + + inspect : function() { + var result = '{'; + var lenght = this._leftElem.length; + for (var i = 0; i < lenght; i++) { + var entry = this._leftElem[lenght - i - 1]; + if (entry != null) { + if (i != 0) { + result += ', '; + } + result += entry.inspect(); + } + } + + lenght = this._rightElem.length; + for (var i = 0; i < lenght; i++) { + var entry = this._rightElem[i]; + if (entry != null) { + if (i != 0) { + result += ', '; + } + result += entry.inspect(); + } + } + result += '}'; + + return result; + + } +});/* + * 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.CentralTopicBoard = new Class({ + Extends: mindplot.Board, + initialize:function(centralTopic, layoutManager) { + var point = new core.Point(0, 0); + this._layoutManager = layoutManager; + this._rightBoard = new mindplot.VariableDistanceBoard(50, point); + this._leftBoard = new mindplot.VariableDistanceBoard(50, point); + this._centralTopic = centralTopic; + }, + + _getBoard : function(position) { + return (position.x >= 0) ? this._rightBoard : this._leftBoard; + }, + + positionateDragTopic : function(dragTopic) { + $assert(dragTopic != null, 'dragTopic can not be null'); + $assert(dragTopic.isDragTopic, 'dragTopic must be DragTopic instance'); + + // This node is a main topic node. Position + var dragPos = dragTopic.getPosition(); + var board = this._getBoard(dragPos); + + // 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(); + } + + + // MainTopic can not be positioned over the drag topic ... + var centralTopic = this._centralTopic; + var centralTopicSize = centralTopic.getSize(); + var halfWidth = (centralTopicSize.width / 2); + if (Math.abs(dragPos.x) < halfWidth + 60) { + var distance = halfWidth + 60; + dragPos.x = (dragPos.x > 0) ? distance : -distance; + } + + // Update board position. + var pivotPos = new core.Point(dragPos.x, yCoord); + dragTopic.setBoardPosition(pivotPos); + }, + + + addBranch : function(topic) { + // Update topic position ... + var position = topic.getPosition(); + + var order = topic.getOrder(); + var board = this._getBoard(position); + var entry = null; + if (order != null) { + entry = board.lookupEntryByOrder(order); + } else { + entry = board.lookupEntryByPosition(position); + } + + // If the entry is not available, I must swap the the entries... + if (!entry.isAvailable()) { + board.freeEntry(entry); + } + + // Add it to the board ... + entry.setTopic(topic); + board.update(entry); + }, + + updateChildrenPosition : function(topic, xOffset, modifiedTopics) { + var board = this._rightBoard; + var oldReferencePosition = board.getReferencePoint(); + var newReferencePosition = new core.Point(oldReferencePosition.x + xOffset, oldReferencePosition.y); + board.updateReferencePoint(newReferencePosition); + + board = this._leftBoard; + oldReferencePosition = board.getReferencePoint(); + newReferencePosition = new core.Point(oldReferencePosition.x - xOffset, oldReferencePosition.y); + board.updateReferencePoint(newReferencePosition); + }, + + repositionate : function() { + //@todo: implement .. + } +});/* + * 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.MainTopicBoard = new Class({ + Extends:mindplot.Board, + initialize:function(topic, layoutManager) { + this._layoutManager = layoutManager; + this._topic = topic; + this._board = null; + this._height = 0; + }, + + + _getBoard: function() { + if (!$defined(this._board)) { + var topic = this._topic; + this._board = new mindplot.FixedDistanceBoard(mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT, topic, this._layoutManager); + } + return this._board; + }, + + updateReferencePoint : function(position) { + this._board.updateReferencePoint(position); + }, + + updateChildrenPosition : function(topic) { + var board = this._getBoard(); + board.updateReferencePoint(); + }, + + positionateDragTopic : function(dragTopic) { + $assert(dragTopic != null, 'dragTopic can not be null'); + $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 doesn't take into account the size of the shape. + */ + _workoutXBorderDistance : function(topic) { + $assert(topic, 'topic can not be null'); + var board = this._getBoard(); + return board.workoutXBorderDistance(topic); + }, + + addBranch : function(topic) { + var order = topic.getOrder(); + $assert(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(); + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent, [parentTopic]); + } + }, + + repositionate : function() { + var board = this._getBoard(); + board.repositionate(); + }, + + 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(); + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeRepositionateEvent, [connectedTopic]); + } + } +}); + +mindplot.MainTopicBoard.DEFAULT_MAIN_TOPIC_HEIGHT = 18; +/* + * 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.ConnectionLine = new Class({ + initialize:function(sourceNode, targetNode, lineType) { + $assert(targetNode, 'parentNode node can not be null'); + $assert(sourceNode, 'childNode node can not be null'); + $assert(sourceNode != targetNode, 'Cilcular connection'); + + this._targetTopic = targetNode; + this._sourceTopic = sourceNode; + + var strokeColor = mindplot.ConnectionLine.getStrokeColor(); + var line; + if (targetNode.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + line = this._createLine(lineType, mindplot.ConnectionLine.CURVED); + // line = new web2d.Line(); + if (line.getType() == "CurvedLine") { + var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); + line.setSrcControlPoint(ctrlPoints[0]); + line.setDestControlPoint(ctrlPoints[1]); + } + line.setStroke(1, 'solid', strokeColor); + } else { + line = this._createLine(lineType, mindplot.ConnectionLine.SIMPLE_CURVED); + if (line.getType() == "CurvedLine") { + var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); + line.setSrcControlPoint(ctrlPoints[0]); + line.setDestControlPoint(ctrlPoints[1]); + } + // line = new web2d.PolyLine(); + line.setStroke(1, 'solid', strokeColor); + } + + this._line2d = line; + }, + + _getCtrlPoints : function(sourceNode, targetNode) { + var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition()); + var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition()); + var deltaX = (srcPos.x - destPos.x) / 3; + return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)]; + }, + + _createLine : function(lineType, defaultStyle) { + if (!$defined(lineType)) { + lineType = defaultStyle; + } + lineType = parseInt(lineType); + this._lineType = lineType; + var line = null; + switch (lineType) { + case mindplot.ConnectionLine.POLYLINE: + line = new web2d.PolyLine(); + break; + case mindplot.ConnectionLine.CURVED: + line = new web2d.CurvedLine(); + break; + case mindplot.ConnectionLine.SIMPLE_CURVED: + line = new web2d.CurvedLine(); + line.setStyle(web2d.CurvedLine.SIMPLE_LINE); + break; + default: + line = new web2d.Line(); + break; + } + return line; + }, + + setVisibility : function(value) { + this._line2d.setVisibility(value); + }, + + isVisible : function() { + return this._line2d.isVisible(); + }, + + setOpacity : function(opacity) { + this._line2d.setOpacity(opacity); + }, + + redraw : function() { + var line2d = this._line2d; + var sourceTopic = this._sourceTopic; + var sourcePosition = sourceTopic.getPosition(); + + var targetTopic = this._targetTopic; + var targetPosition = targetTopic.getPosition(); + + var sPos,tPos; + sPos = sourceTopic.workoutOutgoingConnectionPoint(targetPosition, false); + tPos = targetTopic.workoutIncomingConnectionPoint(sourcePosition, false); + + line2d.setFrom(tPos.x, tPos.y); + line2d.setTo(sPos.x, sPos.y); + + if (line2d.getType() == "CurvedLine") { + var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic); + line2d.setSrcControlPoint(ctrlPoints[0]); + line2d.setDestControlPoint(ctrlPoints[1]); + } +// line2d.moveToBack(); + + // Add connector ... + this._positionateConnector(targetTopic); + + }, + + _positionateConnector : function(targetTopic) { + var targetPosition = targetTopic.getPosition(); + var offset = mindplot.Topic.CONNECTOR_WIDTH / 2; + var targetTopicSize = targetTopic.getSize(); + var y; + if (targetTopic.getShapeType() == mindplot.model.NodeModel.SHAPE_TYPE_LINE) { + y = targetTopicSize.height; + } else { + y = targetTopicSize.height / 2; + } + y = y - offset; + + var connector = targetTopic.getShrinkConnector(); + if (Math.sign(targetPosition.x) > 0) { + var x = targetTopicSize.width; + connector.setPosition(x, y); + } + else { + var x = -mindplot.Topic.CONNECTOR_WIDTH; + connector.setPosition(x, y); + } + }, + + setStroke : function(color, style, opacity) { + var line2d = this._line2d; + this._line2d.setStroke(null, null, color, opacity); + }, + + addToWorkspace : function(workspace) { + workspace.appendChild(this._line2d); + this._line2d.moveToBack(); + }, + + removeFromWorkspace : function(workspace) { + workspace.removeChild(this._line2d); + }, + + getTargetTopic : function() { + return this._targetTopic; + }, + + getSourceTopic : function() { + return this._sourceTopic; + }, + + getLineType : function() { + return this._lineType; + }, + + getLine : function() { + return this._line2d; + }, + + getModel : function() { + return this._model; + }, + + setModel : function(model) { + this._model = model; + }, + + getType : function() { + return "ConnectionLine"; + }, + + getId : function() { + return this._model.getId(); + }, + + moveToBack : function() { + this._line2d.moveToBack(); + }, + + moveToFront : function() { + this._line2d.moveToFront(); + } +}); + +mindplot.ConnectionLine.getStrokeColor = function() { + return '#495879'; +}; + +mindplot.ConnectionLine.SIMPLE = 0; +mindplot.ConnectionLine.POLYLINE = 1; +mindplot.ConnectionLine.CURVED = 2; mindplot.ConnectionLine.SIMPLE_CURVED = 3;/* * Copyright [2011] [wisemapping] * @@ -6750,483 +6749,483 @@ mindplot.RelationshipLine.type = "RelationshipLine"; mindplot.RelationshipLine.getStrokeColor = function() { return '#9b74e6'; } -/* - * 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.DragTopicPositioner = new Class({ - initialize:function(layoutManager) { - $assert(layoutManager, 'layoutManager can not be null'); - this._layoutManager = layoutManager; - this._topics = layoutManager.getDesigner()._getTopics(); - this._workspace = layoutManager.getDesigner().getWorkSpace(); - }, - - positionateDragTopic : function(dragTopic) { - // Workout the real position of the element on the board. - var dragTopicPosition = dragTopic.getPosition(); - var draggedTopic = dragTopic.getDraggedTopic(); - - // Topic can be connected ? - this._checkDragTopicConnection(dragTopic); - - // Position topic in the board - if (dragTopic.isConnected()) { - var targetTopic = dragTopic.getConnectedToTopic(); - var topicBoard = this._layoutManager.getTopicBoardForTopic(targetTopic); - topicBoard.positionateDragTopic(dragTopic); - } - }, - - _checkDragTopicConnection : function(dragTopic) { - var topics = this._topics; - - // Must be disconnected from their current connection ?. - var mainTopicToMainTopicConnection = this._lookUpForMainTopicToMainTopicConnection(dragTopic); - var currentConnection = dragTopic.getConnectedToTopic(); - if ($defined(currentConnection)) { - // MainTopic->MainTopicConnection. - if (currentConnection.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { - if (mainTopicToMainTopicConnection != currentConnection) { - dragTopic.disconnect(this._workspace); - } - } - else if (currentConnection.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { - // Distance if greater that the allowed. - var dragXPosition = dragTopic.getPosition().x; - var currentXPosition = currentConnection.getPosition().x; - - if ($defined(mainTopicToMainTopicConnection)) { - // I have to change the current connection to a main topic. - dragTopic.disconnect(this._workspace); - } else - if (Math.abs(dragXPosition - currentXPosition) > mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) { - dragTopic.disconnect(this._workspace); - } - } - } - - // Finally, connect nodes ... - if (!dragTopic.isConnected()) { - var centalTopic = topics[0]; - if ($defined(mainTopicToMainTopicConnection)) { - dragTopic.connectTo(mainTopicToMainTopicConnection); - } else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) { - dragTopic.connectTo(centalTopic); - } - } - }, - - _lookUpForMainTopicToMainTopicConnection : function(dragTopic) { - var topics = this._topics; - var result = null; - var clouserDistance = -1; - var draggedNode = dragTopic.getDraggedTopic(); - var distance = null; - - // Check MainTopic->MainTopic connection... - for (var i = 0; i < topics.length; i++) { - var targetTopic = topics[i]; - var position = dragTopic.getPosition(); - if (targetTopic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode) { - var canBeConnected = dragTopic.canBeConnectedTo(targetTopic); - if (canBeConnected) { - var targetPosition = targetTopic.getPosition(); - var fix = position.y > targetPosition.y; - var gap = 0; - if (targetTopic._getChildren().length > 0) { - gap = Math.abs(targetPosition.y - targetTopic._getChildren()[0].getPosition().y) - } - var yDistance = Math.abs(position.y - fix * gap - targetPosition.y); - if (distance == null || yDistance < distance) { - result = targetTopic; - distance = yDistance; - } - - } - } - } - return result; - } -}); - -mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE = 400; -/* - * 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.TextEditor = new Class({ - initialize:function(designer, actionRunner) { - this._designer = designer; - this._screenManager = designer.getWorkSpace().getScreenManager(); - this._container = this._screenManager.getContainer(); - this._actionRunner = actionRunner; - this._isVisible = false; - - //Create editor ui - this._createUI(); - - this._addListeners(); - - }, - - _createUI:function() { - this._size = {width:500, height:100}; - this._myOverlay = new Element('div').setStyles({position:"absolute", display: "none", zIndex: "8", top: 0, left:0, width:"500px", height:"100px"}); - var inputContainer = new Element('div').setStyles({border:"none", overflow:"auto"}).inject(this._myOverlay); - this.inputText = new Element('input').setProperties({type:"text", tabindex:'-1', id:"inputText", value:""}).setStyles({border:"none", background:"transparent"}).inject(inputContainer); - var spanContainer = new Element('div').setStyle('visibility', "hidden").inject(this._myOverlay); - this._spanText = new Element('span').setProperties({id: "spanText", tabindex:"-1"}).setStyle('white-space', "nowrap").setStyle('nowrap', 'nowrap').inject(spanContainer); - this._myOverlay.inject(this._container); - }, - - _addListeners:function() { - var elem = this; - this.applyChanges = true; - this.inputText.onkeyup = function (evt) { - var event = new Event(evt); - var key = event.key; - switch (key) { - case 'esc': - elem.applyChanges = false; - case 'enter': - var executor = function(editor) { - return function() { - elem.lostFocus(true); - $(document.documentElement).fireEvent('focus'); - }; - }; - setTimeout(executor(this), 3); - - break; - default: - var span = $('spanText'); - var input = $('inputText'); - span.innerHTML = input.value; - var size = input.value.length + 1; - input.size = size; - if (span.offsetWidth > (parseInt(elem._myOverlay.style.width) - 100)) { - elem._myOverlay.style.width = (span.offsetWidth + 100) + "px"; - } - break; - } - }; - //Register onLostFocus/onBlur event - $(this.inputText).addEvent('blur', this.lostFocusEvent.bind(this)); - $(this._myOverlay).addEvent('click', this.clickEvent.bindWithEvent(this)); - $(this._myOverlay).addEvent('dblclick', this.clickEvent.bindWithEvent(this)); - $(this._myOverlay).addEvent('mousedown', this.mouseDownEvent.bindWithEvent(this)); - - var elem = this; - var onComplete = function() { - this._myOverlay.setStyle('display', "none"); - this._isVisible = false; - this.inputText.setStyle('opacity', 1); - - this.setPosition(0, 0); - if (elem._currentNode != null) { - this._currentNode.getTextShape().setVisibility(true); - if (this.applyChanges) { - this._updateNode(); - } - this.applyChanges = true; - this._currentNode = null; - } - - setTimeout("$('ffoxWorkarroundInput').focus();", 0); - }; - this.fx = new Fx.Tween(this.inputText, {property: 'opacity', duration: 10}); - this.fx.addEvent('onComplete', onComplete.bind(this)); - }, - - lostFocusEvent : function () { - this.fx.options.duration = 10; - this.fx.start(1, 0); - //myAnim.animate(); - }, - - isVisible : function () { - return this._isVisible; - }, - - getFocusEvent: function (node) { - //console.log('focus event'); - if (this.isVisible()) { - this.getFocusEvent.delay(10, this); - } - else { - //console.log('calling init'); - this.init(node); - } - //console.log('focus event done'); - }, - - setInitialText : function (text) { - this.initialText = text; - }, - - _updateNode : function () { - - if ($defined(this._currentNode) && this._currentNode.getText() != this.getText()) { - var text = this.getText(); - var topicId = this._currentNode.getId(); - - var commandFunc = function(topic, value) { - var result = topic.getText(); - topic.setText(value); - return result; - }; - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, text, [topicId]); - this._actionRunner.execute(command); - } - }, - - listenEventOnNode : function(topic, eventName, stopPropagation) { - var elem = this; - topic.addEventListener(eventName, function (event) { - if (elem._designer.getWorkSpace().isWorkspaceEventsEnabled()) { - mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent, [topic ]); - elem.lostFocus(); - elem.getFocusEvent.attempt(topic, elem); - - if (stopPropagation) { - if ($defined(event.stopPropagation)) { - event.stopPropagation(true); - } else { - event.cancelBubble = true; - } - } - } - }); - }, - - init : function (nodeGraph) { - //console.log('init method'); - nodeGraph.getTextShape().setVisibility(false); - this._currentNode = nodeGraph; - - //set Editor Style - var nodeText = nodeGraph.getTextShape(); - var text; - var selectText = true; - if (this.initialText && this.initialText != "") { - text = this.initialText; - this.initialText = null; - selectText = false; - } - else - text = nodeText.getText(); - - var font = nodeText.getFont(); - font.size = nodeText.getHtmlFontSize(); - font.color = nodeText.getColor(); - - this.setStyle(font); - - //set editor's initial text - this.setText(text); - - //set editor's initial size - var editor = this; - var executor = function(editor) { - return function() { - //console.log('setting editor in init thread'); - var scale = web2d.peer.utils.TransformUtil.workoutScale(editor._currentNode.getTextShape()._peer); - var elemSize = editor._currentNode.getSize(); - //var textSize = editor.getSize(); - var pos = editor._screenManager.getWorkspaceElementPosition(editor._currentNode); - - var textWidth = editor._currentNode.getTextShape().getWidth(); - var textHeight = editor._currentNode.getTextShape().getHeight(); - var iconGroup = editor._currentNode.getIconGroup(); - var iconGroupSize; - if ($defined(iconGroup)) { - iconGroupSize = editor._currentNode.getIconGroup().getSize(); - } - else { - iconGroupSize = {width:0, height:0}; - } - var position = {x:0,y:0}; - position.x = pos.x - ((textWidth * scale.width) / 2) + (((iconGroupSize.width) * scale.width) / 2); - var fixError = 1; - position.y = pos.y - ((textHeight * scale.height) / 2) - fixError; - - editor.setEditorSize(elemSize.width, elemSize.height, scale); - //console.log('setting position:'+pos.x+';'+pos.y); - editor.setPosition(position.x, position.y, scale); - editor.showTextEditor(selectText); - //console.log('setting editor done'); - }; - }; - - setTimeout(executor(this), 10); - //console.log('init done'); - }, - - setStyle : function (fontStyle) { - var inputField = $("inputText"); - var spanField = $("spanText"); - if (!$defined(fontStyle.font)) { - fontStyle.font = "Arial"; - } - if (!$defined(fontStyle.style)) { - fontStyle.style = "normal"; - } - if (!$defined(fontStyle.weight)) { - fontStyle.weight = "normal"; - } - if (!$defined(fontStyle.size)) { - fontStyle.size = 12; - } - inputField.style.fontSize = fontStyle.size + "px"; - inputField.style.fontFamily = fontStyle.font; - inputField.style.fontStyle = fontStyle.style; - inputField.style.fontWeight = fontStyle.weight; - inputField.style.color = fontStyle.color; - spanField.style.fontFamily = fontStyle.font; - spanField.style.fontStyle = fontStyle.style; - spanField.style.fontWeight = fontStyle.weight; - spanField.style.fontSize = fontStyle.size + "px"; - }, - - setText : function(text) { - var inputField = $("inputText"); - inputField.size = text.length + 1; - //this._myOverlay.cfg.setProperty("width", (inputField.size * parseInt(inputField.style.fontSize) + 100) + "px"); - this._myOverlay.style.width = (inputField.size * parseInt(inputField.style.fontSize) + 100) + "px"; - var spanField = $("spanText"); - spanField.innerHTML = text; - inputField.value = text; - }, - - getText : function() { - return $('inputText').value; - }, - - setEditorSize : function (width, height, scale) { - //var scale = web2d.peer.utils.TransformUtil.workoutScale(this._currentNode.getTextShape()._peer); - this._size = {width:width * scale.width, height:height * scale.height}; - //this._myOverlay.cfg.setProperty("width",this._size.width*2+"px"); - this._myOverlay.style.width = this._size.width * 2 + "px"; - //this._myOverlay.cfg.setProperty("height",this._size.height+"px"); - this._myOverlay.style.height = this._size.height + "px"; - }, - - getSize : function () { - return {width:$("spanText").offsetWidth,height:$("spanText").offsetHeight}; - }, - - setPosition : function (x, y, scale) { - $(this._myOverlay).setStyles({top : y + "px", left: x + "px"}); - //this._myOverlay.style.left = x + "px"; - }, - - showTextEditor : function(selectText) { - //this._myOverlay.show(); - //var myAnim = new YAHOO.util.Anim('inputText',{opacity: {to:1}}, 0.10, YAHOO.util.Easing.easeOut); - //$('inputText').style.opacity='1'; - var elem = this; - //myAnim.onComplete.subscribe(function(){ - //elem._myOverlay.show(); - elem._myOverlay.setStyle('display', "block"); - this._isVisible = true; - //elem.cfg.setProperty("visible", false); - //elem._myOverlay.cfg.setProperty("xy", [0, 0]); - //elem._myOverlay.cfg.setProperty("visible", true); - //select the text in the input - $('inputText').disabled = false; - - if ($('inputText').createTextRange) //ie - { - var range = $('inputText').createTextRange(); - var pos = $('inputText').value.length; - if (selectText) { - range.select(); - range.move("character", pos); - } - else { - range.move("character", pos); - range.select(); - } - } - else if (selectText) { - $('inputText').setSelectionRange(0, $('inputText').value.length); - } - - var executor = function(editor) { - return function() { - try { - $('inputText').focus(); - } - catch (e) { - - } - }; - }; - setTimeout(executor(this), 0); - //}); - //myAnim.animate(); - - }, - - lostFocus : function(bothBrowsers) { - if (this.isVisible()) { - //the editor is opened in another node. lets Finish it. - var fireOnThis = $('inputText'); - fireOnThis.fireEvent('blur'); - } - }, - clickEvent : function(event) { - if (this.isVisible()) { - if ($defined(event.stopPropagation)) { - event.stopPropagation(true); - } else { - event.cancelBubble = true; - } - event.preventDefault(); - } - - }, - mouseDownEvent : function(event) { - if (this.isVisible()) { - if ($defined(event.stopPropagation)) { - event.stopPropagation(true); - } else { - event.cancelBubble = true; - } - } - } - -}); - +/* + * 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.DragTopicPositioner = new Class({ + initialize:function(layoutManager) { + $assert(layoutManager, 'layoutManager can not be null'); + this._layoutManager = layoutManager; + this._topics = layoutManager.getDesigner()._getTopics(); + this._workspace = layoutManager.getDesigner().getWorkSpace(); + }, + + positionateDragTopic : function(dragTopic) { + // Workout the real position of the element on the board. + var dragTopicPosition = dragTopic.getPosition(); + var draggedTopic = dragTopic.getDraggedTopic(); + + // Topic can be connected ? + this._checkDragTopicConnection(dragTopic); + + // Position topic in the board + if (dragTopic.isConnected()) { + var targetTopic = dragTopic.getConnectedToTopic(); + var topicBoard = this._layoutManager.getTopicBoardForTopic(targetTopic); + topicBoard.positionateDragTopic(dragTopic); + } + }, + + _checkDragTopicConnection : function(dragTopic) { + var topics = this._topics; + + // Must be disconnected from their current connection ?. + var mainTopicToMainTopicConnection = this._lookUpForMainTopicToMainTopicConnection(dragTopic); + var currentConnection = dragTopic.getConnectedToTopic(); + if ($defined(currentConnection)) { + // MainTopic->MainTopicConnection. + if (currentConnection.getType() == mindplot.model.NodeModel.MAIN_TOPIC_TYPE) { + if (mainTopicToMainTopicConnection != currentConnection) { + dragTopic.disconnect(this._workspace); + } + } + else if (currentConnection.getType() == mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE) { + // Distance if greater that the allowed. + var dragXPosition = dragTopic.getPosition().x; + var currentXPosition = currentConnection.getPosition().x; + + if ($defined(mainTopicToMainTopicConnection)) { + // I have to change the current connection to a main topic. + dragTopic.disconnect(this._workspace); + } else + if (Math.abs(dragXPosition - currentXPosition) > mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) { + dragTopic.disconnect(this._workspace); + } + } + } + + // Finally, connect nodes ... + if (!dragTopic.isConnected()) { + var centalTopic = topics[0]; + if ($defined(mainTopicToMainTopicConnection)) { + dragTopic.connectTo(mainTopicToMainTopicConnection); + } else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) { + dragTopic.connectTo(centalTopic); + } + } + }, + + _lookUpForMainTopicToMainTopicConnection : function(dragTopic) { + var topics = this._topics; + var result = null; + var clouserDistance = -1; + var draggedNode = dragTopic.getDraggedTopic(); + var distance = null; + + // Check MainTopic->MainTopic connection... + for (var i = 0; i < topics.length; i++) { + var targetTopic = topics[i]; + var position = dragTopic.getPosition(); + if (targetTopic.getType() != mindplot.model.NodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode) { + var canBeConnected = dragTopic.canBeConnectedTo(targetTopic); + if (canBeConnected) { + var targetPosition = targetTopic.getPosition(); + var fix = position.y > targetPosition.y; + var gap = 0; + if (targetTopic._getChildren().length > 0) { + gap = Math.abs(targetPosition.y - targetTopic._getChildren()[0].getPosition().y) + } + var yDistance = Math.abs(position.y - fix * gap - targetPosition.y); + if (distance == null || yDistance < distance) { + result = targetTopic; + distance = yDistance; + } + + } + } + } + return result; + } +}); + +mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE = 400; +/* + * 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.TextEditor = new Class({ + initialize:function(designer, actionRunner) { + this._designer = designer; + this._screenManager = designer.getWorkSpace().getScreenManager(); + this._container = this._screenManager.getContainer(); + this._actionRunner = actionRunner; + this._isVisible = false; + + //Create editor ui + this._createUI(); + + this._addListeners(); + + }, + + _createUI:function() { + this._size = {width:500, height:100}; + this._myOverlay = new Element('div').setStyles({position:"absolute", display: "none", zIndex: "8", top: 0, left:0, width:"500px", height:"100px"}); + var inputContainer = new Element('div').setStyles({border:"none", overflow:"auto"}).inject(this._myOverlay); + this.inputText = new Element('input').setProperties({type:"text", tabindex:'-1', id:"inputText", value:""}).setStyles({border:"none", background:"transparent"}).inject(inputContainer); + var spanContainer = new Element('div').setStyle('visibility', "hidden").inject(this._myOverlay); + this._spanText = new Element('span').setProperties({id: "spanText", tabindex:"-1"}).setStyle('white-space', "nowrap").setStyle('nowrap', 'nowrap').inject(spanContainer); + this._myOverlay.inject(this._container); + }, + + _addListeners:function() { + var elem = this; + this.applyChanges = true; + this.inputText.onkeyup = function (evt) { + var event = new Event(evt); + var key = event.key; + switch (key) { + case 'esc': + elem.applyChanges = false; + case 'enter': + var executor = function(editor) { + return function() { + elem.lostFocus(true); + $(document.documentElement).fireEvent('focus'); + }; + }; + setTimeout(executor(this), 3); + + break; + default: + var span = $('spanText'); + var input = $('inputText'); + span.innerHTML = input.value; + var size = input.value.length + 1; + input.size = size; + if (span.offsetWidth > (parseInt(elem._myOverlay.style.width) - 100)) { + elem._myOverlay.style.width = (span.offsetWidth + 100) + "px"; + } + break; + } + }; + //Register onLostFocus/onBlur event + $(this.inputText).addEvent('blur', this.lostFocusEvent.bind(this)); + $(this._myOverlay).addEvent('click', this.clickEvent.bindWithEvent(this)); + $(this._myOverlay).addEvent('dblclick', this.clickEvent.bindWithEvent(this)); + $(this._myOverlay).addEvent('mousedown', this.mouseDownEvent.bindWithEvent(this)); + + var elem = this; + var onComplete = function() { + this._myOverlay.setStyle('display', "none"); + this._isVisible = false; + this.inputText.setStyle('opacity', 1); + + this.setPosition(0, 0); + if (elem._currentNode != null) { + this._currentNode.getTextShape().setVisibility(true); + if (this.applyChanges) { + this._updateNode(); + } + this.applyChanges = true; + this._currentNode = null; + } + + setTimeout("$('ffoxWorkarroundInput').focus();", 0); + }; + this.fx = new Fx.Tween(this.inputText, {property: 'opacity', duration: 10}); + this.fx.addEvent('onComplete', onComplete.bind(this)); + }, + + lostFocusEvent : function () { + this.fx.options.duration = 10; + this.fx.start(1, 0); + //myAnim.animate(); + }, + + isVisible : function () { + return this._isVisible; + }, + + getFocusEvent: function (node) { + //console.log('focus event'); + if (this.isVisible()) { + this.getFocusEvent.delay(10, this); + } + else { + //console.log('calling init'); + this.init(node); + } + //console.log('focus event done'); + }, + + setInitialText : function (text) { + this.initialText = text; + }, + + _updateNode : function () { + + if ($defined(this._currentNode) && this._currentNode.getText() != this.getText()) { + var text = this.getText(); + var topicId = this._currentNode.getId(); + + var commandFunc = function(topic, value) { + var result = topic.getText(); + topic.setText(value); + return result; + }; + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, text, [topicId]); + this._actionRunner.execute(command); + } + }, + + listenEventOnNode : function(topic, eventName, stopPropagation) { + var elem = this; + topic.addEventListener(eventName, function (event) { + if (elem._designer.getWorkSpace().isWorkspaceEventsEnabled()) { + mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent, [topic ]); + elem.lostFocus(); + elem.getFocusEvent.attempt(topic, elem); + + if (stopPropagation) { + if ($defined(event.stopPropagation)) { + event.stopPropagation(true); + } else { + event.cancelBubble = true; + } + } + } + }); + }, + + init : function (nodeGraph) { + //console.log('init method'); + nodeGraph.getTextShape().setVisibility(false); + this._currentNode = nodeGraph; + + //set Editor Style + var nodeText = nodeGraph.getTextShape(); + var text; + var selectText = true; + if (this.initialText && this.initialText != "") { + text = this.initialText; + this.initialText = null; + selectText = false; + } + else + text = nodeText.getText(); + + var font = nodeText.getFont(); + font.size = nodeText.getHtmlFontSize(); + font.color = nodeText.getColor(); + + this.setStyle(font); + + //set editor's initial text + this.setText(text); + + //set editor's initial size + var editor = this; + var executor = function(editor) { + return function() { + //console.log('setting editor in init thread'); + var scale = web2d.peer.utils.TransformUtil.workoutScale(editor._currentNode.getTextShape()._peer); + var elemSize = editor._currentNode.getSize(); + //var textSize = editor.getSize(); + var pos = editor._screenManager.getWorkspaceElementPosition(editor._currentNode); + + var textWidth = editor._currentNode.getTextShape().getWidth(); + var textHeight = editor._currentNode.getTextShape().getHeight(); + var iconGroup = editor._currentNode.getIconGroup(); + var iconGroupSize; + if ($defined(iconGroup)) { + iconGroupSize = editor._currentNode.getIconGroup().getSize(); + } + else { + iconGroupSize = {width:0, height:0}; + } + var position = {x:0,y:0}; + position.x = pos.x - ((textWidth * scale.width) / 2) + (((iconGroupSize.width) * scale.width) / 2); + var fixError = 1; + position.y = pos.y - ((textHeight * scale.height) / 2) - fixError; + + editor.setEditorSize(elemSize.width, elemSize.height, scale); + //console.log('setting position:'+pos.x+';'+pos.y); + editor.setPosition(position.x, position.y, scale); + editor.showTextEditor(selectText); + //console.log('setting editor done'); + }; + }; + + setTimeout(executor(this), 10); + //console.log('init done'); + }, + + setStyle : function (fontStyle) { + var inputField = $("inputText"); + var spanField = $("spanText"); + if (!$defined(fontStyle.font)) { + fontStyle.font = "Arial"; + } + if (!$defined(fontStyle.style)) { + fontStyle.style = "normal"; + } + if (!$defined(fontStyle.weight)) { + fontStyle.weight = "normal"; + } + if (!$defined(fontStyle.size)) { + fontStyle.size = 12; + } + inputField.style.fontSize = fontStyle.size + "px"; + inputField.style.fontFamily = fontStyle.font; + inputField.style.fontStyle = fontStyle.style; + inputField.style.fontWeight = fontStyle.weight; + inputField.style.color = fontStyle.color; + spanField.style.fontFamily = fontStyle.font; + spanField.style.fontStyle = fontStyle.style; + spanField.style.fontWeight = fontStyle.weight; + spanField.style.fontSize = fontStyle.size + "px"; + }, + + setText : function(text) { + var inputField = $("inputText"); + inputField.size = text.length + 1; + //this._myOverlay.cfg.setProperty("width", (inputField.size * parseInt(inputField.style.fontSize) + 100) + "px"); + this._myOverlay.style.width = (inputField.size * parseInt(inputField.style.fontSize) + 100) + "px"; + var spanField = $("spanText"); + spanField.innerHTML = text; + inputField.value = text; + }, + + getText : function() { + return $('inputText').value; + }, + + setEditorSize : function (width, height, scale) { + //var scale = web2d.peer.utils.TransformUtil.workoutScale(this._currentNode.getTextShape()._peer); + this._size = {width:width * scale.width, height:height * scale.height}; + //this._myOverlay.cfg.setProperty("width",this._size.width*2+"px"); + this._myOverlay.style.width = this._size.width * 2 + "px"; + //this._myOverlay.cfg.setProperty("height",this._size.height+"px"); + this._myOverlay.style.height = this._size.height + "px"; + }, + + getSize : function () { + return {width:$("spanText").offsetWidth,height:$("spanText").offsetHeight}; + }, + + setPosition : function (x, y, scale) { + $(this._myOverlay).setStyles({top : y + "px", left: x + "px"}); + //this._myOverlay.style.left = x + "px"; + }, + + showTextEditor : function(selectText) { + //this._myOverlay.show(); + //var myAnim = new YAHOO.util.Anim('inputText',{opacity: {to:1}}, 0.10, YAHOO.util.Easing.easeOut); + //$('inputText').style.opacity='1'; + var elem = this; + //myAnim.onComplete.subscribe(function(){ + //elem._myOverlay.show(); + elem._myOverlay.setStyle('display', "block"); + this._isVisible = true; + //elem.cfg.setProperty("visible", false); + //elem._myOverlay.cfg.setProperty("xy", [0, 0]); + //elem._myOverlay.cfg.setProperty("visible", true); + //select the text in the input + $('inputText').disabled = false; + + if ($('inputText').createTextRange) //ie + { + var range = $('inputText').createTextRange(); + var pos = $('inputText').value.length; + if (selectText) { + range.select(); + range.move("character", pos); + } + else { + range.move("character", pos); + range.select(); + } + } + else if (selectText) { + $('inputText').setSelectionRange(0, $('inputText').value.length); + } + + var executor = function(editor) { + return function() { + try { + $('inputText').focus(); + } + catch (e) { + + } + }; + }; + setTimeout(executor(this), 0); + //}); + //myAnim.animate(); + + }, + + lostFocus : function(bothBrowsers) { + if (this.isVisible()) { + //the editor is opened in another node. lets Finish it. + var fireOnThis = $('inputText'); + fireOnThis.fireEvent('blur'); + } + }, + clickEvent : function(event) { + if (this.isVisible()) { + if ($defined(event.stopPropagation)) { + event.stopPropagation(true); + } else { + event.cancelBubble = true; + } + event.preventDefault(); + } + + }, + mouseDownEvent : function(event) { + if (this.isVisible()) { + if ($defined(event.stopPropagation)) { + event.stopPropagation(true); + } else { + event.cancelBubble = true; + } + } + } + +}); + /* * Copyright [2011] [wisemapping] * @@ -7412,218 +7411,218 @@ mindplot.TextEditorFactory.getTextEditorFromName = function(name) { editorClass = mindplot.TextEditor; } return editorClass; -};/* - * 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.VariableDistanceBoard = new Class({ - Extends: mindplot.Board, - initialize: function(defaultHeight, referencePoint) { - this.parent(defaultHeight, referencePoint); - var zeroEntryCoordinate = referencePoint.y; - var entry = this.createBoardEntry(zeroEntryCoordinate - (defaultHeight / 2), zeroEntryCoordinate + (defaultHeight / 2), 0); - this._entries.set(0, entry); - }, - - lookupEntryByOrder:function(order) { - var entries = this._entries; - var index = this._orderToIndex(order); - - var result = entries.get(index); - if (!$defined(result)) { - // I've not found a entry. I have to create a new one. - var i = 1; - var zeroEntry = entries.get(0); - var distance = zeroEntry.getWidth() / 2; - var indexSign = Math.sign(index); - var absIndex = Math.abs(index); - while (i < absIndex) { - // Move to the next entry ... - var entry = entries.get(i, indexSign); - if (entry != null) { - distance += entry.getWidth(); - } else { - distance += this._defaultWidth; - } - i++; - } - - // Calculate limits ... - var upperLimit = -1; - var lowerLimit = -1; - var offset = zeroEntry.workoutEntryYCenter(); - if (index >= 0) { - lowerLimit = offset + distance; - upperLimit = lowerLimit + this._defaultWidth; - } else { - upperLimit = offset - distance; - lowerLimit = upperLimit - this._defaultWidth; - } - - result = this.createBoardEntry(lowerLimit, upperLimit, order); - } - return result; - }, - - createBoardEntry:function(lowerLimit, upperLimit, order) { - return new mindplot.BoardEntry(lowerLimit, upperLimit, order); - }, - - updateReferencePoint:function(position) { - var entries = this._entries; - var referencePoint = this._referencePoint; - - // Update zero entry current position. - this._referencePoint = position.clone(); - var yOffset = position.y - referencePoint.y; - - var i = -entries.lowerLength(); - for (; i <= entries.length(1); i++) { - var entry = entries.get(i); - if (entry != null) { - var upperLimit = entry.getUpperLimit() + yOffset; - var lowerLimit = entry.getLowerLimit() + yOffset; - entry.setUpperLimit(upperLimit); - entry.setLowerLimit(lowerLimit); - - // Update topic position ... - if (!entry.isAvailable()) { - var topic = entry.getTopic(); - var topicPosition = topic.getPosition(); - topicPosition.y = topicPosition.y + yOffset; - - // MainTopicToCentral must be positioned based on the referencePoint. - var xOffset = position.x - referencePoint.x; - topicPosition.x = topicPosition.x + xOffset; - - topic.setPosition(topicPosition); - } - } - } - }, - - lookupEntryByPosition:function(pos) { - $assert(pos, 'position can not be null'); - var entries = this._entries; - var zeroEntry = entries.get(0); - if (zeroEntry.isCoordinateIn(pos.y)) { - return zeroEntry; - } - - // Is Upper or lower ? - var sign = -1; - if (pos.y >= zeroEntry.getUpperLimit()) { - sign = 1; - } - - var i = 1; - var tempEntry = this.createBoardEntry(); - var currentEntry = zeroEntry; - while (true) { - // Move to the next entry ... - var index = i * sign; - var entry = entries.get(index); - if ($defined(entry)) { - currentEntry = entry; - } else { - // Calculate boundaries... - var lowerLimit, upperLimit; - if (sign > 0) { - lowerLimit = currentEntry.getUpperLimit(); - upperLimit = lowerLimit + this._defaultWidth; - } - else { - upperLimit = currentEntry.getLowerLimit(); - lowerLimit = upperLimit - this._defaultWidth; - } - - // Update current entry. - currentEntry = tempEntry; - currentEntry.setLowerLimit(lowerLimit); - currentEntry.setUpperLimit(upperLimit); - - var order = this._indexToOrder(index); - currentEntry.setOrder(order); - } - - // Have I found the item? - if (currentEntry.isCoordinateIn(pos.y)) { - break; - } - i++; - } - return currentEntry; - }, - - update:function(entry) { - $assert(entry, 'Entry can not be null'); - var order = entry.getOrder(); - var index = this._orderToIndex(order); - - this._entries.set(index, entry); - - }, - freeEntry:function(entry) { - var order = entry.getOrder(); - var entries = this._entries; - - var index = this._orderToIndex(order); - var indexSign = Math.sign(index); - - var currentTopic = entry.getTopic(); - var i = Math.abs(index) + 1; - while (currentTopic) { - var e = entries.get(i, indexSign); - if ($defined(currentTopic) && !$defined(e)) { - var entryOrder = this._indexToOrder(i * indexSign); - e = this.lookupEntryByOrder(entryOrder); - } - - // Move the topic to the next entry ... - var topic = null; - if ($defined(e)) { - topic = e.getTopic(); - if ($defined(currentTopic)) { - e.setTopic(currentTopic); - } - this.update(e); - } - currentTopic = topic; - i++; - } - - // Clear the entry topic ... - entry.setTopic(null); - }, - - _orderToIndex:function(order) { - var index = Math.round(order / 2); - return ((order % 2) == 0) ? index : -index; - }, - - _indexToOrder:function(index) { - var order = Math.abs(index) * 2; - return (index >= 0) ? order : order - 1; - }, - - inspect:function() { - return this._entries.inspect(); - } - +};/* + * 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.VariableDistanceBoard = new Class({ + Extends: mindplot.Board, + initialize: function(defaultHeight, referencePoint) { + this.parent(defaultHeight, referencePoint); + var zeroEntryCoordinate = referencePoint.y; + var entry = this.createBoardEntry(zeroEntryCoordinate - (defaultHeight / 2), zeroEntryCoordinate + (defaultHeight / 2), 0); + this._entries.set(0, entry); + }, + + lookupEntryByOrder:function(order) { + var entries = this._entries; + var index = this._orderToIndex(order); + + var result = entries.get(index); + if (!$defined(result)) { + // I've not found a entry. I have to create a new one. + var i = 1; + var zeroEntry = entries.get(0); + var distance = zeroEntry.getWidth() / 2; + var indexSign = Math.sign(index); + var absIndex = Math.abs(index); + while (i < absIndex) { + // Move to the next entry ... + var entry = entries.get(i, indexSign); + if (entry != null) { + distance += entry.getWidth(); + } else { + distance += this._defaultWidth; + } + i++; + } + + // Calculate limits ... + var upperLimit = -1; + var lowerLimit = -1; + var offset = zeroEntry.workoutEntryYCenter(); + if (index >= 0) { + lowerLimit = offset + distance; + upperLimit = lowerLimit + this._defaultWidth; + } else { + upperLimit = offset - distance; + lowerLimit = upperLimit - this._defaultWidth; + } + + result = this.createBoardEntry(lowerLimit, upperLimit, order); + } + return result; + }, + + createBoardEntry:function(lowerLimit, upperLimit, order) { + return new mindplot.BoardEntry(lowerLimit, upperLimit, order); + }, + + updateReferencePoint:function(position) { + var entries = this._entries; + var referencePoint = this._referencePoint; + + // Update zero entry current position. + this._referencePoint = position.clone(); + var yOffset = position.y - referencePoint.y; + + var i = -entries.lowerLength(); + for (; i <= entries.length(1); i++) { + var entry = entries.get(i); + if (entry != null) { + var upperLimit = entry.getUpperLimit() + yOffset; + var lowerLimit = entry.getLowerLimit() + yOffset; + entry.setUpperLimit(upperLimit); + entry.setLowerLimit(lowerLimit); + + // Update topic position ... + if (!entry.isAvailable()) { + var topic = entry.getTopic(); + var topicPosition = topic.getPosition(); + topicPosition.y = topicPosition.y + yOffset; + + // MainTopicToCentral must be positioned based on the referencePoint. + var xOffset = position.x - referencePoint.x; + topicPosition.x = topicPosition.x + xOffset; + + topic.setPosition(topicPosition); + } + } + } + }, + + lookupEntryByPosition:function(pos) { + $assert(pos, 'position can not be null'); + var entries = this._entries; + var zeroEntry = entries.get(0); + if (zeroEntry.isCoordinateIn(pos.y)) { + return zeroEntry; + } + + // Is Upper or lower ? + var sign = -1; + if (pos.y >= zeroEntry.getUpperLimit()) { + sign = 1; + } + + var i = 1; + var tempEntry = this.createBoardEntry(); + var currentEntry = zeroEntry; + while (true) { + // Move to the next entry ... + var index = i * sign; + var entry = entries.get(index); + if ($defined(entry)) { + currentEntry = entry; + } else { + // Calculate boundaries... + var lowerLimit, upperLimit; + if (sign > 0) { + lowerLimit = currentEntry.getUpperLimit(); + upperLimit = lowerLimit + this._defaultWidth; + } + else { + upperLimit = currentEntry.getLowerLimit(); + lowerLimit = upperLimit - this._defaultWidth; + } + + // Update current entry. + currentEntry = tempEntry; + currentEntry.setLowerLimit(lowerLimit); + currentEntry.setUpperLimit(upperLimit); + + var order = this._indexToOrder(index); + currentEntry.setOrder(order); + } + + // Have I found the item? + if (currentEntry.isCoordinateIn(pos.y)) { + break; + } + i++; + } + return currentEntry; + }, + + update:function(entry) { + $assert(entry, 'Entry can not be null'); + var order = entry.getOrder(); + var index = this._orderToIndex(order); + + this._entries.set(index, entry); + + }, + freeEntry:function(entry) { + var order = entry.getOrder(); + var entries = this._entries; + + var index = this._orderToIndex(order); + var indexSign = Math.sign(index); + + var currentTopic = entry.getTopic(); + var i = Math.abs(index) + 1; + while (currentTopic) { + var e = entries.get(i, indexSign); + if ($defined(currentTopic) && !$defined(e)) { + var entryOrder = this._indexToOrder(i * indexSign); + e = this.lookupEntryByOrder(entryOrder); + } + + // Move the topic to the next entry ... + var topic = null; + if ($defined(e)) { + topic = e.getTopic(); + if ($defined(currentTopic)) { + e.setTopic(currentTopic); + } + this.update(e); + } + currentTopic = topic; + i++; + } + + // Clear the entry topic ... + entry.setTopic(null); + }, + + _orderToIndex:function(order) { + var index = Math.round(order / 2); + return ((order % 2) == 0) ? index : -index; + }, + + _indexToOrder:function(index) { + var order = Math.abs(index) * 2; + return (index >= 0) ? order : order - 1; + }, + + inspect:function() { + return this._entries.inspect(); + } + });/* * Copyright [2011] [wisemapping] * @@ -7768,433 +7767,433 @@ mindplot.util.Shape = } }; -/* - * 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.FixedDistanceBoard = new Class({ - Extends:mindplot.Board, - initialize:function(defaultHeight, topic, layoutManager) { - this._topic = topic; - this._layoutManager = layoutManager; - var reference = topic.getPosition(); - this.parent(defaultHeight, reference); - this._height = defaultHeight; - this._entries = []; - }, - - getHeight : function() { - return this._height; - }, - - lookupEntryByOrder : function(order) { - var result = null; - var entries = this._entries; - if (order < entries.length) { - result = entries[order]; - } - - if (result == null) { - var defaultHeight = this._defaultWidth; - var reference = this.getReferencePoint(); - if (entries.length == 0) { - var yReference = reference.y; - result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); - } else { - var entriesLenght = entries.length; - var lastEntry = entries[entriesLenght - 1]; - var lowerLimit = lastEntry.getUpperLimit(); - var upperLimit = lowerLimit + defaultHeight; - result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1); - } - } - return result; - }, - - createBoardEntry : function(lowerLimit, upperLimit, order) { - var result = new mindplot.BoardEntry(lowerLimit, upperLimit, order); - var xPos = this.workoutXBorderDistance(); - result.setXPosition(xPos); - return result; - }, - - updateReferencePoint : function() { - var entries = this._entries; - var parentTopic = this.getTopic(); - var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition()); - var referencePoint = this.getReferencePoint(); - var yOffset = parentPosition.y - referencePoint.y; - - for (var i = 0; i < entries.length; i++) { - var entry = entries[i]; - - if ($defined(entry)) { - var upperLimit = entry.getUpperLimit() + yOffset; - var lowerLimit = entry.getLowerLimit() + yOffset; - entry.setUpperLimit(upperLimit); - entry.setLowerLimit(lowerLimit); - - // Fix x position ... - var xPos = this.workoutXBorderDistance(); - entry.setXPosition(xPos); - entry.update(); - } - } - this._referencePoint = parentPosition.clone(); - - }, - - /** - * This x distance doesn't take into account the size of the shape. - */ - workoutXBorderDistance : function() { - var topic = this.getTopic(); - - var topicPosition = topic.getPosition(); - var topicSize = topic.getSize(); - var halfTargetWidth = topicSize.width / 2; - var result; - if (topicPosition.x >= 0) { - // It's at right. - result = topicPosition.x + halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE; - } else { - result = topicPosition.x - (halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE); - } - return result; - }, - - getTopic : function() { - return this._topic; - }, - - freeEntry : function(entry) { - var newEntries = []; - var entries = this._entries; - var order = 0; - for (var i = 0; i < entries.length; i++) { - var e = entries[i]; - if (e == entry) { - order++; - } - newEntries[order] = e; - order++; - } - this._entries = newEntries; - }, - - repositionate : function() { - // Workout width and update topic height. - var entries = this._entries; - var height = 0; - var model = this._topic.getModel(); - if (entries.length >= 1 && !model.areChildrenShrinked()) { - for (var i = 0; i < entries.length; i++) { - var e = entries[i]; - if (e && e.getTopic()) { - var topic = e.getTopic(); - var topicBoard = this._layoutManager.getTopicBoardForTopic(topic); - var topicBoardHeight = topicBoard.getHeight(); - - - height += topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; - } - } - } - else { - var topic = this._topic; - height = topic.getSize().height + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; - } - - var oldHeight = this._height; - this._height = height; - - // I must update all the parent nodes first... - if (oldHeight != this._height) { - var topic = this._topic; - var parentTopic = topic.getParent(); - if (parentTopic != null) { - var board = this._layoutManager.getTopicBoardForTopic(parentTopic); - board.repositionate(); - } - } - - - // @todo: Esto hace backtraking. Hay que cambiar la implementacion del set position de - // forma tal que no se mande a hacer el update de todos los hijos. - - // Workout center the new topic center... - var refence = this.getReferencePoint(); - var lowerLimit; - if (entries.length > 0) { - var l = 0; - for (l = 0; l < entries.length; l++) { - if ($defined(entries[l])) - break; - } - var topic = entries[l].getTopic(); - var firstNodeHeight = topic.getSize().height; - lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1; - } - - var upperLimit = null; - - // Start moving all the elements ... - var newEntries = []; - var order = 0; - for (var i = 0; i < entries.length; i++) { - var e = entries[i]; - if (e && e.getTopic()) { - - var currentTopic = e.getTopic(); - e.setLowerLimit(lowerLimit); - - // Update entry ... - var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic); - var topicBoardHeight = topicBoard.getHeight(); - - upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; - e.setUpperLimit(upperLimit); - lowerLimit = upperLimit; - - e.setOrder(order); - currentTopic.setOrder(order); - - e.update(); - newEntries[order] = e; - order++; - } - } - this._entries = newEntries; - }, - - removeTopic : function(topic) { - var order = topic.getOrder(); - var entry = this.lookupEntryByOrder(order); - $assert(!entry.isAvailable(), "Illegal state"); - - entry.setTopic(null); - topic.setOrder(null); - this._entries.erase(entry); - - // Repositionate all elements ... - this.repositionate(); - }, - - addTopic : function(order, topic) { - - // If the entry is not available, I must swap the the entries... - var entry = this.lookupEntryByOrder(order); - if (!entry.isAvailable()) { - this.freeEntry(entry); - // Create a dummy entry ... - // Puaj, do something with this... - entry = this.createBoardEntry(-1, 0, order); - this._entries[order] = entry; - } - this._entries[order] = entry; - - // Add to the board ... - entry.setTopic(topic, false); - - // Repositionate all elements ... - this.repositionate(); - }, - - lookupEntryByPosition : function(pos) { - $assert(pos, 'position can not be null'); - - var entries = this._entries; - var result = null; - for (var i = 0; i < entries.length; i++) { - var entry = entries[i]; - if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit()) { - result = entry; - } - } - - if (result == null) { - var defaultHeight = this._defaultWidth; - if (entries.length == 0) { - var reference = this.getReferencePoint(); - var yReference = reference.y; - result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); - } else { - var firstEntry = entries[0]; - if (pos.y < firstEntry.getLowerLimit()) { - var upperLimit = firstEntry.getLowerLimit(); - var lowerLimit = upperLimit - defaultHeight; - result = this.createBoardEntry(lowerLimit, upperLimit, 0); - } else { - var entriesLenght = entries.length; - var lastEntry = entries[entriesLenght - 1]; - var lowerLimit = lastEntry.getUpperLimit(); - var upperLimit = lowerLimit + defaultHeight; - result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght); - } - } - } - - return result; - } -}) - ; -mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6; -mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60; - -/* - * 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.BoardEntry = new Class({ - initialize:function(lowerLimit, upperLimit, order) { - if ($defined(lowerLimit) && $defined(upperLimit)) { - $assert(lowerLimit < upperLimit, 'lowerLimit can not be greater that upperLimit'); - } - this._upperLimit = upperLimit; - this._lowerLimit = lowerLimit; - this._order = order; - this._topic = null; - this._xPos = null; - }, - - - getUpperLimit : function() { - return this._upperLimit; - }, - - setXPosition : function(xPosition) { - this._xPos = xPosition; - }, - - workoutEntryYCenter : function() { - return this._lowerLimit + ((this._upperLimit - this._lowerLimit) / 2); - }, - - setUpperLimit : function(value) { - $assert(value, "upper limit can not be null"); - $assert(!isNaN(value), "illegal value"); - this._upperLimit = value; - }, - - isCoordinateIn : function(coord) { - return this._lowerLimit <= coord && coord < this._upperLimit; - }, - - getLowerLimit : function() { - return this._lowerLimit; - }, - - setLowerLimit : function(value) { - $assert(value, "upper limit can not be null"); - $assert(!isNaN(value), "illegal value"); - this._lowerLimit = value; - }, - - setOrder : function(value) { - this._order = value; - }, - - getWidth : function() { - return Math.abs(this._upperLimit - this._lowerLimit); - }, - - - getTopic : function() { - return this._topic; - }, - - - removeTopic : function() { - $assert(!this.isAvailable(), "Entry doesn't have a topic."); - var topic = this.getTopic(); - this.setTopic(null); - topic.setOrder(null); - }, - - - update : function() { - var topic = this.getTopic(); - this.setTopic(topic); - }, - - setTopic : function(topic, updatePosition) { - if (!$defined(updatePosition) || ($defined(updatePosition) && !updatePosition)) { - updatePosition = true; - } - - this._topic = topic; - if ($defined(topic)) { - // Fixed positioning. Only for main topic ... - var position = null; - var topicPosition = topic.getPosition(); - - // Must update position base on the border limits? - if ($defined(this._xPos)) { - position = new core.Point(); - - // Update x position ... - var topicSize = topic.getSize(); - var halfTopicWidh = parseInt(topicSize.width / 2); - halfTopicWidh = (this._xPos > 0) ? halfTopicWidh : -halfTopicWidh; - position.x = this._xPos + halfTopicWidh; - position.y = this.workoutEntryYCenter(); - } else { - - // Central topic - this._height = topic.getSize().height; - var xPos = topicPosition.x; - var yPos = this.workoutEntryYCenter(); - position = new core.Point(xPos, yPos); - } - - // @todo: No esta de mas... - topic.setPosition(position); - topic.setOrder(this._order); - } - else { - this._height = this._defaultWidth; - } - }, - - isAvailable : function() { - return !$defined(this._topic); - }, - - getOrder : function() { - return this._order; - }, - - inspect : function() { - return '(order: ' + this._order + ', lowerLimit:' + this._lowerLimit + ', upperLimit: ' + this._upperLimit + ', available:' + this.isAvailable() + ')'; - } +/* + * 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.FixedDistanceBoard = new Class({ + Extends:mindplot.Board, + initialize:function(defaultHeight, topic, layoutManager) { + this._topic = topic; + this._layoutManager = layoutManager; + var reference = topic.getPosition(); + this.parent(defaultHeight, reference); + this._height = defaultHeight; + this._entries = []; + }, + + getHeight : function() { + return this._height; + }, + + lookupEntryByOrder : function(order) { + var result = null; + var entries = this._entries; + if (order < entries.length) { + result = entries[order]; + } + + if (result == null) { + var defaultHeight = this._defaultWidth; + var reference = this.getReferencePoint(); + if (entries.length == 0) { + var yReference = reference.y; + result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); + } else { + var entriesLenght = entries.length; + var lastEntry = entries[entriesLenght - 1]; + var lowerLimit = lastEntry.getUpperLimit(); + var upperLimit = lowerLimit + defaultHeight; + result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght + 1); + } + } + return result; + }, + + createBoardEntry : function(lowerLimit, upperLimit, order) { + var result = new mindplot.BoardEntry(lowerLimit, upperLimit, order); + var xPos = this.workoutXBorderDistance(); + result.setXPosition(xPos); + return result; + }, + + updateReferencePoint : function() { + var entries = this._entries; + var parentTopic = this.getTopic(); + var parentPosition = parentTopic.workoutIncomingConnectionPoint(parentTopic.getPosition()); + var referencePoint = this.getReferencePoint(); + var yOffset = parentPosition.y - referencePoint.y; + + for (var i = 0; i < entries.length; i++) { + var entry = entries[i]; + + if ($defined(entry)) { + var upperLimit = entry.getUpperLimit() + yOffset; + var lowerLimit = entry.getLowerLimit() + yOffset; + entry.setUpperLimit(upperLimit); + entry.setLowerLimit(lowerLimit); + + // Fix x position ... + var xPos = this.workoutXBorderDistance(); + entry.setXPosition(xPos); + entry.update(); + } + } + this._referencePoint = parentPosition.clone(); + + }, + + /** + * This x distance doesn't take into account the size of the shape. + */ + workoutXBorderDistance : function() { + var topic = this.getTopic(); + + var topicPosition = topic.getPosition(); + var topicSize = topic.getSize(); + var halfTargetWidth = topicSize.width / 2; + var result; + if (topicPosition.x >= 0) { + // It's at right. + result = topicPosition.x + halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE; + } else { + result = topicPosition.x - (halfTargetWidth + mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE); + } + return result; + }, + + getTopic : function() { + return this._topic; + }, + + freeEntry : function(entry) { + var newEntries = []; + var entries = this._entries; + var order = 0; + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + if (e == entry) { + order++; + } + newEntries[order] = e; + order++; + } + this._entries = newEntries; + }, + + repositionate : function() { + // Workout width and update topic height. + var entries = this._entries; + var height = 0; + var model = this._topic.getModel(); + if (entries.length >= 1 && !model.areChildrenShrinked()) { + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + if (e && e.getTopic()) { + var topic = e.getTopic(); + var topicBoard = this._layoutManager.getTopicBoardForTopic(topic); + var topicBoardHeight = topicBoard.getHeight(); + + + height += topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; + } + } + } + else { + var topic = this._topic; + height = topic.getSize().height + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; + } + + var oldHeight = this._height; + this._height = height; + + // I must update all the parent nodes first... + if (oldHeight != this._height) { + var topic = this._topic; + var parentTopic = topic.getParent(); + if (parentTopic != null) { + var board = this._layoutManager.getTopicBoardForTopic(parentTopic); + board.repositionate(); + } + } + + + // @todo: Esto hace backtraking. Hay que cambiar la implementacion del set position de + // forma tal que no se mande a hacer el update de todos los hijos. + + // Workout center the new topic center... + var refence = this.getReferencePoint(); + var lowerLimit; + if (entries.length > 0) { + var l = 0; + for (l = 0; l < entries.length; l++) { + if ($defined(entries[l])) + break; + } + var topic = entries[l].getTopic(); + var firstNodeHeight = topic.getSize().height; + lowerLimit = refence.y - (height / 2) - (firstNodeHeight / 2) + 1; + } + + var upperLimit = null; + + // Start moving all the elements ... + var newEntries = []; + var order = 0; + for (var i = 0; i < entries.length; i++) { + var e = entries[i]; + if (e && e.getTopic()) { + + var currentTopic = e.getTopic(); + e.setLowerLimit(lowerLimit); + + // Update entry ... + var topicBoard = this._layoutManager.getTopicBoardForTopic(currentTopic); + var topicBoardHeight = topicBoard.getHeight(); + + upperLimit = lowerLimit + topicBoardHeight + mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE; + e.setUpperLimit(upperLimit); + lowerLimit = upperLimit; + + e.setOrder(order); + currentTopic.setOrder(order); + + e.update(); + newEntries[order] = e; + order++; + } + } + this._entries = newEntries; + }, + + removeTopic : function(topic) { + var order = topic.getOrder(); + var entry = this.lookupEntryByOrder(order); + $assert(!entry.isAvailable(), "Illegal state"); + + entry.setTopic(null); + topic.setOrder(null); + this._entries.erase(entry); + + // Repositionate all elements ... + this.repositionate(); + }, + + addTopic : function(order, topic) { + + // If the entry is not available, I must swap the the entries... + var entry = this.lookupEntryByOrder(order); + if (!entry.isAvailable()) { + this.freeEntry(entry); + // Create a dummy entry ... + // Puaj, do something with this... + entry = this.createBoardEntry(-1, 0, order); + this._entries[order] = entry; + } + this._entries[order] = entry; + + // Add to the board ... + entry.setTopic(topic, false); + + // Repositionate all elements ... + this.repositionate(); + }, + + lookupEntryByPosition : function(pos) { + $assert(pos, 'position can not be null'); + + var entries = this._entries; + var result = null; + for (var i = 0; i < entries.length; i++) { + var entry = entries[i]; + if (pos.y < entry.getUpperLimit() && pos.y >= entry.getLowerLimit()) { + result = entry; + } + } + + if (result == null) { + var defaultHeight = this._defaultWidth; + if (entries.length == 0) { + var reference = this.getReferencePoint(); + var yReference = reference.y; + result = this.createBoardEntry(yReference - (defaultHeight / 2), yReference + (defaultHeight / 2), 0); + } else { + var firstEntry = entries[0]; + if (pos.y < firstEntry.getLowerLimit()) { + var upperLimit = firstEntry.getLowerLimit(); + var lowerLimit = upperLimit - defaultHeight; + result = this.createBoardEntry(lowerLimit, upperLimit, 0); + } else { + var entriesLenght = entries.length; + var lastEntry = entries[entriesLenght - 1]; + var lowerLimit = lastEntry.getUpperLimit(); + var upperLimit = lowerLimit + defaultHeight; + result = this.createBoardEntry(lowerLimit, upperLimit, entriesLenght); + } + } + } + + return result; + } +}) + ; +mindplot.FixedDistanceBoard.INTER_TOPIC_DISTANCE = 6; +mindplot.FixedDistanceBoard.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60; + +/* + * 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.BoardEntry = new Class({ + initialize:function(lowerLimit, upperLimit, order) { + if ($defined(lowerLimit) && $defined(upperLimit)) { + $assert(lowerLimit < upperLimit, 'lowerLimit can not be greater that upperLimit'); + } + this._upperLimit = upperLimit; + this._lowerLimit = lowerLimit; + this._order = order; + this._topic = null; + this._xPos = null; + }, + + + getUpperLimit : function() { + return this._upperLimit; + }, + + setXPosition : function(xPosition) { + this._xPos = xPosition; + }, + + workoutEntryYCenter : function() { + return this._lowerLimit + ((this._upperLimit - this._lowerLimit) / 2); + }, + + setUpperLimit : function(value) { + $assert(value, "upper limit can not be null"); + $assert(!isNaN(value), "illegal value"); + this._upperLimit = value; + }, + + isCoordinateIn : function(coord) { + return this._lowerLimit <= coord && coord < this._upperLimit; + }, + + getLowerLimit : function() { + return this._lowerLimit; + }, + + setLowerLimit : function(value) { + $assert(value, "upper limit can not be null"); + $assert(!isNaN(value), "illegal value"); + this._lowerLimit = value; + }, + + setOrder : function(value) { + this._order = value; + }, + + getWidth : function() { + return Math.abs(this._upperLimit - this._lowerLimit); + }, + + + getTopic : function() { + return this._topic; + }, + + + removeTopic : function() { + $assert(!this.isAvailable(), "Entry doesn't have a topic."); + var topic = this.getTopic(); + this.setTopic(null); + topic.setOrder(null); + }, + + + update : function() { + var topic = this.getTopic(); + this.setTopic(topic); + }, + + setTopic : function(topic, updatePosition) { + if (!$defined(updatePosition) || ($defined(updatePosition) && !updatePosition)) { + updatePosition = true; + } + + this._topic = topic; + if ($defined(topic)) { + // Fixed positioning. Only for main topic ... + var position = null; + var topicPosition = topic.getPosition(); + + // Must update position base on the border limits? + if ($defined(this._xPos)) { + position = new core.Point(); + + // Update x position ... + var topicSize = topic.getSize(); + var halfTopicWidh = parseInt(topicSize.width / 2); + halfTopicWidh = (this._xPos > 0) ? halfTopicWidh : -halfTopicWidh; + position.x = this._xPos + halfTopicWidh; + position.y = this.workoutEntryYCenter(); + } else { + + // Central topic + this._height = topic.getSize().height; + var xPos = topicPosition.x; + var yPos = this.workoutEntryYCenter(); + position = new core.Point(xPos, yPos); + } + + // @todo: No esta de mas... + topic.setPosition(position); + topic.setOrder(this._order); + } + else { + this._height = this._defaultWidth; + } + }, + + isAvailable : function() { + return !$defined(this._topic); + }, + + getOrder : function() { + return this._order; + }, + + inspect : function() { + return '(order: ' + this._order + ', lowerLimit:' + this._lowerLimit + ', upperLimit: ' + this._upperLimit + ', available:' + this.isAvailable() + ')'; + } });/* * Copyright [2011] [wisemapping] * @@ -8974,146 +8973,146 @@ mindplot.XMLMindmapSerializerFactory._codeNames = serializer:mindplot.XMLMindmapSerializer_Pela, migrator:mindplot.Beta2PelaMigrator } - ];/* -* 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.PersistanceManager = {}; - -mindplot.PersistanceManager.save = function(mindmap, editorProperties, onSavedHandler,saveHistory) -{ - $assert(mindmap, "mindmap can not be null"); - $assert(editorProperties, "editorProperties can not be null"); - - var mapId = mindmap.getId(); - - var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap(mindmap); - var xmlMap = serializer.toXML(mindmap); - var xmlMapStr = core.Utils.innerXML(xmlMap); - - var pref = JSON.toString(editorProperties); - window.MapEditorService.saveMap(mapId, xmlMapStr, pref,saveHistory, - { - callback:function(response) { - - if (response.msgCode != "OK") - { - monitor.logError("Save could not be completed. Please,try again in a couple of minutes."); - wLogger.error(response.msgDetails); - } else - { - // Execute on success handler ... - if ($defined(onSavedHandler)) - { - onSavedHandler(); - } - } - }, - errorHandler:function(message) { - var monitor = core.Monitor.getInstance(); - monitor.logError("Save could not be completed. Please,try again in a couple of minutes."); - wLogger.error(message); - }, - verb:"POST", - async: false - }); - -}; - -mindplot.PersistanceManager.load = function(mapId) -{ - $assert(mapId, "mapId can not be null"); - - var result = {r:null}; - window.MapEditorService.loadMap(mapId, { - callback:function(response) { - - if (response.msgCode == "OK") - { - // Explorer Hack with local files ... - var xmlContent = response.content; - var domDocument = core.Utils.createDocumentFromText(xmlContent); - var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(domDocument); - var mindmap = serializer.loadFromDom(domDocument); - mindmap.setId(mapId); - - result.r = mindmap; - } else - { - // Handle error message ... - var msg = response.msgDetails; - var monitor = core.Monitor.getInstance(); - monitor.logFatal("We're sorry, an error has occurred and we can't load your map. Please try again in a few minutes."); - wLogger.error(msg); - } - }, - verb:"GET", - async: false, - errorHandler:function(msg) { - var monitor = core.Monitor.getInstance(); - monitor.logFatal("We're sorry, an error has occurred and we can't load your map. Please try again in a few minutes."); - wLogger.error(msg); - } - }); - - return result.r; -}; - - -/* - * 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.EditorProperties = new Class({ - initialize:function() { - this._zoom = 0; - this._position = 0; - }, - - setZoom : function(zoom) { - this._zoom = zoom; - }, - - getZoom : function() { - return this._zoom; - }, - - asProperties : function() { - return "zoom=" + this._zoom + "\n"; - } -}); - - - - + ];/* +* 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.PersistanceManager = {}; + +mindplot.PersistanceManager.save = function(mindmap, editorProperties, onSavedHandler,saveHistory) +{ + $assert(mindmap, "mindmap can not be null"); + $assert(editorProperties, "editorProperties can not be null"); + + var mapId = mindmap.getId(); + + var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap(mindmap); + var xmlMap = serializer.toXML(mindmap); + var xmlMapStr = core.Utils.innerXML(xmlMap); + + var pref = JSON.toString(editorProperties); + window.MapEditorService.saveMap(mapId, xmlMapStr, pref,saveHistory, + { + callback:function(response) { + + if (response.msgCode != "OK") + { + monitor.logError("Save could not be completed. Please,try again in a couple of minutes."); + wLogger.error(response.msgDetails); + } else + { + // Execute on success handler ... + if ($defined(onSavedHandler)) + { + onSavedHandler(); + } + } + }, + errorHandler:function(message) { + var monitor = core.Monitor.getInstance(); + monitor.logError("Save could not be completed. Please,try again in a couple of minutes."); + wLogger.error(message); + }, + verb:"POST", + async: false + }); + +}; + +mindplot.PersistanceManager.load = function(mapId) +{ + $assert(mapId, "mapId can not be null"); + + var result = {r:null}; + window.MapEditorService.loadMap(mapId, { + callback:function(response) { + + if (response.msgCode == "OK") + { + // Explorer Hack with local files ... + var xmlContent = response.content; + var domDocument = core.Utils.createDocumentFromText(xmlContent); + var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(domDocument); + var mindmap = serializer.loadFromDom(domDocument); + mindmap.setId(mapId); + + result.r = mindmap; + } else + { + // Handle error message ... + var msg = response.msgDetails; + var monitor = core.Monitor.getInstance(); + monitor.logFatal("We're sorry, an error has occurred and we can't load your map. Please try again in a few minutes."); + wLogger.error(msg); + } + }, + verb:"GET", + async: false, + errorHandler:function(msg) { + var monitor = core.Monitor.getInstance(); + monitor.logFatal("We're sorry, an error has occurred and we can't load your map. Please try again in a few minutes."); + wLogger.error(msg); + } + }); + + return result.r; +}; + + +/* + * 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.EditorProperties = new Class({ + initialize:function() { + this._zoom = 0; + this._position = 0; + }, + + setZoom : function(zoom) { + this._zoom = zoom; + }, + + getZoom : function() { + return this._zoom; + }, + + asProperties : function() { + return "zoom=" + this._zoom + "\n"; + } +}); + + + + /* * Copyright [2011] [wisemapping] *