public void mousemove(Coord c) { for (Widget wdg = lchild; wdg != null; wdg = wdg.prev) { if (!wdg.visible) continue; Coord cc = xlate(wdg.c, true); wdg.mousemove(c.add(cc.inv())); } }
public void unlink() { if (next != null) next.prev = prev; if (prev != null) prev.next = next; if (parent.child == this) parent.child = next; if (parent.lchild == this) parent.lchild = prev; next = null; prev = null; }
@Deprecated public <T extends Widget> T findchild(Class<T> cl) { for (Widget wdg = child; wdg != null; wdg = wdg.next) { if (cl.isInstance(wdg)) return (cl.cast(wdg)); T ret = wdg.findchild(cl); if (ret != null) return (ret); } return (null); }
public void delfocusable(Widget w) { if (focusctl) { if ((focused != null) && focused.hasparent(w)) { findfocus(); } } else { if (parent != null) parent.delfocusable(w); } }
public void setcanfocus(boolean canfocus) { this.autofocus = this.canfocus = canfocus; if (parent != null) { if (canfocus) { parent.newfocusable(this); } else { parent.delfocusable(this); } } }
public boolean mousewheel(Coord c, int amount) { for (Widget wdg = lchild; wdg != null; wdg = wdg.prev) { if (!wdg.visible) continue; Coord cc = xlate(wdg.c, true); if (c.isect(cc, wdg.sz)) { if (wdg.mousewheel(c.add(cc.inv()), amount)) { return (true); } } } return (false); }
public void draw(GOut g, boolean strict) { Widget next; for (Widget wdg = child; wdg != null; wdg = next) { next = wdg.next; if (!wdg.visible) continue; Coord cc = xlate(wdg.c, true); GOut g2; if (strict) g2 = g.reclip(cc, wdg.sz); else g2 = g.reclipl(cc, wdg.sz); wdg.draw(g2); } }
private void findfocus() { /* XXX: Might need to check subwidgets recursively */ focused = null; for (Widget w = lchild; w != null; w = w.prev) { if (w.visible && w.autofocus) { focused = w; if (hasfocus) { focused.hasfocus = true; w.gotfocus(); } break; } } }
public boolean type(char key, KeyEvent ev) { if (canactivate) { if (key == 10) { wdgmsg("activate"); return (true); } } if (cancancel) { if (key == 27) { wdgmsg("cancel"); return (true); } } if (focusctl) { if (focused != null) { if (focused.type(key, ev)) return (true); if (focustab) { if (key == '\t' && !Config.agroclosest) { Widget f = focused; while (true) { if ((ev.getModifiers() & InputEvent.SHIFT_MASK) == 0) { Widget n = f.rnext(); f = ((n == null) || !n.hasparent(this)) ? child : n; } else { Widget p = f.rprev(); f = ((p == null) || !p.hasparent(this)) ? lchild : p; } if (f.canfocus) break; } setfocus(f); return (true); } else { return (false); } } else { return (false); } } else { return (false); } } else { for (Widget wdg = child; wdg != null; wdg = wdg.next) { if (wdg.visible) { if (wdg.type(key, ev)) return (true); } } return (false); } }
public Resource getcurs(Coord c) { Resource ret; for (Widget wdg = lchild; wdg != null; wdg = wdg.prev) { if (!wdg.visible) continue; Coord cc = xlate(wdg.c, true); if (c.isect(cc, wdg.sz)) { if ((ret = wdg.getcurs(c.add(cc.inv()))) != null) return (ret); } } try { return ((cursor == null) ? null : cursor.get()); } catch (Loading l) { return (null); } }
public void newfocusable(Widget w) { if (focusctl) { if (focused == null) setfocus(w); } else { if (parent != null) parent.newfocusable(w); } }
public void tick(double dt) throws InterruptedException { Widget next; for (Widget wdg = child; wdg != null; wdg = next) { next = wdg.next; wdg.tick(dt); } /* It would be very nice to do these things in harmless mix-in * classes, but alas, this is Java. */ anims.addAll(nanims); nanims.clear(); for (Iterator<Anim> i = anims.iterator(); i.hasNext(); ) { Anim anim = i.next(); if (anim.tick(dt)) i.remove(); } }
private <T extends Widget> T add0(T child) { if (this.ui != null) ((Widget) child).attach(this.ui); child.parent = this; child.link(); child.added(); if (((Widget) child).canfocus && child.visible) newfocusable(child); return (child); }
public boolean keyup(KeyEvent ev) { if (focusctl) { if (focused != null) { if (focused.keyup(ev)) return (true); return (false); } else { return (false); } } else { for (Widget wdg = child; wdg != null; wdg = wdg.next) { if (wdg.visible) { if (wdg.keyup(ev)) return (true); } } } return (false); }
public Object tooltip(Coord c, Widget prev) { if (prev != this) prevtt = null; if (tooltip != null) { prevtt = null; return (tooltip); } for (Widget wdg = lchild; wdg != null; wdg = wdg.prev) { if (!wdg.visible) continue; Coord cc = xlate(wdg.c, true); if (c.isect(cc, wdg.sz)) { Object ret = wdg.tooltip(c.add(cc.inv()), prevtt); if (ret != null) { prevtt = wdg; return (ret); } } } prevtt = null; return (tooltip(c, prev == this)); }
public void setfocus(Widget w) { if (focusctl) { if (w != focused) { Widget last = focused; focused = w; if (hasfocus) { if (last != null) last.hasfocus = false; w.hasfocus = true; if (last != null) last.lostfocus(); w.gotfocus(); } else if ((last != null) && last.hasfocus) { /* Bug, but ah well. */ last.hasfocus = false; last.lostfocus(); } if ((ui != null) && ui.rwidgets.containsKey(w) && ui.rwidgets.containsKey(this)) wdgmsg("focus", ui.rwidgets.get(w)); } if ((parent != null) && visible && canfocus) parent.setfocus(this); } else { parent.setfocus(w); } }
public void resize(Coord sz) { this.sz = sz; for (Widget ch = child; ch != null; ch = ch.next) ch.presize(); if (parent != null) parent.cresize(this); }
public boolean globtype(char key, KeyEvent ev) { for (Widget wdg = lchild; wdg != null; wdg = wdg.prev) { if (wdg.globtype(key, ev)) return (true); } return (false); }
public void linkfirst() { if (parent.child != null) parent.child.prev = this; if (parent.lchild == null) parent.lchild = this; this.next = parent.child; parent.child = this; }
public void link() { if (parent.lchild != null) parent.lchild.next = this; if (parent.child == null) parent.child = this; this.prev = parent.lchild; parent.lchild = this; }
public void lostfocus() { if (focusctl && (focused != null)) { focused.hasfocus = false; focused.lostfocus(); } }
public void gotfocus() { if (focusctl && (focused != null)) { focused.hasfocus = true; focused.gotfocus(); } }
public void wdgmsg(Widget sender, String msg, Object... args) { if (parent == null) ui.wdgmsg(sender, msg, args); else parent.wdgmsg(sender, msg, args); }
protected void attach(UI ui) { this.ui = ui; for (Widget ch = child; ch != null; ch = ch.next) ch.attach(ui); }
public void hide() { visible = false; if (canfocus && (parent != null)) parent.delfocusable(this); }
public Coord parentpos(Widget in) { if (in == this) return (new Coord(0, 0)); return (xlate(parent.parentpos(in).add(c), true)); }
public void destroy() { if (canfocus) setcanfocus(false); unlink(); parent.cdestroy(this); }
public void show() { visible = true; if (canfocus && (parent != null)) parent.newfocusable(this); }
public <T extends Widget> T add(T child) { super.add(child); pack(); if (parent != null) presize(); return (child); }