Package javax.swing.text

Examples of javax.swing.text.Segment


    painter = new TextAreaPainter(this);
    gutter = new Gutter(view,this);
    listenerList = new EventListenerList();
    caretEvent = new MutableCaretEvent();
    blink = true;
    lineSegment = new Segment();
    returnValue = new Point();
    structureMatchers = new LinkedList();
    structureMatchers.add(new StructureMatcher.BracketMatcher());
    //}}}
View Full Code Here


      out = new BufferedWriter(
        new OutputStreamWriter(_out,encoding),
        IOBUFSIZE);

      Segment lineSegment = new Segment();
      String newline = buffer.getStringProperty(Buffer.LINESEP);
      if(newline == null)
        newline = System.getProperty("line.separator");

      setProgressMaximum(buffer.getLineCount() / PROGRESS_INTERVAL);
View Full Code Here

    numDocLines = rootElement.getElementCount();    // The number of lines in our document.
    currentDocLineNumber = 0;          // The line number of the document we're currently on.
    int startingOffset = 0;            // Used when a line is so long it has to be wrapped.
    while (currentDocLineNumber<numDocLines) {

      Segment currentLineSeg = new Segment();

      // Get the current line (as an Element), and its starting and ending offset in doc.
      Element currentLine  = rootElement.getElement(currentDocLineNumber);
      int currentLineStart = currentLine.getStartOffset();
      int currentLineEnd   = currentLine.getEndOffset();

      // Put the chars of this line in currentLineSeg, but only starting at our desired offset
      // (because this line may be the second part of a wrapped line, so we'd start after the part
      // that has already been printed).
      try {
        doc.getText(currentLineStart+startingOffset, currentLineEnd-(currentLineStart+startingOffset),
              currentLineSeg);
      } catch (BadLocationException ble) {
        System.err.println("BadLocationException in print (where there shouldn't be one!): " + ble);
        return Printable.NO_SUCH_PAGE;
      }

      // Remove any spaces and/or tabs from the end of the segment (would cause problems if you left 'em).
      currentLineSeg = removeEndingWhitespace(currentLineSeg);

      // Figger out how long the line is, in pixels.
      int currentLineLengthInPixels = Utilities.getTabbedTextWidth(currentLineSeg, fm, 0, tabExpander, 0);

//System.err.println("'" + currentLineSeg + "' - " + currentLineLengthInPixels + "/" + LINE_LENGTH_IN_PIXELS);
      // If it'll fit by itself on a printed line, great.
      if (currentLineLengthInPixels <= LINE_LENGTH_IN_PIXELS) {
        currentDocLineNumber += 1;   // We (will) have printed one more line from the document.
        startingOffset = 0;      // Start at the first character in the new document line.
      }

      // If it won't fit on a printed line by itself (i.e., it needs to be wrapped)...
      else {

        // Loop while the current line is too long to fit on a printed line.
        int currentPos = -1;
        while (currentLineLengthInPixels > LINE_LENGTH_IN_PIXELS) {

//System.err.println("'" + currentLineSeg + "' - " + currentLineLengthInPixels + "/" + LINE_LENGTH_IN_PIXELS);

          // Remove any spaces and/or tabs from the end of the segment (would cause problems if you left 'em).
          currentLineSeg = removeEndingWhitespace(currentLineSeg);

          // currentPos will be the last position in the current text of a "line break character."
          currentPos = -1;
          String currentLineString = currentLineSeg.toString();
          for (int i=0; i<breakChars.length; i++) {
            // "+1" below so we include the character on the line.
            int pos = currentLineString.lastIndexOf(breakChars[i]) + 1;
            //if (pos>-1 && pos>currentPos)
            //  currentPos = pos;
View Full Code Here

      toTrim++;
      currentChar = segment.previous();
    }
    String stringVal = segment.toString();
    String newStringVal = stringVal.substring(0,stringVal.length()-toTrim);
    return new Segment(newStringVal.toCharArray(), 0, newStringVal.length());
  }
View Full Code Here

    // Default insert trigger is a space.
    // FIXME:  See notes in RSyntaxTextAreaDefaultInputMap.
    setInsertTrigger(TEMPLATE_KEYSTROKE);

    s = new Segment();
    comparator = new TemplateComparator();
    templates = new ArrayList();

  }
View Full Code Here

      final char[] templateArray = t.getID().toCharArray();
      int i = 0;
      int len1 = templateArray.length;

      // Find "token" part of segment and get its offset and length.
      Segment s = (Segment)segment;
      char[] segArray = s.array;
      int len2 = s.count;
      int j = s.offset + len2 - 1;
      while (j>=s.offset && isValidChar(segArray[j])) {
        j--;
View Full Code Here

        HashMap<String,List<Snippet>> snippetMap = new HashMap<String,List<Snippet>>();
        Stack<Snippet> stack = new Stack<Snippet>(); // snippets may be nested
        char startMarkerChars[] = startMarker.toCharArray();
        char endMarkerChars[] = endMarker.toCharArray();
        int nleft = document.getLength();
        Segment segment = new Segment();
        int offset = 0;
        int lineStart = 0;
        int charCount = 0;
        int startMarkerIndex = 0;
        int endMarkerIndex = 0;
        StringBuffer keyBuf = new StringBuffer();
       
        segment.setPartialReturn(true);
        try {
            while (nleft > 0) {
               
                document.getText(offset, nleft, segment);
               
                for(char c = segment.first(); c != CharacterIterator.DONE;
                    c = segment.next()) {
                   
                    if (!stack.isEmpty()) {
                        // already found a begin marker, so looking for end marker
                        if (c == endMarkerChars[endMarkerIndex]) {
                            endMarkerIndex++;
View Full Code Here

    setDoubleBuffered(true);
    setOpaque(true);

    ToolTipManager.sharedInstance().registerComponent(this);

    currentLine = new Segment();
    currentLineIndex = -1;

    setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));

    setFont(new Font("Monospaced",Font.PLAIN,14));
View Full Code Here

   @SuppressWarnings("unchecked")
  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.addElement(segment.toString());
       }
       historyIndex = history.size();
       inPipe.write(segment.array, segment.offset, segment.count);
       append("\n");
       outputMark = doc.getLength();
View Full Code Here

                    int pos, int x0, Rectangle rect) {

    int stableX = x0;  // Cached ending x-coord. of last tab or token.
    Token token = this;
    FontMetrics fm = null;
    Segment s = new Segment();

    while (token!=null && token.isPaintable()) {

      fm = textArea.getFontMetricsForTokenType(token.type);
      if (fm==null) {
View Full Code Here

TOP

Related Classes of javax.swing.text.Segment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.