3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A collection of methods to deal with various text 0N/A * related activities. 0N/A * @author Timothy Prinzing 0N/A * If <code>view</code>'s container is a <code>JComponent</code> it 0N/A * is returned, after casting. 0N/A * Draws the given text, expanding any tabs that are contained 0N/A * using the given tab expansion technique. This particular 0N/A * implementation renders in a 1.1 style coordinate system 0N/A * where ints are used and 72dpi is assumed. 0N/A * @param s the source of the text 0N/A * @param x the X origin >= 0 0N/A * @param y the Y origin >= 0 0N/A * @param g the graphics context 0N/A * @param e how to expand the tabs. If this value is null, 0N/A * tabs will be expanded as a space character. 0N/A * @param startOffset starting offset of the text in the document >= 0 0N/A * @return the X location at the end of the rendered text 0N/A * Draws the given text, expanding any tabs that are contained 0N/A * using the given tab expansion technique. This particular 0N/A * implementation renders in a 1.1 style coordinate system 0N/A * where ints are used and 72dpi is assumed. 0N/A * @param view View requesting rendering, may be null. 0N/A * @param s the source of the text 0N/A * @param x the X origin >= 0 0N/A * @param y the Y origin >= 0 0N/A * @param g the graphics context 0N/A * @param e how to expand the tabs. If this value is null, 0N/A * tabs will be expanded as a space character. 0N/A * @param startOffset starting offset of the text in the document >= 0 0N/A * @return the X location at the end of the rendered text 0N/A // In addition to the previous method it can extend spaces for 0N/A // all params are the same as in the preious method except the last 0N/A // @param justificationData justificationData for the row. 0N/A // if null not justification is needed 0N/A }
else if ((
txt[i] ==
'\n') || (
txt[i] ==
'\r')) {
0N/A * Determines the width of the given segment of text taking tabs 0N/A * into consideration. This is implemented in a 1.1 style coordinate 0N/A * system where ints are used and 72dpi is assumed. 0N/A * @param s the source of the text 0N/A * @param metrics the font metrics to use for the calculation 0N/A * @param x the X origin >= 0 0N/A * @param e how to expand the tabs. If this value is null, 0N/A * tabs will be expanded as a space character. 0N/A * @param startOffset starting offset of the text in the document >= 0 0N/A * @return the width of the text 0N/A // In addition to the previous method it can extend spaces for 0N/A // all params are the same as in the preious method except the last 0N/A // @param justificationData justificationData for the row. 0N/A // if null not justification is needed 0N/A // Ignore newlines, they take up space and we shouldn't be 0N/A * Determines the relative offset into the given text that 0N/A * best represents the given span in the view coordinate 0N/A * system. This is implemented in a 1.1 style coordinate 0N/A * system where ints are used and 72dpi is assumed. 0N/A * @param s the source of the text 0N/A * @param metrics the font metrics to use for the calculation 0N/A * @param x0 the starting view location representing the start 0N/A * of the given text >= 0. 0N/A * @param x the target view location to translate to an 0N/A * offset into the text >= 0. 0N/A * @param e how to expand the tabs. If this value is null, 0N/A * tabs will be expanded as a space character. 0N/A * @param startOffset starting offset of the text in the document >= 0 0N/A * @return the offset into the text >= 0 0N/A // In addition to the previous method it can extend spaces for 0N/A // all params are the same as in the preious method except the last 0N/A // @param justificationData justificationData for the row. 0N/A // if null not justification is needed 0N/A // x before x0, return. 0N/A // s may be a shared segment, so it is copied prior to calling 0N/A // found the hit position... return the appropriate side 3636N/A // the length of the string measured as a whole may differ from 3636N/A // the sum of individual character lengths, for example if 3636N/A // fractional metrics are enabled; and we must guard from this. 0N/A // didn't find, return end offset 0N/A * Determine where to break the given text to fit 0N/A * within the given span. This tries to find a word boundary. 0N/A * @param s the source of the text 0N/A * @param metrics the font metrics to use for the calculation 0N/A * @param x0 the starting view location representing the start 0N/A * of the given text. 0N/A * @param x the target view location to translate to an 0N/A * offset into the text. 0N/A * @param e how to expand the tabs. If this value is null, 0N/A * tabs will be expanded as a space character. 0N/A * @param startOffset starting offset in the document of the text 0N/A * @return the offset into the given text 0N/A // break on whitespace 0N/A // a multibyte char found; use BreakIterator to find line break 0N/A * Determines the starting row model position of the row that contains 0N/A * the specified model position. The component given must have a 0N/A * size to compute the result. If the component doesn't have a size 0N/A * a value of -1 will be returned. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @return the position >= 0 if the request can be computed, otherwise 0N/A * a value of -1 will be returned. 0N/A * @exception BadLocationException if the offset is out of range 0N/A while ((r !=
null) && (y == r.y)) {
0N/A // Skip invisible elements 0N/A * Determines the ending row model position of the row that contains 0N/A * the specified model position. The component given must have a 0N/A * size to compute the result. If the component doesn't have a size 0N/A * a value of -1 will be returned. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @return the position >= 0 if the request can be computed, otherwise 0N/A * a value of -1 will be returned. 0N/A * @exception BadLocationException if the offset is out of range 0N/A while ((r !=
null) && (y == r.y)) {
0N/A // Skip invisible elements 0N/A * Determines the position in the model that is closest to the given 0N/A * view location in the row above. The component given must have a 0N/A * size to compute the result. If the component doesn't have a size 0N/A * a value of -1 will be returned. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @param x the X coordinate >= 0 0N/A * @return the position >= 0 if the request can be computed, otherwise 0N/A * a value of -1 will be returned. 0N/A * @exception BadLocationException if the offset is out of range 0N/A while ((r !=
null) && (y == r.y)) {
0N/A * Determines the position in the model that is closest to the given 0N/A * view location in the row below. The component given must have a 0N/A * size to compute the result. If the component doesn't have a size 0N/A * a value of -1 will be returned. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @param x the X coordinate >= 0 0N/A * @return the position >= 0 if the request can be computed, otherwise 0N/A * a value of -1 will be returned. 0N/A * @exception BadLocationException if the offset is out of range 0N/A while ((r !=
null) && (y == r.y)) {
0N/A * Determines the start of a word for the given model location. 0N/A * Uses BreakIterator.getWordInstance() to actually get the words. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @return the location in the model of the word start >= 0 0N/A * @exception BadLocationException if the offset is out of range 0N/A * Determines the end of a word for the given location. 0N/A * Uses BreakIterator.getWordInstance() to actually get the words. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @return the location in the model of the word end >= 0 0N/A * @exception BadLocationException if the offset is out of range 0N/A * Determines the start of the next word for the given location. 0N/A * Uses BreakIterator.getWordInstance() to actually get the words. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @return the location in the model of the word start >= 0 0N/A * @exception BadLocationException if the offset is out of range 0N/A // didn't find in this line, try the next line 0N/A * Finds the next word in the given elements text. The first 0N/A * parameter allows searching multiple paragraphs where even 0N/A * the first offset is desired. 0N/A * Returns the offset of the next word, or BreakIterator.DONE 0N/A * if there are no more words in the element. 0N/A // there are no more words on this line. 0N/A // if we haven't shot past the end... check to 0N/A // see if the current boundary represents whitespace. 0N/A // if so, we need to try again 0N/A // it was whitespace, try again. The assumption 0N/A // is that it must be a word start if the last 0N/A // one had whitespace following it. 0N/A * Determine the start of the prev word for the given location. 0N/A * Uses BreakIterator.getWordInstance() to actually get the words. 0N/A * @param c the editor 0N/A * @param offs the offset in the document >= 0 0N/A * @return the location in the model of the word start >= 0 0N/A * @exception BadLocationException if the offset is out of range 0N/A // didn't find in this line, try the prev line 0N/A * Finds the previous word in the given elements text. The first 0N/A * parameter allows searching multiple paragraphs where even 0N/A * the first offset is desired. 0N/A * Returns the offset of the next word, or BreakIterator.DONE 0N/A * if there are no more words in the element. 0N/A // there are no more words on this line. 0N/A // if we haven't shot past the end... check to 0N/A // see if the current boundary represents whitespace. 0N/A // if so, we need to try again 0N/A // it was whitespace, try again. The assumption 0N/A // is that it must be a word start if the last 0N/A // one had whitespace following it. 0N/A * @param c the editor 0N/A * @param offs the starting offset in the document >= 0 0N/A * @return the element 0N/A * Draws the given composed text passed from an input method. 0N/A * @param view View hosting text 0N/A * @param attr the attributes containing the composed text 0N/A * @param g the graphics context 0N/A * @param x the X origin 0N/A * @param y the Y origin 0N/A * @param p0 starting offset in the composed text to be rendered 0N/A * @param p1 ending offset in the composed text to be rendered 0N/A * @return the new insertion position 0N/A * Paints the composed text in a GlyphView 0N/A //Add text attributes 0N/A * Convenience function for determining ComponentOrientation. Helps us 0N/A * avoid having Munge directives throughout the code. 0N/A * Provides a way to determine the next visually represented model 0N/A * location that one might place a caret. Some views may not be visible, 0N/A * they might not be in the same order found in the model, or they just 0N/A * might not allow access to some of the locations in the model. 0N/A * This implementation assumes the views are layed out in a logical 0N/A * manner. That is, that the view at index x + 1 is visually after 0N/A * the View at index x, and that the View at index x - 1 is visually 0N/A * before the View at x. There is support for reversing this behavior 0N/A * only if the passed in <code>View</code> is an instance of 0N/A * <code>CompositeView</code>. The <code>CompositeView</code> 0N/A * must then override the <code>flipEastAndWestAtEnds</code> method. 0N/A * @param v View to query 0N/A * @param pos the position to convert >= 0 0N/A * @param a the allocated region to render into 0N/A * @param direction the direction from the current position that can 0N/A * be thought of as the arrow keys typically found on a keyboard; 0N/A * this may be one of the following: 0N/A * <li><code>SwingConstants.WEST</code> 0N/A * <li><code>SwingConstants.EAST</code> 0N/A * <li><code>SwingConstants.NORTH</code> 0N/A * <li><code>SwingConstants.SOUTH</code> 0N/A * @param biasRet an array contain the bias that was checked 0N/A * @return the location within the model that best represents the next 0N/A * location visual position 0N/A * @exception BadLocationException 0N/A * @exception IllegalArgumentException if <code>direction</code> is invalid 0N/A // Start from the first View. 0N/A // Special case that should ONLY happen if first view 0N/A // isn't valid (can happen when end position is put at 0N/A // beginning of line. 0N/A // If there is a bias change, it is a fake position 0N/A // and we should skip it. This is usually the result 0N/A // of two elements side be side flowing the same way. 0N/A // Reached the end of a view, make sure the next view 0N/A // is a different direction.