javax.swing.text.html
Class HRuleView

java.lang.Object
  extended byjavax.swing.text.View
      extended byjavax.swing.text.html.HRuleView
All Implemented Interfaces:
SwingConstants

class HRuleView
extends View

A view implementation to display an html horizontal rule.

Author:
Timothy Prinzing, Sara Swanson

Field Summary
private  int alignment
           
private  AttributeSet attr
          View Attributes.
private  float bottomMargin
           
private  float leftMargin
           
private  String noshade
           
private  float rightMargin
           
private  int size
           
private static int SPACE_ABOVE
           
private static int SPACE_BELOW
           
private  float topMargin
           
private  CSS.LengthValue widthValue
           
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, 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
HRuleView(Element elem)
          Creates a new view that represents an <hr> element.
 
Method Summary
 View breakView(int axis, int offset, float pos, float len)
          Tries to break this view on the given axis.
 void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f)
          Gives notification from the document that attributes were changed in a location that this view is responsible for.
 AttributeSet getAttributes()
          Fetches the attributes to use when rendering.
 int getBreakWeight(int axis, float pos, float len)
          Determines how attractive a break opportunity in this view is.
private  float getLength(CSS.Attribute key, AttributeSet a)
           
 float getPreferredSpan(int axis)
          Calculates the desired shape of the rule... this is basically the preferred size of the border.
 int getResizeWeight(int axis)
          Gets the resize weight for the axis.
 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)
          Paints the view.
protected  void setPropertiesFromAttributes()
          Update any cached values that come from attributes.
 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.View
append, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, setParent, setSize, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

topMargin

private float topMargin

bottomMargin

private float bottomMargin

leftMargin

private float leftMargin

rightMargin

private float rightMargin

alignment

private int alignment

noshade

private String noshade

size

private int size

widthValue

private CSS.LengthValue widthValue

SPACE_ABOVE

private static final int SPACE_ABOVE
See Also:
Constant Field Values

SPACE_BELOW

private static final int SPACE_BELOW
See Also:
Constant Field Values

attr

private AttributeSet attr
View Attributes.

Constructor Detail

HRuleView

public HRuleView(Element elem)
Creates a new view that represents an <hr> element.

Parameters:
elem - the element to create a view for
Method Detail

setPropertiesFromAttributes

protected void setPropertiesFromAttributes()
Update any cached values that come from attributes.


getLength

private float getLength(CSS.Attribute key,
                        AttributeSet a)

paint

public void paint(Graphics g,
                  Shape a)
Paints the view.

Specified by:
paint in class View
Parameters:
g - the graphics context
a - the allocation region for the view
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

getPreferredSpan

public float getPreferredSpan(int axis)
Calculates the desired shape of the rule... this is basically the preferred size of the border.

Specified by:
getPreferredSpan in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the desired span
See Also:
View.getPreferredSpan(int)

getResizeWeight

public int getResizeWeight(int axis)
Gets the resize weight for the axis. The rule is: rigid vertically and flexible horizontally.

Overrides:
getResizeWeight in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the weight

getBreakWeight

public int getBreakWeight(int axis,
                          float pos,
                          float len)
Determines how attractive a break opportunity in this view is. This is implemented to request a forced break.

Overrides:
getBreakWeight in class View
Parameters:
axis - may be either View.X_AXIS or View.Y_AXIS
pos - the potential location of the start of the broken view (greater than or equal to zero). This may be useful for calculating tab positions.
len - specifies the relative length from pos where a potential break is desired. The value must be greater than or equal to zero.
Returns:
the weight, which should be a value between ForcedBreakWeight and BadBreakWeight.
See Also:
LabelView, ParagraphView, View.BadBreakWeight, View.GoodBreakWeight, View.ExcellentBreakWeight, View.ForcedBreakWeight

breakView

public View breakView(int axis,
                      int offset,
                      float pos,
                      float len)
Description copied from class: View
Tries to break this view on the given axis. This is called by views that try to do formatting of their children. For example, a view of a paragraph will typically try to place its children into row and views representing chunks of text can sometimes be broken down into smaller pieces.

This is implemented to return the view itself, which represents the default behavior on not being breakable. If the view does support breaking, the starting offset of the view returned should be the given offset, and the end offset should be less than or equal to the end offset of the view being broken.

Overrides:
breakView in class View
Parameters:
axis - may be either View.X_AXIS or View.Y_AXIS
offset - the location in the document model that a broken fragment would occupy >= 0. This would be the starting offset of the fragment returned
pos - the position along the axis that the broken view would occupy >= 0. This may be useful for things like tab calculations
len - specifies the distance along the axis where a potential break is desired >= 0
Returns:
the fragment of the view that represents the given span, if the view can be broken. If the view doesn't support breaking behavior, the view itself is returned.
See Also:
ParagraphView

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.

Specified by:
modelToView in class View
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; b will have one of these values:
  • Position.Bias.Forward
  • Position.Bias.Backward
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)

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.

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

getAttributes

public AttributeSet getAttributes()
Fetches the attributes to use when rendering. This is implemented to multiplex the attributes specified in the model with a StyleSheet.

Overrides:
getAttributes in class View

changedUpdate

public void changedUpdate(DocumentEvent changes,
                          Shape a,
                          ViewFactory f)
Description copied from class: View
Gives notification from the document that attributes were changed in a location that this view is responsible for. To reduce the burden to subclasses, this functionality is spread out into the following calls that subclasses can reimplement:
  1. updateChildren is called if there were any changes to the element this view is responsible for. If this view has child views that are represent the child elements, then this method should do whatever is necessary to make sure the child views correctly represent the model.
  2. forwardUpdate is called to forward the DocumentEvent to the appropriate child views.
  3. updateLayout is called to give the view a chance to either repair its layout, to reschedule layout, or do nothing.

Overrides:
changedUpdate in class View
Parameters:
changes - 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.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)