Revision: 4787
http://sourceforge.net/p/vexi/code/4787
Author: clrg
Date: 2015-05-02 12:35:32 +0000 (Sat, 02 May 2015)
Log Message:
-----------
Redirect common properties to redirect
- could be internally more efficient (avoid put/get switch)
- can still override with traps
- also some minor comment improvements
Modified Paths:
--------------
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/java/org/vexi/core/Constants.java
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/TestBox.java
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/redirect.t
Modified:
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/java/org/vexi/core/Constants.java
===================================================================
---
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/java/org/vexi/core/Constants.java
2015-04-30 22:43:10 UTC (rev 4786)
+++
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/java/org/vexi/core/Constants.java
2015-05-02 12:35:32 UTC (rev 4787)
@@ -6,6 +6,7 @@
public interface Constants extends org.ibex.js.Constants {
static final JS SC_0 = JSU.S("0",true);
static final JS SC_add = JSU.S("add",true);
+ static final JS SC_align = JSU.S("align",true);
static final JS SC_align_topleft = JSU.S("topleft",true);
static final JS SC_align_top = JSU.S("top",true);
static final JS SC_align_topright = JSU.S("topright",true);
@@ -39,12 +40,14 @@
static final JS SC_html = JSU.S("html",true);
static final JS SC_indexof = JSU.S("indexof",true);
static final JS SC_layer = JSU.S("layer",true);
+ static final JS SC_layout = JSU.S("layout",true);
static final JS SC_maxheight = JSU.S("maxheight",true);
static final JS SC_maxwidth = JSU.S("maxwidth",true);
static final JS SC_minheight = JSU.S("minheight",true);
static final JS SC_minwidth = JSU.S("minwidth",true);
static final JS SC_mouse = JSU.S("mouse",true);
static final JS SC_numchildren = JSU.S("numchildren",true);
+ static final JS SC_orient = JSU.S("orient",true);
static final JS SC_pack = JSU.S("pack",true);
static final JS SC_place = JSU.S("place",true);
static final JS SC_redirect = JSU.S("redirect",true);
@@ -52,6 +55,8 @@
static final JS SC_stringify = JSU.S("stringify",true);
static final JS SC_subComponents = JSU.S("subComponents",true);
static final JS SC_surface = JSU.S("surface",true);
+ static final JS SC_text = JSU.S("text",true);
+ static final JS SC_textcolor = JSU.S("textcolor",true);
static final JS SC_thisobj = JSU.S("thisobj",true);
static final JS SC_vertical = JSU.S("vertical",true);
static final JS SC_visible = JSU.S("visible",true);
Modified:
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
===================================================================
---
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
2015-04-30 22:43:10 UTC (rev 4786)
+++
branches/vexi3_integrated_layout/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
2015-05-02 12:35:32 UTC (rev 4787)
@@ -46,7 +46,7 @@
* property on the box.</p>
*
* <h4>Packed Layout</h4>
- * <p>In packed layout boxes are positioned next to eachother in the direction
of the parents
+ * <p>In packed layout boxes are positioned next to each other in the
direction of the parent's
* orient property. The parent is constrained to the combined size of the
packed children in the
* orient direction and to the maximum size of its children in the non-orient
direction.</p>
*
@@ -1722,6 +1722,7 @@
/** the mouse object of a box */
private class Mouse extends JS.Immutable implements JS.Cloneable {
+ @SuppressWarnings("unused")
public JS get(JS key) throws JSExn {
//#switch (JSU.toString(key))
/*@PAGE(varname=mouse,humanname=Mouse Object)
@@ -1767,6 +1768,7 @@
private Box from;
private Box to;
DistanceTo(Box from, Box to) { this.from = from; this.to = to; }
+ @SuppressWarnings("unused")
public JS get(JS key) throws JSExn {
//#switch (JSU.toString(key))
/*@PAGE(varname=distanceto,humanname=DistanceTo Object)
@@ -1799,6 +1801,7 @@
//#end
return super.get(key);
}
+ @SuppressWarnings("unused")
public void put(JS key, JS value) throws JSExn {
try {
//#switch (JSU.toString(key))
@@ -1818,7 +1821,7 @@
public Box toImage(int x, int y, int w, int h) {
PixelBuffer pb = Platform.createPixelBuffer(w, h, null);
// FIXME: hack
- // this bizzare bit of parent manipulation is to get around
+ // this bizarre bit of parent manipulation is to get around
// the 'getX/YInParent()' look ups in render() for this box
Box p = parent;
parent = null;
@@ -1832,6 +1835,7 @@
}
/** implements functions that can be invoked on a box in JS */
+ @SuppressWarnings("unused")
public JS callMethod(JS this_, JS method, JS[] args) throws JSExn {
try {
switch (args.length) {
@@ -1939,13 +1943,26 @@
//#end
}
} catch (NullPointerException npe) {
- throw new JSExn("Cannot call "+method+"() with null arguments");
+ throw new JSExn("Cannot call '"+method+"()' with null arguments");
}
- throw new JSExn("Incorrect number of arguments for Box method
"+method+"()");
+ throw new JSExn("Incorrect number of arguments for Box method
'"+method+"()'");
}
+ /** returns true if there is a redirect to consume the attempted put */
+ final private boolean tryRedirect(JS name, JS value) throws JSExn {
+ if (redirect == null) {
+ throw new JSExn("Attempt to set '"+name+"' on a box
with a null redirect");
+ }
+ if (redirect != this) {
+ redirect.putAndTriggerTraps(name, value);
+ return true;
+ }
+ return false;
+ }
+
/** implements reading from box properties in JS */
+ @SuppressWarnings("unused")
public JS get(JS name) throws JSExn {
// integer properties translate to box children
if (JSU.isInt(name)) {
@@ -1956,7 +1973,7 @@
case "path":
if (path != null) return JSU.S(path.toString());
String ret = "";
- for(int i=0; i<str.length(); i++) ret +=
font.glyphs[str.charAt(i)].path;
+ for(int i=0; i<text.length(); i++) ret +=
font.glyphs[text.charAt(i)].path;
return JSU.S(ret);
case "strokecolor": return JSU.S(Color.colorToString(strokecolor));
case "strokewidth": return JSU.N(strokewidth);
@@ -1970,8 +1987,7 @@
* */
/*****************************************************************************************/
-
- /*@SECTION(Rendering) The rendering properties affect what the box
looks like visually.*/
+ /* @SECTION(Rendering) The rendering properties affect what the box
looks like visually. */
/* <p>A box will draw itself on-screen filled with the color or image
specified by this
* property.</p>
@@ -2007,7 +2023,10 @@
* @initial_value(vexi.ui.font.vera)
* @nofollow
* */
- case "font": return font.stream;
+ case "font":
+ if (redirect == null) return null;
+ if (redirect == this) return font.stream;
+ return redirect.getAndTriggerTraps(SC_font);
/* <p>The size, either in points or relative size, to render the
text.</p>
*
@@ -2028,7 +2047,10 @@
* @type(Number)
* @initial_value("medium")
* */
- case "fontsize": return sizeToJS(fontsize);
+ case "fontsize":
+ if (redirect == null) return null;
+ if (redirect == this) return sizeToJS(fontsize);
+ return redirect.getAndTriggerTraps(SC_fontsize);
/* <p>The text of a box. Visually <code>null</code> renders the same
as the text to ""
* (i.e as nothing).</p>
@@ -2037,7 +2059,10 @@
* @type(String)
* @nofollow
* */
- case "text": return text;
+ case "text":
+ if (redirect == null) return null;
+ if (redirect == this) return text;
+ return redirect.getAndTriggerTraps(SC_text);
/* <p>If the value is a 5-character hex string (#RGB), 7-character hex
string (#RRGGBB),
* 9-character hex string (#AARRGGBB), a box's text color will be set
to that color.</p>
@@ -2051,7 +2076,10 @@
* @initial_value("#ffffff")
* @type(String)
* */
- case "textcolor": return JSU.S(Color.colorToString(textcolor));
+ case "textcolor":
+ if (redirect == null) return null;
+ if (redirect == this) return
JSU.S(Color.colorToString(textcolor));
+ return redirect.getAndTriggerTraps(SC_textcolor);
/* <p>This property can be set to any of the values specified for
textcolor. If the value
* written is a stream then it will interpreted as a PNG, GIF, or JPEG
image, which will
@@ -2063,9 +2091,9 @@
* */
case "tile": return JSU.B(test(TILE_IMAGE));
-
+
/*****************************************************************************************/
- /*@SECTION(Child Control) The properties/methods related to the
children of the box.*/
+ /* @SECTION(Child Control) The properties/methods related to the
children of the box. */
/* <p>The nth child of box b can be accessed by reading from
<code>b[n]</code>.</p>
*
@@ -2087,6 +2115,30 @@
* @type(Box)
*/
//also "<em>numeric properties</em>":
+
+ /* <p>Determines a box's alignment point. This affects the position
of:</p>
+ *
+ * <div class="itemizedlist"><ul type="disc">
+ * <li>the box's textual content</li>
+ * <li>a tiled texture</li>
+ * <li>children within the space allocated to them by the layout
method of the box</li>
+ * </ul></div>
+ *
+ * <p>Valid values are:</p>
+ *
+ * <ul><li><code>"center"</code>, <code>"left"</code>,
<code>"right"</code>, <code>"top"</code>, <code>"bottom"</code>,
+ * <code>"bottomleft"</code>, <code>"bottomright"</code>,
<code>"topleft"</code>, <code>"topright"</code></li></ul>
+ *
+ * <p>If this box has a redirect, it will return the align of the
redirect.
+ * If redirect is set to null, it will return null.</p>
+ *
+ * @type(String)
+ * @initial_value("center")
+ * */
+ case "align":
+ if (redirect == null) return null;
+ if (redirect == this) return alignToJS();
+ return redirect.getAndTriggerTraps(SC_align);
/* <p>The layout strategy for a box - how it lays out it's
children.</p>
*
@@ -2102,13 +2154,22 @@
* <p>Layered children behaved like placed children, only the parent
box will respect
* the contentsizes of it's children.</p>
*
+ * <p>If this box has a redirect, it will return the layout of the
redirect.
+ * If redirect is set to null, it will return null.</p>
+ *
* @type(String)
* @initial_value("pack")
* */
- case "layout": return test(PACK) ? SC_pack : (test(CLIP) ? SC_place :
SC_layer);
+ case "layout":
+ if (redirect == null) return null;
+ if (redirect == this) return test(PACK) ? SC_pack : (test(CLIP)
? SC_place : SC_layer);
+ return redirect.getAndTriggerTraps(SC_layout);
/* <p><em>Read only</em> reflecting the number of children a box
has.</p>
*
+ * <p>If this box has a redirect, it will return the number of
children of the
+ * redirect. If redirect is set to null, it will return 0.</p>
+ *
* @initial_value(varies,code=false)
* @type(Number)
* */
@@ -2120,10 +2181,16 @@
/* <p>The direction the children are layed out in the box when
<code>layout="pack"</code>.
* Valid values are <code>"horizontal"</code> or
<code>"vertical"</code>.</p>
*
+ * <p>If this box has a redirect, it will return the orient of the
redirect.
+ * If redirect is set to null, it will return null.</p>
+ *
* @type(String)
* @initial_value("horizontal")
* */
- case "orient": return test(ORIENT) ? SC_horizontal : SC_vertical;
+ case "orient":
+ if (redirect == null) return null;
+ if (redirect == this) return test(ORIENT) ? SC_horizontal :
SC_vertical;
+ return redirect.getAndTriggerTraps(SC_orient);
/* <p>Writing to this property sets a box's redirect target. Reading
from this property
* will return a boolean instead of the redirect target -
<code>true</code> if redirect
@@ -2331,24 +2398,6 @@
case "contentwidth": return JSU.N(contentwidth);
case "contentheight": return JSU.N(contentheight);
- /* <p>Determines a box's alignment point. This affects the position
of:</p>
- *
- * <div class="itemizedlist"><ul type="disc">
- * <li>the box's textual content</li>
- * <li>a tiled texture</li>
- * <li>children within the space allocated to them by the layout
method of the box</li>
- * </ul></div>
- *
- * <p>Valid values are:</p>
- *
- * <ul><li><code>"center"</code>, <code>"left"</code>,
<code>"right"</code>, <code>"top"</code>, <code>"bottom"</code>,
- * <code>"bottomleft"</code>, <code>"bottomright"</code>,
<code>"topleft"</code>, <code>"topright"</code></li></ul>
- *
- * @type(String)
- * @initial_value("center")
- * */
- case "align": return alignToJS();
-
/* <p>Whether to display a box and it's contents.</p>
*
* <p>If this box is the root box of a window, its display property
will determine whether
@@ -2570,6 +2619,7 @@
}
/** implements the writing of box properties from JS */
+ @SuppressWarnings("unused")
public void put(JS name, JS value) throws JSExn {
// integer properties translate to box children
// SHOULD differentiate the methods here. isInt checks anything that
@@ -2613,6 +2663,7 @@
throw new JSExn("Attempt to put non-null value to the
'thisbox' property");
}
case "font":
+ if (tryRedirect(name, value)) return;
// We do not convert to a fountain straight away as if it is a
Blessing then
// the fountain won't work as it will refer to the file/url
without .ttf. For
// the moment we handle Blessings separately for this reason.
@@ -2638,6 +2689,7 @@
dirty();
}
case "fontsize":
+ if (tryRedirect(name, value)) return;
if (value==null) {
clear(FONTSIZE_SET);
if (fontsize != MEDIUM_SIZE)
@@ -2655,6 +2707,7 @@
dirty();
}
case "text":
+ if (tryRedirect(name, value)) return;
JSString s = value == null ? null :
value instanceof JSString ? (JSString)value :
(JSString)JSU.S(JSU.toString(value));
if (value == null || EMPTY_STRING.equals(s)) {
@@ -2671,6 +2724,7 @@
setConstrain();
dirty();
case "textcolor":
+ if (tryRedirect(name, value)) return;
try {
if (value==null) {
clear(FONTCOLOR_SET);
@@ -2792,7 +2846,6 @@
// checks for and invokes cursor update
s.processMousePosition();
}
- case "align": setAlign(value);
case "fill":
if (value == null && texture != null && test(TILE_IMAGE)) {
// other cases handled by Box.run()
@@ -2840,7 +2893,11 @@
}
}
}
+ case "align":
+ if (tryRedirect(name, value)) return;
+ setAlign(value);
case "layout":
+ if (tryRedirect(name, value)) return;
if (SC_place.equals(value)) {
if (!test(PACK) && test(CLIP)) {
return;
@@ -2869,6 +2926,7 @@
throw new JSExn("Attempt to set Box property 'layout' to
unsupported value '"+JSU.toString(value)+"'");
}
case "orient":
+ if (tryRedirect(name, value)) return;
if (SC_horizontal.equals(value)) {
if (test(ORIENT)) {
return;
Modified:
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/TestBox.java
===================================================================
---
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/TestBox.java
2015-04-30 22:43:10 UTC (rev 4786)
+++
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/TestBox.java
2015-05-02 12:35:32 UTC (rev 4787)
@@ -40,7 +40,7 @@
public static void main(String[] args) throws Throwable {
CoreTestSuite cts = new CoreTestSuite(TestBox.class);
- TestCase t = cts.createTestCase(cts.getResourceDirs(), "pis_method.t");
+ TestCase t = cts.createTestCase(cts.getResourceDirs(), "redirect.t");
t.runBare();
}
Modified:
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/redirect.t
===================================================================
---
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/redirect.t
2015-04-30 22:43:10 UTC (rev 4786)
+++
branches/vexi3_integrated_layout/org.vexi-core.main/src/test/java/test/core/box/redirect.t
2015-05-02 12:35:32 UTC (rev 4787)
@@ -1,20 +1,68 @@
<vexi xmlns:ui="vexi://ui" xmlns="" xmlns:lib="_lib">
- var b1 = vexi.box;
- var b2 = vexi.box;
- b1[0] = b2;
- b1.redirect = b2;
-
- b2[0] = lib..newBox("a");
- b2[1] = lib..newBox("b");
- b1[2] = lib..newBox("c");
- b1[3] = lib..newBox("d");
-
- //.util..assertEquals("a",b2[0].text);
- .util..assertEquals("b",b1[1].text);
- //.util..assertEquals("c",b2[2].text);
- //.util..assertEquals("d",b1[3].text);
+ var assertEquals = .util..assertEquals;
+
+ var b1 = vexi.box;
+ var b2 = vexi.box;
+ b1[0] = b2;
+ b1.redirect = b2;
+ b2[0] = lib..newBox("a");
+ b2[1] = lib..newBox("b");
+ b1[2] = lib..newBox("c");
+ b1[3] = lib..newBox("d");
+
+ assertEquals("a",b2[0].text);
+ assertEquals("b",b1[1].text);
+ assertEquals("c",b2[2].text);
+ assertEquals("d",b1[3].text);
+
+ var t1 = vexi.box;
+ var t2 = vexi.box;
+ t1[0] = t2;
+ t1.redirect = t2;
+
+ t1.align = "top";
+ assertEquals("top", t2.align);
+
+ t2.align = "bottom";
+ assertEquals("bottom", t1.align);
+
+ t1.layout = "place";
+ assertEquals("place", t2.layout);
+
+ t2.layout = "pack";
+ assertEquals("pack", t1.layout);
+
+ t1.orient = "vertical";
+ assertEquals("vertical", t2.orient);
+
+ t2.orient = "horizontal";
+ assertEquals("horizontal", t1.orient);
+
+ // text properties
+ // NB: should check font
+
+ t1.fontsize = 14;
+ assertEquals(14, t2.fontsize);
+
+ t2.fontsize = 16;
+ assertEquals(16, t1.fontsize);
+
+ t1.text = "foo";
+ assertEquals("foo", t2.text);
+
+ t2.text = "bar";
+ assertEquals("bar", t1.text);
+
+ t1.textcolor = "green";
+// assertEquals("green", t2.textcolor);
+ assertEquals("#008000", t2.textcolor);
+
+ t2.textcolor = "blue";
+// assertEquals("blue", t1.textcolor);
+ assertEquals("#0000ff", t1.textcolor);
+
<ui:box/>
</vexi>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Vexi-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vexi-svn