javax.swing.text.Segment类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中javax.swing.text.Segment类的一些代码示例,展示了Segment类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Segment类的具体详情如下:
包路径:javax.swing.text.Segment
类名称:Segment

Segment介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public char[] getPassword() {
  Document doc = getDocument();
  Segment txt = new Segment();
  try {
    doc.getText(0, doc.getLength(), txt); // use the non-String API
  } catch (BadLocationException e) {
    return null;
  }
  char[] retValue = new char[txt.count];
  System.arraycopy(txt.array, txt.offset, retValue, 0, txt.count);
  return retValue;
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Removes any spaces or tabs from the end of the segment.
 *
 * @param segment The segment from which to remove tailing whitespace.
 * @return <code>segment</code> with trailing whitespace removed.
 */
private static Segment removeEndingWhitespace(Segment segment) {
  int toTrim = 0;
  char currentChar = segment.setIndex(segment.getEndIndex()-1);
  while ((currentChar==' ' || currentChar=='\t') && currentChar!=Segment.DONE) {
    toTrim++;
    currentChar = segment.previous();
  }
  String stringVal = segment.toString();
  String newStringVal = stringVal.substring(0,stringVal.length()-toTrim);
  return new Segment(newStringVal.toCharArray(), 0, newStringVal.length());
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

char ch = seg.first();
if (doc.isIdentifierChar(languageIndex, ch)) {
  do {
    ch = seg.next();
  } while (doc.isIdentifierChar(languageIndex, ch) &&
      ch != CharacterIterator.DONE);
    ch = seg.next();
  } while (Character.isWhitespace(ch));
offs += seg.getIndex() - seg.getBeginIndex();
return offs;

代码示例来源:origin: stackoverflow.com

final Segment segment = new Segment();
try {
        final GeoPoint position = new GeoPoint((int) (start.getDouble("lat")*1E6), 
            (int) (start.getDouble("lng")*1E6));
        segment.setPoint(position);
        segment.setLength(length);
        segment.setDistance(distance/1000);
        segment.setInstruction(step.getString("html_instructions").replaceAll("<(.*?)*>", ""));
        route.addSegment(segment.copy());

代码示例来源:origin: com.github.houbie/rhino-mod

synchronized void returnPressed() {
  Document doc = getDocument();
  int len = doc.getLength();
  Segment segment = new Segment();
  try {
    doc.getText(outputMark, len - outputMark, segment);
  } catch(javax.swing.text.BadLocationException ignored) {
    ignored.printStackTrace();
  }
  if(segment.count > 0) {
    history.add(segment.toString());
  }
  historyIndex = history.size();
  inPipe.write(segment.array, segment.offset, segment.count);
  append("\n");
  outputMark = doc.getLength();
  inPipe.write("\n");
  inPipe.flush();
  console1.flush();
}

代码示例来源:origin: groovy/groovy-core

try {
  Document doc = textComponent.getDocument();
  doc.getText(0, doc.getLength(), SEGMENT);
int start = pos;
boolean wrapped = WRAP_SEARCH_CHECKBOX.isSelected();
int end = backwards ? 0 : SEGMENT.getEndIndex();
pos += backwards ? -1 : 1;
int length = textComponent.getDocument().getLength();
if (pos > length) {
  pos = wrapped ? 0 : length;
      pos = backwards ? SEGMENT.getEndIndex() : 0;
      end = start;
      wrapped = false;

代码示例来源:origin: bobbylight/RSyntaxTextArea

rootElement = doc.getDefaultRootElement();
while (currentDocLineNumber<numDocLines) {
  Segment currentLineSeg = new Segment();
    doc.getText(currentLineStart+startingOffset, currentLineEnd-(currentLineStart+startingOffset),
          currentLineSeg);
  } catch (BadLocationException ble) {
      String currentLineString = currentLineSeg.toString();
      for (int i=0; i<BREAK_CHARS.length; i++) {
          currentPos++;
          try {
            doc.getText(currentLineStart+startingOffset, currentPos, currentLineSeg);
          } catch (BadLocationException ble) {
            System.err.println(ble);
        System.err.println("==> Range: " + (currentLineStart+startingOffset) + " - " +
              (currentLineStart+startingOffset+currentPos));
        ble.printStackTrace();
        return Printable.NO_SUCH_PAGE;

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

document.getLength() - findString.length() < startIndex) {
  return -1;
  Segment text = new Segment();
  text.setPartialReturn(true);
  int offset = startIndex;
  int nleft = document.getLength() - startIndex;
  while (nleft > 0) {
    document.getText(offset, nleft, text);
    char next = text.first();
    for (text.first(); next != Segment.DONE; next = text.next()) {
      char current = text.current();
      if (current == matchUpperCase[nextMatch] ||
      current == matchLowerCase[nextMatch]) {
          int foundIndex = text.getIndex() - text.getBeginIndex() + offset -
          matchLowerCase.length + 1;
          if (matchType == MatchType.CONTAINS) {

代码示例来源:origin: com.google.code.findbugs/findbugs

DocumentCharacterIterator(Document doc) {
  this.doc = doc;
  text = new Segment();
  text.setPartialReturn(true);
  try {
    doc.getText(0, doc.getLength(), text);
  } catch (BadLocationException e) {
    throw new RuntimeException(e);
  }
  segmentEnd = text.count;
}

代码示例来源:origin: net.sf.jazzy/jazzy

/**
 * Creates a new DocumentWordTokenizer to work on a document
 * @param document The document to spell check
 */
public DocumentWordTokenizer(Document document) {
 this.document = document;
 //Create a text segment over the entire document
 text = new Segment();
 sentenceIterator = BreakIterator.getSentenceInstance();
 try {
  document.getText(0, document.getLength(), text);
  sentenceIterator.setText(text);
  // robert: use text.getBeginIndex(), not 0, for segment's first offset
  currentWordPos = getNextWordStart(text, text.getBeginIndex());
  //If the current word pos is -1 then the string was all white space
  if (currentWordPos != -1) {
   currentWordEnd = getNextWordEnd(text, currentWordPos);
   nextWordPos = getNextWordStart(text, currentWordEnd);
  } else {
   moreTokens = false;
  }
 } catch (BadLocationException ex) {
  moreTokens = false;
 }
}

代码示例来源:origin: de.sciss/syntaxpane

/**
 * Get the text of the token from this document
 */
public CharSequence getText(Document doc) {
  Segment text = new Segment();
  try {
    doc.getText(start, length, text);
  } catch (BadLocationException ex) {
    Logger.getLogger(Token.class.getName()).log(Level.SEVERE, null, ex);
  }
  return text;
}

代码示例来源:origin: com.google.code.findbugs/findbugs

/**
 * Increments the iterator's index by one and returns the character at the
 * new index.
 *
 * @return the character at the new position, or DONE if the new position is
 *         off the end
 */
@Override
public char next() {
  ++docPos;
  if (docPos < segmentEnd || segmentEnd >= doc.getLength()) {
    return text.next();
  }
  try {
    doc.getText(segmentEnd, doc.getLength() - segmentEnd, text);
  } catch (BadLocationException e) {
    throw new RuntimeException(e);
  }
  segmentEnd += text.count;
  return text.current();
}

代码示例来源:origin: nz.ac.waikato.cms.weka.thirdparty/bounce

/**
 * Constructs a stream for the document.
 * 
 * @param doc
 *            the document with Xml Information.
 */
public DocumentInputStream( Document doc) {
  this.segment = new Segment();
  this.document = doc;
  end = document.getLength();
  pos = 0;
  try {
    loadSegment();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

代码示例来源:origin: com.fifesoft/autocomplete

@Override
public boolean isAutoActivateOkay(JTextComponent tc) {
  Document doc = tc.getDocument();
  char ch = 0;
  try {
    doc.getText(tc.getCaretPosition(), 1, s);
    ch = s.first();
  } catch (BadLocationException ble) { // Never happens
    ble.printStackTrace();
  }
  return (autoActivateAfterLetters && Character.isLetter(ch)) ||
      (autoActivateChars!=null && autoActivateChars.indexOf(ch)>-1);
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

Segment text = new Segment();
text.setPartialReturn(false);
document.getText(0, startIndex + 1, text);
char previous = text.last();
for (text.last(); previous != Segment.DONE; previous = text.previous()) {
  char current = text.current();
  if (current == matchUpperCase[nextMatch] ||
  current == matchLowerCase[nextMatch]) {
      int foundIndex = text.getIndex() - text.getBeginIndex();

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-completion

private static String matchChar(Document document,
    int offset,
    int limit,
    char origin,
    char matching,
    Set<Integer> excludeOffsets) throws BadLocationException {
  int lookahead =  limit - offset;
  
  // check the character at the right from the caret
  Segment text = new Segment();
  document.getText(offset, lookahead, text);
  int count = 0;
  for(int i = 0 ; i < lookahead; i++) {
    if (origin == text.array[text.offset + i]) {
      count++;
    } else if (matching == text.array[text.offset + i]) {
      if (--count == 0) {
        for (Integer excOffset : excludeOffsets) {
          if( offset<=excOffset && excOffset<=(text.offset + i) ){
            return null;
          }
        }
        return text.subSequence(0, i + 1).toString();
      }
    }
  }
  
  return null;
}

代码示例来源:origin: nativelibs4java/JNAerator

/**
 * Reparses the document, by passing the specified lines to the
 * token marker. This should be called after a large quantity of
 * text is first inserted.
 * @param start The first line to parse
 * @param len The number of lines, after the first one to parse
 */
public void tokenizeLines(int start, int len)
{
  if(tokenMarker == null || !tokenMarker.supportsMultilineTokens())
    return;
  Segment lineSegment = new Segment();
  Element map = getDefaultRootElement();
  len += start;
  try
  {
    for(int i = start; i < len; i++)
    {
      Element lineElement = map.getElement(i);
      int lineStart = lineElement.getStartOffset();
      getText(lineStart,lineElement.getEndOffset()
        - lineStart - 1,lineSegment);
      tokenMarker.markTokens(lineSegment,i);
    }
  }
  catch(BadLocationException bl)
  {
    bl.printStackTrace();
  }
}

代码示例来源:origin: antlr/antlrworks

cursor = t.index;
doc.getText(t.index, 1, text);
final char c = text.first();
save(g);
t.drawToken(ATERenderingView.this, t, g, metrics,

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

Segment txt = new Segment( _charArray, iPosition, segLength );
try
 if( Character.isJavaIdentifierPart( txt.first() ) )
       !"block".equals( txt.toString() ) )

代码示例来源:origin: de.sciss/syntaxpane

/**
 * Gets the line at given position.  The line returned will NOT include
 * the line terminator '\n'
 * @param pos Position (usually from text.getCaretPosition()
 * @return the String of text at given position
 */
public String getLineAt(int pos) throws BadLocationException {
  Element e = getParagraphElement(pos);
  Segment seg = new Segment();
  getText(e.getStartOffset(), e.getEndOffset() - e.getStartOffset(), seg);
  char last = seg.last();
  if (last == '\n' || last == '\r') {
    seg.count--;
  }
  return seg.toString();
}

相关文章