1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

24
150_gfui/.classpath Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src_100_basic"/>
<classpathentry kind="src" path="src_110_draw_core"/>
<classpathentry kind="src" path="src_120_draw_objs"/>
<classpathentry kind="src" path="src_200_ipt"/>
<classpathentry kind="src" path="src_210_lyt"/>
<classpathentry kind="src" path="src_300_gxw"/>
<classpathentry kind="src" path="src_400_win"/>
<classpathentry kind="src" path="src_410_box_core"/>
<classpathentry kind="src" path="src_420_box_basic"/>
<classpathentry kind="src" path="src_430_box_custom"/>
<classpathentry kind="src" path="src_500_tab"/>
<classpathentry kind="src" path="src_600_adp"/>
<classpathentry kind="src" path="src_700_env"/>
<classpathentry kind="src" path="tst"/>
<classpathentry kind="src" path="xtn"/>
<classpathentry kind="src" path="/100_core"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/110_gfml"/>
<classpathentry kind="lib" path="lib/swt.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
150_gfui/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>150_gfui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

BIN
150_gfui/lib/swt.jar Normal file

Binary file not shown.

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class DirInt {
public int Val() {return val;} int val;
public DirInt Rev() {return this == Fwd ? Bwd : Fwd;}
public int CompareToRng(int v, int lo, int hi) {
if (v < lo) return -1 * val;
else if (v > hi) return 1 * val;
else return 0;
}
public int GetValByDir(int ifBwd, int ifFwd) {
return this == Bwd ? ifBwd : ifFwd;
}
public boolean BoundFail(int i, int bound) {return this == Bwd ? i < bound : i > bound;}
DirInt(int v) {this.val = v;}
public static final DirInt
Fwd = new DirInt(1)
, Bwd = new DirInt(-1);
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GfuiAlign {
public int Val() {return val;} int val;
public String Name() {return name;} private String name;
public GfuiAlign(int val, String name) {this.val = val; this.name = name;}
}

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GfuiAlign_ implements ParseAble {
public static GfuiAlign as_(Object obj) {return obj instanceof GfuiAlign ? (GfuiAlign)obj : null;}
public static GfuiAlign cast_(Object obj) {try {return (GfuiAlign)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, GfuiAlign.class, obj);}}
public static final GfuiAlign
Null = new_(0, "nil")
, Lo = new_(1, "lo")
, Mid = new_(2, "mid")
, Hi = new_(3, "hi");
public static final GfuiAlign
Top = Lo
, Bot = Hi
, Left = Lo
, Right = Hi;
static GfuiAlign new_(int v, String s) {return new GfuiAlign(v, s);}
public static final GfuiAlign_ Parser = new GfuiAlign_();
public Object ParseAsObj(String raw) {return parse_(raw);}
public static GfuiAlign val_(int v) {
if (v == Lo.Val()) return Lo;
else if (v == Mid.Val()) return Mid;
else if (v == Hi.Val()) return Hi;
else return Null;
}
public static GfuiAlign parse_(String raw) {
if (String_.Eq(raw, "bot")) return Bot;
else if (String_.Eq(raw, "mid")) return Mid;
else if (String_.Eq(raw, "top")) return Top;
return Null;
}
public static PointAdp CalcInsideOf(GfuiAlign h, GfuiAlign v, SizeAdp inner, SizeAdp outer, PointAdp adjust) {
int x = CalcInsideOfAxis(h.Val(), inner.Width(), outer.Width());
int y = CalcInsideOfAxis(v.Val(), inner.Height(), outer.Height());
return PointAdp_.new_(x + adjust.X(), y + adjust.Y());
}
public static int CalcInsideOfAxis(int posEnm, int innerSize, int outerSize) {
int rv = 0;
if (posEnm == GfuiAlign_.Null.Val()) rv = Int_.MinValue;
else if (posEnm == GfuiAlign_.Lo.Val()) rv = 0;
else if (posEnm == GfuiAlign_.Mid.Val()) rv = (outerSize - innerSize) / 2;
else if (posEnm == GfuiAlign_.Hi.Val()) rv = outerSize - innerSize;
else throw Exc_.new_unhandled(posEnm);
if (rv < 0) rv = 0;
return rv;
}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GfuiAxisType {
public int Val() {return val;} int val;
public GfuiAxisType CrossAxis() {return val == GfuiAxisType.X.val ? GfuiAxisType.Y : GfuiAxisType.X;}
GfuiAxisType(int v) {this.val = v;}
public static final GfuiAxisType X = new GfuiAxisType(1);
public static final GfuiAxisType Y = new GfuiAxisType(2);
}

View File

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GfuiBorderEdge {
public int Val() {return val;} int val;
public boolean Has(GfuiBorderEdge comp) {return Enm_.HasInt(val, comp.val);}
public GfuiBorderEdge Add(GfuiBorderEdge comp) {
return new GfuiBorderEdge(comp.val + val);
}
@gplx.Internal protected GfuiBorderEdge(int v) {this.val = v;}
public static final GfuiBorderEdge Left = new GfuiBorderEdge(1);
public static final GfuiBorderEdge Right = new GfuiBorderEdge(2);
public static final GfuiBorderEdge Top = new GfuiBorderEdge(4);
public static final GfuiBorderEdge Bot = new GfuiBorderEdge(8);
public static final GfuiBorderEdge All = new GfuiBorderEdge(15);
}
class GfuiBorderEdge_ {
public static String XtoStr(GfuiBorderEdge edge) {
int val = edge.Val();
if (val == GfuiBorderEdge.Left.Val()) return Left_raw;
else if (val == GfuiBorderEdge.Right.Val()) return Right_raw;
else if (val == GfuiBorderEdge.Top.Val()) return Top_raw;
else if (val == GfuiBorderEdge.Bot.Val()) return Bot_raw;
else if (val == GfuiBorderEdge.All.Val()) return All_raw;
else throw Exc_.new_unhandled(edge);
}
public static GfuiBorderEdge parse_(String raw) {
if (String_.Eq(raw, Left_raw)) return GfuiBorderEdge.Left;
else if (String_.Eq(raw, Right_raw)) return GfuiBorderEdge.Right;
else if (String_.Eq(raw, Top_raw)) return GfuiBorderEdge.Top;
else if (String_.Eq(raw, Bot_raw)) return GfuiBorderEdge.Bot;
else if (String_.Eq(raw, All_raw)) return GfuiBorderEdge.All;
else throw Exc_.new_unhandled(raw);
}
public static final String
All_raw = "all"
, Top_raw = "top"
, Left_raw = "left"
, Right_raw = "right"
, Bot_raw = "bottom"
;
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class PointAdp implements XtoStrAble {
public int X() {return x;} final int x;
public int Y() {return y;} final int y;
public PointAdp Op_add(PointAdp val) {return new PointAdp(x + val.x, y + val.y);}
@gplx.Internal protected PointAdp Op_add(int xv, int yv) {return new PointAdp(x + xv, y + yv);}
@gplx.Internal protected PointAdp Op_add(int i) {return new PointAdp(x + i, y + i);}
public PointAdp Op_subtract(PointAdp val) {return new PointAdp(x - val.x, y - val.y);}
public boolean Eq(Object compObj) {
PointAdp comp = PointAdp_.as_(compObj); if (comp == null) return false;
return x == comp.x && y == comp.y;
}
public String XtoStr() {return String_.Concat_any(x, ",", y);}
@Override public String toString() {return XtoStr();}
@Override public boolean equals(Object obj) {return Eq(obj);}
@Override public int hashCode() {return super.hashCode();}
@gplx.Internal protected PointAdp(int x, int y) {this.x = x; this.y = y;}
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class PointAdp_ {
public static final PointAdp Null = new PointAdp(Int_.MinValue, Int_.MinValue);
public static final PointAdp Zero = new PointAdp(0, 0);
public static PointAdp as_(Object obj) {return obj instanceof PointAdp ? (PointAdp)obj : null;}
public static PointAdp cast_(Object obj) {try {return (PointAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, PointAdp.class, obj);}}
public static PointAdp new_(int x, int y) {return new PointAdp(x, y);}
public static PointAdp coerce_(Object o) {PointAdp rv = PointAdp_.as_(o); return (rv == null) ? parse_((String)o) : rv;}
public static PointAdp parse_(String raw) {
try {
String[] ary = String_.Split(raw, ",");
return new PointAdp(Int_.parse_(ary[0]), Int_.parse_(ary[1]));
} catch (Exception exc) {throw Exc_.new_parse_exc(exc, PointAdp.class, raw);}
}
}

View File

@@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class RectAdp {
public SizeAdp Size() {return size;} SizeAdp size = SizeAdp_.Zero;
public PointAdp Pos() {return pos;} PointAdp pos = PointAdp_.Zero;
public int Width() {return size.Width();} public int Height() {return size.Height();}
public int X() {return pos.X();} public int Y() {return pos.Y();}
public PointAdp CornerTL() {return pos;}
public PointAdp CornerTR() {return PointAdp_.new_(pos.X() + size.Width(), pos.Y());}
public PointAdp CornerBL() {return PointAdp_.new_(pos.X(), pos.Y() + size.Height());}
public PointAdp CornerBR() {return PointAdp_.new_(pos.X() + size.Width(), pos.Y() + size.Height());}
@gplx.Internal protected boolean ContainsPoint(PointAdp point) {
return point.X() >= pos.X() && point.X() <= pos.X() + size.Width()
&& point.Y() >= pos.Y() && point.Y() <= pos.Y() + size.Height();
}
public RectAdp Op_add(RectAdp v) {
return new RectAdp(pos.Op_add(v.Pos()), size.Op_add(v.Size()));
}
@Override public String toString() {return String_.Concat_any(pos, ";", size);}
@Override public boolean equals(Object obj) {
RectAdp comp = (RectAdp)obj;
return size.Eq(comp.size) && pos.Eq(comp.pos);
}
@Override public int hashCode() {return super.hashCode();}
public String Xto_str() {return String_.Concat_any(pos, ",", size);}
@gplx.Internal protected RectAdp(PointAdp pos, SizeAdp size) {this.pos = pos; this.size = size;}
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class RectAdpF { //_20101206 // supports Graphics.MeasureString
public float X() {return x;} float x; public float Y() {return y;} float y;
public float Width() {return width;} float width; public float Height() {return height;} float height;
public SizeAdpF Size() {if (size == null) size = SizeAdpF_.new_(width, height); return size;} SizeAdpF size;
public boolean Eq(RectAdpF comp) {
return comp.x == x && comp.y == y && comp.width == width && comp.height == height;
}
public static final RectAdpF Null = new_(Int_.MinValue, Int_.MinValue, Int_.MinValue, Int_.MinValue);
public static RectAdpF new_(float x, float y, float width, float height) {
RectAdpF rv = new RectAdpF();
rv.x = x; rv.y = y; rv.width = width; rv.height = height;
return rv;
}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class RectAdp_ {
public static final RectAdp Zero = new RectAdp(PointAdp_.Zero, SizeAdp_.Zero);
public static RectAdp new_(int x, int y, int width, int height) {return new RectAdp(PointAdp_.new_(x, y), SizeAdp_.new_(width, height));}
public static RectAdp corners_(PointAdp upperLeft, PointAdp bottomRight) {return new RectAdp(upperLeft, SizeAdp_.corners_(upperLeft, bottomRight));}
public static RectAdp vector_(PointAdp pos, SizeAdp size) {return new RectAdp(pos, size);}
public static RectAdp size_(int w, int h) {return new_(0, 0, w, h);}
public static RectAdp size_(SizeAdp size) {return new RectAdp(PointAdp_.Zero, size);}
public static RectAdp parse_ws_(String raw) {return parse_(String_.Replace(raw, " ", ""));}
public static RectAdp parse_(String raw) {
try {
String[] ary = String_.Split(raw, ",");
return RectAdp_.new_(Int_.parse_(ary[0]), Int_.parse_(ary[1]), Int_.parse_(ary[2]), Int_.parse_(ary[3]));
} catch(Exception exc) {throw Exc_.new_parse_exc(exc, RectAdp.class, raw);}
}
public static String Xto_str(RectAdp rect) {return String_.Format("{0},{1},{2},{3}", rect.X(), rect.Y(), rect.Width(), rect.Height());}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class SizeAdp {
public int Width() {return width;} int width;
public int Height() {return height;} int height;
public int AxisLength(GfuiAxisType axis) {return axis == GfuiAxisType.X ? width : height;}
public SizeAdp Op_add(int w, int h) {return SizeAdp_.new_(width + w, height + h);}
@gplx.Internal protected SizeAdp Op_add(SizeAdp s) {return SizeAdp_.new_(width + s.width, height + s.height);}
@gplx.Internal protected SizeAdp Op_subtract(int val) {return SizeAdp_.new_(width - val, height - val);}
@gplx.Internal protected SizeAdp Op_subtract(int w, int h) {return SizeAdp_.new_(width - w, height - h);}
public String XtoStr() {return String_.Concat_any(width, ",", height);}
public boolean Eq(Object o) {
SizeAdp comp = (SizeAdp)o; if (comp == null) return false;
return width == comp.width && height == comp.height;
}
@Override public String toString() {return XtoStr();}
@Override public boolean equals(Object obj) {return Eq(obj);}
@Override public int hashCode() {return super.hashCode();}
@gplx.Internal protected SizeAdp(int width, int height) {this.width = width; this.height = height;}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class SizeAdpF implements ParseAble {
public float Width() {return width;} float width;
public float Height() {return height;} float height;
public Object ParseAsObj(String raw) {return SizeAdp_.parse_(raw);}
@Override public String toString() {return String_.Concat_any(width, ":", height);}
@gplx.Internal protected SizeAdpF(float width, float height) {this.width = width; this.height = height;}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class SizeAdpF_ {
public static final SizeAdpF Null = new_(Int_.MinValue, Int_.MinValue);
public static final SizeAdpF Zero = new_(0, 0);
public static final SizeAdpF Parser = new SizeAdpF(0, 0);
public static SizeAdpF as_(Object obj) {return obj instanceof SizeAdpF ? (SizeAdpF)obj : null;}
public static SizeAdpF new_(float width, float height) {return new SizeAdpF(width, height);}
public static SizeAdpF coerce_(Object obj) {SizeAdpF rv = as_(obj); return rv == null ? parse_((String)obj) : rv;}
public static SizeAdpF parse_(String s) {
try {
String[] ary = String_.Split(s, ","); if (ary.length != 2) throw Exc_.new_("SizeAdf should only have 2 numbers separated by 1 comma");
float val1 = Float_.parse_(ary[0]);
float val2 = Float_.parse_(ary[1]);
return new_(val1, val2);
} catch (Exception e) {throw Exc_.new_parse_exc(e, SizeAdpF.class, s);}
}
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class SizeAdp_ {
public static final SizeAdp Null = new SizeAdp(Int_.MinValue, Int_.MinValue);
public static final SizeAdp Zero = new SizeAdp(0, 0);
public static final SizeAdp[] Ary_empty = new SizeAdp[0];
public static SizeAdp cast_(Object obj) {try {return (SizeAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, SizeAdp.class, obj);}}
public static SizeAdp new_(int width, int height) {return new SizeAdp(width, height);}
public static SizeAdp parse_(String raw) {return parse_or_(raw, SizeAdp_.Null);}
public static SizeAdp parse_or_(String raw, SizeAdp or) {
String[] ary = String_.Split(raw, ","); if (ary.length != 2) return or;
int w = Int_.parse_or_(ary[0], Int_.MinValue); if (w == Int_.MinValue) return or;
int h = Int_.parse_or_(ary[1], Int_.MinValue); if (h == Int_.MinValue) return or;
return new SizeAdp(w, h);
}
public static SizeAdp corners_(PointAdp topLeft, PointAdp bottomRight) {
int width = bottomRight.X() - topLeft.X();
int height = bottomRight.Y() - topLeft.Y();
return new_(width, height);
}
public static PointAdp center_(SizeAdp outer, SizeAdp inner) {
int x = (outer.Width() - inner.Width()) / 2; if (x < 0) x = 0;
int y = (outer.Height() - inner.Height()) / 2; if (y < 0) y = 0;
return PointAdp_.new_(x, y);
}
}

View File

@@ -0,0 +1,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.strings.*; import gplx.texts.*;
public class ColorAdp {
public int Value() {return val;} int val;
public int Alpha() {return (255 & val >> 24);}
public int Red () {return (255 & val >> 16);}
public int Green() {return (255 & val >> 8);}
public int Blue() {return (255 & val);}
public String XtoHexStr() {
String_bldr sb = String_bldr_.new_();
sb.Add("#");
sb.Add(HexDecUtl.XtoStr(Alpha(), 2));
sb.Add(HexDecUtl.XtoStr(Red(), 2));
sb.Add(HexDecUtl.XtoStr(Green(), 2));
sb.Add(HexDecUtl.XtoStr(Blue(), 2));
return sb.XtoStr();
}
public boolean Eq(Object obj) {
ColorAdp comp = ColorAdp_.as_(obj); if (comp == null) return false;
return Object_.Eq(val, comp.val);
}
@Override public String toString() {return XtoHexStr();}
public Object CloneNew() {return this;} // NOTE: 'return this' works b/c ColorAdp is read-only class; needed for comparisons; ex: ColorAdp_.Null == ColorAdp_.Null.CloneNew(); alternative would fail: return ColorAdp.new_(this.Alpha(), this.Red(), this.Green(), this.Blue());}
@gplx.Internal protected static ColorAdp new_(int alpha, int red, int green, int blue) {
ColorAdp rv = new ColorAdp();
rv.val = (int)((alpha << 24) | (red << 16) | (green << 8) | (blue));
return rv;
} ColorAdp() {}
}
class ColorAdpCache {
public java.awt.Color GetNativeColor(ColorAdp color) {
Object rv = hash.Get_by(color.Value()); if (rv != null) return (java.awt.Color)rv;
rv = new java.awt.Color(color.Red(), color.Green(), color.Blue(), color.Alpha());
hash.Add(color.Value(), rv);
return (java.awt.Color)rv;
}
Hash_adp hash = Hash_adp_.new_();
public static final ColorAdpCache _ = new ColorAdpCache(); ColorAdpCache() {}
}

View File

@@ -0,0 +1,118 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.texts.*;
public class ColorAdp_ implements ParseAble {
public static ColorAdp as_(Object obj) {return obj instanceof ColorAdp ? (ColorAdp)obj : null;}
public static ColorAdp cast_(Object obj) {try {return (ColorAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, ColorAdp.class, obj);}}
public static ColorAdp new_(int a, int r, int g, int b) {return ColorAdp.new_((int)a, (int)r, (int)g, (int)b);}
public static final ColorAdp_ Parser = new ColorAdp_();
public Object ParseAsObj(String raw) {return ColorAdp_.parse_(raw);}
public static ColorAdp parseOr_(String raw, ColorAdp or) {
ColorAdp rv = parse_internal_(raw); if (rv == null) return or;
return rv;
}
public static ColorAdp parse_(String raw) {
ColorAdp rv = parse_internal_(raw); if (rv == null) throw Exc_.new_parse_type(ColorAdp.class, raw);
return rv;
}
static ColorAdp parse_internal_(String raw) {
if (raw == null) return null;
char firstChar = String_.CharAt(raw, 0);
if (firstChar == '#') return parse_hex_(raw);
else if (Char_.IsNumber(firstChar)) return parse_int_(raw);
String rawLower = String_.Lower(raw);
if (String_.Eq(rawLower, "black")) return Black;
else if (String_.Eq(rawLower, "white")) return White;
else if (String_.Eq(rawLower, "gray")) return Gray;
else if (String_.Eq(rawLower, "red")) return Red;
else if (String_.Eq(rawLower, "lime")) return Lime;
else if (String_.Eq(rawLower, "blue")) return Blue;
else if (String_.Eq(rawLower, "yellow")) return Yellow;
else if (String_.Eq(rawLower, "fuchsia")) return Fuchsia;
else if (String_.Eq(rawLower, "maroon")) return Maroon;
else if (String_.Eq(rawLower, "green")) return Green;
else if (String_.Eq(rawLower, "navy")) return Navy;
else if (String_.Eq(rawLower, "olive")) return Olive;
else if (String_.Eq(rawLower, "purple")) return Purple;
else if (String_.Eq(rawLower, "teal")) return Teal;
else if (String_.Eq(rawLower, "brown")) return Brown;
else if (String_.Eq(rawLower, "lightgray")) return LightGray;
else
return null;
}
@gplx.Internal protected static ColorAdp parse_hex_(String raw) {
try {
int[] ary = new int[4]; // make ARGB ary
int idx = 0;
int rawLen = String_.Len(raw);
for (int i = 1; i < rawLen; i += 2) { // fill ARGB ary by parsing raw 2 at a time; EX: #FFFFFFFF -> 255,255,255,255; NOTE: start at 1 to ignore leading #
String hexStr = String_.MidByLen(raw, i, 2);
ary[idx++] = HexDecUtl.parse_(hexStr);
}
return ColorAdp.new_(ary[0], ary[1], ary[2], ary[3]);
} catch (Exception exc) {throw Exc_.new_parse_exc(exc, ColorAdp.class, raw);}
}
@gplx.Internal protected static ColorAdp parse_int_(String v) {
String[] ary = String_.Split(v, ",");
switch (ary.length) {
case 1: return new_int_(Int_.parse_(ary[0]));
case 3:
case 4: return parse_int_ary_(ary);
default: throw Exc_.new_("invalid array", "len", ary.length);
}
}
static ColorAdp parse_int_ary_(String[] ary) {
int a;
int idx = 0;
if (ary.length == 3) {idx = 0; a = 255;}
else {idx = 1; a = Int_.parse_(ary[0]);}
int r = Int_.parse_(ary[idx++]);
int g = Int_.parse_(ary[idx++]);
int b = Int_.parse_(ary[idx++]);
return ColorAdp_.new_(a, r, g, b);
}
public static ColorAdp new_int_(int val) {
int a = ((val >> 24) & 255);
int r = ((val >> 16) & 255);
int g = ((val >> 8) & 255);
int b = ((val) & 255);
return ColorAdp.new_(a, r, g, b);
}
public static ColorAdp read_(Object o) {String s = String_.as_(o); return s != null ? ColorAdp_.parse_(s) : ColorAdp_.cast_(o);}
public static final ColorAdp
Null = new_( 0, 0, 0, 0)
, Black = new_(255, 0, 0, 0)
, White = new_(255, 255, 255, 255)
, Gray = new_(255, 128, 128, 128)
, Red = new_(255, 255, 0, 0)
, Lime = new_(255, 0, 255, 0)
, Blue = new_(255, 0, 0, 255)
, Yellow = new_(255, 255, 255, 0)
, Fuchsia = new_(255, 255, 0, 255)
, Aqua = new_(255, 0, 255, 255)
, Maroon = new_(255, 128, 0, 0)
, Green = new_(255, 0, 128, 0)
, Navy = new_(255, 0, 0, 128)
, Olive = new_(255, 128, 128, 0)
, Purple = new_(255, 128, 0, 128)
, Teal = new_(255, 0, 128, 128)
, Brown = new_(255, 165, 42, 42)
, LightGray = new_(255, 211, 211, 211)
;
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*;
public class ColorAdp__tst {
@Test public void parse_hex_() {
tst_parse_hex_("#00000000", 0, 0, 0, 0);
tst_parse_hex_("#000102FF", 0, 1, 2, 255);
tst_parse_hex_("#FF000102", 255, 0, 1, 2);
}
@Test public void parse_int_() {
tst_parse_int_(0, 0, 0, 0, 0);
tst_parse_int_(255, 0, 0, 0, 255);
tst_parse_int_(65535, 0, 0, 255, 255);
tst_parse_int_(16777215, 0, 255, 255, 255);
tst_parse_int_(Int_.MaxValue, 127, 255, 255, 255);
tst_parse_int_(-1, 255, 255, 255, 255);
}
@Test public void parse_() {
tst_parse_("0,0,0,0", 0, 0, 0, 0); // parse all ints
tst_parse_("0,0,0", 255, 0, 0, 0); // a=255, parse rest
tst_parse_("255", 0, 0, 0, 255); // parse as single int
}
void tst_parse_hex_(String raw, int a, int r, int g, int b) {
ColorAdp color = ColorAdp_.parse_hex_(raw);
tst_ColorAdp(color, a, r, g, b);
Tfds.Eq(color.XtoHexStr(), raw);
}
void tst_parse_int_(int val, int a, int r, int g, int b) {
ColorAdp color = ColorAdp_.new_int_(val);
tst_ColorAdp(color, a, r, g, b);
Tfds.Eq(color.Value(), val);
}
void tst_parse_(String s, int alpha, int red, int green, int blue) {tst_ColorAdp(ColorAdp_.parse_(s), alpha, red, green, blue);}
void tst_ColorAdp(ColorAdp color, int alpha, int red, int green, int blue) {
TfdsTstr_fxt tstr = TfdsTstr_fxt.new_();
tstr.Eq_str(color.Alpha(), alpha, "alpha");
tstr.Eq_str(color.Red(), red, "red");
tstr.Eq_str(color.Green(), green, "green");
tstr.Eq_str(color.Blue(), blue, "blue");
tstr.tst_Equal("color");
}
}

View File

@@ -0,0 +1,81 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.Font;
import java.awt.Toolkit;
import gplx.core.strings.*;
public class FontAdp implements GfoInvkAble {
public String Name() {return name;} public FontAdp Name_(String val) {name = val; InitUnder(); return this;} private String name;
public float Size() {return size;} public FontAdp Size_(float val) {size = val; InitUnder(); return this;} float size;
public FontStyleAdp Style() {return style;} public FontAdp Style_(FontStyleAdp val) {style = val; InitUnder(); return this;} FontStyleAdp style;
@gplx.Internal protected Font UnderFont() {if (font == null) InitUnder(); return font;} Font font = null;
void InitUnder() {
if (Env_.Mode_testing()) return; // WORKAROUND/.NET: NUnit will randomlyly throw exceptions
font = FontAdpCache._.GetNativeFont(this);
if (ownerGxwCore != null) ownerGxwCore.TextFont_set(this);
}
@gplx.Internal protected FontAdp OwnerGxwCore_(GxwCore_base v) {ownerGxwCore = v; return this;} GxwCore_base ownerGxwCore;
public boolean Eq(Object obj) {
FontAdp comp = FontAdp.as_(obj); if (comp == null) return false;
return name == comp.name && size == comp.size && style == comp.style;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, "Name")) {return ctx.Deny() ? (Object)this : Name();}
else if (ctx.Match(k, "Size")) {return ctx.Deny() ? (Object)this : Size();}
else if (ctx.Match(k, "Style")) {return ctx.Deny() ? (Object)this : Style();}
else if (ctx.Match(k, Invk_name_)) {
String v = m.ReadStr("v");
return ctx.Deny() ? (Object)this : Name_(v);
}
else if (ctx.Match(k, Invk_size_)) {
float v = m.ReadFloat("v");
return ctx.Deny() ? (Object)this : Size_(v);
}
else if (ctx.Match(k, Invk_style_)) {
Object v = m.CastObj("v");
return ctx.Deny() ? (Object)this : Style_(FontStyleAdp_.read_(v));
}
else return GfoInvkAble_.Rv_unhandled;
} static final String Invk_name_ = "name_", Invk_size_ = "size_", Invk_style_ = "style_";
@Override public String toString() {return String_bldr_.new_().Add_kv("name", name).Add_kv_obj("size", size).Add_kv_obj("style", style).XtoStr();}
public static final FontAdp NullPtr = null;
public static FontAdp as_(Object obj) {return obj instanceof FontAdp ? (FontAdp)obj : null;}
public static FontAdp cast_(Object obj) {try {return (FontAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, FontAdp.class, obj);}}
public static FontAdp new_(String name, float size, FontStyleAdp style) {
FontAdp rv = new FontAdp();
rv.name = name; rv.size = size; rv.style = style;
return rv;
}
}
class FontAdpCache {
public Font GetNativeFont(FontAdp fontAdp) {
String key = fontAdp.toString();
Font rv = (Font)hash.Get_by(key); if (rv != null) return rv;
if (screenResolutionInDpi == -1) ScreenResolution_set();
int fontSize = XtoJavaDpi(fontAdp.Size());
rv = new Font(fontAdp.Name(), fontAdp.Style().Val(), fontSize);
hash.Add(key, rv);
return rv;
} Hash_adp hash = Hash_adp_.new_();
public static void ScreenResolution_set() {screenResolutionInDpi = Toolkit.getDefaultToolkit().getScreenResolution();} // usually either 96 or 120
public static int XtoOsDpi(float v) {return Math.round((v * 72) / screenResolutionInDpi);} // WORKAROUND/JAVA: Java needs 72 dpi screen resolution; wnt uses 96 or 120 dpi
public static int XtoJavaDpi(float v) {return Math.round((v * screenResolutionInDpi) / 72);}
static int screenResolutionInDpi = -1;
public static final FontAdpCache _ = new FontAdpCache(); FontAdpCache() {}
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class FontStyleAdp {
public int Val() {return val;} int val;
@Override public String toString() {return FontStyleAdp_.XtoStr_(this);}
@gplx.Internal protected FontStyleAdp(int v) {val = v;}
}

View File

@@ -0,0 +1,68 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.primitives.*;
public class FontStyleAdp_ implements ParseAble {
public static final FontStyleAdp
Plain = new FontStyleAdp(0)
, Bold = new FontStyleAdp(1)
, Italic = new FontStyleAdp(2)
, BoldItalic = new FontStyleAdp(3)
;
public static final FontStyleAdp_ Parser = new FontStyleAdp_();
public Object ParseAsObj(String raw) {return FontStyleAdp_.parse_(raw);}
public static FontStyleAdp cast_(Object obj) {try {return (FontStyleAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, FontStyleAdp.class, obj);}}
public static FontStyleAdp parseOr_(String raw, FontStyleAdp or) {
FontStyleAdp rv = parse_internal_(raw); if (rv == null) return or;
return rv;
}
public static FontStyleAdp parts_(Bool_obj_val bold, Bool_obj_val italic) {
int v = bold == Bool_obj_val.True ? 1 : 0;
v += italic == Bool_obj_val.True ? 2 : 0;
return lang_(v);
}
public static FontStyleAdp parse_(String raw) {
FontStyleAdp rv = parse_internal_(raw); if (rv == null) throw Exc_.new_unhandled(raw);
return rv;
}
public static FontStyleAdp read_(Object o) {String s = String_.as_(o); return s != null ? FontStyleAdp_.parse_(s) : FontStyleAdp_.cast_(o);}
static FontStyleAdp parse_internal_(String raw) {
if (String_.Eq(raw, "plain")) return FontStyleAdp_.Plain;
else if (String_.Eq(raw, "bold")) return FontStyleAdp_.Bold;
else if (String_.Eq(raw, "italic")) return FontStyleAdp_.Italic;
else if (String_.Eq(raw, "bold+italic"))return FontStyleAdp_.BoldItalic;
else if (String_.Eq(raw, "italic+bold"))return FontStyleAdp_.BoldItalic;
else return null;
}
public static FontStyleAdp lang_(int v) {
if (v == Plain.Val()) return Plain;
else if (v == Bold.Val()) return Bold;
else if (v == Italic.Val()) return Italic;
else if (v == BoldItalic.Val()) return BoldItalic;
else throw Err_arg.notFound_key_("v", v);
}
public static String XtoStr_(FontStyleAdp fontStyle) {
int val = fontStyle.Val();
if (val == FontStyleAdp_.Plain.Val()) return "plain";
else if (val == FontStyleAdp_.Bold.Val()) return "bold";
else if (val == FontStyleAdp_.Italic.Val()) return "italic";
else if (val == FontStyleAdp_.BoldItalic.Val()) return "bold+italic";
else throw Exc_.new_unhandled(val);
}
}

View File

@@ -0,0 +1,53 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.BasicStroke;
import java.awt.Stroke;
import gplx.core.strings.*;
public class PenAdp implements GfoInvkAble {
public float Width() {return width;} public void Width_set(float v) {width = v; InitUnder();} float width;
public ColorAdp Color() {return color;} public void Color_set(ColorAdp v) {color = v; InitUnder();} ColorAdp color;
public BasicStroke UnderStroke() {if (underStroke == null) InitUnder(); return underStroke;} BasicStroke underStroke;
void InitUnder() {underStroke = PenAdpCache._.Fetch(width);}
public PenAdp Clone() {return PenAdp_.new_(color, width);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Width_)) Width_set(m.ReadFloat(Invk_Width_));
else if (ctx.Match(k, Invk_Color_)) Color_set((ColorAdp)m.ReadObj(Invk_Color_, ColorAdp_.Parser));
else return GfoInvkAble_.Rv_unhandled;
return this;
} static final String Invk_Width_ = "Width_", Invk_Color_ = "Color_";
@Override public String toString() {return String_bldr_.new_().Add_kv_obj("width", width).Add_kv("color", color.XtoHexStr()).XtoStr();}
@Override public int hashCode() {return color.Value() ^ (int)width;}
@Override public boolean equals(Object obj) { // cannot use Eq b/c of difficulty in comparing null instances
PenAdp comp = PenAdp_.as_(obj); if (comp == null) return false;
return color.Eq(comp.color) && width == comp.width;
}
@gplx.Internal protected PenAdp(ColorAdp color, float width) {this.color = color; this.width = width;}
}
class PenAdpCache {
public BasicStroke Fetch(float width) {
Object rv = hash.Get_by(width);
if (rv == null) {
rv = new BasicStroke(width);
hash.Add(width, rv);
}
return (BasicStroke)rv;
}
Hash_adp hash = Hash_adp_.new_();
public static final PenAdpCache _ = new PenAdpCache(); PenAdpCache() {}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class PenAdp_ {
public static PenAdp as_(Object obj) {return obj instanceof PenAdp ? (PenAdp)obj : null;}
public static PenAdp cast_(Object obj) {try {return (PenAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, PenAdp.class, obj);}}
public static PenAdp black_() {return new_(ColorAdp_.Black, 1);}
public static PenAdp new_(ColorAdp color) {return new_(color, 1);}
public static PenAdp new_(ColorAdp color, float width) {return new PenAdp(color, width);}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class SolidBrushAdp {
public ColorAdp Color() {return color;} ColorAdp color;
@Override public String toString() {return color.XtoHexStr();}
public boolean Eq(Object obj) {
SolidBrushAdp comp = SolidBrushAdp_.as_(obj); if (comp == null) return false;
return color.Eq(comp.color);
}
@gplx.Internal protected static SolidBrushAdp new_(ColorAdp color) {
SolidBrushAdp rv = new SolidBrushAdp();
rv.color = color;
return rv;
}
}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class SolidBrushAdp_ {
public static SolidBrushAdp as_(Object obj) {return obj instanceof SolidBrushAdp ? (SolidBrushAdp)obj : null;}
public static SolidBrushAdp cast_(Object obj) {try {return (SolidBrushAdp)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, SolidBrushAdp.class, obj);}}
public static final SolidBrushAdp Black = new_(ColorAdp_.Black);
public static final SolidBrushAdp White = new_(ColorAdp_.White);
public static final SolidBrushAdp Null = new_(ColorAdp_.Null);
public static SolidBrushAdp new_(ColorAdp color) {return SolidBrushAdpCache._.Get_by(color);}
}
class SolidBrushAdpCache {
public SolidBrushAdp Get_by(ColorAdp color) {
SolidBrushAdp rv = (SolidBrushAdp)hash.Get_by(color.Value());
if (rv == null) {
rv = SolidBrushAdp.new_(color);
hash.Add(color.Value(), rv);
}
return rv;
}
Hash_adp hash = Hash_adp_.new_();
public static final SolidBrushAdpCache _ = new SolidBrushAdpCache(); SolidBrushAdpCache() {}
}

View File

@@ -0,0 +1,69 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.strings.*;
public class GfuiBorderMgr {
public PenAdp All() {return all;} public GfuiBorderMgr All_(PenAdp v) {SyncPens(true); all = v; return this;} PenAdp all;
public PenAdp Left() {return left;} public GfuiBorderMgr Left_(PenAdp v) {SyncPens(false); left = v; return this;} PenAdp left;
public PenAdp Right() {return right;} public GfuiBorderMgr Right_(PenAdp v) {SyncPens(false); right = v; return this;} PenAdp right;
public PenAdp Top() {return top;} public GfuiBorderMgr Top_(PenAdp v) {SyncPens(false); top = v; return this;} PenAdp top;
public PenAdp Bot() {return bot;} public GfuiBorderMgr Bot_(PenAdp v) {SyncPens(false); bot = v; return this;} PenAdp bot;
public void Bounds_sync(RectAdp v) {bounds = v;} RectAdp bounds = RectAdp_.Zero;
public void DrawData(GfxAdp gfx) {
if (all != null)
gfx.DrawRect(all, bounds);
else {
if (left != null) gfx.DrawLine(left, bounds.CornerBL(), bounds.CornerTL());
if (right != null) gfx.DrawLine(right, bounds.CornerTR(), bounds.CornerBR());
if (top != null) gfx.DrawLine(top, bounds.CornerTL(), bounds.CornerTR());
if (bot != null) gfx.DrawLine(bot, bounds.CornerBR(), bounds.CornerBL());
}
}
public GfuiBorderMgr None_() {Edge_set(GfuiBorderEdge.All, null); return this;}
public void Edge_setObj(Object o) {
if (o == null)
this.None_();
else {
Object[] ary = (Object[])o;
this.Edge_set(GfuiBorderEdge.All, PenAdp_.new_((ColorAdp)ary[1], Float_.cast_(ary[0])));
}
}
public void Edge_set(GfuiBorderEdge edge, PenAdp pen) {
int val = edge.Val();
if (val == GfuiBorderEdge.All.Val()) {all = pen; return;}
else if (val == GfuiBorderEdge.Left.Val()) {left = pen; return;}
else if (val == GfuiBorderEdge.Right.Val()) {right = pen; return;}
else if (val == GfuiBorderEdge.Top.Val()) {top = pen; return;}
else if (val == GfuiBorderEdge.Bot.Val()) {bot = pen; return;}
else throw Exc_.new_unhandled(edge);
}
void SyncPens(boolean isAll) {
if (isAll) {
left = null; right = null; top = null; bot = null;
}
else {
if (all != null) {
left = all.Clone(); right = all.Clone(); top = all.Clone(); bot = all.Clone();
}
all = null;
}
}
public String XtoStr() {return String_bldr_.new_().Add_kv_obj("all", all).Add_kv_obj("left", left).Add_kv_obj("right", right).Add_kv_obj("top", top).Add_kv_obj("bot", bot).XtoStr();}
@Override public String toString() {return XtoStr();}
public static GfuiBorderMgr new_() {return new GfuiBorderMgr();} GfuiBorderMgr() {}
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GfxAdp extends RlsAble {
void DrawLine(PenAdp pen, PointAdp src, PointAdp trg);
void DrawRect(PenAdp pen, int x, int y, int width, int height);
void DrawRect(PenAdp pen, PointAdp location, SizeAdp size);
void DrawRect(PenAdp pen, RectAdp rect);
void FillRect(SolidBrushAdp brush, int x, int y, int width, int height);
void DrawImage(ImageAdp image, PointAdp location);
void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h);
void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd);
float[] MeasureStringXtn(String s, FontAdp font, GfxStringData sd);
}

View File

@@ -0,0 +1,107 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
public class GfxAdpBase implements GfxAdp {
public void DrawLine(PenAdp pen, PointAdp src, PointAdp trg) {
gfx.setColor(ColorAdpCache._.GetNativeColor(pen.Color()));
gfx.setStroke(pen.UnderStroke());
gfx.drawLine(src.X(), src.Y(), trg.X(), trg.Y());
}
public void DrawRect(PenAdp pen, PointAdp pos, SizeAdp size) {this.DrawRect(pen, pos.X(), pos.Y(), size.Width(), size.Height());}
public void DrawRect(PenAdp pen, RectAdp rect) {this.DrawRect(pen, rect.X(), rect.Y(), rect.Width(), rect.Height());}
public void DrawRect(PenAdp pen, int x, int y, int width, int height) {
gfx.setPaint(ColorAdpCache._.GetNativeColor(pen.Color()));
gfx.setStroke(pen.UnderStroke());
gfx.drawRect(x, y, width, height);
}
public void FillRect(SolidBrushAdp brush, int x, int y, int width, int height) {
gfx.setPaint(ColorAdpCache._.GetNativeColor(brush.Color()));
gfx.fillRect(x, y, width, height);
}
public void DrawStringXtn(String s, FontAdp font, SolidBrushAdp brush, float x, float y, float width, float height, GfxStringData sd) {
gfx.setPaint(ColorAdpCache._.GetNativeColor(brush.Color()));
// height = y - ascent + descent -> rect.y - rect.height [assume ascent] + 2 [assume descent]
gfx.setClip((int)x, (int)y - (int)height + 2, (int)width, (int)height);
if (sd == null || sd.mnemonicString == null) {
gfx.setFont(font.UnderFont());
gfx.drawString(s, x, y - 2);
}
else {
gfx.drawString(sd.mnemonicString.getIterator(), x, y - 2);
}
gfx.setClip(null);
}
public float[] MeasureStringXtn(String s, FontAdp font, GfxStringData sd) {
FontMetrics fontMetrics = gfx.getFontMetrics(font.UnderFont());
Rectangle2D stringMetrics = fontMetrics.getStringBounds(s, gfx);
float width = (float)stringMetrics.getWidth();
int height = fontMetrics.getHeight();
int descent = fontMetrics.getDescent();
return new float[] {width, height, descent};
}
public static float[] GetStringBounds(String s, FontAdp font, Object o) {
JComponent jcomponent = (JComponent)o;
Graphics2D gfx = (Graphics2D)jcomponent.getGraphics();
FontMetrics fontMetrics = gfx.getFontMetrics(font.UnderFont());
Rectangle2D stringMetrics = fontMetrics.getStringBounds(s, gfx);
float width = (float)stringMetrics.getWidth();
int height = fontMetrics.getHeight();
int descent = fontMetrics.getDescent();
return new float[] {width, height, descent};
}
public void DrawImage(ImageAdp image, PointAdp pt) {
if (image == ImageAdp_.Null) return;
gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gfx.drawImage((java.awt.Image)image.Under(), pt.X(), pt.Y(), null);
// gfx.drawImage(image.UnderImage(),pt.X(),pt.Y(),
// pt.X()+image.Width(),pt.Y()+image.Height(),
// pt.X(),pt.Y(),
// pt.X()+image.Width(),pt.Y()+image.Height(),
// null);
}
public void DrawImage(ImageAdp img, int trg_x, int trg_y, int trg_w, int trg_h, int src_x, int src_y, int src_w, int src_h) {
if (img == ImageAdp_.Null) return;
gfx.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gfx.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
gfx.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gfx.drawImage((java.awt.Image)img.Under(), trg_x, trg_y, trg_x + trg_w, trg_y + trg_h, src_x, src_y, src_x + src_w, src_y + src_h, null);
}
public void Rls() {gfx.dispose();}
public Object Under() {return gfx;}
Graphics2D gfx;
@gplx.Internal protected static GfxAdpBase new_(Graphics2D gfx) {
GfxAdpBase rv = new GfxAdpBase();
rv.gfx = gfx;
return rv;
} GfxAdpBase() {}
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.Graphics2D;
public class GfxAdp_ {
@gplx.Internal protected static GfxAdp new_(Graphics2D graphics) {return GfxAdpBase.new_(graphics);}
public static GfxAdp image_(ImageAdp image) {
Graphics2D graphics = (Graphics2D)((java.awt.Image)image.Under()).getGraphics();
return GfxAdpBase.new_(graphics);
}
}

View File

@@ -0,0 +1,115 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.font.TextAttribute;
import java.text.AttributedString;
public class GfxStringData {
public String Val() {
if (ownerElem == null) return val;
if (ownerElem.TextVal() == null) return "";
return ownerElem.TextVal();
} String val = "";
public GfuiAlign AlignH() {return alignH;} GfuiAlign alignH;
public GfxStringData AlignH_(GfuiAlign val) {
alignH = val;
if (ownerElem != null) GfoInvkAble_.InvkCmd_val(ownerElem, GxwElem_lang.AlignH_cmd, alignH); // needed for TextBox, since its Paint is not overriden
TextRect_setNull();
return this;
}
public GfuiAlign AlignV() {return alignV;} public GfxStringData AlignV_(GfuiAlign val) {alignV = val; return this;} GfuiAlign alignV = GfuiAlign_.Mid;
public ColorAdp Color() {return brush.Color();}
public SolidBrushAdp UnderBrush() {return brush;} SolidBrushAdp brush;
public AttributedString MnemonicString() {return mnemonicString;} AttributedString mnemonicString;
String drawn = "";
public void MnemonicString_sync() {
int pos = GfuiWinKeyCmdMgr.ExtractPosFromText(this.Val()); if (pos == String_.Find_none) return;
drawn = String_.MidByLen(this.Val(), 0, pos) + String_.Mid(this.Val(), pos + 1); // rebuild string without &
mnemonicString = new AttributedString(drawn);
mnemonicString.addAttribute(TextAttribute.FONT, font.UnderFont());
mnemonicString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, pos, pos + 1);
}
public GfxStringData Color_(ColorAdp val) {
brush = SolidBrushAdp_.new_(val);
if (ownerElem != null) ownerElem.Core().ForeColor_set(val);
TextRect_setNull();
return this;
}
public FontAdp Font() {return font;} FontAdp font;
public GfxStringData Font_(FontAdp val) {
font = val;
if (!Env_.Mode_testing() && ownerElem != null) ownerElem.Core().TextFont_set(font);
TextRect_setNull();
MnemonicString_sync();
return this;
}
public RectAdpF TextRect() {return textRect;} public void TextRect_set(RectAdpF val) {textRect = val;} public void TextRect_setNull() {textRect = RectAdpF.Null;} RectAdpF textRect = RectAdpF.Null;
public RectAdpF TextRect_setX(int x) {
textRect = RectAdpF.new_(x, textRect.Y(), textRect.Width(), textRect.Height());
return textRect;
}
@gplx.Internal protected SizeAdp OwnerSize() {return ownerSize;}
public void OwnerSize_sync(SizeAdp val) {
ownerSize = val; TextRect_setNull();
ownerElem.Core().Invalidate(); // NOTE: force redraw; this may be redundant in WINFORMS but needed in SWING especially when windowOpened causes resize; SWING seems to execute windowOpened -> resize -> paint -> componentResized
} SizeAdp ownerSize = SizeAdp_.new_(20, 20);
@gplx.Internal protected GxwElem UnderElem() {return owner.UnderElem();}
public void DrawData(GfxAdp gfx) {
if (textRect.Eq(RectAdpF.Null)) {textRect = TextRect_calc(gfx);}
gfx.DrawStringXtn(this.Val(), font, brush, textRect.X(), textRect.Y(), textRect.Width(), textRect.Height(), this);
}
@gplx.Internal protected void Text_set(String v) {
if (this.Val() == v) return;
if (ownerElem != null) {
ownerElem.TextVal_set(v);
if (owner.CustomDraw()) ownerElem.Core().Invalidate();
}
else
this.val = v;
TextRect_setNull();
MnemonicString_sync();
}
public RectAdpF TextRect_calc(GfxAdp gfx) {
float[] sizeAry = gfx.MeasureStringXtn(drawn == "" ? this.Val() : drawn, font, this);
float width = sizeAry[0], height = sizeAry[1], descent = sizeAry[2];
// if (String_.Eq("opal.gfds 0.0.1", this.Val())) {
// Tfds.Write(this.Val(), alignH.Val(), (int)width, ownerSize.Width());
// }
float x = GfuiAlign_.CalcInsideOfAxis(alignH.Val(), (int)width, ownerSize.Width());
float y = 0; int alignVVal = alignV.Val(); float ownerHeight = ownerSize.Height();
if (alignVVal == GfuiAlign_.Null.Val()) y = Int_.MinValue;
else if (alignVVal == GfuiAlign_.Lo.Val()) y = height - descent;
else if (alignVVal == GfuiAlign_.Mid.Val()) y = (ownerHeight - (ownerHeight - height) / 2);// - descent; // COMMENT: subtracting descent is theoretically correct, but practically results in text shifted up
else if (alignVVal == GfuiAlign_.Hi.Val()) y = ownerHeight - descent;
if (width > ownerElem.Core().Width()) width = ownerElem.Core().Width(); // clip to elem size or else text overflows; EX: tab buttons
if (x < 0) x = 0; if (y < 0) y = 0; // occurs when text is larger than elem; do not allow negative values
return RectAdpF.new_(x, y, width, height);
} GfuiElemBase owner; GxwElem ownerElem;
public static GfxStringData new_(GfuiElemBase owner, GxwElem ownerElem) {
GfxStringData rv = new GfxStringData();
rv.brush = SolidBrushAdp_.Black;
rv.alignH = GfuiAlign_.Left;
rv.owner = owner;
rv.ownerElem = ownerElem;
// WORKAROUND:.NET: setting font on textBox causes odd selection behavior for MediaTimeBox
rv.Font_(FontAdp.new_("Arial", 8, FontStyleAdp_.Plain)); // needed for TextBox, since its Paint is not overriden, and .Font property must be set
return rv;
} GfxStringData() {}
public static final GfxStringData Null = null;
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class PaintArgs {
public GfxAdp Graphics() {return graphics;} GfxAdp graphics;
public RectAdp ClipRect() {return clipRect;} RectAdp clipRect;
public static PaintArgs cast_(Object obj) {try {return (PaintArgs)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, PaintArgs.class, obj);}}
public static PaintArgs new_(GfxAdp graphics, RectAdp clipRect) {
PaintArgs rv = new PaintArgs();
rv.graphics = graphics; rv.clipRect = clipRect;
return rv;
}
}

View File

@@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.strings.*;
public interface IptArg {
String Key();
boolean Eq(IptArg comp); // NOTE: this relies on unique key across all IptArgs; EX: .Key() cannot be just "left"; would have issues with key.left and mouse.left
}
class IptKeyChain implements IptArg {
public String Key() {return key;} private String key;
public boolean Eq(IptArg comp) {return String_.Eq(key, comp.Key());}
public IptArg[] Chained() {return chained;} IptArg[] chained;
@gplx.Internal protected IptKeyChain(IptArg[] ary) {
chained = ary;
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < ary.length; i++) {
IptArg itm = ary[i];
sb.Add_spr_unless_first(itm.Key(), ",", i);
}
key = sb.XtoStr();
}
public static IptKeyChain parse_(String raw) {
String[] itms = String_.Split(raw, ",");
IptArg[] rv = new IptArg[itms.length];
for (int i = 0; i < rv.length; i++)
rv[i] = IptArg_.parse_(String_.Trim(itms[i]));
return new IptKeyChain(rv);
}
}

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*;
public class IptArgChainMgr_tst {
@Before public void setup() {
fx = new IptArgChainMgr_fx();
} IptArgChainMgr_fx fx;
@Test public void Add() {
fx.run_Add(IptKey_.A, IptKey_.B, IptKey_.C);
fx.tst_(IptKey_.A, 1);
fx.tst_(IptKey_.B, 1);
fx.tst_(IptKey_.C, 2);
fx.tst_(IptKey_.B, 0);
fx.tst_(IptKey_.C, 0);
}
@Test public void Del() {
fx.run_Add(IptKey_.A, IptKey_.B, IptKey_.C);
fx.run_Del(IptKey_.A, IptKey_.B, IptKey_.C);
fx.tst_(IptKey_.A, 0);
fx.tst_(IptKey_.B, 0);
fx.tst_(IptKey_.C, 0);
}
class IptArgChainMgr_fx {
public IptArgChainMgr Under() {return under;} IptArgChainMgr under = new IptArgChainMgr();
public IptArgChainMgr_fx run_Add(IptKey... ary) {under.Add(new IptKeyChain(ary)); return this;}
public IptArgChainMgr_fx run_Del(IptKey... ary) {under.Del(new IptKeyChain(ary)); return this;}
public IptArgChainMgr_fx tst_(IptKey key, int expd) {
String process = under.Process(key);
String activeKey = under.ActiveKey();
String literal = key.Key();
if (expd == 0) {
Tfds.Eq(process, "", "0:{0} should be empty:process", literal);
Tfds.Eq(activeKey, "", "0:{0} should be noop:activeKey", literal);
}
else if (expd == 1) {
Tfds.Eq(process, "", "1:{0} should be empty:process", literal);
Tfds.Eq_true(String_.Has_at_end(activeKey, key.Key() + ","), "1:{0} should set key:activeKey,{1}", literal, activeKey);
}
else if (expd == 2) {
Tfds.Eq_true(String_.EqNot(process, ""), "2:{0} should not be empty;process,{1}", literal, process);
Tfds.Eq(activeKey, "", "2:{0} should be empty:activeKey", literal);
}
return this;
}
}
}

View File

@@ -0,0 +1,118 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptArg_ {
public static final IptArg[] Ary_empty = new IptArg[0];
public static final IptArg Null = null;
public static final String Wildcard_key = "wildcard";
public static IptArg Wildcard = new IptKey(Int_.MaxValue, Wildcard_key);
public static boolean Is_null_or_none(IptArg arg) {return arg == Null || arg == IptKey_.None;}
public static IptArg[] Ary(IptArg... v) {return v;}
public static IptArg[] parse_ary_or_empty(String v) {
IptArg[] rv = IptArg_.parse_ary_(v);
int len = rv.length;
for (int i = 0; i < len; i++)
if (rv[i] == null) return Ary_empty;// indicates failed parse
return rv;
}
public static IptArg[] parse_ary_(String raw) {
String[] args = String_.Split(raw, "|");
int args_len = args.length; if (args_len == 0) return Ary_empty;
IptArg[] rv = new IptArg[args_len];
for (int i = 0; i < args_len; i++)
rv[i] = parse_(String_.Trim(args[i]));
return rv;
}
public static IptArg parse_chain_(String raw) {return IptKeyChain.parse_(raw);}
public static IptArg parse_or_none_(String raw) {
try {
return String_.Eq(raw, String_.Empty)
? IptKey_.None
: parse_(raw);
}
catch (Exception exc) { // as an "or" proc, handle errors; note that it may accept raw values from cfg files, so invalid input is possible; DATE:2014-06-04
Exc_.Noop(exc);
return IptKey_.None;
}
}
public static IptArg parse_(String raw) {
if (String_.Has(raw, ",")) return IptKeyChain.parse_(raw);
String bgn = String_.GetStrBefore(raw, ".");
if (String_.Eq(bgn, "wheel")) return IptMouseWheel_.parse_(raw);
else if (String_.Eq(bgn, "mouse")) return IptMouseBtn_.parse_(raw);
else if (String_.Eq(bgn, "key")) return IptKey_.parse_(raw);
else return IptMacro._.parse_(raw);
}
// NOTE: the following two methods should theoretically be interface methods, but since they are only used by two procs, they will be handled with if/else
@gplx.Internal protected static IptEventType EventType_default(IptArg arg) {
Class<?> type = arg.getClass();
if ( type == IptKey.class
|| type == IptKeyChain.class) return IptEventType_.KeyDown;
else if (type == IptMouseBtn.class) return IptEventType_.MouseUp; // changed from MouseDown; confirmed against Firefox, Eclipse; DATE:2014-05-16
else if (type == IptMouseWheel.class) return IptEventType_.MouseWheel;
else if (type == IptMouseMove.class) return IptEventType_.MouseMove;
else throw Exc_.new_unhandled(type);
}
@gplx.Internal protected static boolean EventType_match(IptArg arg, IptEventType match) {
Class<?> type = arg.getClass();
if ( type == IptKey.class
|| type == IptKeyChain.class) return match == IptEventType_.KeyDown || match == IptEventType_.KeyUp || match == IptEventType_.KeyDown;
else if (type == IptMouseBtn.class) return match == IptEventType_.MouseDown || match == IptEventType_.MouseUp || match == IptEventType_.MousePress;
else if (type == IptMouseWheel.class) return match == IptEventType_.MouseWheel;
else if (type == IptMouseMove.class) return match == IptEventType_.MouseMove;
else throw Exc_.new_unhandled(type);
}
}
class IptMacro {
public void Reg(String prefix, String alias, IptArg arg) {
if (regy == null) Init();
Ordered_hash list = (Ordered_hash)regy.Get_by(prefix);
if (list == null) {
list = Ordered_hash_.new_();
regy.Add(prefix, list);
}
list.Add_if_dupe_use_nth(alias, arg);
}
void Init() {
regy = Ordered_hash_.new_();
Reg("mod", "c", IptKey_.add_(IptKey_.Ctrl));
Reg("mod", "a", IptKey_.add_(IptKey_.Alt));
Reg("mod", "s", IptKey_.add_(IptKey_.Shift));
Reg("mod", "ca", IptKey_.add_(IptKey_.Ctrl, IptKey_.Alt));
Reg("mod", "cs", IptKey_.add_(IptKey_.Ctrl, IptKey_.Shift));
Reg("mod", "as", IptKey_.add_(IptKey_.Alt, IptKey_.Shift));
Reg("mod", "cas", IptKey_.add_(IptKey_.Ctrl, IptKey_.Alt, IptKey_.Shift));
}
public IptArg parse_(String raw) {
if (regy == null) Init();
String[] plusAry = String_.Split(raw, "+");
String[] dotAry = String_.Split(plusAry[0], ".");
String bgn = dotAry[0], end = dotAry[1];
Ordered_hash list = (Ordered_hash)regy.Get_by(bgn);
if (list == null) throw parse_err(raw, "list not found").Args_add("list", bgn);
IptKey rv = (IptKey)list.Get_by(end);
if (rv == null) throw parse_err(raw, "arg not found").Args_add("arg", end);
for (int i = 1; i < plusAry.length; i++) {
rv = rv.Add((IptKey)IptKey_.parse_(plusAry[i]));
}
return rv;
}
Ordered_hash regy;
static Exc parse_err(String raw, String loc) {return Exc_.new_w_type("gfui", "could not parse IptArg", "raw", raw, "loc", loc).Stack_erase_1_();}
public static final IptMacro _ = new IptMacro(); IptMacro() {}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface IptBnd extends SrlAble {
String Key();
List_adp Ipts();
IptEventType EventTypes();
void Exec(IptEventData iptData);
}

View File

@@ -0,0 +1,293 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptBndMgr implements SrlAble {
@gplx.Internal protected IptEventType EventsToFwd() {return eventsToFwd;}
public void EventsToFwd_set(IptEventType v) {eventsToFwd = v;} IptEventType eventsToFwd = IptEventType_.KeyDown;
public void EventsToFwd_add(IptEventType v) {eventsToFwd = eventsToFwd.Add(v);}
@gplx.Internal protected boolean Has(IptEventType type) {return IptEventType_.Has(curTypes, type);}
public void Clear() {hash.Clear(); curTypes = IptEventType_.None; ClearLists(); chainMgr.Clear();}
public void Add(IptBnd bnd) {
for (IptBndHash list : regy)
if (IptEventType_.Has(bnd.EventTypes(), list.EventType()))
list.Add(bnd);
for (int i = 0; i < bnd.Ipts().Count(); i++) {
IptArg arg = (IptArg)bnd.Ipts().Get_at(i);
chainMgr.Add(arg);
}
}
@gplx.Internal protected List_adp Cfgs() {return cfgs;} List_adp cfgs = List_adp_.new_();
@gplx.Internal protected void Cfgs_delAll() {
List_adp del = List_adp_.new_();
for (int i = 0; i < cfgs.Count(); i++) {
IptCfgPtr ptr = (IptCfgPtr)cfgs.Get_at(i);
IptCfg cfg = IptCfgRegy._.GetOrNew(ptr.CfgKey());
cfg.Owners_del(ptr.CfgKey());
for (IptBndHash list : regy) {
for (int j = 0; j < list.Count(); j++) {
IptBndListItm itmList = list.Get_at(j);
for (int k = 0; k < itmList.Count(); k++) {
IptBnd bnd = itmList.Get_at(k);
if (String_.Eq(ptr.BndKey(), bnd.Key())) {
list.Del(bnd);
}
}
}
}
del.Add(cfg);
}
for (int i = 0; i < del.Count(); i++) {
IptCfg cfg = (IptCfg)del.Get_at(i);
cfgs.Del(cfg);
}
}
public void Change(String key, IptArg[] ary) {
IptBnd old = null;
for (IptBndHash list : regy) {
for (int j = 0; j < list.Count(); j++) {
IptBndListItm itmList = list.Get_at(j);
for (int i = 0; i < itmList.Count(); i++) {
IptBnd bnd = itmList.Get_at(i);
if (String_.Eq(key, bnd.Key())) {
old = bnd;
break;
}
}
}
}
if (old == null) return;
this.Del(old);
old.Ipts().Clear();
if (ary == IptArg_.Ary_empty) return; // "unbind"; exit after deleting; DATE:2014-05-13
old.Ipts().Add_many((Object[])ary);
this.Add(old);
}
public void Del_by_key(String key) {Del_by(true, key);}
public void Del_by_ipt(IptArg ipt) {
if (IptArg_.Is_null_or_none(ipt)) return;
Del_by(false, ipt.Key());
}
private void Del_by(boolean del_by_key, String del_key) {
int regy_len = regy.length;
List_adp deleted = List_adp_.new_();
for (int i = 0; i < regy_len; i++) {
IptBndHash list = regy[i];
int list_len = list.Count();
for (int j = 0; j < list_len; j++) {
IptBndListItm bnds = list.Get_at(j);
int bnds_len = bnds.Count();
for (int k = 0; k < bnds_len; k++) {
IptBnd itm_bnd = bnds.Get_at(k);
if (del_by_key) {
if (String_.Eq(del_key, itm_bnd.Key())) {
deleted.Add(itm_bnd);
}
}
else {
if (itm_bnd.Ipts().Count() != 1) continue; // only delete if bnd has 1 ipt; should only be called by xowa which does 1 bnd per ipt
IptArg itm_ipt = (IptArg)itm_bnd.Ipts().Get_at(0);
if (String_.Eq(del_key, itm_ipt.Key()))
deleted.Add(itm_bnd);
}
}
}
}
int deleted_len = deleted.Count();
for (int i = 0; i < deleted_len; i++) {
IptBnd bnd = (IptBnd)deleted.Get_at(i);
this.Del(bnd);
bnd.Ipts().Clear();
}
}
public void Del(IptBnd bnd) {
for (IptBndHash list : regy) {
if (IptEventType_.Has(bnd.EventTypes(), list.EventType())) {
list.Del(bnd);
}
}
for (int i = 0; i < bnd.Ipts().Count(); i++) {
IptArg arg = (IptArg)bnd.Ipts().Get_at(i);
chainMgr.Del(arg);
}
}
@gplx.Internal protected boolean Process(IptEventData evData) {
IptBndHash list = regy[AryIdx(evData.EventType())];
String key = evData.EventArg().Key();
if (!String_.Eq(chainMgr.ActiveKey(), "")) key = chainMgr.ActiveKey() + key;
IptBndListItm itm = list.Get_by(key);
String chainP = "";
if (evData.EventType() == IptEventType_.KeyDown) {
chainP = chainMgr.Process(evData.EventArg());
if (!String_.Eq(chainP, "") && itm == null)
UsrDlg_._.Note("cancelled... {0}", chainP);
}
if (itm == null) {
return false;
}
return itm.Exec(evData);
}
public Object Srl(GfoMsg owner) {
GfoMsg m = GfoMsg_.srl_(owner, "mgr");
for (int i = 0; i < hash.Count(); i++)
((IptBnd)hash.Get_at(i)).Srl(m);
return this;
}
IptArgChainMgr chainMgr = new IptArgChainMgr();
Ordered_hash hash = Ordered_hash_.new_(); IptEventType curTypes = IptEventType_.None;
public static IptBndMgr new_() {return new IptBndMgr();}
IptBndHash[] regy = new IptBndHash[8];
IptBndMgr() {ClearLists();}
void ClearLists(){
MakeList(IptEventType_.KeyDown); MakeList(IptEventType_.KeyUp); MakeList(IptEventType_.KeyPress);
MakeList(IptEventType_.MouseMove); MakeList(IptEventType_.MouseDown); MakeList(IptEventType_.MouseUp); MakeList(IptEventType_.MouseWheel); MakeList(IptEventType_.MousePress);
} void MakeList(IptEventType eventType) {regy[AryIdx(eventType)] = new IptBndHash(eventType);}
static int AryIdx(IptEventType eventType) {
int v = eventType.Val();
if (v == IptEventType_.KeyDown.Val()) return 0;
else if (v == IptEventType_.KeyUp.Val()) return 1;
else if (v == IptEventType_.KeyPress.Val()) return 2;
else if (v == IptEventType_.MouseDown.Val()) return 3;
else if (v == IptEventType_.MouseUp.Val()) return 4;
else if (v == IptEventType_.MouseMove.Val()) return 5;
else if (v == IptEventType_.MouseWheel.Val()) return 6;
else if (v == IptEventType_.MousePress.Val()) return 7;
else throw Exc_.new_unhandled(v);
}
}
class IptBndHash implements SrlAble {
private IptBndListItm wildcard_list;
public IptEventType EventType() {return eventType;} IptEventType eventType;
public int Count() {return hash.Count();}
public IptBndListItm Get_by(String key) {return wildcard_list == null ? (IptBndListItm)hash.Get_by(key) : wildcard_list;}
public IptBndListItm Get_at(int i) {return (IptBndListItm)hash.Get_at(i);}
public void Add(IptBnd bnd) {
for (int i = 0; i < bnd.Ipts().Count(); i++) {
IptArg arg = (IptArg)bnd.Ipts().Get_at(i);
if (!IptArg_.EventType_match(arg, eventType)) continue; // bnd may have multiple ipts of different evTypes; only add bnd if evType matches
if (String_.Eq(arg.Key(), IptArg_.Wildcard_key)) {
if (wildcard_list == null) wildcard_list = new IptBndListItm(IptArg_.Wildcard_key);
wildcard_list.Add(bnd);
}
else {
IptBndListItm itm = (IptBndListItm)hash.Get_by(arg.Key());
if (itm == null) {
itm = new IptBndListItm(arg.Key());
hash.Add(arg.Key(), itm);
}
itm.Add(bnd);
}
}
}
public void Del(IptBnd bnd) {
for (int i = 0; i < bnd.Ipts().Count(); i++) {
IptArg arg = (IptArg)bnd.Ipts().Get_at(i);
if (!IptArg_.EventType_match(arg, eventType)) continue; // bnd may have multiple ipts of different evTypes; only add bnd if evType matches
hash.Del(arg.Key());
}
}
public Object Srl(GfoMsg owner) {
GfoMsg m = GfoMsg_.srl_(owner, "list").Add("eventType", eventType.Name());
for (int i = 0; i < hash.Count(); i++)
((IptBndListItm)hash.Get_at(i)).Srl(m);
return this;
}
Ordered_hash hash = Ordered_hash_.new_();
public IptBndHash(IptEventType eventType) {this.eventType = eventType;}
}
class IptBndListItm implements SrlAble {
public String IptKey() {return iptKey;} private String iptKey;
public int Count() {return list.Count();}
public IptBnd Get_at(int i) {return (IptBnd)list.Get_at(i);}
public void Add(IptBnd bnd) {list.Add_at(0, bnd);}
public boolean Exec(IptEventData evData) {
for (int i = 0; i < list.Count(); i++) {
IptBnd bnd = (IptBnd)list.Get_at(i);
try {bnd.Exec(evData);}
catch (Exception exc) {
UsrDlg_._.Stop(UsrMsg.new_("Error while processing event").Add("bnd", SrlAble_.XtoStr(bnd)).Add("exc", Err_.Message_lang(exc)));
return false;
}
if (evData.CancelIteration) break;
}
return true;
}
public Object Srl(GfoMsg owner) {
GfoMsg m = GfoMsg_.srl_(owner, "itm").Add("iptKey", iptKey);
for (int i = 0; i < list.Count(); i++)
((IptBnd)list.Get_at(i)).Srl(m);
return this;
}
List_adp list = List_adp_.new_();
public IptBndListItm(String iptKey) {this.iptKey = iptKey;}
}
class IptArgChainMgr {
public void Clear() {regy.Clear();}
public String Process(IptArg arg) {
// if (String_.Eq(arg.Key(), "key_7")) return "";
Hash_adp hash = (Hash_adp)active.Get_by(arg.Key());
if (hash == null) {
active = regy;
String r = activeKey;
activeKey = "";
return r;
}
active = hash;
activeKey = activeKey + arg.Key() + ",";
UsrDlg_._.Note("{0} pressed...", activeKey);
return "";
}
public String ActiveKey() {return activeKey;}
String activeKey = "";
public IptArgChainMgr() {active = regy;}
Hash_adp active;
public void Add(IptArg arg) {
if (arg.getClass() != IptKeyChain.class) return;
IptKeyChain chain = (IptKeyChain)arg;
Add_recur(regy, chain.Chained(), 0);
}
public void Del(IptArg arg) {
if (arg.getClass() != IptKeyChain.class) return;
IptKeyChain chain = (IptKeyChain)arg;
Del_recur(regy, chain.Chained(), 0);
}
void Add_recur(Hash_adp cur, IptArg[] ary, int i) {
if (i == ary.length - 1) return; // -1 b/c last should not be registered; ex: key.a,key.b should register key.a only
IptArg ipt = ary[i];
Hash_adp next = (Hash_adp)cur.Get_by(ipt.Key());
if (next == null) {
next = Hash_adp_.new_();
cur.Add(ipt.Key(), next);
}
Add_recur(next, ary, i + 1);
}// a,b,c
void Del_recur(Hash_adp cur, IptArg[] ary, int i) {
IptArg ipt = ary[i];
if (i == ary.length - 1) {
cur.Del(ipt.Key());
return; // -1 b/c last should not be registered; ex: key.a,key.b should register key.a only
}
Hash_adp next = (Hash_adp)cur.Get_by(ipt.Key());
if (next == null) {
return;
}
Del_recur(next, ary, i + 1);
if (cur.Count() == 1)
cur.Clear();
}
Hash_adp regy = Hash_adp_.new_();
}

View File

@@ -0,0 +1,72 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*; import gplx.core.strings.*;
public class IptBndMgr_tst {
@Before public void setup() {
fx = new IptBndMgr_fx();
} IptBndMgr_fx fx;
@Test public void Add() {
fx.ini_Clear().run_Add("key.a").tst_Exec_same("key.a").tst_Exec_none("key.b");
fx.ini_Clear().run_Add("key.ctrl+key.a").tst_Exec_same("key.ctrl+key.a").tst_Exec_none("key.ctrl").tst_Exec_none("key.a");
fx.ini_Clear().run_Add("key.a|key.b").tst_Exec_same("key.a").tst_Exec_same("key.b").tst_Exec_none("key.c");
fx.ini_Clear().run_Add("mouse.left").tst_Exec_same("mouse.left");
fx.ini_Clear().run_Add("key.a,key.b")
.tst_Exec_none("key.a").tst_Exec_same("key.b")
.tst_Exec_none("key.a").tst_Exec_none("key.c").tst_Exec_none("key.a").tst_Exec_same("key.b")
.tst_Exec_none("key.a").tst_Exec_none("key.a").tst_Exec_none("key.b");
}
class IptBndMgr_fx {
public IptBndMgr Under() {return under;} IptBndMgr under = IptBndMgr.new_();
public IptBndMgr_fx ini_Clear() {under.Clear(); return this;}
public IptBndMgr_fx run_Add(String raw) {
IptArg[] args = IptArg_.parse_ary_(raw);
List_adp list = List_adp_.new_();
for (IptArg arg : args)
list.Add(arg);
IptBnd_mok bnd = new IptBnd_mok(output).Key_(raw).Ipts_(list).EventTypes_(IptEventType_.default_(args));
under.Add(bnd);
return this;
}
public IptBndMgr_fx tst_Exec_none(String key) {return tst_Exec(key, "");}
public IptBndMgr_fx tst_Exec_same(String key) {return tst_Exec(key, key);}
public IptBndMgr_fx tst_Exec(String key, String expd) {
output.Clear();
IptArg[] args = IptArg_.parse_ary_(key);
for (IptArg arg : args) {
IptEventData evData = IptEventData.new_(null, IptArg_.EventType_default(arg), arg, null, null);
under.Process(evData);
}
Tfds.Eq(expd, output.XtoStr());
return this;
}
String_bldr output = String_bldr_.new_();
public IptBndMgr_fx() {}
}
class IptBnd_mok implements IptBnd {
public String Key() {return key;} public IptBnd_mok Key_(String v) {key = v; return this;} private String key;
public List_adp Ipts() {return args;} public IptBnd_mok Ipts_(List_adp v) {args = v; return this;} List_adp args;
public IptEventType EventTypes() {return eventTypes;} public IptBnd_mok EventTypes_(IptEventType v) {eventTypes = v; return this;} IptEventType eventTypes;
public Object Srl(GfoMsg owner) {return this;}
public void Exec(IptEventData iptData) {
output.Add(iptData.EventArg().Key());
}
public IptBnd_mok(String_bldr v) {output = v;} String_bldr output;
}
}

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.strings.*;
public class IptBnd_ {
public static void msg_(IptCfg cfg, IptBndsOwner box, String bndKey, GfoMsg m, IptArg... ipt) {bld_(cfg, box, GfoInvkAble_.as_(box), bndKey, m, ipt);}
public static void msg_to_(IptCfg cfg, IptBndsOwner box, GfoInvkAble invk, String bndKey, GfoMsg m, IptArg... ipt) {
bld_(cfg, box, invk, bndKey, m, ipt);
}
public static void cmd_(IptCfg cfg, IptBndsOwner box, String key, IptArg... ipt) {bld_(cfg, box, GfoInvkAble_.as_(box), key, GfoMsg_.new_cast_(key), ipt);}
public static void cmd_to_(IptCfg cfg, IptBndsOwner box, GfoInvkAble invk, String key, IptArg... ipt) {bld_(cfg, box, invk, key, GfoMsg_.new_cast_(key), ipt);}
public static void ipt_to_(IptCfg cfg, IptBndsOwner box, GfoInvkAble invk, String key, IptEventType eventType, IptArg... ipt) {bld_(cfg, box, invk, key, GfoMsg_.new_cast_(key), eventType, ipt);}
static void bld_(IptCfg cfg, IptBndsOwner box, GfoInvkAble invk, String bndKey, GfoMsg m, IptArg... ipt) {bld_(cfg, box, invk, bndKey, m, IptEventType_.default_(ipt), ipt);}
static void bld_(IptCfg cfg, IptBndsOwner box, GfoInvkAble invk, String bnd_key, GfoMsg m, IptEventType ev_type, IptArg... ipt) {
IptCfgItm itm = cfg.GetOrDefaultArgs(bnd_key, m, ipt);
IptBnd bnd = IptBnd_invk.new_(box, invk, itm, ev_type);
cfg.Owners_add(bnd_key, box);
box.IptBnds().Add(bnd);
}
public static Object Srl(GfoMsg owner, IptBnd bnd) {GfoMsg_.srl_(owner, "bnd").Add("key", bnd.Key()).Add("ipt", AryXtoStr(bnd.Ipts())); return bnd;}
static String AryXtoStr(List_adp ary) {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < ary.Count(); i++)
sb.Add_spr_unless_first(((IptArg)ary.Get_at(i)).Key(), "|", i);
return sb.XtoStr();
}
}
class IptBnd_invk implements IptBnd {
public String Key() {return key;} private String key;
public List_adp Ipts() {return ipts;} List_adp ipts;
public IptEventType EventTypes() {return eventTypes;} IptEventType eventTypes;
public void Exec(IptEventData iptData) {
GfoMsg newMsg = m.CloneNew();
newMsg.Add("iptData", iptData);
GfsCtx ctx = GfsCtx.new_().MsgSrc_(owner);
invk.Invk(ctx, 0, m.Key(), newMsg);
iptData.Handled_on(); // NOTE: treat invk as SingleDispatch
} IptBndsOwner owner; GfoInvkAble invk; IptCfgItm itm; GfoMsg m;
public Object Srl(GfoMsg owner) {return IptBnd_.Srl(owner, this);}
public static IptBnd_invk new_(IptBndsOwner owner, GfoInvkAble invk, IptCfgItm itm, IptEventType evType) {
IptBnd_invk rv = new IptBnd_invk();
rv.owner = owner; rv.invk = invk; rv.itm = itm;
rv.key = itm.Key(); rv.ipts = itm.Ipt(); rv.m = itm.Msg(); rv.eventTypes = evType;
return rv;
}
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptBnd_chkBox implements InjectAble, GfoEvObj {
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} GfoEvMgr evMgr;
public void Inject(Object owner) {
chkBox = GfuiChkBox_.cast_(owner);
GfoEvMgr_.Sub(chkBox, "Check_end", this, setCmd);
GfoEvMgr_.SubSame(fwd, setEvt, this);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, setCmd))
GfoInvkAble_.InvkCmd_val(invkAble, setCmd, chkBox.Val());
else if (ctx.Match(k, setEvt)) {
boolean v = m.ReadBool(msgArg);
chkBox.Val_sync(v);
}
else return GfoInvkAble_.Rv_unhandled;
return GfoInvkAble_.Rv_handled;
}
GfoEvObj fwd; GfoInvkAble invkAble; String setCmd, setEvt, msgArg; GfuiChkBox chkBox;
public static IptBnd_chkBox new_(GfoEvObj src, String setCmd, String setEvt, String msgArg) {
IptBnd_chkBox rv = new IptBnd_chkBox();
rv.fwd = src; rv.invkAble = GfoInvkAble_.cast_(src); rv.setCmd = setCmd; rv.setEvt = setEvt; rv.msgArg = msgArg;
return rv;
}
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptBnd_txt_cmd implements InjectAble, GfoInvkAble, GfoEvObj {
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} GfoEvMgr evMgr;
public void Inject(Object owner) {
txtBox = GfuiTextBox_.cast_(owner);
txtBox.TextAlignH_center_();
IptBnd_.cmd_to_(IptCfg_.Null, txtBox, this, TxtBox_exec, IptKey_.Enter);
GfoEvMgr_.SubSame(fwd, setEvt, this);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, TxtBox_exec)) GfoInvkAble_.InvkCmd_val(src, setCmd, cls.ParseOrNull(txtBox.Text()));
else if (ctx.Match(k, setEvt)) {
int v = m.ReadInt("v");
txtBox.Text_(cls.XtoUi(v, ClassXtnPool.Format_null));
}
else return GfoInvkAble_.Rv_unhandled;
return GfoInvkAble_.Rv_handled;
} static final String TxtBox_exec = "TxtBox_exec";
GfuiTextBox txtBox; GfoInvkAble src; GfoEvObj fwd; String setCmd, setEvt; ClassXtn cls;
public static IptBnd_txt_cmd new_(GfoEvObj fwd, String setCmd, String setEvt, ClassXtn cls) {
IptBnd_txt_cmd rv = new IptBnd_txt_cmd();
rv.fwd = fwd; rv.src = GfoInvkAble_.cast_(fwd);
rv.setCmd = setCmd; rv.setEvt = setEvt; rv.cls = cls;
return rv;
}
}

View File

@@ -0,0 +1,96 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptBnd_txt_range implements InjectAble, GfoInvkAble, GfoEvObj {
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} GfoEvMgr evMgr;
public IptBnd_txt_range InitSrc_(GfoEvObj initSrc) {this.initSrc = initSrc; return this;}
public IptBnd_txt_range InitEvt_(String initEvt) {this.initEvt = initEvt; return this;} String initEvt;
public IptBnd_txt_range PropSrc_(String getListCmd, String getCmd, String setCmd, String setEvt) {
this.getListCmd = getListCmd; this.getCmd = getCmd; this.setCmd = setCmd; this.setEvt = setEvt;
return this;
} String getListCmd, getCmd, setCmd, setEvt;
public IptBnd_txt_range PropList_(KeyVal[] list) {
this.list = list;
return this;
} KeyVal[] list = null;
public void Inject(Object owner) {
txtBox = GfuiTextBox_.cast_(owner);
txtBox.TextAlignH_center_();
IptBnd_.cmd_to_(IptCfg_.Null, txtBox, this, Invk_dec, IptKey_.Down, IptMouseWheel_.Down);
IptBnd_.cmd_to_(IptCfg_.Null, txtBox, this, Invk_inc, IptKey_.Up, IptMouseWheel_.Up);
IptBnd_.cmd_to_(IptCfg_.Null, txtBox, this, Invk_upd, IptKey_.Enter, IptMouseBtn_.Middle);
GfoEvMgr_.SubSame(initSrc, initEvt, this);
GfoEvMgr_.SubSame(propSrc, setEvt, this);
} GfuiTextBox txtBox; int previewIdx; GfoEvObj propSrc, initSrc; GfoInvkAble propInvk;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.MatchPriv(k, Invk_dec)) PreviewCmd(-1);
else if (ctx.MatchPriv(k, Invk_inc)) PreviewCmd( 1);
else if (ctx.MatchPriv(k, Invk_upd)) return UpdateCmd();
else if (ctx.MatchPriv(k, setEvt)) WhenEvtCmd(m.CastObj("v"));
else if (ctx.MatchPriv(k, initEvt)) ReadyEvtCmd();
else return GfoInvkAble_.Rv_unhandled;
return GfoInvkAble_.Rv_handled;
} static final String Invk_dec = "txtBox_dec", Invk_inc = "txtBox_inc", Invk_upd = "txtBox_exec";
void PreviewCmd(int delta) {
int newVal = previewIdx + delta;
if (!Int_.RangeCheck(newVal, list.length)) return;
WhenEvtCmd(list[newVal].Key_as_obj());
}
Object UpdateCmd() {
int idx = Int_.MinValue;
String find = txtBox.Text();
for (int i = 0; i < list.length; i++) { // try to find .Text in list.Vals
if (String_.Eq(find, (String)list[i].Val())) idx = i;
}
if (idx == Int_.MinValue) { // try to find .Text in list.Keys
int key = Int_.parse_or_(txtBox.Text(), Int_.MinValue); if (key == Int_.MinValue) return GfoInvkAble_.Rv_unhandled;
idx = GetByKey(key); if (idx == Int_.MinValue) return GfoInvkAble_.Rv_unhandled;
}
ExecCmd(setCmd, idx);
return GfoInvkAble_.Rv_handled;
}
void ReadyEvtCmd() {
if (getListCmd != null)
list = (KeyVal[])GfoInvkAble_.InvkCmd(propInvk, getListCmd);
Object curId = GfoInvkAble_.InvkCmd(propInvk, getCmd);
WhenEvtCmd(curId);
}
void WhenEvtCmd(Object id) {
int idx = GetByKey(id); if (idx == Int_.MinValue) return;
previewIdx = idx;
txtBox.Text_(list[idx].Val_to_str_or_empty());
}
void ExecCmd(String c, int idx) {
if (!Int_.RangeCheck(idx, list.length)) return;
GfoInvkAble_.InvkCmd_val(propInvk, setCmd, list[idx].Key_as_obj());
}
int GetByKey(Object find) {
if (list == null) ReadyEvtCmd();
for (int i = 0; i < list.length; i++) {
if (Object_.Eq(find, list[i].Key_as_obj())) return i;
}
return Int_.MinValue;
}
public static IptBnd_txt_range new_(GfoEvObj propSrc) {
IptBnd_txt_range rv = new IptBnd_txt_range();
rv.propSrc = propSrc; rv.propInvk = GfoInvkAble_.as_(propSrc);
rv.initSrc = propSrc;
return rv;
} IptBnd_txt_range() {}
// public static IptBnd_txt_range new_() {return new IptBnd_txt_range();}
}

View File

@@ -0,0 +1,58 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptBnd_upDownRange implements InjectAble, GfoInvkAble, GfoEvObj {
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} GfoEvMgr evMgr;
public void Inject(Object owner) {
txtBox = GfuiTextBox_.cast_(owner);
txtBox.TextAlignH_center_();
if (bndCfg == null) bndCfg = IptCfg_.new_("gplx.gfui.IptBnd_upDownRange");
IptBnd_.cmd_to_(bndCfg, txtBox, this, Invk_TxtBox_dec, IptKey_.Down, IptMouseWheel_.Down);
IptBnd_.cmd_to_(bndCfg, txtBox, this, Invk_TxtBox_inc, IptKey_.Up, IptMouseWheel_.Up);
IptBnd_.cmd_to_(bndCfg, txtBox, this, Invk_TxtBox_exec, IptKey_.Enter, IptMouseBtn_.Middle);
GfoEvMgr_.SubSame(fwd, evt, this);
} static IptCfg bndCfg;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_TxtBox_dec)) ExecCmd(cmd, curVal - 1);
else if (ctx.Match(k, Invk_TxtBox_inc)) ExecCmd(cmd, curVal + 1);
else if (ctx.Match(k, Invk_TxtBox_exec)) {
Object valObj = IntClassXtn._.ParseOrNull(txtBox.Text()); if (valObj == null) throw Exc_.new_("invalid int", "text", txtBox.Text());
ExecCmd(doIt, Int_.cast_(valObj));
}
else if (ctx.Match(k, evt)) WhenEvt(ctx, m);
else return GfoInvkAble_.Rv_unhandled;
return GfoInvkAble_.Rv_handled;
} static final String Invk_TxtBox_dec = "txtBox_dec", Invk_TxtBox_inc = "txtBox_inc", Invk_TxtBox_exec = "txtBox_exec";
public int Adj() {return adj;} public IptBnd_upDownRange Adj_(int v) {adj = v; return this;} int adj;
void WhenEvt(GfsCtx ctx, GfoMsg m) {
curVal = m.ReadInt(arg) + adj;
txtBox.Text_(Int_.Xto_str(curVal));
}
void ExecCmd(String c, int val) {
GfoInvkAble_.InvkCmd_val(src, c, val - adj);
}
int curVal;
GfuiTextBox txtBox; GfoInvkAble src; GfoEvObj fwd; String cmd, evt, doIt, arg;
public static IptBnd_upDownRange new_(GfoEvObj fwd, String cmd, String evt, String arg) {return exec_(fwd, cmd, evt, cmd, arg);}
public static IptBnd_upDownRange exec_(GfoEvObj fwd, String cmd, String evt, String doIt, String arg) {
IptBnd_upDownRange rv = new IptBnd_upDownRange();
rv.fwd = fwd; rv.src = GfoInvkAble_.cast_(fwd);
rv.cmd = cmd; rv.evt = evt; rv.doIt = doIt; rv.arg = arg;
return rv;
}
}

View File

@@ -0,0 +1,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface IptBndsOwner extends GfoEvObj {
IptBndMgr IptBnds();
}

View File

@@ -0,0 +1,92 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface IptCfg extends NewAble, GfoInvkAble {
String CfgKey();
IptCfgItm GetOrDefaultArgs(String key, GfoMsg m, IptArg[] argAry);
void Owners_add(String key, IptBndsOwner owner);
void Owners_del(String key);
}
class IptCfg_base implements IptCfg {
public String CfgKey() {return cfgKey;} private String cfgKey;
public IptCfgItm GetOrDefaultArgs(String bndKey, GfoMsg defaultMsg, IptArg[] defaultArgs) {
IptCfgItm rv = (IptCfgItm)hash.Get_by(bndKey);
if (rv == null) { // no cfg
rv = IptCfgItm.new_().Key_(bndKey).Ipt_(List_adp_.many_((Object[])defaultArgs)).Msg_(defaultMsg);
hash.Add(bndKey, rv);
}
else { // cfg exists
if (rv.Msg() == null) rv.Msg_(defaultMsg); // no msg defined; use default
}
return rv;
}
public IptCfgItm Set(String bndKey, GfoMsg m, IptArg[] argAry) {
IptCfgItm rv = GetOrDefaultArgs(bndKey, m, argAry);
rv.Msg_(m); // always overwrite msg
if (Dif(rv.Ipt(), argAry)) {
rv.Ipt_(List_adp_.many_((Object[])argAry));
this.Change(bndKey, argAry);
}
return rv;
}
boolean Dif(List_adp lhs, IptArg[] rhs) {
if (lhs.Count() != rhs.length) return true;
for (int i = 0; i < rhs.length; i++) {
IptArg lhsArg = (IptArg)lhs.Get_at(i);
IptArg rhsArg = rhs[i];
if (!lhsArg.Eq(rhsArg)) return true;
}
return false;
}
void Change(String bndKey, IptArg[] ary) {
List_adp list = (List_adp)owners.Get_by(bndKey);
if (list == null) return;
for (int i = 0; i < list.Count(); i++) {
IptBndsOwner owner = (IptBndsOwner)list.Get_at(i);
owner.IptBnds().Change(bndKey, ary);
}
}
public void Owners_del(String bndKey) {owners.Del(bndKey);}
public void Owners_add(String bndKey, IptBndsOwner owner) {
List_adp list = (List_adp)owners.Get_by(bndKey);
if (list == null) {
list = List_adp_.new_();
owners.Add(bndKey, list);
}
list.Add(owner);
owner.IptBnds().Cfgs().Add(new IptCfgPtr(cfgKey, bndKey));
} Ordered_hash owners = Ordered_hash_.new_();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.MatchIn(k, Invk_Add, Invk_set)) {
String bndKey = m.ReadStr("bndKey");
String iptStr = m.ReadStr("ipt");
String cmd = m.ReadStrOr("cmd", "");
if (ctx.Deny()) return this;
Set(bndKey, gplx.gfml.GfmlDataNde.XtoMsgNoRoot(cmd), IptArg_.parse_ary_(iptStr));
}
return this;
} public static final String Invk_Add = "Add", Invk_set = "set";
public IptCfg_base(String cfgKey) {this.cfgKey = cfgKey;}
Ordered_hash hash = Ordered_hash_.new_();
public Object NewByKey(Object o) {return new IptCfg_base((String)o);} @gplx.Internal protected static final IptCfg HashProto = new IptCfg_base(); @gplx.Internal protected IptCfg_base() {}
}
class IptCfgPtr {
public String CfgKey() {return cfgKey;} private String cfgKey;
public String BndKey() {return bndKey;} private String bndKey;
public IptCfgPtr(String cfgKey, String bndKey) {this.cfgKey = cfgKey; this.bndKey = bndKey;}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptCfgItm {
public String Key() {return key;} public IptCfgItm Key_(String v) {key = v; return this;} private String key;
public List_adp Ipt() {return ipt;} public IptCfgItm Ipt_(List_adp v) {ipt = v; return this;} List_adp ipt;
public GfoMsg Msg() {return msg;} public IptCfgItm Msg_(GfoMsg v) {msg = v; return this;} GfoMsg msg;
public static IptCfgItm new_() {return new IptCfgItm();} IptCfgItm() {}
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptCfgRegy implements GfoInvkAble {
public void Clear() {hash.Clear();}
public IptCfg GetOrNew(String k) {return (IptCfg)hash.Get_by_or_new(k, IptCfg_base.HashProto);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.MatchIn(k, Invk_Get, Invk_get)) {
String key = m.ReadStr("key");
if (ctx.Deny()) return this;
return GetOrNew(key);
}
return this;
} public static final String Invk_Get = "Get", Invk_get = "get";
Ordered_hash hash = Ordered_hash_.new_();
public static final IptCfgRegy _ = new IptCfgRegy();
public IptCfgRegy() {}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptCfg_ {
public static final IptCfg Null = IptCfg_null._;
public static IptCfg new_(String key) {return IptCfgRegy._.GetOrNew(key);}
}
class IptCfg_null implements IptCfg {
public String CfgKey() {return "<<NULL KEY>>";}
public IptCfgItm GetOrDefaultArgs(String bndKey, GfoMsg m, IptArg[] argAry) {return IptCfgItm.new_().Key_(bndKey).Ipt_(List_adp_.many_((Object[])argAry)).Msg_(m);}
public void Owners_add(String key, IptBndsOwner owner) {}
public void Owners_del(String key) {}
public Object NewByKey(Object o) {return this;}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return GfoInvkAble_.Rv_unhandled;}
public static final IptCfg_null _ = new IptCfg_null(); IptCfg_null() {}
}

View File

@@ -0,0 +1,84 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*;
public class IptCfg_tst {
@Before public void setup() {
IptCfgRegy._.Clear();
box = new IptBndsOwner_mok();
cfg = new IptCfg_mok();
key = IptBndsOwner_mok.Invk_Reg;
} IptBndsOwner_mok box; IptCfg_mok cfg; String key;
@Test public void Basic() {
cfg.run_GetOrDflt(box, key, IptKey_.A);
box.tst_SendKey(IptKey_.A, 1);
}
@Test public void Del() {
cfg.run_GetOrDflt(box, key, IptKey_.A);
box.IptBnds().Cfgs_delAll();
box.tst_SendKey(IptKey_.A, 0);
}
@Test public void Change() {
cfg.run_GetOrDflt(box, key, IptKey_.A);
cfg.run_Set(key, IptKey_.B);
box.tst_SendKey(IptKey_.B, 1);
cfg.run_Set(key, IptKey_.C);
box.tst_SendKey(IptKey_.C, 1);
box.tst_SendKey(IptKey_.B, 0);
}
@Test public void SetBeforeInit() {
cfg.run_Set(key, IptKey_.B);
cfg.run_GetOrDflt(box, key, IptKey_.A);
box.tst_SendKey(IptKey_.B, 1);
box.tst_SendKey(IptKey_.A, 0);
}
@Test public void SetBeforeInit_msg() {
cfg.run_Set_msg(key, 2, IptKey_.B);
cfg.run_GetOrDflt(box, key, IptKey_.A); // iptBnd exists; ignore Key_.A (and also msg=1)
box.tst_SendKey(IptKey_.B, 2);
box.tst_SendKey(IptKey_.A, 0);
}
@Test public void Chained() {
cfg.run_GetOrDflt(box, key, IptKeyChain.parse_("key.ctrl+key.a,key.b"));
cfg.run_Set(key, IptKey_.A);
box.tst_SendKey(IptKey_.A, 1);
}
class IptCfg_mok {
public IptCfg Cfg() {return cfg;}
public void run_GetOrDflt(IptBndsOwner box, String key, IptArg... ary) {IptBnd_.msg_(cfg, box, key, make_(key, 1), ary);}
public void run_Set(String key, IptArg... ary) {cfg.Set(key, make_(key, 1), ary);}
public void run_Set_msg(String key, int i, IptArg... ary) {cfg.Set(key, make_(key, i), ary);}
GfoMsg make_(String key, int i) {return GfoMsg_.new_cast_(key).Add("val", i);}
public IptCfg_mok() {cfg = (IptCfg_base)IptCfg_.new_("cfg");} IptCfg_base cfg;
}
class IptBndsOwner_mok implements IptBndsOwner {
public IptBndMgr IptBnds() {return iptBnds;} IptBndMgr iptBnds = IptBndMgr.new_();
public GfoEvMgr EvMgr() {if (evMgr == null) evMgr = GfoEvMgr.new_(this); return evMgr;} GfoEvMgr evMgr;
public void tst_SendKey(IptKey key, int expd) {
iptBnds.Process(IptEventData.new_(null, IptEventType_.KeyDown, key, IptEvtDataKey.new_(key), IptEvtDataMouse.Null));
Tfds.Eq(expd, actl);
actl = 0;
} int actl;
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Reg)) {actl = m.ReadIntOr("val", 0);}
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Invk_Reg = "Reg";
}
}

View File

@@ -0,0 +1,49 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptEventData {
public GfuiElem Sender() {return sender;} GfuiElem sender;
public IptArg EventArg() {return eventArg;} IptArg eventArg;
public IptEventType EventType() {return eventType;} IptEventType eventType;
public IptKey Key() {return keyData.Key();} IptEvtDataKey keyData; IptEvtDataKeyHeld keyPressData;
public IptMouseBtn MouseBtn() {return mouseData.Button();} IptEvtDataMouse mouseData;
public IptMouseWheel MouseWheel() {return mouseData.Wheel();}
public PointAdp MousePos() {return mouseData.Pos();}
public boolean Handled() {return handled;} private boolean handled;
public void Handled_on() {Handled_set(true);}
public void Handled_off() {Handled_set(false);}
public boolean CancelIteration;
void Handled_set(boolean val) {
keyData.Handled_set(val);
keyPressData.Handled_set(val);
handled = val;
}
public static IptEventData as_(Object obj) {return obj instanceof IptEventData ? (IptEventData)obj : null;}
public static IptEventData cast_(Object obj) {try {return (IptEventData)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, IptEventData.class, obj);}}
@gplx.Internal protected static IptEventData new_(GfuiElem sender, IptEventType eventType, IptArg eventArg, IptEvtDataKey keyData, IptEvtDataMouse mouseData) {return new_(sender, eventType, eventArg, keyData, IptEvtDataKeyHeld.Null, mouseData);}
@gplx.Internal protected static IptEventData new_(GfuiElem sender, IptEventType eventType, IptArg eventArg, IptEvtDataKey keyData, IptEvtDataKeyHeld keyPressData, IptEvtDataMouse mouseData) {
IptEventData rv = new IptEventData();
rv.sender = sender;
rv.eventType = eventType; rv.eventArg = eventArg;
rv.keyData = keyData; rv.keyPressData = keyPressData; rv.mouseData = mouseData;
return rv;
} IptEventData() {}
public static IptEventData ctx_(GfsCtx ctx, GfoMsg m) {return IptEventData.cast_(m.CastObj("iptData"));}
}

View File

@@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
class IptEventMgr implements GfoInvkAble {
@gplx.Internal protected static void ExecKeyDown(GfuiElem sender, IptEvtDataKey keyState) {
keyHandled = false; keyStateCur = keyState; // cache for simultaneous ipt events (ex: key.ctrl + mouse.left)
IptEventData iptData = IptEventData.new_(sender, IptEventType_.KeyDown, keyState.Key(), keyState, mouseStateCur);
// if (keyState.Key().Eq(IptKey_.add_(IptKey_.F1))) {
// Tfds.Write(keyState.Key(), keyState.Key().Val());
// }
sender.IptBnds().Process(iptData);
SendData(iptData);
keyHandled = keyState.Handled(); // WORKAROUND (WinForms): cache keyHandled b/c KeyDown.Handled=true does not make KeyPress.Handled=true;
}
@gplx.Internal protected static void ExecKeyPress(GfuiElem sender, IptEvtDataKeyHeld keyPressState) {
// Tfds.Write(keyPressState.KeyChar());
if (keyHandled) {keyPressState.Handled_set(true); return;}
IptEventData iptData = IptEventData.new_(sender, IptEventType_.KeyPress, IptKeyStrMgr._.FetchByKeyPress((int)(byte)keyPressState.KeyChar()), keyStateCur, keyPressState, mouseStateCur);
sender.IptBnds().Process(iptData);
SendData(iptData);
}
@gplx.Internal protected static void ExecKeyUp(GfuiElem sender, IptEvtDataKey keyState) {
keyStateCur = IptEvtDataKey.Null; // keyStateCur no longer needed; set to Null
if (keyHandled) {keyState.Handled_set(true); return;}
IptEventData iptData = IptEventData.new_(sender, IptEventType_.KeyUp, keyState.Key(), keyState, mouseStateCur);
sender.IptBnds().Process(iptData);
SendData(iptData);
}
@gplx.Internal protected static void ExecMouseDown(GfuiElem sender, IptEvtDataMouse mouseState) {
mouseStateCur = mouseState; // cache for simultaneous ipt events (ex: key.ctrl + mouse.left)
if (sender.IptBnds().Has(IptEventType_.MousePress)) {
if (mousePressTimer == null) mousePressTimer = TimerAdp.new_(EventSink2, Tmr_cmd, 100, false);
senderCur = sender; mousePressTimer.Enabled_on();
}
IptEventData iptData = IptEventData.new_(sender, IptEventType_.MouseDown, mouseState.Button(), keyStateCur, mouseState);
sender.IptBnds().Process(iptData);
SendData(iptData);
}
@gplx.Internal protected static void ExecMouseMove(GfuiElem sender, IptEvtDataMouse mouseState) {
IptEventData iptData = IptEventData.new_(sender, IptEventType_.MouseMove, IptMouseMove.AnyDirection, keyStateCur, mouseState);
sender.IptBnds().Process(iptData);
// SendData(iptData); // TOMBSTONE: do not send mouseMove events for PERF and DESIGN reasons
}
@gplx.Internal protected static void ExecMouseUp(GfuiElem sender, IptEvtDataMouse mouseState) {
mouseStateCur = IptEvtDataMouse.Null; // mouseStateCur no longer needed; set to Null
if (mousePressTimer != null)
mousePressTimer.Enabled_off();
IptEventData iptData = IptEventData.new_(sender, IptEventType_.MouseUp, mouseState.Button(), keyStateCur, mouseState);
sender.IptBnds().Process(iptData);
SendData(iptData);
}
@gplx.Internal protected static void ExecMouseWheel(GfuiElem sender, IptEvtDataMouse mouseState) {
IptEventData iptData = IptEventData.new_(sender, IptEventType_.MouseWheel, mouseState.Wheel(), keyStateCur, mouseState);
sender.IptBnds().Process(iptData);
SendData(iptData);
}
@gplx.Internal protected static void ExecMousePress(GfuiElem sender, IptEvtDataMouse mouseState) {
IptEventData iptData = IptEventData.new_(sender, IptEventType_.MousePress, mouseState.Button(), keyStateCur, mouseState);
sender.IptBnds().Process(iptData);
SendData(iptData);
}
static void MousePressTick() {
IptEventMgr.ExecMousePress(senderCur, mouseStateCur);
}
static void SendData(IptEventData iptData) {
if (StopFwd(iptData)) return;
GfsCtx ctx = GfsCtx.new_();
GfoMsg m = GfoMsg_.new_cast_(GfuiElemKeys.IptRcvd_evt).Add("iptData", iptData);
GfoEvMgr_.PubMsg(iptData.Sender(), ctx, GfuiElemKeys.IptRcvd_evt, m);
}
public static boolean StopFwd(IptEventData iptData) { // check if (a) control bubbles event; (b) iptData.Handled
return !IptEventType_.Has(iptData.Sender().IptBnds().EventsToFwd(), iptData.EventType())
|| iptData.Handled();
}
static boolean keyHandled = false; static IptEvtDataKey keyStateCur = IptEvtDataKey.Null; static IptEvtDataMouse mouseStateCur = IptEvtDataMouse.Null;
static TimerAdp mousePressTimer; static GfuiElem senderCur;
public static final IptEventMgr EventSink2 = new IptEventMgr(); IptEventMgr() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Tmr_cmd)) MousePressTick();
else return GfoInvkAble_.Rv_unhandled;
return this;
} public static final String Tmr_cmd = "Tmr";
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptEventType {
public int Val() {return val;} int val;
public String Name() {return name;} private String name;
public IptEventType Add(IptEventType comp) {return IptEventType_.add_(this, comp);}
@Override public String toString() {return name;}
@gplx.Internal protected IptEventType(int v, String s) {this.val = v; this.name = s;}
public static Object HandleEvt(IptBndsOwner owner, GfsCtx ctx, GfoMsg m) {
IptEventData iptData = IptEventData.ctx_(ctx, m);
boolean processed = owner.IptBnds().Process(iptData);
if (processed || IptEventMgr.StopFwd(iptData)) { // NOTE: IptMsgs are single-dispatch;
}
else {
GfoEvMgr_.PubMsg(owner, ctx, GfuiElemKeys.IptRcvd_evt, m);
}
return GfoInvkAble_.Rv_handled;
}
}

View File

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptEventType_ {
static EnmMgr enmMgr = EnmMgr.new_().BitRngEnd_(128);
public static final IptEventType
None = new_( 0, "none")
, KeyDown = new_( 1, "keyDown")
, KeyUp = new_( 2, "keyUp")
, KeyPress = new_( 4, "keyPress")
, MouseDown = new_( 8, "mouseDown")
, MouseUp = new_( 16, "mouseUp")
, MouseMove = new_( 32, "mouseMove")
, MouseWheel = new_( 64, "mouseWheel")
, MousePress = new_( 128, "mousePress");
public static IptEventType add_(IptEventType... ary) {
if (ary.length == 0) return IptEventType_.None;
int newVal = ary[0].Val();
for (int i = 1; i < ary.length; i++)
newVal = Enm_.FlipInt(true, newVal, ary[i].Val());
return getOrNew_(newVal);
}
static IptEventType getOrNew_(int v) {
IptEventType rv = (IptEventType)enmMgr.Get(v);
return (rv == null) ? new_(v, enmMgr.GetStr(v)) : rv;
}
static IptEventType new_(int val, String name) {
IptEventType rv = new IptEventType(val, name);
enmMgr.RegObj(val, name, rv);
return rv;
}
@gplx.Internal protected static boolean Has(IptEventType val, IptEventType find) {
if (find == IptEventType_.None && val != IptEventType_.None) return false; // check .None manually b/c 0 is identity when BitShifting
return Enm_.HasInt(val.Val(), find.Val());
}
public static IptEventType default_(IptArg[] args) {
IptEventType rv = IptEventType_.None;
for (IptArg arg : args)
rv = rv.Add(IptArg_.EventType_default(arg));
return rv;
}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptEvtDataKey {
public IptKey Key() {return key;} IptKey key;
public boolean Handled() {return handled;} public void Handled_set(boolean v) {handled = v;} private boolean handled;
public static IptEvtDataKey as_(Object obj) {return obj instanceof IptEvtDataKey ? (IptEvtDataKey)obj : null;}
public static IptEvtDataKey cast_(Object obj) {try {return (IptEvtDataKey)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, IptEvtDataKey.class, obj);}}
@gplx.Internal protected static final IptEvtDataKey Null = new_(IptKey_.None);
@gplx.Internal protected static IptEvtDataKey test_(IptKey keyArg) {return new_(keyArg);}
@gplx.Internal protected static IptEvtDataKey int_(int val) {
IptKey keyArg = IptKey_.api_(val);
return new_(keyArg);
}
@gplx.Internal protected static IptEvtDataKey new_(IptKey key) {
IptEvtDataKey rv = new IptEvtDataKey();
rv.key = key;
return rv;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptEvtDataKeyHeld {
public char KeyChar() {return c;} char c;
public boolean Handled() {return handled;} public void Handled_set(boolean v) {handled = v;} private boolean handled;
public static IptEvtDataKeyHeld as_(Object obj) {return obj instanceof IptEvtDataKeyHeld ? (IptEvtDataKeyHeld)obj : null;}
public static IptEvtDataKeyHeld cast_(Object obj) {try {return (IptEvtDataKeyHeld)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, IptEvtDataKeyHeld.class, obj);}}
@gplx.Internal protected static final IptEvtDataKeyHeld Null = char_((char)0);
@gplx.Internal protected static IptEvtDataKeyHeld char_(char c) {
IptEvtDataKeyHeld rv = new IptEvtDataKeyHeld();
rv.c = c;
return rv;
}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptEvtDataMouse {
public IptMouseBtn Button() {return button;} IptMouseBtn button;
public IptMouseWheel Wheel() {return wheel;} IptMouseWheel wheel;
public PointAdp Pos() {return location;} PointAdp location;
public static IptEvtDataMouse as_(Object obj) {return obj instanceof IptEvtDataMouse ? (IptEvtDataMouse)obj : null;}
public static IptEvtDataMouse cast_(Object obj) {try {return (IptEvtDataMouse)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, IptEvtDataMouse.class, obj);}}
@gplx.Internal protected static final IptEvtDataMouse Null = IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, 0, 0);
public static IptEvtDataMouse new_(IptMouseBtn button, IptMouseWheel wheel, int x, int y) {
IptEvtDataMouse rv = new IptEvtDataMouse();
rv.button = button;
rv.wheel = wheel;
rv.location = PointAdp_.new_(x, y);
return rv;
}
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptKey implements IptArg {
@gplx.Internal protected IptKey(int val, String key) {this.val = val; this.key = key;}
public String Key() {return key;} private final String key;
public int Val() {return val;} private final int val;
public boolean Eq(IptArg comp) {return String_.Eq(key, comp.Key());}
public String XtoUiStr() {return IptKeyStrMgr._.XtoStr(this);}
public IptKey Add(IptKey comp) {return IptKey_.add_(this, comp);}
public boolean Mod_shift() {return Enm_.HasInt(val, IptKey_.Shift.Val());}
public boolean Mod_ctrl() {return Enm_.HasInt(val, IptKey_.Ctrl.Val());}
public boolean Mod_alt() {return Enm_.HasInt(val, IptKey_.Alt.Val());}
}

View File

@@ -0,0 +1,75 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
class IptKeyStrMgr {
public IptKey FetchByKeyPress(int charVal) {
if (literals == null) Init();
IptKey rv = charKeys[charVal];
return (rv == null) ? IptKey_.None : rv;
}
public String XtoStr(IptKey key) {
if (literals == null) Init();
Object rv = literals.Get_by(key.Val());
return rv == null ? String_.Empty : (String)rv;
}
public void XtoIptKeyAry(List_adp list) {
if (literals == null) Init();
for (int i = 0; i < keys.Count(); i++)
list.Add((IptKey)keys.Get_at(i));
}
void Init() {// default to US style keyboard
literals = Hash_adp_.new_();
charKeys = new IptKey[256];
RegLtr(IptKey_.A, 'a'); RegLtr(IptKey_.B, 'b'); RegLtr(IptKey_.C, 'c'); RegLtr(IptKey_.D, 'd'); RegLtr(IptKey_.E, 'e');
RegLtr(IptKey_.F, 'f'); RegLtr(IptKey_.G, 'g'); RegLtr(IptKey_.H, 'h'); RegLtr(IptKey_.I, 'i'); RegLtr(IptKey_.J, 'j');
RegLtr(IptKey_.K, 'k'); RegLtr(IptKey_.L, 'l'); RegLtr(IptKey_.M, 'm'); RegLtr(IptKey_.N, 'n'); RegLtr(IptKey_.O, 'o');
RegLtr(IptKey_.P, 'p'); RegLtr(IptKey_.Q, 'q'); RegLtr(IptKey_.R, 'r'); RegLtr(IptKey_.S, 's'); RegLtr(IptKey_.T, 't');
RegLtr(IptKey_.U, 'u'); RegLtr(IptKey_.V, 'v'); RegLtr(IptKey_.W, 'w'); RegLtr(IptKey_.X, 'x'); RegLtr(IptKey_.Y, 'y'); RegLtr(IptKey_.Z, 'z');
RegSym(IptKey_.D0, '0', ')'); RegSym(IptKey_.D1, '1', '!'); RegSym(IptKey_.D2, '2', '@'); RegSym(IptKey_.D3, '3', '#'); RegSym(IptKey_.D4, '4', '$');
RegSym(IptKey_.D5, '5', '%'); RegSym(IptKey_.D6, '6', '^'); RegSym(IptKey_.D7, '7', '&'); RegSym(IptKey_.D8, '8', '*'); RegSym(IptKey_.D9, '9', '(');
RegSym(IptKey_.Equal, '=', '+'); RegSym(IptKey_.Minus, '-', '_'); RegSym(IptKey_.Backslash, '\\', '|'); RegSym(IptKey_.Semicolon, ';', ':');
RegSym(IptKey_.Quote, '\'', '"'); RegSym(IptKey_.Comma, ',', '<'); RegSym(IptKey_.Period, '.', '>'); RegSym(IptKey_.Slash, '?', '/');
RegSym(IptKey_.OpenBracket, '[', '{'); RegSym(IptKey_.CloseBracket, ']', '}'); RegSym(IptKey_.Tick, '`', '~');
Reg(IptKey_.Space, ' ');
Reg(IptKey_.Escape, "", 27); // escape should be "" or else prints on grid
Reg(IptKey_.Enter, "\n", 10);
charKeys[13] = IptKey_.Enter; // WORKAROUND.WINFORMS: Enter generates keypress of 13 while Shift+Enter generates keypress of 10; JAVA always sends 10
Reg(IptKey_.CapsLock, "CapsLock", 20);
}
void RegLtr(IptKey lowerKey, char lowerChr) {
IptKey upperKey = IptKey_.add_(lowerKey, IptKey_.Shift);
char upperChr = (char)((int)lowerChr - 32);
Reg(lowerKey, lowerChr); // 'a' 97 Key_.A
Reg(upperKey, upperChr); // 'A' 65 Key_.A+Key_.Shift
}
void RegSym(IptKey lowerKey, char lowerChr, char upperChr) {
IptKey upperKey = IptKey_.add_(lowerKey, IptKey_.Shift);
Reg(lowerKey, lowerChr);
Reg(upperKey, upperChr);
}
void Reg(IptKey k, char c) {Reg(k, Char_.XtoStr(c), (int)c);}
void Reg(IptKey k, String s, int charVal) {
int v = k.Val();
literals.Add(v, s);
keys.Add(v, k);
charKeys[charVal] = k;
}
IptKey[] charKeys;
Hash_adp literals; Ordered_hash keys = Ordered_hash_.new_();
public static final IptKeyStrMgr _ = new IptKeyStrMgr(); IptKeyStrMgr() {}
}

View File

@@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*;
public class IptKeyStrMgr_tst {
@Test public void KeyBasic() {
tst_XtoUiStr(IptKey_.A, "a");
tst_XtoUiStr(IptKey_.Z, "z");
tst_XtoUiStr(IptKey_.Shift.Add(IptKey_.A), "A");
tst_XtoUiStr(IptKey_.Shift.Add(IptKey_.Z), "Z");
tst_XtoUiStrShifted(IptKey_.Equal, "=", "+");
tst_XtoUiStrShifted(IptKey_.D0, "0", ")");
tst_XtoUiStrShifted(IptKey_.D1, "1", "!");
tst_XtoUiStrShifted(IptKey_.D2, "2", "@");
tst_XtoUiStrShifted(IptKey_.D3, "3", "#");
tst_XtoUiStrShifted(IptKey_.D4, "4", "$");
tst_XtoUiStrShifted(IptKey_.D5, "5", "%");
tst_XtoUiStrShifted(IptKey_.D6, "6", "^");
tst_XtoUiStrShifted(IptKey_.D7, "7", "&");
tst_XtoUiStrShifted(IptKey_.D8, "8", "*");
tst_XtoUiStrShifted(IptKey_.D9, "9", "(");
tst_XtoUiStrShifted(IptKey_.Minus, "-", "_");
tst_XtoUiStrShifted(IptKey_.Backslash, "\\", "|");
tst_XtoUiStrShifted(IptKey_.Semicolon, ";", ":");
tst_XtoUiStrShifted(IptKey_.Quote, "'", "\"");
tst_XtoUiStrShifted(IptKey_.Comma, ",", "<");
tst_XtoUiStrShifted(IptKey_.Period, ".", ">");
tst_XtoUiStrShifted(IptKey_.Slash, "?", "/");
tst_XtoUiStrShifted(IptKey_.Tick, "`", "~");
tst_XtoUiStrShifted(IptKey_.OpenBracket, "[", "{");
tst_XtoUiStrShifted(IptKey_.CloseBracket, "]", "}");
}
@Test public void FetchByKeyPress() {
tst_FetchByKeyPress('a', IptKey_.add_(IptKey_.A));
tst_FetchByKeyPress('A', IptKey_.add_(IptKey_.A, IptKey_.Shift));
tst_FetchByKeyPress('1', IptKey_.add_(IptKey_.D1));
tst_FetchByKeyPress('!', IptKey_.add_(IptKey_.D1, IptKey_.Shift));
} void tst_FetchByKeyPress(char c, IptKey expd) {Tfds.Eq(expd.Key(), IptKeyStrMgr._.FetchByKeyPress((int)c).Key());}
void tst_XtoUiStr(IptKey key, String expd) {Tfds.Eq(expd, key.XtoUiStr());}
void tst_XtoUiStrShifted(IptKey key, String expdNormal, String expdShifted) {
Tfds.Eq(expdNormal, key.XtoUiStr());
Tfds.Eq(expdShifted, IptKey_.Shift.Add(key).XtoUiStr());
}
}

View File

@@ -0,0 +1,153 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.event.KeyEvent;
import gplx.core.primitives.*;
public class IptKey_ {
private static EnmMgr enm_mgr = EnmMgr.new_().BitRngBgn_(65536).BitRngEnd_(262144).Prefix_("key.");
public static IptKey[] Ary(IptKey... ary) {return ary;}
public static final IptKey[] Ary_empty = new IptKey[0];
public static IptKey as_(Object obj) {return obj instanceof IptKey ? (IptKey)obj : null;}
public static IptKey cast_(Object obj) {try {return (IptKey)obj;} catch(Exception exc) {throw Exc_.new_type_mismatch_w_exc(exc, IptKey.class, obj);}}
public static IptKey add_(IptKey... ary) {
if (ary.length == 0) return IptKey_.None;
int newVal = ary[0].Val();
for (int i = 1; i < ary.length; i++)
newVal = Enm_.FlipInt(true, newVal, ary[i].Val());
return get_or_new_(newVal);
}
public static IptKey api_(int val) {
IptKey rv = (IptKey)enm_mgr.Get(val);
return (rv == null) ? new_(val, "key_" + Int_.Xto_str(val)) : rv;
}
public static IptKey parse_(String raw) {return get_or_new_(enm_mgr.GetVal(raw));}
public static IptKey rdr_or_(DataRdr rdr, String key, IptKey or) {
String val = rdr.ReadStrOr(key, ""); // NOTE: "" cannot be null, b/c nullRdr returns String.empty
return (String_.Eq(val, "")) ? or : parse_(val);
}
public static List_adp printableKeys2_(IptKey[] add, IptKey[] del) {
List_adp list = List_adp_.new_();
for (IptKey key : add)
list.Add(key);
IptKeyStrMgr._.XtoIptKeyAry(list);
for (IptKey key : del)
list.Del(key);
return list;
}
public static IptKey[] printableKeys_(IptKey[] add, IptKey[] del) {
List_adp list = List_adp_.new_();
for (IptKey key : add)
list.Add(key);
IptKeyStrMgr._.XtoIptKeyAry(list);
for (IptKey key : del)
list.Del(key);
return (IptKey[])list.To_ary(IptKey.class);
}
private static IptKey get_or_new_(int val) {
IptKey rv = (IptKey)enm_mgr.Get(val);
return (rv == null) ? new_(val, enm_mgr.GetStr(val)) : rv;
}
static IptKey new_(int val, String name) {
IptKey rv = new IptKey(val, String_.Has_at_bgn(name, "key.") ? name : "key." + name);
enm_mgr.RegObj(val, name, rv);
return rv;
}
public static final int KeyCode_Shift = 65536, KeyCode_Ctrl = 131072, KeyCode_Alt = 262144;
public static final IptKey
None = new_(0, "none")
, Back = new_(8, "back"), Tab = new_(9, "tab"), Clear = new_(12, "clear"), Enter = new_(KeyEvent.VK_ENTER, "enter")
, ShiftKey = new_(16, "shiftKey"), CtrlKey = new_(17, "ctrlKey"), AltKey = new_(18, "altKey")
, Pause = new_(KeyEvent.VK_PAUSE, "pause")
, CapsLock = new_(20, "capsLock"), Escape = new_(27, "escape"), Space = new_(32, "space")
, PageUp = new_(33, "pageUp"), PageDown = new_(34, "pageDown"), End = new_(35, "end"), Home = new_(36, "home")
, Left = new_(37, "left"), Up = new_(38, "up"), Right = new_(39, "right"), Down = new_(40, "down")
, PrintScreen = new_(44, "printScreen"), Insert = new_(45, "insert")
, Delete = new_(KeyEvent.VK_DELETE, "delete")
, D0 = new_(48, "d0"), D1 = new_(49, "d1"), D2 = new_(50, "d2"), D3 = new_(51, "d3"), D4 = new_(52, "d4")
, D5 = new_(53, "d5"), D6 = new_(54, "d6"), D7 = new_(55, "d7"), D8 = new_(56, "d8"), D9 = new_(57, "d9")
, A = new_(65, "a"), B = new_(66, "b"), C = new_(67, "c"), D = new_(68, "d"), E = new_(69, "e")
, F = new_(70, "f"), G = new_(71, "g"), H = new_(72, "h"), I = new_(73, "i"), J = new_(74, "j")
, K = new_(75, "k"), L = new_(76, "l"), M = new_(77, "m"), N = new_(78, "n"), O = new_(79, "o")
, P = new_(80, "p"), Q = new_(81, "q"), R = new_(82, "r"), S = new_(83, "s"), T = new_(84, "t")
, U = new_(85, "u"), V = new_(86, "v"), W = new_(87, "w"), X = new_(88, "x"), Y = new_(89, "y"), Z = new_(90, "z")
, F1 = new_(112, "f1"), F2 = new_(113, "f2"), F3 = new_(114, "f3"), F4 = new_(115, "f4"), F5 = new_(116, "f5"), F6 = new_(117, "f6")
, F7 = new_(118, "f7"), F8 = new_(119, "f8"), F9 = new_(120, "f9"), F10 = new_(121, "f10"), F11 = new_(122, "f11"), F12 = new_(123, "f12")
, NumLock = new_(144, "numLock"), ScrollLock = new_(145, "scrollLock")
, Semicolon = new_(KeyEvent.VK_SEMICOLON, "semicolon")
, Equal = new_(KeyEvent.VK_EQUALS, "equal")
, Comma = new_(KeyEvent.VK_COMMA, "comma")
, Minus = new_(KeyEvent.VK_MINUS, "minus")
, Period = new_(KeyEvent.VK_PERIOD, "period")
, Slash = new_(KeyEvent.VK_SLASH, "slash")
, Tick = new_(KeyEvent.VK_BACK_QUOTE, "tick")
, OpenBracket = new_(219, "openBracket")
, Backslash = new_(KeyEvent.VK_BACK_SLASH, "backslash")
, CloseBracket = new_(221, "closeBracket")
, Quote = new_(222, "quote")
, Shift = new_(KeyCode_Shift, "shift"), Ctrl = new_(KeyCode_Ctrl, "ctrl"), Alt = new_(KeyCode_Alt, "alt")
, Keypad_enter = new_(16777296, "keypad_enter")
;
private static Ordered_hash ui_str_hash;
public static Ordered_hash Ui_str_hash() {
if (ui_str_hash == null) {
ui_str_hash = Ordered_hash_.new_();
All_add(ui_str_hash
, IptKey_.Back, IptKey_.Tab, IptKey_.Clear, IptKey_.Enter
, IptKey_.Pause, IptKey_.CapsLock, IptKey_.Escape, IptKey_.Space
, IptKey_.PageUp, IptKey_.PageDown, IptKey_.End, IptKey_.Home
, IptKey_.Left, IptKey_.Up, IptKey_.Right, IptKey_.Down
, IptKey_.PrintScreen, IptKey_.Insert, IptKey_.Delete
, IptKey_.D0, IptKey_.D1, IptKey_.D2, IptKey_.D3, IptKey_.D4
, IptKey_.D5, IptKey_.D6, IptKey_.D7, IptKey_.D8, IptKey_.D9
, IptKey_.A, IptKey_.B, IptKey_.C, IptKey_.D, IptKey_.E
, IptKey_.F, IptKey_.G, IptKey_.H, IptKey_.I, IptKey_.J
, IptKey_.K, IptKey_.L, IptKey_.M, IptKey_.N, IptKey_.O
, IptKey_.P, IptKey_.Q, IptKey_.R, IptKey_.S, IptKey_.T
, IptKey_.U, IptKey_.V, IptKey_.W, IptKey_.X, IptKey_.Y
, IptKey_.Z
, IptKey_.F1, IptKey_.F2, IptKey_.F3, IptKey_.F4, IptKey_.F5, IptKey_.F6
, IptKey_.F7, IptKey_.F8, IptKey_.F9, IptKey_.F10, IptKey_.F11, IptKey_.F12
, IptKey_.NumLock, IptKey_.ScrollLock
, IptKey_.Semicolon, IptKey_.Equal, IptKey_.Comma, IptKey_.Minus, IptKey_.Period, IptKey_.Slash, IptKey_.Tick
, IptKey_.OpenBracket, IptKey_.Back, IptKey_.CloseBracket, IptKey_.Quote
);
}
return ui_str_hash;
}
private static void All_add(Ordered_hash hash, IptKey... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
IptKey key = ary[i];
hash.Add_if_dupe_use_nth(Int_obj_ref.new_(key.Val()), key);
}
}
public static String To_str(int val) {
String mod_str = "", rv = "";
boolean mod_c = Enm_.HasInt(val, IptKey_.Ctrl.Val()); if (mod_c) {mod_str += "c"; val = Enm_.FlipInt(Bool_.N, val, IptKey_.Ctrl.Val());}
boolean mod_a = Enm_.HasInt(val, IptKey_.Alt.Val()); if (mod_a) {mod_str += "a"; val = Enm_.FlipInt(Bool_.N, val, IptKey_.Alt.Val());}
boolean mod_s = Enm_.HasInt(val, IptKey_.Shift.Val()); if (mod_s) {mod_str += "s"; val = Enm_.FlipInt(Bool_.N, val, IptKey_.Shift.Val());}
if (String_.Len_gt_0(mod_str)) {
rv = "mod." + mod_str;
if (val == 0) return rv; // handle modifiers only, like "mod.cs"; else will be "mod.cs+key.#0"
rv += "+";
}
IptKey key = (IptKey)IptKey_.Ui_str_hash().Get_by(Int_obj_ref.new_(val));
String key_str = key == null ? "key.#" + Int_.Xto_str(val) : key.Key();
return rv + key_str;
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*;
public class IptKey__tst {
private final IptKey__fxt fxt = new IptKey__fxt();
@Test public void To_str() {
fxt.Test_to_str(196608, "mod.cs");
}
@Test public void To_str__numeric() {
fxt.Test_to_str(16777296, "key.#16777296");
}
@Test public void parse_() {
fxt.Test_parse("key.#10", 10);
}
}
class IptKey__fxt {
public void Test_to_str(int keycode, String expd) {
Tfds.Eq(expd, IptKey_.To_str(keycode));
}
public void Test_parse(String raw, int keycode) {
Tfds.Eq(keycode, IptKey_.parse_(raw).Val());
}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptMouseBtn implements IptArg {
@gplx.Internal protected IptMouseBtn(int val, String key) {this.val = val; this.key = key;}
public String Key() {return key;} private String key;
@gplx.Internal protected int Val() {return val;} int val;
public boolean Eq(IptArg comp) {return String_.Eq(key, comp.Key());}
}

View File

@@ -0,0 +1,54 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptMouseBtn_ {
public static final int
Tid_none = 0x00000000
, Tid_left = 0x00100000
, Tid_right = 0x00200000
, Tid_middle = 0x00400000
, Tid_x1 = 0x00400000
, Tid_x2 = 0x01000000
;
public static final IptMouseBtn // REF: System.Windows.Forms.MouseButtons
None = new IptMouseBtn(Tid_none , "mouse.none")
, Left = new IptMouseBtn(Tid_left , "mouse.left")
, Right = new IptMouseBtn(Tid_right , "mouse.right")
, Middle = new IptMouseBtn(Tid_middle , "mouse.middle")
, X1 = new IptMouseBtn(Tid_x1 , "mouse.x1")
, X2 = new IptMouseBtn(Tid_x2 , "mouse.x2")
;
public static IptMouseBtn parse_(String raw) {
if (String_.Eq(raw, None.Key())) return None;
else if (String_.Eq(raw, Left.Key())) return Left;
else if (String_.Eq(raw, Right.Key())) return Right;
else if (String_.Eq(raw, Middle.Key())) return Middle;
else if (String_.Eq(raw, X1.Key())) return X1;
else if (String_.Eq(raw, X2.Key())) return X2;
else throw Exc_.new_parse_type(IptMouseBtn.class, raw);
}
@gplx.Internal protected static IptMouseBtn api_(int val) {
if (val == None.Val()) return None;
else if (val == Left.Val()) return Left;
else if (val == Right.Val()) return Right;
else if (val == Middle.Val()) return Middle;
else if (val == X1.Val()) return X1;
else if (val == X2.Val()) return X2;
else throw Exc_.new_unhandled(val);
}
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptMouseMove implements IptArg {
public String Key() {return key;} private String key = "move.any";
public boolean Eq(IptArg comp) {return String_.Eq(this.Key(), comp.Key());}
public static final IptMouseMove AnyDirection = new IptMouseMove(); IptMouseMove() {}
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptMouseWheel implements IptArg {
public String Key() {return key;} private String key;
public boolean Eq(IptArg comp) {return String_.Eq(key, comp.Key());}
@gplx.Internal protected IptMouseWheel(String key) {this.key = key;}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptMouseWheel_ {
public static final IptMouseWheel
None = new IptMouseWheel("wheel.none")
, Up = new IptMouseWheel("wheel.up")
, Down = new IptMouseWheel("wheel.down");
public static IptMouseWheel parse_(String raw) {
if (String_.Eq(raw, None.Key())) return None;
else if (String_.Eq(raw, Up.Key())) return Up;
else if (String_.Eq(raw, Down.Key())) return Down;
else throw Exc_.new_parse_type(IptMouseWheel.class, raw);
}
@gplx.Internal protected static IptMouseWheel api_(Object obj) {
int delta = Int_.cast_(obj);
if (delta > 0) return Up;
else if (delta < 0) return Down;
else return None;
}
}

View File

@@ -0,0 +1,90 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GftBand {
public String Key() {return key;} public GftBand Key_(String v) {key = v; return this;} private String key;
public int Idx() {return idx;} public GftBand Idx_(int v) {idx = v; return this;} int idx;
public GftSizeCalc Len1() {return len1;} public GftBand Len1_(GftSizeCalc v) {len1 = v; return this;} GftSizeCalc len1 = new GftSizeCalc_abs(20);
public GftBand Len1_pct_(float val) {return Len1_(new GftSizeCalc_pct(val));}
public GftBand Len1_abs_(int v) {return Len1_(new GftSizeCalc_abs(v));}
public GftCell Cell_dfl() {return cell_dfl;} GftCell cell_dfl = new GftCell();
public List_adp Cells() {return cells;} List_adp cells = List_adp_.new_();
public GftBand Cells_var_(int count) {
for (int i = 0; i < count; i++)
cells.Add(new GftCell().Len0_(new GftSizeCalc_var(count)));
return this;
}
public GftBand Cell_abs_(int val) {cells.Add(new GftCell().Len0_(new GftSizeCalc_abs(val))); return this;}
public GftBand Cell_pct_(float val) {cells.Add(new GftCell().Len0_(new GftSizeCalc_pct(val))); return this;}
public GftBand Cells_num_(int num) {
cells.Clear();
for (int i = 0; i < num; i++)
cells.Add(new GftCell().Len0_(new GftSizeCalc_num(num)));
return this;
}
public List_adp Items() {return items;} List_adp items = List_adp_.new_();
public void Items_add(GftItem item) {items.Add(item);}
public void Calc(GftItem owner, int y, int h) {
int x = 0;
y = grid.Bands_dir().GetValByDir(y - h, y);
int availX = owner.Gft_w();
for (int i = 0; i < cells.Count(); i++) {
GftCell cell = (GftCell)cells.Get_at(i);
if (cell.Len0().Key() == GftSizeCalc_abs.KEY) {
GftSizeCalc_abs calc = (GftSizeCalc_abs)cell.Len0();
availX -= calc.Val();
}
else if (cell.Len0().Key() == GftSizeCalc_var.KEY) {
if (i >= items.Count()) continue;
GftItem item = (GftItem)items.Get_at(i);
GfuiElem elem = GfuiElem_.as_(item);
availX -= elem == null ? item.Gft_w() : elem.Width();
}
}
for (int i = 0; i < items.Count(); i++) {
GftItem item = (GftItem)items.Get_at(i);
GftCell cell = i >= cells.Count() ? cell_dfl : (GftCell)cells.Get_at(i);
int w = cell.Len0().Calc(grid, this, owner, item, availX);
item.Gft_rect_(RectAdp_.new_(x, y, w, h));
// Tfds.Write(item.Key_of_GfuiElem(), w, h, x, y);
x += w;
}
this.items.Clear();
}
public GftBand Clone(GftGrid grid, int idx) {
GftBand rv = new GftBand();
rv.grid = grid;
rv.key = key; rv.idx = idx; rv.cell_dfl = cell_dfl.Clone(); rv.len1 = this.len1.Clone();
for (int i = 0; i < cells.Count(); i++) {
GftCell cell = (GftCell)cells.Get_at(i);
rv.cells.Add(cell.Clone());
}
return rv;
} GftGrid grid;
public static GftBand new_() {return new GftBand();} GftBand() {}
public static GftBand fillWidth_() {
GftBand rv = new GftBand();
rv.Cells_num_(1);
return rv;
}
public static GftBand fillAll_() {
GftBand rv = new GftBand();
rv.Cells_num_(1).Len1_pct_(100);
return rv;
}
}

View File

@@ -0,0 +1,112 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import org.junit.*;
public class GftBand_tst {
@Before public void setup() {
fx.Clear().ini_OwnerSize(200, 400);
} GftGrid_fx fx = new GftGrid_fx();
@Test public void Bands_1() {
fx .ini_AddItms(2)
.ini_Set(0, GftBand.new_().Cells_num_(2))
.run()
.tst_Filter(0, 1).tst_X(0, 100).tst_W_all(100).tst_H_all(20).tst_Y_all(0);
}
@Test public void Bands_1_half() { // only add 1 to 2 cell-band
fx .ini_AddItms(1)
.ini_Set(0, GftBand.new_().Cells_num_(2))
.run()
.tst_Filter(0).tst_X(0).tst_W(100).tst_H(20).tst_Y(0);
}
@Test public void Bands_2() { // put cells 2, 3 on band 1
fx .ini_AddItms(4)
.ini_Set(0, GftBand.new_().Cells_num_(2))
.ini_Set(1, GftBand.new_().Cells_num_(2))
.run()
.tst_Filter(0, 1).tst_X(0, 100).tst_W_all(100).tst_H_all(20).tst_Y_all(0)
.tst_Filter(2, 3).tst_X(0, 100).tst_W_all(100).tst_H_all(20).tst_Y_all(20); // put on 2nd row
}
@Test public void Pct_one() {
fx .ini_AddItms(1)
.ini_Set(0, GftBand.new_().Cell_pct_(50))
.run()
.tst_Filter(0).tst_X(0).tst_W(100).tst_H_all(20).tst_Y_all(0);
}
@Test public void Pct_many() {
fx .ini_AddItms(3)
.ini_Set(0, GftBand.new_().Cell_pct_(20).Cell_pct_(70).Cell_pct_(10))
.run()
.tst_Filter(0, 2).tst_W(40, 140, 20).tst_X(0, 40, 180).tst_H_all(20).tst_Y_all(0);
}
@Test public void Mix_pctAtEnd() {
fx .ini_AddItms(2)
.ini_Set(0, GftBand.new_().Cell_abs_(60).Cell_pct_(100))
.run()
.tst_Filter(0, 1).tst_X(0, 60).tst_W(60, 140).tst_H_all(20).tst_Y_all(0);
}
@Test public void Mix_pctAtBgn() {
fx .ini_AddItms(2)
.ini_Set(0, GftBand.new_().Cell_pct_(100).Cell_abs_(60))
.run()
.tst_Filter(0, 1).tst_X(0, 140).tst_W(140, 60).tst_H_all(20).tst_Y_all(0);
}
@Test public void Mix_pctAtMid() {
fx .ini_AddItms(3)
.ini_Set(0, GftBand.new_().Cell_abs_(60).Cell_pct_(100).Cell_abs_(40))
.run()
.tst_Filter(0, 2).tst_X(0, 60, 160).tst_W(60, 100, 40).tst_H_all(20).tst_Y_all(0);
}
@Test public void Height_pct() {
fx .ini_AddItms(1)
.ini_Set(0, GftBand.new_().Cell_pct_(100).Len1_pct_(100))
.run()
.tst_Filter(0).tst_X(0).tst_W(200).tst_H_all(400).tst_Y_all(0);
}
@Test public void Height_mix() {
fx .ini_AddItms(3)
.ini_Set(0, GftBand.new_().Cells_num_(1).Len1_abs_( 60))
.ini_Set(1, GftBand.new_().Cells_num_(1).Len1_pct_(100))
.ini_Set(2, GftBand.new_().Cells_num_(1).Len1_abs_( 20))
.run()
.tst_Filter(0).tst_H( 60).tst_Y_all( 0).tst_X(0).tst_W(200)
.tst_Filter(1).tst_H(320).tst_Y_all( 60).tst_X(0).tst_W(200)
.tst_Filter(2).tst_H( 20).tst_Y_all(380).tst_X(0).tst_W(200);
}
@Test public void RevDir() {
fx .ini_AddItms(2).ini_BandDir(DirInt.Bwd)
.ini_Set(0, 1, GftBand.new_().Cells_num_(1).Len1_abs_(20))
.run()
.tst_Filter(0).tst_W(200).tst_H(20).tst_X(0).tst_Y(380)
.tst_Filter(1).tst_W(200).tst_H(20).tst_X(0).tst_Y(360);
}
@Test public void SubLyts() {
fx .ini_AddItms(2).ini_AddLyts(2)
.ini_Lyt(0).ini_Set(0, GftBand.new_().Cells_num_(1).Len1_pct_(100))
.ini_Lyt(1).ini_Set(0, GftBand.new_().Cells_num_(1).Len1_abs_( 20)).ini_BandDir(DirInt.Bwd)
.run()
.tst_Filter(0).tst_W(200).tst_H(400).tst_X(0).tst_Y( 0)
.tst_Filter(1).tst_W(200).tst_H( 20).tst_X(0).tst_Y(380);
}
@Test public void Var() {
fx .ini_AddItms(2)
.ini_ItmWidth(0, 30).ini_ItmWidth(1, 40)
.ini_Set(0, GftBand.new_().Cells_var_(2))
.run()
.tst_Filter(0, 1).tst_X(0, 30).tst_W(30, 40).tst_H_all(20).tst_Y_all(0);
}
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GftCell {
public GftSizeCalc Len0() {return len0;} public GftCell Len0_(GftSizeCalc c) {len0 = c; return this;} GftSizeCalc len0 = new GftSizeCalc_num(1);
public GftCell Clone() {
GftCell rv = new GftCell();
rv.len0 = len0.Clone();
return rv;
}
}

View File

@@ -0,0 +1,138 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GftGrid {
public String Key() {return key;} public GftGrid Key_(String v) {key = v; return this;} private String key;
public List_adp Bands() {return bands;} List_adp bands = List_adp_.new_();
public List_adp SubLyts() {return subLyts;} List_adp subLyts = List_adp_.new_();
public void Clear() {bands.Clear(); subLyts.Clear(); bandDir = DirInt.Fwd;}
public DirInt Bands_dir() {return bandDir;} public GftGrid Bands_dir_(DirInt v) {bandDir = v; return this;} DirInt bandDir = DirInt.Fwd;
public GftGrid SubLyts_get(String key) {
for (int i = 0; i < subLyts.Count(); i++) {
GftGrid grid = (GftGrid)subLyts.Get_at(i);
if (String_.Eq(key, grid.Key())) return grid;
}
return null;
}
public GftBand Bands_get(String key) {
for (int i = 0; i < bands.Count(); i++) {
GftBand band = (GftBand)bands.Get_at(i);
if (String_.Eq(key, band.Key())) return band;
}
return null;
}
public GftGrid Bands_add(GftBand band) {
bands.Add(band.Clone(this, bands.Count()));
return this;
}
public GftGrid Bands_add(int count, GftBand band) {
for (int i = 0; i < count; i++) {
GftBand copy = band.Clone(this, bands.Count() + i);
bands.Add(copy);
}
return this;
}
@gplx.Internal protected void Bands_delAt(int i) {bands.Del_at(i);}
@gplx.Internal protected boolean Bands_has(String key) {return Bands_indexOf(key) != List_adp_.NotFound;}
@gplx.Internal protected void Bands_del(String key) {
int idx = Bands_indexOf(key);
if (idx != List_adp_.NotFound) bands.Del_at(idx);
}
int Bands_indexOf(String key) {
int curIdx = List_adp_.NotFound;
for (int i = 0; i < bands.Count(); i++) {
GftBand band = (GftBand)bands.Get_at(i);
if (String_.Eq(key, band.Key())) {
curIdx = i;
break;
}
}
return curIdx;
}
public GftGrid Bands_set(int idx, GftBand orig) {return Bands_set(idx, idx, orig);}
public GftGrid Bands_set(int bgn, int end, GftBand orig) {
int len = end - bgn + 1;
for (int i = 0; i < len; i++) {
GftBand copy = orig.Clone(this, bgn + i);
bands.Add(copy);
}
return this;
}
public void Exec(GftItem owner, GftItem... ary) {
ExecLyts(owner, ary);
ExecBands(owner, ary);
}
void ExecLyts(GftItem owner, GftItem[] ary) {
int idx = 0;
for (int i = 0; i < subLyts.Count(); i++) {
GftGrid subGrid = (GftGrid)subLyts.Get_at(i);
GftItem[] subAry = new GftItem[subGrid.Bands_cellCount()];
for (int j = 0; j < subAry.length; j++) {
subAry[j] = ary[idx++];
}
subGrid.Exec(owner, subAry);
}
}
void ExecBands(GftItem owner, GftItem[] ary) {
if (bands.Count() == 0) return;
int availY = owner.Gft_h();
GftBand band = null;
int bgn = bandDir.GetValByDir(bands.Idx_last(), 0);
int end = bandDir.GetValByDir(-1, bands.Count());
for (int i = bgn; i != end; i += bandDir.Val()) {
band = (GftBand)bands.Get_at(i);
if (band.Len1().Key() == GftSizeCalc_abs.KEY) {
GftSizeCalc_abs calc = (GftSizeCalc_abs)band.Len1();
availY -= calc.Val();
}
}
int bandIdx = 0;
band = (GftBand)bands.Get_at(bandIdx);
band.Items().Clear();
int y = bandDir.GetValByDir(owner.Gft_h(), 0);
for (int itmIdx = 0; itmIdx < ary.length; itmIdx++) {
GftItem itm = ary[itmIdx];
if (band.Items().Count() >= band.Cells().Count()) {
int h = band.Len1().Calc(this, band, owner, itm, availY);
band.Calc(owner, y, h);
y += h * bandDir.Val();
if (bandIdx + 1 >= bands.Count()) throw Exc_.new_("error retrieving band", "owner", owner.Key_of_GfuiElem(), "item", itm.Key_of_GfuiElem(), "bandIdx", bandIdx + 1, "count", bands.Count());
band = (GftBand)bands.Get_at(++bandIdx);
band.Items().Clear();
}
band.Items_add(itm);
}
band.Calc(owner, y, band.Len1().Calc(this, band, owner, null, availY));
}
int Bands_cellCount() {
int rv = 0;
for (int i = 0; i < bands.Count(); i++) {
GftBand band = (GftBand)bands.Get_at(i);
rv += band.Cells().Count();
}
return rv;
}
public static GftGrid new_() {return new GftGrid();} GftGrid() {}
public static void LytExecRecur(GfuiElemBase owner) {
if (owner.Lyt() != null) owner.Lyt_exec();
for (int i = 0; i < owner.SubElems().Count(); i++) {
GfuiElemBase sub = (GfuiElemBase)owner.SubElems().Get_at(i);
LytExecRecur(sub);
}
}
}

View File

@@ -0,0 +1,93 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
class GftGrid_fx {
public GftItem Owner() {return owner;} GftItem owner;
public GftGrid_fx Clear() {
itms.Clear();
grid.Clear();
curGrid = grid;
owner = new GftItem_mok();//.Key_("owner");
return this;
}
public GftGrid_fx ini_AddItms(int num) {
for (int i = 0; i < num; i++)
itms.Add(new GftItem_mok());//.Key_("key" + Int_.Xto_str(i)));
return this;
}
public GftGrid_fx ini_ItmWidth(int i, int width) {
GftItem itm = (GftItem)itms.Get_at(i);
itm.Gft_w_(width);
return this;
}
public GftGrid_fx ini_AddLyts(int num) {
for (int i = 0; i < num; i++) {
GftGrid newGrid = GftGrid.new_();
grid.SubLyts().Add(newGrid);
}
return this;
}
public GftGrid_fx ini_Lyt(int num) {
curGrid = (GftGrid)grid.SubLyts().Get_at(num);
return this;
}
public GftGrid_fx ini_BandDir(DirInt dir) {curGrid.Bands_dir_(dir); return this;}
public GftGrid_fx ini_OwnerSize(int w, int h) {owner.Gft_w_(w); owner.Gft_h_(h); return this;}
public GftGrid_fx ini_Set(int idx, GftBand orig) {return ini_Set(idx, idx, orig);}
public GftGrid_fx ini_Set(int bgn, int end, GftBand orig) {curGrid.Bands_set(bgn, end, orig); return this;}
public GftGrid_fx run() {
GftItem[] ary = (GftItem[])itms.To_ary(GftItem.class);
grid.Exec(owner, ary);
return this;
}
public GftGrid_fx tst_Filter(int idx) {return tst_Filter(idx, idx);}
public GftGrid_fx tst_Filter(int bgn, int end) {this.bgn = bgn; this.end = end; return this;} int bgn, end;
public GftGrid_fx tst_W(int... expd) {return tst_ary("w", expd);}
public GftGrid_fx tst_H(int... expd) {return tst_ary("h", expd);}
public GftGrid_fx tst_X(int... expd) {return tst_ary("x", expd);}
public GftGrid_fx tst_Y(int... expd) {return tst_ary("y", expd);}
public GftGrid_fx tst_W_all(int expd) {return tst_all("w", expd);}
public GftGrid_fx tst_H_all(int expd) {return tst_all("h", expd);}
public GftGrid_fx tst_X_all(int expd) {return tst_all("x", expd);}
public GftGrid_fx tst_Y_all(int expd) {return tst_all("y", expd);}
GftGrid_fx tst_all(String name, int expdVal) {return tst_ary(name, rng_(expdVal, end - bgn + 1));}
GftGrid_fx tst_ary(String name, int[] expd) {
int len = end - bgn + 1;
int[] actl = new int[len];
for (int i = 0; i < len; i++) {
GftItem itm = (GftItem)itms.Get_at(i + bgn);
actl[i] = GetVal(itm, name);
}
Tfds.Eq_ary(expd, actl, name);
return this;
}
int GetVal(GftItem item, String name) {
if (String_.Eq(name, "x")) return item.Gft_x();
else if (String_.Eq(name, "y")) return item.Gft_y();
else if (String_.Eq(name, "w")) return item.Gft_w();
else if (String_.Eq(name, "h")) return item.Gft_h();
else throw Exc_.new_unhandled(name);
}
static int[] rng_(int expdVal, int len) {
int[] rv = new int[len];
for (int i = 0; i < len; i++) rv[i] = expdVal;
return rv;
}
GftGrid grid = GftGrid.new_(), curGrid;
List_adp itms = List_adp_.new_();
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GftItem {
String Key_of_GfuiElem();
int Gft_h(); GftItem Gft_h_(int v);
int Gft_w(); GftItem Gft_w_(int v);
int Gft_x(); GftItem Gft_x_(int v);
int Gft_y(); GftItem Gft_y_(int v);
GftItem Gft_rect_(RectAdp rect);
}
class GftItem_mok implements GftItem {
public String Key_of_GfuiElem() {return "null";}
public int Gft_h() {return gft_h;} public GftItem Gft_h_(int v) {gft_h = v; return this;} int gft_h;
public int Gft_w() {return gft_w;} public GftItem Gft_w_(int v) {gft_w = v; return this;} int gft_w;
public int Gft_x() {return gft_x;} public GftItem Gft_x_(int v) {gft_x = v; return this;} int gft_x;
public int Gft_y() {return gft_y;} public GftItem Gft_y_(int v) {gft_y = v; return this;} int gft_y;
public GftItem Gft_rect_(RectAdp rect) {gft_x = rect.X(); gft_y = rect.Y(); gft_w = rect.Width(); gft_h = rect.Height(); return this;}
}

View File

@@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GftSizeCalc {
int Key();
int Calc(GftGrid grid, GftBand band, GftItem owner, GftItem item, int ownerWidth);
GftSizeCalc Clone();
}
class GftSizeCalc_pct implements GftSizeCalc {
public int Key() {return KEY;} public static final int KEY = 1;
public float Val() {return pct;} float pct;
public int Calc(GftGrid grid, GftBand band, GftItem owner, GftItem item, int ownerWidth) {
return Int_.Mult(ownerWidth, pct / 100);
}
public GftSizeCalc Clone() {return new GftSizeCalc_pct(pct);}
public GftSizeCalc_pct(float v) {pct = v;}
}
class GftSizeCalc_abs implements GftSizeCalc {
public int Key() {return KEY;} public static final int KEY = 2;
public int Val() {return abs;} int abs;
public int Calc(GftGrid grid, GftBand band, GftItem owner, GftItem item, int ownerWidth) {
return abs;
}
public GftSizeCalc Clone() {return new GftSizeCalc_abs(abs);}
public GftSizeCalc_abs(int v) {abs = v;}
}
class GftSizeCalc_num implements GftSizeCalc {
public int Key() {return KEY;} public static final int KEY = 3;
public int Val() {return num;} int num;
public int Calc(GftGrid grid, GftBand band, GftItem owner, GftItem item, int ownerWidth) {
return owner.Gft_w() / num;
}
public GftSizeCalc Clone() {return new GftSizeCalc_num(num);}
public GftSizeCalc_num(int num) {this.num = num;}
}
class GftSizeCalc_var implements GftSizeCalc {
public int Key() {return KEY;} public static final int KEY = 4;
public int Val() {return num;} int num;
public int Calc(GftGrid grid, GftBand band, GftItem owner, GftItem item, int ownerWidth) {
GfuiElem elem = GfuiElem_.as_(item);
return elem == null ? item.Gft_w() : elem.Width();
}
public GftSizeCalc Clone() {return new GftSizeCalc_var(num);}
public GftSizeCalc_var(int num) {this.num = num;}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
public class GxwBoxListener implements ComponentListener, FocusListener {
@Override public void componentShown(ComponentEvent e) {host.Host().VisibleChangedCbk();}
@Override public void componentHidden(ComponentEvent e) {host.Host().VisibleChangedCbk();}
@Override public void componentMoved(ComponentEvent e) {}
@Override public void componentResized(ComponentEvent e) {host.Host().SizeChangedCbk();}
@Override public void focusGained(FocusEvent e) {host.Host().FocusGotCbk();}
@Override public void focusLost(FocusEvent e) {host.Host().FocusLostCbk();}
public GxwBoxListener(GxwElem host) {this.host = host;} GxwElem host;
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwCbkHost {
boolean KeyDownCbk(IptEvtDataKey data);
boolean KeyHeldCbk(IptEvtDataKeyHeld data);
boolean KeyUpCbk(IptEvtDataKey data);
boolean MouseDownCbk(IptEvtDataMouse data);
boolean MouseUpCbk(IptEvtDataMouse data);
boolean MouseMoveCbk(IptEvtDataMouse data);
boolean MouseWheelCbk(IptEvtDataMouse data);
boolean PaintCbk(PaintArgs paint);
boolean PaintBackgroundCbk(PaintArgs paint);
boolean DisposeCbk();
boolean SizeChangedCbk();
boolean FocusGotCbk();
boolean FocusLostCbk();
boolean VisibleChangedCbk();
//boolean WndProcCbk(WindowMessage windowMessage);
}

View File

@@ -0,0 +1,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
class GxwCbkHost_ {
public static final GxwCbkHost Null = new GfuiHost_cls_null();
public static final boolean ExecKeyEvent(GxwCbkHost host, KeyEvent e) {
boolean rv = true; int id = e.getID(), val = e.getKeyCode();
boolean isAltF4 = false;
if (e.isAltDown() && val == IptKey_.F4.Val() ) {
isAltF4 = true;
}
if (id == KeyEvent.KEY_TYPED) {
IptEvtDataKeyHeld keyHeldData = IptEvtDataKeyHeld.char_(e.getKeyChar());
rv = host.KeyHeldCbk(keyHeldData);
if (keyHeldData.Handled()) rv = false;
}
else {
if (e.isShiftDown()) val |= IptKey_.Shift.Val();
if (e.isControlDown()) val |= IptKey_.Ctrl.Val();
if (e.isAltDown()) val |= IptKey_.Alt.Val();
IptEvtDataKey keyData = IptEvtDataKey.int_(val);
// Tfds.Write(e.getKeyChar(), e.getKeyCode(), val, id);
if (id == KeyEvent.KEY_PRESSED) rv = host.KeyDownCbk(keyData);
else if (id == KeyEvent.KEY_RELEASED) rv = host.KeyUpCbk(keyData);
if (keyData.Handled()) rv = false; // was false
}
if (isAltF4) {
e.consume();
}
if (e.getKeyCode() == KeyEvent.VK_ALT) e.consume(); // force consume of alt-keys; occurs when alt-f4ing out of video app (though not audio app)
return rv;
}
public static final boolean ExecMouseEvent(GxwCbkHost host, MouseEvent e) {
int button = e.getButton(), val = 0;
if (button == MouseEvent.BUTTON1)
val = IptMouseBtn_.Left.Val();
if (button == MouseEvent.BUTTON2) val |= IptMouseBtn_.Middle.Val();
if (button == MouseEvent.BUTTON3) val |= IptMouseBtn_.Right.Val();
IptEvtDataMouse data = IptEvtDataMouse.new_(IptMouseBtn_.api_(val), IptMouseWheel_.None, e.getX(), e.getY());
boolean rv = true;
int id = e.getID();
if (id == MouseEvent.MOUSE_PRESSED) rv = host.MouseDownCbk(data);
else if (id == MouseEvent.MOUSE_RELEASED) rv = host.MouseUpCbk(data);
return rv;
}
public static final boolean ExecMouseWheel(GxwCbkHost host, MouseWheelEvent e) {
IptMouseWheel wheel = e.getWheelRotation() < 0 ? IptMouseWheel_.Up : IptMouseWheel_.Down;
return host.MouseWheelCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, wheel, e.getX(), e.getY()));
}
}
class GfuiHost_cls_null implements GxwCbkHost { // NOTE: return true by default so that super.proc() is always called; ex: SizeChangedCbk should return true so that super.OnResize will be called
public boolean KeyDownCbk(IptEvtDataKey data) {return true;}
public boolean KeyHeldCbk(IptEvtDataKeyHeld data) {return true;}
public boolean KeyUpCbk(IptEvtDataKey data) {return true;}
public boolean MouseDownCbk(IptEvtDataMouse data) {return true;}
public boolean MouseUpCbk(IptEvtDataMouse data) {return true;}
public boolean MouseMoveCbk(IptEvtDataMouse data) {return true;}
public boolean MouseWheelCbk(IptEvtDataMouse data) {return true;}
public boolean PaintCbk(PaintArgs paint) {return true;}
public boolean PaintBackgroundCbk(PaintArgs paint) {return true;}
public boolean DisposeCbk() {return true;}
public boolean SizeChangedCbk() {return true;}
public boolean FocusGotCbk() {return true;}
public boolean FocusLostCbk() {return true;}
public boolean VisibleChangedCbk() {return true;}
// public boolean WndProcCbk(WindowMessage windowMessage) {return true;}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwCheckListBox extends GxwElem {
int Items_count();
List_adp Items_getAll();
List_adp Items_getChecked();
void Items_add(Object obj, boolean v);
void Items_reverse();
boolean Items_getCheckedAt(int i);
void Items_setCheckedAt(int i, boolean v);
void Items_setAll(boolean v);
void Items_clear();
}

View File

@@ -0,0 +1,201 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import gplx.gfui.*;
public class GxwCheckListBox_lang extends JScrollPane implements GxwCheckListBox, GxwElem {
Vector<CheckListItem> internalItems;
GxwListBox_lang listBox;
public GxwCheckListBox_lang() {
initComponents();
}
private void initComponents() {
listBox = GxwListBox_lang.new_();
this.setViewportView(listBox);
internalItems = new Vector<CheckListItem>();
this.listBox.setListData(internalItems);
CheckListCellRenderer renderer = new CheckListCellRenderer();
listBox.setCellRenderer(renderer);
listBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
CheckListListener lst = new CheckListListener(this); listBox.addMouseListener(lst); listBox.addKeyListener(lst);
ctrlMgr = new GxwCore_host(GxwCore_lang.new_(this), listBox.ctrlMgr);
// ctrlMgr = GxwCore_lang.new_(this);
this.enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
GxwBoxListener_checkListBox lnr = new GxwBoxListener_checkListBox(this, this);
// this.setFocusTraversalKeysEnabled(false);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
}
public GxwCbkHost Host() {return host;}
public void Host_set(GxwCbkHost host) {
this.host = host;
listBox.Host_set(host);
} private GxwCbkHost host = GxwCbkHost_.Null;
// @Override public boolean requestFocusInWindow() {
// return listBox.requestFocusInWindow();
//// return super.requestFocusInWindow();
// }
public List_adp Items_getAll() {return Items_get(Mode_All);}
public int Items_count() {return internalItems.size();}
public boolean Items_getCheckedAt(int i) {return internalItems.get(i).selected;}
public void Items_setCheckedAt(int i, boolean v) {internalItems.get(i).selected = v;}
public List_adp Items_getChecked() {return Items_get(Mode_Selected);}
static final int Mode_All = 1, Mode_Selected = 2;
List_adp Items_get(int mode) {
List_adp list = List_adp_.new_();
for (CheckListItem data: internalItems) {
boolean add = (mode == Mode_All) || (mode == Mode_Selected) && data.Selected();
if (add)
list.Add(data.Data());
}
return list;
}
public void Items_add(Object data, boolean selected) {
internalItems.add(new CheckListItem(data, selected));
this.listBox.setListData(internalItems);
this.listBox.updateUI();
}
public void Items_setAll(boolean v) {
for (CheckListItem data: internalItems) {
data.Selected_set(v);
}
this.listBox.updateUI();
}
public void Items_reverse() {
for (CheckListItem data: internalItems) {
data.Selected_set(!data.Selected());
}
this.listBox.updateUI();
}
public void Items_clear() {
internalItems.clear();
this.listBox.updateUI();
}
@Override public void setBounds(Rectangle r) {super.setBounds(r); this.validate();}
@Override public void setSize(int w, int h) {super.setSize(w, h); this.validate();}
@Override public void setSize(Dimension d) {super.setSize(d); this.validate();}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public String TextVal() {return "GxwCheckListBox_lang";} public void TextVal_set(String v) {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void SendMouseWheel(IptMouseWheel direction) {}
@Override public void processKeyEvent(KeyEvent e) {
if (GxwCbkHost_.ExecKeyEvent(host, e))
super.processKeyEvent(e);
}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
public void EnableDoubleBuffering() { // eliminates flickering during OnPaint
}
public void CreateControlIfNeeded() {
}
}
class GxwBoxListener_checkListBox extends GxwBoxListener {
@Override public void focusGained(FocusEvent e) {
host.Host().FocusGotCbk();
clb.listBox.requestFocusInWindow();
if (clb.listBox.getSelectedIndex() < 0)
clb.listBox.setSelectedIndex(0);
}
@Override public void focusLost(FocusEvent e) {host.Host().FocusLostCbk();}
public GxwBoxListener_checkListBox(GxwElem host, GxwCheckListBox_lang clb) {super(host); this.clb = clb;}
GxwCheckListBox_lang clb;
}
class CheckListListener implements MouseListener, KeyListener {
GxwCheckListBox_lang m_parent; JList m_list;
public CheckListListener(GxwCheckListBox_lang parent) {
m_parent = parent;
m_list = parent.listBox;
}
public void mouseClicked(MouseEvent e) {
if (e.getX() < 20) doCheck();
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == ' ') doCheck();
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
protected void doCheck() {
int index = m_list.getSelectedIndex();
if (index < 0) return;
CheckListItem data = (CheckListItem)m_list.getModel().getElementAt(index);
data.Selected_toggle();
m_list.repaint();
}
}
class CheckListCellRenderer extends JCheckBox implements ListCellRenderer{
public CheckListCellRenderer() {
setOpaque(true);
setBorder(GxwBorderFactory.Empty);
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value != null) setText(value.toString());
setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
CheckListItem data = (CheckListItem)value;
setSelected(data.Selected());
setFont(list.getFont());
setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : GxwBorderFactory.Empty);
return this;
}
}
class CheckListItem {
public CheckListItem(Object data, Boolean selected) {this.data = data; this.selected = selected;}
public Object Data() {return data;} Object data;
public boolean Selected() {return selected;} public void Selected_set(boolean selected) {this.selected = selected;} protected boolean selected;
public void Selected_toggle() {selected = !selected;}
public String toString() {return Object_.Xto_str_strict_or_null_mark(data);}
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwComboBox extends GxwElem {
void DataSource_set(Object... ary);
Object SelectedItm(); void SelectedItm_set(Object v);
}

View File

@@ -0,0 +1,108 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GxwComboBox_lang extends JComboBox implements GxwComboBox, GxwElem, ActionListener {
public void DataSource_set(Object... ary) {
for (Object o : ary)
this.insertItemAt(o, this.getItemCount());
/*
Get current value
Object obj = cb.getSelectedItem();
Set a new valu
cb.setSelectedItem("item2");
obj = cb.getSelectedItem();
*/
}
public Object SelectedItm() {return this.getEditor().getItem();} public void SelectedItm_set(Object v) {
this.getEditor().setItem(v);
}
void ctor_() {
ctrlMgr = GxwCore_lang.new_(this);
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
GxwBoxListener lnr = new GxwBoxListener(this);
// this.setFocusTraversalKeysEnabled(false);
// this.addKeyListener(this);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
this.setEditable(true);
// this.addActionListener(this);
this.setFocusable(true);
this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
Component jc = this.getEditor().getEditorComponent(); // WORKAROUND:SWING:JComboBox does not reroute events from editor; will not handle canceling key
jc.addKeyListener(new ComboBox_keylistener(this));
}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
// need to validate, else dropDownArrow will not get redrawn in correct pos
@Override public void setBounds(Rectangle r) {super.setBounds(r); this.validate();}
@Override public void setSize(int w, int h) {super.setSize(w, h); this.validate();}
@Override public void setSize(Dimension d) {super.setSize(d); this.validate();}
public String TextVal() {return Object_.Xto_str_strict_or_empty(this.SelectedItm());} public void TextVal_set(String v) {this.SelectedItm_set(v);}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void SendMouseWheel(IptMouseWheel direction) {}
// @Override public void keyPressed(KeyEvent arg0) {this.processKeyEvent(arg0);}
// @Override public void keyReleased(KeyEvent arg0) {this.processKeyEvent(arg0);}
// @Override public void keyTyped(KeyEvent arg0) {this.processKeyEvent(arg0);}
@Override public void processKeyEvent(KeyEvent e) {
if (GxwCbkHost_.ExecKeyEvent(host, e))
super.processKeyEvent(e);
}
// @Override public void actionPerformed(ActionEvent e) {
// }
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
public void EnableDoubleBuffering() { // eliminates flickering during OnPaint
}
public void CreateControlIfNeeded() {
}
public static GxwComboBox_lang new_() {
GxwComboBox_lang rv = new GxwComboBox_lang();
rv.ctor_();
return rv;
} GxwComboBox_lang() {}
}
class ComboBox_keylistener implements KeyListener {
public ComboBox_keylistener(GxwComboBox_lang host) {this.host = host;} GxwComboBox_lang host;
@Override public void keyPressed(KeyEvent arg0) {
// if (arg0.getKeyChar() == 'f')
// System.out.println('h');
host.processKeyEvent(arg0);
}
@Override public void keyReleased(KeyEvent arg0) {
//host.processKeyEvent(arg0);
}
@Override public void keyTyped(KeyEvent arg0) {
//host.processKeyEvent(arg0);
}
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public abstract class GxwCore_base {
public abstract void Controls_add(GxwElem sub);
public abstract void Controls_del(GxwElem sub);
public abstract int Width(); public abstract void Width_set(int v);
public abstract int Height(); public abstract void Height_set(int v);
public abstract int X(); public abstract void X_set(int v);
public abstract int Y(); public abstract void Y_set(int v);
public abstract SizeAdp Size(); public abstract void Size_set(SizeAdp v);
public abstract PointAdp Pos(); public abstract void Pos_set(PointAdp v);
public abstract RectAdp Rect(); public abstract void Rect_set(RectAdp v);
public abstract boolean Visible(); public abstract void Visible_set(boolean v);
public abstract ColorAdp BackColor(); public abstract void BackColor_set(ColorAdp v);
public abstract ColorAdp ForeColor(); public abstract void ForeColor_set(ColorAdp v);
public abstract FontAdp TextFont(); public abstract void TextFont_set(FontAdp v);
public abstract String TipText(); public abstract void TipText_set(String v);
public abstract int Focus_index(); public abstract void Focus_index_set(int v);
public abstract boolean Focus_able(); public abstract void Focus_able_(boolean v);
public abstract boolean Focus_has();
public abstract void Focus();
public abstract void Select_exec();
public abstract void Zorder_front(); public abstract void Zorder_back();
public abstract void Invalidate();
public abstract void Dispose();
}

View File

@@ -0,0 +1,159 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import javax.swing.JComponent;
import javax.swing.JWindow;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics2D;
public class GxwCore_lang extends GxwCore_base {
@Override public int Width() {return control.getWidth();} @Override public void Width_set(int v) {control.setSize(v, control.getHeight());}
@Override public int Height() {return control.getHeight();} @Override public void Height_set(int v) {control.setSize(control.getWidth(), v);}
@Override public int X() {return control.getX();} @Override public void X_set(int v) {control.setLocation(v, control.getY());}
@Override public int Y() {return control.getY();} @Override public void Y_set(int v) {control.setLocation(control.getX(), v);}
@Override public SizeAdp Size() {return GxwCore_lang.XtoSizeAdp(control.getSize());} @Override public void Size_set(SizeAdp v) {control.setSize(GxwCore_lang.Xto_size(v));}
@Override public PointAdp Pos() {return GxwCore_lang.XtoPointAdp(control.getLocation());} @Override public void Pos_set(PointAdp v) {control.setLocation(GxwCore_lang.XtoPoint(v));}
@Override public RectAdp Rect() {return GxwCore_lang.XtoRectAdp(control.getBounds());} @Override public void Rect_set(RectAdp v) {
control.setBounds(GxwCore_lang.XtoRect(v));
// control.setLocation(v.Pos().XtoPoint());
// control.setSize(v.Size().XtoDimension());
}
@Override public boolean Visible() {
Container owner = control.getParent();
// WORKAROUND:JAVA: .NET automatically propagates .Visible down ElementTree; .Visible needs to propagate else sub.Visible can be true though owner.Visible will be false
while (owner != null) {
if (!owner.isVisible())
return false; // handles case wherein sub is visible but owner is not -> sub should be marked not visible
owner = owner.getParent();
}
return control.isVisible();
}
@Override public void Visible_set(boolean v) {
control.setVisible(v);
}
@Override public ColorAdp BackColor() {return XtoColorAdp(control.getBackground());}
@Override public void BackColor_set(ColorAdp v) {
if (control instanceof JComponent) {
((JComponent)control).setBackground(ColorAdpCache._.GetNativeColor(v));
}
else if (control instanceof RootPaneContainer) {
RootPaneContainer container = (RootPaneContainer)control;
container.getContentPane().setBackground(ColorAdpCache._.GetNativeColor(v));
}
}
@Override public ColorAdp ForeColor() {return XtoColorAdp(control.getForeground());} @Override public void ForeColor_set(ColorAdp v) {control.setForeground(ColorAdpCache._.GetNativeColor(v));}
@Override public FontAdp TextFont() {
if (prvFont != null) return prvFont;
Font f = control.getFont();
FontAdp curFont = FontAdp.new_(f.getFontName(), FontAdpCache.XtoOsDpi(f.getSize2D()), FontStyleAdp_.lang_(f.getStyle()));
curFont.OwnerGxwCore_(this);
prvFont = curFont;
return prvFont;
} FontAdp prvFont;
@Override public void TextFont_set(FontAdp v) {
control.setFont(v.UnderFont());
v.OwnerGxwCore_(this);
prvFont = v;
}
@Override public String TipText() {return tipText;} @Override public void TipText_set(String v) {tipText = v;} String tipText;
@Override public void Controls_add(GxwElem sub) {
try {
JComponent component = (JComponent)sub;
Container container = (Container)control;
container.add(component);
}catch (Exception e) {}
}
@Override public void Controls_del(GxwElem sub) {
JComponent component = (JComponent)sub;
// clear out painted area, or residue will remain (see opal when navigating to empty grid)
Graphics2D g2 = (Graphics2D) component.getGraphics();
g2.setColor(component.getBackground());
g2.fillRect(0, 0, component.getWidth(), component.getHeight());
g2.dispose();
Container container = (Container)control;
container.remove(component);
}
@Override public boolean Focus_has() {return control.hasFocus();}
// @Override public boolean Focus_able() {return control.isFocusable();}
// @Override public void Focus_able_(boolean v) {control.setFocusable(v);}
@Override public boolean Focus_able() {return focus_able;} boolean focus_able;
@Override public void Focus_able_(boolean v) {focus_able = v;}
// @Override public void Focus_able_force_(boolean v){control.setFocusable(v);}
@Override public int Focus_index() {return focusIndex;} @Override public void Focus_index_set(int v) {focusIndex = v;} int focusIndex;
@Override public void Focus() {
if (Focus_able()) { // NOTE: .Focus() only works if TabStop = true; otherwise, must call .Select()
// FocusableThread t = new FocusableThread(control);
// SwingUtilities.invokeLater(t);
// control.requestFocus();
if (!control.requestFocusInWindow()) { // will fail when switching to imgApp with gallery open from opalMain
// control.requestFocus();
}
}
}
class FocusableThread implements Runnable {
public void run() {
// comp.requestFocusInWindow();
comp.requestFocus();
comp.repaint();
}
public FocusableThread(Component comp) {this.comp = comp;} Component comp;
}
@Override public void Select_exec() {
control.requestFocus();
}
@Override public void Zorder_front() {
Container owner = control.getParent();
if (owner == null)return;
owner.setComponentZOrder(control, 0); // NOTE: last component gets drawn last, so will be first visually
}
@Override public void Zorder_back() {
Container owner = control.getParent();
owner.setComponentZOrder(control, owner.getComponentCount() - 1);
}
@Override public void Invalidate() {control.repaint();
}
@Override public void Dispose() {} // JAVA: no Dispose for component? only for form
protected Component control;
public static GxwCore_lang new_(Component control) {
GxwCore_lang rv = new GxwCore_lang();
rv.control = control;
return rv;
} GxwCore_lang() {}
public static ColorAdp XtoColorAdp(java.awt.Color v) {return ColorAdp.new_((int)v.getAlpha(), (int)v.getRed(), (int)v.getGreen(), (int)v.getBlue());}
public static java.awt.Dimension Xto_size(SizeAdp v) {return new java.awt.Dimension(v.Width(), v.Height());}
public static SizeAdp XtoSizeAdp(java.awt.Dimension val) {
return new SizeAdp(val.width, val.height);
}
public static java.awt.Point XtoPoint(PointAdp v) {return new java.awt.Point(v.X(), v.Y());}
public static PointAdp XtoPointAdp(java.awt.Point v) {
return new PointAdp(v.x, v.y);
}
public static RectAdp XtoRectAdp(java.awt.Rectangle rect) {
return new RectAdp(GxwCore_lang.XtoPointAdp(rect.getLocation())
, GxwCore_lang.XtoSizeAdp(rect.getSize()));
}
public static java.awt.Rectangle XtoRect(RectAdp rect) {return new java.awt.Rectangle(rect.X(), rect.Y(), rect.Width(), rect.Height());}
public static java.awt.Rectangle XtoRect(int x, int y, int w, int h) {return new java.awt.Rectangle(x, y, w, h);}
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GxwCore_mock extends GxwCore_base {
@Override public int Width() {return size.Width();} @Override public void Width_set(int v) {size = SizeAdp_.new_(v, size.Height());}
@Override public int Height() {return size.Height();} @Override public void Height_set(int v) {size = SizeAdp_.new_(size.Width(), v);}
@Override public int X() {return pos.X();} @Override public void X_set(int v) {pos = PointAdp_.new_(v, pos.Y());}
@Override public int Y() {return pos.Y();} @Override public void Y_set(int v) {pos = PointAdp_.new_(pos.X(), v);}
@Override public SizeAdp Size() {return size;} @Override public void Size_set(SizeAdp v) {size = v;} SizeAdp size = SizeAdp_.Zero;
@Override public PointAdp Pos() {return pos;} @Override public void Pos_set(PointAdp v) {pos = v;} PointAdp pos = PointAdp_.Zero;
@Override public RectAdp Rect() {return RectAdp_.vector_(pos, size);} @Override public void Rect_set(RectAdp v) {size = v.Size(); pos = v.Pos();}
@Override public boolean Visible() {return visible;} @Override public void Visible_set(boolean v) {visible = v;} private boolean visible = true; // HACK: default all controls to visible (should be set to visible only when form is loaded); will cause FocusKeyMgrTst.SubWidget test to fail
@Override public ColorAdp BackColor() {return backColor;} @Override public void BackColor_set(ColorAdp v) {backColor = v;} ColorAdp backColor = ColorAdp_.Null;
@Override public ColorAdp ForeColor() {return textColor;} @Override public void ForeColor_set(ColorAdp v) {textColor = v;} ColorAdp textColor = ColorAdp_.Null;
@Override public FontAdp TextFont() {return font;} @Override public void TextFont_set(FontAdp v) {font = v;} FontAdp font;
@Override public String TipText() {return tipText;} @Override public void TipText_set(String v) {tipText = v;} private String tipText;
@Override public void Controls_add(GxwElem sub) {list.Add(sub);}
@Override public void Controls_del(GxwElem sub) {list.Del(sub);}
@Override public int Focus_index() {return focusKeyIndex;} @Override public void Focus_index_set(int v) {focusKeyIndex = v;} int focusKeyIndex;
@Override public boolean Focus_able() {return canFocus;} @Override public void Focus_able_(boolean v) {canFocus = v;} private boolean canFocus = true;
@Override public boolean Focus_has() {return false;}
@Override public void Focus() {}
@Override public void Select_exec() {}
@Override public void Zorder_front() {} @Override public void Zorder_back() {}
@Override public void Invalidate() {} @Override public void Dispose() {}
public void SendKey(IptKey key) {}
List_adp list = List_adp_.new_();
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwElem extends GfoInvkAble {
GxwCore_base Core();
GxwCbkHost Host(); void Host_set(GxwCbkHost host);
String TextVal(); void TextVal_set(String v);
void EnableDoubleBuffering();
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public abstract class GxwElemFactory_base {
@gplx.Internal protected abstract GxwElem control_();
@gplx.Internal protected abstract GxwWin win_app_();
@gplx.Internal protected abstract GxwWin win_tool_(KeyValHash ctorArgs);
@gplx.Internal protected abstract GxwWin win_toaster_(KeyValHash ctorArgs);
@gplx.Internal protected abstract GxwElem lbl_();
@gplx.Internal protected abstract GxwTextFld text_fld_();
@gplx.Internal protected abstract GxwTextFld text_memo_();
@gplx.Internal protected abstract GxwTextHtml text_html_();
@gplx.Internal protected abstract GxwCheckListBox checkListBox_(KeyValHash ctorArgs);
@gplx.Internal protected abstract GxwComboBox comboBox_();
@gplx.Internal protected abstract GxwListBox listBox_();
// @gplx.Internal protected GxwElem spacer_() {return MockControl.new_();}
}
class GxwElemFactory_ {
public static GxwElemFactory_base _ = new GxwElemFactory_cls_mock();
public static void winForms_() {_ = new GxwElemFactory_cls_lang();}
public static void swt_(org.eclipse.swt.widgets.Display display) {_ = new GxwElemFactory_swt(display);}
}
class GxwElemFactory_cls_lang extends GxwElemFactory_base {
@gplx.Internal @Override protected GxwElem control_() {return new GxwElem_lang();}
@gplx.Internal @Override protected GxwWin win_tool_(KeyValHash ctorArgs) {
GfuiWin ownerForm = (GfuiWin)ctorArgs.FetchValOr(GfuiElem_.InitKey_ownerWin, null);
GxwWin ownerElem = ownerForm == null ? null : (GxwWin)ownerForm.UnderElem();
return GxwWin_jdialog.new_(ownerElem);
// return GxwWin_lang.new_();
}
@gplx.Internal @Override protected GxwWin win_toaster_(KeyValHash ctorArgs) {
GfsCtx ctx = GfsCtx.new_(); ctx.Match("", "");
GfuiWin ownerForm = (GfuiWin)ctorArgs.FetchValOr(GfuiElem_.InitKey_ownerWin, null);
GxwWin ownerElem = ownerForm == null ? null : (GxwWin)ownerForm.UnderElem();
return GxwWin_jwindow.new_(ownerElem);
// return GxwWin_lang.new_();
}
@gplx.Internal @Override protected GxwWin win_app_() {return GxwWin_lang.new_();}
@gplx.Internal @Override protected GxwElem lbl_() {return new GxwElem_lang();}
@gplx.Internal @Override protected GxwTextFld text_fld_() {return GxwTextBox_lang_.fld_();}
@gplx.Internal @Override protected GxwTextFld text_memo_() {return GxwTextBox_lang_.memo_();}
@gplx.Internal @Override protected GxwTextHtml text_html_() {return new GxwTextHtml_lang().ctor();}
@gplx.Internal @Override protected GxwCheckListBox checkListBox_(KeyValHash ctorArgs) {return new GxwCheckListBox_lang();}
@gplx.Internal @Override protected GxwComboBox comboBox_() {return GxwComboBox_lang.new_();}
@gplx.Internal @Override protected GxwListBox listBox_() {return GxwListBox_lang.new_();}
}
class GxwElemFactory_cls_mock extends GxwElemFactory_base {
@gplx.Internal @Override protected GxwElem control_() {return GxwElem_mock_base.new_();}
@gplx.Internal @Override protected GxwWin win_app_() {return MockForm._;}
@gplx.Internal @Override protected GxwWin win_tool_(KeyValHash ctorArgs) {return MockForm._;}
@gplx.Internal @Override protected GxwWin win_toaster_(KeyValHash ctorArgs) {return MockForm._;}
@gplx.Internal @Override protected GxwElem lbl_() {return GxwElem_mock_base.new_();}
@gplx.Internal @Override protected GxwTextFld text_fld_() {return new MockTextBox();}
@gplx.Internal @Override protected GxwTextFld text_memo_() {return new MockTextBoxMulti();}
@gplx.Internal @Override protected GxwTextHtml text_html_() {return new MockTextBoxMulti();}
@gplx.Internal @Override protected GxwCheckListBox checkListBox_(KeyValHash ctorArgs) {throw Exc_.new_unimplemented();}
@gplx.Internal @Override protected GxwComboBox comboBox_() {return new MockComboBox();}
@gplx.Internal @Override protected GxwListBox listBox_() {return new MockListBox();}
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.AWTEvent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import javax.swing.JComponent;
public class GxwElem_lang extends JComponent implements GxwElem {
public static final String AlignH_cmd = "AlignH";
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return text;} public void TextVal_set(String v) {text = v;} String text; // JAVA: JComponent does not support Text (.NET Control does)
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;} // noop: intended for AlignH
@Override public void processKeyEvent(KeyEvent e) {if (GxwCbkHost_.ExecKeyEvent(host, e)) super.processKeyEvent(e);}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {
if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
// always paint background color; must happen before any controlPaint; extract to separate method if override needed
Graphics2D g2 = (Graphics2D)g;
g2.setBackground(this.getBackground());
RectAdp clipRect = GxwCore_lang.XtoRectAdp(g2.getClipBounds());
g2.clearRect(clipRect.X(), clipRect.Y(), clipRect.Width(), clipRect.Height());
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_(g2), clipRect))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
// todo: call Dispose when ownerForm is disposed
// @Override protected void Dispose(boolean disposing) {if (host.DisposeCbk()) super.Dispose(disposing);}
public void ctor_GxwElem() {
ctrlMgr = GxwCore_lang.new_(this);
GxwBoxListener lnr = new GxwBoxListener(this);
//this.setFocusTraversalKeysEnabled(false);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {
}
public void EnableDoubleBuffering() {} // eliminates flickering during OnPaint
JComponent comp = null;
public GxwElem_lang() {this.ctor_GxwElem();}
}

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class GxwElem_mock_base implements GxwElem {
public GxwCore_base Core() {return ctrlMgr;} final GxwCore_mock ctrlMgr = new GxwCore_mock();
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return text;} public void TextVal_set(String v) {text = v;} private String text = "";
public void SendKeyDown(IptKey key) {}
public void EnableDoubleBuffering() {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}
List_adp list = List_adp_.new_();
public static GxwElem_mock_base new_() {return new GxwElem_mock_base();} protected GxwElem_mock_base() {}
}
class MockTextBox extends GxwElem_mock_base implements GxwTextFld {
public boolean Border_on() {return borderOn;} public void Border_on_(boolean v) {borderOn = v;} private boolean borderOn = true;
public boolean OverrideTabKey() {return false;} public void OverrideTabKey_(boolean v) {}
public int SelBgn() {return selectionStart;} public void SelBgn_set(int v) {selectionStart = v;} int selectionStart;
public int SelLen() {return selectionLength;} public void SelLen_set(int v) {selectionLength = v;} int selectionLength;
public void AlignH_(GfuiAlign val) {}
public void CreateControlIfNeeded() {}
public void Margins_set(int left, int top, int right, int bot) {}
}
class MockTextBoxMulti extends MockTextBox implements GxwTextMemo, GxwTextHtml { public KeyVal[] Html_sel_atrs() {return KeyVal_.Ary_empty;}
public void Html_enabled(boolean v) {}
public String Html_doc_html() {return "";}
public void Html_css_set(String s) {}
public int LinesPerScreen() {return linesPerScreen;} int linesPerScreen = 1;
public int LinesTotal() {return linesTotal;} int linesTotal = 1;
public int ScreenCount() {return screenCount;} int screenCount = 1;
public int LineLength(int lineIndex) {return -1;}
public int CharIndexOf(int lineIndex) {return -1;}
public int CharIndexOfFirst() {return -1;}
public int LineIndexOfFirst() {return -1;}
public int LineIndexOf(int charIndex) {return -1;}
public PointAdp PosOf(int charIndex) {return PointAdp_.Null;}
public void ScrollLineUp() {}
public void ScrollLineDown() {}
public void ExtendLineUp() {}
public void ExtendLineDown() {}
public void ScrollScreenUp() {}
public void ScrollScreenDown() {}
public void SelectionStart_toFirstChar() {}
public void ScrollTillSelectionStartIsFirstLine() {}
public void ScrollTillCaretIsVisible() {}
}
class MockComboBox extends GxwElem_mock_base implements GxwComboBox {
public void DataSource_set(Object... ary) {}
public Object SelectedItm() {return selectedItm;} public void SelectedItm_set(Object v) {this.selectedItm = v;} Object selectedItm;
}
class MockListBox extends GxwElem_mock_base implements GxwListBox {
public void Items_Add(Object item) {}
public void Items_Clear() {}
public Object Items_SelObj() {return null;}
public int Items_Count() {return -1;}
public int Items_SelIdx() {return -1;} public void Items_SelIdx_set(int v) {}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwListBox extends GxwElem {
void Items_Add(Object item);
void Items_Clear();
int Items_Count();
int Items_SelIdx(); void Items_SelIdx_set(int v);
Object Items_SelObj();
}

View File

@@ -0,0 +1,82 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
class GxwListBox_lang extends JList implements GxwListBox {
void ctor_() {
ctrlMgr = GxwCore_lang.new_(this);
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
GxwBoxListener lnr = new GxwBoxListener(this);
// this.setFocusTraversalKeysEnabled(false);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
this.setFocusable(true);
this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
}
Vector<String> internalItems = new Vector<String>();
public void Items_Add(Object item) {
internalItems.add((String)item);
this.setListData(internalItems);
this.updateUI();
}
public void Items_Clear() {internalItems.clear();}
public int Items_Count() {return internalItems.size();}
public int Items_SelIdx() {return this.getSelectedIndex();} public void Items_SelIdx_set(int v) {this.setSelectedIndex(v);}
public Object Items_SelObj() {return this.getSelectedValue();}
public Object SelectedItm() {return this.getSelectedValue();} public void SelectedItm_set(Object v) {this.setSelectedValue(v, true);}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
// need to validate, else dropDownArrow will not get redrawn in correct pos
@Override public void setBounds(Rectangle r) {super.setBounds(r); this.validate();}
@Override public void setSize(int w, int h) {super.setSize(w, h); this.validate();}
@Override public void setSize(Dimension d) {super.setSize(d); this.validate();}
public String TextVal() {return Object_.Xto_str_strict_or_empty(this.SelectedItm());} public void TextVal_set(String v) {this.SelectedItm_set(v);}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void SendMouseWheel(IptMouseWheel direction) {}
@Override public void processKeyEvent(KeyEvent e) {
if (GxwCbkHost_.ExecKeyEvent(host, e)){
super.processKeyEvent(e);
}
}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
public void EnableDoubleBuffering() { // eliminates flickering during OnPaint
}
public void CreateControlIfNeeded() {
}
public static GxwListBox_lang new_() {
GxwListBox_lang rv = new GxwListBox_lang();
rv.ctor_();
return rv;
} GxwListBox_lang() {}
}

View File

@@ -0,0 +1,216 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.text.JTextComponent;
public class GxwTextBox_lang extends JTextArea implements GxwTextFld {
public Object UnderElem() {return this;}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public int SelBgn() {return this.getSelectionStart();} public void SelBgn_set(int v) {this.setSelectionStart(v); this.setCaretPosition(v);}
public int SelLen() {return this.getSelectionEnd() - this.getSelectionStart();} public void SelLen_set(int v) {this.setSelectionEnd(this.SelBgn() + v);}
public String TextVal() {return this.getText();} public void TextVal_set(String v) {this.setText(v);}
public void AlignH_(GfuiAlign val) {} // TODO
//@#if !plat_wce
public int BorderWidth() {return borderOn ? 2 : 0;}
public boolean Border_on() {return borderOn;} boolean borderOn = true;
public void Border_on_(boolean v) {
borderOn = v;
Border border = v ? BorderFactory.createLineBorder(Color.BLACK, 1) : null;
this.setBorder(border);
}
public void Margins_set(int left, int top, int right, int bot) {}
public boolean OverrideTabKey() {return overrideTabKey;} boolean overrideTabKey;
public void OverrideTabKey_(boolean val) {
overrideTabKey = val;
if (val)
GxwTextBox_overrideKeyCmd.new_((GfuiElem)host, this, "TAB", "\t", false);
else
GxwTextBox_overrideKeyCmd.focus_((GfuiElem)host, this, "TAB");
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return this;
}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void SendMouseWheel(IptMouseWheel direction) {}
@Override public void processKeyEvent(KeyEvent e) {
if (overrideTabKey && e.getKeyCode() == KeyEvent.VK_TAB) {
super.processKeyEvent(e); return;}
if (GxwCbkHost_.ExecKeyEvent(host, e))
super.processKeyEvent(e);
}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
public GxwTextBox_lang(){ctor_();}
void ctor_() {
ctrlMgr = GxwCore_lang.new_(this);
this.setTabSize(4);
}
public void EnableDoubleBuffering() {} // eliminates flickering during OnPaint
public void CreateControlIfNeeded() {}
@gplx.Virtual public void ctor_MsTextBox_() {
ctor_();
}
}
class GxwTextFld_cls_lang extends JTextField implements GxwTextFld {
public Object UnderElem() {return this;}
public void AlignH_(GfuiAlign val) {
int align = JTextField.LEFT;
if (val.Val() == GfuiAlign_.Mid.Val()) align = JTextField.CENTER;
else if (val.Val() == GfuiAlign_.Right.Val()) align = JTextField.RIGHT;
this.setHorizontalAlignment(align);
}
public int SelBgn() {return this.getSelectionStart();}
public void SelBgn_set(int v) {
// if (v >= this.getSelectionStart() && v < this.getSelectionEnd())
try {
this.setSelectionStart(v);
} catch (Exception e) {
Exc_.Noop(e);
} // NOTE: sometimes fails when skipping ahead in dvd player; v = 0, and start/end = 0
}
public int SelLen() {return this.getSelectionEnd() - this.getSelectionStart();} public void SelLen_set(int v) {this.setSelectionEnd(this.SelBgn() + v);}
@gplx.Virtual public void ctor_MsTextBox_() {
ctor_();
}
//@#if !plat_wce
public int BorderWidth() {return borderOn ? 2 : 0;}
public boolean Border_on() {return borderOn;}
// @Override public void setBorder(Border border) {
// if (borderOn) super.setBorder(border);
// else {
// super.setBorder(null);
// }
// // NO!
// }
public void Border_on_(boolean v) {
borderOn = v;
Border border = v ? BorderFactory.createLineBorder(Color.BLACK) : null;
this.setBorder(border);
} boolean borderOn = true;
public void Margins_set(int left, int top, int right, int bot) {}
public boolean OverrideTabKey() {return overrideTabKey;}
public void OverrideTabKey_(boolean val) {
overrideTabKey = val;
GxwTextBox_overrideKeyCmd.new_((GfuiElem)host, this, "TAB", "\t", false);
} boolean overrideTabKey;
void ctor_() {
ctrlMgr = GxwCore_lang.new_(this);
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
this.Border_on_(true);
GxwBoxListener lnr = new GxwBoxListener(this);
// this.setFocusTraversalKeysEnabled(false);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return this.getText();} public void TextVal_set(String v) {
this.setText(v);
this.SelBgn_set(0); this.SelLen_set(0); // otherwise will set cursor to end; want to see text start
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, GxwElem_lang.AlignH_cmd)) AlignH_(GfuiAlign_.cast_(m.CastObj("v")));
return this;
}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void SendMouseWheel(IptMouseWheel direction) {}
@Override public void processKeyEvent(KeyEvent e) {
if (overrideTabKey && e.getKeyCode() == KeyEvent.VK_TAB) {
super.processKeyEvent(e); return;}
if (GxwCbkHost_.ExecKeyEvent(host, e))
super.processKeyEvent(e);
}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {
if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
public void EnableDoubleBuffering() { // eliminates flickering during OnPaint
}
public void CreateControlIfNeeded() {
}
}
class GxwTextBox_overrideKeyCmd extends AbstractAction {
public void actionPerformed(ActionEvent e) {
if (focus) {
int z = owner.OwnerWin().FocusMgr().SubElems().Idx_of(owner);
owner.OwnerWin().FocusMgr().Focus(focusDir, z);
return;
}
if (overrideText == null) return;
textBox.replaceSelection(overrideText);
}
public GxwTextBox_overrideKeyCmd(JTextComponent textBox, String overrideText) {this.textBox = textBox; this.overrideText = overrideText;}
public static GxwTextBox_overrideKeyCmd focus_(GfuiElem owner, JTextComponent textBox, String keyName) {return GxwTextBox_overrideKeyCmd.new_(owner, textBox, keyName, null, true);}
public static GxwTextBox_overrideKeyCmd focusPrv_(GfuiElem owner, JTextComponent textBox, String keyName) {
GxwTextBox_overrideKeyCmd rv = GxwTextBox_overrideKeyCmd.new_(owner, textBox, keyName, null, true);
rv.focusDir = false;
return rv;
}
public static GxwTextBox_overrideKeyCmd noop_(GfuiElem owner, JTextComponent textBox, String keyName) {return GxwTextBox_overrideKeyCmd.new_(owner, textBox, keyName, null, false);}
public static GxwTextBox_overrideKeyCmd new_(GfuiElem owner, JTextComponent textBox, String keyName, String overrideText, boolean focus) {
KeyStroke tabKey = KeyStroke.getKeyStroke(keyName);
GxwTextBox_overrideKeyCmd action = new GxwTextBox_overrideKeyCmd(textBox, overrideText);
action.focus = focus;
action.owner = owner;
textBox.getInputMap().remove(tabKey);
textBox.getInputMap().put(tabKey, action);
return action;
}
JTextComponent textBox; String overrideText; GfuiElem owner; boolean focus; boolean focusDir = true;
}
class GxwTextBox_lang_ {
public static GxwTextFld fld_() {
GxwTextFld_cls_lang rv = new GxwTextFld_cls_lang();
rv.ctor_MsTextBox_();
return rv;
}
public static GxwTextMemo_lang memo_() {
GxwTextMemo_lang rv = new GxwTextMemo_lang();
rv.ctor_MsTextBoxMultiline_();
return rv;
}
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwTextFld extends GxwElem {
boolean Border_on(); void Border_on_(boolean v);
int SelBgn(); void SelBgn_set(int v);
int SelLen(); void SelLen_set(int v);
void CreateControlIfNeeded();
boolean OverrideTabKey(); void OverrideTabKey_(boolean v);
void Margins_set(int left, int top, int right, int bot);
}
interface GxwTextMemo extends GxwTextFld {
int LinesPerScreen();
int LinesTotal();
int ScreenCount();
int CharIndexOf(int lineIndex);
int CharIndexOfFirst();
int LineIndexOfFirst();
int LineIndexOf(int charIndex);
PointAdp PosOf(int charIndex);
void ScrollLineUp();
void ScrollLineDown();
void ScrollScreenUp();
void ScrollScreenDown();
void SelectionStart_toFirstChar();
void ScrollTillSelectionStartIsFirstLine();
void ScrollTillCaretIsVisible();
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
interface GxwTextHtml extends GxwTextMemo {
KeyVal[] Html_sel_atrs();
void Html_enabled(boolean v);
String Html_doc_html();
void Html_css_set(String s);
}

View File

@@ -0,0 +1,253 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.core.strings.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.io.StringWriter;
import java.util.Enumeration;
import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BoxView;
import javax.swing.text.ComponentView;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.Element;
import javax.swing.text.IconView;
import javax.swing.text.LabelView;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.ParagraphView;
import javax.swing.text.PlainDocument;
import javax.swing.text.Segment;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
import javax.swing.text.html.InlineView;
import javax.swing.text.html.StyleSheet;
public class GxwTextHtml_lang extends JScrollPane implements GxwTextHtml {
@Override public GxwCore_base Core() {return core;} GxwCore_host core;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host; editor.Host_set(host);} GxwCbkHost host;
@Override public int SelBgn() {return editor.SelBgn();} @Override public void SelBgn_set(int v) {editor.SelBgn_set(v);}
@Override public int SelLen() {return editor.SelLen();} @Override public void SelLen_set(int v) {editor.SelLen_set(v);}
@Override public String TextVal() {return editor.TextVal();} @Override public void TextVal_set(String v) {editor.TextVal_set(v);}
@Override public boolean Border_on() {return false;} //boolean borderOn = true;
@Override public void Border_on_(boolean v) {
// borderOn = v;
// Border border = v ? BorderFactory.createLineBorder(Color.BLACK) : null;
// this.setBorder(border);
}
@Override public boolean OverrideTabKey() {return false;}
@Override public void OverrideTabKey_(boolean v) {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return null;}
public void Html_enabled(boolean v) {
// String newContentType = v ? "text/html" : "text/plain";
// if (!String_.Eq(editor.getContentType(), newContentType)) {
// editor = new GxwTextHtml_editor().ctor();
// core.Inner_set(editor.core);
// this.setViewportView(editor);
// }
editor.Html_enabled(v);
}
public GxwTextHtml_editor Editor() {return editor;} GxwTextHtml_editor editor;
public void ScrollTillCaretIsVisible() {throw Exc_.new_unimplemented();}
public GxwTextHtml_lang ctor() {
editor = new GxwTextHtml_editor().ctor();
core = new GxwCore_host(GxwCore_lang.new_(this), editor.core);
this.setViewportView(editor);
// this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
// this.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
this.setBorder(null);
return this;
}
public KeyVal[] Html_sel_atrs() {return editor.Html_sel_atrs();}
public String Html_doc_html() {return editor.Html_doc_html();}
public void Html_css_set(String s) {editor.Html_css_set(s);}
@Override public void Margins_set(int left, int top, int right, int bot) {}
@Override public void EnableDoubleBuffering() {}
@Override public void CreateControlIfNeeded() {}
@Override public int LinesPerScreen() {return 0;}
@Override public int LinesTotal() {return 0;}
@Override public int ScreenCount() {return 0;}
@Override public int CharIndexOf(int lineIndex) {return 0;}
@Override public int CharIndexOfFirst() {return 0;}
@Override public int LineIndexOfFirst() {return 0;}
@Override public int LineIndexOf(int charIndex) {return 0;}
@Override public PointAdp PosOf(int charIndex) {return null;}
@Override public void ScrollLineUp() {}
@Override public void ScrollLineDown() {}
@Override public void ScrollScreenUp() {}
@Override public void ScrollScreenDown() {}
@Override public void SelectionStart_toFirstChar() {}
@Override public void ScrollTillSelectionStartIsFirstLine() {}
}
class GxwTextHtml_editor extends JEditorPane implements GxwTextHtml {
public GxwTextHtml_editor ctor() {
styledKit = new StyledEditorKit();
htmlKit = new HTMLEditorKit();
this.setEditorKit(htmlKit);
// this.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); this.setFont(new Font("Courier New", 6, Font.PLAIN)); // force jeditorpane to take font
core = GxwCore_lang.new_(this);
this.setCaret(new javax.swing.text.DefaultCaret() {public void setSelectionVisible(boolean vis) {super.setSelectionVisible(true);}});// else highlighted selection will not be visible when text box loses focus
return this;
}
// public HTMLEditorKit HtmlKit() {return htmlKit;} HTMLEditorKit htmlKit;
@Override public GxwCore_base Core() {return core;} GxwCore_base core;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public int SelBgn() {return this.getSelectionStart();} @Override public void SelBgn_set(int v) {this.setSelectionStart(v); this.setCaretPosition(v);}
@Override public int SelLen() {return this.getSelectionEnd() - this.getSelectionStart();} @Override public void SelLen_set(int v) {this.setSelectionEnd(this.getSelectionStart() + v);}
@Override public String TextVal() {return this.getText();}
@Override public void TextVal_set(String v) {this.setText(v);}
@Override public boolean Border_on() {return borderOn;} boolean borderOn = true;
@Override public void Border_on_(boolean v) {
borderOn = v;
Border border = v ? BorderFactory.createLineBorder(Color.BLACK) : null;
this.setBorder(border);
}
@Override public boolean OverrideTabKey() {return false;}
@Override public void OverrideTabKey_(boolean v) {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return null;}
StyledEditorKit styledKit; HTMLEditorKit htmlKit;
public void Html_enabled(boolean v) {
// String contentType = v ? "text/html" : "text/rtf";
// this.setEditorKit(v ? new StyledEditorKit() : new DefaultEditorKit());
this.setEditorKit(v ? htmlKit : styledKit);
}
public void ScrollTillCaretIsVisible() {throw Exc_.new_unimplemented();}
public void Html_css_set(String s) {
StyleSheet styleSheet = htmlKit.getStyleSheet();
styleSheet.addRule(s);
}
public String Html_print() {
String_bldr sb = String_bldr_.new_();
sb.Add("selBgn=").Add(Int_.Xto_str(Html_sel_bgn())).Add_char_crlf();
sb.Add("selEnd=").Add(Int_.Xto_str(Html_sel_end())).Add_char_crlf();
sb.Add("selTxt=").Add(Html_sel_text()).Add_char_crlf();
KeyVal[] atrs = Html_sel_atrs();
for (int i = 0; i < atrs.length; i++) {
KeyVal atr = atrs[i];
sb.Add(atr.Key() + "=").Add(atr.Val_to_str_or_null()).Add_char_crlf();
}
return sb.XtoStr();
}
Element Html_sel_elm() {
HTMLDocument doc = (HTMLDocument)this.getDocument();
int pos = this.getCaretPosition();
return doc.getCharacterElement(pos);
}
public int Html_sel_bgn() {return Html_sel_elm().getStartOffset();}
public int Html_sel_end() {return Html_sel_elm().getEndOffset();}
// public String Html_doc_html() {
// HTMLEditorKit kit = (HTMLEditorKit)this.getEditorKit();
// HTMLDocument doc = (HTMLDocument)this.getDocument();
// StringWriter sw = new StringWriter();
// try {kit.write(sw, doc, 0, doc.getLength());}
// catch (Exception exc) {throw Err_.err_(exc, "Html_doc_html");}
// return sw.toString();
// }
public String Html_doc_html() {
Document doc = this.getDocument();
try {return this.getDocument().getText(0, doc.getLength());}
catch (Exception e) {throw Exc_.new_exc(e, "ui", "Html_doc_html");}
}
public String Html_sel_text() {
Element elm = Html_sel_elm();
int sel_bgn = elm.getStartOffset();
int sel_end = elm.getEndOffset();
try {return this.getDocument().getText(sel_bgn, sel_end - sel_bgn);}
catch (Exception e) {throw Exc_.new_exc(e, "ui", "Html_sel_text");}
}
static void Html_sel_atrs(AttributeSet atrs, List_adp list, String ownerKey, String dlm) {
if (atrs == null) return;
Enumeration<?> keys = atrs.getAttributeNames();
while (true) {
if (!keys.hasMoreElements()) break;
Object atr_key = keys.nextElement(); if (atr_key == null) break;
Object atr_val = atrs.getAttribute(atr_key);
String atr_key_str = atr_key.toString();
String itm_key = ownerKey == null ? atr_key_str : ownerKey + dlm + atr_key_str;
if (atr_val instanceof javax.swing.text.AttributeSet)
Html_sel_atrs((AttributeSet)atr_val, list, itm_key, dlm);
else
list.Add(KeyVal_.new_(itm_key, atr_val));
}
}
public KeyVal[] Html_sel_atrs() {
if (String_.Eq(this.getContentType(), "text/plain")) return KeyVal_.Ary_empty;
Element elm = Html_sel_elm(); if (elm == null) return KeyVal_.Ary_empty;
List_adp sel_atrs_list = List_adp_.new_();
Html_sel_atrs(elm.getAttributes(), sel_atrs_list, null, ".");
return (KeyVal[])sel_atrs_list.To_ary(KeyVal.class);
}
@Override public void processKeyEvent(KeyEvent e) {
// if (overrideTabKey && e.getKeyCode() == KeyEvent.VK_TAB) {
// super.processKeyEvent(e); return;}
if (GxwCbkHost_.ExecKeyEvent(host, e))
super.processKeyEvent(e);
}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g); // Reevaluate if necessary: super.paint might need to (a) always happen and (b) go before PaintCbk (had issues with drawing text on images)
}
@Override public void Margins_set(int left, int top, int right, int bot) {}
@Override public void EnableDoubleBuffering() {}
@Override public void CreateControlIfNeeded() {}
@Override public int LinesPerScreen() {return 0;}
@Override public int LinesTotal() {return 0;}
@Override public int ScreenCount() {return 0;}
@Override public int CharIndexOf(int lineIndex) {return 0;}
@Override public int CharIndexOfFirst() {return 0;}
@Override public int LineIndexOfFirst() {return 0;}
@Override public int LineIndexOf(int charIndex) {return 0;}
@Override public PointAdp PosOf(int charIndex) {return null;}
@Override public void ScrollLineUp() {}
@Override public void ScrollLineDown() {}
@Override public void ScrollScreenUp() {}
@Override public void ScrollScreenDown() {}
@Override public void SelectionStart_toFirstChar() {}
@Override public void ScrollTillSelectionStartIsFirstLine() {}
}

View File

@@ -0,0 +1,335 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.AWTKeyStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.util.HashSet;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.Document;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
public class GxwTextMemo_lang extends JScrollPane implements GxwTextMemo {
public JTextArea Inner() {return txt_box;} GxwTextBox_lang txt_box;
public GxwCore_base Core() {return core;} GxwCore_base core;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host; txt_box.Host_set(host);} GxwCbkHost host;
@Override public void setBackground(Color c) {
if (txt_box == null) return; // WORKAROUND.OSX: OSX LookAndFeel calls setBackground during ctor of Mem_html; DATE:2015-05-11
if (c.getRGB() == Color.BLACK.getRGB()) txt_box.setCaretColor(Color.WHITE);
else if (c.getRGB() == Color.WHITE.getRGB()) txt_box.setCaretColor(Color.BLACK);
super.setBackground(c);
}
public void ScrollTillCaretIsVisible() {throw Exc_.new_unimplemented();}
public void Margins_set(int left, int top, int right, int bot) {
if (left == 0 && right == 0) {
txt_box.setBorder(BorderFactory.createLineBorder(Color.BLACK));
txt_box.setMargin(new Insets(0, 0, 0,0));
}
else {
// txt_box.setBorder(BasicBorders.getTextFieldBorder());
// txt_box.setMargin(new Insets(0, l, 0, r));
txt_box.setFont(new Font("Courier New", FontStyleAdp_.Plain.val, 12));
txt_box.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(top, left, bot, right)));
}
}
public void ctor_MsTextBoxMultiline_() {
txt_box = new GxwTextBox_lang();
txt_box.ctor_MsTextBox_();
core = new GxwCore_host(GxwCore_lang.new_(this), txt_box.ctrlMgr);
this.setViewportView(txt_box);
txt_box.setLineWrap(true);
txt_box.setWrapStyleWord(true); // else text will wrap in middle of words
this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
this.setBorder(null);
txt_box.setBorder(BorderFactory.createLineBorder(Color.BLACK));
txt_box.setCaretColor(Color.BLACK);
txt_box.getCaret().setBlinkRate(0);
txt_box.setMargin(new Insets(0, 200, 200,0));
OverrideKeyBindings();
InitUndoMgr();
txt_box.setCaret(new javax.swing.text.DefaultCaret() {public void setSelectionVisible(boolean vis) {super.setSelectionVisible(true);}});// else highlighted selection will not be visible when text box loses focus
// this.setLayout(null);
// Object fontDefinition = new UIDefaults.ProxyLazyValue("javax.swing.plaf.FontUIResource", null, new Object[] { "dialog", new Integer(Font.PLAIN), new Integer(12) });
// java.util.Enumeration keys = UIManager.getDefaults().keys();
// while (keys.hasMoreElements()) {
// Object key = keys.nextElement();
// Object value = UIManager.get(key);
// if (value instanceof javax.swing.plaf.FontUIResource) {
// UIManager.put(key, fontDefinition);
// }
// }
} @gplx.Internal protected GxwTextMemo_lang() {}
void InitUndoMgr() {
final UndoManager undo = new UndoManager();
Document doc = txt_box.getDocument();
// Listen for undo and redo events
doc.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent evt) {
undo.addEdit(evt.getEdit());
}
});
// Create an undo action and add it to the text component
txt_box.getActionMap().put("Undo",
new AbstractAction("Undo") {
public void actionPerformed(ActionEvent evt) {
try {
if (undo.canUndo()) {
undo.undo();
}
} catch (CannotUndoException e) {
}
}
});
// Bind the undo action to ctl-Z
txt_box.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");
// Create a redo action and add it to the text component
txt_box.getActionMap().put("Redo",
new AbstractAction("Redo") {
public void actionPerformed(ActionEvent evt) {
try {
if (undo.canRedo()) {
undo.redo();
}
} catch (CannotRedoException e) {
}
}
});
// Bind the redo action to ctl-Y
txt_box.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo");
}
void OverrideKeyBindings() {
Set<AWTKeyStroke> forTraSet = new HashSet<AWTKeyStroke> ();
txt_box.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forTraSet);
txt_box.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, forTraSet);
GxwTextBox_overrideKeyCmd.noop_((GfuiElem)host, txt_box, "control H"); // else ctrl+h deletes current char
// GxwTextBox_overrideKeyCmd.new_(txt_box, "ENTER", Env_.NewLine); // else enter will always use \n on window; jtextBox allows separation of \r from \n
}
public void AlignH_(GfuiAlign val) {
// can't work with jtextArea
// if (val.Val() == GfuiAlign_.Mid.Val())
// txt_box.setAlignmentY(JTextArea.CENTER_ALIGNMENT);
}
public int LinesPerScreen() {return LinesPerScreen(this);}
public int LinesTotal() {
return 40;
// return this.getStyledDocument(). .getLineCount();
}
public int ScreenCount() {return Int_.DivAndRoundUp(this.LinesTotal(), this.LinesPerScreen());}
public int LineLength(int lineIndex) {return LineLength(this, lineIndex);}
public int CharIndexOfFirst() {
int firstLineIndex = LineIndexOfFirst();
return CharIndexOf(firstLineIndex);
}
public int CharIndexOf(int lineIndex) {
return lineIndex;
// try {return this.getLineStartOffset(lineIndex);}
// catch (BadLocationException e) {return -1;}
}
public int LineIndexOfFirst() {
// this.getl
return 0; //todo
// return TextBoxNpi.LineIndexFirst(ControlNpi.Hwnd(this));
}
public int LineIndexOf(int charIndex) {
return charIndex;
// try {return this.getLineOfOffset(charIndex);}
// catch (BadLocationException e) {return -1;}
}
public PointAdp PosOf(int charIndex) {
// Document d = this.getDocument();
// Element e = d.getDefaultRootElement();
// e.
return PointAdp_.Zero; //todo
// PointAdp point = TextBoxNpi.PosOf(ControlNpi.Hwnd(this), charIndex);
// return (point.Eq(TextBoxNpi.InvalidPoint))
// ? TextBoxNpi.InvalidPoint
// : PointAdp_.XtoPointAdp(this.PointToScreen(point.XtoPoint()));
}
public void SelectionStart_toFirstChar() {
// scrollPane.s
// JScrollPane scrollingResult = new JScrollPane(this);
// scrollingResult.
//todo
// this.SelectionStart = this.CharIndexOfFirst();
}
public void ScrollLineUp() {
// ScrollWindow(TextBoxScrollTypes.LineUp);
}
public void ScrollLineDown() {
// ScrollWindow(TextBoxScrollTypes.LineDown);
}
// public void ExtendLineUp() {int l = this.SelectionStart; ScrollWindow(TextBoxScrollTypes.LineUp); int m = this.SelectionStart; this.SelectionStart = l; this.SelectionLength = m - l;}
// public void ExtendLineDown() {int l = this.SelectionStart; ScrollWindow(TextBoxScrollTypes.LineDown); int m = this.SelectionStart; this.SelectionStart = l; this.SelectionLength = m - l;}
public void ScrollScreenUp() {
// ScrollWindow(TextBoxScrollTypes.PageUp);
}
public void ScrollScreenDown() {
// ScrollWindow(TextBoxScrollTypes.PageDown);
}
public void ScrollTillSelectionStartIsFirstLine() {
// this.Visible = false;
// this.ScrollToCaret();
// int currentLine = TextBoxNpi.LineIndex(ControlNpi.Hwnd(this), this.SelectionStart);
// int lineCount = this.LinesPerScreen();
// int previousFirstLine = -1;
// do {
// int firstLine = TextBoxNpi.LineIndexFirst(ControlNpi.Hwnd(this));
// if (firstLine == previousFirstLine) break; // NOTE: avoid infinite loop
//
// if (firstLine - currentLine > lineCount)
// this.ScrollScreenUp();
// else if (currentLine - firstLine > lineCount)
// this.ScrollScreenDown();
// else if (currentLine < firstLine)
// this.ScrollLineUp();
// else if (currentLine > firstLine)
// this.ScrollLineDown();
// else
// break;
// previousFirstLine = firstLine;
// } while (true);
// this.Visible = true;
// GfuiEnv_.DoEvents(); // WORKAROUND (WCE): needed to repaint screen
// this.Parent.Focus();
}
// void ScrollWindow(TextBoxScrollTypes scrollType) {TextBoxNpi.ScrollWindow(ControlNpi.Hwnd(this), scrollType);}
public static int LinesPerScreen(GxwTextMemo_lang textBox) {
return 50;
// int lineIndexLine0 = textBox.LineIndexOfFirst();
// int charIndexLine0 = textBox.CharIndexOf(lineIndexLine0);
// PointAdp posLine0 = textBox.PosOf(charIndexLine0);
// int charIndexLine1 = textBox.CharIndexOf(lineIndexLine0 + 1);
// PointAdp posLine1 = textBox.PosOf(charIndexLine1);
//
// int availHeight = textBox.Height - (2 * textBox.BorderWidth());
// int lineHeight = (posLine1.Eq(TextBoxNpi.InvalidPoint)) // TextBox is sized for one line, or textBox.Text = ""
// ? availHeight
// : posLine1.Y() - posLine0.Y();
// int rv = availHeight / lineHeight;
// return rv == 0 ? 1 : rv; // always return at least 1 line
}
public static int LineLength(GxwTextMemo_lang textBox, int lineIndex) {
return -1;
// int lineLength = TextBoxNpi.LineLength(ControlNpi.Hwnd(textBox), lineIndex);
//
// // WORKAROUND (TextBox): TextBoxNpi.LineLength ignores String_.NewLine; manually check for NewLine
// int newLineLength = String_.NewLine.length;
// String text = textBox.Text;
// int charIndexFirst = textBox.CharIndexOf(lineIndex);
// int charIndexLastAccordingToApi = charIndexFirst + lineLength;
// if (charIndexLastAccordingToApi + newLineLength > text.length) return lineLength; // last line of text; no ignored line possible
// String charactersPastEndOfLine = text.Substring(charIndexLastAccordingToApi, newLineLength);
// return charactersPastEndOfLine == String_.NewLine ? lineLength + newLineLength : lineLength;
}
public boolean Border_on() {return txt_box.Border_on();} public void Border_on_(boolean v) {txt_box.Border_on_(v);}
public void CreateControlIfNeeded() {txt_box.CreateControlIfNeeded();}
public boolean OverrideTabKey() {return txt_box.OverrideTabKey();}
public void OverrideTabKey_(boolean v) {
txt_box.OverrideTabKey_(v);
if (v) {
Set<AWTKeyStroke> forTraSet = new HashSet<AWTKeyStroke> ();
txt_box.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forTraSet);
txt_box.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, forTraSet);
}
else {
Set<AWTKeyStroke> forTraSet = new HashSet<AWTKeyStroke> ();
txt_box.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forTraSet);
txt_box.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, forTraSet);
GxwTextBox_overrideKeyCmd.focus_((GfuiElem)host, txt_box, "TAB"); // else ctrl+h deletes current char
GxwTextBox_overrideKeyCmd.focusPrv_((GfuiElem)host, txt_box, "shift TAB"); // else ctrl+h deletes current char
// Set<AWTKeyStroke> forTraSet = new HashSet<AWTKeyStroke> ();
// forTraSet.add(AWTKeyStroke.getAWTKeyStroke("TAB"));
// Set<AWTKeyStroke> bwdTraSet = new HashSet<AWTKeyStroke> ();
// bwdTraSet.add(AWTKeyStroke.getAWTKeyStroke("control TAB"));
// txt_box.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forTraSet);
// txt_box.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, bwdTraSet);
// txt_box.OverrideTabKey_(false);
}
}
public int SelBgn() {return txt_box.SelBgn();} public void SelBgn_set(int v) {txt_box.SelBgn_set(v);}
public int SelLen() {return txt_box.SelLen();} public void SelLen_set(int v) {txt_box.SelLen_set(v);}
public void EnableDoubleBuffering() {txt_box.EnableDoubleBuffering();}
public void SendKeyDown(IptKey key) {txt_box.SendKeyDown(key);}
public String TextVal() {return txt_box.TextVal();}
public void TextVal_set(String v) {
txt_box.TextVal_set(v);
txt_box.setSelectionStart(0); txt_box.setSelectionEnd(0); // else selects whole text and scrolls to end of selection
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, GxwElem_lang.AlignH_cmd)) AlignH_(GfuiAlign_.cast_(m.CastObj("v")));
return txt_box.Invk(ctx, ikey, k, m);
}
}
class GxwCore_host extends GxwCore_base {
@Override public void Controls_add(GxwElem sub){outer.Controls_add(sub);}
@Override public void Controls_del(GxwElem sub){outer.Controls_del(sub);}
@Override public int Width(){return outer.Width();} @Override public void Width_set(int v){outer.Width_set(v); inner.Width_set(v);}
@Override public int Height(){return outer.Height();} @Override public void Height_set(int v){outer.Height_set(v); inner.Height_set(v);}
@Override public int X(){return outer.X();} @Override public void X_set(int v){outer.X_set(v);} // NOTE: noop inner.x
@Override public int Y(){return outer.Y();} @Override public void Y_set(int v){outer.Y_set(v);} // NOTE: noop inner.y
@Override public SizeAdp Size(){return outer.Size();} @Override public void Size_set(SizeAdp v){outer.Size_set(v); inner.Size_set(v);}
@Override public PointAdp Pos(){return outer.Pos();} @Override public void Pos_set(PointAdp v){outer.Pos_set(v);} // NOTE: noop inner.pos
@Override public RectAdp Rect(){return outer.Rect();} @Override public void Rect_set(RectAdp v){outer.Rect_set(v); inner.Size_set(v.Size());} // NOTE: noop inner.pos
@Override public boolean Visible(){return outer.Visible();} @Override public void Visible_set(boolean v){outer.Visible_set(v); inner.Visible_set(v);}
@Override public ColorAdp BackColor(){return outer.BackColor();} @Override public void BackColor_set(ColorAdp v){outer.BackColor_set(v); inner.BackColor_set(v);}
@Override public ColorAdp ForeColor(){return outer.ForeColor();} @Override public void ForeColor_set(ColorAdp v){outer.ForeColor_set(v); inner.ForeColor_set(v);}
@Override public FontAdp TextFont(){return outer.TextFont();} @Override public void TextFont_set(FontAdp v){outer.TextFont_set(v); inner.TextFont_set(v);}
@Override public String TipText() {return tipText;} @Override public void TipText_set(String v) {tipText = v;} String tipText;
public Object Reapply() {
TextFont_set(outer.TextFont()); return this;} // HACK:
@Override public int Focus_index(){return inner.Focus_index();} @Override public void Focus_index_set(int v){outer.Focus_index_set(v); inner.Focus_index_set(v);}
@Override public boolean Focus_able(){return inner.Focus_able();} @Override public void Focus_able_(boolean v){outer.Focus_able_(v); inner.Focus_able_(v);}
// @Override public void Focus_able_force_(boolean v){outer.Focus_able_force_(v); inner.Focus_able_force_(v);}
@Override public boolean Focus_has(){return inner.Focus_has();}
@Override public void Focus(){
inner.Focus();
}
@Override public void Select_exec(){
inner.Select_exec();
}
@Override public void Zorder_front(){outer.Zorder_front();} @Override public void Zorder_back(){outer.Zorder_back();}
@Override public void Invalidate(){outer.Invalidate();
inner.Invalidate();}
@Override public void Dispose(){outer.Dispose();}
GxwCore_base outer; GxwCore_base inner;
public void Inner_set(GxwCore_base v) {inner = v;}
public GxwCore_host(GxwCore_base outer, GxwCore_base inner) {this.outer = outer; this.inner = inner;}
}

View File

@@ -0,0 +1,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface GxwWin extends GxwElem {
IconAdp IconWin(); void IconWin_set(IconAdp v);
void ShowWin();
void HideWin();
boolean Maximized(); void Maximized_(boolean v);
boolean Minimized(); void Minimized_(boolean v);
void CloseWin();
boolean Pin(); void Pin_set(boolean val);
void OpenedCmd_set(GfoInvkAbleCmd v);
void TaskbarVisible_set(boolean val);
void TaskbarParkingWindowFix(GxwElem form);
}

View File

@@ -0,0 +1,271 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JWindow;
import org.eclipse.swt.widgets.Display;
import java.awt.AWTEvent;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class GxwWin_lang extends JFrame implements GxwWin, WindowListener {
public void ShowWin() {this.setVisible(true);}
public void HideWin() {this.setVisible(false);}
public boolean Minimized() {return this.getState() == Frame.ICONIFIED;} public void Minimized_(boolean v) {this.setState(v ? Frame.ICONIFIED : Frame.NORMAL);}
public boolean Maximized() {return this.getState() == Frame.MAXIMIZED_BOTH;} public void Maximized_(boolean v) {this.setState(v ? Frame.MAXIMIZED_BOTH : Frame.NORMAL);}
public void CloseWin() {this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.dispose();}
public boolean Pin() {return pin;}
public void Pin_set(boolean val) {
this.setAlwaysOnTop(val); pin = val;} boolean pin = false;
public IconAdp IconWin() {return icon;} IconAdp icon;
public void IconWin_set(IconAdp i) {
if (i == null) return;
icon = i;
this.setIconImage(i.XtoImage());
}
public void OpenedCmd_set(GfoInvkAbleCmd v) {whenLoadedCmd = v;} GfoInvkAbleCmd whenLoadedCmd = GfoInvkAbleCmd.Null;
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return this.getTitle();} public void TextVal_set(String v) {this.setTitle(v);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {host.DisposeCbk();}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {host.SizeChangedCbk();}
public void windowIconified(WindowEvent e) {host.SizeChangedCbk();}
public void windowOpened(WindowEvent e) {whenLoadedCmd.Invk();}
@Override public void processKeyEvent(KeyEvent e) {if (GxwCbkHost_.ExecKeyEvent(host, e)) super.processKeyEvent(e);}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g);
}
public void EnableDoubleBuffering() {}
public void TaskbarVisible_set(boolean val) {} public void TaskbarParkingWindowFix(GxwElem form) {}
public static GxwWin_lang new_() {
GxwWin_lang rv = new GxwWin_lang();
rv.ctor_GxwForm();
return rv;
} GxwWin_lang() {}
void ctor_GxwForm() {
ctrlMgr = GxwCore_form.new_(this);
this.setLayout(null); // use gfui layout
this.ctrlMgr.BackColor_set(ColorAdp_.White); // default form backColor to white
this.setUndecorated(true); // remove icon, titleBar, minimize, maximize, close, border
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // JAVA: cannot cancel alt+f4; set Close to noop, and manually control closing by calling this.CloseForm
enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
this.addWindowListener(this);
GxwBoxListener lnr = new GxwBoxListener(this);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
}
}
class GxwWin_jdialog extends JDialog implements GxwWin, WindowListener {
public void ShowWin() {this.setVisible(true);}
public void HideWin() {this.setVisible(false);}
public void CloseWin() {this.dispose();}//this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.dispose();
public boolean Maximized() {return false;} public void Maximized_(boolean v) {}
public boolean Minimized() {return false;} public void Minimized_(boolean v) {} //this.setState(Frame.ICONIFIED);
public boolean Pin() {return pin;} public void Pin_set(boolean val) {
this.setAlwaysOnTop(val); pin = val;} boolean pin = false;
public IconAdp IconWin() {return icon;} IconAdp icon;
public void IconWin_set(IconAdp i) {
if (i == null) return;
icon = i;
this.setIconImage(i.XtoImage());
}
public void OpenedCmd_set(GfoInvkAbleCmd v) {whenLoadedCmd = v;} GfoInvkAbleCmd whenLoadedCmd = GfoInvkAbleCmd.Null;
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return "";} public void TextVal_set(String v) {}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {host.DisposeCbk();}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {host.SizeChangedCbk();}
public void windowIconified(WindowEvent e) {host.SizeChangedCbk();}
public void windowOpened(WindowEvent e) {whenLoadedCmd.Invk();}
@Override public void processKeyEvent(KeyEvent e) {if (GxwCbkHost_.ExecKeyEvent(host, e)) super.processKeyEvent(e);}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g);
}
public void EnableDoubleBuffering() {}
public void TaskbarVisible_set(boolean val) {} public void TaskbarParkingWindowFix(GxwElem form) {}
public static GxwWin new_(GxwWin owner) {
Window ownerWindow = owner instanceof Window ? (Window)owner : null;
GxwWin_jdialog rv = new GxwWin_jdialog(ownerWindow);
rv.ctor_GxwForm();
return rv;
} GxwWin_jdialog(Window owner) {super(owner);}
void ctor_GxwForm() {
ctrlMgr = GxwCore_form.new_(this);
this.setLayout(null); // use gfui layout
this.ctrlMgr.BackColor_set(ColorAdp_.White); // default form backColor to white
this.setUndecorated(true); // remove icon, titleBar, minimize, maximize, close, border
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // JAVA: cannot cancel alt+f4; set CloseOp to noop, and manually control closing by calling this.CloseForm
enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
this.addWindowListener(this);
GxwBoxListener lnr = new GxwBoxListener(this);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
}
}
class GxwWin_jwindow extends JWindow implements GxwWin, WindowListener {
public void ShowWin() {this.setVisible(true);}
public void HideWin() {this.setVisible(false);}
public void CloseWin() {} //this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.dispose();
public boolean Maximized() {return false;} public void Maximized_(boolean v) {}
public boolean Minimized() {return false;} public void Minimized_(boolean v) {}
public boolean Pin() {return pin;} public void Pin_set(boolean val) {this.setAlwaysOnTop(val); pin = val;} boolean pin = false;
public IconAdp IconWin() {return icon;} IconAdp icon;
public void IconWin_set(IconAdp i) {
if (i == null) return;
icon = i;
this.setIconImage(i.XtoImage());
}
public void OpenedCmd_set(GfoInvkAbleCmd v) {whenLoadedCmd = v;} GfoInvkAbleCmd whenLoadedCmd = GfoInvkAbleCmd.Null;
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return "";} public void TextVal_set(String v) {}// this.setTitle(v);
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e) {host.DisposeCbk();}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {host.SizeChangedCbk();}
public void windowIconified(WindowEvent e) {host.SizeChangedCbk();}
public void windowOpened(WindowEvent e) {whenLoadedCmd.Invk();}
@Override public void processKeyEvent(KeyEvent e) {if (GxwCbkHost_.ExecKeyEvent(host, e)) super.processKeyEvent(e);}
@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
@Override public void paint(Graphics g) {
if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
super.paint(g);
}
public void EnableDoubleBuffering() {}
public void TaskbarVisible_set(boolean val) {} public void TaskbarParkingWindowFix(GxwElem form) {}
public static GxwWin new_(GxwWin owner) {
// Window ownerWindow = owner instanceof Window ? (Window)owner : null;
// GxwWin_jwindow rv = new GxwWin_jwindow((Window)owner);
GxwWin_jwindow rv = new GxwWin_jwindow();
rv.ctor_GxwForm();
// rv.setUndecorated(true);
return rv;
} GxwWin_jwindow(Window owner) {super(owner);}
GxwWin_jwindow() {}
public static GxwWin owner_(GxwWin owner) {
GxwWin_jwindow rv = new GxwWin_jwindow((Window)owner);
rv.setFocusable(true);
rv.setFocusableWindowState(true);
rv.ctor_GxwForm();
return rv;
}
public void ctor_GxwForm() {
ctrlMgr = GxwCore_form.new_(this);
this.setLayout(null); // use gfui layout
this.ctrlMgr.BackColor_set(ColorAdp_.White); // default form backColor to white
// this.setUndecorated(true); // remove icon, titleBar, minimize, maximize, close, border
// this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // JAVA: cannot cancel alt+f4; set CloseOp to noop, and manually control closing by calling this.CloseForm
enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
this.addWindowListener(this);
GxwBoxListener lnr = new GxwBoxListener(this);
this.addComponentListener(lnr);
this.addFocusListener(lnr);
}
}
class GxwCore_form extends GxwCore_lang {
@Override public void Zorder_front() {
Window frame = (Window)this.control;
frame.toFront();
}
@Override public void Zorder_back() {
Window frame = (Window)this.control;
frame.toBack();
}
public static GxwCore_form new_(Component control) {
GxwCore_form rv = new GxwCore_form();
rv.control = control;
return rv;
} GxwCore_form() {}
}
class GxwElemFactory_swt extends GxwElemFactory_base {
public GxwElemFactory_swt(org.eclipse.swt.widgets.Display display) {
this.display = display;
} Display display;
@gplx.Internal @Override protected GxwElem control_() {return null;}
@gplx.Internal @Override protected GxwWin win_app_() {
return new Swt_win(display);
}
@gplx.Internal @Override protected GxwWin win_tool_(KeyValHash ctorArgs) {
return null;
}
@gplx.Internal @Override protected GxwWin win_toaster_(KeyValHash ctorArgs) {
return null;
}
@gplx.Internal @Override protected GxwElem lbl_() {return null;}
@gplx.Internal @Override protected GxwTextFld text_fld_() {return null;}
@gplx.Internal @Override protected GxwTextFld text_memo_() {return null;}
@gplx.Internal @Override protected GxwTextHtml text_html_() {return null;}
@gplx.Internal @Override protected GxwCheckListBox checkListBox_(KeyValHash ctorArgs) {throw Exc_.new_unimplemented();}
@gplx.Internal @Override protected GxwComboBox comboBox_() {return null;}
@gplx.Internal @Override protected GxwListBox listBox_() {return null;}
}
//#}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface Gxw_html extends GxwElem {
void Html_doc_html_load_by_mem(String html);
void Html_doc_html_load_by_url(String path, String html);
byte Html_doc_html_load_tid(); void Html_doc_html_load_tid_(byte v);
void Html_js_enabled_(boolean v);
String Html_js_eval_proc_as_str (String name, Object... args);
boolean Html_js_eval_proc_as_bool (String name, Object... args);
String Html_js_eval_script (String script);
void Html_js_cbks_add (String js_func_name, GfoInvkAble invk);
void Html_invk_src_(GfoEvObj v);
void Html_dispose();
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class Gxw_html_load_tid_ {
public static final byte Tid_mem = 0, Tid_url = 1;
public static final String Key_mem = "mem", Key_url = "url";
public static String Xto_key(byte v) {
switch (v) {
case Tid_mem: return Key_mem;
case Tid_url: return Key_url;
default: throw Exc_.new_unimplemented();
}
}
public static byte Xto_tid(String s) {
if (String_.Eq(s, Key_mem)) return Tid_mem;
else if (String_.Eq(s, Key_url)) return Tid_url;
else throw Exc_.new_unimplemented();
}
public static KeyVal[] Options__list = KeyVal_.Ary(KeyVal_.new_(Key_mem), KeyVal_.new_(Key_url));
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public interface Gxw_tab_itm extends GxwElem {
void Subs_add(GfuiElem sub);
Gfui_tab_itm_data Tab_data();
String Tab_name(); void Tab_name_(String v);
String Tab_tip_text(); void Tab_tip_text_(String v);
}

Some files were not shown because too many files have changed in this diff Show More