int (int width) { myTooSmall = width < MIN_WIDTH; if (myTooSmall) { return -1; } int result = 0; myWraps = new ArrayList(); for (String aLine : myLines) { int lineFirstChar = 0; int lineLastChar = aLine.length() - 1; int currFirst = lineFirstChar; int printableWidth = width - myTextInsets.left - myTextInsets.right; if (aLine.isEmpty()) { myWraps.add(aLine); result++; } else { while (currFirst <= lineLastChar) { int currLast = calculateLastVisibleChar(aLine, printableWidth, currFirst, lineLastChar); if (currLast < lineLastChar) { int currChar = currLast + 1; if (!Character.isWhitespace(aLine.charAt(currChar))) { while (currChar >= currFirst) { if (Character.isWhitespace(aLine.charAt(currChar))) { break; } currChar--; } if (currChar > currFirst) { currLast = currChar; } } } myWraps.add(aLine.substring(currFirst, currLast + 1)); currFirst = currLast + 1; while ((currFirst <= lineLastChar) && (Character.isWhitespace(aLine.charAt(currFirst)))) { currFirst++; } result++; } } } return result; }