2362N/A * Copyright (c) 1998, 2008, 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 * ZoneView is a View implementation that creates zones for which 0N/A * the child views are not created or stored until they are needed 0N/A * for display or model/view translations. This enables a substantial 0N/A * reduction in memory consumption for situations where the model 0N/A * being represented is very large, by building view objects only for 0N/A * can be estimated in some way, or calculated asynchronously with 0N/A * only the result being saved. 0N/A * ZoneView extends BoxView to provide a box that implements 0N/A * zones for its children. The zones are special View implementations 0N/A * (the children of an instance of this class) that represent only a 0N/A * portion of the model that an instance of ZoneView is responsible 0N/A * for. The zones don't create child views until an attempt is made 0N/A * to display them. A box shaped view is well suited to this because: 0N/A * Boxes are a heavily used view, and having a box that 0N/A * provides this behavior gives substantial opportunity 0N/A * to plug the behavior into a view hierarchy from the 0N/A * Boxes are tiled in one direction, so it is easy to 0N/A * divide them into zones in a reliable way. 0N/A * Boxes typically have a simple relationship to the model (i.e. they 0N/A * create child views that directly represent the child elements). 0N/A * Boxes are easier to estimate the size of than some other shapes. 0N/A * The default behavior is controled by two properties, maxZoneSize 0N/A * and maxZonesLoaded. Setting maxZoneSize to Integer.MAX_VALUE would 0N/A * have the effect of causing only one zone to be created. This would 0N/A * effectively turn the view into an implementation of the decorator 0N/A * pattern. Setting maxZonesLoaded to a value of Integer.MAX_VALUE would 0N/A * cause zones to never be unloaded. For simplicity, zones are created on 0N/A * boundaries represented by the child elements of the element the view is 0N/A * responsible for. The zones can be any View implementation, but the 0N/A * default implementation is based upon AsyncBoxView which supports fairly 0N/A * large zones efficiently. 0N/A * @author Timothy Prinzing 0N/A * Constructs a ZoneView. 0N/A * @param elem the element this view is responsible for 0N/A * @param axis either View.X_AXIS or View.Y_AXIS 0N/A * Get the current maximum zone size. 0N/A * Set the desired maximum zone size. A 0N/A * zone may get larger than this size if 0N/A * a single child view is larger than this 0N/A * size since zones are formed on child view 0N/A * @param size the number of characters the zone 0N/A * may represent before attempting to break 0N/A * the zone into a smaller size. 0N/A * Get the current setting of the number of zones 0N/A * allowed to be loaded at the same time. 0N/A * Sets the current setting of the number of zones 0N/A * allowed to be loaded at the same time. This will throw an 0N/A * <code>IllegalArgumentException</code> if <code>mzl</code> is less 0N/A * @param mzl the desired maximum number of zones 0N/A * to be actively loaded, must be greater than 0 0N/A * @exception IllegalArgumentException if <code>mzl</code> is < 1 0N/A * Called by a zone when it gets loaded. This happens when 0N/A * translation on a zone that was in an unloaded state. 0N/A * This is imlemented to check if the maximum number of 0N/A * zones was reached and to unload the oldest zone if so. 0N/A * @param zone the child view that was just loaded. 0N/A //System.out.println("loading: " + zone.getStartOffset() + "," + zone.getEndOffset()); 0N/A * Unload a zone (Convert the zone to its memory saving state). 0N/A * The zones are expected to represent a subset of the 0N/A * child elements of the element this view is responsible for. 0N/A * Therefore, the default implementation is to simple remove 0N/A * @param zone the child view desired to be set to an 0N/A //System.out.println("unloading: " + zone.getStartOffset() + "," + zone.getEndOffset()); 0N/A * Determine if a zone is in the loaded state. 0N/A * The zones are expected to represent a subset of the 0N/A * child elements of the element this view is responsible for. 0N/A * Therefore, the default implementation is to return 0N/A * true if the view has children. 0N/A * Create a view to represent a zone for the given 0N/A * range within the model (which should be within 0N/A * the range of this objects responsibility). This 0N/A * is called by the zone management logic to create 0N/A * new zones. Subclasses can provide a different 0N/A * implementation for a zone by changing this method. 0N/A * @param p0 the start of the desired zone. This should 0N/A * be >= getStartOffset() and < getEndOffset(). This 0N/A * value should also be < p1. 0N/A * @param p1 the end of the desired zone. This should 0N/A * be > getStartOffset() and <= getEndOffset(). This 0N/A * value should also be > p0. 0N/A // this should puke in some way. 0N/A * Loads all of the children to initialize the view. 0N/A * This is called by the <code>setParent</code> method. 0N/A * This is reimplemented to not load any children directly 0N/A * (as they are created by the zones). This method creates 0N/A * the initial set of zones. Zones don't actually get 0N/A * populated however until an attempt is made to display 0N/A * @param f the view factory 0N/A // build the first zone. 0N/A * Returns the child view index representing the given position in 0N/A * @param pos the position >= 0 0N/A * @return index of the view representing the given position, or 0N/A * -1 if no view represents that position 0N/A // PENDING(prinz) this could be done as a binary 0N/A // search, and probably should be. 0N/A for(
int i =
0; i < n; i++) {
0N/A * Break up the zone at the given index into pieces 0N/A * of an acceptable size. 0N/A // divide the old zone into a new set of bins 0N/A * Returns the zone position to use for the 0N/A * end of a zone that starts at the given 0N/A * position. By default this returns something 0N/A * close to half the max zone size. 0N/A // ---- View methods ---------------------------------------------------- 0N/A * The superclass behavior will try to update the child views 0N/A * which is not desired in this case, since the children are 0N/A * zones and not directly effected by the changes to the 0N/A * associated element. This is reimplemented to do nothing 0N/A * Gives notification that something was inserted into the document 0N/A * in a location that this view is responsible for. This is largely 0N/A * delegated to the superclass, but is reimplemented to update the 0N/A * relevant zone (i.e. determine if a zone needs to be split into a 0N/A * set of 2 or more zones). 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. This is largely 0N/A * delegated to the superclass, but is reimplemented to update the 0N/A * relevant zones (i.e. determine if zones need to be removed or 0N/A * joined with another zone). 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 * Internally created view that has the purpose of holding 0N/A * the views that represent the children of the ZoneView 0N/A * that have been arranged in a zone. 0N/A * Creates the child views and populates the 0N/A * zone with them. This is done by translating 0N/A * the positions to child element index locations 0N/A * and building views to those elements. If the 0N/A * zone is already loaded, this does nothing. 0N/A * Removes the child views and returns to a 0N/A * state of unloaded. 0N/A * Determines if the zone is in the loaded state 0N/A * This method is reimplemented to not build the children 0N/A * since the children are created when the zone is loaded 0N/A * rather then when it is placed in the view hierarchy. 0N/A * The major span is estimated at this point by building 0N/A * the first child (but not storing it), and calling 0N/A * setEstimatedMajorSpan(true) followed by setSpan for 0N/A * the major axis with the estimated span. 0N/A // mark the major span as estimated 0N/A // estimate the span 0N/A // replace this with something real 0N/A //setSpan(getMajorAxis(), nChildren * 10); 0N/A * Publish the changes in preferences upward to the parent 0N/A * This is reimplemented to stop the superclass behavior 0N/A * if the zone has not yet been loaded. If the zone is 0N/A * unloaded for example, the last seen major span is the 0N/A * best estimate and a calculated span for no children 0N/A * Returns the child view index representing the given position in 0N/A * the model. Since the zone contains a cluster of the overall 0N/A * set of child elements, we can determine the index fairly 0N/A * quickly from the model by subtracting the index of the 0N/A * start offset from the index of the position given. 0N/A * @param pos the position >= 0 0N/A * @return index of the view representing the given position, or 0N/A * -1 if no view represents that position 0N/A // the structure of this element changed. 0N/A // The change is in this zone 0N/A // --- View methods ---------------------------------- 0N/A * Fetches the attributes to use when rendering. This view 0N/A * isn't directly responsible for an element so it returns 0N/A * the outer classes attributes. 0N/A * Renders using the given rendering surface and area on that 0N/A * surface. This is implemented to load the zone if its not 0N/A * already loaded, and then perform the superclass behavior. 0N/A * @param g the rendering surface to use 0N/A * @param a the allocated region to render into 0N/A * Provides a mapping from the view coordinate space to the logical 0N/A * coordinate space of the model. This is implemented to first 0N/A * make sure the zone is loaded before providing the superclass 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 * Provides a mapping from the document model coordinate space 0N/A * to the coordinate space of the view mapped to it. This is 0N/A * implemented to provide the superclass behavior after first 0N/A * making sure the zone is loaded (The zone must be loaded to 0N/A * make this calculation). 0N/A * @param pos the position to convert 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 represent a 0N/A * valid location in the associated document 0N/A * @see View#modelToView 0N/A * Start of the zones range. 0N/A * @see View#getStartOffset 0N/A * End of the zones range. 0N/A * Gives notification that something was inserted into 0N/A * the document in a location that this view is responsible for. 0N/A * If the zone has been loaded, the superclass behavior is 0N/A * invoked, otherwise this does nothing. 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 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 * If the zone has been loaded, the superclass behavior is 0N/A * invoked, otherwise this does nothing. 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 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 * If the zone has been loaded, the superclass behavior is 0N/A * invoked, otherwise this does nothing. 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 View#removeUpdate