2362N/A * Copyright (c) 1997, 2006, 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 * Implements View interface for a simple multi-line text view 0N/A * that has text in one font and color. The view represents each 0N/A * child element as a line of text. 0N/A * @author Timothy Prinzing 0N/A * Constructs a new PlainView wrapped on an element. 0N/A * @param elem the element 0N/A * Returns the tab size set for the document, defaulting to 8. 0N/A * @return the tab size 0N/A * Renders a line of text, suppressing whitespace at the end 0N/A * and expanding any tabs. This is implemented to make calls 0N/A * to the methods <code>drawUnselectedText</code> and 0N/A * <code>drawSelectedText</code> so that the way selected and 0N/A * unselected text are rendered can be customized. 0N/A * @param lineIndex the line to draw >= 0 0N/A * @param g the <code>Graphics</code> context 0N/A * @param x the starting X position >= 0 0N/A * @param y the starting Y position >= 0 0N/A * @see #drawUnselectedText 0N/A * @see #drawSelectedText 0N/A // this line contains the composed text. 0N/A // no selection, or it is invisible 0N/A * Renders the given range in the model as normal unselected 0N/A * text. Uses the foreground or disabled color to render the text. 0N/A * @param g the graphics context 0N/A * @param x the starting X coordinate >= 0 0N/A * @param y the starting Y coordinate >= 0 0N/A * @param p0 the beginning position in the model >= 0 0N/A * @param p1 the ending position in the model >= 0 0N/A * @return the X location of the end of the range >= 0 0N/A * @exception BadLocationException if the range is invalid 0N/A * Renders the given range in the model as selected text. This 0N/A * is implemented to render the text in the color specified in 0N/A * the hosting component. It assumes the highlighter will render 0N/A * the selected background. 0N/A * @param g the graphics context 0N/A * @param x the starting X coordinate >= 0 0N/A * @param y the starting Y coordinate >= 0 0N/A * @param p0 the beginning position in the model >= 0 0N/A * @param p1 the ending position in the model >= 0 0N/A * @return the location of the end of the range 0N/A * @exception BadLocationException if the range is invalid 0N/A * Gives access to a buffer that can be used to fetch 0N/A * text from the associated document. 0N/A * @return the buffer 0N/A * Checks to see if the font metrics and longest line 0N/A // The font changed, we need to recalculate the 0N/A // ---- View methods ---------------------------------------------------- 0N/A * Determines the preferred span for this view along an 0N/A * @param axis may be either View.X_AXIS or View.Y_AXIS 0N/A * @return the span the view would like to be rendered into >= 0. 0N/A * Typically the view is told to render into the span 0N/A * that is returned, although there is no guarantee. 0N/A * The parent may choose to resize or break the view. 0N/A * @exception IllegalArgumentException for an invalid axis 0N/A * Renders using the given rendering surface and area on that surface. 0N/A * The view may need to do layout and create child views to enable 0N/A * itself to render into the given allocation. 0N/A * @param g the rendering surface to use 0N/A * @param a the allocated region to render into 0N/A // If the lines are clipped then we don't expend the effort to 0N/A // try and paint them. Since all of the lines are the same height 0N/A // with this object, determination of what lines need to be repainted 0N/A // update the visible lines 0N/A // This should never really happen, in so far as if 0N/A // firstLineOffset is non 0, there should only be one 0N/A * Should return a shape ideal for painting based on the passed in 0N/A * Shape <code>a</code>. This is useful if painting in a different 0N/A * region. The default implementation returns <code>a</code>. 0N/A * Provides a mapping from the document model coordinate space 0N/A * to the coordinate space of the view mapped to it. 0N/A * @param pos the position to convert >= 0 0N/A * @param a the allocated region to render into 0N/A * @return the bounding box of the given position 0N/A * @exception BadLocationException if the given position does not 0N/A * represent a valid location in the associated document 0N/A * @see View#modelToView 0N/A // determine span from the start of the line 0N/A // fill in the results and return 0N/A * Provides a mapping from the view coordinate space to the logical 0N/A * coordinate space of the model. 0N/A * @param fx the X coordinate >= 0 0N/A * @param fy the Y coordinate >= 0 0N/A * @param a the allocated region to render into 0N/A * @return the location within the model that best represents the 0N/A * given point in the view >= 0 0N/A * @see View#viewToModel 0N/A // PENDING(prinz) properly calculate bias 0N/A // above the area covered by this icon, so the the position 0N/A // is assumed to be the start of the coverage for this view. 0N/A // below the area covered by this icon, so the the position 0N/A // is assumed to be the end of the coverage for this view. 0N/A // positioned within the coverage of this view vertically, 0N/A // so we figure out which line the point corresponds to. 0N/A // if the line is greater than the number of lines contained, then 0N/A // simply use the last line as it represents the last possible place 0N/A // we can position to. 0N/A // point is to the left of the line 0N/A // point is to the right of the line 0N/A // Determine the offset into the text 0N/A // should not happen 0N/A * Gives notification that something was inserted into the document 0N/A * in a location that this view is responsible for. 0N/A * @param changes the change information from the associated document 0N/A * @param a the current allocation of the view 0N/A * @param f the factory to use to rebuild if the view has children 0N/A * @see View#insertUpdate 0N/A * Gives notification that something was removed from the document 0N/A * in a location that this view is responsible for. 0N/A * @param changes the change information from the associated document 0N/A * @param a the current allocation of the view 0N/A * @param f the factory to use to rebuild if the view has children 0N/A * @see View#removeUpdate 0N/A * Gives notification from the document that attributes were changed 0N/A * in a location that this view is responsible for. 0N/A * @param changes the change information from the associated document 0N/A * @param a the current allocation of the view 0N/A * @param f the factory to use to rebuild if the view has children 0N/A * @see View#changedUpdate 0N/A * Sets the size of the view. This should cause 0N/A * layout of the view along the given axis, if it 0N/A * has any layout duties. 0N/A * @param width the width >= 0 0N/A * @param height the height >= 0 0N/A // --- TabExpander methods ------------------------------------------ 0N/A * Returns the next tab stop position after a given reference position. 0N/A * This implementation does not support things like centering so it 0N/A * ignores the tabOffset argument. 0N/A * @param x the current position >= 0 0N/A * @param tabOffset the position within the text stream 0N/A * that the tab occurred at >= 0. 0N/A * @return the tab stop, measured in points >= 0 0N/A // --- local methods ------------------------------------------------ 0N/A * Repaint the region of change covered by the given document 0N/A * event. Damages the line that begins the range to cover 0N/A * If lines are added or removed, damages the whole 0N/A * view. The longest line is checked to see if it has 0N/A // lines were added or removed... 0N/A // check to see if the line is longer than current 0N/A // removed from longest line... recalc 0N/A * Repaint the given line range. 0N/A * @param host the component hosting the view (used to call repaint) 0N/A * @param a the region allocated for the view to render into 0N/A * @param line0 the starting line number to repaint. This must 0N/A * be a valid line number in the model. 0N/A * @param line1 the ending line number to repaint. This must 0N/A * be a valid line number in the model. 0N/A * Determine the rectangle that represents the given line. 0N/A * @param a the region allocated for the view to render into 0N/A * @param line the line number to find the region of. This must 0N/A * be a valid line number in the model. 0N/A * Iterate over the lines represented by the child elements 0N/A * of the element this view represents, looking for the line 0N/A * that is the longest. The <em>longLine</em> variable is updated to 0N/A * represent the longest line contained. The <em>font</em> variable 0N/A * is updated to indicate the font used to calculate the 0N/A for (
int i =
0; i < n; i++) {
0N/A * Calculate the width of the line represented by 0N/A * the given element. It is assumed that the font 0N/A * and font metrics are up-to-date. 0N/A // --- member variables ----------------------------------------------- 0N/A * Font metrics for the current font. 0N/A * The current longest line. This is used to calculate 0N/A * the preferred width of the view. Since the calculation 0N/A * is potentially expensive we try to avoid it by stashing 0N/A * which line is currently the longest. 0N/A * Font used to calculate the longest line... if this 0N/A * changes we need to recalculate the longest line 0N/A * Offset of where to draw the first character on the first line. 0N/A * This is a hack and temporary until we can better address the problem 0N/A * of text measuring. This field is actually never set directly in 0N/A * PlainView, but by FieldView.