/** * This is called by the nested wrapped line views to determine the break location. This can be * reimplemented to alter the breaking behavior. It will either break at word or character * boundaries depending upon the break argument given at construction. */ protected int calculateBreakPosition(int p0, Token tokenList, float x0) { // System.err.println("------ beginning calculateBreakPosition() --------"); int p = p0; RSyntaxTextArea textArea = (RSyntaxTextArea) getContainer(); float currentWidth = getWidth(); if (currentWidth == Integer.MAX_VALUE) currentWidth = getPreferredSpan(X_AXIS); // Make sure width>0; this is a huge hack to fix a bug where // loading text into an RTextArea before it is visible if word wrap // is enabled causes an infinite loop in calculateBreakPosition() // because of the 0-width! We cannot simply check in setSize() // because the width is set to 0 somewhere else too somehow... currentWidth = Math.max(currentWidth, MIN_WIDTH); Token t = tokenList; while (t != null && t.isPaintable()) { // FIXME: Replace the code below with the commented-out line below. This will // allow long tokens to be broken at embedded spaces (such as MLC's). But it // currently throws BadLocationExceptions sometimes... float tokenWidth = t.getWidth(textArea, this, x0); if (tokenWidth > currentWidth) { // If the current token alone is too long for this line, // break at a character boundary. if (p == p0) { return t.getOffsetBeforeX(textArea, this, 0, currentWidth); } // Return the first non-whitespace char (i.e., don't start // off the continuation of a wrapped line with whitespace). return t.isWhitespace() ? p + t.length() : p; // return getBreakLocation(t, fm, x0, currentWidth, this); } currentWidth -= tokenWidth; x0 += tokenWidth; p += t.length(); // System.err.println("*** *** *** token fit entirely (width==" + tokenWidth + "), adding " + // t.textCount + " to p, now p==" + p); t = t.getNextToken(); } // System.err.println("... ... whole line fits; returning p==" + p); // System.err.println("------ ending calculateBreakPosition() --------"); // return p; return p + 1; }