Beispiel #1
0
 /**
  * Copies the specified substring of the document into a segment. If the offsets are invalid, the
  * segment will contain a null string.
  *
  * @param start The start offset
  * @param len The length of the substring
  * @param segment The segment
  */
 public final void getText(int start, int len, Segment segment) {
   try {
     document.getText(start, len, segment);
   } catch (BadLocationException bl) {
     bl.printStackTrace();
     segment.offset = segment.count = 0;
   }
 }
Beispiel #2
0
 public void getChars(int where, int len, Segment txt) throws BadLocationException {
   CharBuffer b = buffer;
   int start = b.getSegment(where, len);
   if (start < 0) throw new BadLocationException("invalid offset", where);
   txt.offset = start;
   txt.array = b.getArray();
   txt.count = len;
 }
Beispiel #3
0
 /** Removes all mappings from this map. */
 public void clear() {
   // We don't need all locks at once so long as locks
   //   are obtained in low to high order
   for (int s = 0; s < segments.length; ++s) {
     Segment seg = segments[s];
     synchronized (seg) {
       Entry[] tab = table;
       for (int i = s; i < tab.length; i += segments.length) {
         for (Entry e = tab[i]; e != null; e = e.next) e.value = null;
         tab[i] = null;
         seg.count = 0;
       }
     }
   }
 }
    boolean getText(Segment brtext, int voff, int len, Segment s) {
      s.array = new char[len + 1];
      s.count = 0;
      s.offset = 0;

      if (len == 0) return false;

      int spos = 0;
      int line = 0;

      // first find the line where the data starts
      for (int i = 1; i < num_lines; ++i) {
        int npos =
            spos
                + line_data[i].getOffset()
                - line_data[i - 1].getOffset()
                + line_data[i - 1].getViewDelta();
        if (voff < npos) break;
        spos = npos;
        line = i;
      }

      // now add the data
      int pos = spos;
      for (int i = line + 1; i < num_lines; ++i) {
        int rpos = line_data[i - 1].getOffset();
        rpos += line_data[i - 1].getDelete();
        int npos =
            spos
                + line_data[i].getOffset()
                - line_data[i - 1].getOffset()
                + line_data[i - 1].getViewDelta();
        int addct = (line_data[i - 1].getDelete() > 0 ? line_data[i - 1].getAdd() : 0);
        while (pos < npos) {
          char c;
          if (pos - spos < addct) c = ' ';
          else c = brtext.charAt(rpos + pos - spos - addct);
          if (pos >= voff) s.array[s.count++] = c;
          if (s.count == len) break;
          ++pos;
        }
        spos = npos;
        if (s.count == len) break;
      }

      boolean lastbad = false;

      if (s.count < len && num_lines > 0) {
        if (pos < voff) pos = voff;
        int rpos = line_data[num_lines - 1].getOffset();
        rpos += line_data[num_lines - 1].getDelete();
        int addct = line_data[num_lines - 1].getAdd();
        while (s.count < len) {
          char c;
          int idx = rpos + pos - spos - addct;
          if (pos - spos < addct) c = ' ';
          else if (idx < brtext.length()) c = brtext.charAt(idx);
          else {
            lastbad = true;
            c = '\n';
          }
          s.array[s.count++] = c;
          ++pos;
        }
      } else if (s.count < len) {
        while (s.count < len) {
          s.array[s.count++] = '\n';
        }
        lastbad = true;
      }

      return lastbad;
    }