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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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