ZoneView extends BoxView to provide a box that implements zones for its children. The zones are special View implementations (the children of an instance of this class) that represent only a portion of the model that an instance of ZoneView is responsible for. The zones don't create child views until an attempt is made to display them. A box shaped view is well suited to this because:
The default behavior is controlled by two properties, maxZoneSize and maxZonesLoaded. Setting maxZoneSize to Integer.MAX_VALUE would have the effect of causing only one zone to be created. This would effectively turn the view into an implementation of the decorator pattern. Setting maxZonesLoaded to a value of Integer.MAX_VALUE would cause zones to never be unloaded. For simplicity, zones are created on boundaries represented by the child elements of the element the view is responsible for. The zones can be any View implementation, but the default implementation is based upon AsyncBoxView which supports fairly large zones efficiently.
View
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | ZoneView.
Internally created view that has the purpose of holding the views that represent the children of the ZoneView that have been arranged in a zone. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Vector | |
| pack-priv int | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected View | Returns: a view to represent a zone for the given range within the modelthe start of the desired zone. This should
be >= getStartOffset() and < getEndOffset(). This
value should also be < p1. p0, int the end of the desired zone. This should
be > getStartOffset() and <= getEndOffset(). This
value should also be > p0. p1)Create a view to represent a zone for the given range within the model (which should be within the range of this objects responsibility). |
| pack-priv int | getDesiredZoneEnd(int pos)
Returns the zone position to use for the end of a zone that starts at the given position. |
| public int | |
| public int | Returns: current setting of the number of zones allowed to be loaded at the same timeGet the current setting of the number of zones allowed to be loaded at the same time. |
| protected int | Returns: index of the view representing the given position, or -1 if no view represents that positionthe position >= 0 pos)Overrides javax. Returns the child view index representing the given position in the model. |
| pack-priv void | |
| pack-priv void | |
| public void | insertUpdate(DocumentEvent
the change information from the associated document changes, Shape the current allocation of the view a, ViewFactory the factory to use to rebuild if the view has children f)Overrides javax. Gives notification that something was inserted into the document in a location that this view is responsible for. |
| protected boolean | Returns: whether or not the zone is in the loaded state.the zone zone)Determine if a zone is in the loaded state. |
| protected void | loadChildren(ViewFactory
the view factory f)Overrides javax. Loads all of the children to initialize the view. |
| public void | removeUpdate(DocumentEvent
the change information from the associated document changes, Shape the current allocation of the view a, ViewFactory the factory to use to rebuild if the view has children f)Overrides javax. Gives notification that something was removed from the document in a location that this view is responsible for. |
| public void | setMaximumZoneSize(int
the number of characters the zone
may represent before attempting to break
the zone into a smaller size. size)Set the desired maximum zone size. |
| public void | setMaxZonesLoaded(int
the desired maximum number of zones
to be actively loaded, must be greater than 0 mzl)Sets the current setting of the number of zones allowed to be loaded at the same time. |
| pack-priv void | splitZone(int index, int offs0, int offs1)
Break up the zone at the given index into pieces of an acceptable size. |
| pack-priv void | |
| protected void | unloadZone(View
the child view desired to be set to an
unloaded state. zone)Unload a zone (Convert the zone to its memory saving state). |
| protected boolean | updateChildren(DocumentEvent.
Overrides javax. The superclass behavior will try to update the child views which is not desired in this case, since the children are zones and not directly effected by the changes to the associated element. |
| protected void |
| loadedZones | back to summary |
|---|---|
| pack-priv Vector<View> loadedZones | |
| maxZoneSize | back to summary |
|---|---|
| pack-priv int maxZoneSize | |
| maxZonesLoaded | back to summary |
|---|---|
| pack-priv int maxZonesLoaded | |
| ZoneView | back to summary |
|---|---|
| public ZoneView(Element elem, int axis) Constructs a ZoneView.
| |
| createZone | back to summary |
|---|---|
| protected View createZone(int p0, int p1) Create a view to represent a zone for the given range within the model (which should be within the range of this objects responsibility). This is called by the zone management logic to create new zones. Subclasses can provide a different implementation for a zone by changing this method.
| |
| getDesiredZoneEnd | back to summary |
|---|---|
| pack-priv int getDesiredZoneEnd(int pos) Returns the zone position to use for the end of a zone that starts at the given position. By default this returns something close to half the max zone size. | |
| getMaximumZoneSize | back to summary |
|---|---|
| public int getMaximumZoneSize() Get the current maximum zone size.
| |
| getMaxZonesLoaded | back to summary |
|---|---|
| public int getMaxZonesLoaded() Get the current setting of the number of zones allowed to be loaded at the same time.
| |
| getViewIndexAtPosition | back to summary |
|---|---|
| protected int getViewIndexAtPosition(int pos) Overrides javax. Returns the child view index representing the given position in the model.
| |
| handleInsert | back to summary |
|---|---|
| pack-priv void handleInsert(int pos, int length) | |
| handleRemove | back to summary |
|---|---|
| pack-priv void handleRemove(int pos, int length) | |
| insertUpdate | back to summary |
|---|---|
| public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) Overrides javax. Gives notification that something was inserted into the document in a location that this view is responsible for. This is largely delegated to the superclass, but is reimplemented to update the relevant zone (i.e. determine if a zone needs to be split into a set of 2 or more zones).
| |
| isZoneLoaded | back to summary |
|---|---|
| protected boolean isZoneLoaded(View zone) Determine if a zone is in the loaded state. The zones are expected to represent a subset of the child elements of the element this view is responsible for. Therefore, the default implementation is to return true if the view has children. param zone the child view
| |
| loadChildren | back to summary |
|---|---|
| protected void loadChildren(ViewFactory f) Overrides javax. Loads all of the children to initialize the view.
This is called by the
| |
| removeUpdate | back to summary |
|---|---|
| public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) Overrides javax. Gives notification that something was removed from the document in a location that this view is responsible for. This is largely delegated to the superclass, but is reimplemented to update the relevant zones (i.e. determine if zones need to be removed or joined with another zone).
| |
| setMaximumZoneSize | back to summary |
|---|---|
| public void setMaximumZoneSize(int size) Set the desired maximum zone size. A zone may get larger than this size if a single child view is larger than this size since zones are formed on child view boundaries.
| |
| setMaxZonesLoaded | back to summary |
|---|---|
| public void setMaxZonesLoaded(int mzl) Sets the current setting of the number of zones
allowed to be loaded at the same time. This will throw an
| |
| splitZone | back to summary |
|---|---|
| pack-priv void splitZone(int index, int offs0, int offs1) Break up the zone at the given index into pieces of an acceptable size. | |
| unloadOldZones | back to summary |
|---|---|
| pack-priv void unloadOldZones() | |
| unloadZone | back to summary |
|---|---|
| protected void unloadZone(View zone) Unload a zone (Convert the zone to its memory saving state). The zones are expected to represent a subset of the child elements of the element this view is responsible for. Therefore, the default implementation is to simple remove all the children.
| |
| updateChildren | back to summary |
|---|---|
| protected boolean updateChildren(DocumentEvent. Overrides javax. The superclass behavior will try to update the child views which is not desired in this case, since the children are zones and not directly effected by the changes to the associated element. This is reimplemented to do nothing and return false. | |
| zoneWasLoaded | back to summary |
|---|---|
| protected void zoneWasLoaded(View zone) Called by a zone when it gets loaded. This happens when an attempt is made to display or perform a model/view translation on a zone that was in an unloaded state. This is implemented to check if the maximum number of zones was reached and to unload the oldest zone if so.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | changedUpdate(DocumentEvent
the change information from the associated document e, Shape the current allocation of the view a, ViewFactory the factory to use to rebuild if the view has children f)Overrides javax. Gives notification from the document that attributes were changed in a location that this view is responsible for. |
| protected void | flushRequirementChanges()
Overrides javax. Publish the changes in preferences upward to the parent view. |
| public AttributeSet | getAttributes()
Overrides javax. Fetches the attributes to use when rendering. |
| public int | |
| public int | |
| public int | Returns: index of the view representing the given position, or -1 if no view represents that positionthe position >= 0 pos, Position.Overrides javax. Returns the child view index representing the given position in the model. |
| public void | insertUpdate(DocumentEvent
the change information from the associated document e, Shape the current allocation of the view a, ViewFactory the factory to use to rebuild if the view has children f)Overrides javax. Gives notification that something was inserted into the document in a location that this view is responsible for. |
| public boolean | |
| public void | |
| protected void | loadChildren(ViewFactory f)
Overrides javax. This method is reimplemented to not build the children since the children are created when the zone is loaded rather then when it is placed in the view hierarchy. |
| public Shape | Returns: the bounding box of the given positionthe position to convert pos, Shape the allocated region to render into a, Position.Overrides javax. Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. |
| public void | paint(Graphics
the rendering surface to use g, Shape the allocated region to render into a)Overrides javax. Renders using the given rendering surface and area on that surface. |
| public void | removeUpdate(DocumentEvent
the change information from the associated document e, Shape the current allocation of the view a, ViewFactory the factory to use to rebuild if the view has children f)Overrides javax. Gives notification that something was removed from the document in a location that this view is responsible for. |
| public void | |
| protected boolean | updateChildren(DocumentEvent.
Overrides javax. Updates the child views in response to receiving notification that the model changed, and there is change record for the element this view is responsible for. |
| public int | Returns: the location within the model that best represents the given point in the view >= 0x coordinate of the view location to convert >= 0 x, float y coordinate of the view location to convert >= 0 y, Shape the allocated region to render into a, Position.Overrides javax. Provides a mapping from the view coordinate space to the logical coordinate space of the model. |
| Zone | back to summary |
|---|---|
| public Zone(Element elem, Position start, Position end) | |
| changedUpdate | back to summary |
|---|---|
| public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) Overrides javax. Gives notification from the document that attributes were changed in a location that this view is responsible for. If the zone has been loaded, the superclass behavior is invoked, otherwise this does nothing.
| |
| flushRequirementChanges | back to summary |
|---|---|
| protected void flushRequirementChanges() Overrides javax. Publish the changes in preferences upward to the parent view. This is reimplemented to stop the superclass behavior if the zone has not yet been loaded. If the zone is unloaded for example, the last seen major span is the best estimate and a calculated span for no children is undesirable. | |
| getAttributes | back to summary |
|---|---|
| public AttributeSet getAttributes() Overrides javax. Fetches the attributes to use when rendering. This view isn't directly responsible for an element so it returns the outer classes attributes. | |
| getEndOffset | back to summary |
|---|---|
| public int getEndOffset() Overrides javax. End of the zones range. | |
| getStartOffset | back to summary |
|---|---|
| public int getStartOffset() Overrides javax. Start of the zones range.
| |
| getViewIndex | back to summary |
|---|---|
| public int getViewIndex(int pos, Position. Overrides javax. Returns the child view index representing the given position in the model. Since the zone contains a cluster of the overall set of child elements, we can determine the index fairly quickly from the model by subtracting the index of the start offset from the index of the position given.
| |
| insertUpdate | back to summary |
|---|---|
| public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) Overrides javax. Gives notification that something was inserted into the document in a location that this view is responsible for. If the zone has been loaded, the superclass behavior is invoked, otherwise this does nothing.
| |
| isLoaded | back to summary |
|---|---|
| public boolean isLoaded() Determines if the zone is in the loaded state or not. | |
| load | back to summary |
|---|---|
| public void load() Creates the child views and populates the zone with them. This is done by translating the positions to child element index locations and building views to those elements. If the zone is already loaded, this does nothing. | |
| loadChildren | back to summary |
|---|---|
| protected void loadChildren(ViewFactory f) Overrides javax. This method is reimplemented to not build the children since the children are created when the zone is loaded rather then when it is placed in the view hierarchy. The major span is estimated at this point by building the first child (but not storing it), and calling setEstimatedMajorSpan(true) followed by setSpan for the major axis with the estimated span. | |
| modelToView | back to summary |
|---|---|
| public Shape modelToView(int pos, Shape a, Position. Overrides javax. Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. This is implemented to provide the superclass behavior after first making sure the zone is loaded (The zone must be loaded to make this calculation).
| |
| paint | back to summary |
|---|---|
| public void paint(Graphics g, Shape a) Overrides javax. Renders using the given rendering surface and area on that surface. This is implemented to load the zone if its not already loaded, and then perform the superclass behavior.
| |
| removeUpdate | back to summary |
|---|---|
| public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) Overrides javax. Gives notification that something was removed from the document in a location that this view is responsible for. If the zone has been loaded, the superclass behavior is invoked, otherwise this does nothing.
| |
| unload | back to summary |
|---|---|
| public void unload() Removes the child views and returns to a state of unloaded. | |
| updateChildren | back to summary |
|---|---|
| protected boolean updateChildren(DocumentEvent. Overrides javax. Doc from javax. Updates the child views in response to receiving notification
that the model changed, and there is change record for the
element this view is responsible for. This is implemented
to assume the child views are directly responsible for the
child elements of the element this view represents. The
| |
| viewToModel | back to summary |
|---|---|
| public int viewToModel(float x, float y, Shape a, Position. Overrides javax. Provides a mapping from the view coordinate space to the logical coordinate space of the model. This is implemented to first make sure the zone is loaded before providing the superclass behavior.
| |