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 * A view that arranges its children into a box shape by tiling 0N/A * its children along an axis. The box is somewhat like that 0N/A * found in TeX where there is alignment of the 0N/A * children, flexibility of the children is considered, etc. 0N/A * This is a building block that might be useful to represent 0N/A * things like a collection of lines, paragraphs, 0N/A * lists, columns, pages, etc. The axis along which the children are tiled is 0N/A * considered the major axis. The orthoginal axis is the minor axis. 0N/A * Layout for each axis is handled separately by the methods 0N/A * <code>layoutMajorAxis</code> and <code>layoutMinorAxis</code>. 0N/A * Subclasses can change the layout algorithm by 0N/A * reimplementing these methods. These methods will be called 0N/A * as necessary depending upon whether or not there is cached 0N/A * layout information and the cache is considered 0N/A * valid. These methods are typically called if the given size 0N/A * along the axis changes, or if <code>layoutChanged</code> is 0N/A * called to force an updated layout. The <code>layoutChanged</code> 0N/A * method invalidates cached layout information, if there is any. 0N/A * The requirements published to the parent view are calculated by 0N/A * the methods <code>calculateMajorAxisRequirements</code> 0N/A * and <code>calculateMinorAxisRequirements</code>. 0N/A * If the layout algorithm is changed, these methods will 0N/A * likely need to be reimplemented. 0N/A * @author Timothy Prinzing 0N/A * Constructs a <code>BoxView</code>. 0N/A * @param elem the element this view is responsible for 0N/A * @param axis either <code>View.X_AXIS</code> or <code>View.Y_AXIS</code> 0N/A * Fetches the tile axis property. This is the axis along which 0N/A * the child views are tiled. 0N/A * @return the major axis of the box, either 0N/A * <code>View.X_AXIS</code> or <code>View.Y_AXIS</code> 0N/A * Sets the tile axis property. This is the axis along which 0N/A * the child views are tiled. 0N/A * @param axis either <code>View.X_AXIS</code> or <code>View.Y_AXIS</code> 0N/A * Invalidates the layout along an axis. This happens 0N/A * automatically if the preferences have changed for 0N/A * any of the child views. In some cases the layout 0N/A * may need to be recalculated when the preferences 0N/A * have not changed. The layout can be marked as 0N/A * invalid by calling this method. The layout will 0N/A * be updated the next time the <code>setSize</code> method 0N/A * is called on this view (typically in paint). 0N/A * @param axis either <code>View.X_AXIS</code> or <code>View.Y_AXIS</code> 0N/A * Determines if the layout is valid along the given axis. 0N/A * @param axis either <code>View.X_AXIS</code> or <code>View.Y_AXIS</code> 0N/A * Paints a child. By default 0N/A * that is all it does, but a subclass can use this to paint 0N/A * things relative to the child. 0N/A * @param g the graphics context 0N/A * @param alloc the allocated region to paint into 0N/A * @param index the child index, >= 0 && < getViewCount() 0N/A // --- View methods --------------------------------------------- 0N/A * Invalidates the layout and resizes the cache of 0N/A * be accessed for the old layout, but the new children 0N/A * will have an offset and span of 0. 0N/A * @param index the starting index into the child views to insert 0N/A * the new views; this should be a value >= 0 and <= getViewCount 0N/A * @param length the number of existing child views to remove; 0N/A * This should be a value >= 0 and <= (getViewCount() - offset) 0N/A * @param elems the child views to add; this value can be 0N/A * <code>null</code>to indicate no children are being added 0N/A * (useful to remove) 0N/A * Resizes the given layout array to match the new number of 0N/A * child views. The current number of child views are used to 0N/A * produce the new array. The contents of the old array are 0N/A * inserted into the new array at the appropriate places so that 0N/A * the old layout information is transferred to the new array. 0N/A * @param oldArray the original layout array 0N/A * @param offset location where new views will be inserted 0N/A * @param nInserted the number of child views being inserted; 0N/A * therefore the number of blank spaces to leave in the 0N/A * new array at location <code>offset</code> 0N/A * @return the new layout array 0N/A * Forwards the given <code>DocumentEvent</code> to the child views 0N/A * that need to be notified of the change to the model. 0N/A * If a child changed its requirements and the allocation 0N/A * was valid prior to forwarding the portion of the box 0N/A * from the starting child to the end of the box will 0N/A * @param ec changes to the element this view is responsible 0N/A * for (may be <code>null</code> if there were no changes) 0N/A * @param e 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 #insertUpdate 0N/A * @see #removeUpdate 0N/A * @see #changedUpdate 0N/A // determine if a repaint is needed 0N/A // Repaint is needed because one of the tiled children 0N/A // have changed their span along the major axis. If there 0N/A // is a hosting component and an allocated shape we repaint. 0N/A * This is called by a child to indicate its 0N/A * preferred span has changed. This is implemented to 0N/A * throw away cached layout information so that new 0N/A * calculations will be done the next time the children 0N/A * need an allocation. 0N/A * @param child the child view 0N/A * @param width true if the width preference should change 0N/A * @param height true if the height preference should change 0N/A * Gets the resize weight. A value of 0 or less is not resizable. 0N/A * @param axis may be either <code>View.X_AXIS</code> or 0N/A * <code>View.Y_AXIS</code> 0N/A * @return the weight 0N/A * @exception IllegalArgumentException for an invalid axis 0N/A * Sets the size of the view along an axis. This should cause 0N/A * layout of the view along the given axis. 0N/A * @param axis may be either <code>View.X_AXIS</code> or 0N/A * <code>View.Y_AXIS</code> 0N/A * @param span the span to layout to >= 0 0N/A // layout the major axis 0N/A // flush changes to the children 0N/A // layout the minor axis 0N/A // flush changes to the children 0N/A * Propagates the current allocations to the child views. 0N/A for (
int i =
0; i < n; i++) {
0N/A for (
int i =
0; i < n; i++) {
0N/A * Returns the size of the view along an axis. This is implemented 0N/A * @param axis may be either <code>View.X_AXIS</code> or 0N/A * <code>View.Y_AXIS</code> 0N/A * @return the current span of the view along the given axis, >= 0 0N/A * Sets the size of the view. This should cause 0N/A * layout of the view if the view caches any layout 0N/A * information. This is implemented to call the 0N/A * layout method with the sizes inside of the insets. 0N/A * @param width the width >= 0 0N/A * @param height the height >= 0 0N/A * Renders the <code>BoxView</code> using the given 0N/A * rendering surface and area 0N/A * on that surface. Only the children that intersect 0N/A * the clip bounds of the given <code>Graphics</code> 0N/A * @param g the rendering surface to use 0N/A * @param allocation the allocated region to render into 0N/A for (
int i =
0; i < n; i++) {
0N/A // We should paint views that intersect with clipping region 0N/A // even if the intersection has no inside points (is a line). 0N/A // This is needed for supporting views that have zero width, like 0N/A // views that contain only combining marks. 0N/A * Fetches the allocation for the given child view. 0N/A * This enables finding out where various views 0N/A * are located. This is implemented to return 0N/A * <code>null</code> if the layout is invalid, 0N/A * otherwise the superclass behavior is executed. 0N/A * @param index the index of the child, >= 0 && < getViewCount() 0N/A * @param a the allocation to this view 0N/A * @return the allocation to the child; or <code>null</code> 0N/A * if <code>a</code> is <code>null</code>; 0N/A * or <code>null</code> if the layout is invalid 0N/A // The child allocation may not have been set yet. 0N/A * Provides a mapping from the document model coordinate space 0N/A * to the coordinate space of the view mapped to it. This makes 0N/A * sure the allocation is valid before calling the superclass. 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 0N/A * not represent a valid location in the associated document 0N/A * @see View#modelToView 0N/A * Provides a mapping from the view coordinate space to the logical 0N/A * coordinate space of the model. 0N/A * @param x x coordinate of the view location to convert >= 0 0N/A * @param y y coordinate of the view location to convert >= 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 * Determines the desired alignment for this view along an 0N/A * axis. This is implemented to give the total alignment 0N/A * needed to position the children with the alignment points 0N/A * lined up along the axis orthoginal to the axis that is 0N/A * being tiled. The axis being tiled will request to be 0N/A * centered (i.e. 0.5f). 0N/A * @param axis may be either <code>View.X_AXIS</code> 0N/A * or <code>View.Y_AXIS</code> 0N/A * @return the desired alignment >= 0.0f && <= 1.0f; this should 0N/A * be a value between 0.0 and 1.0 where 0 indicates alignment at the 0N/A * origin and 1.0 indicates alignment to the full span 0N/A * away from the origin; an alignment of 0.5 would be the 0N/A * center of the view 0N/A * @exception IllegalArgumentException for an invalid axis 0N/A * Determines the preferred span for this view along an 0N/A * @param axis may be either <code>View.X_AXIS</code> 0N/A * or <code>View.Y_AXIS</code> 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 type 0N/A * Determines the minimum span for this view along an 0N/A * @param axis may be either <code>View.X_AXIS</code> 0N/A * or <code>View.Y_AXIS</code> 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 type 0N/A * Determines the maximum span for this view along an 0N/A * @param axis may be either <code>View.X_AXIS</code> 0N/A * or <code>View.Y_AXIS</code> 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 type 0N/A // --- local methods ---------------------------------------------------- 0N/A * Are the allocations for the children still 0N/A * @return true if allocations still valid 0N/A * Determines if a point falls before an allocated region. 0N/A * @param x the X coordinate >= 0 0N/A * @param y the Y coordinate >= 0 0N/A * @param innerAlloc the allocated region; this is the area 0N/A * inside of the insets 0N/A * @return true if the point lies before the region else false 0N/A * Determines if a point falls after an allocated region. 0N/A * @param x the X coordinate >= 0 0N/A * @param y the Y coordinate >= 0 0N/A * @param innerAlloc the allocated region; this is the area 0N/A * inside of the insets 0N/A * @return true if the point lies after the region else false 0N/A * Fetches the child view at the given coordinates. 0N/A * @param x the X coordinate >= 0 0N/A * @param y the Y coordinate >= 0 0N/A * @param alloc the parents inner allocation on entry, which should 0N/A * be changed to the childs allocation on exit 0N/A for (
int i =
0; i < n; i++) {
0N/A for (
int i =
0; i < n; i++) {
0N/A * Allocates a region for a child view. 0N/A * @param index the index of the child view to 0N/A * allocate, >= 0 && < getViewCount() 0N/A * @param alloc the allocated region 0N/A * Perform layout on the box 0N/A * @param width the width (inside of the insets) >= 0 0N/A * @param height the height (inside of the insets) >= 0 0N/A * Returns the current width of the box. This is the width that 0N/A * it was last allocated. 0N/A * @return the current width of the box 0N/A * Returns the current height of the box. This is the height that 0N/A * it was last allocated. 0N/A * @return the current height of the box 0N/A * Performs layout for the major axis of the box (i.e. the 0N/A * axis that it represents). The results of the layout (the 0N/A * offset and span for each children) are placed in the given 0N/A * arrays which represent the allocations to the children 0N/A * along the major axis. 0N/A * @param targetSpan the total span given to the view, which 0N/A * would be used to layout the children 0N/A * @param axis the axis being layed out 0N/A * @param offsets the offsets from the origin of the view for 0N/A * each of the child views; this is a return value and is 0N/A * filled in by the implementation of this method 0N/A * @param spans the span of each child view; this is a return 0N/A * value and is filled in by the implementation of this method 0N/A * first pass, calculate the preferred sizes 0N/A * and the flexibility to adjust the sizes. 0N/A for (
int i =
0; i < n; i++) {
0N/A * Second pass, expand or contract by as much as possible to reach 0N/A // determine the adjustment to be made 0N/A for (
int i =
0; i < n; i++) {
0N/A // make the adjustments 0N/A for (
int i =
0; i < n; i++) {
0N/A * Performs layout for the minor axis of the box (i.e. the 0N/A * axis orthoginal to the axis that it represents). The results 0N/A * of the layout (the offset and span for each children) are 0N/A * placed in the given arrays which represent the allocations to 0N/A * the children along the minor axis. 0N/A * @param targetSpan the total span given to the view, which 0N/A * would be used to layout the children 0N/A * @param axis the axis being layed out 0N/A * @param offsets the offsets from the origin of the view for 0N/A * each of the child views; this is a return value and is 0N/A * filled in by the implementation of this method 0N/A * @param spans the span of each child view; this is a return 0N/A * value and is filled in by the implementation of this method 0N/A for (
int i =
0; i < n; i++) {
0N/A // can't make the child this wide, align it 0N/A // make it the target width, or as small as it can get. 0N/A * Calculates the size requirements for the major axis 0N/A * <code>axis</code>. 0N/A * @param axis the axis being studied 0N/A * @param r the <code>SizeRequirements</code> object; 0N/A * if <code>null</code> one will be created 0N/A * @return the newly initialized <code>SizeRequirements</code> object 0N/A * @see javax.swing.SizeRequirements 0N/A // calculate tiled request 0N/A for (
int i =
0; i < n; i++) {
0N/A * Calculates the size requirements for the minor axis 0N/A * <code>axis</code>. 0N/A * @param axis the axis being studied 0N/A * @param r the <code>SizeRequirements</code> object; 0N/A * if <code>null</code> one will be created 0N/A * @return the newly initialized <code>SizeRequirements</code> object 0N/A * @see javax.swing.SizeRequirements 0N/A for (
int i =
0; i < n; i++) {
0N/A * Checks the request cache and update if needed. 0N/A * @param axis the axis being studied 0N/A * @exception IllegalArgumentException if <code>axis</code> is 0N/A * neither <code>View.X_AXIS</code> nor <code>View.Y_AXIS</code> 0N/A * Computes the location and extent of each child view 0N/A * in this <code>BoxView</code> given the <code>targetSpan</code>, 0N/A * which is the width (or height) of the region we have to 0N/A * @param targetSpan the total span given to the view, which 0N/A * would be used to layout the children 0N/A * @param axis the axis being studied, either 0N/A * <code>View.X_AXIS</code> or <code>View.Y_AXIS</code> 0N/A * @param offsets an empty array filled by this method with 0N/A * values specifying the location of each child view 0N/A * @param spans an empty array filled by this method with 0N/A * values specifying the extent of each child view 0N/A for (
int i =
0; i < n; i++) {
0N/A // if resizable then resize to the best fit 0N/A // the smallest span possible 0N/A // the largest span possible 0N/A // if the alignment is 0 then we need to fit into the descent 0N/A // if the alignment is 1 then we need to fit into the ascent 0N/A // figure out the span that we must fit into 0N/A // fit into the calculated span 0N/A // otherwise use the preferred spans 0N/A * Calculates the size requirements for this <code>BoxView</code> 0N/A * by examining the size of each child view. 0N/A * @param axis the axis being studied 0N/A * @param r the <code>SizeRequirements</code> object; 0N/A * if <code>null</code> one will be created 0N/A * @return the newly initialized <code>SizeRequirements</code> object 0N/A // loop through all children calculating the max of all their ascents and 0N/A // descents at minimum, preferred, and maximum sizes 0N/A for (
int i =
0; i < n; i++) {
0N/A // find the maximum of the preferred ascents and descents 0N/A // if the view is resizable then do the same for the minimum and 0N/A // maximum ascents and descents 0N/A // otherwise use the preferred 0N/A // we now have an overall preferred, minimum, and maximum ascent and descent 0N/A // calculate the preferred span as the sum of the preferred ascent and preferred descent 0N/A // calculate the preferred alignment as the preferred ascent divided by the preferred span 0N/A // if the preferred alignment is 0 then the minimum and maximum spans are simply 0N/A // the minimum and maximum descents since there's nothing above the baseline 0N/A // if the preferred alignment is 1 then the minimum and maximum spans are simply 0N/A // the minimum and maximum ascents since there's nothing below the baseline 0N/A // we want to honor the preferred alignment so we calculate two possible minimum 0N/A // span values using 1) the minimum ascent and the alignment, and 2) the minimum 0N/A // descent and the alignment. We'll choose the larger of these two numbers. 0N/A // a similar calculation is made for the maximum but we choose the smaller number. 0N/A * Fetches the offset of a particular child's current layout. 0N/A * @param axis the axis being studied 0N/A * @param childIndex the index of the requested child 0N/A * @return the offset (location) for the specified child 0N/A * Fetches the span of a particular childs current layout. 0N/A * @param axis the axis being studied 0N/A * @param childIndex the index of the requested child 0N/A * @return the span (width or height) of the specified child 0N/A * Determines in which direction the next view lays. 0N/A * Consider the View at index n. Typically the <code>View</code>s 0N/A * are layed out from left to right, so that the <code>View</code> 0N/A * to the EAST will be at index n + 1, and the <code>View</code> 0N/A * to the WEST will be at index n - 1. In certain situations, 0N/A * such as with bidirectional text, it is possible 0N/A * that the <code>View</code> to EAST is not at index n + 1, 0N/A * but rather at index n - 1, or that the <code>View</code> 0N/A * to the WEST is not at index n - 1, but index n + 1. 0N/A * In this case this method would return true, 0N/A * indicating the <code>View</code>s are layed out in 0N/A * descending order. Otherwise the method would return false 0N/A * indicating the <code>View</code>s are layed out in ascending order. 0N/A * If the receiver is laying its <code>View</code>s along the 0N/A * <code>Y_AXIS</code>, this will will return the value from 0N/A * invoking the same method on the <code>View</code> 0N/A * responsible for rendering <code>position</code> and 0N/A * <code>bias</code>. Otherwise this will return false. 0N/A * @param position position into the model 0N/A * @param bias either <code>Position.Bias.Forward</code> or 0N/A * <code>Position.Bias.Backward</code> 0N/A * @return true if the <code>View</code>s surrounding the 0N/A * <code>View</code> responding for rendering 0N/A * <code>position</code> and <code>bias</code> 0N/A * are layed out in descending order; otherwise false 0N/A // --- variables ------------------------------------------------ 0N/A /** used in paint. */