コード例 #1
0
ファイル: ChatUI.java プロジェクト: Trojanz/Custom-Salem
 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) {
   }
 }
コード例 #2
0
ファイル: World.java プロジェクト: munro/lzr
 public World() {
   // Parse foobar
   float x = 0, y = 0;
   CharacterIterator it = new StringCharacterIterator(foobar);
   for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next(), x++) {
     switch (ch) {
       case '+':
         walls.add(new Wall(new Vector2f(x + 0.5f, y), new Vector2f(x + 0.5f, y + 1.0f)));
       case '-':
         walls.add(new Wall(new Vector2f(x, y + 0.5f), new Vector2f(x + 1.0f, y + 0.5f)));
         break;
       case '|':
         walls.add(new Wall(new Vector2f(x + 0.5f, y), new Vector2f(x + 0.5f, y + 1.0f)));
         break;
       case '\n':
         x = -1;
         y++;
         break;
     }
   }
   singleton = this;
 }