javax.swing.text
Class ZoneView.Zone

java.lang.Object
  extended byjavax.swing.text.View
      extended byjavax.swing.text.AsyncBoxView
          extended byjavax.swing.text.ZoneView.Zone
All Implemented Interfaces:
SwingConstants
Enclosing class:
ZoneView

class ZoneView.Zone
extends AsyncBoxView

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.


Nested Class Summary
 
Nested classes inherited from class javax.swing.text.AsyncBoxView
AsyncBoxView.ChildLocator, AsyncBoxView.ChildState, AsyncBoxView.FlushTask
 
Field Summary
private  Position end
           
private  Position start
           
 
Fields inherited from class javax.swing.text.AsyncBoxView
axis, bottomInset, changing, estimatedMajorSpan, flushTask, leftInset, locator, majorChanged, majorSpan, minorChanged, minorSpan, minRequest, prefRequest, rightInset, stats, topInset
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, sharedBiasReturn, X_AXIS, Y_AXIS
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
ZoneView.Zone(Element elem, Position start, Position end)
           
 
Method Summary
 void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification from the document that attributes were changed in a location that this view is responsible for.
protected  void flushRequirementChanges()
          Publish the changes in preferences upward to the parent view.
 AttributeSet getAttributes()
          Fetches the attributes to use when rendering.
 int getEndOffset()
          End of the zones range.
 int getStartOffset()
          Start of the zones range.
 int getViewIndex(int pos, Position.Bias b)
          Returns the child view index representing the given position in the model.
 void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification that something was inserted into the document in a location that this view is responsible for.
 boolean isLoaded()
          Determines if the zone is in the loaded state or not.
 void load()
          Creates the child views and populates the zone with them.
protected  void loadChildren(ViewFactory f)
          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.
 Shape modelToView(int pos, Shape a, Position.Bias b)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 void paint(Graphics g, Shape a)
          Renders using the given rendering surface and area on that surface.
 void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification that something was removed from the document in a location that this view is responsible for.
 void unload()
          Removes the child views and returns to a state of unloaded.
protected  boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f)
          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.
 int viewToModel(float x, float y, Shape a, Position.Bias[] bias)
          Provides a mapping from the view coordinate space to the logical coordinate space of the model.
 
Methods inherited from class javax.swing.text.AsyncBoxView
createChildState, getBottomInset, getChildAllocation, getChildState, getEstimatedMajorSpan, getInsetSpan, getLayoutQueue, getLeftInset, getMajorAxis, getMaximumSpan, getMinimumSpan, getMinorAxis, getNextVisualPositionFrom, getPreferredSpan, getRightInset, getSpanOnAxis, getTopInset, getView, getViewCount, getViewIndexAtPosition, majorRequirementChange, minorRequirementChange, preferenceChanged, replace, setBottomInset, setEstimatedMajorSpan, setLeftInset, setParent, setRightInset, setSize, setSpanOnAxis, setTopInset, updateLayout
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getBreakWeight, getContainer, getDocument, getElement, getGraphics, getParent, getResizeWeight, getToolTipText, getViewFactory, getViewIndex, insert, isVisible, modelToView, modelToView, remove, removeAll, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

start

private Position start

end

private Position end
Constructor Detail

ZoneView.Zone

public ZoneView.Zone(Element elem,
                     Position start,
                     Position end)
Method Detail

load

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.


unload

public void unload()
Removes the child views and returns to a state of unloaded.


isLoaded

public boolean isLoaded()
Determines if the zone is in the loaded state or not.


loadChildren

protected void loadChildren(ViewFactory f)
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.

Overrides:
loadChildren in class AsyncBoxView
Parameters:
f - the view factory
See Also:
AsyncBoxView.setParent(javax.swing.text.View)

flushRequirementChanges

protected void flushRequirementChanges()
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.

Overrides:
flushRequirementChanges in class AsyncBoxView

getViewIndex

public int getViewIndex(int pos,
                        Position.Bias b)
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.

Overrides:
getViewIndex in class AsyncBoxView
Parameters:
pos - the position >= 0
Returns:
index of the view representing the given position, or -1 if no view represents that position
Since:
1.3

updateChildren

protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e,
                                 ViewFactory f)
Description copied from class: View
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 ViewFactory is used to create child views for each element specified as added in the ElementChange, starting at the index specified in the given ElementChange. The number of child views representing the removed elements specified are removed.

Overrides:
updateChildren in class View
Parameters:
ec - the change information for the element this view is responsible for. This should not be null if this method gets called
e - the change information from the associated document
f - the factory to use to build child views
Returns:
whether or not the child views represent the child elements of the element this view is responsible for. Some views create children that represent a portion of the element they are responsible for, and should return false. This information is used to determine if views in the range of the added elements should be forwarded to or not
See Also:
View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory), View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory), View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

getAttributes

public AttributeSet getAttributes()
Fetches the attributes to use when rendering. This view isn't directly responsible for an element so it returns the outer classes attributes.

Overrides:
getAttributes in class View

paint

public void paint(Graphics g,
                  Shape a)
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.

Overrides:
paint in class AsyncBoxView
Parameters:
g - the rendering surface to use
a - the allocated region to render into
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

viewToModel

public int viewToModel(float x,
                       float y,
                       Shape a,
                       Position.Bias[] bias)
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.

Overrides:
viewToModel in class AsyncBoxView
Parameters:
x - x coordinate of the view location to convert >= 0
y - y coordinate of the view location to convert >= 0
a - the allocated region to render into
Returns:
the location within the model that best represents the given point in the view >= 0
See Also:
View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])

modelToView

public Shape modelToView(int pos,
                         Shape a,
                         Position.Bias b)
                  throws BadLocationException
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).

Overrides:
modelToView in class AsyncBoxView
Parameters:
pos - the position to convert
a - the allocated region to render into
b - the bias toward the previous character or the next character represented by the offset, in case the position is a boundary of two views.
Returns:
the bounding box of the given position
Throws:
BadLocationException - if the given position does not represent a valid location in the associated document
See Also:
View.modelToView(int, java.awt.Shape, javax.swing.text.Position.Bias)

getStartOffset

public int getStartOffset()
Start of the zones range.

Overrides:
getStartOffset in class View
Returns:
the starting offset into the model >= 0
See Also:
View.getStartOffset()

getEndOffset

public int getEndOffset()
End of the zones range.

Overrides:
getEndOffset in class View
Returns:
the ending offset into the model >= 0
See Also:
View.getEndOffset()

insertUpdate

public void insertUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
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.

Overrides:
insertUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

removeUpdate

public void removeUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
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.

Overrides:
removeUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

changedUpdate

public void changedUpdate(DocumentEvent e,
                          Shape a,
                          ViewFactory f)
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.

Overrides:
changedUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)