1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Embeddable: Create core dbs in proper subdirectory

This commit is contained in:
gnosygnu
2017-10-23 20:50:50 -04:00
parent 1336d44f34
commit 66877212bf
4537 changed files with 311750 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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,21 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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,61 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
import gplx.core.interfaces.*;
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 Err_.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_.Min_value;
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 Err_.new_unhandled(posEnm);
if (rv < 0) rv = 0;
return rv;
}
}

View File

@@ -0,0 +1,23 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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,56 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
import gplx.core.bits.*;
public class GfuiBorderEdge {
public int Val() {return val;} int val;
public boolean Has(GfuiBorderEdge comp) {return Bitmask_.Has_int(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 To_str(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 Err_.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 Err_.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,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
public class PointAdp implements To_str_able {
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);}
public PointAdp Op_add(int xv, int yv) {return new PointAdp(x + xv, y + yv);}
public 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 To_str() {return String_.Concat_any(x, ",", y);}
@Override public String toString() {return To_str();}
@Override public boolean equals(Object obj) {return Eq(obj);}
@Override public int hashCode() {return super.hashCode();}
public PointAdp(int x, int y) {this.x = x; this.y = y;}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
public class PointAdp_ {
public static final PointAdp Null = new PointAdp(Int_.Min_value, Int_.Min_value);
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 Err_.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 Err_.new_parse_exc(exc, PointAdp.class, raw);}
}
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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);}
public RectAdp(PointAdp pos, SizeAdp size) {this.pos = pos; this.size = size;}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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_.Min_value, Int_.Min_value, Int_.Min_value, Int_.Min_value);
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,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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 Err_.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,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
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);}
public SizeAdp Op_add(SizeAdp s) {return SizeAdp_.new_(width + s.width, height + s.height);}
public SizeAdp Op_subtract(int val) {return SizeAdp_.new_(width - val, height - val);}
public SizeAdp Op_subtract(int w, int h) {return SizeAdp_.new_(width - w, height - h);}
public String To_str() {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 To_str();}
@Override public boolean equals(Object obj) {return Eq(obj);}
@Override public int hashCode() {return super.hashCode();}
public SizeAdp(int width, int height) {this.width = width; this.height = height;}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
import gplx.core.interfaces.*;
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,32 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
public class SizeAdpF_ {
public static final SizeAdpF Null = new_(Int_.Min_value, Int_.Min_value);
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 Err_.new_wo_type("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 Err_.new_parse_exc(e, SizeAdpF.class, s);}
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui; import gplx.*;
public class SizeAdp_ {
public static final SizeAdp Null = new SizeAdp(Int_.Min_value, Int_.Min_value);
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 Err_.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_.Min_value); if (w == Int_.Min_value) return or;
int h = Int_.Parse_or(ary[1], Int_.Min_value); if (h == Int_.Min_value) 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

@@ -13,3 +13,56 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls; import gplx.*; import gplx.gfui.*;
import gplx.gfui.draws.*; import gplx.gfui.gfxs.*;
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 Err_.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 To_str() {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).To_str();}
@Override public String toString() {return To_str();}
public static GfuiBorderMgr new_() {return new GfuiBorderMgr();} GfuiBorderMgr() {}
}

View File

@@ -13,3 +13,39 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls; import gplx.*; import gplx.gfui.*;
import org.junit.*; import gplx.gfui.draws.*; import gplx.gfui.imgs.*;
public class GfuiBorderMgr_tst {
@Before public void setup() {
borderMgr = GfuiBorderMgr.new_();
}
@Test public void NullToEdge() { // all null -> one edge
tst_Eq(borderMgr, null, null, null, null, null);
borderMgr.Top_(red);
tst_Eq(borderMgr, null, red, null, null, null);
}
@Test public void EdgeToAll() { // one edge -> all edge
borderMgr.Top_(red);
tst_Eq(borderMgr, null, red, null, null, null);
borderMgr.All_(black);
tst_Eq(borderMgr, black, null, null, null, null);
}
@Test public void AllToEdge() { // all edge -> one new; three old
borderMgr.All_(red);
tst_Eq(borderMgr, red, null, null, null, null);
borderMgr.Top_(black);
tst_Eq(borderMgr, null, black, red, red, red);
}
void tst_Eq(GfuiBorderMgr borderMgr, PenAdp all, PenAdp top, PenAdp left, PenAdp right, PenAdp bottom) {
Tfds.Eq(borderMgr.All(), all);
Tfds.Eq(borderMgr.Top(), top);
Tfds.Eq(borderMgr.Left(), left);
Tfds.Eq(borderMgr.Right(), right);
Tfds.Eq(borderMgr.Bot(), bottom);
}
GfuiBorderMgr borderMgr;
PenAdp black = PenAdp_.black_(), red = PenAdp_.new_(ColorAdp_.Red, 1);
}

View File

@@ -13,3 +13,38 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.interfaces.*; import gplx.gfui.controls.elems.*;
public class DataBndr_whenEvt_execCmd implements InjectAble, Gfo_invk, Gfo_evt_itm {
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public DataBndr_whenEvt_execCmd WhenArg_(String v) {whenArg = v; return this;} private String whenArg = "v";
public DataBndr_whenEvt_execCmd WhenEvt_(Gfo_evt_itm whenSrc, String whenEvt) {
this.whenEvt = whenEvt;
Gfo_evt_mgr_.Sub_same(whenSrc, whenEvt, this);
return this;
}
public DataBndr_whenEvt_execCmd GetCmd_(Gfo_invk getInvk, String getCmd) {
this.getInvk = getInvk;
this.getCmd = getCmd;
return this;
} Gfo_invk getInvk; String getCmd;
public void Inject(Object owner) {
setInvk = (Gfo_invk)owner;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, whenEvt)) {
Object evtVal = m.CastObjOr(whenArg, "");
Object getVal = getInvk.Invk(GfsCtx.Instance, 0, getCmd, GfoMsg_.new_cast_(getCmd).Add("v", evtVal));
GfoMsg setMsg = GfoMsg_.new_cast_(setCmd).Add("v", Object_.Xto_str_strict_or_empty(getVal));
setInvk.Invk(GfsCtx.Instance, 0, setCmd, setMsg);
return Gfo_invk_.Rv_handled;
}
else return Gfo_invk_.Rv_unhandled;
}
String whenEvt, setCmd; Gfo_invk setInvk;
public static DataBndr_whenEvt_execCmd text_() {
DataBndr_whenEvt_execCmd rv = new DataBndr_whenEvt_execCmd();
rv.setCmd = GfuiElemKeys.Text_set;
return rv;
}
}

View File

@@ -13,3 +13,42 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.envs.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
public class GfuiBnd_box_status implements Gfo_invk, UsrMsgWkr {
public GfuiElem Box() {return box;} GfuiElem box;
public void ExecUsrMsg(int type, UsrMsg umsg) {
box.Invoke(Gfo_invk_cmd.New_by_val(this, WriteText_cmd, umsg.To_str()));
}
public void WriteText(String text) {
GfuiElem lastFocus = GfuiFocusMgr.Instance.FocusedElem(); // HACK:WINFORMS:.Visible=true will automatically transfer focus to textBox; force Focus back to original
box.Text_(text);
GfuiWin ownerWin = box.OwnerWin();
if (ownerWin != null && !ownerWin.Visible()) {
ownerWin.Visible_set(true);
ownerWin.Zorder_front();
}
timer.Enabled_off(); timer.Enabled_on(); // reset time
GfuiEnv_.DoEvents(); // WORKAROUND:WIN32: needed, else text will not refresh (ex: splash screen); will cause other timers to fire! (ex: mediaPlaylistMgr)
if (lastFocus != null) lastFocus.Focus();
}
public void HideWin() {
if (box.OwnerWin() != null)
box.OwnerWin().Visible_off_();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, WriteText_cmd)) WriteText(m.ReadStr("v"));
else if (ctx.Match(k, TimerTick_evt)) HideWin();
return this;
} static final String TimerTick_evt = "TimerTick", WriteText_cmd = "WriteText";
TimerAdp timer;
public static GfuiBnd_box_status new_(String key) {
GfuiBnd_box_status rv = new GfuiBnd_box_status();
GfuiTextBox txtBox = GfuiTextBox_.new_();
txtBox.Key_of_GfuiElem_(key);
txtBox.BackColor_(ColorAdp_.Black).ForeColor_(ColorAdp_.Green).TextAlignH_right_();
rv.box = txtBox;
rv.timer = TimerAdp.new_(rv, TimerTick_evt, 2000, false);
return rv;
}
}

View File

@@ -13,3 +13,28 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.lists.*;
import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiCheckListBox extends GfuiElemBase {
public void Items_reverse() {checkListBox.Items_reverse();}
public void Items_count() {checkListBox.Items_count();}
public void Items_setAt(int i, boolean v) {checkListBox.Items_setCheckedAt(i, v);}
public void Items_setAll(boolean v) {checkListBox.Items_setAll(v);}
public void Items_clear() {checkListBox.Items_clear();}
public void Items_add(Object item, boolean v) {checkListBox.Items_add(item, v);}
public List_adp Items_getAll() {return checkListBox.Items_getAll();}
public List_adp Items_getChecked() {return checkListBox.Items_getChecked();}
GxwCheckListBox checkListBox;
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return new GxwCheckListBox_lang();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.checkListBox = (GxwCheckListBox)UnderElem();
}
public static GfuiCheckListBox new_() {
GfuiCheckListBox rv = new GfuiCheckListBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
}

View File

@@ -13,3 +13,47 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.layouts.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
public class GfuiCheckListPanel extends GfuiElemBase {
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
InitToggleWidget();
InitReverseWidget();
InitListBoxWidget();
this.Lyt_activate();
this.Lyt().Bands_add(GftBand.new_().Cell_abs_(60));
this.Lyt().Bands_add(GftBand.new_().Cell_abs_(70));
this.Lyt().Bands_add(GftBand.fillAll_());
}
public void Items_clear() {listBox.Items_clear();}
public void Items_add(Object item, boolean checkBoxState) {listBox.Items_add(item, checkBoxState);}
public List_adp Items_getAll() {return listBox.Items_getAll();}
public List_adp Items_getChecked() {return listBox.Items_getChecked();}
public void SetAllCheckStates(boolean v) {
listBox.Items_setAll(v);
}
void InitToggleWidget() {
toggle = GfuiChkBox_.invk_("toggle", this, "&toggle", this, ToggleChecks_cmd); toggle.Size_(60, 20); toggle.AlignH_set(GfuiAlign_.Left);
}
void InitReverseWidget() {
GfuiBtn_.invk_("reverse", this, this, ReverseChks_cmd).Size_(70, 20).Text_("&reverse");
}
void InitListBoxWidget() {
listBox.Owner_(this, "listBox");
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, ToggleChecks_cmd)) SetAllCheckStates(toggle.Val());
else if (ctx.Match(k, ReverseChks_cmd)) listBox.Items_reverse();
else return super.Invk(ctx, ikey, k, m);
return this;
} public static final String ToggleChecks_cmd = "ToggleChecks", ReverseChks_cmd = "ReverseChks";
GfuiChkBox toggle;
GfuiCheckListBox listBox = GfuiCheckListBox.new_();
public static GfuiCheckListPanel new_() {
GfuiCheckListPanel rv = new GfuiCheckListPanel();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
return rv;
}
}

View File

@@ -13,3 +13,25 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.layouts.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.elems.*;
public class GfuiFormPanel extends GfuiElemBase {
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.Width_(60); // default to 60; do not force callers to always set width
GfuiWin ownerForm = (GfuiWin)ctorArgs.Get_val_or(GfuiElem_.InitKey_ownerWin, null);
GfoFactory_gfui.Btn_MoveBox(this, ownerForm);
GfoFactory_gfui.Btn_MinWin2(this);
GfoFactory_gfui.Btn_QuitWin3(this);
this.Lyt_activate();
this.Lyt().Bands_add(GftBand.new_().Cells_num_(3));
}
public static GfuiFormPanel new_(GfuiWin form) {
GfuiFormPanel rv = new GfuiFormPanel();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_().Add(GfuiElem_.InitKey_ownerWin, form));
rv.Owner_(form, "formPanel");
return rv;
}
}

View File

@@ -13,3 +13,39 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import java.io.File;
import java.awt.FileDialog;
import javax.swing.JFrame;
import gplx.gfui.controls.elems.*; import gplx.gfui.controls.windows.*;
public class GfuiIoDialogUtl {
public static Io_url SelectDir() {return SelectDir(Io_url_.Empty);}
public static Io_url SelectDir(Io_url startingDir) {
FileDialog openFileDialog = NewOpenFileDialog(startingDir);
// openFileDialog.FileName = @"press enter to select this folder";
openFileDialog.setVisible(true);
String selectedDir = openFileDialog.getDirectory();
if (selectedDir == null) return Io_url_.Empty; // nothing selected
Io_url selected = Io_url_.new_any_(selectedDir);
Io_url selectedFil = selected.GenSubFil(openFileDialog.getFile());
return selectedFil.OwnerDir();
}
public static Io_url SelectFile() {return SelectFile(Io_url_.Empty);}
public static Io_url SelectFile(Io_url startingDir) {
FileDialog openFileDialog = NewOpenFileDialog(startingDir);
openFileDialog.setVisible(true);
String selectedDir = openFileDialog.getDirectory();
if (selectedDir == null) return Io_url_.Empty; // nothing selected
Io_url selected = Io_url_.new_any_(selectedDir);
Io_url selectedFil = selected.GenSubFil(openFileDialog.getFile());
return selectedFil;
}
static FileDialog NewOpenFileDialog(Io_url startingDir) {
//WORKAROUND (Windows.Forms): InitialDirectory only works for new instances; http://groups.google.com/groups?hl=en&lr=&threadm=ubk6dEUYDHA.536%40TK2MSFTNGP10.phx.gbl&rnum=30&prev=/groups%3Fq%3Ddotnet%2BInitialDirectory%26hl%3Den%26btnG%3DGoogle%2BSearch
FileDialog openFileDialog = new FileDialog(new JFrame());
if (!startingDir.EqNull())
openFileDialog.setDirectory(startingDir.Xto_api());
return openFileDialog;
}
}

View File

@@ -13,3 +13,57 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.layouts.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
public abstract class GfuiIoUrlSelectBox extends GfuiElemBase {
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
label = GfuiLbl_.sub_("label", this);
pathBox.Owner_(this, "pathBox");
GfuiBtn_.invk_("selectPath", this, this, SelectAction_cmd).Text_("...");
this.Lyt_activate();
this.Lyt().Bands_add(GftBand.new_().Cell_abs_(60).Cell_pct_(100).Cell_abs_(30));
}
public static final String PathSelected_evt = "PathSelected_evt";
public GfuiLbl Label() {return label;} GfuiLbl label;
public Io_url Url() {return Io_url_.new_any_(pathBox.TextMgr().Val());}
public Io_url StartingFolder() {return startingFolder;}
public void StartingFolder_set(Io_url v) {this.startingFolder = v;} Io_url startingFolder = Io_url_.Empty;
@Override public void Focus() {pathBox.Focus();}
void SelectAction() {
Io_url selectedPath = SelectAction_hook(this.startingFolder);
if (selectedPath.EqNull()) return;
pathBox.Text_(selectedPath.Raw());
Gfo_evt_mgr_.Pub(this, PathSelected_evt);
}
protected abstract Io_url SelectAction_hook(Io_url startingFolder);
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, SelectAction_cmd)) SelectAction();
else return super.Invk(ctx, ikey, k, m);
return this;
} public static final String SelectAction_cmd = "SelectAction";
GfuiComboBox pathBox = GfuiComboBox.new_();
}
class IoFileSelector extends GfuiIoUrlSelectBox { @Override protected Io_url SelectAction_hook(Io_url startingFolder) {
return GfuiIoDialogUtl.SelectFile(startingFolder);
}
public static IoFileSelector new_() {
IoFileSelector rv = new IoFileSelector();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
return rv;
} IoFileSelector() {}
}
class IoFolderSelector extends GfuiIoUrlSelectBox { @Override protected Io_url SelectAction_hook(Io_url startingFolder) {
Io_url url = GfuiIoDialogUtl.SelectDir(startingFolder);
this.StartingFolder_set(url);
return url;
}
public static IoFolderSelector new_() {
IoFolderSelector rv = new IoFolderSelector();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
return rv;
} IoFolderSelector() {}
}

View File

@@ -13,3 +13,8 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GfuiIoUrlSelectBox_ {
public static GfuiIoUrlSelectBox dir_() {return IoFolderSelector.new_();}
public static GfuiIoUrlSelectBox fil_() {return IoFileSelector.new_();}
}

View File

@@ -13,3 +13,68 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.elems.*;
import gplx.core.interfaces.*;
public class GfuiMoveElemBnd implements IptBnd, Gfo_invk, InjectAble {
public String Key() {return "gplx.gfui.moveWidget";}
public List_adp Ipts() {return args;} List_adp args = List_adp_.New();
public IptEventType EventTypes() {return IptEventType_.add_(IptEventType_.KeyDown, IptEventType_.MouseDown, IptEventType_.MouseMove, IptEventType_.MouseUp);}
public void Exec(IptEventData iptData) {
int val = iptData.EventType().Val();
if (val == IptEventType_.KeyDown.Val()) ExecKeyDown(iptData);
else if (val == IptEventType_.MouseDown.Val()) ExecMouseDown(iptData);
else if (val == IptEventType_.MouseUp.Val()) ExecMouseUp(iptData);
else if (val == IptEventType_.MouseMove.Val()) ExecMouseMove(iptData);
}
public GfuiElem TargetElem() {return targetElem;} public void TargetElem_set(GfuiElem v) {this.targetElem = v;} GfuiElem targetElem;
public static final String target_idk = "target";
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, target_idk)) return targetElem;
else if (ctx.Match(k, "key")) return key;
else return Gfo_invk_.Rv_unhandled;
}
public String Key_of_GfuiElem() {return keyIdf;} public void Key_of_GfuiElem_(String val) {keyIdf = val;} private String keyIdf = "moveElemBtnBnd";
public void Inject(Object owner) {
GfuiElem ownerElem = (GfuiElem)owner;
ownerElem.IptBnds().Add(this);
ownerElem.IptBnds().EventsToFwd_set(IptEventType_.None); // NOTE: suppress bubbling else ctrl+right will cause mediaPlayer to jump forward
}
void ExecMouseDown(IptEventData msg) {
moving = true;
anchor = msg.MousePos();
}
void ExecMouseMove(IptEventData msg) {
if (!moving) return;
targetElem.Pos_(msg.MousePos().Op_subtract(anchor).Op_add(targetElem.Pos()));
}
void ExecMouseUp(IptEventData msg) {
moving = false;
}
void ExecKeyDown(IptEventData msg) {
PointAdp current = targetElem.Pos();
PointAdp offset = PointAdp_.cast(hash.Get_by(msg.EventArg()));
targetElem.Pos_(current.Op_add(offset));
}
@gplx.Internal protected void Key_set(String key) {this.key = key;} private String key;
public Object Srl(GfoMsg owner) {return IptBnd_.Srl(owner, this);}
boolean moving = false;
PointAdp anchor = PointAdp_.Zero; Hash_adp hash = Hash_adp_.New();
public static GfuiMoveElemBnd new_() {return new GfuiMoveElemBnd();}
GfuiMoveElemBnd() {
args.Add_many(IptMouseBtn_.Left, IptMouseMove.AnyDirection);
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Up), PointAdp_.new_(0, -10));
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Down), PointAdp_.new_(0, 10));
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Left), PointAdp_.new_(-10, 0));
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Right), PointAdp_.new_(10, 0));
}
}
class IptBndArgsBldr {
public static void AddWithData(List_adp list, Hash_adp hash, IptArg arg, Object data) {
list.Add(arg);
hash.Add(arg, data);
}
}

View File

@@ -13,3 +13,74 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.ipts.*; import gplx.gfui.layouts.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.windows.*;
public class GfuiMoveElemBtn extends GfuiBtn { @Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.lbl_();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.Text_("*");
this.TipText_("move/resize");
this.IptBnds().EventsToFwd_set(IptEventType_.None);
this.IptBnds().Add(moveBinding);
this.IptBnds().Add(GfuiResizeFormBnd.new_());
}
public void TargetElem_set(GfuiElem v) {moveBinding.TargetElem_set(v);}
final GfuiMoveElemBnd moveBinding = GfuiMoveElemBnd.new_();
public static GfuiMoveElemBtn new_() {
GfuiMoveElemBtn rv = new GfuiMoveElemBtn();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
}
class GfuiResizeFormBnd implements IptBnd {
public String Key() {return "gplx.gfui.resizeForm";}
public List_adp Ipts() {return args;} List_adp args = List_adp_.New();
public IptEventType EventTypes() {return IptEventType_.KeyDown.Add(IptEventType_.MouseDown).Add(IptEventType_.MouseUp).Add(IptEventType_.MouseMove);}
public void Exec(IptEventData iptData) {
int val = iptData.EventType().Val();
if (val == IptEventType_.KeyDown.Val()) ExecKeyDown(iptData);
else if (val == IptEventType_.MouseDown.Val()) ExecMouseDown(iptData);
else if (val == IptEventType_.MouseUp.Val()) ExecMouseUp(iptData);
else if (val == IptEventType_.MouseMove.Val()) ExecMouseMove(iptData);
}
void ExecMouseDown(IptEventData iptData) {
active = true;
lastPos = iptData.MousePos();
}
void ExecMouseMove(IptEventData iptData) {
if (!active) return;
PointAdp delta = iptData.MousePos().Op_subtract(lastPos);
if (delta.Eq(PointAdp_.Zero)) return;
ResizeForm(iptData.Sender(), XtoSize(delta));
}
void ExecMouseUp(IptEventData iptData) {
active = false;
}
void ExecKeyDown(IptEventData iptData) {
SizeAdp deltaSize = (SizeAdp)hash.Get_by(iptData.EventArg());
ResizeForm(iptData.Sender(), deltaSize);
}
void ResizeForm(GfuiElem elem, SizeAdp deltaSize) {
GfuiWin form = elem.OwnerWin();
SizeAdp newSize = Op_add(form.Size(), deltaSize);
form.Size_(newSize);
GftGrid.LytExecRecur(form);
form.Redraw(); // must redraw, else artifacts will remain; ex: grid may leave random lines
}
static SizeAdp XtoSize(PointAdp point) {return SizeAdp_.new_(point.X(), point.Y());}
static SizeAdp Op_add(SizeAdp lhs, SizeAdp rhs) {return SizeAdp_.new_(lhs.Width() + rhs.Width(), lhs.Height() + rhs.Height());}
public Object Srl(GfoMsg owner) {return IptBnd_.Srl(owner, this);}
boolean active = false; PointAdp lastPos = PointAdp_.Zero; Hash_adp hash = Hash_adp_.New();
public static GfuiResizeFormBnd new_() {return new GfuiResizeFormBnd();}
GfuiResizeFormBnd() {
args.Add_many(IptMouseBtn_.Right, IptMouseMove.AnyDirection);
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Shift).Add(IptKey_.Up), SizeAdp_.new_(0, -10));
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Shift).Add(IptKey_.Down), SizeAdp_.new_(0, 10));
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Shift).Add(IptKey_.Left), SizeAdp_.new_(-10, 0));
IptBndArgsBldr.AddWithData(args, hash, IptKey_.Ctrl.Add(IptKey_.Shift).Add(IptKey_.Right), SizeAdp_.new_(10, 0));
}
}

View File

@@ -13,3 +13,21 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import org.junit.*; import gplx.gfui.ipts.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.customs.*;
public class GfuiMoveElemBtn_tst {
@Before public void setup() {
form = GfuiWin_.app_("form"); form.Size_(100, 100);
moveBtn = GfuiBtn_.new_("moveBtn");
GfuiMoveElemBnd bnd = GfuiMoveElemBnd.new_(); bnd.TargetElem_set(form);
moveBtn.IptBnds().Add(bnd);
}
@Test public void Basic() {
Tfds.Eq(form.X(), 0);
IptEventMgr.ExecKeyDown(moveBtn, IptEvtDataKey.test_(MoveRightArg()));
Tfds.Eq(form.X(), 10);
}
IptKey MoveRightArg() {return IptKey_.Ctrl.Add(IptKey_.Right);}
GfuiWin form; GfuiBtn moveBtn;
}

View File

@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.layouts.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.elems.*;
public class GfuiStatusBar extends GfuiElemBase {
public GfuiStatusBox Box() {return statusBox;} GfuiStatusBox statusBox;
public GfuiMoveElemBtn MoveButton() {return moveBtn;} GfuiMoveElemBtn moveBtn;
void StatusBar_Focus() {
statusBox.Focus_able_(true);
statusBox.Visible_set(true);
statusBox.Focus();
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, StatusBarFocus_cmd)) StatusBar_Focus();
else return super.Invk(ctx, ikey, k, m);
return this;
} public static final String StatusBarFocus_cmd = "StatusBarFocus";
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
moveBtn = GfuiMoveElemBtn.new_();
statusBox = GfuiStatusBox_.new_("statusBox");
statusBox.Owner_(this).Border_off_().Visible_on_();
moveBtn.Owner_(this, "moveBox");
GfoFactory_gfui.Btn_MinWin2(this);
GfoFactory_gfui.Btn_QuitWin3(this);
this.Lyt_activate();
this.Lyt().Bands_add(GftBand.new_().Cell_pct_(100).Cell_abs_(20).Cell_abs_(20).Cell_abs_(20));
}
public static GfuiStatusBar new_() {
GfuiStatusBar rv = new GfuiStatusBar();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
return rv;
}
}

View File

@@ -13,3 +13,16 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.interfaces.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.windows.*;
public class GfuiStatusBarBnd implements InjectAble {
public GfuiStatusBar Bar() {return statusBar;} GfuiStatusBar statusBar = GfuiStatusBar.new_();
public void Inject(Object owner) {
GfuiWin form = GfuiWin_.as_(owner); if (form == null) throw Err_.new_type_mismatch(GfuiWin.class, owner);
statusBar.Owner_(form, "statusBar");
IptBnd_.cmd_to_(IptCfg_.Null, form, statusBar, GfuiStatusBar.StatusBarFocus_cmd, IptKey_.add_(IptKey_.Ctrl, IptKey_.Alt, IptKey_.T));
statusBar.MoveButton().TargetElem_set(form);
}
public static GfuiStatusBarBnd new_() {return new GfuiStatusBarBnd();} GfuiStatusBarBnd() {}
}

View File

@@ -13,3 +13,80 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.envs.*; import gplx.gfui.kits.core.*; import gplx.gfui.envs.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.standards.*;
public class GfuiStatusBox extends GfuiTextBox implements UsrMsgWkr { public GfuiStatusBox Active_(boolean v) {active = v; return this;} private boolean active = true;
public GfuiStatusBox VisibilityDuration_(int v) {timer.Interval_(v); visibilityDuration = v; return this;} int visibilityDuration;
@Override public void Opened_cbk() {
super.Opened_cbk();
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Note, this);
}
public void ExecUsrMsg(int type, UsrMsg umsg) {
if ( !active
|| !this.OwnerElem().Visible() // WORKAROUND.WINFORMS: else application hangs on Invoke
|| !this.Opened_done()
) return;
this.CreateControlIfNeeded(); // WORKAROUND.WINFORMS: else will sometimes throw: Cannot call Invoke or InvokeAsync on a control until the window handle has been created
this.VisibilityDuration_(umsg.VisibilityDuration());
String text = String_.Replace(umsg.To_str(), Op_sys.Cur().Nl_str(), " "); // replace NewLine with " " since TextBox cannot show NewLine
Invoke(Gfo_invk_cmd.New_by_val(this, Invk_WriteText, text));
}
public void WriteText(String text) {
if (!this.Visible()) {
this.Visible_set(true);
this.Zorder_front();
}
this.Text_(text);
timer.Enabled_off().Enabled_on(); // Enabled_off().Enabled_on() resets timer; timer can be at second 1 of 3, and this will reset back to timer 0
GfuiEnv_.DoEvents(); // WORKAROUND.WINFORMS: needed, else text will not refresh (ex: splash screen); NOTE!!: will cause other timers to fire! (ex: mediaPlaylistMgr)
}
@Override public void Focus() {
this.Focus_able_(true);
super.Focus();
this.Focus_able_(false);
}
@Override public boolean DisposeCbk() {
super.DisposeCbk();
timer.Rls();
UsrDlg_.Instance.RegOff(UsrMsgWkr_.Type_Note, this);
if (timerCmd != null) timerCmd.Rls();
return true;
}
void HideWindow() {
timer.Enabled_off();
Text_("");
this.Visible_set(false);
this.Zorder_back();
}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_HideWindow)) HideWindow();
else if (ctx.Match(k, Invk_Text_empty)) {timer.Enabled_off(); Text_(GfuiTextBox_.NewLine + Text());}
else if (ctx.Match(k, Invk_WriteText)) WriteText(m.ReadStr("v"));
else return super.Invk(ctx, ikey, k, m);
return this;
} static final String Invk_HideWindow = "HideWindow", Invk_WriteText = "WriteText", Invk_Text_empty = "Text_empty";
TimerAdp timer;
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.Border_on_(false);
this.Focus_able_(false);
this.Visible_set(false);
timer = TimerAdp.new_(this, Invk_HideWindow, 2000, false);
}
@Override public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
this.Border_on_(false);
this.Focus_able_(false);
this.Visible_set(true);
timerCmd = kit.New_cmd_sync(this);
timer = TimerAdp.new_(timerCmd, GfuiInvkCmd_.Invk_sync, 2000, false);
} GfuiInvkCmd timerCmd;
public void ctor_kit_GfuiElemBase_drd(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
this.Border_on_(false);
this.Focus_able_(false);
this.Visible_set(true);
timerCmd = kit.New_cmd_sync(this);
// timer = TimerAdp.new_(timerCmd, GfuiInvkCmd_.Invk_sync, 2000, false);
}
}

View File

@@ -13,3 +13,26 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.ipts.*; import gplx.gfui.layouts.*; import gplx.gfui.controls.windows.*;
public class GfuiStatusBoxBnd implements Gfo_invk {
public GfuiStatusBox Box() {return statusBox;} GfuiStatusBox statusBox = GfuiStatusBox_.new_("statusBox");
void ShowTime() {
statusBox.ExecUsrMsg(UsrMsgWkr_.Type_Note, UsrMsg.new_(Datetime_now.Get().XtoStr_gplx_long()));
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_ShowTime)) ShowTime();
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_ShowTime = "ShowTime";
public static GfuiStatusBoxBnd gft_(GfuiWin owner) {
GfuiStatusBoxBnd rv = new GfuiStatusBoxBnd();
rv.ctor_GfuiStatusBoxBnd(owner);
return rv;
}
void ctor_GfuiStatusBoxBnd(GfuiWin win) {
IptBnd_.cmd_to_(IptCfg_.Null, win, this, GfuiStatusBoxBnd.Invk_ShowTime, IptKey_.add_(IptKey_.Ctrl, IptKey_.Shift, IptKey_.T));
statusBox.Owner_(win).Visible_off_().BackColor_(ColorAdp_.Black).TextAlignH_right_().ForeColor_(ColorAdp_.Green);
win.Lyt().SubLyts().Add(GftGrid.new_().Bands_dir_(DirInt.Bwd).Bands_add(GftBand.new_().Cells_num_(1).Len1_abs_(13)));
}
}

View File

@@ -13,3 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.customs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiStatusBox_ {
public static GfuiStatusBox new_(String key) {
GfuiStatusBox rv = new GfuiStatusBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
rv.Key_of_GfuiElem_(key);
return rv;
}
public static GfuiStatusBox kit_(Gfui_kit kit, String key, GxwElem underElem) {
GfuiStatusBox rv = new GfuiStatusBox();
rv.ctor_kit_GfuiElemBase(kit, key, underElem, GfuiElem_.init_focusAble_false_());
return rv;
}
}

View File

@@ -13,3 +13,66 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.elems; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.gfxs.*; import gplx.gfui.ipts.*; import gplx.gfui.layouts.*; import gplx.gfui.imgs.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.*; import gplx.gfui.controls.windows.*;
import gplx.gfui.layouts.swts.*;
import gplx.core.interfaces.*;
public interface GfuiElem extends Gfo_invk, GxwCbkHost, IptBndsOwner, GftItem, Gfo_evt_itm {
//% Layout
int X(); GfuiElem X_(int val);
int Y(); GfuiElem Y_(int val);
int X_max();
int Y_max();
GfuiElem Pos_(PointAdp val); GfuiElem Pos_(int x, int y);
int Width(); GfuiElem Width_(int val);
int Height(); GfuiElem Height_(int val);
GfuiElem Size_(SizeAdp val); GfuiElem Size_(int w, int h);
RectAdp Rect(); void Rect_set(RectAdp rect);
void Zorder_front(); void Zorder_back();
PointAdp Pos();
SizeAdp Size();
Swt_layout_mgr Layout_mgr(); void Layout_mgr_(Swt_layout_mgr v);
Swt_layout_data Layout_data(); void Layout_data_(Swt_layout_data v);
//% Visual
boolean Visible(); void Visible_set(boolean v); GfuiElem Visible_on_(); GfuiElem Visible_off_();
ColorAdp BackColor(); GfuiElem BackColor_(ColorAdp v);
GfuiBorderMgr Border(); GfuiElem Border_on_(); GfuiElem Border_off_();
void Redraw();
//% Text
GfxStringData TextMgr();
String Text(); GfuiElem Text_(String v); GfuiElem Text_any_(Object v);
GfuiElem ForeColor_(ColorAdp v);
void TextAlignH_(GfuiAlign v);
GfuiElem TextAlignH_left_(); GfuiElem TextAlignH_right_(); GfuiElem TextAlignH_center_();
String TipText(); GfuiElem TipText_(String v);
//% Focus
boolean Focus_has();
boolean Focus_able(); GfuiElem Focus_able_(boolean v);
int Focus_idx(); GfuiElem Focus_idx_(int val);
String Focus_default(); GfuiElem Focus_default_(String v);
void Focus();
//% Action
void Click();
//% Elem Tree Hierarchy (Owners And Subs)
//String Key_of_GfuiElem();
GfuiElem Key_of_GfuiElem_(String val);
GfuiElem OwnerElem(); GfuiElem OwnerElem_(GfuiElem val); GfuiElem Owner_(GfuiElem owner); GfuiElem Owner_(GfuiElem owner, String key);
GfuiElemList SubElems();
GfuiElem Inject_(InjectAble sub);
//% Form
GfuiWin OwnerWin(); GfuiElem OwnerWin_(GfuiWin val);
void Opened_cbk(); boolean Opened_done();
void Dispose();
//% Infrastructure
GxwElem UnderElem();
GxwElem UnderElem_make(Keyval_hash ctorArgs);
void ctor_GfuiBox_base(Keyval_hash ctorArgs);
void Invoke(Gfo_invk_cmd cmd);
}

View File

@@ -13,3 +13,286 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.elems; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.gfxs.*; import gplx.gfui.ipts.*; import gplx.gfui.layouts.*; import gplx.gfui.imgs.*; import gplx.gfui.kits.core.*;
import gplx.gfui.layouts.swts.*;
import gplx.gfui.controls.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.windows.*;
import gplx.core.strings.*; import gplx.core.interfaces.*;
public class GfuiElemBase implements GfuiElem {
//% Layout
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public Gfo_invk_cmd_mgr InvkMgr() {return invkMgr;} Gfo_invk_cmd_mgr invkMgr = Gfo_invk_cmd_mgr.new_();
public int X() {return underMgr.X();} public GfuiElem X_(int val) {underMgr.X_set(val); return this;}
public int Y() {return underMgr.Y();} public GfuiElem Y_(int val) {underMgr.Y_set(val); return this;}
public int X_max() {return underMgr.X() + underMgr.Width();} public int Y_max() {return underMgr.Y() + underMgr.Height();}
public PointAdp Pos() {return underMgr.Pos();} public GfuiElem Pos_(PointAdp val) {underMgr.Pos_set(val); return this;} public GfuiElem Pos_(int x, int y) {return Pos_(PointAdp_.new_(x, y));}
public int Width() {return underMgr.Width();} public GfuiElem Width_(int val) {underMgr.Width_set(val); return this;}
public int Height() {return underMgr.Height();}
public GfuiElem Height_(int val) {underMgr.Height_set(val); return this;}
public SizeAdp Size() {return underMgr.Size();} public GfuiElem Size_(int w, int h) {return Size_(SizeAdp_.new_(w, h));}
public GfuiElem Size_(SizeAdp val) {
underMgr.Size_set(val);
return this;
}
public RectAdp Rect() {return RectAdp_.vector_(this.Pos(), this.Size());}
public void Rect_set(RectAdp rect) {
underMgr.Rect_set(rect);
textMgr.OwnerSize_sync(rect.Size());
}
public int Gft_w() {return underElem.Core().Width();} public GftItem Gft_w_(int v) {underElem.Core().Width_set(v); return this;}
public int Gft_h() {return underElem.Core().Height();} public GftItem Gft_h_(int v) {underElem.Core().Height_set(v); return this;}
public int Gft_x() {return underElem.Core().X();} public GftItem Gft_x_(int v) {underElem.Core().X_set(v); return this;}
public int Gft_y() {return underElem.Core().Y();} public GftItem Gft_y_(int v) {underElem.Core().Y_set(v); return this;}
public GftItem Gft_rect_(RectAdp rect) {underElem.Core().Rect_set(rect); return this;}
public GftGrid Lyt() {return lyt;} GftGrid lyt = null;
public GfuiElemBase Lyt_activate() {lyt = GftGrid.new_(); return this;}
public void Lyt_exec() {
GftItem[] ary = new GftItem[subElems.Count()];
for (int i = 0; i < ary.length; i++)
ary[i] = (GfuiElemBase)subElems.Get_at(i);
SizeChanged_ignore = true;
lyt.Exec(this, ary);
SizeChanged_ignore = false;
}
public void Zorder_front() {underMgr.Zorder_front();} public void Zorder_back() {underMgr.Zorder_back();}
@gplx.Virtual public void Zorder_front_and_focus() {
this.Zorder_front();
this.Visible_set(true);
this.Focus();
}
public Swt_layout_mgr Layout_mgr() {return underElem.Core().Layout_mgr();}
public void Layout_mgr_(Swt_layout_mgr v) {underElem.Core().Layout_mgr_(v);}
public Swt_layout_data Layout_data() {return underElem.Core().Layout_data();}
public void Layout_data_(Swt_layout_data v) {underElem.Core().Layout_data_(v);}
//% Visual
@gplx.Virtual public boolean Visible() {return underMgr.Visible();} @gplx.Virtual public void Visible_set(boolean v) {underMgr.Visible_set(v);}
public GfuiElem Visible_on_() {this.Visible_set(true); return this;} public GfuiElem Visible_off_() {this.Visible_set(false); return this;}
@gplx.Virtual public ColorAdp BackColor() {return backColor;} ColorAdp backColor = ColorAdp_.White;
@gplx.Virtual public GfuiElem BackColor_(ColorAdp v) {backColor = v; underMgr.BackColor_set(backColor); return this;}
public GfuiBorderMgr Border() {return border;} GfuiBorderMgr border = GfuiBorderMgr.new_();
public GfuiElem Border_on_() {border.All_(PenAdp_.new_(ColorAdp_.Black, 1)); return this;}
public GfuiElem Border_off_() {border.All_(null); return this;}
public GfxStringData TextMgr() {return textMgr;} GfxStringData textMgr;
public String Text() {return textMgr.Val();}
public GfuiElem Text_any_(Object obj) {return Text_(Object_.Xto_str_strict_or_null_mark(obj));}
@gplx.Virtual public GfuiElem Text_(String v) {
this.TextMgr().Text_set(v);
Click_key_set_(v);
return this;
}
@gplx.Virtual public GfuiElem ForeColor_(ColorAdp v) {textMgr.Color_(v); return this;}
public void TextAlignH_(GfuiAlign v) {textMgr.AlignH_(v);}
public GfuiElem TextAlignH_left_() {textMgr.AlignH_(GfuiAlign_.Left); return this;}
public GfuiElem TextAlignH_right_() {textMgr.AlignH_(GfuiAlign_.Right); return this;}
public GfuiElem TextAlignH_center_() {textMgr.AlignH_(GfuiAlign_.Mid); return this;}
public String TipText() {return underElem.Core().TipText();} public GfuiElem TipText_(String v) {underElem.Core().TipText_set(v); return this;}
@gplx.Virtual public void Redraw() {underMgr.Invalidate();}
public boolean CustomDraw() {return customDraw;} public void CustomDraw_set(boolean v) {customDraw = v;} private boolean customDraw;
//% Focus
public boolean Focus_has() {return underElem.Core().Focus_has();}
public boolean Focus_able() {return underElem.Core().Focus_able();} public GfuiElem Focus_able_(boolean v) {underElem.Core().Focus_able_(v); return this;}
public String Focus_default() {return defaultFocusKey;} public GfuiElem Focus_default_(String v) {defaultFocusKey = v; return this;} private String defaultFocusKey;
public int Focus_idx() {return focusKey_order_manual;} int focusKey_order_manual = GfuiFocusOrderer.NullVal;
public GfuiElem Focus_idx_(int val) {
underElem.Core().Focus_index_set(val);
focusKey_order_manual = val;
return this;
}
@gplx.Virtual public void Focus() {
if (subElems.Count() == 0) // if no subs, focus self
underElem.Core().Focus();
else if (defaultFocusKey != null) { // if default is specified, focus it
GfuiElem focusTarget = subElems.Get_by(defaultFocusKey); if (focusTarget == null) throw Err_.new_wo_type("could not find defaultTarget for focus", "ownerKey", this.Key_of_GfuiElem(), "defaultTarget", defaultFocusKey);
focusTarget.Focus();
}
else { // else, activate first visible elem; NOTE: some elems are visible, but not Focus_able (ex: ImgGalleryBox)
for (int i = 0; i < subElems.Count(); i++) {
GfuiElem sub = subElems.Get_at(i);
if (sub.Visible() && !String_.Eq(sub.Key_of_GfuiElem(), "statusBox")) {
sub.Focus();
return;
}
}
underElem.Core().Focus(); // no visible subElems found; focus self
}
}
//% Inputs
public IptBndMgr IptBnds() {return iptBnds;} IptBndMgr iptBnds = IptBndMgr.new_();
//% ActionKey
@gplx.Virtual public void Click() {}
@gplx.Virtual public boolean Click_able() {return false;}
public IptKey Click_key() {return clickKey;}
@gplx.Internal @gplx.Virtual protected void Click_key_set_(String v) {clickKey = GfuiWinKeyCmdMgr.ExtractKeyFromText(v);} IptKey clickKey = IptKey_.None;
//% Owner
public String Key_of_GfuiElem() {return keyIdf;} public GfuiElem Key_of_GfuiElem_(String val) {keyIdf = val; return this;} private String keyIdf;
public GfuiElemList SubElems() {return subElems;} GfuiElemList subElems;
public GfuiElem OwnerElem() {return ownerElem;} public GfuiElem OwnerElem_(GfuiElem owner) {ownerElem = owner; return this;} GfuiElem ownerElem = null;
public GfuiElem Owner_(GfuiElem owner, String key) {this.Key_of_GfuiElem_(key); return Owner_(owner);}
public GfuiElem Owner_(GfuiElem owner) {
owner.SubElems().Add(this);
return this;
}
//% Form
@gplx.Virtual public GfuiWin OwnerWin() {return ownerForm;} public GfuiElem OwnerWin_(GfuiWin val) {ownerForm = val; return this;} GfuiWin ownerForm = null;
@gplx.Virtual public boolean Opened_done() {return ownerForm == null ? false : ownerForm.Opened_done();}
@gplx.Virtual public void Opened_cbk() {
for (int i = 0; i < subElems.Count(); i++) {
GfuiElem elem = subElems.Get_at(i);
elem.Opened_cbk();
}
}
public void Dispose() {
Gfo_evt_mgr_.Rls_sub(this);
underMgr.Dispose();
}
//% Cbks
@gplx.Virtual public boolean KeyDownCbk(IptEvtDataKey data) {IptEventMgr.ExecKeyDown(this, data); return true;}
@gplx.Virtual public boolean KeyUpCbk(IptEvtDataKey data) {IptEventMgr.ExecKeyUp(this, data); return true;}
@gplx.Virtual public boolean KeyHeldCbk(IptEvtDataKeyHeld data) {IptEventMgr.ExecKeyPress(this, data); return true;}
@gplx.Virtual public boolean MouseDownCbk(IptEvtDataMouse data) {IptEventMgr.ExecMouseDown(this, data); return true;}
@gplx.Virtual public boolean MouseUpCbk(IptEvtDataMouse data) {IptEventMgr.ExecMouseUp(this, data); return true;}
@gplx.Virtual public boolean MouseMoveCbk(IptEvtDataMouse data) {IptEventMgr.ExecMouseMove(this, data); return true;}
@gplx.Virtual public boolean MouseWheelCbk(IptEvtDataMouse data) {IptEventMgr.ExecMouseWheel(this, data); return true;}
@gplx.Virtual public boolean PaintCbk(PaintArgs args) {border.DrawData(args.Graphics()); return true;}
@gplx.Virtual public boolean PaintBackgroundCbk(PaintArgs args) {return true;}
@gplx.Virtual public boolean DisposeCbk() {return true;}
@gplx.Virtual public boolean VisibleChangedCbk() {return true;}
@gplx.Virtual public boolean FocusGotCbk() {
GfuiFocusMgr.Instance.FocusedElem_set(this);
return true;
}
@gplx.Virtual public boolean FocusLostCbk() {return true;}
@gplx.Virtual public boolean SizeChangedCbk() {
this.TextMgr().OwnerSize_sync(this.Size());
this.Border().Bounds_sync(RectAdp_.size_(this.Size().Op_subtract(1)));
if (SizeChanged_ignore
|| !this.Opened_done()
) return true;
if (lyt != null) {
GftGrid.LytExecRecur(this);
return true;
}
return true;
}
//% InjectAble
public GfuiElem Inject_(InjectAble sub) {sub.Inject(this); return this;}
@gplx.Virtual public GxwElem UnderElem() {return underElem;} GxwElem underElem;
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, GfuiElemKeys.Redraw_cmd)) Redraw();
else if (ctx.Match(k, GfuiElemKeys.Key_set)) {
String v = m.ReadStr("v");
return ctx.Deny() ? (Object)this : Key_of_GfuiElem_(v);
}
else if (ctx.Match(k, GfuiElemKeys.Text_set)) {
String v = m.ReadStr("v");
return ctx.Deny() ? (Object)this : Text_(v);
}
else if (ctx.Match(k, GfuiElemKeys.TipText_)) {
String v = m.ReadStr("v");
return ctx.Deny() ? (Object)this : TipText_(v);
}
else if (ctx.Match(k, GfuiElemKeys.width_)) {
int v = m.ReadInt("v");
return ctx.Deny() ? (Object)this : Width_(v);
}
else if (ctx.Match(k, GfuiElemKeys.height_)) {
int v = m.ReadInt("v");
return ctx.Deny() ? (Object)this : Height_(v);
}
else if (ctx.Match(k, GfuiElemKeys.x_)) {
int v = m.ReadInt("v");
return ctx.Deny() ? (Object)this : X_(v);
}
else if (ctx.Match(k, GfuiElemKeys.y_)) {
int v = m.ReadInt("v");
return ctx.Deny() ? (Object)this : Y_(v);
}
else if (ctx.Match(k, GfuiElemKeys.TipText)) return TipText();
else if (ctx.Match(k, GfuiElemKeys.font_style_set)) {
FontStyleAdp v = (FontStyleAdp)m.ReadObj("v", FontStyleAdp_.Parser);
return ctx.Deny() ? (Object)this : textMgr.Font().Style_(v);
}
else if (ctx.Match(k, GfuiElemKeys.fore_color_set)) {
ColorAdp v = (ColorAdp)m.ReadObj("v", ColorAdp_.Parser);
if (ctx.Deny()) return this;
textMgr.Color_(v);
}
else if (ctx.Match(k, GfuiElemKeys.back_color_set)) {
ColorAdp v = (ColorAdp)m.ReadObj("v", ColorAdp_.Parser);
if (ctx.Deny()) return this;
BackColor_(v);
}
else if (ctx.Match(k, GfuiElemKeys.font_get)) return textMgr.Font();
else if (ctx.Match(k, GfuiElemKeys.IptRcvd_evt)) return IptEventType.HandleEvt(this, ctx, m);
else if (ctx.Match(k, GfuiElemKeys.OwnerBox_prp)) return ownerElem;
else if (ctx.Match(k, GfuiElemKeys.Focus_cmd)) Focus();
else if (ctx.Match(k, GfuiElemKeys.ActionExec_cmd)) Click();
else if (ctx.Match(k, GfuiElemKeys.Zorder_front_cmd)) Zorder_front();
else if (ctx.Match(k, Invk_OwnerWin_cmd)) return OwnerWin();
else {
if (ctx.Help_browseMode()) {
String_bldr sb = String_bldr_.new_();
for (int i = 0; i < this.SubElems().Count(); i++) {
GfuiElem subE = (GfuiElem)this.SubElems().Get_at(i);
sb.Add_str_w_crlf(subE.Key_of_GfuiElem());
}
return sb.To_str();
}
else {
Object rv = this.InvkMgr().Invk(ctx, ikey, k, m, this);
if (rv != Gfo_invk_.Rv_unhandled) return rv;
Object findObj = injected.Get_by(k);
if (findObj == null) findObj = this.subElems.Get_by(k);
if (findObj == null) return Gfo_invk_.Rv_unhandled;
return findObj; // necessary for gplx.images
}
}
return this;
} public static final String Invk_OwnerWin_cmd = "ownerWin";
public void Invoke(Gfo_invk_cmd cmd) {
cmd.Exec();
}
public Gfui_kit Kit() {return kit;} private Gfui_kit kit = Gfui_kit_.Mem();
@gplx.Virtual public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
this.kit = Swing_kit.Instance; // NOTE: assume that callers want Swing; SWT / Mem should be calling ctor_kit_GfuiElemBase
underElem = UnderElem_make(ctorArgs);
underElem.Host_set(this);
underMgr = underElem.Core();
subElems = GfuiElemList.new_(this);
textMgr = GfxStringData.new_(this, underElem);
this.Focus_able_(Bool_.Cast(ctorArgs.Get_val_or(GfuiElem_.InitKey_focusAble, true)));
underMgr.Size_set(SizeAdp_.new_(20, 20)); // NOTE: CS inits to 20,20; JAVA inits to 0,0
}
@gplx.Virtual public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
this.kit = kit;
this.keyIdf = key;
this.underElem = underElem;
underElem.Host_set(this);
underMgr = underElem.Core();
subElems = GfuiElemList.new_(this);
textMgr = GfxStringData.new_(this, underElem);
this.Focus_able_(Bool_.Cast(ctorArgs.Get_val_or(GfuiElem_.InitKey_focusAble, true)));
// underMgr.Size_set(SizeAdp_.new_(20, 20)); // NOTE: CS inits to 20,20; JAVA inits to 0,0
}
@gplx.Virtual public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.control_();}
public Object SubItms_getObj(String key) {return injected.Get_by(key);}
public GfuiElemBase SubItms_add(String key, Object v) {injected.Add(key, v); return this;}
public Ordered_hash XtnAtrs() {return xtnAtrs;} Ordered_hash xtnAtrs = Ordered_hash_.New();
Hash_adp injected = Hash_adp_.New();
GxwCore_base underMgr;
@gplx.Internal protected static boolean SizeChanged_ignore = false;
}

View File

@@ -13,3 +13,8 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.elems; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GfuiElemBase_ {
public static GfuiElemBase as_(Object obj) {return obj instanceof GfuiElemBase ? (GfuiElemBase)obj : null;}
public static GfuiElemBase cast(Object obj) {try {return (GfuiElemBase)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfuiElemBase.class, obj);}}
}

View File

@@ -13,3 +13,32 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.elems; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GfuiElemKeys {
public static final String
ActionExec_cmd = "actionExec"
, Focus_cmd = "focus"
, Redraw_cmd = "redraw"
, Zorder_front_cmd = "zorder_front"
, Text_set = "text_set"
, IptRcvd_evt = "IptRcvd_evt"
, Evt_menu_detected = "menu_detected"
;
@gplx.Internal protected static final String
Key_set = "Key_"
, TipText = "TipText"
, TipText_ = "TipText_"
, width_ = "width_"
, height_ = "height_"
, x_get = "x"
, x_ = "x_"
, y_ = "y_"
, font_style_set = "font_style_"
, fore_color_set = "fore_color_"
, back_color_set = "back_color_"
, font_get = "font"
, OwnerBox_prp = "ownerBox"
, Border_prp = "border"
;
}

View File

@@ -13,3 +13,39 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.elems; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GfuiElemList {
public int Count() {return hash.Count();}
public GfuiElem Get_at(int idx) {return (GfuiElem)hash.Get_at(idx);}
public GfuiElem Get_by(String key) {return (GfuiElem)hash.Get_by(key);}
public void Add(GfuiElem box) {Add_exec(box);}
public void DelOrFail(GfuiElem box) {Del_exec(box);}
public void Del_at(int idx) {Del_exec(Get_at(idx));}
public int IndexOfA(GfuiElem box) {return hash.Idx_of(box);}
public void Move_to(int src, int trg) {hash.Move_to(src, trg);}
public void Clear() {
for (int i = 0; i < this.Count(); i++)
Del_exec(this.Get_at(i));
hash.Clear();
}
void Add_exec(GfuiElem box) {
String key = box.Key_of_GfuiElem(); if (String_.Eq(key, String_.Empty)) throw Err_.new_wo_type("box does not have key", "type", box.getClass(), "owner", owner.Key_of_GfuiElem(), "ownerSubs", owner.SubElems().Count());
hash.Add(key, box);
owner.UnderElem().Core().Controls_add(box.UnderElem());
box.OwnerElem_(owner).OwnerWin_(owner.OwnerWin()); // needed b/c box may be added after form is loaded
Gfo_evt_mgr_.Sub_same(box, GfuiElemKeys.IptRcvd_evt, owner); // bubble iptEvts to owner
}
void Del_exec(GfuiElem box) {
String key = box.Key_of_GfuiElem(); if (!hash.Has(key)) throw Err_.new_missing_key(key);
hash.Del(key);
owner.UnderElem().Core().Controls_del(box.UnderElem());
owner.IptBnds().Cfgs_delAll();
box.Dispose();
}
GfuiElem owner; Ordered_hash hash = Ordered_hash_.New();
public static GfuiElemList new_(GfuiElem owner) {
GfuiElemList rv = new GfuiElemList();
rv.owner = owner;
return rv;
} GfuiElemList() {}
}

View File

@@ -13,3 +13,30 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.elems; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GfuiElem_ {
public static final String
InitKey_focusAble = "focusAble"
, InitKey_ownerWin = "ownerForm";
public static GfuiElem as_(Object obj) {return obj instanceof GfuiElem ? (GfuiElem)obj : null;}
public static GfuiElem cast(Object obj) {try {return (GfuiElem)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfuiElem.class, obj);}}
public static GfuiElemBase sub_(String key, GfuiElem owner) {
GfuiElemBase rv = new_();
rv.Owner_(owner, key);
return rv;
}
public static GfuiElemBase new_() {
GfuiElemBase rv = new GfuiElemBase();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
public static Keyval_hash init_focusAble_true_() {return new Keyval_hash().Add(GfuiElem_.InitKey_focusAble, true);}
public static Keyval_hash init_focusAble_false_() {return new Keyval_hash().Add(GfuiElem_.InitKey_focusAble, false);}
public static void Y_adj(int adj, GfuiElem... ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
GfuiElem itm = ary[i];
itm.Y_(itm.Y() + adj);
}
}
}

View File

@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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

@@ -13,3 +13,22 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*;
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

@@ -13,3 +13,73 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*;
public 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

@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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

@@ -13,3 +13,187 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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.ipts.*; import gplx.gfui.gfxs.*; import gplx.gfui.controls.windows.*;
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

@@ -13,3 +13,25 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*;
public interface GxwComboBox extends GxwElem {
ColorAdp Border_color();
void Border_color_(ColorAdp v);
int SelBgn(); void SelBgn_set(int v);
int SelLen(); void SelLen_set(int v);
void Sel_(int bgn, int end);
Object SelectedItm(); void SelectedItm_set(Object v);
String[] DataSource_as_str_ary();
void DataSource_set(Object... ary);
String Text_fallback(); void Text_fallback_(String v);
int List_sel_idx(); void List_sel_idx_(int v);
boolean List_visible(); void List_visible_(boolean v);
void Items__update(String[] ary);
void Items__size_to_fit(int count);
void Items__visible_rows_(int v);
void Items__jump_len_(int v);
void Items__backcolor_(ColorAdp v);
void Items__forecolor_(ColorAdp v);
void Margins_set(int left, int top, int right, int bot);
}

View File

@@ -13,3 +13,111 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import gplx.gfui.draws.*;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*;
public class GxwComboBox_lang extends JComboBox implements GxwComboBox, GxwElem, ActionListener {
public String[] DataSource_as_str_ary() {return String_.Ary_empty;}
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 ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
public void Items__backcolor_(ColorAdp v) {}
public void Items__forecolor_(ColorAdp v) {}
public int SelBgn() {return -1;} public void SelBgn_set(int v) {}
public int SelLen() {return 0;} public void SelLen_set(int v) {}
public void Sel_(int bgn, int end) {}
public Object SelectedItm() {return this.getEditor().getItem();} public void SelectedItm_set(Object v) {
this.getEditor().setItem(v);
}
@Override public String Text_fallback() {return "";} @Override public void Text_fallback_(String v) {}
@Override public int List_sel_idx() {return -1;} @Override public void List_sel_idx_(int v) {}
public boolean List_visible() {return false;} public void List_visible_(boolean v) {}
public void Items__update(String[] ary) {}
public void Items__size_to_fit(int count) {}
public void Items__visible_rows_(int v) {}
public void Items__jump_len_(int v) {}
public void Margins_set(int left, int top, int right, int bot) {}
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

@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*;
import gplx.gfui.layouts.swts.*;
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 Swt_layout_mgr Layout_mgr();
public abstract void Layout_mgr_(Swt_layout_mgr v);
public abstract Swt_layout_data Layout_data();
public abstract void Layout_data_(Swt_layout_data 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

@@ -13,3 +13,152 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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;
import gplx.gfui.draws.*; import gplx.gfui.controls.gxws.*;
import gplx.gfui.layouts.swts.*;
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.Instance.GetNativeColor(v));
}
else if (control instanceof RootPaneContainer) {
RootPaneContainer container = (RootPaneContainer)control;
container.getContentPane().setBackground(ColorAdpCache.Instance.GetNativeColor(v));
}
}
@Override public ColorAdp ForeColor() {return XtoColorAdp(control.getForeground());} @Override public void ForeColor_set(ColorAdp v) {control.setForeground(ColorAdpCache.Instance.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 Swt_layout_mgr Layout_mgr() {return null;}
@Override public void Layout_mgr_(Swt_layout_mgr v) {}
@Override public Swt_layout_data Layout_data() {return null;}
@Override public void Layout_data_(Swt_layout_data v) {}
@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

@@ -13,3 +13,37 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.ipts.*;
import gplx.gfui.layouts.swts.*;
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 Swt_layout_mgr Layout_mgr() {return null;}
@Override public void Layout_mgr_(Swt_layout_mgr v) {}
@Override public Swt_layout_data Layout_data() {return null;}
@Override public void Layout_data_(Swt_layout_data v) {}
@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

@@ -13,3 +13,12 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public interface GxwElem extends Gfo_invk {
GxwCore_base Core();
GxwCbkHost Host(); void Host_set(GxwCbkHost host);
String TextVal(); void TextVal_set(String v);
void EnableDoubleBuffering();
}

View File

@@ -13,3 +13,9 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GxwElemFactory_ {
public static GxwElemFactory_base Instance = new GxwElemFactory_cls_mock();
public static void winForms_() {Instance = new GxwElemFactory_cls_lang();}
public static void swt_(org.eclipse.swt.widgets.Display display) {Instance = new GxwElemFactory_swt(display);}
}

View File

@@ -13,3 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public abstract class GxwElemFactory_base {
public abstract GxwElem control_();
public abstract GxwWin win_app_();
public abstract GxwWin win_tool_(Keyval_hash ctorArgs);
public abstract GxwWin win_toaster_(Keyval_hash ctorArgs);
public abstract GxwElem lbl_();
public abstract GxwTextFld text_fld_();
public abstract GxwTextFld text_memo_();
public abstract GxwTextHtml text_html_();
public abstract GxwCheckListBox checkListBox_(Keyval_hash ctorArgs);
public abstract GxwComboBox comboBox_();
public abstract GxwListBox listBox_();
// @gplx.Internal protected GxwElem spacer_() {return MockControl.new_();}
}

View File

@@ -13,3 +13,29 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.controls.elems.*; import gplx.gfui.controls.windows.*;
public class GxwElemFactory_cls_lang extends GxwElemFactory_base {
@Override public GxwElem control_() {return new GxwElem_lang();}
@Override public GxwWin win_tool_(Keyval_hash ctorArgs) {
GfuiWin ownerForm = (GfuiWin)ctorArgs.Get_val_or(GfuiElem_.InitKey_ownerWin, null);
GxwWin ownerElem = ownerForm == null ? null : (GxwWin)ownerForm.UnderElem();
return GxwWin_jdialog.new_(ownerElem);
// return GxwWin_lang.new_();
}
@Override public GxwWin win_toaster_(Keyval_hash ctorArgs) {
GfsCtx ctx = GfsCtx.new_(); ctx.Match("", "");
GfuiWin ownerForm = (GfuiWin)ctorArgs.Get_val_or(GfuiElem_.InitKey_ownerWin, null);
GxwWin ownerElem = ownerForm == null ? null : (GxwWin)ownerForm.UnderElem();
return GxwWin_jwindow.new_(ownerElem);
// return GxwWin_lang.new_();
}
@Override public GxwWin win_app_() {return GxwWin_lang.new_();}
@Override public GxwElem lbl_() {return new GxwElem_lang();}
@Override public GxwTextFld text_fld_() {return GxwTextBox_lang_.fld_();}
@Override public GxwTextFld text_memo_() {return GxwTextBox_lang_.memo_();}
@Override public GxwTextHtml text_html_() {return new GxwTextHtml_lang().ctor();}
@Override public GxwCheckListBox checkListBox_(Keyval_hash ctorArgs) {return new GxwCheckListBox_lang();}
@Override public GxwComboBox comboBox_() {return GxwComboBox_lang.new_();}
@Override public GxwListBox listBox_() {return GxwListBox_lang.new_();}
}

View File

@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class GxwElemFactory_cls_mock extends GxwElemFactory_base {
@Override public GxwElem control_() {return GxwElem_mock_base.new_();}
@Override public GxwWin win_app_() {return MockForm.Instance;}
@Override public GxwWin win_tool_(Keyval_hash ctorArgs) {return MockForm.Instance;}
@Override public GxwWin win_toaster_(Keyval_hash ctorArgs) {return MockForm.Instance;}
@Override public GxwElem lbl_() {return GxwElem_mock_base.new_();}
@Override public GxwTextFld text_fld_() {return new MockTextBox();}
@Override public GxwTextFld text_memo_() {return new MockTextBoxMulti();}
@Override public GxwTextHtml text_html_() {return new MockTextBoxMulti();}
@Override public GxwCheckListBox checkListBox_(Keyval_hash ctorArgs) {throw Err_.new_unimplemented();}
@Override public GxwComboBox comboBox_() {return new MockComboBox();}
@Override public GxwListBox listBox_() {return new MockListBox();}
}

View File

@@ -13,3 +13,54 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*;
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

@@ -13,3 +13,78 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.ipts.*;
import gplx.gfui.draws.*;
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 ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
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 ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
public int SelBgn() {return -1;} public void SelBgn_set(int v) {}
public int SelLen() {return 0;} public void SelLen_set(int v) {}
public void Sel_(int bgn, int end) {}
public String[] DataSource_as_str_ary() {return String_.Ary_empty;}
public void DataSource_set(Object... ary) {}
public String Text_fallback() {return "";} public void Text_fallback_(String v) {}
public int List_sel_idx() {return -1;} public void List_sel_idx_(int v) {}
public boolean List_visible() {return false;} public void List_visible_(boolean v) {}
public void Items__update(String[] ary) {}
public void Items__size_to_fit(int count) {}
public void Items__visible_rows_(int v) {}
public void Items__jump_len_(int v) {}
public void Items__backcolor_(ColorAdp v) {}
public void Items__forecolor_(ColorAdp v) {}
public void Margins_set(int left, int top, int right, int bot) {}
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

@@ -13,3 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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

@@ -13,3 +13,69 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*;
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

@@ -13,3 +13,206 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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;
import gplx.gfui.draws.*;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*; import gplx.gfui.controls.elems.*;
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 ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
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) {
Err_.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 ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
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

@@ -13,3 +13,14 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*;
public interface GxwTextFld extends GxwElem {
boolean Border_on(); void Border_on_(boolean v);
ColorAdp Border_color(); void Border_color_(ColorAdp 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);
}

View File

@@ -13,3 +13,10 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public 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

@@ -13,3 +13,243 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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;
import gplx.gfui.draws.*;
import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*;
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);
}
public ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
@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 Err_.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);
}
public ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
@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 Err_.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_.To_str(Html_sel_bgn())).Add_char_crlf();
sb.Add("selEnd=").Add(Int_.To_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.To_str();
}
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 Err_.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 Err_.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

@@ -13,3 +13,21 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public 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

@@ -13,3 +13,338 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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;
import gplx.gfui.GfuiAlign;
import gplx.gfui.GfuiAlign_;
import gplx.gfui.PointAdp;
import gplx.gfui.PointAdp_;
import gplx.gfui.RectAdp;
import gplx.gfui.SizeAdp;
import gplx.gfui.controls.elems.GfuiElem;
import gplx.gfui.draws.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.windows.*;
import gplx.gfui.layouts.swts.*;
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 Err_.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 ColorAdp Border_color() {return border_color;} public void Border_color_(ColorAdp v) {border_color = v;} private ColorAdp border_color;
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;
@Override public Swt_layout_mgr Layout_mgr() {return null;}
@Override public void Layout_mgr_(Swt_layout_mgr v) {}
@Override public Swt_layout_data Layout_data() {return null;}
@Override public void Layout_data_(Swt_layout_data v) {}
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

@@ -13,3 +13,19 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.imgs.*;
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(Gfo_invk_cmd v);
void TaskbarVisible_set(boolean val);
void TaskbarParkingWindowFix(GxwElem form);
}

View File

@@ -13,3 +13,256 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
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;
import gplx.gfui.draws.*; import gplx.gfui.ipts.*; import gplx.gfui.gfxs.*; import gplx.gfui.imgs.*; import gplx.gfui.kits.swts.*;
public class GxwWin_lang extends JFrame implements GxwWin, WindowListener {
public void ShowWin() {this.setVisible(true);}
public void ShowWinModal() {}
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(Gfo_invk_cmd v) {whenLoadedCmd = v;} Gfo_invk_cmd whenLoadedCmd = Gfo_invk_cmd.Noop;
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.Exec();}
@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(Gfo_invk_cmd v) {whenLoadedCmd = v;} Gfo_invk_cmd whenLoadedCmd = Gfo_invk_cmd.Noop;
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.Exec();}
@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 ShowWinModal() {}
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(Gfo_invk_cmd v) {whenLoadedCmd = v;} Gfo_invk_cmd whenLoadedCmd = Gfo_invk_cmd.Noop;
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.Exec();}
@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;
public GxwElem control_() {return null;}
public GxwWin win_app_() {
return new Swt_win(display);
}
public GxwWin win_tool_(Keyval_hash ctorArgs) {
return null;
}
public GxwWin win_toaster_(Keyval_hash ctorArgs) {
return null;
}
public GxwElem lbl_() {return null;}
public GxwTextFld text_fld_() {return null;}
public GxwTextFld text_memo_() {return null;}
public GxwTextHtml text_html_() {return null;}
public GxwCheckListBox checkListBox_(Keyval_hash ctorArgs) {throw Err_.new_unimplemented();}
public GxwComboBox comboBox_() {return null;}
public GxwListBox listBox_() {return null;}
}
//#}

View File

@@ -13,3 +13,7 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.controls.standards.*;
public interface Gxw_grp extends GxwElem {
}

View File

@@ -13,3 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public interface Gxw_html extends GxwElem {
void Html_doc_html_load_by_mem(String html);
void Html_doc_html_load_by_url(Io_url 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);
Object Html_js_eval_script_as_obj (String script);
void Html_js_cbks_add (String js_func_name, Gfo_invk invk);
String Html_js_send_json (String name, String data);
void Html_invk_src_(Gfo_evt_itm v);
void Html_dispose();
}

View File

@@ -13,3 +13,12 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class Gxw_html_load_tid_ {
public static final byte Tid_mem = 0, Tid_url = 1;
public static byte Xto_tid(String s) {
if (String_.Eq(s, "mem")) return Tid_mem;
else if (String_.Eq(s, "url")) return Tid_url;
else throw Err_.new_unimplemented();
}
}

View File

@@ -13,3 +13,11 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
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);
}

View File

@@ -13,3 +13,21 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.controls.standards.*;
public interface Gxw_tab_mgr extends GxwElem {
ColorAdp Btns_selected_background(); void Btns_selected_background_(ColorAdp v);
ColorAdp Btns_selected_foreground(); void Btns_selected_foreground_(ColorAdp v);
ColorAdp Btns_unselected_background(); void Btns_unselected_background_(ColorAdp v);
ColorAdp Btns_unselected_foreground(); void Btns_unselected_foreground_(ColorAdp v);
int Btns_height(); void Btns_height_(int v);
boolean Btns_place_on_top(); void Btns_place_on_top_(boolean v);
boolean Btns_curved(); void Btns_curved_(boolean v);
boolean Btns_close_visible(); void Btns_close_visible_(boolean v);
boolean Btns_unselected_close_visible(); void Btns_unselected_close_visible_(boolean v);
Gxw_tab_itm Tabs_add(Gfui_tab_itm_data tab_data);
void Tabs_select_by_idx(int i);
void Tabs_close_by_idx(int i);
void Tabs_switch(int src, int trg);
}

View File

@@ -13,3 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.gxws; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.imgs.*;
public class MockForm extends GxwElem_mock_base implements GxwWin {
public IconAdp IconWin() {return null;} public void IconWin_set(IconAdp v) {}
public void ShowWin() {}
public void CloseWin() {}
public void HideWin() {}
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) {pin = val;} private boolean pin;
public void OpenedCmd_set(Gfo_invk_cmd v) {}
public void TaskbarVisible_set(boolean val) {}
public void TaskbarParkingWindowFix(GxwElem form) {}
public static final MockForm Instance = new MockForm(); MockForm() {}
}

View File

@@ -13,3 +13,60 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.langs.gfs.*;
import gplx.gfui.draws.*; import gplx.gfui.gfxs.*; import gplx.gfui.imgs.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.windows.*;
public class GfuiBtn extends GfuiElemBase {
@Override public boolean Click_able() {return true;}
@Override public void Click() {GfuiBtn.DoThis(this, clickMsg, clickInvkCmd);}
public GfuiBtn Click_msg_(GfoMsg v) {clickMsg = v; return this;} GfoMsg clickMsg;
public GfuiBtn Click_invk(Gfo_invk_cmd v) {clickInvkCmd = v; return this;} Gfo_invk_cmd clickInvkCmd;
@Override public boolean PaintCbk(PaintArgs args) {
super.PaintCbk(args);
if (this.Focus_has()) focusBorder.DrawData(args.Graphics());
this.TextMgr().DrawData(args.Graphics());
return true;
} GfuiBorderMgr focusBorder;
@Override public boolean SizeChangedCbk() {super.SizeChangedCbk(); GfuiBtn_.FocusBorderRect_set(focusBorder, this); this.Redraw(); return true;}
@Override public boolean FocusGotCbk() {super.FocusGotCbk(); this.Redraw(); return true;} // Redraw for focusBorder
@Override public boolean FocusLostCbk() {super.FocusLostCbk(); this.Redraw(); return true;} // Redraw for focusBorder
public ImageAdp Btn_img() {
Object o = Gfo_invk_.Invk_by_key(UnderElem(), Invk_btn_img);
return o == UnderElem() ? null : (ImageAdp)o; // NOTE: lgc guard
} public GfuiBtn Btn_img_(ImageAdp v) {Gfo_invk_.Invk_by_val(UnderElem(), Invk_btn_img_, v); return this;}
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.control_();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
focusBorder = GfuiBorderMgr.new_().All_(PenAdp_.new_(ColorAdp_.Gray, 1));
super.ctor_GfuiBox_base(ctorArgs);
this.TextMgr().AlignH_(GfuiAlign_.Mid);
this.Border().All_(PenAdp_.black_()); this.Border().Bounds_sync(RectAdp_.size_(this.Size().Op_subtract(1)));
GfuiBtn_.FocusBorderRect_set(focusBorder, this);
Inject_(GfuiBtnClickBnd.Instance);
Inject_(GfuiFocusXferBnd.Instance);
this.CustomDraw_set(true);
}
@Override public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
this.kit = kit;
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
focusBorder = GfuiBorderMgr.new_().All_(PenAdp_.new_(ColorAdp_.Gray, 1));
Inject_(GfuiBtnClickBnd.Instance);
Inject_(GfuiFocusXferBnd.Instance);
} Gfui_kit kit;
@gplx.Internal protected static void DoThis(GfuiElem click, GfoMsg clickMsg, Gfo_invk_cmd clickInvkCmd) {
try {
if (clickInvkCmd != null) {
GfsCtx ctx = GfsCtx.new_().MsgSrc_(click);
clickInvkCmd.Exec_by_ctx(ctx, GfoMsg_.Null);
}
else if (clickMsg != null && clickMsg != GfoMsg_.Null) {
GfsCtx ctx = GfsCtx.new_().MsgSrc_(click);
if (String_.Eq(clickMsg.Key(), "."))
GfsCore.Instance.ExecOne_to(ctx, click, clickMsg.Subs_getAt(0));
else
GfsCore.Instance.ExecOne(ctx, clickMsg);
}
} catch (Exception e) {GfuiEnv_.ShowMsg(Err_.Message_gplx_full(e));}
}
public static final String Invk_btn_img = "btn_img", Invk_btn_img_ = "btn_img_";
public static final String CFG_border_on_ = "border_on_";
}

View File

@@ -13,3 +13,28 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.elems.*;
import gplx.core.interfaces.*;
class GfuiBtnClickBnd implements InjectAble, Gfo_invk {
public void Inject(Object owner) {
GfuiElem elem = GfuiElem_.cast(owner);
IptBnd_.cmd_(IptCfg_.Null, elem, GfuiElemKeys.ActionExec_cmd, IptKey_.Enter, IptKey_.Space);
IptBnd_.cmd_(IptCfg_.Null, elem, GfuiElemKeys.Focus_cmd, IptMouseBtn_.Left);
IptBnd_.ipt_to_(IptCfg_.Null, elem, this, ExecMouseUp_cmd, IptEventType_.MouseUp, IptMouseBtn_.Left);
}
void ExecMouseUp(IptEventData iptData) {
GfuiElem elem = GfuiElem_.cast(iptData.Sender());
int x = iptData.MousePos().X(), y = iptData.MousePos().Y();
SizeAdp buttonSize = elem.Size();
if ( x >= 0 && x <= buttonSize.Width()
&& y >= 0 && y <= buttonSize.Height())
elem.Click();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, ExecMouseUp_cmd)) ExecMouseUp(IptEventData.ctx_(ctx, m));
else return Gfo_invk_.Rv_unhandled;
return this;
} static final String ExecMouseUp_cmd = "ExecMouseUp";
public static final GfuiBtnClickBnd Instance = new GfuiBtnClickBnd(); GfuiBtnClickBnd() {}
}

View File

@@ -13,3 +13,34 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.imgs.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiBtn_ {
public static GfuiBtn as_(Object obj) {return obj instanceof GfuiBtn ? (GfuiBtn)obj : null;}
public static GfuiBtn cast(Object obj) {try {return (GfuiBtn)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfuiBtn.class, obj);}}
public static GfuiBtn msg_(String key, GfuiElem owner, GfoMsg msg) {
GfuiBtn rv = new_(key); rv.Owner_(owner);
rv.Click_msg_(msg);
return rv;
}
public static GfuiBtn invk_(String key, GfuiElem owner, Gfo_invk invk, String m) {
GfuiBtn rv = new_(key); rv.Owner_(owner);
rv.Click_invk(Gfo_invk_cmd.New_by_key(invk, m));
return rv;
}
public static GfuiBtn kit_(Gfui_kit kit, String key, GxwElem elm, Keyval_hash ctorArgs) {
GfuiBtn rv = new GfuiBtn();
rv.ctor_kit_GfuiElemBase(kit, key, elm, ctorArgs);
return rv;
}
public static GfuiBtn new_(String key) {
GfuiBtn rv = new GfuiBtn();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
rv.Key_of_GfuiElem_(key);
return rv;
}
@gplx.Internal protected static void FocusBorderRect_set(GfuiBorderMgr borderMgr, GfuiElem elem) {
borderMgr.Bounds_sync(RectAdp_.new_(3, 3, elem.Width() - 6, elem.Height() - 6));
}
}

View File

@@ -13,3 +13,48 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.gfxs.*; import gplx.gfui.imgs.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.windows.*;
public class GfuiChkBox extends GfuiElemBase {
public boolean Val() {return val;} private boolean val;
public void Val_set(boolean val) {
this.val = val;
Gfo_evt_mgr_.Pub_val(this, "Check_end", val);
GfuiBtn.DoThis(this, clickMsg, clickInvkCmd);
}
public void Val_sync(boolean val) {
this.val = val;//(boolean)v; // NOTE: do not resend message
this.Redraw();
}
@gplx.Internal protected void Click_msg_(GfoMsg v) {clickMsg = v;} GfoMsg clickMsg;
@gplx.Internal protected GfuiChkBox Click_invk(Gfo_invk_cmd v) {clickInvkCmd = v; return this;} Gfo_invk_cmd clickInvkCmd;
public GfuiBorderMgr FocusBorder() {return focusBorder;} GfuiBorderMgr focusBorder = GfuiBorderMgr.new_();
@Override public boolean Click_able() {return true;}
@Override public void Click() {
Val_set(!val);
this.Redraw();
}
public GfuiAlign AlignH() {return alignH;} public void AlignH_set(GfuiAlign v) {alignH = v;} GfuiAlign alignH = GfuiAlign_.Mid;
public GfuiAlign AlignV() {return alignV;} public void AlignV_set(GfuiAlign v) {alignV = v;} GfuiAlign alignV = GfuiAlign_.Mid;
public PointAdp ChkAlignCustom() {return chkAlignCustom;} public void ChkAlignCustom_set(PointAdp val) {chkAlignCustom = val;} PointAdp chkAlignCustom = PointAdp_.Zero;
@gplx.Internal protected PenAdp ChkPen() {return chkPen;} PenAdp chkPen = PenAdp_.new_(ColorAdp_.Black);
@Override public boolean PaintCbk(PaintArgs args) {
super.PaintCbk(args);
GfuiChkBox_.DrawCheckBox(this, args.Graphics());
return true;
}
@Override public boolean SizeChangedCbk() {
boolean rv = super.SizeChangedCbk();
this.Redraw();
return rv;
}
@Override public boolean FocusGotCbk() {super.FocusGotCbk(); this.Redraw(); return true;} // Redraw for focusBorder
@Override public boolean FocusLostCbk() {super.FocusLostCbk(); this.Redraw(); return true;} // Redraw for focusBorder
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.lbl_();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
focusBorder.All_(PenAdp_.new_(ColorAdp_.Gray, 1));
Inject_(GfuiFocusXferBnd.Instance).Inject_(GfuiBtnClickBnd.Instance);
this.CustomDraw_set(true);
}
}

View File

@@ -13,3 +13,60 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.gfxs.*; import gplx.gfui.controls.elems.*;
public class GfuiChkBox_ {
public static GfuiChkBox as_(Object obj) {return obj instanceof GfuiChkBox ? (GfuiChkBox)obj : null;}
public static GfuiChkBox cast(Object obj) {try {return (GfuiChkBox)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfuiChkBox.class, obj);}}
@gplx.Internal protected static GfuiChkBox new_() {
GfuiChkBox rv = new GfuiChkBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
public static GfuiChkBox msg_(String key, GfuiElem owner, String text, GfoMsg msg) {
GfuiChkBox rv = new_(); rv.Owner_(owner, key).Text_any_(text);
rv.Click_msg_(msg);
return rv;
}
public static GfuiChkBox invk_(String key, GfuiElem owner, String text, Gfo_invk invk, String m) {
GfuiChkBox rv = new_(); rv.Owner_(owner, key).Text_any_(text);
rv.Click_invk(Gfo_invk_cmd.New_by_key(invk, m));
return rv;
}
public static GfuiChkBox noop_(String key, GfuiElem owner, String text) {
GfuiChkBox rv = new_(); rv.Owner_(owner, key); rv.Text_any_(text);
return rv;
}
public static RectAdp CboxRect(GfuiChkBox box) {
SizeAdp size = SizeAdp_.new_(12, 12);
PointAdp pos = GfuiAlign_.CalcInsideOf(box.AlignH(), box.AlignV(), size, box.Size(), box.ChkAlignCustom());
return RectAdp_.vector_(pos.Op_add(0, 0), size);
}
public static void DrawCheckBox(GfuiChkBox box, GfxAdp gfx) {
RectAdp cboxRect = CboxRect(box);
box.TextMgr().AlignH_(box.AlignH()).AlignV_(box.AlignV());
RectAdpF textRect = box.TextMgr().TextRect_calc(gfx);
int w = cboxRect.Width() + 4 + (int)textRect.Width();
int h = (int)textRect.Height(); // assume textRect.Height is >= cboxRect.Height
SizeAdp size = SizeAdp_.new_(w, h);
PointAdp pos = GfuiAlign_.CalcInsideOf(box.AlignH(), box.AlignV(), size, box.Size(), PointAdp_.Zero);
cboxRect = RectAdp_.vector_(pos.Op_add(0, 1), cboxRect.Size());
textRect = RectAdpF.new_(pos.X() + cboxRect.Width() + 4, textRect.Y(), textRect.Width(), textRect.Height());
box.TextMgr().TextRect_set(textRect);
box.TextMgr().DrawData(gfx);
gfx.DrawRect(box.ChkPen(), cboxRect.X(), cboxRect.Y(), cboxRect.Width(), cboxRect.Height());
if (box.Val()) {
gfx.DrawLine(box.ChkPen(), cboxRect.CornerTL().Op_add(3), cboxRect.CornerBR().Op_add(-3));
gfx.DrawLine(box.ChkPen(), cboxRect.CornerBL().Op_add(3, -3), cboxRect.CornerTR().Op_add(-3, 3));
}
if (box.Focus_has()) {
// -1 so border does not start right on top of text; RoundUp to give a little more space to edges
// +2 so that focusRect does not overlap mnemonic (in C#)
box.FocusBorder().Bounds_sync(RectAdp_.new_((int)textRect.X() - 1, (int)cboxRect.Y(), Float_.RoundUp(textRect.Width()), Float_.RoundUp(cboxRect.Height())));
box.FocusBorder().DrawData(gfx);
}
}
}

View File

@@ -13,3 +13,59 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*;
import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiComboBox extends GfuiElemBase {
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.combo = (GxwComboBox)this.UnderElem();
}
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.comboBox_();} private GxwComboBox combo;
public ColorAdp Border_color() {return combo.Border_color();} public void Border_color_(ColorAdp v) {combo.Border_color_(v);}
public int SelBgn() {return combo.SelBgn();} public void SelBgn_set(int v) {combo.SelBgn_set(v); Gfo_evt_mgr_.Pub(this, Evt__selection_start_changed);}
public int SelLen() {return combo.SelLen();} public void SelLen_set(int v) {combo.SelLen_set(v);}
public void Sel_(int bgn, int len) {combo.Sel_(bgn, len);}
public Object SelectedItm() {return combo.SelectedItm();} public void SelectedItm_set(Object v) {combo.SelectedItm_set(v);}
@Override public GfuiElem BackColor_(ColorAdp v) {
super.BackColor_(v);
combo.Items__backcolor_(v);
return this;
}
@Override public GfuiElem ForeColor_(ColorAdp v) {
super.ForeColor_(v);
combo.Items__forecolor_(v);
return this;
}
public String[] DataSource_as_str_ary() {return combo.DataSource_as_str_ary();}
public void DataSource_set(Object... ary) {combo.DataSource_set(ary);}
public String Text_fallback() {return combo.Text_fallback();}
public void Text_fallback_(String v) {combo.Text_fallback_(v);}
public int List_sel_idx() {return combo.List_sel_idx();}
public void List_sel_idx_(int v) {combo.List_sel_idx_(v);}
public boolean List_visible() {return combo.List_visible();}
public void List_visible_(boolean v) {combo.List_visible_(v);}
public void Items__update(String[] ary) {combo.Items__update(ary);}
public void Items__size_to_fit(int len) {combo.Items__size_to_fit(len);}
public void Items__visible_rows_(int v) {combo.Items__visible_rows_(v);}
public void Items__jump_len_(int v) {combo.Items__jump_len_(v);}
public void Items__backcolor_(ColorAdp v) {combo.Items__backcolor_(v);}
public void Items__forecolor_(ColorAdp v) {combo.Items__forecolor_(v);}
public void Margins_set(int left, int top, int right, int bot) {combo.Margins_set(left, top, right, bot);}
public static GfuiComboBox new_() {
GfuiComboBox rv = new GfuiComboBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
public static GfuiComboBox kit_(Gfui_kit kit, String key, GxwElem elm, Keyval_hash ctorArgs) {
GfuiComboBox rv = new GfuiComboBox();
rv.ctor_kit_GfuiElemBase(kit, key, elm, ctorArgs);
rv.combo = (GxwComboBox)elm;
return rv;
}
public static final String
Evt__selected_changed = "Selected_changed"
, Evt__selected_accepted = "Selected_accepted"
, Evt__selection_start_changed = "SelectionStartChanged"
;
}

View File

@@ -13,3 +13,26 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.gfxs.*; import gplx.gfui.imgs.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiLbl extends GfuiElemBase { // standard label does not support tooltips
@Override public void Click() {
int focusOrder = this.OwnerElem().SubElems().IndexOfA(this);
GfuiElem focusNext = this.OwnerElem().SubElems().Get_at(focusOrder + 1); // FIXME: incorporate into new FocusOrder
focusNext.Focus();
}
@Override public boolean PaintCbk(PaintArgs args) {
super.PaintCbk(args);
this.TextMgr().DrawData(args.Graphics());
return true;
}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.CustomDraw_set(true);
}
@Override public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
this.CustomDraw_set(true);
}
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.lbl_();}
}

View File

@@ -13,3 +13,38 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiLbl_ {
public static GfuiLbl sub_(String key, GfuiElem owner) {
GfuiLbl rv = new_();
rv.Owner_(owner, key); // must be after ctor, else "Error creating window handle"
rv.TextMgr().AlignH_(GfuiAlign_.Mid);
return rv;
}
public static GfuiLbl kit_(Gfui_kit kit, String key, GxwElem elm, Keyval_hash ctorArgs) {
GfuiLbl rv = new GfuiLbl();
rv.ctor_kit_GfuiElemBase(kit, key, elm, ctorArgs);
return rv;
}
public static GfuiLbl prefix_(String key, GfuiElem owner, String text) {
GfuiLbl rv = sub_(key, owner);
rv.Text_(text);
rv.TextMgr().AlignH_(GfuiAlign_.Left);
return rv;
}
public static GfuiLbl menu_(String key, GfuiElem owner, String text, String tipText) {
GfuiLbl rv = sub_(key, owner);
rv.Text_(text);
rv.TextMgr().AlignH_(GfuiAlign_.Mid);
rv.TipText_(tipText);
rv.Border().All_(PenAdp_.black_());
return rv;
}
public static final String Text_Null = null;
@gplx.Internal protected static GfuiLbl new_() {
GfuiLbl rv = new GfuiLbl();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
return rv;
}
}

View File

@@ -13,3 +13,30 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.lists.*; /*EnumerAble*/
import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiListBox extends GfuiElemBase {
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.listBox_();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
this.listBox = (GxwListBox)UnderElem();
}
public void Items_Add(Object o) {listBox.Items_Add(o);}
public void Items_Clear() {listBox.Items_Clear();}
public Object Items_SelObj() {return listBox.Items_SelObj();}
public void BindData(EnumerAble enumerable) {
for (Object item : enumerable)
this.listBox.Items_Add(item.toString());
}
public int Items_Count() {return listBox.Items_Count();}
public int Items_SelIdx() {return listBox.Items_SelIdx();} public void Items_SelIdx_set(int v) {listBox.Items_SelIdx_set(v);}
GxwListBox listBox;
public static GfuiListBox new_() {
GfuiListBox rv = new GfuiListBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
}

View File

@@ -13,3 +13,56 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*;
import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiTextBox extends GfuiElemBase {
public static final String SelectionStartChanged_evt = "SelectionStartChanged";
public boolean Border_on() {return textBox.Border_on();} public void Border_on_(boolean v) {BorderOn_set(v);}
public ColorAdp Border_color() {return textBox.Border_color();} public void Border_color_(ColorAdp v) {textBox.Border_color_(v);}
public int SelBgn() {return textBox.SelBgn();} public void SelBgn_set(int v) {textBox.SelBgn_set(v); Gfo_evt_mgr_.Pub(this, SelectionStartChanged_evt);}
public int SelLen() {return textBox.SelLen();} public void SelLen_set(int v) {textBox.SelLen_set(v);}
public String SelText() {
return String_.MidByLen(this.TextMgr().Val(), this.SelBgn(), this.SelLen());
}
public void Focus_select_all() {
this.Focus();
this.SelBgn_set(0);
int len = String_.Len(this.Text());
this.SelLen_set(len);
}
public boolean OverrideTabKey() {return textBox.OverrideTabKey();} public void OverrideTabKey_(boolean val) {textBox.OverrideTabKey_(val);}
public void Margins_set(int left, int top, int right, int bot) {textBox.Margins_set(left, top, right, bot);}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Margins_)) {
int u = m.ReadInt("u");
int l = m.ReadInt("l");
int d = m.ReadInt("d");
int r = m.ReadInt("r");
if (ctx.Deny()) return this;
Margins_set(l, u, r, d);
return this;
}
else return super.Invk (ctx, ikey, k, m);
} static final String Invk_Margins_ = "Margins_";
void BorderOn_set(boolean val) {
textBox.Border_on_(val);
if (val == false)
this.Height_(13); // WORKAROUND (WinForms): if border is off, height automatically becomes 13 and immutable for singleLine fields; affects statusBox in opal.imgs which will show with small gap over bottom of screen
}
@gplx.Internal @Override protected void Click_key_set_(String v) {}// TextBox's shouldn't have clickKeys; among other things, .Text is used to set ClickKey, which for textBox may be very large
@gplx.Internal protected void SetTextBox(GxwTextFld textBox) {this.textBox = textBox;}
public void CreateControlIfNeeded() {textBox.CreateControlIfNeeded();}
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.text_fld_();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
textBox = (GxwTextFld)this.UnderElem();
} GxwTextFld textBox;
@Override public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, Keyval_hash ctorArgs) {
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
textBox = (GxwTextFld)underElem;
}
public static final String CFG_border_on_ = "border_on_";
}

View File

@@ -13,3 +13,33 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class GfuiTextBox_ {
public static GfuiTextBox as_(Object obj) {return obj instanceof GfuiTextBox ? (GfuiTextBox)obj : null;}
public static GfuiTextBox cast(Object obj) {try {return (GfuiTextBox)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, GfuiTextBox.class, obj);}}
public static final String NewLine = "\n";
public static final String Ctor_Memo = "TextBox_Memo";
public static GfuiTextBox new_() {
GfuiTextBox rv = new GfuiTextBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
return rv;
}
public static GfuiTextBox fld_(String key, GfuiElem owner) {
GfuiTextBox rv = new_();
rv.Owner_(owner, key);
return rv;
}
public static GfuiTextMemo multi_(String key, GfuiElem owner) {
GfuiTextMemo rv = new GfuiTextMemo();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_true_());
rv.Key_of_GfuiElem_(key).Owner_(owner);
return rv;
}
public static GfuiTextBox kit_(Gfui_kit kit, String key, GxwTextFld wk_textBox, Keyval_hash ctorArgs) {
GfuiTextBox rv = new GfuiTextBox();
rv.ctor_kit_GfuiElemBase(kit, key, wk_textBox, ctorArgs);
return rv;
}
}

View File

@@ -13,3 +13,28 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.controls.gxws.*;
public class GfuiTextMemo extends GfuiTextBox { public int LinesPerScreen() {return textBox.LinesPerScreen();}
public int LinesTotal() {return textBox.LinesTotal();}
public int ScreenCount() {return Int_.DivAndRoundUp(this.LinesTotal(), this.LinesPerScreen());}
public int CharIndexOfFirst() {return textBox.CharIndexOfFirst();}
public int CharIndexOf(int lineIndex) {return textBox.CharIndexOf(lineIndex);}
public int CharIndexAtLine(int lineIndex) {return textBox.CharIndexOf(lineIndex);}
public int LineIndexOfFirst() {return textBox.LineIndexOfFirst();}
public int LineIndexOf(int charIndex) {return textBox.LineIndexOf(charIndex);}
public PointAdp PosOf(int charIndex) {return textBox.PosOf(charIndex);}
public void ScrollLineUp() {textBox.ScrollLineUp();}
public void ScrollLineDown() {textBox.ScrollLineDown();}
public void ScrollScreenUp() {textBox.ScrollScreenUp();}
public void ScrollScreenDown() {textBox.ScrollScreenDown();}
public void SelectionStart_toFirstChar() {textBox.SelectionStart_toFirstChar(); Gfo_evt_mgr_.Pub(this, SelectionStartChanged_evt);}
public void ScrollTillSelectionStartIsFirstLine() {textBox.ScrollTillSelectionStartIsFirstLine();}
@Override public GxwElem UnderElem_make(Keyval_hash ctorArgs) {return GxwElemFactory_.Instance.text_memo_();}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
textBox = (GxwTextMemo)UnderElem();
this.SetTextBox(textBox);
} GxwTextMemo textBox;
}

View File

@@ -13,3 +13,12 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class Gfui_grp extends GfuiElemBase {
public static Gfui_grp kit_(Gfui_kit kit, String key, GxwElem under, Keyval_hash ctor_args) {
Gfui_grp rv = new Gfui_grp();
rv.ctor_kit_GfuiElemBase(kit, key, under, ctor_args);
return rv;
}
}

View File

@@ -13,3 +13,58 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class Gfui_html extends GfuiElemBase {
public void Under_html_(Gxw_html v) {under = v;} private Gxw_html under;
public void Html_doc_html_load_by_mem(String html) {under.Html_doc_html_load_by_mem(html);}
public void Html_doc_html_load_by_url(Io_url path, String html) {under.Html_doc_html_load_by_url(path, html);}
public byte Html_doc_html_load_tid() {return under.Html_doc_html_load_tid();}
public void Html_doc_html_load_tid_(byte v) {under.Html_doc_html_load_tid_(v);}
public void Html_js_enabled_(boolean v) {under.Html_js_enabled_(v);}
@gplx.Virtual public String Html_js_eval_proc_as_str(String name, Object... args) {return under.Html_js_eval_proc_as_str(name, args);}
@gplx.Virtual public boolean Html_js_eval_proc_as_bool(String name, Object... args) {return under.Html_js_eval_proc_as_bool(name, args);}
public String Html_js_eval_script(String script) {return under.Html_js_eval_script(script);}
public Object Html_js_eval_script_as_obj(String script) {return under.Html_js_eval_script_as_obj(script);}
public String Html_js_send_json(String name, String data) {return under.Html_js_send_json(name, data);}
public void Html_js_cbks_add(String js_func_name, Gfo_invk invk) {under.Html_js_cbks_add(js_func_name, invk);}
public void Html_invk_src_(Gfo_evt_itm v) {under.Html_invk_src_(v);}
public void Html_dispose() {under.Html_dispose();}
@Override public GfuiElem Text_(String v) {
this.Html_doc_html_load_by_mem(v);
return this;
}
public static Gfui_html kit_(Gfui_kit kit, String key, Gxw_html under, Keyval_hash ctorArgs) {
Gfui_html rv = new Gfui_html();
rv.ctor_kit_GfuiElemBase(kit, key, (GxwElem)under, ctorArgs);
rv.under = under;
return rv;
}
public static Gfui_html mem_(String key, Gxw_html under) {
Gfui_html rv = new Gfui_html();
rv.Key_of_GfuiElem_(key);
rv.under = under;
return rv;
}
public static Object Js_args_exec(Gfo_invk invk, Object[] args) {
GfoMsg m = Js_args_to_msg(args);
return Gfo_invk_.Invk_by_msg(invk, m.Key(), m);
}
public static GfoMsg Js_args_to_msg(Object[] args) {
String proc = (String)args[0];
GfoMsg rv = GfoMsg_.new_parse_(proc);
for (int i = 1; i < args.length; i++)
rv.Add(Int_.To_str(i), args[i]); // NOTE: args[i] can be either String or String[]
return rv;
}
public static final String Atr_href = "href", Atr_title = "title", Atr_value = "value", Atr_innerHTML = "innerHTML", Atr_src = "src";
public static final String Elem_id_body = "body";
public static final String
Evt_location_changed = "location_changed"
, Evt_location_changing = "location_changing"
, Evt_link_hover = "link_hover"
, Evt_win_resized = "win_resized"
, Evt_zoom_changed = "zoom_changed"
;
}

View File

@@ -13,3 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class Gfui_tab_itm extends GfuiElemBase {
private Gxw_tab_itm under;
public String Tab_name() {return under.Tab_name();} public void Tab_name_(String v) {under.Tab_name_(v);}
public String Tab_tip_text() {return under.Tab_tip_text();} public void Tab_tip_text_(String v) {under.Tab_tip_text_(v);}
public void Subs_add(GfuiElem elem) {under.Subs_add(elem);}
public static Gfui_tab_itm kit_(Gfui_kit kit, String key, Gxw_tab_itm under, Keyval_hash ctor_args) {
Gfui_tab_itm rv = new Gfui_tab_itm();
// rv.ctor_kit_GfuiElemBase(kit, key, (GxwElem)under, ctor_args); // causes swt_tab_itm to break, since it's not a real Swt Control
rv.under = under;
return rv;
}
}

View File

@@ -13,3 +13,24 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class Gfui_tab_itm_data {
public Gfui_tab_itm_data(String key, int idx) {this.key = key; this.idx = idx;}
public String Key() {return key;} private String key;
public int Idx() {return idx;} public Gfui_tab_itm_data Idx_(int v) {idx = v; return this;} private int idx;
public String Name() {return name;} public void Name_(String v) {name = v;} private String name;
public String Tip_text() {return tip_text;} public Gfui_tab_itm_data Tip_text_(String v) {tip_text = v; return this;} private String tip_text;
public boolean Pinned() {return pinned;} public Gfui_tab_itm_data Pinned_(boolean v) {pinned = v; return this;} private boolean pinned;
public void Switch(Gfui_tab_itm_data comp) { // NOTE: key is invariant; idx should not be switched, as tab_idx remains the same; only contents have been switched
String tmp_str = name;
this.name = comp.name; comp.name = tmp_str;
tmp_str = tip_text;
this.tip_text = comp.tip_text; comp.tip_text = tmp_str;
}
public static int Get_idx_after_closing(int cur, int len) {
if (len < 1) return Idx_null; // 1 or 0 tabs; return -1
else if (cur == len - 1) return len - 2; // last tab; select_bwd
else return cur + 1; // else, select_fwd
}
public static final int Idx_null = -1;
}

View File

@@ -13,3 +13,18 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import org.junit.*;
public class Gfui_tab_itm_data_tst {
@Before public void init() {} private Gfui_tab_itm_data_fxt fxt = new Gfui_tab_itm_data_fxt();
@Test public void Get_idx_after_closing() {
fxt.Test_Get_idx_after_closing(0, 1, -1);
fxt.Test_Get_idx_after_closing(4, 5, 3);
fxt.Test_Get_idx_after_closing(3, 5, 4);
}
}
class Gfui_tab_itm_data_fxt {
public void Test_Get_idx_after_closing(int cur, int len, int expd) {
Tfds.Eq(expd, Gfui_tab_itm_data.Get_idx_after_closing(cur, len));
}
}

View File

@@ -13,3 +13,35 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.standards; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.kits.core.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*;
public class Gfui_tab_mgr extends GfuiElemBase {
public void Under_tab_mgr_(Gxw_tab_mgr v) {under = v;} private Gxw_tab_mgr under;
public ColorAdp Btns_selected_background() {return under.Btns_selected_background();} public void Btns_selected_background_(ColorAdp v) {under.Btns_selected_background_(v);}
public ColorAdp Btns_selected_foreground() {return under.Btns_selected_foreground();} public void Btns_selected_foreground_(ColorAdp v) {under.Btns_selected_foreground_(v);}
public ColorAdp Btns_unselected_background() {return under.Btns_unselected_background();} public void Btns_unselected_background_(ColorAdp v) {under.Btns_unselected_background_(v);}
public ColorAdp Btns_unselected_foreground() {return under.Btns_unselected_foreground();} public void Btns_unselected_foreground_(ColorAdp v) {under.Btns_unselected_foreground_(v);}
public Gfui_tab_itm Tabs_add(Gfui_tab_itm_data tab_data) {
Gxw_tab_itm tab_itm = under.Tabs_add(tab_data);
return Gfui_tab_itm.kit_(this.Kit(), tab_data.Key(), tab_itm, new Keyval_hash());
}
public int Btns_height() {return under.Btns_height();} public void Btns_height_(int v) {under.Btns_height_(v);}
public boolean Btns_place_on_top() {return under.Btns_place_on_top();} public void Btns_place_on_top_(boolean v) {under.Btns_place_on_top_(v);}
public boolean Btns_curved() {return under.Btns_curved();} public void Btns_curved_(boolean v) {under.Btns_curved_(v);}
public boolean Btns_close_visible_() {return under.Btns_close_visible();} public void Btns_close_visible_(boolean v) {under.Btns_close_visible_(v);}
public boolean Btns_unselected_close_visible() {return under.Btns_unselected_close_visible();} public void Btns_unselected_close_visible_(boolean v) {under.Btns_unselected_close_visible_(v);}
public void Tabs_select_by_idx(int idx) {under.Tabs_select_by_idx(idx);}
public void Tabs_close_by_idx(int idx) {under.Tabs_close_by_idx(idx);}
public void Tabs_switch(int src, int trg) {under.Tabs_switch(src, trg);}
public static Gfui_tab_mgr kit_(Gfui_kit kit, String key, Gxw_tab_mgr under, Keyval_hash ctor_args) {
Gfui_tab_mgr rv = new Gfui_tab_mgr();
rv.ctor_kit_GfuiElemBase(kit, key, (GxwElem)under, ctor_args);
rv.under = under;
return rv;
}
public static final String
Evt_tab_selected = "tab_selected"
, Evt_tab_closed = "tab_closed"
, Evt_tab_switched = "tab_switched"
;
}

View File

@@ -13,3 +13,77 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.interfaces.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.standards.*;
class TabBoxEvt_nameChange {
public static String Key = "TabBoxEvt_nameChange";
public static void Send(TabBoxMgr mgr, TabPnlItm itm) {
Gfo_evt_mgr_.Pub_val(mgr, Key, itm);
}
public static void Rcvd(TabBox tabBox, GfsCtx ctx, GfoMsg m) {
TabPnlItm itm = (TabPnlItm)m.CastObj("v");
GfuiBtn btn = GfuiBtn_.as_(tabBox.BtnBox().SubElems().Get_by(itm.Key()));
if (btn != null) // HACK: check needed b/c Gfds will raise UpdateCaption event before Creating tab
btn.Text_(itm.Name()).TipText_(itm.Name());
}
}
class TabBoxEvt_tabSelectByBtn {
public static String Key = "TabBoxEvt_tabSelectByBtn";
public static void Rcvd(Object sender, TabBox tabBox) {
GfuiBtn btn = (GfuiBtn)sender;
String key = btn.Key_of_GfuiElem();
TabBoxMgr mgr = tabBox.Mgr();
mgr.Select(mgr.Get_by(key));
}
}
class TabBnd_selectTab implements InjectAble, Gfo_invk {
public void Inject(Object obj) {
tabBox = TabBox_.cast(obj);
IptBnd_.cmd_to_(IptCfg_.Null, tabBox, this, SelectNext_cmd, IptKey_.add_(IptKey_.Ctrl, IptKey_.Tab), IptKey_.add_(IptKey_.Ctrl, IptKey_.PageDown));
IptBnd_.cmd_to_(IptCfg_.Null, tabBox, this, SelectPrev_cmd, IptKey_.add_(IptKey_.Ctrl, IptKey_.Tab, IptKey_.Shift), IptKey_.add_(IptKey_.Ctrl, IptKey_.PageUp));
}
void Select(GfoMsg msg, int delta) {
TabPnlItm curTab = tabBox.Mgr().CurTab();
int newIdx = TabBox_.Cycle(delta > 0, curTab.Idx(), tabBox.Mgr().Count());
tabBox.Tabs_Select(newIdx);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, SelectNext_cmd)) Select(m, 1);
else if (ctx.Match(k, SelectPrev_cmd)) Select(m, -1);
else return Gfo_invk_.Rv_unhandled;
return this;
} static final String SelectNext_cmd = "SelectNext", SelectPrev_cmd = "SelectPrev";
TabBox tabBox;
public static TabBnd_selectTab new_() {return new TabBnd_selectTab();} TabBnd_selectTab() {}
}
class TabBnd_reorderTab implements InjectAble, Gfo_invk {
public void Inject(Object owner) {
GfuiBtn btn = GfuiBtn_.cast(owner);
IptBnd_.cmd_to_(IptCfg_.Null, btn, this, MovePrev_cmd, IptKey_.add_(IptKey_.Ctrl, IptKey_.Left));
IptBnd_.cmd_to_(IptCfg_.Null, btn, this, MoveNext_cmd, IptKey_.add_(IptKey_.Ctrl, IptKey_.Right));
}
@gplx.Internal protected void MoveTab(GfuiBtn curBtn, int delta) {
TabPnlItm curItm = tabBox.Mgr().Get_by(curBtn.Key_of_GfuiElem());
int curIdx = curItm.Idx();
int newIdx = TabBox_.Cycle(delta > 0, curIdx, tabBox.Mgr().Count());
tabBox.Mgr().Move_to(curIdx, newIdx);
tabBox.Mgr().Reorder(0); // reorder all; exchanging curIdx for newIdx does not work when going from last to first (17 -> 0, but 0 -> 1)
tabBox.PnlBox().SubElems().Move_to(curIdx, newIdx);
TabBtnAreaMgr.Move_to(tabBox, curIdx, newIdx);
TabBoxEvt_orderChanged.Publish(tabBox, curIdx, newIdx);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, MoveNext_cmd)) MoveTab(GfuiBtn_.cast(ctx.MsgSrc()), 1);
else if (ctx.Match(k, MovePrev_cmd)) MoveTab(GfuiBtn_.cast(ctx.MsgSrc()), -1);
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String MoveNext_cmd = "MoveNext", MovePrev_cmd = "MovePrev";
public static TabBnd_reorderTab new_(TabBox tabBox) {
TabBnd_reorderTab rv = new TabBnd_reorderTab();
rv.tabBox = tabBox;
return rv;
} TabBnd_reorderTab() {}
TabBox tabBox;
}

View File

@@ -13,3 +13,141 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.layouts.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
public class TabBox extends GfuiElemBase {
public int Tabs_Count() {return mgr.Count();}
public TabPnlItm Tabs_SelectedItm() {return mgr.CurTab();}
public GfuiElem Tabs_FetchAt(int i) {return pnlBox.SubElems().Get_by(mgr.Get_at(i).Key());}
public GfuiElem Tabs_SelectedPnl() {return pnlBox.SubElems().Get_by(mgr.CurTab().Key());}
public void Tabs_Select(int idx) {mgr.Select(idx);}
public GfuiElem Tabs_Add(String key, String name) {
TabPnlItm newTab = mgr.Add(key, name);
TabBtnAreaMgr.Add(this, newTab);
GfuiElem pnl = TabPnlAreaMgr.Add(this, newTab);
mgr.Select(newTab); // always select added tab
return pnl;
}
public void Tabs_DelAt(int idx) {
TabBtnAreaMgr.Del(this, mgr.Get_at(idx));
TabPnlAreaMgr.Del(this, mgr.Get_at(idx));
mgr.Del_at(idx);
}
@gplx.Internal protected TabBoxMgr Mgr() {return mgr;} TabBoxMgr mgr = TabBoxMgr.new_();
public GfuiElem BtnBox() {return btnBox;} GfuiElem btnBox;
@gplx.Internal protected GfuiElem PnlBox() {return pnlBox;} GfuiElem pnlBox;
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, TabBoxEvt_tabSelectByBtn.Key)) TabBoxEvt_tabSelectByBtn.Rcvd(ctx.MsgSrc(), this);
else if (ctx.Match(k, TabBoxEvt_tabSelect.Key)) TabBoxEvt_tabSelect.Select(this, ctx, m);
else if (ctx.Match(k, TabBoxEvt_nameChange.Key)) TabBoxEvt_nameChange.Rcvd(this, ctx, m);
else return super.Invk(GfsCtx.Instance, 0, k, m);
return this;
}
@Override public void ctor_GfuiBox_base(Keyval_hash ctorArgs) {
super.ctor_GfuiBox_base(ctorArgs);
btnBox = TabBtnAreaMgr.new_("btnBox", this);
pnlBox = TabPnlAreaMgr.new_("pnlBox", this);
this.Inject_(TabBnd_selectTab.new_());
Gfo_evt_mgr_.Sub_same(mgr, TabBoxEvt_tabSelect.Key, this);
Gfo_evt_mgr_.Sub_same(mgr, TabBoxEvt_nameChange.Key, this);
this.Lyt_activate();
this.Lyt().Bands_add(GftBand.fillWidth_());
this.Lyt().Bands_add(GftBand.fillAll_());
}
}
class TabBtnAreaMgr {
public static GfuiElemBase new_(String key, GfuiElem owner) {
GfuiElemBase rv = new GfuiElemBase();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
rv.Owner_(owner, key);
return rv;
}
public static GfuiBtn Add(TabBox tabBox, TabPnlItm itm) {
GfuiElem btnBox = tabBox.BtnBox();
GfuiBtn btn = GfuiBtn_.new_(itm.Key());
btn.TipText_(itm.Name()).Text_(itm.Name()).Width_(80);
btn.TextMgr().Font_(btn.TextMgr().Font().Size_(8));
btn.Click_invk(Gfo_invk_cmd.New_by_key(tabBox, TabBoxEvt_tabSelectByBtn.Key));
btn.Inject_(TabBnd_reorderTab.new_(tabBox));
if (btnBox.SubElems().Count() > 0) { // place button after last
GfuiElem lastBtn = btnBox.SubElems().Get_at(btnBox.SubElems().Count() - 1);
btn.X_(lastBtn.X() + lastBtn.Width());
}
btnBox.SubElems().Add(btn);
return btn;
}
public static void Del(TabBox tabBox, TabPnlItm itm) {
GfuiElem btnBox = tabBox.BtnBox();
int idx = itm.Idx();
GfuiBtn btn = (GfuiBtn)btnBox.SubElems().Get_at(idx);
btnBox.SubElems().Del_at(idx);
for (int i = idx; i < btnBox.SubElems().Count(); i++) {
GfuiBtn cur = (GfuiBtn)btnBox.SubElems().Get_at(i);
cur.X_(cur.X() - btn.Width());
}
}
public static void Select(TabBox tabBox, TabPnlItm curTabItm, TabPnlItm newTabItm) {
if (curTabItm != null) {
GfuiBtn curBtn = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(curTabItm.Idx());
Select(curBtn, false);
}
GfuiBtn newBtn = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(newTabItm.Idx());
Select(newBtn, true);
}
public static void Move_to(TabBox tabBox, int curIdx, int newIdx) {
GfuiElemList btns = tabBox.BtnBox().SubElems();
btns.Move_to(curIdx, newIdx);
int curX = 0;
for (int i = 0; i < btns.Count(); i++) {
GfuiBtn cur = (GfuiBtn)btns.Get_at(i);
cur.X_(curX);
curX += cur.Width();
}
}
static void Select(GfuiBtn btn, boolean enabled) {
btn.TextMgr().Color_(enabled ? ColorAdp_.Black : ColorAdp_.Gray);
btn.TextMgr().Font().Style_(enabled ? FontStyleAdp_.Bold : FontStyleAdp_.Plain);
if (enabled)
btn.Border().All_(PenAdp_.black_());
else
btn.Border().None_();
}
}
class TabPnlAreaMgr {
public static GfuiElemBase new_(String key, GfuiElem owner) {
GfuiElemBase rv = new GfuiElemBase();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
rv.Owner_(owner, key);
rv.Lyt_activate();
return rv;
}
public static GfuiElemBase Add(TabBox tabBox, TabPnlItm itm) {
GfuiElem pnlBox = tabBox.PnlBox();
GfuiElemBase pnl = pnl_(tabBox, pnlBox, itm.Key());
return pnl;
}
public static void Del(TabBox tabBox, TabPnlItm itm) {
tabBox.PnlBox().SubElems().Del_at(itm.Idx());
((GfuiElemBase)tabBox.PnlBox()).Lyt().SubLyts().Del_at(itm.Idx());
}
public static void Select(TabBox tabBox, TabPnlItm curTabItm, TabPnlItm newTabItm) {
if (curTabItm != null) {
GfuiElem curTab = tabBox.PnlBox().SubElems().Get_at(curTabItm.Idx());
curTab.Visible_set(false);
}
GfuiElem newTab = tabBox.PnlBox().SubElems().Get_at(newTabItm.Idx());
newTab.Visible_set(true);
newTab.Zorder_front();
newTab.Focus();
}
@gplx.Internal protected static GfuiElemBase pnl_(TabBox tabBox, GfuiElem pnlBox, String key) {
GfuiElemBase rv = new GfuiElemBase();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
rv.Owner_(pnlBox, key);
rv.Lyt_activate();
rv.Lyt().Bands_add(GftBand.fillAll_());
((GfuiElemBase)pnlBox).Lyt().SubLyts().Add(GftGrid.new_().Bands_add(GftBand.fillAll_()));
return rv;
}
}

View File

@@ -13,3 +13,19 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class TabBoxEvt_orderChanged {
public int CurIdx() {return curIdx;} public TabBoxEvt_orderChanged CurIdx_(int v) {curIdx = v; return this;} int curIdx;
public int NewIdx() {return newIdx;} public TabBoxEvt_orderChanged NewIdx_(int v) {newIdx = v; return this;} int newIdx;
public static final String OrderChanged_evt = "OrderChanged_evt";
public static void Publish(TabBox tabBox, int curIdx, int newIdx) {
Gfo_evt_mgr_.Pub_vals(tabBox, OrderChanged_evt, Keyval_.new_("curIdx", curIdx), Keyval_.new_("newIdx", newIdx));
}
public static TabBoxEvt_orderChanged Handle(GfsCtx ctx, GfoMsg m) {
TabBoxEvt_orderChanged rv = new TabBoxEvt_orderChanged();
rv.curIdx = m.ReadInt("curIdx");
rv.newIdx = m.ReadInt("newIdx");
return rv;
}
}

View File

@@ -13,3 +13,23 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class TabBoxEvt_tabSelect {
public static String Key = "TabBoxEvt_tabSelect";
public static final String SelectedChanged_evt = "SelectedChanged_evt";
public static void Send(TabBoxMgr tabBoxMgr, TabPnlItm oldTab, TabPnlItm newTab) {
Gfo_evt_mgr_.Pub_val(tabBoxMgr, Key, new TabPnlItm[] {oldTab, newTab});
}
@gplx.Internal protected static void Select(TabBox tabBox, GfsCtx ctx, GfoMsg m) {
TabPnlItm[] ary = (TabPnlItm[])m.CastObj("v");
Select(tabBox, ary[0], ary[1]);
}
@gplx.Internal protected static void Select(TabBox tabBox, TabPnlItm curTabItm, TabPnlItm newTabItm) {
TabPnlAreaMgr.Select(tabBox, curTabItm, newTabItm);
TabBtnAreaMgr.Select(tabBox, curTabItm, newTabItm);
Gfo_evt_mgr_.Pub_val(tabBox, SelectedChanged_evt, newTabItm.Idx());
}
public static int Handle(GfsCtx ctx, GfoMsg m) {
return m.ReadInt("v");
}
}

View File

@@ -13,3 +13,43 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class TabBoxMgr implements Gfo_evt_mgr_owner {
public Gfo_evt_mgr Evt_mgr() {if (evt_mgr == null) evt_mgr = new Gfo_evt_mgr(this); return evt_mgr;} Gfo_evt_mgr evt_mgr;
public int Count() {return itms.Count();}
public TabPnlItm Get_by(String k) {return (TabPnlItm)itms.Get_by(k);}
public TabPnlItm Get_at(int i) {return (TabPnlItm)itms.Get_at(i);}
public TabPnlItm CurTab() {return curTab;} TabPnlItm curTab;
public TabPnlItm Add(String key, String name) {
TabPnlItm itm = TabPnlItm.new_(this, key).Name_(name).Idx_(itms.Count());
itms.Add(itm.Key(), itm);
return itm;
}
public void Del_at(int i) {
boolean isCur = i == curTab.Idx(), isLast = i == itms.Count() - 1;
TabPnlItm itm = this.Get_at(i);
itms.Del(itm.Key());
this.Reorder(i);
if (isCur) {
curTab = null; // must null out curTab since it has been deleted from itms; TODO_OLD: should raise Deleted event to delete btn,pnl,view; wait for rewrite of view
if (isLast) i--; // last was dropped; select prev; otherwise re-select idx (effectively, whatever tab drops into slot)
if (i >=0)
this.Select(i);
}
}
public void Select(int i) {Select((TabPnlItm)itms.Get_at(i));}
@gplx.Internal protected void Move_to(int src, int trg) {itms.Move_to(src, trg);}
@gplx.Internal protected void Reorder(int bgn) {
for (int i = bgn; i < itms.Count(); i++) {
TabPnlItm itm = (TabPnlItm)itms.Get_at(i);
itm.Idx_(i);
}
}
@gplx.Internal protected void Select(TabPnlItm newTab) {
TabPnlItm oldTab = curTab;
curTab = newTab;
TabBoxEvt_tabSelect.Send(this, oldTab, newTab);
}
Ordered_hash itms = Ordered_hash_.New();
@gplx.Internal protected static TabBoxMgr new_() {return new TabBoxMgr();} TabBoxMgr() {}
}

View File

@@ -13,3 +13,20 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.controls.elems.*;
public class TabBox_ {
public static TabBox as_(Object obj) {return obj instanceof TabBox ? (TabBox)obj : null;}
public static TabBox cast(Object obj) {try {return (TabBox)obj;} catch(Exception exc) {throw Err_.new_type_mismatch_w_exc(exc, TabBox.class, obj);}}
public static TabBox new_() {
TabBox rv = new TabBox();
rv.ctor_GfuiBox_base(GfuiElem_.init_focusAble_false_());
return rv;
}
public static int Cycle(boolean fwd, int val, int max) {
if (fwd)
return val == max - 1 ? 0 : val + 1;
else
return val == 0 ? max - 1 : val - 1;
}
}

View File

@@ -13,3 +13,117 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import org.junit.*; import gplx.gfui.controls.tabs.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
public class TabBox_tst {
// @Before public void setup() {
// fx = TabBoxFxt.new_();
// } TabBoxFxt fx;
@Test public void Add() {
// fx.Make(1).tst_Selected("0").FetchBtnAt(0).tst_X(0);
// fx.Make(3).tst_Selected("2").FetchBtnAt(2).tst_X(160);
}
// @Test public void Del_at() {
// fx.Make(2).Del_at(1).tst_Btns("0");
// fx.Make(2).Del_at(0).tst_Btns("1");
// fx.Make(3).Del_at(0).tst_Btns("1", "2");
// fx.Make(3).Del_at(1).tst_Btns("0", "2");
// fx.Make(3).Del_at(2).tst_Btns("0", "1");
// fx.Make(3).Select(1).Del_at(1).tst_Selected("2"); // 1 deleted; 2 shifted down into slot
// fx.Make(3).Select(1).Del_at(0).tst_Selected("1"); // 0 deleted; 1 still remains active (but will have idx of 0
// fx.Make(3).Select(2).Del_at(2).tst_Selected("1"); // 2 deleted; 1 selected
// }
// @Test public void Selected_byAdd() {
// fx.Make(2).Select(0).tst_Selected("0").Select(1).tst_Selected("1");
// }
// @Test public void Selected_byBtn() {
// fx.Make(2).tst_Selected("1");
//
// GfuiBtn btn = fx.TabBox().SubBtnArea().Get_at(0);
// btn.Click();
// fx.tst_Selected("0");
// }
// @Test public void ReorderTab() {
// fx.Make(3).Reorder(0, -1).tst_Raised(false);
// fx.Make(3).Reorder(2, 1).tst_Raised(false);
// fx.Make(3).Reorder(0, 1).tst_Btns("1", "0", "2").tst_Raised(true).tst_FocusOrder();
// fx.Make(3).Reorder(0, 2).tst_Btns("1", "2", "0").tst_Raised(true).tst_FocusOrder();
// fx.Make(3).Reorder(2, -1).tst_Btns("0", "2", "1").tst_Raised(true).tst_FocusOrder();
// fx.Make(3).Reorder(0, 1).Reorder(1, 2).tst_Btns("0", "2", "1").tst_Raised(true);//.tst_FocusOrder(); // FIXME: broken after FocusOrder set for entire form (instead of per container)
// }
}
class GfuiElemFxt {
public GfuiElem UnderElem() {return underElem;} GfuiElem underElem;
@gplx.Internal protected GfuiElemFxt tst_X(int expd) {Tfds.Eq(expd, underElem.X()); return this;}
public static GfuiElemFxt new_(GfuiElem elem) {
GfuiElemFxt rv = new GfuiElemFxt();
rv.underElem = elem;
return rv;
} GfuiElemFxt() {}
}
class TabBoxFxt implements Gfo_invk {
@gplx.Internal protected TabBox TabBox() {return tabBox;}
@gplx.Internal protected TabBoxFxt Make(int count) {
for (int i = 0; i < tabBox.Tabs_Count(); i++)
tabBox.Tabs_DelAt(0);
for (int i = 0; i < count; i++)
tabBox.Tabs_Add(Int_.To_str(i), Int_.To_str(i));
return this;
}
@gplx.Internal protected TabBoxFxt Del_at(int index) {tabBox.Tabs_DelAt(index); return this;}
// @gplx.Internal protected TabBoxFxt Select(int index) {tabBox.Tabs_Select(index); return this;}
@gplx.Internal protected GfuiElemFxt FetchBtnAt(int index) {
GfuiBtn btn = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(index);
GfuiElemFxt fx_elem = GfuiElemFxt.new_(btn);
return fx_elem;
}
// @gplx.Internal protected TabBoxFxt tst_BtnX(int idx, int expdX) {
// Tfds.Eq(expdX, tabBox.SubBtnArea().Get_at(idx).X());
// return this;
// }
@gplx.Internal protected TabBoxFxt tst_Selected(String expd) {
TabPnlItm curTab = tabBox.Tabs_SelectedItm();
GfuiBtn btn = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(curTab.Idx());
Tfds.Eq(expd, btn.Text());
return this;
}
@gplx.Internal protected TabBoxFxt tst_Btns(String... expd) {
String[] actl = new String[tabBox.Tabs_Count() ];
for (int i = 0; i < tabBox.Tabs_Count() ; i++) {
GfuiBtn button = (GfuiBtn)tabBox.BtnBox().SubElems().Get_at(i);
actl[i] = button.TextMgr().Val();
}
Tfds.Eq_ary(expd, actl);
return this;
}
// @gplx.Internal protected TabBoxFxt tst_Raised(boolean expd) {Tfds.Eq(expd, received != null); return this;}
// @gplx.Internal protected TabBoxFxt Reorder(int i, int delta) {
// tabBox.Width_(240); // needed for lytMgr
// TabBnd_reorderTab reorderBnd = TabBnd_reorderTab.Instance;
// received = null;
// TabPnl pnl = tabBox.Tabs_FetchAt(i);
// reorderBnd.MoveTab(pnl.SubTabBtn(), delta);
// return this;
// }
// @gplx.Internal protected TabBoxFxt tst_FocusOrder() {
// for (int i = 0; i < tabBox.SubBtnArea().SubZones().Get_at(0).Count(); i++) {
// GfuiElem subBtn = (GfuiElem)tabBox.SubBtnArea().SubZones().Get_at(0).Get_at(i);
// Tfds.Eq(i, subBtn.UnderElem().Core().Focus_index());
// }
// return this;
// }
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, OrderChangedReceived_cmd)) OrderChangedReceived(m);
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String OrderChangedReceived_cmd = "OrderChangedReceived";
TabBox tabBox;
public static TabBoxFxt new_() {
TabBoxFxt rv = new TabBoxFxt();
rv.tabBox = TabBox_.new_();
return rv;
} TabBoxFxt() {}
void OrderChangedReceived(GfoMsg msg) {
} //int[] received = null;
}

View File

@@ -13,3 +13,24 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.tabs; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
public class TabPnlItm {
public String Key() {return key;} private String key;
public String Name() {return name;}
public TabPnlItm Name_(String val) {
name = val;
TabBoxEvt_nameChange.Send(mgr, this);
return this;
} String name;
public int Idx() {return idx;}
@gplx.Internal protected TabPnlItm Idx_(int val) {
idx = val;
return this;
} int idx;
TabBoxMgr mgr;
public static TabPnlItm new_(TabBoxMgr mgr, String key) {
TabPnlItm rv = new TabPnlItm();
rv.mgr = mgr; rv.key = key;
return rv;
} TabPnlItm() {}
}

View File

@@ -13,3 +13,241 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.windows; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.draws.*; import gplx.gfui.ipts.*; import gplx.gfui.layouts.*; import gplx.gfui.envs.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.customs.*;
import gplx.core.envs.*;
import gplx.gfml.*; import gplx.langs.gfs.*;
public class GfoConsoleWin implements Gfo_invk, UsrMsgWkr {
GfuiWin win; GfoConsoleWinCmds cmds; GfuiTextBox statusBox, resultBox; GfuiTextBoxLogger logger;
public boolean Enabled() {return enabled;} public GfoConsoleWin Enabled_(boolean v) {enabled = v; return this;} private boolean enabled = true;
public GfuiWin Win() {return win;}
void Init() {
win = GfuiWin_.tool_("gfoConsoleWin");
win.Size_(700, 600);
PointAdp point = PointAdp_.new_(ScreenAdp_.Primary.Width() - win.Width(), ScreenAdp_.Primary.Height() - win.Height());
win.Pos_(point).Focus_default_("consoleBox"); win.QuitMode_(GfuiQuitMode.Suspend);
GfuiTextBox_.fld_("consoleFilBox", win);
GfuiTextBox consoleBox = GfuiTextBox_.multi_("consoleBox", win);
consoleBox.TextMgr().Font_(FontAdp.new_("Courier New", 8, FontStyleAdp_.Plain));
consoleBox.OverrideTabKey_(false);
resultBox = GfuiTextBox_.multi_("resultBox", win);
resultBox .OverrideTabKey_(false);
resultBox.TextMgr().Font_(FontAdp.new_("Courier New", 8, FontStyleAdp_.Plain));
statusBox = GfuiTextBox_.multi_("statusBox", win);
statusBox.OverrideTabKey_(false);
statusBox.TextMgr().Font_(FontAdp.new_("Courier New", 8, FontStyleAdp_.Plain));
win.Inject_(GfuiStatusBarBnd.new_());
cmds = new GfoConsoleWinCmds(this);
cmds.Owner_set(win); cmds.Init();
IptBnd_.cmd_to_(IptCfg_.Null, win, cmds, GfoConsoleWinCmds.Invk_Hide, IptKey_.Escape);
IptBnd_.cmd_to_(IptCfg_.Null, consoleBox, cmds, GfoConsoleWinCmds.Invk_Exec, IptKey_.add_(IptKey_.Ctrl, IptKey_.E));
IptBnd_.cmd_to_(IptCfg_.Null, consoleBox, cmds, GfoConsoleWinCmds.Invk_Save, IptKey_.add_(IptKey_.Ctrl, IptKey_.S));
IptBnd_.cmd_to_(IptCfg_.Null, consoleBox, cmds, GfoConsoleWinCmds.Invk_Load, IptKey_.add_(IptKey_.Ctrl, IptKey_.L));
IptBnd_.cmd_to_(IptCfg_.Null, consoleBox, cmds, GfoConsoleWinCmds.Invk_Help, IptKey_.add_(IptKey_.Ctrl, IptKey_.D));
IptBnd_.cmd_to_(IptCfg_.Null, consoleBox, cmds, GfoConsoleWinCmds.Invk_Clear, IptKey_.add_(IptKey_.Ctrl, IptKey_.Alt, IptKey_.C));
logger = new GfuiTextBoxLogger(this).Init(statusBox);
// gplx.core.ios.GfioApp.InitGfs();
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Note, this);
win.Lyt_activate();
win.Lyt().Bands_add(GftBand.fillWidth_());
win.Lyt().Bands_add(GftBand.fillWidth_().Len1_pct_(50));
win.Lyt().Bands_add(GftBand.fillWidth_().Len1_abs_(20));
win.Lyt().Bands_add(GftBand.fillWidth_().Len1_pct_(50));
win.Lyt().Bands_add(GftBand.fillWidth_());
}
void Show() {
if (win == null) this.Init();
win.Pin_(false);
win.Visible_set(true);
win.Zorder_front_and_focus();
}
public void ExecUsrMsg(int type, UsrMsg umsg) {
if (win == null) this.Init();
String s = umsg.To_str();
if (type == UsrMsgWkr_.Type_Warn) {
if (!win.Pin()) win.Pin_();
s = "!!warn!! " + umsg.To_str();
if (logger == null) return;
logger.Write(s);
}
else {
statusBox.Text_(statusBox.Text() + s);
statusBox.SelBgn_set(String_.Len(statusBox.Text()) - 1);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Show)) Show();
else return Gfo_invk_.Rv_unhandled;
return this;
} public static final String Invk_Show = "Show"
;
public static final GfoConsoleWin Instance = new GfoConsoleWin(); GfoConsoleWin() {}
}
class GfoConsoleWinCmds implements Gfo_invk {
GfuiWin win; GfuiTextBox consoleFilBox, consoleBox, statusBox, resultBox;
public void Owner_set(GfuiElem elem) {win = (GfuiWin)elem;}
public void Init() {
consoleFilBox = (GfuiTextBox)win.SubElems().Get_by("consoleFilBox");
consoleBox = (GfuiTextBox)win.SubElems().Get_by("consoleBox");
resultBox = (GfuiTextBox)win.SubElems().Get_by("resultBox");
statusBox = (GfuiTextBox)win.SubElems().Get_by("statusBox");
GfsCore.Instance.AddObj(this, "gfoConsoleWin");
GfsCore.Instance.ExecRegy("gplx.gfui.GfoConsoleWin.ini");
}
public void Results_add(String s) {
if (!String_.Has_at_end(s, GfuiTextBox_.NewLine))
s += GfuiTextBox_.NewLine;
statusBox.Text_(statusBox.Text() + s);
statusBox.SelBgn_set(String_.Len(statusBox.Text()) - 1);
}
void Hide() {win.Hide();}
void Exec(GfoMsg msg) {
String cmdText = consoleBox.SelLen() == 0 ? consoleBox.Text() : consoleBox.SelText();
String cmd = FixNewLines(cmdText);
GfoMsg runMsg = GfoMsg_.Null;
try {runMsg = GfsCore.Instance.MsgParser().ParseToMsg(cmd);} catch (Exception e) {statusBox.Text_("invalid gfml " + Err_.Message_gplx_full(e)); return;}
GfsCtx ctx = GfsCtx.new_();
Object rv = GfsCore.Instance.ExecMany(ctx, runMsg);
resultBox.Text_(Object_.Xto_str_strict_or_empty(rv));
}
void Help() {
statusBox.Text_("");
if (consoleBox.SelLen() == 0) return;
String cmdText = "help:'" + consoleBox.SelText() + "';";
String cmd = FixNewLines(cmdText);
GfoMsg runMsg = GfoMsg_.Null;
try {runMsg = GfmlDataNde.XtoMsgNoRoot(cmd);} catch (Exception e) {statusBox.Text_("invalid gfml " + Err_.Message_gplx_full(e)); return;}
GfsCtx ctx = GfsCtx.new_();
try {
Object rv = GfsCore.Instance.ExecOne(ctx, runMsg);
if (rv != Gfo_invk_.Rv_handled && rv != Gfo_invk_.Rv_unhandled) {
UsrDlg_.Instance.Note(Object_.Xto_str_strict_or_empty(rv));
}
// Results_add(FixNewLines(ctx.Results_XtoStr()));
} catch (Exception e) {statusBox.Text_("help failed " + Err_.Message_gplx_full(e)); return;}
}
void Save() {
String consoleFilStr = consoleFilBox.Text();
Io_url url = Io_url_.Empty;
if (String_.Len_eq_0(consoleFilStr)) {
url = GfuiIoDialogUtl.SelectFile();
consoleFilBox.Text_(url.Raw());
return;
}
else
url = Io_url_.new_any_(consoleFilStr);
Io_mgr.Instance.SaveFilStr(url, consoleBox.Text());
}
void Load() {
String consoleFilStr = consoleFilBox.Text();
Io_url dir = Io_url_.Empty;
if (String_.Len_eq_0(consoleFilStr))
dir = Io_url_.Empty;
else {
dir = Io_url_.new_any_(consoleFilStr);
dir = dir.OwnerDir();
}
Io_url url = GfuiIoDialogUtl.SelectFile(dir); if (url == Io_url_.Empty) return;
consoleBox.Text_(Io_mgr.Instance.LoadFilStr(url));
}
String FixNewLines(String cmd) {
cmd = String_.Replace(cmd, "\n", "\r\n");
cmd = String_.Replace(cmd, "\r\r", "\r");
return cmd;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_Exec)) Exec(m);
else if (ctx.Match(k, Invk_Hide)) Hide();
else if (ctx.Match(k, Invk_Save)) Save();
else if (ctx.Match(k, Invk_Load)) Load();
else if (ctx.Match(k, Invk_Help)) Help();
else if (ctx.Match(k, Invk_Clear)) statusBox.Text_("");
else if (ctx.Match(k, "consoleBox")) return consoleBox;
else if (ctx.Match(k, Invk_X_)) {
int v = m.ReadInt("v");
if (ctx.Deny()) return this;
win.X_(v);
}
else if (ctx.Match(k, Invk_Y_)) {
int v = m.ReadInt("v");
if (ctx.Deny()) return this;
win.Y_(v);
}
else if (ctx.Match(k, Invk_Width_)) {
int v = m.ReadInt("v");
if (ctx.Deny()) return this;
win.Width_(v);
}
else if (ctx.Match(k, Invk_Height_)) {
int v = m.ReadInt("v");
if (ctx.Deny()) return this;
win.Height_(v);
}
else if (ctx.Match(k, Invk_Enabled_)) {
boolean v = m.ReadBool("v");
if (ctx.Deny()) return this;
owner.Enabled_(v);
}
else if (ctx.Match(k, Invk_SaveUrl_)) {
Io_url v = m.ReadIoUrl("v");
if (ctx.Deny()) return this;
consoleFilBox.Text_(v.Xto_api());
consoleBox.Text_(Io_mgr.Instance.LoadFilStr(v));
}
else return win.Invk(ctx, ikey, k, m);
return this;
} public static final String Invk_Exec = "Exec", Invk_Hide = "Hide", Invk_Save = "Save", Invk_Load = "Load", Invk_Help = "Help", Invk_Clear = "Clear"
, Invk_X_ = "X_", Invk_Y_ = "Y_", Invk_Width_ = "Width_", Invk_Height_ = "Height_", Invk_Enabled_ = "Enabled_", Invk_SaveUrl_ = "SaveUrl_"
;
GfoConsoleWin owner;
public GfoConsoleWinCmds(GfoConsoleWin owner) {this.owner = owner;}
}
class GfuiTextBoxLogger implements Gfo_invk {
public GfuiTextBoxLogger Init(GfuiTextBox tbox) {
this.tbox = tbox;
win = tbox.OwnerWin();
timer = TimerAdp.new_(this, Tmr_cmd, 500, false);
return this;
}
public void Write(String s) {
if (!owner.Enabled()) return;
if (!win.Visible()) win.Visible_set(true);
textToShow += tbox.Text() + String_.as_(s)+ String_.CrLf;
long curTick = System_.Ticks();
// if (curTick - lastTick > 500) {
WriteText(textToShow);
textToShow = "";
timer.Enabled_off();
// }
// else
// timer.Enabled_on();
lastTick = curTick;
}
void WriteText(String text) {
if (!win.Visible()) return; // StatusForm not visible; return; otherwise .CreateControl will be called
tbox.CreateControlIfNeeded(); // otherwise will occasionally throw: Cannot call Invoke or InvokeAsync on a control until the window handle has been created
tbox.Invoke(Gfo_invk_cmd.New_by_val(this, Invk_WriteText_cmd, text));
}
void Invk_WriteText(String text) {
tbox.Text_(text);
tbox.SelBgn_set(String_.Len(text) - 1);
if (!tbox.Focus_has()) tbox.Focus();
}
void WhenTick() {
WriteText(textToShow);
textToShow = "";
timer.Enabled_off();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Tmr_cmd)) WhenTick();
else if (ctx.Match(k, Invk_WriteText_cmd)) Invk_WriteText(m.ReadStr("v"));
else return Gfo_invk_.Rv_unhandled;
return this;
}
String Invk_WriteText_cmd = "Invk_WriteText", Tmr_cmd = "Tmr";
GfoConsoleWin owner;
public GfuiTextBoxLogger(GfoConsoleWin owner) {this.owner = owner;}
GfuiTextBox tbox; GfuiWin win;
TimerAdp timer; long lastTick; String textToShow = "";
}

View File

@@ -13,3 +13,26 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.windows; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.elems.*;
public class GfuiBnd_win_host {
public GfuiWin HosterWin() {return hosterWin;} GfuiWin hosterWin;
public GfuiElem HosteeBox() {return hosteeBox;} GfuiElem hosteeBox;
public GfuiWin OwnerWin() {return ownerWin;} GfuiWin ownerWin;
public static GfuiBnd_win_host new_(GfuiElem elemToHost, GfuiWin ownerForm) {
GfuiBnd_win_host rv = new GfuiBnd_win_host();
rv.ctor_(elemToHost, ownerForm);
return rv;
}
void ctor_(GfuiElem elemToHost, GfuiWin ownerForm) {
this.hosteeBox = elemToHost;
this.ownerWin = ownerForm;
this.hosterWin = GfuiWin_.toaster_("hosterWin_" + elemToHost.Key_of_GfuiElem(), ownerForm);
hosterWin.IptBnds().EventsToFwd_set(IptEventType_.None);
hosterWin.Size_(hosteeBox.Size());
hosteeBox.Owner_(hosterWin);
hosterWin.TaskbarVisible_(false);
hosterWin.TaskbarParkingWindowFix(ownerForm); // else ContextMenu shows up as WindowsFormsParkingWindow
}
}

View File

@@ -13,3 +13,40 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.gfui.controls.windows; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
import gplx.core.interfaces.*;
import gplx.gfui.ipts.*; import gplx.gfui.controls.elems.*;
public class GfuiCmdForm implements Gfo_invk, InjectAble {
public void Inject(Object ownerObj) {
GfuiElem owner = (GfuiElem)ownerObj;
GfuiCmdForm.host_(key, cmdElem, owner);
}
public static GfuiCmdForm new_(String key, GfuiElem cmdElem) {
GfuiCmdForm rv = new GfuiCmdForm();
rv.key = key;
rv.cmdElem = cmdElem;
return rv;
} String key; GfuiElem cmdElem;
public static GfuiWin host_(String key, GfuiElem cmdElem, GfuiElem hostElem) {
GfuiWin rv = GfuiWin_.sub_(key, hostElem.OwnerWin()); rv.Size_(cmdElem.Size());
cmdElem.Owner_(rv);
GfuiCmdForm cmd = new GfuiCmdForm(); cmd.cmdForm = rv;
IptBnd_.cmd_to_(IptCfg_.Null, rv, cmd, HideMe_cmd, IptKey_.Escape);
IptBnd_.cmd_to_(IptCfg_.Null, hostElem, cmd, DoStuff, IptKey_.add_(IptKey_.Ctrl, IptKey_.Space), IptMouseBtn_.Right);
return rv;
}
GfuiWin cmdForm;
static final String DoStuff = "doStuff", HideMe_cmd = "HideMe";
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, DoStuff)) ActivateMe((GfuiElem)ctx.MsgSrc());
else if (ctx.Match(k, HideMe_cmd)) ((GfuiWin)ctx.MsgSrc()).Hide();
else return Gfo_invk_.Rv_unhandled;
return this;
}
void ActivateMe(GfuiElem elem) {
cmdForm.Pos_(elem.Pos().Op_add(elem.OwnerWin().Pos()));
cmdForm.Show();
}
}

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