public void run() { for (; ; ) { try { int n = sel.select(); if (n > 0) processSelectedKeys(); processPendingTargets(); if (shutdown) { sel.close(); return; } } catch (IOException x) { x.printStackTrace(); } } }
private void expand() { resize(new Coord(sz.x, 100)); setcanfocus(true); if (sel != null) sel.show(); chansel.show(); expanded = true; }
void add(Target t) { SocketChannel sc = null; try { sc = SocketChannel.open(); sc.configureBlocking(false); boolean connected = sc.connect(t.address); t.channel = sc; t.connectStart = System.currentTimeMillis(); if (connected) { t.connectFinish = t.connectStart; sc.close(); printer.add(t); } else { synchronized (pending) { pending.add(t); } sel.wakeup(); } } catch (IOException x) { if (sc != null) { try { sc.close(); } catch (IOException xx) { } } t.failure = x; printer.add(t); } }
private void contract() { resize(new Coord(sz.x, 50)); setcanfocus(false); if (sel != null) sel.hide(); chansel.hide(); expanded = false; }
public void cdestroy(Widget w) { if (w instanceof Channel) { Channel chan = (Channel) w; if (chan == sel) sel = null; chansel.rm(chan); } }
public void newchild(Widget w) { if (w instanceof Channel) { Channel chan = (Channel) w; select(chan); chansel.add(chan); if (!expanded) chan.hide(); } }
public ChatUI(Coord c, int w, Widget parent) { super(c.add(0, -50), new Coord(w, 50), parent); chansel = new Selector(Coord.z, new Coord(selw, sz.y)); chansel.hide(); base = c; setfocusctl(true); setcanfocus(false); }
public boolean keydown(KeyEvent ev) { boolean M = (ev.getModifiersEx() & (KeyEvent.META_DOWN_MASK | KeyEvent.ALT_DOWN_MASK)) != 0; if (qline != null) { if (M && (ev.getKeyCode() == KeyEvent.VK_UP)) { Channel prev = this.sel; while (chansel.up()) { if (this.sel instanceof EntryChannel) break; } if (!(this.sel instanceof EntryChannel)) { select(prev); return (true); } qline = new QuickLine((EntryChannel) sel); return (true); } else if (M && (ev.getKeyCode() == KeyEvent.VK_DOWN)) { Channel prev = this.sel; while (chansel.down()) { if (this.sel instanceof EntryChannel) break; } if (!(this.sel instanceof EntryChannel)) { select(prev); return (true); } qline = new QuickLine((EntryChannel) sel); return (true); } qline.key(ev); return (true); } else { if (M && (ev.getKeyCode() == KeyEvent.VK_UP)) { chansel.up(); return (true); } else if (M && (ev.getKeyCode() == KeyEvent.VK_DOWN)) { chansel.down(); return (true); } return (super.keydown(ev)); } }
void processSelectedKeys() throws IOException { for (Iterator i = sel.selectedKeys().iterator(); i.hasNext(); ) { SelectionKey sk = (SelectionKey) i.next(); i.remove(); Target t = (Target) sk.attachment(); SocketChannel sc = (SocketChannel) sk.channel(); try { if (sc.finishConnect()) { sk.cancel(); t.connectFinish = System.currentTimeMillis(); sc.close(); printer.add(t); } } catch (IOException x) { sc.close(); t.failure = x; printer.add(t); } } }
void shutdown() { shutdown = true; sel.wakeup(); }
Connector(Printer pr) throws IOException { printer = pr; sel = Selector.open(); setName("Connector"); }
public void resize(Coord sz) { super.resize(sz); this.c = base.add(0, -this.sz.y); chansel.resize(new Coord(selw, this.sz.y)); if (sel != null) sel.resize(new Coord(this.sz.x - selw, this.sz.y)); }