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-10 23:00:43 -04:00
parent 0b5aa9aefe
commit 6eec99a713
157 changed files with 2148 additions and 975 deletions

View File

@@ -19,7 +19,7 @@ package gplx.gfui; import gplx.*;
import java.awt.event.KeyEvent;
import gplx.core.primitives.*;
public class IptKey_ {
private static EnmMgr enmMgr = EnmMgr.new_().BitRngBgn_(65536).BitRngEnd_(262144).Prefix_("key.");
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;}
@@ -29,13 +29,13 @@ public class IptKey_ {
int newVal = ary[0].Val();
for (int i = 1; i < ary.length; i++)
newVal = Enm_.FlipInt(true, newVal, ary[i].Val());
return getOrNew_(newVal);
return get_or_new_(newVal);
}
public static IptKey api_(int val) {
IptKey rv = (IptKey)enmMgr.Get(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 getOrNew_(enmMgr.GetVal(raw));}
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);
@@ -58,13 +58,13 @@ public class IptKey_ {
list.Del(key);
return (IptKey[])list.Xto_ary(IptKey.class);
}
static IptKey getOrNew_(int val) {
IptKey rv = (IptKey)enmMgr.Get(val);
return (rv == null) ? new_(val, enmMgr.GetStr(val)) : rv;
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_.HasAtBgn(name, "key.") ? name : "key." + name);
enmMgr.RegObj(val, name, rv);
enm_mgr.RegObj(val, name, rv);
return rv;
}
public static final int KeyCode_Shift = 65536, KeyCode_Ctrl = 131072, KeyCode_Alt = 262144;
@@ -100,6 +100,7 @@ public class IptKey_ {
, 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 OrderedHash ui_str_hash;
public static OrderedHash Ui_str_hash() {
@@ -140,10 +141,13 @@ public class IptKey_ {
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 (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().Fetch(Int_obj_ref.new_(val));
String key_str = key == null ? "key." + Int_.Xto_str(val) : key.Key();
String key_str = key == null ? "key.#" + Int_.Xto_str(val) : key.Key();
return rv + key_str;
}
}

View File

@@ -20,11 +20,20 @@ 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");
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

@@ -28,6 +28,7 @@ public interface Gxw_html extends GxwElem {
boolean Html_doc_find(String id, String find, boolean dir_fwd, boolean case_match, boolean wrap_find);
void Html_doc_body_focus();
void Html_doc_selection_focus_toggle();
boolean Html_doc_loaded();
String Html_elem_atr_get_str (String id, String atr_key);
boolean Html_elem_atr_get_bool (String id, String atr_key);
boolean Html_elem_atr_set (String id, String atr_key, String val);

View File

@@ -47,6 +47,7 @@ public class Gfui_html extends GfuiElemBase {
public String Html_active_atr_get_str(String atrKey, String or) {return under.Html_active_atr_get_str(atrKey, or);}
public void Html_js_enabled_(boolean v) {under.Html_js_enabled_(v);}
public void Html_js_eval_proc(String name, String... args) {under.Html_js_eval_proc(name, args);}
public boolean Html_doc_loaded() {return under.Html_doc_loaded();}
public String Html_js_eval_script(String script) {return under.Html_js_eval_script(script);}
public void Html_js_cbks_add(String js_func_name, GfoInvkAble invk) {under.Html_js_cbks_add(js_func_name, invk);}
public void Html_invk_src_(GfoEvObj v) {under.Html_invk_src_(v);}

View File

@@ -25,6 +25,7 @@ public class Gfui_html_cfg implements GfoInvkAble {
public String Doc_selected_get_href_or_text() {return Exec_fmt(fmtr_doc_selected_get_href_or_text);} private Bry_fmtr fmtr_doc_selected_get_href_or_text = Bry_fmtr.keys_();
public String Doc_selected_get_src_or_empty() {return Exec_fmt(fmtr_doc_selected_get_src_or_empty);} private Bry_fmtr fmtr_doc_selected_get_src_or_empty = Bry_fmtr.keys_();
public String Doc_selected_get_active_or_selection() {return Exec_fmt(fmtr_doc_selected_get_active_or_selection);} private Bry_fmtr fmtr_doc_selected_get_active_or_selection = Bry_fmtr.keys_();
public String Doc_loaded() {return Exec_fmt(fmtr_doc_loaded);} private Bry_fmtr fmtr_doc_loaded = Bry_fmtr.keys_();
public String Doc_find_html(String find, boolean dir_fwd, boolean case_match, boolean wrap_find, boolean search_text_is_diff, int prv_find_bgn) {
return Exec_fmt(fmtr_doc_find_html, find, Bool_.Xto_str_lower(dir_fwd), Bool_.Xto_str_lower(case_match), Bool_.Xto_str_lower(wrap_find), Bool_.Xto_str_lower(search_text_is_diff), Int_.Xto_str(prv_find_bgn));
} private Bry_fmtr fmtr_doc_find_html = Bry_fmtr.keys_("find_text", "dir_fwd", "case_match", "wrap_find", "find_text_is_diff", "prv_find_bgn");
@@ -74,6 +75,7 @@ public class Gfui_html_cfg implements GfoInvkAble {
else if (ctx.Match(k, Invk_doc_selected_get_active_or_selection_)) fmtr_doc_selected_get_active_or_selection.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_doc_find_html_)) fmtr_doc_find_html.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_doc_find_edit_)) fmtr_doc_find_edit.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_doc_loaded_)) fmtr_doc_loaded.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_elem_atr_get_)) fmtr_elem_atr_get.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_elem_atr_get_toString_)) fmtr_elem_atr_get_toString.Fmt_(m.ReadBry("v"));
else if (ctx.Match(k, Invk_elem_atr_set_)) fmtr_elem_atr_set.Fmt_(m.ReadBry("v"));
@@ -102,7 +104,7 @@ public class Gfui_html_cfg implements GfoInvkAble {
node_path.Val_(node_path_val);
}
public static final String Invk_debug_file_ = "debug_file_"
, Invk_doc_html_ = "doc_html_", Invk_doc_body_focus_ = "doc_body_focus_", Invk_doc_selection_focus_toggle_ = "doc_selection_focus_toggle_"
, Invk_doc_html_ = "doc_html_", Invk_doc_body_focus_ = "doc_body_focus_", Invk_doc_selection_focus_toggle_ = "doc_selection_focus_toggle_", Invk_doc_loaded_ = "doc_loaded"
, Invk_doc_active_atr_get_ = "doc_active_atr_get_", Invk_doc_find_html_ = "doc_find_html_", Invk_doc_find_edit_ = "doc_find_edit_"
, Invk_doc_selected_get_text_or_href_ = "doc_selected_get_text_or_href_", Invk_doc_selected_get_href_or_text_ = "doc_selected_get_href_or_text_", Invk_doc_selected_get_src_or_empty_ = "doc_selected_get_src_or_empty_", Invk_doc_selected_get_active_or_selection_ = "doc_selected_get_active_or_selection_"
, Invk_win_print_preview_ = "win_print_preview_"

View File

@@ -25,6 +25,7 @@ class Mem_html extends GxwTextMemo_lang implements Gxw_html { public String Htm
public String Html_doc_selected_get_href_or_text() {return "";}
public String Html_doc_selected_get_src_or_empty() {return "";}
public String Html_doc_selected_get_active_or_selection() {return "";}
public boolean Html_doc_loaded() {return true;}
public boolean Html_window_print_preview() {return false;}
public void Html_invk_src_(GfoEvObj v) {}
public String Html_elem_atr_get_str(String elem_id, String atr_key) {

View File

@@ -75,6 +75,7 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
public String Html_doc_selected_get_src_or_empty() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_src_or_empty());}
public String Html_doc_selected_get_active_or_selection() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_active_or_selection());}
public void Html_doc_body_focus() {Eval_script_as_exec(kit.Html_cfg().Doc_body_focus());}
public boolean Html_doc_loaded() {return Bool_.parse_((String)Eval_script(kit.Html_cfg().Doc_loaded()));}
public void Html_doc_selection_focus_toggle() {Eval_script_as_exec(kit.Html_cfg().Doc_selection_focus_toggle());}
public String Html_elem_atr_get_str(String elem_id, String atr_key) {return Eval_script_as_str(kit.Html_cfg().Elem_atr_get(elem_id, atr_key));}
public boolean Html_elem_atr_get_bool(String elem_id, String atr_key) {return Bool_.parse_((String)Eval_script(kit.Html_cfg().Elem_atr_get_toString(elem_id, atr_key)));}