Exemplo n.º 1
0
 public void append(Message msg) {
   synchronized (msgs) {
     msgs.add(msg);
     int y = 0;
     for (Message m : msgs) y += m.sz().y;
     boolean b = sb.val >= sb.max;
     sb.max = y - ih();
     if (b) sb.val = sb.max;
   }
 }
Exemplo n.º 2
0
 protected void selected(CharPos start, CharPos end) {
   StringBuilder buf = new StringBuilder();
   synchronized (msgs) {
     boolean sel = false;
     for (Message msg : msgs) {
       if (!(msg.text() instanceof RichText)) continue;
       RichText rt = (RichText) msg.text();
       RichText.Part part = null;
       if (sel) {
         part = rt.parts;
       } else if (msg == start.msg) {
         sel = true;
         for (part = rt.parts; part != null; part = part.next) {
           if (part == start.part) break;
         }
       }
       if (sel) {
         for (; part != null; part = part.next) {
           if (!(part instanceof RichText.TextPart)) continue;
           RichText.TextPart tp = (RichText.TextPart) part;
           CharacterIterator iter = tp.ti();
           int sch;
           if (tp == start.part) sch = tp.start + start.ch.getInsertionIndex();
           else sch = tp.start;
           int ech;
           if (tp == end.part) ech = tp.start + end.ch.getInsertionIndex();
           else ech = tp.end;
           for (int i = sch; i < ech; i++) buf.append(iter.setIndex(i));
           if (part == end.part) {
             sel = false;
             break;
           }
           buf.append(' ');
         }
         if (sel) buf.append('\n');
       }
       if (msg == end.msg) break;
     }
   }
   Clipboard cl;
   if ((cl = java.awt.Toolkit.getDefaultToolkit().getSystemSelection()) == null)
     cl = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
   try {
     final CharPos ownsel = selstart;
     cl.setContents(
         new StringSelection(buf.toString()),
         new ClipboardOwner() {
           public void lostOwnership(Clipboard cl, Transferable tr) {
             if (selstart == ownsel) selstart = selend = null;
           }
         });
   } catch (IllegalStateException e) {
   }
 }
Exemplo n.º 3
0
 public void resize(Coord sz) {
   super.resize(sz);
   if (sb != null) {
     sb.resize(ih());
     sb.move(new Coord(sz.x, 0));
     int y = 0;
     for (Message m : msgs) y += m.sz().y;
     boolean b = sb.val >= sb.max;
     sb.max = y - ih();
     if (b) sb.val = sb.max;
   }
   if (cbtn != null) cbtn.c = new Coord(sz.x - cbtn.sz.x - sb.sz.x - 3, 0);
 }
Exemplo n.º 4
0
 private void drawsel(GOut g, Message msg, int y) {
   RichText rt = (RichText) msg.text();
   boolean sel = msg != selstart.msg;
   for (RichText.Part part = rt.parts; part != null; part = part.next) {
     if (!(part instanceof RichText.TextPart)) continue;
     RichText.TextPart tp = (RichText.TextPart) part;
     if (tp.start == tp.end) continue;
     TextHitInfo a, b;
     if (sel) {
       a = TextHitInfo.leading(0);
     } else if (tp == selstart.part) {
       a = selstart.ch;
       sel = true;
     } else {
       continue;
     }
     if (tp == selend.part) {
       sel = false;
       b = selend.ch;
     } else {
       b = TextHitInfo.trailing(tp.end - tp.start - 1);
     }
     Coord ul = new Coord(tp.x + (int) tp.advance(0, a.getInsertionIndex()), tp.y + y);
     Coord sz =
         new Coord((int) tp.advance(a.getInsertionIndex(), b.getInsertionIndex()), tp.height());
     g.chcolor(0, 0, 255, 255);
     g.frect(ul, sz);
     g.chcolor();
     if (!sel) break;
   }
 }
Exemplo n.º 5
0
 public Message messageat(Coord c, Coord hc) {
   int y = -sb.val;
   synchronized (msgs) {
     for (Message msg : msgs) {
       Coord sz = msg.sz();
       if ((c.y >= y) && (c.y < y + sz.y)) {
         if (hc != null) {
           hc.x = c.x;
           hc.y = c.y - y;
         }
         return (msg);
       }
       y += sz.y;
     }
   }
   return (null);
 }
Exemplo n.º 6
0
    public CharPos charat(Coord c) {
      if (c.y < -sb.val) {
        if (msgs.size() < 1) return (null);
        Message msg = msgs.get(0);
        if (!(msg.text() instanceof RichText)) return (null);
        RichText.TextPart fp = null;
        for (RichText.Part part = ((RichText) msg.text()).parts; part != null; part = part.next) {
          if (part instanceof RichText.TextPart) {
            fp = (RichText.TextPart) part;
            break;
          }
        }
        if (fp == null) return (null);
        return (new CharPos(msg, fp, TextHitInfo.leading(0)));
      }

      Coord hc = new Coord();
      Message msg = messageat(c, hc);
      if ((msg == null) || !(msg.text() instanceof RichText)) return (null);
      RichText rt = (RichText) msg.text();
      RichText.Part p = rt.partat(hc);
      if (p == null) {
        RichText.TextPart lp = null;
        for (RichText.Part part = ((RichText) msg.text()).parts; part != null; part = part.next) {
          if (part instanceof RichText.TextPart) lp = (RichText.TextPart) part;
        }
        if (lp == null) return (null);
        return (new CharPos(msg, lp, TextHitInfo.trailing(lp.end - lp.start - 1)));
      }
      if (!(p instanceof RichText.TextPart)) return (null);
      RichText.TextPart tp = (RichText.TextPart) p;
      return (new CharPos(msg, tp, tp.charat(hc)));
    }
Exemplo n.º 7
0
 public void draw(GOut g) {
   g.chcolor(24, 24, 16, 200);
   g.frect(Coord.z, sz);
   g.chcolor();
   int y = 0;
   boolean sel = false;
   synchronized (msgs) {
     for (Message msg : msgs) {
       if ((selstart != null) && (msg == selstart.msg)) sel = true;
       int y1 = y - sb.val;
       int y2 = y1 + msg.sz().y;
       if ((y2 > 0) && (y1 < ih())) {
         if (sel) drawsel(g, msg, y1);
         g.image(msg.tex(), new Coord(0, y1));
       }
       if ((selend != null) && (msg == selend.msg)) sel = false;
       y += msg.sz().y;
     }
   }
   sb.max = y - ih();
   super.draw(g);
 }