Have Base.read() clone owned objects such as SegmentPoint or LinkedPoint.

This commit is contained in:
Jürg Lehni 2011-05-08 13:38:09 +01:00
parent 926fffee4a
commit 2f4f003873
2 changed files with 22 additions and 15 deletions

View file

@ -59,8 +59,13 @@ Base.inject({
var start = start || 0, var start = start || 0,
length = length || list.length - start; length = length || list.length - start;
var obj = list[start]; var obj = list[start];
// If the class defines _readNull, return null when nothing was provided // As a convention, do not return objects that are owned, e.g.
if (obj instanceof this // LinkedPoint or SegmentPoint, although they are instances of Point,
// since they override properties with beans. Convert these to pure
// Points instead, further down.
if (obj && !obj._owner && obj instanceof this
// If the class defines _readNull, return null when nothing
// was provided
|| this.prototype._readNull && obj == null && length <= 1) || this.prototype._readNull && obj == null && length <= 1)
return obj; return obj;
obj = new this(this.dont); obj = new this(this.dont);
@ -158,21 +163,23 @@ Base.inject({
//#include "color/Gradient.js" //#include "color/Gradient.js"
//#include "color/GradientStop.js" //#include "color/GradientStop.js"
//#ifdef BROWSER
//#include "browser/DomElement.js"
//#include "browser/DomEvent.js"
//#include "ui/Event.js"
//#include "ui/KeyEvent.js"
//#include "ui/Key.js"
//#include "tool/ToolEvent.js" //#include "tool/ToolEvent.js"
//#include "tool/ToolHandler.js" //#include "tool/ToolHandler.js"
//#include "tool/Tool.js" //#include "tool/Tool.js"
//#ifdef BROWSER
//#include "browser/DomElement.js"
//#include "browser/DomEvent.js"
//#endif // BROWSER //#endif // BROWSER
//#include "util/CanvasProvider.js" //#include "util/CanvasProvider.js"
//#include "util/Numerical.js" //#include "util/Numerical.js"
//#include "util/PaperScript.js" //#include "util/PaperScript.js"
//#include "util/BlendMode.js" //#include "util/BlendMode.js"
//#ifdef BROWSER
//#include "ui/Key.js"
//#endif // BROWSER
}; };

View file

@ -24,7 +24,7 @@ var SegmentPoint = Point.extend({
set: function(x, y) { set: function(x, y) {
this._x = x; this._x = x;
this._y = y; this._y = y;
this._segment._changed(this); this._owner._changed(this);
return this; return this;
}, },
@ -34,7 +34,7 @@ var SegmentPoint = Point.extend({
setX: function(x) { setX: function(x) {
this._x = x; this._x = x;
this._segment._changed(this); this._owner._changed(this);
}, },
getY: function() { getY: function() {
@ -43,15 +43,15 @@ var SegmentPoint = Point.extend({
setY: function(y) { setY: function(y) {
this._y = y; this._y = y;
this._segment._changed(this); this._owner._changed(this);
}, },
setSelected: function(selected) { setSelected: function(selected) {
this._segment._setSelected(this, selected); this._owner._setSelected(this, selected);
}, },
isSelected: function() { isSelected: function() {
return this._segment._isSelected(this); return this._owner._isSelected(this);
}, },
statics: { statics: {
@ -65,7 +65,7 @@ var SegmentPoint = Point.extend({
var point = new SegmentPoint(SegmentPoint.dont); var point = new SegmentPoint(SegmentPoint.dont);
point._x = x; point._x = x;
point._y = y; point._y = y;
point._segment = segment; point._owner = segment;
return point; return point;
} }
} }