Example #1
0
 public void run() {
   for (; ; ) {
     try {
       int n = sel.select();
       if (n > 0) processSelectedKeys();
       processPendingTargets();
       if (shutdown) {
         sel.close();
         return;
       }
     } catch (IOException x) {
       x.printStackTrace();
     }
   }
 }
Example #2
0
 private void expand() {
   resize(new Coord(sz.x, 100));
   setcanfocus(true);
   if (sel != null) sel.show();
   chansel.show();
   expanded = true;
 }
Example #3
0
    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);
      }
    }
Example #4
0
 private void contract() {
   resize(new Coord(sz.x, 50));
   setcanfocus(false);
   if (sel != null) sel.hide();
   chansel.hide();
   expanded = false;
 }
Example #5
0
 public void cdestroy(Widget w) {
   if (w instanceof Channel) {
     Channel chan = (Channel) w;
     if (chan == sel) sel = null;
     chansel.rm(chan);
   }
 }
Example #6
0
 public void newchild(Widget w) {
   if (w instanceof Channel) {
     Channel chan = (Channel) w;
     select(chan);
     chansel.add(chan);
     if (!expanded) chan.hide();
   }
 }
Example #7
0
 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);
 }
Example #8
0
 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));
   }
 }
Example #9
0
    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);
        }
      }
    }
Example #10
0
 void shutdown() {
   shutdown = true;
   sel.wakeup();
 }
Example #11
0
 Connector(Printer pr) throws IOException {
   printer = pr;
   sel = Selector.open();
   setName("Connector");
 }
Example #12
0
 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));
 }