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-05-03 22:30:22 -04:00
parent f4b95f5ce6
commit 0b5aa9aefe
207 changed files with 2339 additions and 1460 deletions

View File

@@ -19,6 +19,8 @@ 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) {

View File

@@ -21,7 +21,7 @@ public class IptBndMgr implements SrlAble {
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);}
@gplx.Internal protected void Clear() {hash.Clear(); curTypes = IptEventType_.None; ClearLists(); chainMgr.Clear();}
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()))
@@ -40,7 +40,7 @@ public class IptBndMgr implements SrlAble {
cfg.Owners_del(ptr.CfgKey());
for (IptBndHash list : regy) {
for (int j = 0; j < list.Count(); j++) {
IptBndListItm itmList = list.GetAt(j);
IptBndListItm itmList = list.Get_at(j);
for (int k = 0; k < itmList.Count(); k++) {
IptBnd bnd = itmList.FetchAt(k);
if (String_.Eq(ptr.BndKey(), bnd.Key())) {
@@ -60,7 +60,7 @@ public class IptBndMgr implements SrlAble {
IptBnd old = null;
for (IptBndHash list : regy) {
for (int j = 0; j < list.Count(); j++) {
IptBndListItm itmList = list.GetAt(j);
IptBndListItm itmList = list.Get_at(j);
for (int i = 0; i < itmList.Count(); i++) {
IptBnd bnd = itmList.FetchAt(i);
if (String_.Eq(key, bnd.Key())) {
@@ -89,7 +89,7 @@ public class IptBndMgr implements SrlAble {
IptBndHash list = regy[i];
int list_len = list.Count();
for (int j = 0; j < list_len; j++) {
IptBndListItm bnds = list.GetAt(j);
IptBndListItm bnds = list.Get_at(j);
int bnds_len = bnds.Count();
for (int k = 0; k < bnds_len; k++) {
IptBnd itm_bnd = bnds.FetchAt(k);
@@ -129,7 +129,7 @@ public class IptBndMgr implements SrlAble {
IptBndHash list = regy[AryIdx(evData.EventType())];
String key = evData.EventArg().Key();
if (!String_.Eq(chainMgr.ActiveKey(), "")) key = chainMgr.ActiveKey() + key;
IptBndListItm itm = list.Get(key);
IptBndListItm itm = list.Get_by(key);
String chainP = "";
if (evData.EventType() == IptEventType_.KeyDown) {
chainP = chainMgr.Process(evData.EventArg());
@@ -170,20 +170,27 @@ public class IptBndMgr implements SrlAble {
}
}
class IptBndHash implements SrlAble {
private IptBndListItm wildcard_list;
public IptEventType EventType() {return eventType;} IptEventType eventType;
public int Count() {return hash.Count();}
public IptBndListItm Get(String iptKey) {return (IptBndListItm)hash.Fetch(iptKey);}
public IptBndListItm GetAt(int i) {return (IptBndListItm)hash.FetchAt(i);}
public IptBndListItm Get_by(String key) {return wildcard_list == null ? (IptBndListItm)hash.Fetch(key) : wildcard_list;}
public IptBndListItm Get_at(int i) {return (IptBndListItm)hash.FetchAt(i);}
public void Add(IptBnd bnd) {
for (int i = 0; i < bnd.Ipts().Count(); i++) {
IptArg arg = (IptArg)bnd.Ipts().FetchAt(i);
if (!IptArg_.EventType_match(arg, eventType)) continue; // bnd may have multiple ipts of different evTypes; only add bnd if evType matches
IptBndListItm itm = (IptBndListItm)hash.Fetch(arg.Key());
if (itm == null) {
itm = new IptBndListItm(arg.Key());
hash.Add(arg.Key(), itm);
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.Fetch(arg.Key());
if (itm == null) {
itm = new IptBndListItm(arg.Key());
hash.Add(arg.Key(), itm);
}
itm.Add(bnd);
}
itm.Add(bnd);
}
}
public void Del(IptBnd bnd) {

View File

@@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptKey implements IptArg {
public String Key() {return key;} private String key;
@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());}
@gplx.Internal protected int Val() {return val;} int val;
@gplx.Internal protected IptKey(int val, String key) {this.val = val; this.key = key;}
}

View File

@@ -24,8 +24,8 @@ class IptKeyStrMgr {
}
public String XtoStr(IptKey key) {
if (literals == null) Init();
Object rvObj = literals.Fetch(key.Val());
return rvObj == null ? String_.Empty : (String)rvObj;
Object rv = literals.Fetch(key.Val());
return rv == null ? String_.Empty : (String)rv;
}
public void XtoIptKeyAry(ListAdp list) {
if (literals == null) Init();

View File

@@ -17,9 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.event.KeyEvent;
public class IptKey_ {
import gplx.core.primitives.*;
public class IptKey_ {
private static EnmMgr enmMgr = 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 Err_.type_mismatch_exc_(exc, IptKey.class, obj);}}
public static IptKey add_(IptKey... ary) {
@@ -99,4 +101,49 @@ public class IptKey_ {
, Quote = new_(222, "quote")
, Shift = new_(KeyCode_Shift, "shift"), Ctrl = new_(KeyCode_Ctrl, "ctrl"), Alt = new_(KeyCode_Alt, "alt")
;
private static OrderedHash ui_str_hash;
public static OrderedHash Ui_str_hash() {
if (ui_str_hash == null) {
ui_str_hash = OrderedHash_.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(OrderedHash hash, IptKey... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
IptKey key = ary[i];
hash.AddReplace(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 + "+";
IptKey key = (IptKey)IptKey_.Ui_str_hash().Fetch(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,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
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+key.0");
}
}
class IptKey__fxt {
public void Test_to_str(int keycode, String expd) {
Tfds.Eq(expd, IptKey_.To_str(keycode));
}
}