Home » openjdk-7 » javax » swing » text » [javadoc | source]
javax.swing.text
public class: BoxView [javadoc | source]
java.lang.Object
   javax.swing.text.View
      javax.swing.text.CompositeView
         javax.swing.text.BoxView

All Implemented Interfaces:
    SwingConstants

A view that arranges its children into a box shape by tiling its children along an axis. The box is somewhat like that found in TeX where there is alignment of the children, flexibility of the children is considered, etc. This is a building block that might be useful to represent things like a collection of lines, paragraphs, lists, columns, pages, etc. The axis along which the children are tiled is considered the major axis. The orthoginal axis is the minor axis.

Layout for each axis is handled separately by the methods layoutMajorAxis and layoutMinorAxis. Subclasses can change the layout algorithm by reimplementing these methods. These methods will be called as necessary depending upon whether or not there is cached layout information and the cache is considered valid. These methods are typically called if the given size along the axis changes, or if layoutChanged is called to force an updated layout. The layoutChanged method invalidates cached layout information, if there is any. The requirements published to the parent view are calculated by the methods calculateMajorAxisRequirements and calculateMinorAxisRequirements. If the layout algorithm is changed, these methods will likely need to be reimplemented.

Field Summary
 int majorAxis     
 int majorSpan     
 int minorSpan     
 boolean majorReqValid     
 boolean minorReqValid     
 SizeRequirements majorRequest     
 SizeRequirements minorRequest     
 boolean majorAllocValid     
 int[] majorOffsets     
 int[] majorSpans     
 boolean minorAllocValid     
 int[] minorOffsets     
 int[] minorSpans     
 Rectangle tempRect    used in paint. 
Fields inherited from javax.swing.text.View:
BadBreakWeight,  GoodBreakWeight,  ExcellentBreakWeight,  ForcedBreakWeight,  X_AXIS,  Y_AXIS,  sharedBiasReturn
Constructor:
 public BoxView(Element elem,
    int axis) 
    Constructs a BoxView.
    Parameters:
    elem - the element this view is responsible for
    axis - either View.X_AXIS or View.Y_AXIS
Method from javax.swing.text.BoxView Summary:
baselineLayout,   baselineRequirements,   calculateMajorAxisRequirements,   calculateMinorAxisRequirements,   checkRequests,   childAllocation,   flipEastAndWestAtEnds,   forwardUpdate,   getAlignment,   getAxis,   getChildAllocation,   getHeight,   getMaximumSpan,   getMinimumSpan,   getOffset,   getPreferredSpan,   getResizeWeight,   getSpan,   getSpanOnAxis,   getViewAtPoint,   getWidth,   isAfter,   isAllocationValid,   isBefore,   isLayoutValid,   layout,   layoutChanged,   layoutMajorAxis,   layoutMinorAxis,   modelToView,   paint,   paintChild,   preferenceChanged,   replace,   setAxis,   setSize,   setSpanOnAxis,   updateChildSizes,   updateLayoutArray,   viewToModel
Methods from javax.swing.text.CompositeView:
childAllocation,   flipEastAndWestAtEnds,   getBottomInset,   getChildAllocation,   getInsideAllocation,   getLeftInset,   getNextEastWestVisualPositionFrom,   getNextNorthSouthVisualPositionFrom,   getNextVisualPositionFrom,   getRightInset,   getTopInset,   getView,   getViewAtPoint,   getViewAtPosition,   getViewCount,   getViewIndex,   getViewIndexAtPosition,   isAfter,   isBefore,   loadChildren,   modelToView,   modelToView,   replace,   setInsets,   setParagraphInsets,   setParent,   viewToModel
Methods from javax.swing.text.View:
append,   breakView,   changedUpdate,   createFragment,   forwardUpdate,   forwardUpdateToView,   getAlignment,   getAttributes,   getBreakWeight,   getChildAllocation,   getContainer,   getDocument,   getElement,   getEndOffset,   getGraphics,   getMaximumSpan,   getMinimumSpan,   getNextVisualPositionFrom,   getParent,   getPreferredSpan,   getResizeWeight,   getStartOffset,   getToolTipText,   getView,   getViewCount,   getViewFactory,   getViewIndex,   getViewIndex,   insert,   insertUpdate,   isVisible,   modelToView,   modelToView,   modelToView,   paint,   preferenceChanged,   remove,   removeAll,   removeUpdate,   replace,   setParent,   setSize,   updateChildren,   updateLayout,   viewToModel,   viewToModel
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.text.BoxView Detail:
 protected  void baselineLayout(int targetSpan,
    int axis,
    int[] offsets,
    int[] spans) 
    Computes the location and extent of each child view in this BoxView given the targetSpan, which is the width (or height) of the region we have to work with.
 protected SizeRequirements baselineRequirements(int axis,
    SizeRequirements r) 
    Calculates the size requirements for this BoxView by examining the size of each child view.
 protected SizeRequirements calculateMajorAxisRequirements(int axis,
    SizeRequirements r) 
    Calculates the size requirements for the major axis axis.
 protected SizeRequirements calculateMinorAxisRequirements(int axis,
    SizeRequirements r) 
    Calculates the size requirements for the minor axis axis.
  void checkRequests(int axis) 
    Checks the request cache and update if needed.
 protected  void childAllocation(int index,
    Rectangle alloc) 
    Allocates a region for a child view.
 protected boolean flipEastAndWestAtEnds(int position,
    Bias bias) 
    Determines in which direction the next view lays. Consider the View at index n. Typically the Views are layed out from left to right, so that the View to the EAST will be at index n + 1, and the View to the WEST will be at index n - 1. In certain situations, such as with bidirectional text, it is possible that the View to EAST is not at index n + 1, but rather at index n - 1, or that the View to the WEST is not at index n - 1, but index n + 1. In this case this method would return true, indicating the Views are layed out in descending order. Otherwise the method would return false indicating the Views are layed out in ascending order.

    If the receiver is laying its Views along the Y_AXIS, this will will return the value from invoking the same method on the View responsible for rendering position and bias. Otherwise this will return false.

 protected  void forwardUpdate(ElementChange ec,
    DocumentEvent e,
    Shape a,
    ViewFactory f) 
    Forwards the given DocumentEvent to the child views that need to be notified of the change to the model. If a child changed its requirements and the allocation was valid prior to forwarding the portion of the box from the starting child to the end of the box will be repainted.
 public float getAlignment(int axis) 
    Determines the desired alignment for this view along an axis. This is implemented to give the total alignment needed to position the children with the alignment points lined up along the axis orthoginal to the axis that is being tiled. The axis being tiled will request to be centered (i.e. 0.5f).
 public int getAxis() 
    Fetches the tile axis property. This is the axis along which the child views are tiled.
 public Shape getChildAllocation(int index,
    Shape a) 
    Fetches the allocation for the given child view. This enables finding out where various views are located. This is implemented to return null if the layout is invalid, otherwise the superclass behavior is executed.
 public int getHeight() 
    Returns the current height of the box. This is the height that it was last allocated.
 public float getMaximumSpan(int axis) 
    Determines the maximum span for this view along an axis.
 public float getMinimumSpan(int axis) 
    Determines the minimum span for this view along an axis.
 protected int getOffset(int axis,
    int childIndex) 
    Fetches the offset of a particular child's current layout.
 public float getPreferredSpan(int axis) 
    Determines the preferred span for this view along an axis.
 public int getResizeWeight(int axis) 
    Gets the resize weight. A value of 0 or less is not resizable.
 protected int getSpan(int axis,
    int childIndex) 
    Fetches the span of a particular childs current layout.
 float getSpanOnAxis(int axis) 
    Returns the size of the view along an axis. This is implemented to return zero.
 protected View getViewAtPoint(int x,
    int y,
    Rectangle alloc) 
    Fetches the child view at the given coordinates.
 public int getWidth() 
    Returns the current width of the box. This is the width that it was last allocated.
 protected boolean isAfter(int x,
    int y,
    Rectangle innerAlloc) 
    Determines if a point falls after an allocated region.
 protected boolean isAllocationValid() 
    Are the allocations for the children still valid?
 protected boolean isBefore(int x,
    int y,
    Rectangle innerAlloc) 
    Determines if a point falls before an allocated region.
 protected boolean isLayoutValid(int axis) 
    Determines if the layout is valid along the given axis.
 protected  void layout(int width,
    int height) 
    Perform layout on the box
 public  void layoutChanged(int axis) 
    Invalidates the layout along an axis. This happens automatically if the preferences have changed for any of the child views. In some cases the layout may need to be recalculated when the preferences have not changed. The layout can be marked as invalid by calling this method. The layout will be updated the next time the setSize method is called on this view (typically in paint).
 protected  void layoutMajorAxis(int targetSpan,
    int axis,
    int[] offsets,
    int[] spans) 
    Performs layout for the major axis of the box (i.e. the axis that it represents). The results of the layout (the offset and span for each children) are placed in the given arrays which represent the allocations to the children along the major axis.
 protected  void layoutMinorAxis(int targetSpan,
    int axis,
    int[] offsets,
    int[] spans) 
    Performs layout for the minor axis of the box (i.e. the axis orthoginal to the axis that it represents). The results of the layout (the offset and span for each children) are placed in the given arrays which represent the allocations to the children along the minor axis.
 public Shape modelToView(int pos,
    Shape a,
    Bias b) throws BadLocationException 
    Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. This makes sure the allocation is valid before calling the superclass.
 public  void paint(Graphics g,
    Shape allocation) 
    Renders the BoxView using the given rendering surface and area on that surface. Only the children that intersect the clip bounds of the given Graphics will be rendered.
 protected  void paintChild(Graphics g,
    Rectangle alloc,
    int index) 
    Paints a child. By default that is all it does, but a subclass can use this to paint things relative to the child.
 public  void preferenceChanged(View child,
    boolean width,
    boolean height) 
    This is called by a child to indicate its preferred span has changed. This is implemented to throw away cached layout information so that new calculations will be done the next time the children need an allocation.
 public  void replace(int index,
    int length,
    View[] elems) 
    Invalidates the layout and resizes the cache of requests/allocations. The child allocations can still be accessed for the old layout, but the new children will have an offset and span of 0.
 public  void setAxis(int axis) 
    Sets the tile axis property. This is the axis along which the child views are tiled.
 public  void setSize(float width,
    float height) 
    Sets the size of the view. This should cause layout of the view if the view caches any layout information. This is implemented to call the layout method with the sizes inside of the insets.
  void setSpanOnAxis(int axis,
    float span) 
    Sets the size of the view along an axis. This should cause layout of the view along the given axis.
  void updateChildSizes() 
    Propagates the current allocations to the child views.
 int[] updateLayoutArray(int[] oldArray,
    int offset,
    int nInserted) 
    Resizes the given layout array to match the new number of child views. The current number of child views are used to produce the new array. The contents of the old array are inserted into the new array at the appropriate places so that the old layout information is transferred to the new array.
 public int viewToModel(float x,
    float y,
    Shape a,
    Bias[] bias) 
    Provides a mapping from the view coordinate space to the logical coordinate space of the model.