diff --git a/core-js/src/main/javascript/Utils.js b/core-js/src/main/javascript/Utils.js index ef7d3bae..c6c369c2 100644 --- a/core-js/src/main/javascript/Utils.js +++ b/core-js/src/main/javascript/Utils.js @@ -59,7 +59,7 @@ objects.extend = function(subClass, baseClass) { }; $assert = function(assert, message) { - if (!assert) { + if (!$defined(assert) || !assert) { var stack; try { null.eval(); diff --git a/mindplot/src/main/javascript/Board.js b/mindplot/src/main/javascript/Board.js index 8423252e..8d86507f 100644 --- a/mindplot/src/main/javascript/Board.js +++ b/mindplot/src/main/javascript/Board.js @@ -66,7 +66,7 @@ mindplot.BidirectionalArray = new Class({ }, get :function(index, sign) { - $assert($defined(index), 'Illegal argument, index must be passed.'); + $assert(index, 'Illegal argument, index must be passed.'); if ($defined(sign)) { $assert(index >= 0, 'Illegal absIndex value'); index = index * sign; @@ -82,14 +82,14 @@ mindplot.BidirectionalArray = new Class({ }, set : function(index, elem) { - $assert($defined(index), 'Illegal index value'); + $assert(index, 'Illegal index value'); var array = (index >= 0) ? this._rightElem : this._leftElem; array[Math.abs(index)] = elem; }, length : function(index) { - $assert($defined(index), 'Illegal index value'); + $assert(index, 'Illegal index value'); return (index >= 0) ? this._rightElem.length : this._leftElem.length; }, diff --git a/mindplot/src/main/javascript/BoardEntry.js b/mindplot/src/main/javascript/BoardEntry.js index 1b15a63f..a9c8f64c 100644 --- a/mindplot/src/main/javascript/BoardEntry.js +++ b/mindplot/src/main/javascript/BoardEntry.js @@ -42,7 +42,7 @@ mindplot.BoardEntry = new Class({ }, setUpperLimit : function(value) { - $assert($defined(value), "upper limit can not be null"); + $assert(value, "upper limit can not be null"); $assert(!isNaN(value), "illegal value"); this._upperLimit = value; }, @@ -56,7 +56,7 @@ mindplot.BoardEntry = new Class({ }, setLowerLimit : function(value) { - $assert($defined(value), "upper limit can not be null"); + $assert(value, "upper limit can not be null"); $assert(!isNaN(value), "illegal value"); this._lowerLimit = value; }, diff --git a/mindplot/src/main/javascript/DragTopic.js b/mindplot/src/main/javascript/DragTopic.js index 4df59e76..820ec4a3 100644 --- a/mindplot/src/main/javascript/DragTopic.js +++ b/mindplot/src/main/javascript/DragTopic.js @@ -18,8 +18,8 @@ mindplot.DragTopic = function(dragShape, draggedNode) { - $assert($defined(dragShape), 'Rect can not be null.'); - $assert($defined(draggedNode), 'draggedNode can not be null.'); + $assert(dragShape, 'Rect can not be null.'); + $assert(draggedNode, 'draggedNode can not be null.'); this._elem2d = dragShape; this._order = null; @@ -68,7 +68,7 @@ mindplot.DragTopic.prototype.disconnect = function(workspace) mindplot.DragTopic.prototype.canBeConnectedTo = function(targetTopic) { - $assert($defined(targetTopic), 'parent can not be null'); + $assert(targetTopic, 'parent can not be null'); var result = true; if (!targetTopic.areChildrenShrinked() && !targetTopic.isCollapsed()) diff --git a/mindplot/src/main/javascript/FixedDistanceBoard.js b/mindplot/src/main/javascript/FixedDistanceBoard.js index 70cb950d..7582ae5b 100644 --- a/mindplot/src/main/javascript/FixedDistanceBoard.js +++ b/mindplot/src/main/javascript/FixedDistanceBoard.js @@ -245,7 +245,7 @@ mindplot.FixedDistanceBoard = new Class({ }, lookupEntryByPosition : function(pos) { - $assert($defined(pos), 'position can not be null'); + $assert(pos, 'position can not be null'); var entries = this._entries; var result = null; diff --git a/mindplot/src/main/javascript/Icon.js b/mindplot/src/main/javascript/Icon.js index f31d9169..0149590b 100644 --- a/mindplot/src/main/javascript/Icon.js +++ b/mindplot/src/main/javascript/Icon.js @@ -18,6 +18,7 @@ mindplot.Icon = new Class({ initialize:function(url) { + $assert(url, 'topic can not be null'); this._image = new web2d.Image(); this._image.setHref(url); this._image.setSize(12, 12); diff --git a/mindplot/src/main/javascript/IconModel.js b/mindplot/src/main/javascript/IconModel.js index 7d633655..b508885c 100644 --- a/mindplot/src/main/javascript/IconModel.js +++ b/mindplot/src/main/javascript/IconModel.js @@ -1,64 +1,58 @@ /* -* 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. -*/ + * 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.IconModel = function(iconType, topic) -{ - $assert(iconType, 'Icon id can not be null'); - $assert(topic, 'topic can not be null'); - this._iconType = iconType; - this._id = mindplot.IconModel._nextUUID(); - this._topic = topic; -}; +mindplot.IconModel = new Class({ + initialize:function(iconType, topic) { + $assert(iconType, 'Icon id can not be null'); + $assert(topic, 'topic can not be null'); -mindplot.IconModel.prototype.getId = function() -{ - return this._id; -}; + this._iconType = iconType; + this._id = mindplot.IconModel._nextUUID(); + this._topic = topic; + }, -mindplot.IconModel.prototype.getIconType = function() -{ - return this._iconType; -}; + getId : function() { + return this._id; + }, + + getIconType : function() { + return this._iconType; + }, -mindplot.IconModel.prototype.setIconType = function(iconType) -{ - this._iconType = iconType; -}; + setIconType : function(iconType) { + this._iconType = iconType; + }, -mindplot.IconModel.prototype.getTopic = function() -{ - return this._topic; -}; + getTopic : function() { + return this._topic; + }, -mindplot.IconModel.prototype.isIconModel = function() -{ - return true; -}; + isIconModel : function() { + return true; + }}); /** * @todo: This method must be implemented. */ -mindplot.IconModel._nextUUID = function() -{ - if (!$defined(this._uuid)) - { +mindplot.IconModel._nextUUID = function() { + if (!$defined(this._uuid)) { this._uuid = 0; } diff --git a/mindplot/src/main/javascript/ImageIcon.js b/mindplot/src/main/javascript/ImageIcon.js index af5a0fee..695f924e 100644 --- a/mindplot/src/main/javascript/ImageIcon.js +++ b/mindplot/src/main/javascript/ImageIcon.js @@ -1,155 +1,170 @@ /* -* 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. -*/ + * 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.ImageIcon = function(iconModel, topic, designer) { - - $assert(iconModel, 'iconModel can not be null'); - $assert(topic, 'topic can not be null'); - $assert(designer, 'designer can not be null'); - this._topic = topic; - this._iconModel = iconModel; - this._designer = designer; - - // Build graph image representation ... - var iconType = iconModel.getIconType(); - var imgUrl = this._getImageUrl(iconType); - mindplot.Icon.call(this, imgUrl); - - //Remove - var divContainer = designer.getWorkSpace().getScreenManager().getContainer(); - var tip = mindplot.Tip.getInstance(divContainer); - - var container = new Element('div'); - var removeImage = new Element('img'); - removeImage.src = "../images/bin.png"; - removeImage.inject(container); - - if (!$defined(designer._viewMode)|| ($defined(designer._viewMode) && !designer._viewMode)) +mindplot.ImageIcon = new Class( { + Extends:mindplot.Icon, + initialize:function(iconModel, topic, designer) { + $assert(iconModel, 'iconModel can not be null'); + $assert(topic, 'topic can not be null'); + $assert(designer, 'designer can not be null'); + this._topic = topic; + this._iconModel = iconModel; + this._designer = designer; - removeImage.addEvent('click', function(event) { - var actionRunner = designer._actionRunner; - var command = new mindplot.commands.RemoveIconFromTopicCommand(this._topic.getId(), iconModel); - actionRunner.execute(command); - tip.forceClose(); - }.bindWithEvent(this)); - - //Icon - var image = this.getImage(); - image.addEventListener('click', function(event) { + // Build graph image representation ... var iconType = iconModel.getIconType(); - var newIconType = this._getNextFamilyIconId(iconType); - iconModel.setIconType(newIconType); + var imgUrl = this._getImageUrl(iconType); - var imgUrl = this._getImageUrl(newIconType); - this._image.setHref(imgUrl); + this.parent(imgUrl); - // // @Todo: Support revert of change icon ... - // var actionRunner = designer._actionRunner; - // var command = new mindplot.commands.ChangeIconFromTopicCommand(this._topic.getId()); - // this._actionRunner.execute(command); + //Remove + var divContainer = designer.getWorkSpace().getScreenManager().getContainer(); + var tip = mindplot.Tip.getInstance(divContainer); + + var container = new Element('div'); + var removeImage = new Element('img'); + removeImage.src = "../images/bin.png"; + removeImage.inject(container); + + if (!$defined(designer._viewMode) || ($defined(designer._viewMode) && !designer._viewMode)) { + + removeImage.addEvent('click', function(event) { + var actionRunner = designer._actionRunner; + var command = new mindplot.commands.RemoveIconFromTopicCommand(this._topic.getId(), iconModel); + actionRunner.execute(command); + tip.forceClose(); + }.bindWithEvent(this)); + + //Icon + var image = this.getImage(); + image.addEventListener('click', function(event) { + var iconType = iconModel.getIconType(); + var newIconType = this._getNextFamilyIconId(iconType); + iconModel.setIconType(newIconType); + + var imgUrl = this._getImageUrl(newIconType); + this._image.setHref(imgUrl); + + // // @Todo: Support revert of change icon ... + // var actionRunner = designer._actionRunner; + // var command = new mindplot.commands.ChangeIconFromTopicCommand(this._topic.getId()); + // this._actionRunner.execute(command); - }.bindWithEvent(this)); + }.bindWithEvent(this)); - var imageIcon = this; - image.addEventListener('mouseover', function(event) { - tip.open(event, container, imageIcon); - }); - image.addEventListener('mouseout', function(event) { - tip.close(event); - }); - image.addEventListener('mousemove', function(event) { - tip.updatePosition(event); - }); + var imageIcon = this; + image.addEventListener('mouseover', function(event) { + tip.open(event, container, imageIcon); + }); + image.addEventListener('mouseout', function(event) { + tip.close(event); + }); + image.addEventListener('mousemove', function(event) { + tip.updatePosition(event); + }); - } -}; - -objects.extend(mindplot.ImageIcon, mindplot.Icon); - -mindplot.ImageIcon.prototype.initialize = function() { - -}; - -mindplot.ImageIcon.prototype._getImageUrl = function(iconId) { - return "../icons/"+iconId+".png"; -}; - -mindplot.ImageIcon.prototype.getModel = function() { - return this._iconModel; -}; - - -mindplot.ImageIcon.prototype._getNextFamilyIconId = function(iconId) { - - var familyIcons = this._getFamilyIcons(iconId); - $assert(familyIcons != null, "Family Icon not found!"); - - var result = null; - for (var i = 0; i < familyIcons.length && result == null; i++) - { - if (familyIcons[i] == iconId) { - var nextIconId; - //Is last one? - if (i == (familyIcons.length - 1)) { - result = familyIcons[0]; - } else { - result = familyIcons[i + 1]; } - break; + }, + + _getImageUrl : function(iconId) { + return "../icons/" + iconId + ".png"; + }, + + getModel : function() { + return this._iconModel; + }, + + _getNextFamilyIconId : function(iconId) { + + var familyIcons = this._getFamilyIcons(iconId); + $assert(familyIcons != null, "Family Icon not found!"); + + var result = null; + for (var i = 0; i < familyIcons.length && result == null; i++) { + if (familyIcons[i] == iconId) { + var nextIconId; + //Is last one? + if (i == (familyIcons.length - 1)) { + result = familyIcons[0]; + } else { + result = familyIcons[i + 1]; + } + break; + } + } + + return result; + }, + + _getFamilyIcons : function(iconId) { + $assert(iconId != null, "id must not be null"); + $assert(iconId.indexOf("_") != -1, "Invalid icon id (it must contain '_')"); + + var result = null; + for (var i = 0; i < mindplot.ImageIcon.prototype.ICON_FAMILIES.length; i++) { + var family = mindplot.ImageIcon.prototype.ICON_FAMILIES[i]; + var iconFamilyId = iconId.substr(0, iconId.indexOf("_")); + + if (family.id == iconFamilyId) { + result = family.icons; + break; + } + } + return result; + }, + + getId : function() { + return this._iconType; + }, + + getUiId : function() { + return this._uiId; } } +); - return result; -}; -mindplot.ImageIcon.prototype._getFamilyIcons = function(iconId) { - $assert(iconId != null, "id must not be null"); - $assert(iconId.indexOf("_") != -1, "Invalid icon id (it must contain '_')"); - - var result = null; - for (var i = 0; i < mindplot.ImageIcon.prototype.ICON_FAMILIES.length; i++) - { - var family = mindplot.ImageIcon.prototype.ICON_FAMILIES[i]; - var iconFamilyId = iconId.substr(0, iconId.indexOf("_")); - - if (family.id == iconFamilyId) { - result = family.icons; - break; - } - } - return result; -}; - -mindplot.ImageIcon.prototype.getId = function() -{ - return this._iconType; -}; - -mindplot.ImageIcon.prototype.getUiId = function() -{ - return this._uiId; -}; - - - -mindplot.ImageIcon.prototype.ICON_FAMILIES = [{"id": "face", "icons" : ["face_plain","face_sad","face_crying","face_smile","face_surprise","face_wink"]},{"id": "funy", "icons" : ["funy_angel","funy_devilish","funy_glasses","funy_grin","funy_kiss","funy_monkey"]},{"id": "conn", "icons" : ["conn_connect","conn_disconnect"]},{"id": "sport", "icons" : ["sport_basketball","sport_football","sport_golf","sport_raquet","sport_shuttlecock","sport_soccer","sport_tennis"]},{"id": "bulb", "icons" : ["bulb_light_on","bulb_light_off"]},{"id": "thumb", "icons" : ["thumb_thumb_up","thumb_thumb_down"]},{"id": "tick", "icons" : ["tick_tick","tick_cross"]},{"id": "onoff", "icons" : ["onoff_clock","onoff_clock_red","onoff_add","onoff_delete","onoff_status_offline","onoff_status_online"]},{"id": "money", "icons" : ["money_money","money_dollar","money_euro","money_pound","money_yen","money_coins","money_ruby"]},{"id": "time", "icons" : ["time_calendar","time_clock","time_hourglass"]},{"id": "chart", "icons" : ["chart_bar","chart_line","chart_curve","chart_pie","chart_organisation"]},{"id": "sign", "icons" : ["sign_warning","sign_info","sign_stop","sign_help","sign_cancel"]},{"id": "hard", "icons" : ["hard_cd","hard_computer","hard_controller","hard_driver_disk","hard_ipod","hard_keyboard","hard_mouse","hard_printer"]},{"id": "soft", "icons" : ["soft_bug","soft_cursor","soft_database_table","soft_database","soft_feed","soft_folder_explore","soft_rss","soft_penguin"]},{"id": "arrow", "icons" : ["arrow_up","arrow_down","arrow_left","arrow_right"]},{"id": "arrowc", "icons" : ["arrowc_rotate_anticlockwise","arrowc_rotate_clockwise","arrowc_turn_left","arrowc_turn_right"]},{"id": "people", "icons" : ["people_group","people_male1","people_male2","people_female1","people_female2"]},{"id": "mail", "icons" : ["mail_envelop","mail_mailbox","mail_edit","mail_list"]},{"id": "flag", "icons" : ["flag_blue","flag_green","flag_orange","flag_pink","flag_purple","flag_yellow"]},{"id": "bullet", "icons" : ["bullet_black","bullet_blue","bullet_green","bullet_orange","bullet_red","bullet_pink","bullet_purple"]},{"id": "tag", "icons" : ["tag_blue","tag_green","tag_orange","tag_red","tag_pink","tag_yellow"]},{"id": "object", "icons" : ["object_bell","object_clanbomber","object_key","object_pencil","object_phone","object_magnifier","object_clip","object_music","object_star","object_wizard","object_house","object_cake","object_camera","object_palette","object_rainbow"]}] +mindplot.ImageIcon.prototype.ICON_FAMILIES = [ + {"id": "face", "icons" : ["face_plain","face_sad","face_crying","face_smile","face_surprise","face_wink"]}, + {"id": "funy", "icons" : ["funy_angel","funy_devilish","funy_glasses","funy_grin","funy_kiss","funy_monkey"]}, + {"id": "conn", "icons" : ["conn_connect","conn_disconnect"]}, + {"id": "sport", "icons" : ["sport_basketball","sport_football","sport_golf","sport_raquet","sport_shuttlecock","sport_soccer","sport_tennis"]}, + {"id": "bulb", "icons" : ["bulb_light_on","bulb_light_off"]}, + {"id": "thumb", "icons" : ["thumb_thumb_up","thumb_thumb_down"]}, + {"id": "tick", "icons" : ["tick_tick","tick_cross"]}, + {"id": "onoff", "icons" : ["onoff_clock","onoff_clock_red","onoff_add","onoff_delete","onoff_status_offline","onoff_status_online"]}, + {"id": "money", "icons" : ["money_money","money_dollar","money_euro","money_pound","money_yen","money_coins","money_ruby"]}, + {"id": "time", "icons" : ["time_calendar","time_clock","time_hourglass"]}, + {"id": "chart", "icons" : ["chart_bar","chart_line","chart_curve","chart_pie","chart_organisation"]}, + {"id": "sign", "icons" : ["sign_warning","sign_info","sign_stop","sign_help","sign_cancel"]}, + {"id": "hard", "icons" : ["hard_cd","hard_computer","hard_controller","hard_driver_disk","hard_ipod","hard_keyboard","hard_mouse","hard_printer"]}, + {"id": "soft", "icons" : ["soft_bug","soft_cursor","soft_database_table","soft_database","soft_feed","soft_folder_explore","soft_rss","soft_penguin"]}, + {"id": "arrow", "icons" : ["arrow_up","arrow_down","arrow_left","arrow_right"]}, + {"id": "arrowc", "icons" : ["arrowc_rotate_anticlockwise","arrowc_rotate_clockwise","arrowc_turn_left","arrowc_turn_right"]}, + {"id": "people", "icons" : ["people_group","people_male1","people_male2","people_female1","people_female2"]}, + {"id": "mail", "icons" : ["mail_envelop","mail_mailbox","mail_edit","mail_list"]}, + {"id": "flag", "icons" : ["flag_blue","flag_green","flag_orange","flag_pink","flag_purple","flag_yellow"]}, + {"id": "bullet", "icons" : ["bullet_black","bullet_blue","bullet_green","bullet_orange","bullet_red","bullet_pink","bullet_purple"]}, + {"id": "tag", "icons" : ["tag_blue","tag_green","tag_orange","tag_red","tag_pink","tag_yellow"]}, + {"id": "object", "icons" : ["object_bell","object_clanbomber","object_key","object_pencil","object_phone","object_magnifier","object_clip","object_music","object_star","object_wizard","object_house","object_cake","object_camera","object_palette","object_rainbow"]} +] diff --git a/mindplot/src/main/javascript/Issue.txt b/mindplot/src/main/javascript/Issue.txt index 155b8213..aeb0ea74 100644 --- a/mindplot/src/main/javascript/Issue.txt +++ b/mindplot/src/main/javascript/Issue.txt @@ -17,3 +17,9 @@ Later nodos en vez de borrarlos. * Menu contextual para agregar nodos. * Es necesario manejar para los central topic to main topic correctamente el concepto de height. + + + +From: RelationshipLine +- Falta topic... +XMLMindmapSerializer_Beta \ No newline at end of file diff --git a/mindplot/src/main/javascript/LinkIcon.js b/mindplot/src/main/javascript/LinkIcon.js index 76c22ccd..3d6c38d2 100644 --- a/mindplot/src/main/javascript/LinkIcon.js +++ b/mindplot/src/main/javascript/LinkIcon.js @@ -1,160 +1,161 @@ /* -* 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. -*/ + * 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.LinkIcon = function(urlModel, topic, designer) { - var divContainer=designer.getWorkSpace().getScreenManager().getContainer(); - var bubbleTip = mindplot.BubbleTip.getInstance(divContainer); - mindplot.Icon.call(this, mindplot.LinkIcon.IMAGE_URL); - this._linkModel = urlModel; - this._topic = topic; - this._designer = designer; - var image = this.getImage(); - var imgContainer = new Element('div').setStyles({textAlign:'center', cursor:'pointer'}); - this._img = new Element('img'); - var url = urlModel.getUrl(); - this._img.src = 'http://open.thumbshots.org/image.pxf?url=' + url; +mindplot.LinkIcon = new Class({ - if (url.indexOf('http:') == -1) - { - url = 'http://' + url; + Extends:mindplot.Icon, + initialize:function(urlModel, topic, designer) { + $assert(urlModel, "urlModel can not be null"); + $assert(designer, "designer can not be null"); + $assert(topic, "topic can not be null"); + + this.parent(mindplot.LinkIcon.IMAGE_URL); + + var divContainer = designer.getWorkSpace().getScreenManager().getContainer(); + var bubbleTip = mindplot.BubbleTip.getInstance(divContainer); + + this._linkModel = urlModel; + this._topic = topic; + this._designer = designer; + var image = this.getImage(); + var imgContainer = new Element('div').setStyles({textAlign:'center', cursor:'pointer'}); + this._img = new Element('img'); + var url = urlModel.getUrl(); + this._img.src = 'http://open.thumbshots.org/image.pxf?url=' + url; + + if (url.indexOf('http:') == -1) { + url = 'http://' + url; + } + this._img.alt = url; + this._url = url; + var openWindow = function() { + var wOpen; + var sOptions; + + sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes'; + sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString(); + sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString(); + sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0'; + var url = this._img.alt; + wOpen = window.open(url, "link", "width=100px, height=100px"); + wOpen.focus(); + wOpen.moveTo(0, 0); + wOpen.resizeTo(screen.availWidth, screen.availHeight); + }; + + this._img.addEvent('click', openWindow.bindWithEvent(this)); + this._img.inject(imgContainer); + + var attribution = new Element('div').setStyles({fontSize:10, textAlign:"center"}); + attribution.innerHTML = "About Thumbshots thumbnails"; + + var container = new Element('div'); + var element = new Element('div').setStyles({borderBottom:'1px solid #e5e5e5'}); + + var title = new Element('div').setStyles({fontSize:12, textAlign:'center'}); + this._link = new Element('span'); + this._link.href = url; + this._link.innerHTML = url; + this._link.setStyle("text-decoration", "underline"); + this._link.setStyle("cursor", "pointer"); + this._link.inject(title); + this._link.addEvent('click', openWindow.bindWithEvent(this)); + title.inject(element); + + imgContainer.inject(element); + attribution.inject(element); + element.inject(container); + + if (!$defined(designer._viewMode) || ($defined(designer._viewMode) && !designer._viewMode)) { + var buttonContainer = new Element('div').setStyles({paddingTop:5, textAlign:'center'}); + var editBtn = new Element('input', {type:'button', 'class':'btn-primary', value:'Edit'}).addClass('button').inject(buttonContainer); + var removeBtn = new Element('input', {type:'button', value:'Remove','class':'btn-primary'}).addClass('button').inject(buttonContainer); + + editBtn.setStyle("margin-right", "3px"); + removeBtn.setStyle("margin-left", "3px"); + + removeBtn.addEvent('click', function(event) { + var command = new mindplot.commands.RemoveLinkFromTopicCommand(this._topic.getId()); + designer._actionRunner.execute(command); + bubbleTip.forceClose(); + }.bindWithEvent(this)); + + var okButtonId = 'okLinkButtonId'; + editBtn.addEvent('click', function(event) { + var topic = this._topic; + var designer = this._designer; + var link = this; + var okFunction = function(e) { + var result = false; + var url = urlInput.value; + if ("" != url.trim()) { + link._img.src = 'http://open.thumbshots.org/image.pxf?url=' + url; + link._img.alt = url; + link._link.href = url; + link._link.innerHTML = url; + this._linkModel.setUrl(url); + result = true; + } + return result; + }; + var msg = new Element('div'); + var urlText = new Element('div').inject(msg); + urlText.innerHTML = "URL:"; + + var formElem = new Element('form', {'action': 'none', 'id':'linkFormId'}); + var urlInput = new Element('input', {'type': 'text', 'size':30,'value':url}); + urlInput.inject(formElem); + formElem.inject(msg); + + formElem.addEvent('submit', function(e) { + $(okButtonId).fireEvent('click', e); + e = new Event(e); + e.stop(); + }); + + + var dialog = mindplot.LinkIcon.buildDialog(designer, okFunction, okButtonId); + dialog.adopt(msg).show(); + + }.bindWithEvent(this)); + buttonContainer.inject(container); + } + + var linkIcon = this; + image.addEventListener('mouseover', function(event) { + bubbleTip.open(event, container, linkIcon); + }); + image.addEventListener('mousemove', function(event) { + bubbleTip.updatePosition(event); + }); + image.addEventListener('mouseout', function(event) { + bubbleTip.close(event); + }); + }, + + getUrl : function() { + return this._url; + }, + + getModel : function() { + return this._linkModel; } - this._img.alt = url; - this._url=url; - var openWindow = function() { - var wOpen; - var sOptions; - - sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes'; - sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString(); - sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString(); - sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0'; - var url = this._img.alt; - wOpen = window.open(url, "link", "width=100px, height=100px"); - wOpen.focus(); - wOpen.moveTo(0, 0); - wOpen.resizeTo(screen.availWidth, screen.availHeight); - }; - this._img.addEvent('click', openWindow.bindWithEvent(this)); - this._img.inject(imgContainer); - - var attribution = new Element('div').setStyles({fontSize:10, textAlign:"center"}); - attribution.innerHTML = "About Thumbshots thumbnails"; - - var container = new Element('div'); - var element = new Element('div').setStyles({borderBottom:'1px solid #e5e5e5'}); - - var title = new Element('div').setStyles({fontSize:12, textAlign:'center'}); - this._link = new Element('span'); - this._link.href = url; - this._link.innerHTML = url; - this._link.setStyle("text-decoration", "underline"); - this._link.setStyle("cursor", "pointer"); - this._link.inject(title); - this._link.addEvent('click', openWindow.bindWithEvent(this)); - title.inject(element); - - imgContainer.inject(element); - attribution.inject(element); - element.inject(container); - - if(!$defined(designer._viewMode)|| ($defined(designer._viewMode) && !designer._viewMode)){ - var buttonContainer = new Element('div').setStyles({paddingTop:5, textAlign:'center'}); - var editBtn = new Element('input', {type:'button', 'class':'btn-primary', value:'Edit','class':'btn-primary'}).addClass('button').inject(buttonContainer); - var removeBtn = new Element('input', {type:'button', value:'Remove','class':'btn-primary'}).addClass('button').inject(buttonContainer); - - editBtn.setStyle("margin-right", "3px"); - removeBtn.setStyle("margin-left", "3px"); - - removeBtn.addEvent('click', function(event) { - var command = new mindplot.commands.RemoveLinkFromTopicCommand(this._topic.getId()); - designer._actionRunner.execute(command); - bubbleTip.forceClose(); - }.bindWithEvent(this)); - - var okButtonId = 'okLinkButtonId' - editBtn.addEvent('click', function(event) { - var topic = this._topic; - var designer = this._designer; - var link = this; - var okFunction = function(e) { - var result = false; - var url = urlInput.value; - if ("" != url.trim()) - { - link._img.src = 'http://open.thumbshots.org/image.pxf?url=' + url; - link._img.alt = url; - link._link.href = url; - link._link.innerHTML = url; - this._linkModel.setUrl(url); - result = true; - } - return result; - }; - var msg = new Element('div'); - var urlText = new Element('div').inject(msg); - urlText.innerHTML = "URL:" - - var formElem = new Element('form', {'action': 'none', 'id':'linkFormId'}); - var urlInput = new Element('input', {'type': 'text', 'size':30,'value':url}); - urlInput.inject(formElem); - formElem.inject(msg) - - formElem.addEvent('submit', function(e) - { - $(okButtonId).fireEvent('click', e); - e = new Event(e); - e.stop(); - }); - - - var dialog = mindplot.LinkIcon.buildDialog(designer, okFunction, okButtonId); - dialog.adopt(msg).show(); - - }.bindWithEvent(this)); - buttonContainer.inject(container); - } - - - var linkIcon = this; - image.addEventListener('mouseover', function(event) { - bubbleTip.open(event, container, linkIcon); - }); - image.addEventListener('mousemove', function(event) { - bubbleTip.updatePosition(event); - }); - image.addEventListener('mouseout', function(event) { - bubbleTip.close(event); - }); -}; - -objects.extend(mindplot.LinkIcon, mindplot.Icon); - -mindplot.LinkIcon.prototype.initialize = function() { - -}; - -mindplot.LinkIcon.prototype.getUrl=function(){ - return this._url; -}; - -mindplot.LinkIcon.prototype.getModel=function(){ - return this._linkModel; -}; +}); mindplot.LinkIcon.buildDialog = function(designer, okFunction, okButtonId) { var windoo = new Windoo({ @@ -166,18 +167,17 @@ mindplot.LinkIcon.buildDialog = function(designer, okFunction, okButtonId) { height:130 }); - var cancel = new Element('input', {'type': 'button', 'class':'btn-primary', 'value': 'Cancel','class':'btn-primary'}).setStyle('margin-right', "5px"); + var cancel = new Element('input', {'type': 'button', 'class':'btn-primary', 'value': 'Cancel'}).setStyle('margin-right', "5px"); cancel.setStyle('margin-left', "5px"); cancel.addEvent('click', function(event) { $(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer)); windoo.close(); }.bindWithEvent(this)); - var ok = new Element('input', {'type': 'button', 'class':'btn-primary','value': 'Ok','class':'btn-primary','id':okButtonId}).setStyle('marginRight', 10); + var ok = new Element('input', {'type': 'button', 'class':'btn-primary','value': 'Ok','id':okButtonId}).setStyle('marginRight', 10); ok.addEvent('click', function(event) { var couldBeUpdated = okFunction.attempt(); - if (couldBeUpdated) - { + if (couldBeUpdated) { $(document).addEvent('keydown', designer.keyEventHandler.bindWithEvent(designer)); windoo.close(); } diff --git a/mindplot/src/main/javascript/LinkModel.js b/mindplot/src/main/javascript/LinkModel.js index 8a83cec3..54b15691 100644 --- a/mindplot/src/main/javascript/LinkModel.js +++ b/mindplot/src/main/javascript/LinkModel.js @@ -1,44 +1,44 @@ /* -* 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. -*/ + * 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.LinkModel = function(url, topic) -{ - $assert(url, 'link url can not be null'); - $assert(topic, 'mindmap can not be null'); - this._url = url; - this._topic = topic; -}; +mindplot.LinkModel = new Class({ + initialize : function(url, topic) { + $assert(url, 'url can not be null'); + $assert(topic, 'mindmap can not be null'); -mindplot.LinkModel.prototype.getUrl = function() -{ - return this._url; -}; + this._url = url; + this._topic = topic; + }, -mindplot.LinkModel.prototype.setUrl = function(url){ - this._url = url; -} + getUrl : function() { + return this._url; + }, -mindplot.LinkModel.prototype.getTopic = function() -{ - return this._topic; -}; + setUrl : function(url) { + $assert(url, 'url can not be null'); + this._url = url; + }, -mindplot.LinkModel.prototype.isLinkModel = function() -{ - return true; -}; \ No newline at end of file + getTopic : function() { + return this._topic; + }, + + isLinkModel : function() { + return true; + } +}); \ No newline at end of file diff --git a/mindplot/src/main/javascript/MainTopicBoard.js b/mindplot/src/main/javascript/MainTopicBoard.js index 16268849..e30feaf4 100644 --- a/mindplot/src/main/javascript/MainTopicBoard.js +++ b/mindplot/src/main/javascript/MainTopicBoard.js @@ -89,7 +89,7 @@ mindplot.MainTopicBoard = new Class({ addBranch : function(topic) { var order = topic.getOrder(); - $assert($defined(order), "Order must be defined"); + $assert(order, "Order must be defined"); // If the entry is not available, I must swap the the entries... var board = this._getBoard(); diff --git a/mindplot/src/main/javascript/Mindmap.js b/mindplot/src/main/javascript/Mindmap.js index f1bdbfdd..2172f663 100644 --- a/mindplot/src/main/javascript/Mindmap.js +++ b/mindplot/src/main/javascript/Mindmap.js @@ -41,7 +41,6 @@ mindplot.Mindmap = new Class({ this._iconType = id; }, - getVersion : function() { return this._version; }, diff --git a/mindplot/src/main/javascript/MindmapDesigner.js b/mindplot/src/main/javascript/MindmapDesigner.js index 81aa0149..be751562 100644 --- a/mindplot/src/main/javascript/MindmapDesigner.js +++ b/mindplot/src/main/javascript/MindmapDesigner.js @@ -1,1344 +1,1175 @@ /* -* 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. -*/ + * 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.MindmapDesigner = function(profile, divElement) -{ - $assert($defined(profile.zoom), "zoom must be defined"); +mindplot.MindmapDesigner = new Class({ + initialize: function(profile, divElement) { + $assert(profile, "profile must be defined"); + $assert(profile.zoom, "zoom must be defined"); + $assert(divElement, "divElement must be defined"); - // Undo manager ... - this._actionRunner = new mindplot.DesignerActionRunner(this); - mindplot.DesignerActionRunner.setInstance(this._actionRunner); + // Undo manager ... + this._actionRunner = new mindplot.DesignerActionRunner(this); + mindplot.DesignerActionRunner.setInstance(this._actionRunner); - // Initial Zoom - this._zoom = profile.zoom; - this._viewMode = profile.viewMode; + // Initial Zoom + this._zoom = profile.zoom; + this._viewMode = profile.viewMode; - // Init Screen manager.. - var screenManager = new mindplot.ScreenManager(profile.width, profile.height, divElement); + // Init Screen manager.. + var screenManager = new mindplot.ScreenManager(profile.width, profile.height, divElement); - var workspace = new mindplot.Workspace(profile, screenManager, this._zoom); - this._workspace = workspace; + this._workspace = new mindplot.Workspace(profile, screenManager, this._zoom); - //create editor - var editorClass = mindplot.TextEditorFactory.getTextEditorFromName(mindplot.EditorOptions.textEditor); - this._editor = new editorClass(this, this._actionRunner); + //create editor + var editorClass = mindplot.TextEditorFactory.getTextEditorFromName(mindplot.EditorOptions.textEditor); + this._editor = new editorClass(this, this._actionRunner); - // Init layout managers ... - this._topics = []; + // Init layout managers ... + this._topics = []; // var layoutManagerClass = mindplot.layoutManagers.LayoutManagerFactory.getManagerByName(mindplot.EditorOptions.LayoutManager); // this._layoutManager = new layoutManagerClass(this); - this._layoutManager = new mindplot.layoutManagers.OriginalLayoutManager(this); + this._layoutManager = new mindplot.layoutManagers.OriginalLayoutManager(this); - // Register handlers.. - this._registerEvents(); + // Register handlers.. + this._registerEvents(); - this._relationships={}; + this._relationships = {}; - this._events = {}; -}; + this._events = {}; + }, -mindplot.MindmapDesigner.prototype._getTopics = function() -{ - return this._topics; -}; + _getTopics : function() { + return this._topics; + }, -mindplot.MindmapDesigner.prototype.getCentralTopic = function() -{ - var topics = this._getTopics(); - return topics[0]; -}; + getCentralTopic : function() { + var topics = this._getTopics(); + return topics[0]; + }, -mindplot.MindmapDesigner.prototype.addEventListener = function(eventType, listener) -{ + addEventListener : function(eventType, listener) { - this._events[eventType] = listener; + this._events[eventType] = listener; -} + }, -mindplot.MindmapDesigner.prototype._fireEvent = function(eventType, event) -{ - var listener = this._events[eventType]; - if (listener != null) - { - listener(event); - } -} - -mindplot.MindmapDesigner.prototype._registerEvents = function() -{ - var mindmapDesigner = this; - var workspace = this._workspace; - var screenManager = workspace.getScreenManager(); - - if (!$defined(this._viewMode) || ($defined(this._viewMode) && !this._viewMode)) - { - // Initialize workspace event listeners. - // Create nodes on double click... - screenManager.addEventListener('click', function(event) - { - if(workspace.isWorkspaceEventsEnabled()){ - var t = mindmapDesigner.getEditor().isVisible(); - mindmapDesigner.getEditor().lostFocus(); - // @todo: Puaj hack... - mindmapDesigner._cleanScreen(); + _fireEvent : function(eventType, event) { + var listener = this._events[eventType]; + if (listener != null) { + listener(event); } - }); + }, - screenManager.addEventListener('dblclick', function(event) - { - if(workspace.isWorkspaceEventsEnabled()){ - mindmapDesigner.getEditor().lostFocus(); - // Get mouse position - var pos = screenManager.getWorkspaceMousePosition(event); + _registerEvents : function() { + var mindmapDesigner = this; + var workspace = this._workspace; + var screenManager = workspace.getScreenManager(); - // Create a new topic model ... - var mindmap = mindmapDesigner.getMindmap(); - var model = mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE); - model.setPosition(pos.x, pos.y); + if (!$defined(this._viewMode) || ($defined(this._viewMode) && !this._viewMode)) { + // Initialize workspace event listeners. + // Create nodes on double click... + screenManager.addEventListener('click', function(event) { + if (workspace.isWorkspaceEventsEnabled()) { + var t = mindmapDesigner.getEditor().isVisible(); + mindmapDesigner.getEditor().lostFocus(); + // @todo: Puaj hack... + mindmapDesigner._cleanScreen(); + } + }); - // Get central topic ... - var centralTopic = mindmapDesigner.getCentralTopic(); - var centralTopicId = centralTopic.getId(); + screenManager.addEventListener('dblclick', function(event) { + if (workspace.isWorkspaceEventsEnabled()) { + mindmapDesigner.getEditor().lostFocus(); + // Get mouse position + var pos = screenManager.getWorkspaceMousePosition(event); + + // Create a new topic model ... + var mindmap = mindmapDesigner.getMindmap(); + var model = mindmap.createNode(mindplot.NodeModel.MAIN_TOPIC_TYPE); + model.setPosition(pos.x, pos.y); + + // Get central topic ... + var centralTopic = mindmapDesigner.getCentralTopic(); + var centralTopicId = centralTopic.getId(); + + // Execute action ... + var command = new mindplot.commands.AddTopicCommand(model, centralTopicId, true); + this._actionRunner.execute(command); + } + }.bind(this)); + } + }, + + _buildNodeGraph : function(model) { + var workspace = this._workspace; + + // Create node graph ... + var topic = mindplot.NodeGraph.create(model); + + this._layoutManager.addHelpers(topic); + + // Append it to the workspace ... + var topics = this._topics; + topics.push(topic); + + // Add Topic events ... + this._layoutManager.registerListenersOnNode(topic); + + // Connect Topic ... + var isConnected = model.isConnected(); + if (isConnected) { + // Improve this ... + var targetTopicModel = model.getParent(); + var targetTopicId = targetTopicModel.getId(); + var targetTopic = null; + + for (var i = 0; i < topics.length; i++) { + var t = topics[i]; + if (t.getModel() == targetTopicModel) { + targetTopic = t; + // Disconnect the node. It will be connected again later ... + model.disconnect(); + break; + } + } + $assert(targetTopic, "Could not find a topic to connect"); + topic.connectTo(targetTopic, workspace); + } + + return topic; + }, + + onObjectFocusEvent : function(currentObject, event) { + this.getEditor().lostFocus(); + var selectableObjects = this.getSelectedObjects(); + // Disable all nodes on focus but not the current if Ctrl key isn't being pressed + if (!$defined(event) || event.ctrlKey == false) { + for (var i = 0; i < selectableObjects.length; i++) { + var selectableObject = selectableObjects[i]; + if (selectableObject.isOnFocus() && selectableObject != currentObject) { + selectableObject.setOnFocus(false); + } + } + } + }, + + zoomOut : function() { + var scale = this._zoom * 1.2; + if (scale <= 4) { + this._zoom = scale; + this._workspace.setZoom(this._zoom); + } + else { + core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?'); + } + + }, + + zoomIn : function() { + var scale = this._zoom / 1.2; + if (scale >= 0.3) { + this._zoom = scale; + this._workspace.setZoom(this._zoom); + } + else { + core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?'); + } + }, + + createChildForSelectedNode : function() { + + var nodes = this._getSelectedNodes(); + if (nodes.length <= 0) { + // If there are more than one node selected, + core.Monitor.getInstance().logMessage('Could not create a topic. Only one node must be selected.'); + return; + + } + if (nodes.length > 1) { + + // If there are more than one node selected, + core.Monitor.getInstance().logMessage('Could not create a topic. One topic must be selected.'); + return; + } + + // Add new node ... + var centalTopic = nodes[0]; + var parentTopicId = centalTopic.getId(); + var childModel = centalTopic.createChildModel(this._layoutManager.needsPrepositioning()); + + var command = new mindplot.commands.AddTopicCommand(childModel, parentTopicId, true); + this._actionRunner.execute(command); + }, + + createSiblingForSelectedNode : function() { + var nodes = this._getSelectedNodes(); + if (nodes.length <= 0) { + // If there are more than one node selected, + core.Monitor.getInstance().logMessage('Could not create a topic. Only one node must be selected.'); + return; + + } + if (nodes.length > 1) { + // If there are more than one node selected, + core.Monitor.getInstance().logMessage('Could not create a topic. One topic must be selected.'); + return; + } + + var topic = nodes[0]; + if (topic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { + // Central topic doesn't have siblings ... + this.createChildForSelectedNode(); + + } else { + var parentTopic = topic.getOutgoingConnectedTopic(); + var siblingModel = topic.createSiblingModel(this._layoutManager.needsPrepositioning()); + var parentTopicId = parentTopic.getId(); + var command = new mindplot.commands.AddTopicCommand(siblingModel, parentTopicId, true); - // Execute action ... - var command = new mindplot.commands.AddTopicCommand(model, centralTopicId, true); this._actionRunner.execute(command); } - }.bind(this)); - } - ; -}; + }, -mindplot.MindmapDesigner.prototype._buildNodeGraph = function(model) -{ - var workspace = this._workspace; - var elem = this; - - // Create node graph ... - var topic = mindplot.NodeGraph.create(model); - - this._layoutManager.addHelpers(topic); - - // Append it to the workspace ... - var topics = this._topics; - topics.push(topic); - - // Add Topic events ... - this._layoutManager.registerListenersOnNode(topic); - - // Connect Topic ... - var isConnected = model.isConnected(); - if (isConnected) - { - // Improve this ... - var targetTopicModel = model.getParent(); - var targetTopicId = targetTopicModel.getId(); - var targetTopic = null; - - for (var i = 0; i < topics.length; i++) - { - var t = topics[i]; - if (t.getModel() == targetTopicModel) - { - targetTopic = t; - // Disconnect the node. It will be connected again later ... - model.disconnect(); - break; + addRelationShip2SelectedNode : function(event) { + var screen = this._workspace.getScreenManager(); + var pos = screen.getWorkspaceMousePosition(event); + var selectedTopics = this.getSelectedNodes(); + if (selectedTopics.length > 0 && + (!$defined(this._creatingRelationship) || ($defined(this._creatingRelationship) && !this._creatingRelationship))) { + this._workspace.enableWorkspaceEvents(false); + var fromNodePosition = selectedTopics[0].getPosition(); + this._relationship = new web2d.CurvedLine(); + this._relationship.setStyle(web2d.CurvedLine.SIMPLE_LINE); + this._relationship.setDashed(2, 2); + this._relationship.setFrom(fromNodePosition.x, fromNodePosition.y); + this._relationship.setTo(pos.x, pos.y); + this._workspace.appendChild(this._relationship); + this._creatingRelationship = true; + this._relationshipMouseMoveFunction = this._relationshipMouseMove.bindWithEvent(this); + this._relationshipMouseClickFunction = this._relationshipMouseClick.bindWithEvent(this, selectedTopics[0]); + this._workspace.getScreenManager().addEventListener('mousemove', this._relationshipMouseMoveFunction); + this._workspace.getScreenManager().addEventListener('click', this._relationshipMouseClickFunction); } - } - $assert(targetTopic, "Could not find a topic to connect"); - topic.connectTo(targetTopic, workspace); - } + }, - return topic; -}; + _relationshipMouseMove : function(event) { + var screen = this._workspace.getScreenManager(); + var pos = screen.getWorkspaceMousePosition(event); + this._relationship.setTo(pos.x - 1, pos.y - 1); //to prevent click event target to be the line itself + event.preventDefault(); + event.stop(); + return false; + }, -mindplot.MindmapDesigner.prototype.onObjectFocusEvent = function(currentObject, event) -{ - this.getEditor().lostFocus(); - var selectableObjects = this.getSelectedObjects(); - // Disable all nodes on focus but not the current if Ctrl key isn't being pressed - if (!$defined(event) || event.ctrlKey == false) - { - for (var i = 0; i < selectableObjects.length; i++) - { - var selectableObject = selectableObjects[i]; - if (selectableObject.isOnFocus() && selectableObject != currentObject) - { - selectableObject.setOnFocus(false); + _relationshipMouseClick : function (event, fromNode) { + var target = event.target; + while (target.tagName != "g" && $defined(target.parentNode)) { + target = target.parentNode; } - } - } -}; - -mindplot.MindmapDesigner.prototype.zoomOut = function() -{ - var scale = this._zoom * 1.2; - if (scale <= 4) - { - this._zoom = scale; - this._workspace.setZoom(this._zoom); - } - else - { - core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?'); - } - -}; - -mindplot.MindmapDesigner.prototype.zoomIn = function() -{ - var scale = this._zoom / 1.2; - if (scale >= 0.3) - { - this._zoom = scale; - this._workspace.setZoom(this._zoom); - } - else - { - core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?'); - } -}; - -mindplot.MindmapDesigner.prototype.createChildForSelectedNode = function() -{ - - var nodes = this._getSelectedNodes(); - if (nodes.length <= 0) - { - // If there are more than one node selected, - core.Monitor.getInstance().logMessage('Could not create a topic. Only one node must be selected.'); - return; - - } - if (nodes.length > 1) - { - - // If there are more than one node selected, - core.Monitor.getInstance().logMessage('Could not create a topic. One topic must be selected.'); - return; - } - - // Add new node ... - var centalTopic = nodes[0]; - var parentTopicId = centalTopic.getId(); - var childModel = centalTopic.createChildModel(this._layoutManager.needsPrepositioning()); - - var command = new mindplot.commands.AddTopicCommand(childModel, parentTopicId, true); - this._actionRunner.execute(command); -}; - -mindplot.MindmapDesigner.prototype.createSiblingForSelectedNode = function() -{ - var nodes = this._getSelectedNodes(); - if (nodes.length <= 0) - { - // If there are more than one node selected, - core.Monitor.getInstance().logMessage('Could not create a topic. Only one node must be selected.'); - return; - - } - if (nodes.length > 1) - { - // If there are more than one node selected, - core.Monitor.getInstance().logMessage('Could not create a topic. One topic must be selected.'); - return; - } - - var topic = nodes[0]; - if (topic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) - { - // Central topic doesn't have siblings ... - this.createChildForSelectedNode(); - - } else - { - var parentTopic = topic.getOutgoingConnectedTopic(); - var siblingModel = topic.createSiblingModel(this._layoutManager.needsPrepositioning()); - var parentTopicId = parentTopic.getId(); - var command = new mindplot.commands.AddTopicCommand(siblingModel, parentTopicId, true); - - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.addRelationShip2SelectedNode = function(event) -{ - var screen = this._workspace.getScreenManager(); - var pos = screen.getWorkspaceMousePosition(event); - var selectedTopics = this.getSelectedNodes(); - if(selectedTopics.length >0 && - (!$defined(this._creatingRelationship) || ($defined(this._creatingRelationship) && !this._creatingRelationship))){ - this._workspace.enableWorkspaceEvents(false); - var fromNodePosition = selectedTopics[0].getPosition(); - this._relationship = new web2d.CurvedLine(); - this._relationship.setStyle(web2d.CurvedLine.SIMPLE_LINE); - this._relationship.setDashed(2,2); - this._relationship.setFrom(fromNodePosition.x, fromNodePosition.y); - this._relationship.setTo(pos.x, pos.y); - this._workspace.appendChild(this._relationship); - this._creatingRelationship=true; - this._relationshipMouseMoveFunction = this._relationshipMouseMove.bindWithEvent(this); - this._relationshipMouseClickFunction = this._relationshipMouseClick.bindWithEvent(this, selectedTopics[0]); - this._workspace.getScreenManager().addEventListener('mousemove',this._relationshipMouseMoveFunction); - this._workspace.getScreenManager().addEventListener('click',this._relationshipMouseClickFunction); - } -}; - -mindplot.MindmapDesigner.prototype._relationshipMouseMove = function(event){ - var screen = this._workspace.getScreenManager(); - var pos = screen.getWorkspaceMousePosition(event); - this._relationship.setTo(pos.x-1, pos.y-1); //to prevent click event target to be the line itself - event.preventDefault(); - event.stop(); - return false; -}; - -mindplot.MindmapDesigner.prototype._relationshipMouseClick = function (event, fromNode) { - var target = event.target; - while(target.tagName != "g" && $defined(target.parentNode)){ - target=target.parentNode; - } - if($defined(target.virtualRef)){ - var targetNode = target.virtualRef; - this.addRelationship(fromNode, targetNode); - } - this._workspace.removeChild(this._relationship); - this._relationship = null; - this._workspace.getScreenManager().removeEventListener('mousemove',this._relationshipMouseMoveFunction); - this._workspace.getScreenManager().removeEventListener('click',this._relationshipMouseClickFunction); - this._creatingRelationship=false; - this._workspace.enableWorkspaceEvents(true); - event.preventDefault(); - event.stop(); - return false; -}; - -mindplot.MindmapDesigner.prototype.addRelationship= function(fromNode, toNode){ - // Create a new topic model ... - var mindmap = this.getMindmap(); - var model = mindmap.createRelationship(fromNode.getModel().getId(), toNode.getModel().getId()); - - var command = new mindplot.commands.AddRelationshipCommand(model, mindmap); - this._actionRunner.execute(command); -}; - -mindplot.MindmapDesigner.prototype.needsSave = function() -{ - return this._actionRunner.hasBeenChanged(); -} - -mindplot.MindmapDesigner.prototype.autoSaveEnabled = function(value) -{ - if ($defined(value) && value) - { - var autosave = function() { - - if (this.needsSave()) - { - this.save(null, false); + if ($defined(target.virtualRef)) { + var targetNode = target.virtualRef; + this.addRelationship(fromNode, targetNode); } - }; - autosave.bind(this).periodical(30000); - } -} - -mindplot.MindmapDesigner.prototype.save = function(onSavedHandler, saveHistory) -{ - var persistantManager = mindplot.PersistanceManager; - var mindmap = this._mindmap; - - var properties = {zoom:this._zoom, layoutManager:this._layoutManager.getClassName()}; - persistantManager.save(mindmap, properties, onSavedHandler, saveHistory); - this._fireEvent("save", {type:saveHistory}); - - // Refresh undo state... - this._actionRunner.markAsChangeBase(); -}; - -mindplot.MindmapDesigner.prototype.loadFromXML = function(mapId, xmlContent) -{ - $assert(xmlContent, 'mindmapId can not be null'); - $assert(xmlContent, 'xmlContent can not be null'); - - // Explorer Hack with local files ... - var domDocument = core.Utils.createDocumentFromText(xmlContent); - - var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(domDocument); - var mindmap = serializer.loadFromDom(domDocument); - - this._loadMap(mapId, mindmap); - - // Place the focus on the Central Topic - var centralTopic = this.getCentralTopic(); - this._goToNode.attempt(centralTopic, this); - - this._fireEvent("loadsuccess"); - -}; - -mindplot.MindmapDesigner.prototype.load = function(mapId) -{ - $assert(mapId, 'mapName can not be null'); - - // Build load function ... - var persistantManager = mindplot.PersistanceManager; - - // Loading mindmap ... - var mindmap = persistantManager.load(mapId); - - // Finally, load the map in the editor ... - this._loadMap(mapId, mindmap); - - // Place the focus on the Central Topic - var centralTopic = this.getCentralTopic(); - this._goToNode.attempt(centralTopic, this); - - this._fireEvent("loadsuccess"); -}; - -mindplot.MindmapDesigner.prototype._loadMap = function(mapId, mindmapModel) -{ - var designer = this; - if (mindmapModel != null) - { - mindmapModel.setId(mapId); - designer._mindmap = mindmapModel; - - // Building node graph ... - var branches = mindmapModel.getBranches(); - for (var i = 0; i < branches.length; i++) - { - // NodeModel -> NodeGraph ... - var nodeModel = branches[i]; - var nodeGraph = this._nodeModelToNodeGraph(nodeModel); - - // Update shrink render state... - nodeGraph.setBranchVisibility(true); - } - var relationships = mindmapModel.getRelationships(); - for (var j=0; j 0) - { - this._removeNode(node._getChildren()[0]); - } - - this._workspace.removeChild(node); - this._topics.erase(node); - - // Delete this node from the model... - var model = node.getModel(); - model.deleteNode(); - - if ($defined(parent)) - { - this._goToNode(parent); - } - } -}; - -mindplot.MindmapDesigner.prototype.deleteCurrentNode = function() -{ - - var validateFunc = function(selectedObject) { - return selectedObject.getType() == mindplot.RelationshipLine.type || selectedObject.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE - }; - var validateError = 'Central topic can not be deleted.'; - var selectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); - if (selectedObjects.nodes.length > 0 || selectedObjects.relationshipLines.length>0) - { - var command = new mindplot.commands.DeleteTopicCommand(selectedObjects); - this._actionRunner.execute(command); - } - -}; - -mindplot.MindmapDesigner.prototype.setFont2SelectedNode = function(font) -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var commandFunc = function(topic, font) - { - var result = topic.getFontFamily(); - topic.setFontFamily(font, true); - - core.Executor.instance.delay(topic.updateNode, 0,topic); - /*var updated = function() { - topic.updateNode(); - }; - updated.delay(0);*/ - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, font, topicsIds); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.setStyle2SelectedNode = function() -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var commandFunc = function(topic) - { - var result = topic.getFontStyle(); - var style = (result == "italic") ? "normal" : "italic"; - topic.setFontStyle(style, true); - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, "", topicsIds); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.setFontColor2SelectedNode = function(color) -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var commandFunc = function(topic, color) - { - var result = topic.getFontColor(); - topic.setFontColor(color, true); - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds); - command.discartDuplicated = "fontColorCommandId"; - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.setBackColor2SelectedNode = function(color) -{ - - var validateFunc = function(topic) { - return topic.getShapeType() != mindplot.NodeModel.SHAPE_TYPE_LINE - }; - var validateError = 'Color can not be setted to line topics.'; - var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);; - var topicsIds = validSelectedObjects.nodes; - - if (topicsIds.length > 0) - { - var commandFunc = function(topic, color) - { - var result = topic.getBackgroundColor(); - topic.setBackgroundColor(color); - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds); - command.discartDuplicated = "backColor"; - this._actionRunner.execute(command); - } -}; - - -mindplot.MindmapDesigner.prototype._getValidSelectedObjectsIds = function(validate, errorMsg) -{ - var result = {"nodes":[],"relationshipLines":[]}; - var selectedNodes = this._getSelectedNodes(); - var selectedRelationshipLines = this.getSelectedRelationshipLines(); - if (selectedNodes.length == 0 && selectedRelationshipLines.length == 0) - { - core.Monitor.getInstance().logMessage('At least one element must be selected to execute this operation.'); - } else - { - var isValid = true; - for (var i = 0; i < selectedNodes.length; i++) - { - var selectedNode = selectedNodes[i]; - if ($defined(validate)) - { - isValid = validate(selectedNode); - } - - // Add node only if it's valid. - if (isValid) - { - result.nodes.push(selectedNode.getId()); - } else - { - core.Monitor.getInstance().logMessage(errorMsg); - } - } - for( var j = 0; j< selectedRelationshipLines.length; j++){ - var selectedLine = selectedRelationshipLines[j]; - isValid = true; - if($defined(validate)){ - isValid = validate(selectedLine); - } - - if(isValid){ - result.relationshipLines.push(selectedLine.getId()); - } else - { - core.Monitor.getInstance().logMessage(errorMsg); - } - } - } - return result; -} - -mindplot.MindmapDesigner.prototype.setBorderColor2SelectedNode = function(color) -{ - var validateFunc = function(topic) { - return topic.getShapeType() != mindplot.NodeModel.SHAPE_TYPE_LINE - }; - var validateError = 'Color can not be setted to line topics.'; - var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError);; - var topicsIds = validSelectedObjects.nodes; - - if (topicsIds.length > 0) - { - var commandFunc = function(topic, color) - { - var result = topic.getBorderColor(); - topic.setBorderColor(color); - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds); - command.discartDuplicated = "borderColorCommandId"; - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.setFontSize2SelectedNode = function(size) -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var commandFunc = function(topic, size) - { - var result = topic.getFontSize(); - topic.setFontSize(size, true); - - core.Executor.instance.delay(topic.updateNode, 0,topic); - /*var updated = function() { - topic.updateNode(); - }; - updated.delay(0);*/ - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, size, topicsIds); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.setShape2SelectedNode = function(shape) -{ - var validateFunc = function(topic) { - return !(topic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.NodeModel.SHAPE_TYPE_LINE) - }; - var validateError = 'Central Topic shape can not be changed to line figure.'; - var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); - var topicsIds = validSelectedObjects.nodes; - - if (topicsIds.length > 0) - { - var commandFunc = function(topic, size) - { - var result = topic.getShapeType(); - topic.setShapeType(size, true); - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, shape, topicsIds); - this._actionRunner.execute(command); - } -}; - - -mindplot.MindmapDesigner.prototype.setWeight2SelectedNode = function() -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var commandFunc = function(topic) - { - var result = topic.getFontWeight(); - var weight = (result == "bold") ? "normal" : "bold"; - topic.setFontWeight(weight, true); - - core.Executor.instance.delay(topic.updateNode, 0,topic); - /*var updated = function() { - topic.updateNode(); - }; - updated.delay(0);*/ - return result; - } - var command = new mindplot.commands.GenericFunctionCommand(commandFunc, "", topicsIds); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.addImage2SelectedNode = function(iconType) -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - - var command = new mindplot.commands.AddIconToTopicCommand(topicsIds[0], iconType); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.addLink2Node = function(url) -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var command = new mindplot.commands.AddLinkToTopicCommand(topicsIds[0], url); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.addLink2SelectedNode = function() -{ - var selectedTopics = this.getSelectedNodes(); - var topic = null; - if (selectedTopics.length > 0) - { - topic = selectedTopics[0]; - if (!$chk(topic._hasLink)) { - var msg = new Element('div'); - var urlText = new Element('div').inject(msg); - urlText.innerHTML = "URL:" - var formElem = new Element('form', {'action': 'none', 'id':'linkFormId'}); - var urlInput = new Element('input', {'type': 'text', 'size':30}); - urlInput.inject(formElem); - formElem.inject(msg) - - var okButtonId = "linkOkButtonId"; - formElem.addEvent('submit', function(e) - { - $(okButtonId).fireEvent('click', e); - e = new Event(e); - e.stop(); - }); - - - var okFunction = function() { - var url = urlInput.value; - var result = false; - if ("" != url.trim()) - { - this.addLink2Node(url); - result = true; + this._workspace.removeChild(this._relationship); + this._relationship = null; + this._workspace.getScreenManager().removeEventListener('mousemove', this._relationshipMouseMoveFunction); + this._workspace.getScreenManager().removeEventListener('click', this._relationshipMouseClickFunction); + this._creatingRelationship = false; + this._workspace.enableWorkspaceEvents(true); + event.preventDefault(); + event.stop(); + return false; + }, + + addRelationship : function(fromNode, toNode) { + // Create a new topic model ... + var mindmap = this.getMindmap(); + var model = mindmap.createRelationship(fromNode.getModel().getId(), toNode.getModel().getId()); + + var command = new mindplot.commands.AddRelationshipCommand(model, mindmap); + this._actionRunner.execute(command); + }, + + needsSave : function() { + return this._actionRunner.hasBeenChanged(); + }, + + autoSaveEnabled : function(value) { + if ($defined(value) && value) { + var autosave = function() { + + if (this.needsSave()) { + this.save(null, false); } - return result; - }.bind(this); - var dialog = mindplot.LinkIcon.buildDialog(this, okFunction, okButtonId); - dialog.adopt(msg).show(); + }; + autosave.bind(this).periodical(30000); + } + }, - // IE doesn't like too much this focus action... - if(!core.UserAgent.isIE()) - { - urlInput.focus(); + save : function(onSavedHandler, saveHistory) { + var persistantManager = mindplot.PersistanceManager; + var mindmap = this._mindmap; + + var properties = {zoom:this._zoom, layoutManager:this._layoutManager.getClassName()}; + persistantManager.save(mindmap, properties, onSavedHandler, saveHistory); + this._fireEvent("save", {type:saveHistory}); + + // Refresh undo state... + this._actionRunner.markAsChangeBase(); + }, + + loadFromXML : function(mapId, xmlContent) { + $assert(xmlContent, 'mindmapId can not be null'); + $assert(xmlContent, 'xmlContent can not be null'); + + // Explorer Hack with local files ... + var domDocument = core.Utils.createDocumentFromText(xmlContent); + + var serializer = mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument(domDocument); + var mindmap = serializer.loadFromDom(domDocument); + + this._loadMap(mapId, mindmap); + + // Place the focus on the Central Topic + var centralTopic = this.getCentralTopic(); + this._goToNode.attempt(centralTopic, this); + + this._fireEvent("loadsuccess"); + + }, + + load : function(mapId) { + $assert(mapId, 'mapName can not be null'); + + // Build load function ... + var persistantManager = mindplot.PersistanceManager; + + // Loading mindmap ... + var mindmap = persistantManager.load(mapId); + + // Finally, load the map in the editor ... + this._loadMap(mapId, mindmap); + + // Place the focus on the Central Topic + var centralTopic = this.getCentralTopic(); + this._goToNode.attempt(centralTopic, this); + + this._fireEvent("loadsuccess"); + }, + + _loadMap : function(mapId, mindmapModel) { + var designer = this; + if (mindmapModel != null) { + mindmapModel.setId(mapId); + designer._mindmap = mindmapModel; + + // Building node graph ... + var branches = mindmapModel.getBranches(); + for (var i = 0; i < branches.length; i++) { + // NodeModel -> NodeGraph ... + var nodeModel = branches[i]; + var nodeGraph = this._nodeModelToNodeGraph(nodeModel); + + // Update shrink render state... + nodeGraph.setBranchVisibility(true); + } + var relationships = mindmapModel.getRelationships(); + for (var j = 0; j < relationships.length; j++) { + var relationship = this._relationshipModelToRelationship(relationships[j]); } } - } else - { - core.Monitor.getInstance().logMessage('At least one topic must be selected to execute this operation.'); - } -}; + core.Executor.instance.setLoading(false); + this._getTopics().forEach(function(topic) { + delete topic.getModel()._finalPosition; + }); + this._fireEvent("loadsuccess"); -mindplot.MindmapDesigner.prototype.addNote2Node = function(text) -{ - var validSelectedObjects = this._getValidSelectedObjectsIds(); - var topicsIds = validSelectedObjects.nodes; - if (topicsIds.length > 0) - { - var command = new mindplot.commands.AddNoteToTopicCommand(topicsIds[0], text); - this._actionRunner.execute(command); - } -}; - -mindplot.MindmapDesigner.prototype.addNote2SelectedNode = function() -{ - var selectedTopics = this.getSelectedNodes(); - var topic = null; - if (selectedTopics.length > 0) - { - topic = selectedTopics[0]; - if (!$chk(topic._hasNote)) { - var msg = new Element('div'); - var text = new Element('div').inject(msg); - var formElem = new Element('form', {'action': 'none', 'id':'noteFormId'}); - var textInput = new Element('textarea').setStyles({'width':280, 'height':50}); - textInput.inject(formElem); - formElem.inject(msg); - - var okButtonId = "noteOkButtonId"; - formElem.addEvent('submit', function(e) - { - $(okButtonId).fireEvent('click', e); - e = new Event(e); - e.stop(); - }); + }, - var okFunction = function() { - var text = textInput.value; - var result = false; - if ("" != text.trim()) - { - this.addNote2Node(text); - result = true; - } - return result; - }.bind(this); - var dialog = mindplot.Note.buildDialog(this, okFunction, okButtonId); - dialog.adopt(msg).show(); + getMindmap : function() { + return this._mindmap; + }, - // IE doesn't like too much this focus action... - if(!core.UserAgent.isIE()) - { - textInput.focus(); + undo : function() { + this._actionRunner.undo(); + }, + + redo : function() { + this._actionRunner.redo(); + }, + + _nodeModelToNodeGraph : function(nodeModel, isVisible) { + $assert(nodeModel, "Node model can not be null"); + var nodeGraph = this._buildNodeGraph(nodeModel); + + if ($defined(isVisible)) + nodeGraph.setVisibility(isVisible); + + var children = nodeModel.getChildren().slice(); + + children = this._layoutManager.prepareNode(nodeGraph, children); + + for (var i = 0; i < children.length; i++) { + var child = children[i]; + if ($defined(child)) + this._nodeModelToNodeGraph(child); + } + + var workspace = this._workspace; + workspace.appendChild(nodeGraph); + return nodeGraph; + }, + + _relationshipModelToRelationship : function(model) { + $assert(model, "Node model can not be null"); + var relationship = this._buildRelationship(model); + var sourceTopic = relationship.getSourceTopic(); + sourceTopic.addRelationship(relationship); + var targetTopic = relationship.getTargetTopic(); + targetTopic.addRelationship(relationship); + relationship.setVisibility(sourceTopic.isVisible() && targetTopic.isVisible()); + var workspace = this._workspace; + workspace.appendChild(relationship); + relationship.redraw(); + return relationship; + }, + + createRelationship : function(model) { + this._mindmap.addRelationship(model); + return this._relationshipModelToRelationship(model); + }, + + removeRelationship : function(model) { + this._mindmap.removeRelationship(model); + var relationship = this._relationships[model.getId()]; + var sourceTopic = relationship.getSourceTopic(); + sourceTopic.removeRelationship(relationship); + var targetTopic = relationship.getTargetTopic(); + targetTopic.removeRelationship(relationship); + this._workspace.removeChild(relationship); + delete this._relationships[model.getId()]; + }, + + _buildRelationship : function (model) { + var workspace = this._workspace; + var elem = this; + + var fromNodeId = model.getFromNode(); + var toNodeId = model.getToNode(); + + var fromTopic = null; + var toTopic = null; + var topics = this._topics; + + for (var i = 0; i < topics.length; i++) { + var t = topics[i]; + if (t.getModel().getId() == fromNodeId) { + fromTopic = t; + } + if (t.getModel().getId() == toNodeId) { + toTopic = t; + } + if (toTopic != null && fromTopic != null) { + break; } } - } else - { - core.Monitor.getInstance().logMessage('At least one topic must be selected to execute this operation.'); - } -}; -mindplot.MindmapDesigner.prototype.removeLastImageFromSelectedNode = function() -{ - var nodes = this._getSelectedNodes(); - if (nodes.length == 0) - { - core.Monitor.getInstance().logMessage('A topic must be selected in order to execute this operation.'); - } else - { - var elem = nodes[0]; - elem.removeLastIcon(this); - core.Executor.instance.delay(elem.updateNode, 0,elem); - /*var executor = function(editor) - { - return function() - { - elem.updateNode(); + // Create node graph ... + var relationLine = new mindplot.RelationshipLine(fromTopic, toTopic, model.getLineType()); + if ($defined(model.getSrcCtrlPoint())) { + var srcPoint = model.getSrcCtrlPoint().clone(); + relationLine.setSrcControlPoint(srcPoint); + } + if ($defined(model.getDestCtrlPoint())) { + var destPoint = model.getDestCtrlPoint().clone(); + relationLine.setDestControlPoint(destPoint); + } + + + relationLine.getLine().setDashed(3, 2); + relationLine.setShowEndArrow(model.getEndArrow()); + relationLine.setShowStartArrow(model.getStartArrow()); + relationLine.setModel(model); + + //Add Listeners + var elem = this; + relationLine.addEventListener('onfocus', function(event) { + elem.onObjectFocusEvent.attempt([relationLine, event], elem); + }); + + // Append it to the workspace ... + this._relationships[model.getId()] = relationLine; + + return relationLine; + }, + + getEditor : function() { + return this._editor; + }, + + _removeNode : function(node) { + if (node.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { + var parent = node._parent; + node.disconnect(this._workspace); + + //remove children + while (node._getChildren().length > 0) { + this._removeNode(node._getChildren()[0]); + } + + this._workspace.removeChild(node); + this._topics.erase(node); + + // Delete this node from the model... + var model = node.getModel(); + model.deleteNode(); + + if ($defined(parent)) { + this._goToNode(parent); + } + } + }, + + deleteCurrentNode : function() { + + var validateFunc = function(selectedObject) { + return selectedObject.getType() == mindplot.RelationshipLine.type || selectedObject.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE }; - }; + var validateError = 'Central topic can not be deleted.'; + var selectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); + if (selectedObjects.nodes.length > 0 || selectedObjects.relationshipLines.length > 0) { + var command = new mindplot.commands.DeleteTopicCommand(selectedObjects); + this._actionRunner.execute(command); + } - setTimeout(executor(this), 0);*/ - } -}; + }, + + setFont2SelectedNode : function(font) { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var commandFunc = function(topic, font) { + var result = topic.getFontFamily(); + topic.setFontFamily(font, true); + + core.Executor.instance.delay(topic.updateNode, 0, topic); + /*var updated = function() { + topic.updateNode(); + }; + updated.delay(0);*/ + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, font, topicsIds); + this._actionRunner.execute(command); + } + }, + + setStyle2SelectedNode : function() { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var commandFunc = function(topic) { + var result = topic.getFontStyle(); + var style = (result == "italic") ? "normal" : "italic"; + topic.setFontStyle(style, true); + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, "", topicsIds); + this._actionRunner.execute(command); + } + }, + + setFontColor2SelectedNode : function(color) { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var commandFunc = function(topic, color) { + var result = topic.getFontColor(); + topic.setFontColor(color, true); + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds); + command.discartDuplicated = "fontColorCommandId"; + this._actionRunner.execute(command); + } + }, + + setBackColor2SelectedNode : function(color) { + + var validateFunc = function(topic) { + return topic.getShapeType() != mindplot.NodeModel.SHAPE_TYPE_LINE + }; + var validateError = 'Color can not be setted to line topics.'; + var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); + ; + var topicsIds = validSelectedObjects.nodes; + + if (topicsIds.length > 0) { + var commandFunc = function(topic, color) { + var result = topic.getBackgroundColor(); + topic.setBackgroundColor(color); + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds); + command.discartDuplicated = "backColor"; + this._actionRunner.execute(command); + } + }, -mindplot.MindmapDesigner.prototype._getSelectedNodes = function() -{ - var result = new Array(); - for (var i = 0; i < this._topics.length; i++) - { - if (this._topics[i].isOnFocus()) - { - result.push(this._topics[i]); - } - } - return result; -}; - -mindplot.MindmapDesigner.prototype.getSelectedRelationshipLines = function(){ - var result = new Array(); - for (var id in this._relationships) - { - var relationship = this._relationships[id]; - if (relationship.isOnFocus()) - { - result.push(relationship); - } - } - return result; -}; - -mindplot.MindmapDesigner.prototype.getSelectedNodes = function() -{ - return this._getSelectedNodes(); -}; - -mindplot.MindmapDesigner.prototype.getSelectedObjects = function() -{ - var selectedNodes = this.getSelectedNodes(); - var selectedRelationships = this.getSelectedRelationshipLines(); - selectedRelationships.extend(selectedNodes); - return selectedRelationships; -}; - -mindplot.MindmapDesigner.prototype.keyEventHandler = function(event) -{ - if(this._workspace.isWorkspaceEventsEnabled()){ - var evt = (event) ? event : window.event; - - if (evt.keyCode == 8) - { - if ($defined(event)) - { - if ($defined(event.preventDefault)) { - event.preventDefault(); + _getValidSelectedObjectsIds : function(validate, errorMsg) { + var result = {"nodes":[],"relationshipLines":[]}; + var selectedNodes = this._getSelectedNodes(); + var selectedRelationshipLines = this.getSelectedRelationshipLines(); + if (selectedNodes.length == 0 && selectedRelationshipLines.length == 0) { + core.Monitor.getInstance().logMessage('At least one element must be selected to execute this operation.'); } else { - event.returnValue = false; - } - new Event(event).stop(); - } - else - evt.returnValue = false; - } - else - { - evt = new Event(event); - var key = evt.key; - if (!this._editor.isVisible()) - { - if (((evt.code >= 65 && evt.code <= 90) || (evt.code >= 48 && evt.code <= 57)) && !(evt.control || evt.meta)) - { - if($chk(evt.shift)){ - key = key.toUpperCase(); + var isValid = true; + for (var i = 0; i < selectedNodes.length; i++) { + var selectedNode = selectedNodes[i]; + if ($defined(validate)) { + isValid = validate(selectedNode); + } + + // Add node only if it's valid. + if (isValid) { + result.nodes.push(selectedNode.getId()); + } else { + core.Monitor.getInstance().logMessage(errorMsg); + } } - this._showEditor(key); - } - else - { - switch (key) - { - case 'delete': - this.deleteCurrentNode(); - break; - case 'enter': - if (!evt.meta) - { - this.createSiblingForSelectedNode(); - break; - } - case 'insert': - this.createChildForSelectedNode(); - break; - case 'right': - var nodes = this._getSelectedNodes(); - if (nodes.length > 0) - { - var node = nodes[0]; - if (node.getTopicType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) - { - this._goToSideChild(node, 'RIGHT'); - } - else - { - if (node.getPosition().x < 0) - { - this._goToParent(node); - } - else if (!node.areChildrenShrinked()) - { - this._goToChild(node); - } - } - } - break; - case 'left': - var nodes = this._getSelectedNodes(); - if (nodes.length > 0) - { - var node = nodes[0]; - if (node.getTopicType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) - { - this._goToSideChild(node, 'LEFT'); - } - else - { - if (node.getPosition().x > 0) - { - this._goToParent(node); - } - else if (!node.areChildrenShrinked()) - { - this._goToChild(node); - } - } - } - break; - case'up': - var nodes = this._getSelectedNodes(); - if (nodes.length > 0) - { - var node = nodes[0]; - if (node.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE) - { - this._goToBrother(node, 'UP'); - } - } - break; - case 'down': - var nodes = this._getSelectedNodes(); - if (nodes.length > 0) - { - var node = nodes[0]; - if (node.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE) - { - this._goToBrother(node, 'DOWN'); - } - } - break; - case 'f2': - this._showEditor(); - break; - case 'space': + for (var j = 0; j < selectedRelationshipLines.length; j++) { + var selectedLine = selectedRelationshipLines[j]; + isValid = true; + if ($defined(validate)) { + isValid = validate(selectedLine); + } - var nodes = this._getSelectedNodes(); - if (nodes.length > 0) - { - var topic = nodes[0]; - - var model = topic.getModel(); - var isShrink = !model.areChildrenShrinked(); - topic.setChildrenShrinked(isShrink); - } - break; - case 'backspace': - evt.preventDefault(); - break; - case 'esc': - var nodes = this._getSelectedNodes(); - for (var i = 0; i < nodes.length; i++) - { - var node = nodes[i]; - node.setOnFocus(false); - } - break; - case 'z': - if (evt.control || evt.meta) - { - if (evt.shift) - { - this.redo(); - } - else - { - this.undo(); - } - } - break; - default: - break; + if (isValid) { + result.relationshipLines.push(selectedLine.getId()); + } else { + core.Monitor.getInstance().logMessage(errorMsg); + } } } - evt.stop(); + return result; + }, + + setBorderColor2SelectedNode : function(color) { + var validateFunc = function(topic) { + return topic.getShapeType() != mindplot.NodeModel.SHAPE_TYPE_LINE + }; + var validateError = 'Color can not be setted to line topics.'; + var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); + ; + var topicsIds = validSelectedObjects.nodes; + + if (topicsIds.length > 0) { + var commandFunc = function(topic, color) { + var result = topic.getBorderColor(); + topic.setBorderColor(color); + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, color, topicsIds); + command.discartDuplicated = "borderColorCommandId"; + this._actionRunner.execute(command); + } + }, + + setFontSize2SelectedNode : function(size) { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var commandFunc = function(topic, size) { + var result = topic.getFontSize(); + topic.setFontSize(size, true); + + core.Executor.instance.delay(topic.updateNode, 0, topic); + /*var updated = function() { + topic.updateNode(); + }; + updated.delay(0);*/ + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, size, topicsIds); + this._actionRunner.execute(command); + } + }, + + setShape2SelectedNode : function(shape) { + var validateFunc = function(topic) { + return !(topic.getType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE && shape == mindplot.NodeModel.SHAPE_TYPE_LINE) + }; + var validateError = 'Central Topic shape can not be changed to line figure.'; + var validSelectedObjects = this._getValidSelectedObjectsIds(validateFunc, validateError); + var topicsIds = validSelectedObjects.nodes; + + if (topicsIds.length > 0) { + var commandFunc = function(topic, size) { + var result = topic.getShapeType(); + topic.setShapeType(size, true); + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, shape, topicsIds); + this._actionRunner.execute(command); + } + }, + + + setWeight2SelectedNode : function() { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var commandFunc = function(topic) { + var result = topic.getFontWeight(); + var weight = (result == "bold") ? "normal" : "bold"; + topic.setFontWeight(weight, true); + + core.Executor.instance.delay(topic.updateNode, 0, topic); + /*var updated = function() { + topic.updateNode(); + }; + updated.delay(0);*/ + return result; + } + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, "", topicsIds); + this._actionRunner.execute(command); + } + }, + + addImage2SelectedNode : function(iconType) { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + + var command = new mindplot.commands.AddIconToTopicCommand(topicsIds[0], iconType); + this._actionRunner.execute(command); + } + }, + + addLink2Node : function(url) { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var command = new mindplot.commands.AddLinkToTopicCommand(topicsIds[0], url); + this._actionRunner.execute(command); + } + }, + + addLink2SelectedNode : function() { + var selectedTopics = this.getSelectedNodes(); + var topic = null; + if (selectedTopics.length > 0) { + topic = selectedTopics[0]; + if (!$chk(topic._hasLink)) { + var msg = new Element('div'); + var urlText = new Element('div').inject(msg); + urlText.innerHTML = "URL:" + var formElem = new Element('form', {'action': 'none', 'id':'linkFormId'}); + var urlInput = new Element('input', {'type': 'text', 'size':30}); + urlInput.inject(formElem); + formElem.inject(msg) + + var okButtonId = "linkOkButtonId"; + formElem.addEvent('submit', function(e) { + $(okButtonId).fireEvent('click', e); + e = new Event(e); + e.stop(); + }); + + + var okFunction = function() { + var url = urlInput.value; + var result = false; + if ("" != url.trim()) { + this.addLink2Node(url); + result = true; + } + return result; + }.bind(this); + var dialog = mindplot.LinkIcon.buildDialog(this, okFunction, okButtonId); + dialog.adopt(msg).show(); + + // IE doesn't like too much this focus action... + if (!core.UserAgent.isIE()) { + urlInput.focus(); + } + } + } else { + core.Monitor.getInstance().logMessage('At least one topic must be selected to execute this operation.'); + } + }, + + addNote2Node : function(text) { + var validSelectedObjects = this._getValidSelectedObjectsIds(); + var topicsIds = validSelectedObjects.nodes; + if (topicsIds.length > 0) { + var command = new mindplot.commands.AddNoteToTopicCommand(topicsIds[0], text); + this._actionRunner.execute(command); + } + }, + + addNote2SelectedNode : function() { + var selectedTopics = this.getSelectedNodes(); + var topic = null; + if (selectedTopics.length > 0) { + topic = selectedTopics[0]; + if (!$chk(topic._hasNote)) { + var msg = new Element('div'); + var text = new Element('div').inject(msg); + var formElem = new Element('form', {'action': 'none', 'id':'noteFormId'}); + var textInput = new Element('textarea').setStyles({'width':280, 'height':50}); + textInput.inject(formElem); + formElem.inject(msg); + + var okButtonId = "noteOkButtonId"; + formElem.addEvent('submit', function(e) { + $(okButtonId).fireEvent('click', e); + e = new Event(e); + e.stop(); + }); + + + var okFunction = function() { + var text = textInput.value; + var result = false; + if ("" != text.trim()) { + this.addNote2Node(text); + result = true; + } + return result; + }.bind(this); + var dialog = mindplot.Note.buildDialog(this, okFunction, okButtonId); + dialog.adopt(msg).show(); + + // IE doesn't like too much this focus action... + if (!core.UserAgent.isIE()) { + textInput.focus(); + } + } + } else { + core.Monitor.getInstance().logMessage('At least one topic must be selected to execute this operation.'); + } + }, + + removeLastImageFromSelectedNode : function() { + var nodes = this._getSelectedNodes(); + if (nodes.length == 0) { + core.Monitor.getInstance().logMessage('A topic must be selected in order to execute this operation.'); + } else { + var elem = nodes[0]; + elem.removeLastIcon(this); + core.Executor.instance.delay(elem.updateNode, 0, elem); + /*var executor = function(editor) + { + return function() + { + elem.updateNode(); + }; + }; + + setTimeout(executor(this), 0);*/ + } + }, + + + _getSelectedNodes : function() { + var result = new Array(); + for (var i = 0; i < this._topics.length; i++) { + if (this._topics[i].isOnFocus()) { + result.push(this._topics[i]); + } + } + return result; + }, + + getSelectedRelationshipLines : function() { + var result = new Array(); + for (var id in this._relationships) { + var relationship = this._relationships[id]; + if (relationship.isOnFocus()) { + result.push(relationship); + } + } + return result; + }, + + getSelectedNodes : function() { + return this._getSelectedNodes(); + }, + + getSelectedObjects : function() { + var selectedNodes = this.getSelectedNodes(); + var selectedRelationships = this.getSelectedRelationshipLines(); + selectedRelationships.extend(selectedNodes); + return selectedRelationships; + }, + + keyEventHandler : function(event) { + if (this._workspace.isWorkspaceEventsEnabled()) { + var evt = (event) ? event : window.event; + + if (evt.keyCode == 8) { + if ($defined(event)) { + if ($defined(event.preventDefault)) { + event.preventDefault(); + } else { + event.returnValue = false; + } + new Event(event).stop(); + } + else + evt.returnValue = false; + } + else { + evt = new Event(event); + var key = evt.key; + if (!this._editor.isVisible()) { + if (((evt.code >= 65 && evt.code <= 90) || (evt.code >= 48 && evt.code <= 57)) && !(evt.control || evt.meta)) { + if ($chk(evt.shift)) { + key = key.toUpperCase(); + } + this._showEditor(key); + } + else { + switch (key) { + case 'delete': + this.deleteCurrentNode(); + break; + case 'enter': + if (!evt.meta) { + this.createSiblingForSelectedNode(); + break; + } + case 'insert': + this.createChildForSelectedNode(); + break; + case 'right': + var nodes = this._getSelectedNodes(); + if (nodes.length > 0) { + var node = nodes[0]; + if (node.getTopicType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { + this._goToSideChild(node, 'RIGHT'); + } + else { + if (node.getPosition().x < 0) { + this._goToParent(node); + } + else if (!node.areChildrenShrinked()) { + this._goToChild(node); + } + } + } + break; + case 'left': + var nodes = this._getSelectedNodes(); + if (nodes.length > 0) { + var node = nodes[0]; + if (node.getTopicType() == mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { + this._goToSideChild(node, 'LEFT'); + } + else { + if (node.getPosition().x > 0) { + this._goToParent(node); + } + else if (!node.areChildrenShrinked()) { + this._goToChild(node); + } + } + } + break; + case'up': + var nodes = this._getSelectedNodes(); + if (nodes.length > 0) { + var node = nodes[0]; + if (node.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { + this._goToBrother(node, 'UP'); + } + } + break; + case 'down': + var nodes = this._getSelectedNodes(); + if (nodes.length > 0) { + var node = nodes[0]; + if (node.getTopicType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE) { + this._goToBrother(node, 'DOWN'); + } + } + break; + case 'f2': + this._showEditor(); + break; + case 'space': + + var nodes = this._getSelectedNodes(); + if (nodes.length > 0) { + var topic = nodes[0]; + + var model = topic.getModel(); + var isShrink = !model.areChildrenShrinked(); + topic.setChildrenShrinked(isShrink); + } + break; + case 'backspace': + evt.preventDefault(); + break; + case 'esc': + var nodes = this._getSelectedNodes(); + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + node.setOnFocus(false); + } + break; + case 'z': + if (evt.control || evt.meta) { + if (evt.shift) { + this.redo(); + } + else { + this.undo(); + } + } + break; + default: + break; + } + } + evt.stop(); + } + } + } + }, + + _showEditor : function(key) { + var nodes = this._getSelectedNodes(); + if (nodes.length == 1) { + var node = nodes[0]; + if (key && key != "") { + this._editor.setInitialText(key); + } + this._editor.getFocusEvent.attempt(node, this._editor); + } + }, + + _goToBrother : function(node, direction) { + var brothers = node._parent._getChildren(); + var target = node; + var y = node.getPosition().y; + var x = node.getPosition().x; + var dist = null; + for (var i = 0; i < brothers.length; i++) { + var sameSide = (x * brothers[i].getPosition().x) >= 0; + if (brothers[i] != node && sameSide) { + var brother = brothers[i]; + var brotherY = brother.getPosition().y; + if (direction == "DOWN" && brotherY > y) { + var distancia = y - brotherY; + if (distancia < 0) { + distancia = distancia * (-1); + } + if (dist == null || dist > distancia) { + dist = distancia; + target = brothers[i]; + } + } + else if (direction == "UP" && brotherY < y) { + var distancia = y - brotherY; + if (distancia < 0) { + distancia = distancia * (-1); + } + if (dist == null || dist > distancia) { + dist = distancia; + target = brothers[i]; + } + } + } + } + this._goToNode(target); + }, + + _goToNode : function(node) { + node.setOnFocus(true); + this.onObjectFocusEvent.attempt(node, this); + }, + + _goToSideChild : function(node, side) { + var children = node._getChildren(); + if (children.length > 0) { + var target = children[0]; + var top = null; + for (var i = 0; i < children.length; i++) { + var child = children[i]; + var childY = child.getPosition().y; + if (side == 'LEFT' && child.getPosition().x < 0) { + if (top == null || childY < top) { + target = child; + top = childY; + } + } + if (side == 'RIGHT' && child.getPosition().x > 0) { + if (top == null || childY < top) { + target = child; + top = childY; + } + } + } + + this._goToNode(target); + } + }, + + _goToParent : function(node) { + var parent = node._parent; + this._goToNode(parent); + }, + + _goToChild : function(node) { + var children = node._getChildren(); + if (children.length > 0) { + var target = children[0]; + var top = target.getPosition().y; + for (var i = 0; i < children.length; i++) { + var child = children[i]; + if (child.getPosition().y < top) { + top = child.getPosition().y; + target = child; + } + } + this._goToNode(target); + } + }, + + getWorkSpace : function() { + return this._workspace; + }, + + findRelationShipsByTopicId : function(topicId) { + var result = []; + for (var relationshipId in this._relationships) { + var relationship = this._relationships[relationshipId]; + if (relationship.getModel().getFromNode() == topicId || relationship.getModel().getToNode() == topicId) { + result.push(relationship); + } + } + return result; } } - } -}; - -mindplot.MindmapDesigner.prototype._showEditor = function(key) -{ - var nodes = this._getSelectedNodes(); - if (nodes.length == 1) - { - var node = nodes[0]; - if (key && key != "") - { - this._editor.setInitialText(key); - } - this._editor.getFocusEvent.attempt(node, this._editor); - } -}; - -mindplot.MindmapDesigner.prototype._goToBrother = function(node, direction) -{ - var brothers = node._parent._getChildren(); - var target = node; - var y = node.getPosition().y; - var x = node.getPosition().x; - var dist = null; - for (var i = 0; i < brothers.length; i++) - { - var sameSide = (x * brothers[i].getPosition().x) >= 0; - if (brothers[i] != node && sameSide) - { - var brother = brothers[i]; - var brotherY = brother.getPosition().y; - if (direction == "DOWN" && brotherY > y) - { - var distancia = y - brotherY; - if (distancia < 0) - { - distancia = distancia * (-1); - } - if (dist == null || dist > distancia) - { - dist = distancia; - target = brothers[i]; - } - } - else if (direction == "UP" && brotherY < y) - { - var distancia = y - brotherY; - if (distancia < 0) - { - distancia = distancia * (-1); - } - if (dist == null || dist > distancia) - { - dist = distancia; - target = brothers[i]; - } - } - } - } - this._goToNode(target); -}; - -mindplot.MindmapDesigner.prototype._goToNode = function(node) -{ - node.setOnFocus(true); - this.onObjectFocusEvent.attempt(node, this); -}; - -mindplot.MindmapDesigner.prototype._goToSideChild = function(node, side) -{ - var children = node._getChildren(); - if (children.length > 0) - { - var target = children[0]; - var top = null; - for (var i = 0; i < children.length; i++) - { - var child = children[i]; - var childY = child.getPosition().y; - if (side == 'LEFT' && child.getPosition().x < 0) - { - if (top == null || childY < top) - { - target = child; - top = childY; - } - } - if (side == 'RIGHT' && child.getPosition().x > 0) - { - if (top == null || childY < top) - { - target = child; - top = childY; - } - } - } - - this._goToNode(target); - } -}; - -mindplot.MindmapDesigner.prototype._goToParent = function(node) -{ - var parent = node._parent; - this._goToNode(parent); -}; - -mindplot.MindmapDesigner.prototype._goToChild = function(node) -{ - var children = node._getChildren(); - if (children.length > 0) - { - var target = children[0]; - var top = target.getPosition().y; - for (var i = 0; i < children.length; i++) - { - var child = children[i]; - if (child.getPosition().y < top) - { - top = child.getPosition().y; - target = child; - } - } - this._goToNode(target); - } -}; - -mindplot.MindmapDesigner.prototype.getWorkSpace = function() -{ - return this._workspace; -}; - -mindplot.MindmapDesigner.prototype.findRelationShipsByTopicId = function(topicId){ - var result = []; - for(var relationshipId in this._relationships){ - var relationship = this._relationships[relationshipId]; - if(relationship.getModel().getFromNode()==topicId || relationship.getModel().getToNode()==topicId){ - result.push(relationship); - } - } - return result; -}; +); diff --git a/mindplot/src/main/javascript/NodeModel.js b/mindplot/src/main/javascript/NodeModel.js index 4fac7e23..c67d8cfd 100644 --- a/mindplot/src/main/javascript/NodeModel.js +++ b/mindplot/src/main/javascript/NodeModel.js @@ -183,8 +183,8 @@ mindplot.NodeModel = new Class({ }, setPosition : function(x, y) { - $assert($defined(x), "x coordinate must be defined"); - $assert($defined(y), "y coordinate must be defined"); + $assert(x, "x coordinate must be defined"); + $assert(y, "y coordinate must be defined"); if (!$defined(this._position)) { this._position = new core.Point(); @@ -198,8 +198,8 @@ mindplot.NodeModel = new Class({ }, setFinalPosition : function(x, y) { - $assert($defined(x), "x coordinate must be defined"); - $assert($defined(y), "y coordinate must be defined"); + $assert(x, "x coordinate must be defined"); + $assert(y, "y coordinate must be defined"); if (!$defined(this._finalPosition)) { this._finalPosition = new core.Point(); @@ -253,7 +253,7 @@ mindplot.NodeModel = new Class({ 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($defined(targetTopicHeight), 'childrenWidth 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; diff --git a/mindplot/src/main/javascript/RelationshipLine.js b/mindplot/src/main/javascript/RelationshipLine.js index 26df1fc0..44f70861 100644 --- a/mindplot/src/main/javascript/RelationshipLine.js +++ b/mindplot/src/main/javascript/RelationshipLine.js @@ -1,283 +1,275 @@ /* -* 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.RelationshipLine = function(sourceNode, targetNode, lineType) -{ - mindplot.ConnectionLine.call(this,sourceNode, targetNode, lineType); - this._line2d.setIsSrcControlPointCustom(false); - this._line2d.setIsDestControlPointCustom(false); - this._isOnfocus = false; - this._focusShape = this._createLine(this.getLineType(), mindplot.ConnectionLine.SIMPLE_CURVED); - this._focusShape.setStroke(2, "solid", "#3f96ff"); - var ctrlPoints = this._line2d.getControlPoints(); - this._focusShape.setSrcControlPoint(ctrlPoints[0]); - this._focusShape.setDestControlPoint(ctrlPoints[1]); - this._focusShape.setVisibility(false); - this._onFocus = false; - this._isInWorkspace = false; - this._controlPointsController = new mindplot.ControlPoint(); + * 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.RelationshipLine = new Class({ + Extends: mindplot.ConnectionLine, + initialize:function(sourceNode, targetNode, lineType) { + this.parent(sourceNode, targetNode, lineType); - var strokeColor = mindplot.RelationshipLine.getStrokeColor(); - this._startArrow = new web2d.Arrow(); - this._endArrow = new web2d.Arrow(); - this._startArrow.setStrokeColor(strokeColor); - this._startArrow.setStrokeWidth(2); - this._endArrow.setStrokeColor(strokeColor); - this._endArrow.setStrokeWidth(2); - this._line2d.setStroke(1, 'solid', strokeColor); + this._line2d.setIsSrcControlPointCustom(false); + this._line2d.setIsDestControlPointCustom(false); + this._isOnfocus = false; + this._focusShape = this._createLine(this.getLineType(), mindplot.ConnectionLine.SIMPLE_CURVED); + this._focusShape.setStroke(2, "solid", "#3f96ff"); + var ctrlPoints = this._line2d.getControlPoints(); + this._focusShape.setSrcControlPoint(ctrlPoints[0]); + this._focusShape.setDestControlPoint(ctrlPoints[1]); + this._focusShape.setVisibility(false); + this._onFocus = false; + this._isInWorkspace = false; + this._controlPointsController = new mindplot.ControlPoint(); -}; + var strokeColor = mindplot.RelationshipLine.getStrokeColor(); + this._startArrow = new web2d.Arrow(); + this._endArrow = new web2d.Arrow(); + this._startArrow.setStrokeColor(strokeColor); + this._startArrow.setStrokeWidth(2); + this._endArrow.setStrokeColor(strokeColor); + this._endArrow.setStrokeWidth(2); + this._line2d.setStroke(1, 'solid', strokeColor); -objects.extend(mindplot.RelationshipLine, mindplot.ConnectionLine); + }, -mindplot.RelationshipLine.getStrokeColor = function() -{ - return '#9b74e6'; -}; + setStroke : function(color, style, opacity) { + // @Todo: How this is supported in mootools ? + mindplot.ConnectionLine.prototype.setStroke.call(this, color, style, opacity); + this._startArrow.setStrokeColor(color); + }, -mindplot.RelationshipLine.prototype.setStroke = function(color, style, opacity) -{ - mindplot.RelationshipLine.superClass.setStroke.call(this, color, style, opacity); - this._startArrow.setStrokeColor(color); -}; + redraw : function() { + var line2d = this._line2d; + var sourceTopic = this._sourceTopic; + var sourcePosition = sourceTopic.getPosition(); -mindplot.RelationshipLine.prototype.redraw = function() -{ - var line2d = this._line2d; - var sourceTopic = this._sourceTopic; - var sourcePosition = sourceTopic.getPosition(); + var targetTopic = this._targetTopic; + var targetPosition = targetTopic.getPosition(); - var targetTopic = this._targetTopic; - var targetPosition = targetTopic.getPosition(); + var sPos,tPos; + this._line2d.setStroke(2); + var ctrlPoints = this._line2d.getControlPoints(); + if (!this._line2d.isDestControlPointCustom() && !this._line2d.isSrcControlPointCustom()) { + var defaultPoints = core.Utils.calculateDefaultControlPoints(sourcePosition, targetPosition); + ctrlPoints[0].x = defaultPoints[0].x; + ctrlPoints[0].y = defaultPoints[0].y; + ctrlPoints[1].x = defaultPoints[1].x; + ctrlPoints[1].y = defaultPoints[1].y; + } + var spoint = new core.Point(); + spoint.x = parseInt(ctrlPoints[0].x) + parseInt(sourcePosition.x); + spoint.y = parseInt(ctrlPoints[0].y) + parseInt(sourcePosition.y); + var tpoint = new core.Point(); + tpoint.x = parseInt(ctrlPoints[1].x) + parseInt(targetPosition.x); + tpoint.y = parseInt(ctrlPoints[1].y) + parseInt(targetPosition.y); + sPos = core.Utils.calculateRelationShipPointCoordinates(sourceTopic, spoint); + tPos = core.Utils.calculateRelationShipPointCoordinates(targetTopic, tpoint); - var sPos,tPos; - this._line2d.setStroke(2); - var ctrlPoints = this._line2d.getControlPoints(); - if(!this._line2d.isDestControlPointCustom() && !this._line2d.isSrcControlPointCustom()){ - var defaultPoints = core.Utils.calculateDefaultControlPoints(sourcePosition, targetPosition); - ctrlPoints[0].x=defaultPoints[0].x; - ctrlPoints[0].y=defaultPoints[0].y; - ctrlPoints[1].x=defaultPoints[1].x; - ctrlPoints[1].y=defaultPoints[1].y; - } - var spoint = new core.Point(); - spoint.x=parseInt(ctrlPoints[0].x)+parseInt(sourcePosition.x); - spoint.y=parseInt(ctrlPoints[0].y)+parseInt(sourcePosition.y); - var tpoint = new core.Point(); - tpoint.x=parseInt(ctrlPoints[1].x)+parseInt(targetPosition.x); - tpoint.y=parseInt(ctrlPoints[1].y)+parseInt(targetPosition.y); - sPos = core.Utils.calculateRelationShipPointCoordinates(sourceTopic,spoint); - tPos = core.Utils.calculateRelationShipPointCoordinates(targetTopic,tpoint); + line2d.setFrom(sPos.x, sPos.y); + line2d.setTo(tPos.x, tPos.y); - line2d.setFrom(sPos.x, sPos.y); - line2d.setTo(tPos.x, tPos.y); + line2d.moveToFront(); - line2d.moveToFront(); + //Positionate Arrows + this._positionateArrows(); - //Positionate Arrows - this._positionateArrows(); + // Add connector ... + this._positionateConnector(targetTopic); - // Add connector ... - this._positionateConnector(targetTopic); + if (this.isOnFocus()) { + this._refreshSelectedShape(); + } + this._focusShape.moveToBack(); + this._controlPointsController.redraw(); + }, - if(this.isOnFocus()){ - this._refreshSelectedShape(); - } - this._focusShape.moveToBack(); - this._controlPointsController.redraw(); -}; + _positionateArrows : function() { + this._endArrow.setVisibility(this.isVisible() && this._showEndArrow); + this._startArrow.setVisibility(this.isVisible() && this._showStartArrow); -mindplot.RelationshipLine.prototype._positionateArrows = function() -{ - this._endArrow.setVisibility(this.isVisible() && this._showEndArrow); - this._startArrow.setVisibility(this.isVisible() && this._showStartArrow); + var tpos = this._line2d.getTo(); + this._endArrow.setFrom(tpos.x, tpos.y); + var spos = this._line2d.getFrom(); + this._startArrow.setFrom(spos.x, spos.y); + this._endArrow.moveToBack(); + this._startArrow.moveToBack(); - var tpos = this._line2d.getTo(); - this._endArrow.setFrom(tpos.x, tpos.y); - var spos = this._line2d.getFrom(); - this._startArrow.setFrom(spos.x, spos.y); - this._endArrow.moveToBack(); - this._startArrow.moveToBack(); + if (this._line2d.getType() == "CurvedLine") { + var controlPoints = this._line2d.getControlPoints(); + this._startArrow.setControlPoint(controlPoints[0]); + this._endArrow.setControlPoint(controlPoints[1]); + } else { + this._startArrow.setControlPoint(this._line2d.getTo()); + this._endArrow.setControlPoint(this._line2d.getFrom()); + } + }, - if(this._line2d.getType() == "CurvedLine"){ - var controlPoints = this._line2d.getControlPoints(); - this._startArrow.setControlPoint(controlPoints[0]); - this._endArrow.setControlPoint(controlPoints[1]); - } else { - this._startArrow.setControlPoint(this._line2d.getTo()); - this._endArrow.setControlPoint(this._line2d.getFrom()); - } -}; + addToWorkspace : function(workspace) { + workspace.appendChild(this._focusShape); + workspace.appendChild(this._controlPointsController); + this._controlPointControllerListener = this._initializeControlPointController.bindWithEvent(this, workspace); + this._line2d.addEventListener('click', this._controlPointControllerListener); + this._isInWorkspace = true; -mindplot.RelationshipLine.prototype.addToWorkspace = function(workspace) -{ - workspace.appendChild(this._focusShape); - workspace.appendChild(this._controlPointsController); - this._controlPointControllerListener =this._initializeControlPointController.bindWithEvent(this,workspace); - this._line2d.addEventListener('click', this._controlPointControllerListener); - this._isInWorkspace = true; + workspace.appendChild(this._startArrow); + workspace.appendChild(this._endArrow); - workspace.appendChild(this._startArrow); - workspace.appendChild(this._endArrow); + mindplot.ConnectionLine.prototype.addToWorkspace.call(this, workspace); + }, - mindplot.RelationshipLine.superClass.addToWorkspace.call(this, workspace); -}; - -mindplot.RelationshipLine.prototype._initializeControlPointController = function(event,workspace){ + _initializeControlPointController : function(event, workspace) { this.setOnFocus(true); -}; + }, -mindplot.RelationshipLine.prototype.removeFromWorkspace = function(workspace){ - workspace.removeChild(this._focusShape); - workspace.removeChild(this._controlPointsController); - this._line2d.removeEventListener('click',this._controlPointControllerListener); - this._isInWorkspace = false; - workspace.removeChild(this._startArrow); - workspace.removeChild(this._endArrow); - - mindplot.RelationshipLine.superClass.removeFromWorkspace.call(this,workspace); -}; + removeFromWorkspace : function(workspace) { + workspace.removeChild(this._focusShape); + workspace.removeChild(this._controlPointsController); + this._line2d.removeEventListener('click', this._controlPointControllerListener); + this._isInWorkspace = false; + workspace.removeChild(this._startArrow); + workspace.removeChild(this._endArrow); -mindplot.RelationshipLine.prototype.getType = function(){ - return mindplot.RelationshipLine.type; -}; + mindplot.ConnectionLine.prototype.removeFromWorkspace.call(this, workspace); + }, -mindplot.RelationshipLine.prototype.setOnFocus = function(focus){ - // Change focus shape - if(focus){ - this._refreshSelectedShape(); - this._controlPointsController.setLine(this); - } - this._focusShape.setVisibility(focus); + getType : function() { + return mindplot.RelationshipLine.type; + }, - this._controlPointsController.setVisibility(focus); - this._onFocus = focus; -}; + setOnFocus : function(focus) { + // Change focus shape + if (focus) { + this._refreshSelectedShape(); + this._controlPointsController.setLine(this); + } + this._focusShape.setVisibility(focus); -mindplot.RelationshipLine.prototype._refreshSelectedShape = function () { - var sPos = this._line2d.getFrom(); - var tPos = this._line2d.getTo(); - var ctrlPoints = this._line2d.getControlPoints(); - this._focusShape.setFrom(sPos.x, sPos.y); - this._focusShape.setTo(tPos.x, tPos.y); - var shapeCtrlPoints = this._focusShape.getControlPoints(); - shapeCtrlPoints[0].x = ctrlPoints[0].x; - shapeCtrlPoints[0].y = ctrlPoints[0].y; - shapeCtrlPoints[1].x = ctrlPoints[1].x; - shapeCtrlPoints[1].y = ctrlPoints[1].y; - this._focusShape.updateLine(); - //this._focusShape.setSrcControlPoint(ctrlPoints[0]); - //this._focusShape.setDestControlPoint(ctrlPoints[1]); -}; + this._controlPointsController.setVisibility(focus); + this._onFocus = focus; + }, -mindplot.RelationshipLine.prototype.addEventListener = function(type, listener){ - // Translate to web 2d events ... - if (type == 'onfocus') - { - type = 'mousedown'; - } + _refreshSelectedShape : function () { + var sPos = this._line2d.getFrom(); + var tPos = this._line2d.getTo(); + var ctrlPoints = this._line2d.getControlPoints(); + this._focusShape.setFrom(sPos.x, sPos.y); + this._focusShape.setTo(tPos.x, tPos.y); + var shapeCtrlPoints = this._focusShape.getControlPoints(); + shapeCtrlPoints[0].x = ctrlPoints[0].x; + shapeCtrlPoints[0].y = ctrlPoints[0].y; + shapeCtrlPoints[1].x = ctrlPoints[1].x; + shapeCtrlPoints[1].y = ctrlPoints[1].y; + this._focusShape.updateLine(); + //this._focusShape.setSrcControlPoint(ctrlPoints[0]); + //this._focusShape.setDestControlPoint(ctrlPoints[1]); + }, - var line = this._line2d; - line.addEventListener(type, listener); -}; + addEventListener : function(type, listener) { + // Translate to web 2d events ... + if (type == 'onfocus') { + type = 'mousedown'; + } -mindplot.RelationshipLine.prototype.isOnFocus = function() -{ - return this._onFocus; -}; + var line = this._line2d; + line.addEventListener(type, listener); + }, -mindplot.RelationshipLine.prototype.isInWorkspace = function(){ - return this._isInWorkspace; -}; + isOnFocus : function() { + return this._onFocus; + }, -mindplot.RelationshipLine.prototype.setVisibility = function(value) -{ - mindplot.RelationshipLine.superClass.setVisibility.call(this,value); - this._endArrow.setVisibility(this._showEndArrow && value); - this._startArrow.setVisibility(this._showStartArrow && value); -}; + isInWorkspace : function() { + return this._isInWorkspace; + }, -mindplot.RelationshipLine.prototype.setOpacity = function(opacity){ - mindplot.RelationshipLine.superClass.setOpacity.call(this,opacity); - if(this._showEndArrow) - this._endArrow.setOpacity(opacity); - if(this._showStartArrow) - this._startArrow.setOpacity(opacity); -}; + setVisibility : function(value) { + mindplot.ConnectionLine.prototype.setVisibility.call(this, value); + this._endArrow.setVisibility(this._showEndArrow && value); + this._startArrow.setVisibility(this._showStartArrow && value); + }, -mindplot.RelationshipLine.prototype.setShowEndArrow = function(visible){ - this._showEndArrow = visible; - if(this._isInWorkspace) - this.redraw(); -}; + setOpacity : function(opacity) { + mindplot.ConnectionLine.prototype.setOpacity.call(this, opacity); + if (this._showEndArrow) + this._endArrow.setOpacity(opacity); + if (this._showStartArrow) + this._startArrow.setOpacity(opacity); + }, -mindplot.RelationshipLine.prototype.setShowStartArrow = function(visible){ - this._showStartArrow = visible; - if(this._isInWorkspace) - this.redraw(); -}; + setShowEndArrow : function(visible) { + this._showEndArrow = visible; + if (this._isInWorkspace) + this.redraw(); + }, -mindplot.RelationshipLine.prototype.isShowEndArrow = function(){ - return this._showEndArrow; -}; + setShowStartArrow : function(visible) { + this._showStartArrow = visible; + if (this._isInWorkspace) + this.redraw(); + }, -mindplot.RelationshipLine.prototype.isShowStartArrow = function(){ - return this._showStartArrow; -}; + isShowEndArrow : function() { + return this._showEndArrow; + }, -mindplot.RelationshipLine.prototype.setFrom = function(x,y){ - this._line2d.setFrom(x,y); - this._startArrow.setFrom(x,y); -}; + isShowStartArrow : function() { + return this._showStartArrow; + }, -mindplot.RelationshipLine.prototype.setTo = function(x,y){ - this._line2d.setTo(x,y); - this._endArrow.setFrom(x,y); -}; + setFrom : function(x, y) { + this._line2d.setFrom(x, y); + this._startArrow.setFrom(x, y); + }, -mindplot.RelationshipLine.prototype.setSrcControlPoint = function(control){ - this._line2d.setSrcControlPoint(control); - this._startArrow.setControlPoint(control); -}; + setTo : function(x, y) { + this._line2d.setTo(x, y); + this._endArrow.setFrom(x, y); + }, -mindplot.RelationshipLine.prototype.setDestControlPoint = function(control){ - this._line2d.setDestControlPoint(control); - this._endArrow.setControlPoint(control); -}; + setSrcControlPoint : function(control) { + this._line2d.setSrcControlPoint(control); + this._startArrow.setControlPoint(control); + }, -mindplot.RelationshipLine.prototype.getControlPoints = function(){ - return this._line2d.getControlPoints(); -}; + setDestControlPoint : function(control) { + this._line2d.setDestControlPoint(control); + this._endArrow.setControlPoint(control); + }, -mindplot.RelationshipLine.prototype.isSrcControlPointCustom = function(){ - return this._line2d.isSrcControlPointCustom(); -}; + getControlPoints : function() { + return this._line2d.getControlPoints(); + }, -mindplot.RelationshipLine.prototype.isDestControlPointCustom = function(){ - return this._line2d.isDestControlPointCustom(); -}; + isSrcControlPointCustom : function() { + return this._line2d.isSrcControlPointCustom(); + }, -mindplot.RelationshipLine.prototype.setIsSrcControlPointCustom = function(isCustom){ - this._line2d.setIsSrcControlPointCustom(isCustom); -}; + isDestControlPointCustom : function() { + return this._line2d.isDestControlPointCustom(); + }, -mindplot.RelationshipLine.prototype.setIsDestControlPointCustom = function(isCustom){ - this._line2d.setIsDestControlPointCustom(isCustom); -}; + setIsSrcControlPointCustom : function(isCustom) { + this._line2d.setIsSrcControlPointCustom(isCustom); + }, + + setIsDestControlPointCustom : function(isCustom) { + this._line2d.setIsDestControlPointCustom(isCustom); + }}); -mindplot.RelationshipLine.type = "RelationshipLine"; \ No newline at end of file +mindplot.RelationshipLine.type = "RelationshipLine"; +mindplot.RelationshipLine.getStrokeColor = function() { + return '#9b74e6'; +} diff --git a/mindplot/src/main/javascript/RelationshipModel.js b/mindplot/src/main/javascript/RelationshipModel.js index f1d7263c..9cf7edad 100644 --- a/mindplot/src/main/javascript/RelationshipModel.js +++ b/mindplot/src/main/javascript/RelationshipModel.js @@ -1,116 +1,113 @@ /* -* 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.RelationshipModel = function(fromNode, toNode) -{ - $assert(fromNode, 'from node type can not be null'); - $assert(toNode, 'to node type can not be 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.RelationshipModel = new Class({ + initialize:function(fromNode, toNode) { + $assert(fromNode, 'from node type can not be null'); + $assert(toNode, 'to node type can not be null'); - this._id = mindplot.RelationshipModel._nextUUID(); - this._fromNode = fromNode; - this._toNode = toNode; - this._lineType=mindplot.ConnectionLine.SIMPLE_CURVED; - this._srcCtrlPoint=null; - this._destCtrlPoint=null; - this._endArrow=true; - this._startArrow=false; - this._ctrlPointRelative=false; + this._id = mindplot.RelationshipModel._nextUUID(); + this._fromNode = fromNode; + this._toNode = toNode; + this._lineType = mindplot.ConnectionLine.SIMPLE_CURVED; + this._srcCtrlPoint = null; + this._destCtrlPoint = null; + this._endArrow = true; + this._startArrow = false; + }, -}; + getFromNode : function() { + return this._fromNode; + }, -mindplot.RelationshipModel.prototype.getFromNode=function(){ - return this._fromNode; -}; + getToNode : function() { + return this._toNode; + }, -mindplot.RelationshipModel.prototype.getToNode=function(){ - return this._toNode; -}; + getId : function() { + return this._id; + }, -mindplot.RelationshipModel.prototype.getId=function(){ - return this._id; -}; + getLineType : function() { + return this._lineType; + }, -mindplot.RelationshipModel.prototype.getLineType = function(){ - return this._lineType; -}; + setLineType : function(lineType) { + this._lineType = lineType; + }, -mindplot.RelationshipModel.prototype.setLineType = function(lineType){ - this._lineType = lineType; -}; + getSrcCtrlPoint : function() { + return this._srcCtrlPoint; + }, -mindplot.RelationshipModel.prototype.getSrcCtrlPoint= function(){ - return this._srcCtrlPoint; -}; + setSrcCtrlPoint : function(srcCtrlPoint) { + this._srcCtrlPoint = srcCtrlPoint; + }, -mindplot.RelationshipModel.prototype.setSrcCtrlPoint= function(srcCtrlPoint){ - this._srcCtrlPoint = srcCtrlPoint; -}; + getDestCtrlPoint : function() { + return this._destCtrlPoint; + }, -mindplot.RelationshipModel.prototype.getDestCtrlPoint= function(){ - return this._destCtrlPoint; -}; + setDestCtrlPoint : function(destCtrlPoint) { + this._destCtrlPoint = destCtrlPoint; + }, -mindplot.RelationshipModel.prototype.setDestCtrlPoint= function(destCtrlPoint){ - this._destCtrlPoint = destCtrlPoint; -}; + getEndArrow : function() { + return this._endArrow; + }, -mindplot.RelationshipModel.prototype.getEndArrow= function(){ - return this._endArrow; -}; + setEndArrow : function(endArrow) { + this._endArrow = endArrow; + }, -mindplot.RelationshipModel.prototype.setEndArrow= function(endArrow){ - this._endArrow = endArrow; -}; + getStartArrow : function() { + return this._startArrow; + }, -mindplot.RelationshipModel.prototype.getStartArrow= function(){ - return this._startArrow; -}; + setStartArrow : function(startArrow) { + this._startArrow = startArrow; + }, -mindplot.RelationshipModel.prototype.setStartArrow= function(startArrow){ - this._startArrow = startArrow; -}; + clone : function(model) { + var result = new mindplot.RelationshipModel(this._fromNode, this._toNode); + result._id = this._id; + result._lineType = this._lineType; + result._srcCtrlPoint = this._srcCtrlPoint; + result._destCtrlPoint = this._destCtrlPoint; + result._endArrow = this._endArrow; + result._startArrow = this._startArrow; + return result; + }, + + inspect : function() { + return '(fromNode:' + this.getFromNode().getId() + ' , toNode: ' + this.getToNode().getId() + ')'; + } +}); -mindplot.RelationshipModel.prototype.clone = function(model){ - var result = new mindplot.RelationshipModel(this._fromNode, this._toNode); - result._id = this._id; - result._lineType = this._lineType; - result._srcCtrlPoint = this._srcCtrlPoint; - result._destCtrlPoint = this._destCtrlPoint; - result._endArrow = this._endArrow; - result._startArrow = this._startArrow; - return result; -}; /** * @todo: This method must be implemented. */ -mindplot.RelationshipModel._nextUUID = function() -{ - if (!$defined(this._uuid)) - { +mindplot.RelationshipModel._nextUUID = function() { + if (!$defined(this._uuid)) { this._uuid = 0; } this._uuid = this._uuid + 1; return this._uuid; -}; +} - -mindplot.RelationshipModel.prototype.inspect = function() -{ - return '(fromNode:' + this.getFromNode().getId() + ' , toNode: ' + this.getToNode().getId() + ')'; -}; diff --git a/mindplot/src/main/javascript/ScreenManager.js b/mindplot/src/main/javascript/ScreenManager.js index a5220b7a..1ca5364c 100644 --- a/mindplot/src/main/javascript/ScreenManager.js +++ b/mindplot/src/main/javascript/ScreenManager.js @@ -1,140 +1,134 @@ /* -* 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 = function(width, height, divElement) -{ - this._divContainer = divElement; - this._offset = {x:0,y:0}; -}; - -mindplot.ScreenManager.prototype.setScale = function(scale) -{ - $assert($defined(scale), 'Screen scale can not be null'); - this._workspaceScale = scale; -}; - -mindplot.ScreenManager.prototype.addEventListener=function(event, listener){ - $(this._divContainer).addEvent(event, listener); -}; - -mindplot.ScreenManager.prototype.removeEventListener=function(event, listener){ - $(this._divContainer).removeEvent(event, listener); -}; - -mindplot.ScreenManager.prototype.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}; -}; - -mindplot.ScreenManager.prototype.getWorkspaceIconPosition = function(e) -{ - // Retrive 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}; -}; - -mindplot.ScreenManager.prototype.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 + * 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.prototype._getMousePosition = function(event) -{ - return core.Utils.getMousePosition(event); -}; -mindplot.ScreenManager.prototype.getContainer = function() -{ - return this._divContainer; -}; +mindplot.ScreenManager = new Class({ + initialize:function(width, height, divElement) { + $assert(divElement, "can not be null"); + this._divContainer = divElement; + this._offset = {x:0,y:0}; + }, -mindplot.ScreenManager.prototype.setOffset = function(x, y) -{ - this._offset.x = x; - this._offset.y = y; -}; + 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; + }}); diff --git a/mindplot/src/main/javascript/SingleCommandDispatcher.js b/mindplot/src/main/javascript/SingleCommandDispatcher.js index 0750ef81..7093aa51 100644 --- a/mindplot/src/main/javascript/SingleCommandDispatcher.js +++ b/mindplot/src/main/javascript/SingleCommandDispatcher.js @@ -16,10 +16,10 @@ * limitations under the License. */ -mindplot.SingleCommandDispatcher = new Class({ +mindplot.SingleCommandDispatcher = new Class( +{ Extends:mindplot.BaseCommandDispatcher, - initialize: function() - { + initialize: function() { }, addIconToTopic: function() { diff --git a/mindplot/src/main/javascript/TextEditor.js b/mindplot/src/main/javascript/TextEditor.js index b44abfb9..cb7a5fd0 100644 --- a/mindplot/src/main/javascript/TextEditor.js +++ b/mindplot/src/main/javascript/TextEditor.js @@ -17,13 +17,12 @@ */ mindplot.TextEditor = new Class({ - initialize:function(designer,actionRunner) - { + initialize:function(designer, actionRunner) { this._designer = designer; this._screenManager = designer.getWorkSpace().getScreenManager(); this._container = this._screenManager.getContainer(); this._actionRunner = actionRunner; - this._isVisible=false; + this._isVisible = false; //Create editor ui this._createUI(); @@ -31,7 +30,8 @@ mindplot.TextEditor = new Class({ this._addListeners(); }, - _createUI:function(){ + + _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); @@ -40,21 +40,19 @@ mindplot.TextEditor = new Class({ 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(){ + + _addListeners:function() { var elem = this; - this.applyChanges=true; + this.applyChanges = true; this.inputText.onkeyup = function (evt) { var event = new Event(evt); var key = event.key; - switch(key) - { + switch (key) { case 'esc': - elem.applyChanges=false; + elem.applyChanges = false; case 'enter': - var executor = function(editor) - { - return function() - { + var executor = function(editor) { + return function() { elem.lostFocus(true); $(document.documentElement).fireEvent('focus'); }; @@ -63,13 +61,12 @@ mindplot.TextEditor = new Class({ break; default: - var span =$('spanText'); + 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)) - { + input.size = size; + if (span.offsetWidth > (parseInt(elem._myOverlay.style.width) - 100)) { elem._myOverlay.style.width = (span.offsetWidth + 100) + "px"; } break; @@ -84,18 +81,16 @@ mindplot.TextEditor = new Class({ var elem = this; var onComplete = function() { this._myOverlay.setStyle('display', "none"); - this._isVisible=false; + this._isVisible = false; this.inputText.setStyle('opacity', 1); this.setPosition(0, 0); - if (elem._currentNode != null) - { + if (elem._currentNode != null) { this._currentNode.getTextShape().setVisibility(true); - if(this.applyChanges) - { + if (this.applyChanges) { this._updateNode(); } - this.applyChanges=true; + this.applyChanges = true; this._currentNode = null; } @@ -104,76 +99,69 @@ mindplot.TextEditor = new Class({ this.fx = new Fx.Tween(this.inputText, {property: 'opacity', duration: 10}); this.fx.addEvent('onComplete', onComplete.bind(this)); }, - lostFocusEvent : function () - { + + lostFocusEvent : function () { this.fx.options.duration = 10; this.fx.start(1, 0); //myAnim.animate(); }, - isVisible : function () - { + + isVisible : function () { return this._isVisible; }, - getFocusEvent: function (node) - { + + getFocusEvent: function (node) { //console.log('focus event'); - if (this.isVisible()) - { + if (this.isVisible()) { this.getFocusEvent.delay(10, this); } - else - { + 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()) - { + 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 commandFunc = function(topic, value) { var result = topic.getText(); topic.setText(value); return result; }; - var command = new mindplot.commands.GenericFunctionCommand(commandFunc,text,[topicId]); + var command = new mindplot.commands.GenericFunctionCommand(commandFunc, text, [topicId]); this._actionRunner.execute(command); } }, - listenEventOnNode : function(topic, eventName, stopPropagation) - { + + 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 ]); + 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)) - { + if (stopPropagation) { + if ($defined(event.stopPropagation)) { event.stopPropagation(true); - } else - { + } else { event.cancelBubble = true; } } } }); }, - init : function (nodeGraph) - { + + init : function (nodeGraph) { //console.log('init method'); nodeGraph.getTextShape().setVisibility(false); this._currentNode = nodeGraph; @@ -181,12 +169,11 @@ mindplot.TextEditor = new Class({ //set Editor Style var nodeText = nodeGraph.getTextShape(); var text; - var selectText=true; - if(this.initialText && this.initialText!="") - { + var selectText = true; + if (this.initialText && this.initialText != "") { text = this.initialText; - this.initialText=null; - selectText=false; + this.initialText = null; + selectText = false; } else text = nodeText.getText(); @@ -202,10 +189,8 @@ mindplot.TextEditor = new Class({ //set editor's initial size var editor = this; - var executor = function(editor) - { - return function() - { + 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(); @@ -216,17 +201,15 @@ mindplot.TextEditor = new Class({ var textHeight = editor._currentNode.getTextShape().getHeight(); var iconGroup = editor._currentNode.getIconGroup(); var iconGroupSize; - if($chk(iconGroup)) - { + if ($chk(iconGroup)) { iconGroupSize = editor._currentNode.getIconGroup().getSize(); } - else - { + 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.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); @@ -240,24 +223,20 @@ mindplot.TextEditor = new Class({ setTimeout(executor(this), 10); //console.log('init done'); }, - setStyle : function (fontStyle) - { + + setStyle : function (fontStyle) { var inputField = $("inputText"); var spanField = $("spanText"); - if (!$defined(fontStyle.font)) - { + if (!$defined(fontStyle.font)) { fontStyle.font = "Arial"; } - if (!$defined(fontStyle.style)) - { + if (!$defined(fontStyle.style)) { fontStyle.style = "normal"; } - if (!$defined(fontStyle.weight)) - { + if (!$defined(fontStyle.weight)) { fontStyle.weight = "normal"; } - if (!$defined(fontStyle.size)) - { + if (!$defined(fontStyle.size)) { fontStyle.size = 12; } inputField.style.fontSize = fontStyle.size + "px"; @@ -270,8 +249,8 @@ mindplot.TextEditor = new Class({ spanField.style.fontWeight = fontStyle.weight; spanField.style.fontSize = fontStyle.size + "px"; }, - setText : function(text) - { + + setText : function(text) { var inputField = $("inputText"); inputField.size = text.length + 1; //this._myOverlay.cfg.setProperty("width", (inputField.size * parseInt(inputField.style.fontSize) + 100) + "px"); @@ -280,12 +259,12 @@ mindplot.TextEditor = new Class({ spanField.innerHTML = text; inputField.value = text; }, - getText : function() - { + + getText : function() { return $('inputText').value; }, - setEditorSize : function (width, height, scale) - { + + 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"); @@ -293,17 +272,17 @@ mindplot.TextEditor = new Class({ //this._myOverlay.cfg.setProperty("height",this._size.height+"px"); this._myOverlay.style.height = this._size.height + "px"; }, - getSize : function () - { + + getSize : function () { return {width:$("spanText").offsetWidth,height:$("spanText").offsetHeight}; }, - setPosition : function (x, y, scale) - { + + setPosition : function (x, y, scale) { $(this._myOverlay).setStyles({top : y + "px", left: x + "px"}); //this._myOverlay.style.left = x + "px"; }, - showTextEditor : function(selectText) - { + + 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'; @@ -311,7 +290,7 @@ mindplot.TextEditor = new Class({ //myAnim.onComplete.subscribe(function(){ //elem._myOverlay.show(); elem._myOverlay.setStyle('display', "block"); - this._isVisible=true; + this._isVisible = true; //elem.cfg.setProperty("visible", false); //elem._myOverlay.cfg.setProperty("xy", [0, 0]); //elem._myOverlay.cfg.setProperty("visible", true); @@ -322,31 +301,25 @@ mindplot.TextEditor = new Class({ { var range = $('inputText').createTextRange(); var pos = $('inputText').value.length; - if(selectText) - { + if (selectText) { range.select(); range.move("character", pos); } - else - { + else { range.move("character", pos); range.select(); } } - else if(selectText) - { + else if (selectText) { $('inputText').setSelectionRange(0, $('inputText').value.length); } - var executor = function(editor) - { - return function() - { + var executor = function(editor) { + return function() { try { $('inputText').focus(); } - catch (e) - { + catch (e) { } }; @@ -356,35 +329,30 @@ mindplot.TextEditor = new Class({ //myAnim.animate(); }, - lostFocus : function(bothBrowsers) - { - if (this.isVisible()) - { + + 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)) - { + clickEvent : function(event) { + if (this.isVisible()) { + if ($defined(event.stopPropagation)) { event.stopPropagation(true); - } else - { + } else { event.cancelBubble = true; } event.preventDefault(); } }, - mouseDownEvent : function(event){ - if(this.isVisible()){ - if ($defined(event.stopPropagation)) - { + mouseDownEvent : function(event) { + if (this.isVisible()) { + if ($defined(event.stopPropagation)) { event.stopPropagation(true); - } else - { + } else { event.cancelBubble = true; } } diff --git a/mindplot/src/main/javascript/TextEditorFactory.js b/mindplot/src/main/javascript/TextEditorFactory.js index 0e7537b8..32ac8fdc 100644 --- a/mindplot/src/main/javascript/TextEditorFactory.js +++ b/mindplot/src/main/javascript/TextEditorFactory.js @@ -1,27 +1,27 @@ /* -* 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.TextEditorFactory={}; + * 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.TextEditorFactory = {}; -mindplot.TextEditorFactory.getTextEditorFromName = function(name){ +mindplot.TextEditorFactory.getTextEditorFromName = function(name) { var editorClass = null; - if(name == "RichTextEditor"){ + if (name == "RichTextEditor") { editorClass = mindplot.RichTextEditor; - }else { + } else { editorClass = mindplot.TextEditor; } return editorClass; diff --git a/mindplot/src/main/javascript/Tip.js b/mindplot/src/main/javascript/Tip.js index 0e1c634a..f06a2dce 100644 --- a/mindplot/src/main/javascript/Tip.js +++ b/mindplot/src/main/javascript/Tip.js @@ -1,114 +1,115 @@ /* -* 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. -*/ + * 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.Tip = function(divContainer){ - this.initialize(divContainer); -}; - -mindplot.Tip.prototype.initialize=function(divContainer){ - this.options={ - panel:null, - container:null, - divContainer:divContainer, - content:null, - onShowComplete:Class.empty, - onHideComplete:Class.empty, - width:null, - height:null, - form:null - }; +mindplot.Tip = new Class({ + initialize:function(divContainer) { + this.options = { + panel:null, + container:null, + divContainer:divContainer, + content:null, + onShowComplete:Class.empty, + onHideComplete:Class.empty, + width:null, + height:null, + form:null + }; this.buildTip(); - this._isMouseOver=false; - this._open=false; -}; + this._isMouseOver = false; + this._open = false; + }, -mindplot.Tip.prototype.buildTip=function(){ + buildTip : function() { var opts = this.options; var panel = new Element('div').addClass('bubbleContainer'); - if($chk(opts.height)) + if ($chk(opts.height)) panel.setStyle('height', opts.height); - if($chk(opts.width)) + if ($chk(opts.width)) panel.setStyle('width', opts.width); - if(!$chk(opts.divContainer)) - { - opts.divContainer=document.body; + if (!$chk(opts.divContainer)) { + opts.divContainer = document.body; } panel.injectTop(opts.divContainer); opts.panel = $(panel); - opts.panel.setStyle('opacity',0); - opts.panel.addEvent('mouseover',function(){this._isMouseOver=true;}.bind(this)); - opts.panel.addEvent('mouseleave',function(event){this.close(event);}.bindWithEvent(this));//this.close.bindWithEvent(this) + opts.panel.setStyle('opacity', 0); + opts.panel.addEvent('mouseover', function() { + this._isMouseOver = true; + }.bind(this)); + opts.panel.addEvent('mouseleave', function(event) { + this.close(event); + }.bindWithEvent(this));//this.close.bindWithEvent(this) -}; + }, -mindplot.Tip.prototype.click= function(event, el) { + click : function(event, el) { return this.open(event, el); -}; + }, -mindplot.Tip.prototype.open= function(event, content, source){ - this._isMouseOver=true; + open : function(event, content, source) { + this._isMouseOver = true; this._evt = new Event(event); - this.doOpen.delay(500, this,[content,source]); -}; + this.doOpen.delay(500, this, [content,source]); + }, -mindplot.Tip.prototype.doOpen= function(content, source){ - if($chk(this._isMouseOver) &&!$chk(this._open) && !$chk(this._opening)) - { - this._opening=true; + doOpen : function(content, source) { + if ($chk(this._isMouseOver) && !$chk(this._open) && !$chk(this._opening)) { + this._opening = true; var container = new Element('div'); $(content).inject(container); - this.options.content=content; - this.options.container=container; + this.options.content = content; + this.options.container = container; $(this.options.container).inject(this.options.panel); - this.init(this._evt,source); - $(this.options.panel).effect('opacity',{duration:500, onComplete:function(){this._open=true; this._opening = false;}.bind(this)}).start(0,100); + this.init(this._evt, source); + $(this.options.panel).effect('opacity', {duration:500, onComplete:function() { + this._open = true; + this._opening = false; + }.bind(this)}).start(0, 100); } -}; + }, -mindplot.Tip.prototype.updatePosition=function(event){ + updatePosition : function(event) { this._evt = new Event(event); -}; + }, -mindplot.Tip.prototype.close=function(event){ - this._isMouseOver=false; - this.doClose.delay(50,this,new Event(event)); -}; + close : function(event) { + this._isMouseOver = false; + this.doClose.delay(50, this, new Event(event)); + }, -mindplot.Tip.prototype.doClose=function(event){ + doClose : function(event) { - if(!$chk(this._isMouseOver) && $chk(this._opening)) - this.doClose.delay(500,this,this._evt); + if (!$chk(this._isMouseOver) && $chk(this._opening)) + this.doClose.delay(500, this, this._evt); - if(!$chk(this._isMouseOver) && $chk(this._open)) - { + if (!$chk(this._isMouseOver) && $chk(this._open)) { this.forceClose(); } -}; + }, -mindplot.Tip.prototype.forceClose=function(){ - this.options.panel.effect('opacity',{duration:100, onComplete:function(){ - this._open=false; + forceClose : function() { + this.options.panel.effect('opacity', {duration:100, onComplete:function() { + this._open = false; $(this.options.panel).setStyles({left:0,top:0}); $(this.options.container).dispose(); - }.bind(this)}).start(100,0); -}; + }.bind(this)}).start(100, 0); + }, -mindplot.Tip.prototype.init=function(event,source){ + init : function(event, source) { var opts = this.options; var coordinates = $(opts.panel).getCoordinates(); var width = coordinates.width; //not total width, but close enough @@ -124,21 +125,21 @@ mindplot.Tip.prototype.init=function(event,source){ this.buildTip(); $(this.options.container).inject(this.options.panel); this.moveTopic(offset, $(opts.panel).getCoordinates().height); -}; + }, -mindplot.Tip.prototype.moveTopic=function(offset, panelHeight){ + moveTopic : function(offset, panelHeight) { var opts = this.options; var width = $(opts.panel).getCoordinates().width; - $(opts.panel).setStyles({left:offset.x - (width/2), top:offset.y - (panelHeight*2) + 35}); -}; + $(opts.panel).setStyles({left:offset.x - (width / 2), top:offset.y - (panelHeight * 2) + 35}); + } -mindplot.Tip.getInstance = function(divContainer) -{ +}); + +mindplot.Tip.getInstance = function(divContainer) { var result = mindplot.Tip.instance; - if(!$defined(result)) - { + if (!$defined(result)) { mindplot.Tip.instance = new mindplot.Tip(divContainer); result = mindplot.Tip.instance; } return result; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/mindplot/src/main/javascript/VariableDistanceBoard.js b/mindplot/src/main/javascript/VariableDistanceBoard.js index cf80cd58..03244c1c 100644 --- a/mindplot/src/main/javascript/VariableDistanceBoard.js +++ b/mindplot/src/main/javascript/VariableDistanceBoard.js @@ -17,197 +17,197 @@ */ 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); - }, + 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); + 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; + 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 { - upperLimit = offset - distance; + 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; } - result = this.createBoardEntry(lowerLimit, upperLimit, order); + // Update current entry. + currentEntry = tempEntry; + currentEntry.setLowerLimit(lowerLimit); + currentEntry.setUpperLimit(upperLimit); + + var order = this._indexToOrder(index); + currentEntry.setOrder(order); } - return result; - }, - createBoardEntry:function(lowerLimit, upperLimit, order) { - return new mindplot.BoardEntry(lowerLimit, upperLimit, order); - }, + // Have I found the item? + if (currentEntry.isCoordinateIn(pos.y)) { + break; + } + i++; + } + return currentEntry; + }, - updateReferencePoint:function(position) { - var entries = this._entries; - var referencePoint = this._referencePoint; + update:function(entry) { + $assert(entry, 'Entry can not be null'); + var order = entry.getOrder(); + var index = this._orderToIndex(order); - // Update zero entry current position. - this._referencePoint = position.clone(); - var yOffset = position.y - referencePoint.y; + this._entries.set(index, entry); - 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); + }, + freeEntry:function(entry) { + var order = entry.getOrder(); + var entries = this._entries; - // Update topic position ... - if (!entry.isAvailable()) { - var topic = entry.getTopic(); - var topicPosition = topic.getPosition(); - topicPosition.y = topicPosition.y + yOffset; + var index = this._orderToIndex(order); + var indexSign = Math.sign(index); - // MainTopicToCentral must be positioned based on the referencePoint. - var xOffset = position.x - referencePoint.x; - topicPosition.x = topicPosition.x + xOffset; + 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); + } - topic.setPosition(topicPosition); - } + // 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); } - }, - - lookupEntryByPosition:function(pos) { - $assert($defined(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(); + currentTopic = topic; + i++; } - }); \ No newline at end of file + // 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(); + } + +}); \ No newline at end of file diff --git a/mindplot/src/main/javascript/Workspace.js b/mindplot/src/main/javascript/Workspace.js index 487eb110..4a4852a7 100644 --- a/mindplot/src/main/javascript/Workspace.js +++ b/mindplot/src/main/javascript/Workspace.js @@ -150,8 +150,7 @@ mindplot.Workspace = new Class({ var screenManager = this._screenManager; this._dragging = true; var mWorkspace = this; - var mouseDownListener = function(event) - { + var mouseDownListener = function(event) { if (!$defined(workspace.mouseMoveListener)) { if (mWorkspace.isWorkspaceEventsEnabled()) { mWorkspace.enableWorkspaceEvents(false); diff --git a/mindplot/src/main/javascript/XMLMindmapSerializerFactory.js b/mindplot/src/main/javascript/XMLMindmapSerializerFactory.js index abc48f7d..6a891ce1 100644 --- a/mindplot/src/main/javascript/XMLMindmapSerializerFactory.js +++ b/mindplot/src/main/javascript/XMLMindmapSerializerFactory.js @@ -1,45 +1,45 @@ /* -* 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. -*/ + * 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.XMLMindmapSerializerFactory = {}; -mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap = function(mindmap){ +mindplot.XMLMindmapSerializerFactory.getSerializerFromMindmap = function(mindmap) { return mindplot.XMLMindmapSerializerFactory.getSerializer(mindmap.getVersion()); }; -mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument = function(domDocument){ +mindplot.XMLMindmapSerializerFactory.getSerializerFromDocument = function(domDocument) { var rootElem = domDocument.documentElement; return mindplot.XMLMindmapSerializerFactory.getSerializer(rootElem.getAttribute("version")) }; -mindplot.XMLMindmapSerializerFactory.getSerializer = function(version){ - if(!$defined(version)){ +mindplot.XMLMindmapSerializerFactory.getSerializer = function(version) { + if (!$defined(version)) { version = mindplot.ModelCodeName.BETA; } var codeNames = mindplot.XMLMindmapSerializerFactory._codeNames; var found = false; var serializer = null; - for(var i=0; i0){ + // Create Relationships + var relationships = mindmap.getRelationships(); + if (relationships.length > 0) { // var relationshipDom=document.createElement("relationships"); // mapElem.appendChild(relationshipDom); - for (var j = 0; j