Fix flicker.

Remove more code.
This commit is contained in:
Paulo Veiga
2011-08-29 20:10:05 -03:00
parent d94414775e
commit c74d2de32d
11 changed files with 83 additions and 155 deletions

View File

@@ -66,10 +66,8 @@
<include>${basedir}/target/tmp/peer/svg/LinePeer-min.js</include>
<include>${basedir}/target/tmp/peer/svg/TahomaFont-min.js</include>
<include>${basedir}/target/tmp/peer/svg/VerdanaFont-min.js</include>
<include>${basedir}/target/tmp/Element-min.js</include>
<include>${basedir}/target/tmp/Elipse-min.js</include>
<include>${basedir}/target/tmp/EventDispatcher-min.js</include>
<include>${basedir}/target/tmp/Font-min.js</include>
<include>${basedir}/target/tmp/Group-min.js</include>
<include>${basedir}/target/tmp/Image-min.js</include>

View File

@@ -87,19 +87,7 @@ web2d.Element.prototype.positionRelativeTo = function(elem, options) {
*
*/
web2d.Element.prototype.addEvent = function(type, listener) {
if (!this._supportedEvents.include(type)) {
throw "Unsupported event type: " + type;
}
// Concat previous event listeners for a given type.
if (!this._dispatcherByEventType[type]) {
this._dispatcherByEventType[type] = new web2d.EventDispatcher(this);
var eventListener = this._dispatcherByEventType[type].eventListener;
this._peer.addEvent(type, eventListener);
}
this._dispatcherByEventType[type].addListener(type, listener);
this._peer.addEvent(type, listener);
};
/**
*
@@ -113,17 +101,7 @@ web2d.Element.prototype.addEvent = function(type, listener) {
* This interace will be invoked passing an event as argument and the 'this' referece in the function will be the element.
*/
web2d.Element.prototype.removeEvent = function(type, listener) {
var dispatcher = this._dispatcherByEventType[type];
if (dispatcher == null) {
throw "There is no listener previously registered";
}
var result = dispatcher.removeListener(type, listener);
// If there is not listeners, EventDispatcher must be removed.
if (dispatcher.getListenersCount() <= 0) {
this._peer.removeEvent(type, dispatcher.eventListener);
this._dispatcherByEventType[type] = null;
}
this._peer.removeEvent(type, listener);
};
/**

View File

@@ -85,12 +85,12 @@ web2d.peer.svg.ElementPeer.prototype.removeChild = function(elementPeer) {
*/
web2d.peer.svg.ElementPeer.prototype.addEvent = function(type, listener) {
this._native.addEventListener(type, listener, false);
this._native.addEvent(type, listener);
};
web2d.peer.svg.ElementPeer.prototype.removeEvent = function(type, listener) {
this._native.removeEventListener(type, listener, false);
this._native.removeEvent(type, listener);
};
web2d.peer.svg.ElementPeer.prototype.setSize = function(width, height) {

View File

@@ -1,26 +1,24 @@
/*
* 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.
*/
web2d.peer.svg.TextPeer = function()
{
web2d.peer.svg.TextPeer = function() {
var svgElement = window.document.createElementNS(this.svgNamespace, 'text');
web2d.peer.svg.ElementPeer.call(this, svgElement);
this._native.setAttribute("focusable", "false");
this._position = {x:0,y:0};
this._font = new web2d.Font("Arial", this);
};
@@ -29,24 +27,21 @@ objects.extend(web2d.peer.svg.TextPeer, web2d.peer.svg.ElementPeer);
//todo: use ths method to specify the maximum size of the text box
/*web2d.web2d.peer.svg.TextPeer.prototype.setSize = function(width, height)
{
web2d.web2d.peer.svg.TextPeer.superClass.setSize.call(this,width,height);
this._native.setAttribute('rx', width / 2);
this._native.setAttribute('ry', height /ose 2);
};
*/
{
web2d.web2d.peer.svg.TextPeer.superClass.setSize.call(this,width,height);
this._native.setAttribute('rx', width / 2);
this._native.setAttribute('ry', height /ose 2);
};
*/
web2d.peer.svg.TextPeer.prototype.appendChild = function(element)
{
web2d.peer.svg.TextPeer.prototype.appendChild = function(element) {
this._native.appendChild(element._native);
};
web2d.peer.svg.TextPeer.prototype.setText = function(text)
{
web2d.peer.svg.TextPeer.prototype.setText = function(text) {
text = core.Utils.escapeInvalidTags(text);
var child = this._native.firstChild;
if ($defined(child))
{
if ($defined(child)) {
this._native.removeChild(child);
}
this._text = text;
@@ -54,51 +49,42 @@ web2d.peer.svg.TextPeer.prototype.setText = function(text)
this._native.appendChild(textNode);
};
web2d.peer.svg.TextPeer.prototype.getText = function()
{
web2d.peer.svg.TextPeer.prototype.getText = function() {
return this._text;
};
web2d.peer.svg.TextPeer.prototype.setPosition = function(x, y)
{
web2d.peer.svg.TextPeer.prototype.setPosition = function(x, y) {
this._position = {x:x, y:y};
var height = this._font.getSize();
if($defined(this._parent) && $defined(this._native.getBBox))
if ($defined(this._parent) && $defined(this._native.getBBox))
height = this.getHeight();
var size = parseInt(height);
this._native.setAttribute('y', y+size*3/4);
this._native.setAttribute('y', y + size * 3 / 4);
//y+size/2
this._native.setAttribute('x', x);
};
web2d.peer.svg.TextPeer.prototype.getPosition = function()
{
web2d.peer.svg.TextPeer.prototype.getPosition = function() {
return this._position;
};
web2d.peer.svg.TextPeer.prototype.setFont = function(font, size, style, weight)
{
if ($defined(font))
{
web2d.peer.svg.TextPeer.prototype.setFont = function(font, size, style, weight) {
if ($defined(font)) {
this._font = new web2d.Font(font, this);
}
if ($defined(style))
{
if ($defined(style)) {
this._font.setStyle(style);
}
if ($defined(weight))
{
if ($defined(weight)) {
this._font.setWeight(weight);
}
if ($defined(size))
{
if ($defined(size)) {
this._font.setSize(size);
}
this._updateFontStyle();
};
web2d.peer.svg.TextPeer.prototype._updateFontStyle = function()
{
web2d.peer.svg.TextPeer.prototype._updateFontStyle = function() {
this._native.setAttribute('font-family', this._font.getFontFamily());
this._native.setAttribute('font-size', this._font.getGraphSize());
this._native.setAttribute('font-style', this._font.getStyle());
@@ -108,41 +94,34 @@ web2d.peer.svg.TextPeer.prototype._updateFontStyle = function()
this._native.xFontScale = scale.toFixed(1);
};
web2d.peer.svg.TextPeer.prototype.setColor = function(color)
{
web2d.peer.svg.TextPeer.prototype.setColor = function(color) {
this._native.setAttribute('fill', color);
};
web2d.peer.svg.TextPeer.prototype.getColor = function()
{
web2d.peer.svg.TextPeer.prototype.getColor = function() {
return this._native.getAttribute('fill');
};
web2d.peer.svg.TextPeer.prototype.setTextSize = function (size)
{
web2d.peer.svg.TextPeer.prototype.setTextSize = function (size) {
this._font.setSize(size);
this._updateFontStyle();
};
web2d.peer.svg.TextPeer.prototype.setContentSize = function(width, height)
{
web2d.peer.svg.TextPeer.prototype.setContentSize = function(width, height) {
this._native.xTextSize = width.toFixed(1) + "," + height.toFixed(1);
};
web2d.peer.svg.TextPeer.prototype.setStyle = function (style)
{
web2d.peer.svg.TextPeer.prototype.setStyle = function (style) {
this._font.setStyle(style);
this._updateFontStyle();
};
web2d.peer.svg.TextPeer.prototype.setWeight = function (weight)
{
web2d.peer.svg.TextPeer.prototype.setWeight = function (weight) {
this._font.setWeight(weight);
this._updateFontStyle();
};
web2d.peer.svg.TextPeer.prototype.setFontFamily = function (family)
{
web2d.peer.svg.TextPeer.prototype.setFontFamily = function (family) {
var oldFont = this._font;
this._font = new web2d.Font(family, this);
this._font.setSize(oldFont.getSize());
@@ -151,8 +130,7 @@ web2d.peer.svg.TextPeer.prototype.setFontFamily = function (family)
this._updateFontStyle();
};
web2d.peer.svg.TextPeer.prototype.getFont = function ()
{
web2d.peer.svg.TextPeer.prototype.getFont = function () {
return {
font:this._font.getFont(),
size:parseInt(this._font.getSize()),
@@ -161,28 +139,24 @@ web2d.peer.svg.TextPeer.prototype.getFont = function ()
};
};
web2d.peer.svg.TextPeer.prototype.setSize = function (size)
{
web2d.peer.svg.TextPeer.prototype.setSize = function (size) {
this._font.setSize(size);
this._updateFontStyle();
};
web2d.peer.svg.TextPeer.prototype.getWidth = function ()
{
web2d.peer.svg.TextPeer.prototype.getWidth = function () {
var computedWidth = this._native.getBBox().width;
var width = parseInt(computedWidth);
width = width + this._font.getWidthMargin();
return width;
};
web2d.peer.svg.TextPeer.prototype.getHeight = function ()
{
web2d.peer.svg.TextPeer.prototype.getHeight = function () {
var computedHeight = this._native.getBBox().height;
return parseInt(computedHeight);
};
web2d.peer.svg.TextPeer.prototype.getHtmlFontSize = function ()
{
web2d.peer.svg.TextPeer.prototype.getHtmlFontSize = function () {
return this._font.getHtmlSize();
};