Fix zoom.

This commit is contained in:
Paulo Veiga 2011-08-25 00:01:17 -03:00
parent 046789bb6a
commit b9ff7f9c03
2 changed files with 112 additions and 126 deletions

View File

@ -16,8 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
core.Monitor = function(fadeElement, logContentElem) core.Monitor = new Class({
{ initialize : function(fadeElement, logContentElem) {
$assert(fadeElement, "fadeElement can not be null"); $assert(fadeElement, "fadeElement can not be null");
$assert(logContentElem, "logContentElem can not be null"); $assert(logContentElem, "logContentElem can not be null");
@ -29,40 +29,34 @@ core.Monitor = function(fadeElement, logContentElem)
this._fxOpacity = fadeElement.effect('opacity', { duration: 6000 }); this._fxOpacity = fadeElement.effect('opacity', { duration: 6000 });
}; },
core.Monitor.prototype._logMessage = function(msg, msgKind) _logMessage : function(msg, msgKind) {
{
this._fxOpacity.clearTimer(); this._fxOpacity.clearTimer();
if (msgKind == core.Monitor.MsgKind.ERROR) if (msgKind == core.Monitor.MsgKind.ERROR) {
{
msg = "<div id='small_error_icon'>" + msg + "</div>"; msg = "<div id='small_error_icon'>" + msg + "</div>";
} }
this._currentMessage = msg; this._currentMessage = msg;
this._fxOpacity.start(1, 0); this._fxOpacity.start(1, 0);
this._logContentElem.innerHTML = msg; this._logContentElem.innerHTML = msg;
}; },
core.Monitor.prototype.logError = function(userMsg) logError : function(userMsg) {
{
this.logMessage(userMsg, core.Monitor.MsgKind.ERROR); this.logMessage(userMsg, core.Monitor.MsgKind.ERROR);
}; console.log(userMsg);
},
core.Monitor.prototype.logFatal = function(userMsg) logFatal : function(userMsg) {
{
this.logMessage(userMsg, core.Monitor.MsgKind.FATAL); this.logMessage(userMsg, core.Monitor.MsgKind.FATAL);
}; },
core.Monitor.prototype.logMessage = function(msg, msgKind) logMessage : function(msg, msgKind) {
{ if (!msgKind) {
if (!msgKind)
{
msgKind = core.Monitor.MsgKind.INFO; msgKind = core.Monitor.MsgKind.INFO;
} }
if (msgKind == core.Monitor.MsgKind.FATAL) if (msgKind == core.Monitor.MsgKind.FATAL) {
{
// In this case, a modal dialog must be shown... No recovery is possible. // In this case, a modal dialog must be shown... No recovery is possible.
new Windoo.Alert(msg, new Windoo.Alert(msg,
{ {
@ -72,28 +66,23 @@ core.Monitor.prototype.logMessage = function(msg, msgKind)
} }
} }
}); });
} else } else {
{
var messages = this.pendingMessages; var messages = this.pendingMessages;
var monitor = this; var monitor = this;
if (!this.executer) if (!this.executer) {
{
// Log current message ... // Log current message ...
monitor._logMessage(msg, msgKind); monitor._logMessage(msg, msgKind);
// Start worker thread ... // Start worker thread ...
var disptacher = function() var disptacher = function() {
{ if (messages.length > 0) {
if (messages.length > 0)
{
var msgToDisplay = messages.shift(); var msgToDisplay = messages.shift();
monitor._logMessage(msgToDisplay); monitor._logMessage(msgToDisplay);
} }
// Stop thread? // Stop thread?
if (messages.length == 0) if (messages.length == 0) {
{
$clear(monitor.executer); $clear(monitor.executer);
monitor.executer = null; monitor.executer = null;
monitor._fxOpacity.hide(); monitor._fxOpacity.hide();
@ -101,30 +90,29 @@ core.Monitor.prototype.logMessage = function(msg, msgKind)
} }
}; };
this.executer = disptacher.periodical(600); this.executer = disptacher.periodical(600);
} else } else {
{ if (this._currentMessage != msg) {
if (this._currentMessage != msg)
{
messages.push(msg); messages.push(msg);
} }
} }
} }
}; }
});
core.Monitor.setInstance = function(monitor) core.Monitor.setInstance = function(monitor) {
{
this.monitor = monitor; this.monitor = monitor;
}; };
core.Monitor.getInstance = function() core.Monitor.getInstance = function() {
{
var result = this.monitor; var result = this.monitor;
if (result == null) if (result == null) {
{
result = { result = {
logError: function() { logError: function(msg) {
console.log(msg)
}, },
logMessage: function() {
logMessage: function(msg) {
console.log(msg)
} }
}; };
} }

View File

@ -30,15 +30,11 @@ mindplot.MindmapDesigner = new Class({
this._fireEvent("modelUpdate", event); this._fireEvent("modelUpdate", event);
}.bind(this)); }.bind(this));
mindplot.ActionDispatcher.setInstance(this._actionDispatcher); mindplot.ActionDispatcher.setInstance(this._actionDispatcher);
// Initial Zoom
this._zoom = profile.zoom;
this._model = new mindplot.DesignerModel(profile); this._model = new mindplot.DesignerModel(profile);
// Init Screen manager.. // Init Screen manager..
var screenManager = new mindplot.ScreenManager(profile.width, profile.height, divElement); var screenManager = new mindplot.ScreenManager(profile.width, profile.height, divElement);
this._workspace = new mindplot.Workspace(profile, screenManager, this._zoom); this._workspace = new mindplot.Workspace(profile, screenManager, this._model.getZoom());
this._readOnly = profile.readOnly ? true : false; this._readOnly = profile.readOnly ? true : false;
// Init layout managers ... // Init layout managers ...
@ -198,22 +194,6 @@ mindplot.MindmapDesigner = new Class({
}, },
zoomOut : function(factor) {
if (!factor)
factor = 1.2;
var model = this.getModel();
var scale = model.getZoom() * factor;
if (scale <= 4) {
model.setZoom(scale);
this._workspace.setZoom(this._zoom);
}
else {
core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?');
}
},
selectAll : function() { selectAll : function() {
var model = this.getModel(); var model = this.getModel();
var objects = model.getObjects(); var objects = model.getObjects();
@ -229,15 +209,33 @@ mindplot.MindmapDesigner = new Class({
}); });
}, },
zoomOut : function(factor) {
if (!factor)
factor = 1.2;
var model = this.getModel();
var scale = model.getZoom() * factor;
if (scale <= 1.9) {
model.setZoom(scale);
this._workspace.setZoom(scale);
}
else {
core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?');
}
},
zoomIn : function(factor) { zoomIn : function(factor) {
if (!factor) if (!factor)
factor = 1.2; factor = 1.2;
var model = this.getModel(); var model = this.getModel();
var scale = model.getZoom() / factor; var scale = model.getZoom() / factor;
if (scale >= 0.3) { if (scale >= 0.3) {
model.setZoom(scale); model.setZoom(scale);
this._workspace.setZoom(this._zoom); this._workspace.setZoom(scale);
} }
else { else {
core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?'); core.Monitor.getInstance().logMessage('Sorry, no more zoom can be applied. \n Why do you need more?');
@ -383,7 +381,7 @@ mindplot.MindmapDesigner = new Class({
var persistantManager = mindplot.PersistanceManager; var persistantManager = mindplot.PersistanceManager;
var mindmap = this._mindmap; var mindmap = this._mindmap;
var properties = {zoom:this._zoom, layoutManager:this._layoutManager.getClassName()}; var properties = {zoom:this.getModel().getZoom(), layoutManager:this._layoutManager.getClassName()};
persistantManager.save(mindmap, properties, onSavedHandler, saveHistory); persistantManager.save(mindmap, properties, onSavedHandler, saveHistory);
this._fireEvent("save", {type:saveHistory}); this._fireEvent("save", {type:saveHistory});