Revision: 3508
http://vexi.svn.sourceforge.net/vexi/?rev=3508&view=rev
Author: clrg
Date: 2009-05-26 00:21:46 +0000 (Tue, 26 May 2009)
Log Message:
-----------
- Some cleanup of Box, remove [commented out] "lock" code
- Use JSString in core.Text
Modified Paths:
--------------
trunk/core/org.ibex.js/src/org/ibex/js/JSString.java
trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
trunk/core/org.vexi.core/src/org/vexi/core/Text.java
Modified: trunk/core/org.ibex.js/src/org/ibex/js/JSString.java
===================================================================
--- trunk/core/org.ibex.js/src/org/ibex/js/JSString.java 2009-05-25
23:54:55 UTC (rev 3507)
+++ trunk/core/org.ibex.js/src/org/ibex/js/JSString.java 2009-05-26
00:21:46 UTC (rev 3508)
@@ -14,10 +14,10 @@
public JS type() { return SC_string; }
public boolean equals(Object o) {
- if(o == this) return true;
- if(o instanceof JSString) {
+ if (o == this) return true;
+ if (o instanceof JSString) {
return ((JSString)o).s.equals(s);
- } else if(o instanceof JSNumber) {
+ } else if (o instanceof JSNumber) {
return o.equals(this);
} else {
return false;
@@ -28,7 +28,7 @@
static synchronized JS intern(String s) {
synchronized(internHash) {
JS js = (JS)internHash.get(s);
- if(js == null) internHash.put(s,js = new Intern(s));
+ if (js == null) internHash.put(s,js = new Intern(s));
return js;
}
}
@@ -39,5 +39,5 @@
public String coerceToString() { return s; }
- public String toString(){ return s; }
+ public String toString() { return s; }
}
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2009-05-25 23:54:55 UTC
(rev 3507)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp 2009-05-26 00:21:46 UTC
(rev 3508)
@@ -15,6 +15,7 @@
import org.ibex.js.JSArrayLike;
import org.ibex.js.JSU;
import org.ibex.js.JSExn;
+import org.ibex.js.JSString;
import org.ibex.js.Scheduler;
import org.ibex.util.Callable;
import org.ibex.util.Log;
@@ -134,7 +135,7 @@
private static final int TILE_IMAGE = 0x00000010;
private static final int MOUSEINSIDE = 0x00000020;
private static final int CURSOR = 0x00000040;
- //private static final int LOCK_CHILDREN = 0x00000080;
+ //private static final int UNUSED = 0x00000080;
private static final int CONSTRAIN = 0x00000100;
private static final int CONSTRAIN_DESCENDENT = 0x00000200;
@@ -366,12 +367,9 @@
box.justTriggerTraps(SC_fontsize,
Text.sizeToJS(box.text.pointsize));
}
int i=0;
- //boolean lock = !box.test(LOCK_CHILDREN);
- //if (lock) box.set(LOCK_CHILDREN);
for (Box b = box.getChild(i); b!=null; b=box.getChild(++i)) {
reflowTreeTextSize(box.getChild(i));
}
- //if (lock) box.clear(LOCK_CHILDREN);
}
/** used to invoke reflow on a box and it's children */
@@ -397,16 +395,13 @@
/** constrain box children then establish the minimum size of a box */
private void constrain() {
int i;
- //boolean lock = !test(LOCK_CHILDREN);
// reconstrain any children
if (test(CONSTRAIN_DESCENDENT)) {
- //if (lock) set(LOCK_CHILDREN);
for (Box c = getChild(i=0); c != null; c = getChild(++i)) {
if (!c.test(DISPLAY)) continue;
c.constrain();
}
- //if (lock) clear(LOCK_CHILDREN);
clear(CONSTRAIN_DESCENDENT);
}
@@ -415,7 +410,6 @@
// remember current size
int newwidth = 0, newheight = 0;
- //if (lock) set(LOCK_CHILDREN);
if (test(PACK)) {
//#repeat width/height HORIZONTAL/VERTICAL
// accumulate child contentwidth
@@ -441,7 +435,6 @@
newheight = max(newheight, c.contentheight);
}
}
- //if (lock) clear(LOCK_CHILDREN);
//#repeat width/height WIDTH/HEIGHT
if (test(CLIP)) {
@@ -487,14 +480,11 @@
placeChildren(clean);
if (test(PLACE_DESCENDENT)) {
clear(PLACE_DESCENDENT);
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
int i = 0;
for (Box child = getChild(0); child != null; child =
getChild(++i)) {
if (!child.test(DISPLAY)) continue;
child.place(clean && child.test(PLACE_CLEAN));
}
- //if (lock) clear(LOCK_CHILDREN);
}
} else clear(PLACE|PLACE_DESCENDENT);
set(PLACE_CLEAN);
@@ -503,8 +493,6 @@
private final void placeChildren(boolean clean) {
if (test(PLACE)) {
clear(PLACE);
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
// needed for later resize()
int child_width, child_height, i;
@@ -744,7 +732,6 @@
}
}
}
- //if (lock) clear(LOCK_CHILDREN);
}
}
@@ -789,7 +776,7 @@
int gap_y = height - text.height;
int text_x = globalx + (test(ALIGN_RIGHT) ? gap_x :
!test(ALIGN_LEFT) ? gap_x/2 : 0);
int text_y = globaly + (test(ALIGN_BOTTOM) ? gap_y :
!test(ALIGN_TOP) ? gap_y/2 : 0);
- text.font.rasterizeGlyphs(text.str, buf, text.color, text_x,
text_y, cx1, cy1, cx2, cy2);
+ text.font.rasterizeGlyphs(text.str.toString(), buf, text.color,
text_x, text_y, cx1, cy1, cx2, cy2);
}
//if (path != null) path.realize(Affine.translate(globalx,
globaly)).stroke(buf, 1, strokecolor);
@@ -1038,11 +1025,8 @@
private final void propagateLeave() throws JSExn {
clear(MOUSEINSIDE);
int i = treeSize()-1;
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
for (Box b = getChild(i); b != null; b = getChild(--i))
if (b.test(MOUSEINSIDE)) b.propagateLeave();
- //if (lock) clear(LOCK_CHILDREN);
if (test(LEAVE_TRAP)) justTriggerTraps(SC_Leave, JSU.T);
}
@@ -1058,8 +1042,6 @@
return true;
int i;
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
// absolute layout - allows for interruption by overlaying siblings
if (!test(PACK)) {
for (Box b = getChild(i=treeSize()-1); b != null; b =
getChild(--i)) {
@@ -1081,7 +1063,6 @@
else if (b.test(MOUSEINSIDE)) b.propagateLeave();
}
}
- //if (lock) clear(LOCK_CHILDREN);
// set cursor if applicable to this box
if (test(CURSOR)) {
@@ -1128,8 +1109,6 @@
return true;
int i;
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
// absolute layout - check all children
if (!test(PACK)) {
for (Box b = getChild(i=treeSize()-1); b != null; b =
getChild(--i)) {
@@ -1152,7 +1131,6 @@
}
}
}
- //if (lock) clear(LOCK_CHILDREN);
if (Interpreter.CASCADE_PREVENTED == justTriggerTraps(event, value))
return true;
@@ -1277,7 +1255,7 @@
case "forcereflow": return METHOD;
case "sendEvent": return METHOD;
case "distanceto": return METHOD;
- case "text": return JSU.S(text.str);
+ case "text": return text.str;
case "fill": if (texture == null) return
JSU.S(Color.colorToString(fillcolor)); return texture.stream;
case "tile": return JSU.B(test(TILE_IMAGE));
case "textcolor": return JSU.S(Color.colorToString(text.color));
@@ -1369,10 +1347,9 @@
}
if (!text.isEmpty()) { setConstrain(); dirty(); }
case "text":
- String s = value==null ? Text.EMPTY_STRING : JSU.toString(value);
- // is this necessary? - strings are immutable so
""==Text.EMPTY_STRING
- //if (s.equals("")) s = Text.EMPTY_STRING;
- if (s == text.str) return;
+ // FIXME: must be a better way to get JS to JSString
+ JSString s = value==null ? Text.EMPTY_STRING :
(JSString)JSU.S(JSU.toString(value));
+ if (s.equals(text.str)) return;
text = text.setString(s);
setConstrain();
dirty();
@@ -1755,15 +1732,12 @@
return trapchain;
}
int i=0;
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
for (Box b = getChild(i); b!=null; b=getChild(++i)) {
trapchain = b.fireSurfaceTraps(val, trapchain);
// interrupted by a JS exception
if (trapchain != null && trapchain.exn != null)
return trapchain;
}
- //if (lock) clear(LOCK_CHILDREN);
return trapchain;
}
@@ -1782,8 +1756,6 @@
return trapchain;
}
int i=0;
- //boolean lock = !test(LOCK_CHILDREN);
- //if (lock) set(LOCK_CHILDREN);
for (Box b = getChild(i); b!=null; b=getChild(++i)) {
if (b.test(DISPLAY)) {
trapchain = b.fireVisibleTraps(val, trapchain);
@@ -1792,7 +1764,6 @@
return trapchain;
}
}
- //if (lock) clear(LOCK_CHILDREN);
return trapchain;
}
@@ -1832,8 +1803,6 @@
if (oldparent == null) return;
int ind = oldparent.indexNode(this);
if (ind == i) return;
- //if (oldparent.test(LOCK_CHILDREN))
- // throw new JSExn("Attempt to move child within parent whilst
box tree is active");
if (test(DISPLAY)) dirty();
oldparent.deleteNode(ind);
oldparent.insertNode(i, this);
@@ -1842,15 +1811,8 @@
}
// check validity of new parent assignment
if (newparent != null) {
- if (i == -1)
- throw new JSExn("Illegal attempt to set the parent of a box");
- // only allow new children to be placed at the end of a locked box
- //if (newparent.test(LOCK_CHILDREN) && i<newparent.treeSize())
- // throw new JSExn("Attempt to add child to parent whilst box
tree is active");
- }/* else {
- if (parent.test(LOCK_CHILDREN))
- throw new JSExn("Attempt to remove child from parent whilst
box tree is active");
- }*/
+ if (i<0) throw new JSExn("Illegal attempt to set the parent of a
box");
+ }
// FIXME handle Enter/Leave better
clear(MOUSEINSIDE);
boolean wasvisible = isVisible();
@@ -1905,7 +1867,7 @@
* knowledge that we may never return!!) and not on the redirect where we
don't
* exist!
*/
- private void put(int i, JS value, boolean fireTrapsOnRemove, boolean
viaRedirect) throws JSExn{
+ private void put(int i, JS value, boolean fireTrapsOnRemove, boolean
viaRedirect) throws JSExn {
Trap rangeTrap = test(CHILDREN_TRAP) ? wtrap(SC_Children) : null;
JSExn rangeTrapException = null;
try {
Modified: trunk/core/org.vexi.core/src/org/vexi/core/Text.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Text.java 2009-05-25
23:54:55 UTC (rev 3507)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Text.java 2009-05-26
00:21:46 UTC (rev 3508)
@@ -8,6 +8,7 @@
import org.ibex.js.JS;
import org.ibex.js.JSExn;
import org.ibex.js.JSU;
+import org.ibex.js.JSString;
import org.vexi.graphics.Font;
/** amalgamates common text properties for memory/runtime efficiency */
@@ -27,7 +28,7 @@
static Fountain DEFAULT_STREAM = Main.vera;
static Font DEFAULT_FONT = Font.getFont(DEFAULT_STREAM, MEDIUM_SIZE);
static Text DEFAULT_TEXT = new Text();
- static String EMPTY_STRING = "";
+ static JSString EMPTY_STRING = (JSString) JSU.S("", true);
static int getDefaultFontSize() { return MEDIUM_SIZE; }
static Fountain getDefaultStream() { return DEFAULT_STREAM; }
@@ -114,7 +115,7 @@
int width = 0;
int height = 0;
Font font = DEFAULT_FONT;
- String str = "";
+ JSString str = EMPTY_STRING;
// put these here to avoid consuming Box flags
boolean font_trap = false;
@@ -233,7 +234,7 @@
/** set string representing text object */
Text setString() { return setString(EMPTY_STRING); }
- Text setString(String str) {
+ Text setString(JSString str) {
if (str.equals(this.str)) return this;
Text t = (this == DEFAULT_TEXT) ? new Text() : this;
t.str = str;
@@ -244,7 +245,7 @@
/** synchronize dimensions with text object contents */
private void calculateDimensions() {
if (str == EMPTY_STRING) { width = 0; height = 0; return; }
- width = font.textwidth(str);
- height = font.textheight(str);
+ width = font.textwidth(str.toString());
+ height = font.textheight(str.toString());
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn