2021-11-28 08:16:54 -05:00
|
|
|
/*
|
|
|
|
|
XOWA: the XOWA Offline Wiki Application
|
|
|
|
|
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
|
|
|
|
|
|
|
|
|
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
|
|
|
|
or alternatively under the terms of the Apache License Version 2.0.
|
|
|
|
|
|
|
|
|
|
You may use XOWA according to either of these licenses as is most appropriate
|
|
|
|
|
for your project on a case-by-case basis.
|
|
|
|
|
|
|
|
|
|
The terms of each license can be found in the source code repository:
|
|
|
|
|
|
|
|
|
|
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
|
|
|
|
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|
|
|
|
*/
|
|
|
|
|
package gplx.gfui.controls.windows; import gplx.Err_;
|
|
|
|
|
import gplx.List_adp;
|
|
|
|
|
import gplx.List_adp_;
|
|
|
|
|
import gplx.gfui.controls.elems.GfuiElem;
|
|
|
|
|
import gplx.gfui.controls.gxws.GxwElem;
|
|
|
|
|
import gplx.gfui.controls.gxws.GxwTextMemo_lang;
|
2017-10-23 20:50:50 -04:00
|
|
|
import java.awt.Component;
|
|
|
|
|
import java.awt.Container;
|
|
|
|
|
import java.awt.FocusTraversalPolicy;
|
|
|
|
|
public class GfuiWinFocusMgr {
|
|
|
|
|
public List_adp SubElems() {return subElems;} List_adp subElems = List_adp_.New();
|
|
|
|
|
public void InitForm() {this.Init(win);}
|
|
|
|
|
public void Init(GfuiWin win) {
|
|
|
|
|
subElems.Clear();
|
|
|
|
|
InitRecursive(win, 0);
|
|
|
|
|
}
|
|
|
|
|
int InitRecursive(GfuiElem owner, int focusIdx) {
|
|
|
|
|
for (int i = 0; i < owner.SubElems().Count(); i++) {
|
|
|
|
|
GfuiElem sub = (GfuiElem)owner.SubElems().Get_at(i);
|
|
|
|
|
if (sub.Focus_able()) {
|
|
|
|
|
sub.Focus_idx_(focusIdx++);
|
|
|
|
|
subElems.Add(sub);
|
|
|
|
|
}
|
|
|
|
|
focusIdx = InitRecursive(sub, focusIdx);
|
|
|
|
|
}
|
|
|
|
|
return focusIdx;
|
|
|
|
|
}
|
|
|
|
|
public GfuiElem Focus(boolean fwd, int cur) {
|
|
|
|
|
int nxt = fwd
|
2021-12-01 07:49:25 -05:00
|
|
|
? cur == subElems.IdxLast() ? 0 : ++cur
|
|
|
|
|
: cur == 0 ? subElems.IdxLast() : --cur;
|
2017-10-23 20:50:50 -04:00
|
|
|
GfuiElem elm = (GfuiElem)subElems.Get_at(nxt);
|
|
|
|
|
elm.Focus();
|
|
|
|
|
return elm;
|
|
|
|
|
}
|
|
|
|
|
GfuiWin win;
|
|
|
|
|
public static GfuiWinFocusMgr new_(GfuiWin win) {
|
|
|
|
|
GfuiWinFocusMgr rv = new GfuiWinFocusMgr();
|
|
|
|
|
rv.win = win;
|
|
|
|
|
return rv;
|
|
|
|
|
} GfuiWinFocusMgr() {}
|
|
|
|
|
}
|
|
|
|
|
class FocusTraversalPolicy_cls_base extends FocusTraversalPolicy {
|
|
|
|
|
List_adp elems; GfuiWinFocusMgr formFocusMgr;
|
|
|
|
|
public FocusTraversalPolicy_cls_base(GfuiWinFocusMgr formFocusMgr) {
|
|
|
|
|
this.elems = formFocusMgr.subElems;
|
|
|
|
|
this.formFocusMgr = formFocusMgr;
|
|
|
|
|
}
|
2021-12-01 07:49:25 -05:00
|
|
|
boolean elems_empty() {return elems.Len() == 0;}
|
2017-10-23 20:50:50 -04:00
|
|
|
public Component getComponentAfter(Container focusCycleRoot, Component c) {
|
|
|
|
|
formFocusMgr.InitForm();
|
|
|
|
|
if (elems_empty()) return c;
|
|
|
|
|
GxwElem gxw = GxwElemOf(c);
|
|
|
|
|
int orig = gxw.Core().Focus_index();
|
|
|
|
|
int idx = orig;
|
|
|
|
|
while (true) {
|
|
|
|
|
idx++;
|
2021-12-01 07:49:25 -05:00
|
|
|
if (idx == elems.Len())
|
2017-10-23 20:50:50 -04:00
|
|
|
idx = 0;
|
|
|
|
|
GfuiElem elem = null;
|
|
|
|
|
try {elem = (GfuiElem)elems.Get_at(idx);}
|
|
|
|
|
catch (Exception e) {
|
2021-11-28 08:16:54 -05:00
|
|
|
System.out.println("getComponentAfter:" + e.getMessage() + ":" + idx);
|
2017-10-23 20:50:50 -04:00
|
|
|
Err_.Noop(e);
|
|
|
|
|
}
|
|
|
|
|
if (elem == null) return c; // FIXME: why is elem null?; REP: add new tab through history and then close out
|
|
|
|
|
if (elem.Focus_able() && elem.Visible()) {
|
|
|
|
|
if (elem.UnderElem() instanceof GxwTextMemo_lang) {
|
|
|
|
|
GxwTextMemo_lang xx = (GxwTextMemo_lang)elem.UnderElem();
|
|
|
|
|
return xx.Inner();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return (Component)elem.UnderElem();
|
|
|
|
|
}
|
|
|
|
|
if (idx == orig)
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Component getComponentBefore(Container focusCycleRoot, Component c) {
|
|
|
|
|
formFocusMgr.InitForm();
|
|
|
|
|
if (elems_empty()) return c;
|
|
|
|
|
GxwElem gxw = GxwElemOf(c);
|
|
|
|
|
int orig = gxw.Core().Focus_index();
|
|
|
|
|
int idx = orig;
|
|
|
|
|
while (true) {
|
|
|
|
|
idx--;
|
|
|
|
|
if (idx == -1)
|
2021-12-01 07:49:25 -05:00
|
|
|
idx = elems.Len() - List_adp_.Base1;
|
2017-10-23 20:50:50 -04:00
|
|
|
GfuiElem elem = null;
|
|
|
|
|
try {
|
|
|
|
|
elem = (GfuiElem)elems.Get_at(idx);
|
|
|
|
|
// System.out.println(elem.Key_of_GfuiElem() + " " + elem.Focus_able() + " " + elem.Visible());
|
|
|
|
|
if (elem.getClass().getName().equals("gplx.gfds.gbu.GbuGrid") && elem.Key_of_GfuiElem().equals("grid0")) {
|
|
|
|
|
System.out.println(elem.Key_of_GfuiElem() + " " + elem.Focus_able() + " " + elem.Visible());
|
|
|
|
|
System.out.println(elem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
2021-11-28 08:16:54 -05:00
|
|
|
System.out.println("getComponentBefore:" + e.getMessage() + ":" + idx);
|
2017-10-23 20:50:50 -04:00
|
|
|
Err_.Noop(e);
|
|
|
|
|
}
|
|
|
|
|
if (elem == null) return c; // FIXME: why is elem null?; REP: add new tab through history and then close out
|
|
|
|
|
if (elem.Focus_able() && elem.Visible()) {
|
|
|
|
|
if (elem.UnderElem() instanceof GxwTextMemo_lang) {
|
|
|
|
|
GxwTextMemo_lang xx = (GxwTextMemo_lang)elem.UnderElem();
|
|
|
|
|
return xx.Inner();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return (Component)elem.UnderElem();
|
|
|
|
|
}
|
|
|
|
|
if (idx == orig)
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Component getDefaultComponent(Container focusCycleRoot) {return getFirstComponent(focusCycleRoot);}
|
|
|
|
|
public Component getFirstComponent(Container focusCycleRoot) {return elems_empty() ? focusCycleRoot : (Component)FetchAt(0).UnderElem();}
|
2021-12-01 07:49:25 -05:00
|
|
|
public Component getLastComponent(Container focusCycleRoot) {return elems_empty() ? focusCycleRoot : (Component)FetchAt(elems.Len() - 1).UnderElem();}
|
2017-10-23 20:50:50 -04:00
|
|
|
GfuiElem FetchAt(int idx) {return (GfuiElem)elems.Get_at(idx);}
|
|
|
|
|
GxwElem GxwElemOf(Component c) {
|
|
|
|
|
if (GxwElem.class.isAssignableFrom(c.getClass())) return (GxwElem)c;
|
|
|
|
|
return (GxwElem)c.getParent(); // HACK: occurs for JComboBox when editable is true; focus is on MetalComboBox, with parent of JComboBox
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#}
|