javax.swing.text.html
Class ImageView

java.lang.Object
  extended by javax.swing.text.View
      extended by javax.swing.text.html.ImageView
All Implemented Interfaces:
SwingConstants

public class ImageView
extends View

A view, representing a single image, represented by the HTML IMG tag.


Field Summary
 
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
ImageView(Element element)
          Creates the image view that represents the given element.
 
Method Summary
 float getAlignment(int axis)
          Get the image alignment.
 String getAltText()
          Get the text that should be shown as the image replacement and also as the image tool tip text.
 AttributeSet getAttributes()
          Returns the combination of the document and the style sheet attributes.
 Image getImage()
          Get the image to render.
 URL getImageURL()
          Get the URL location of the image to render.
 Icon getLoadingImageIcon()
          Get the icon that should be displayed while the image is loading and hence not yet available.
 boolean getLoadsSynchronously()
          Get the image loading strategy.
 Icon getNoImageIcon()
          Get the icon that should be displayed when the image is not available.
 float getPreferredSpan(int axis)
          Get the preferred span of the image along the axis.
protected  StyleSheet getStyleSheet()
          Get the associated style sheet from the document.
 String getToolTipText(float x, float y, Shape shape)
          Get the tool tip text.
 Shape modelToView(int pos, Shape area, Position.Bias bias)
          This is currently implemented always to return the area of the image view, as the image is not divideable by character positions.
 void paint(Graphics g, Shape bounds)
          Paints the image or one of the two image state icons.
 void setLoadsSynchronously(boolean load_on_demand)
          Set if the image should be loaded only when needed (synchronuosly).
protected  void setPropertiesFromAttributes()
          Update all cached properties from the attribute set, returned by the getAttributes().
 void setSize(float width, float height)
          Starts loading the image asynchronuosly.
 int viewToModel(float x, float y, Shape shape, Position.Bias[] bias)
          Maps the picture co-ordinates into the image position in the model.
 
Methods inherited from class javax.swing.text.View
append, breakView, changedUpdate, createFragment, dump, forwardUpdate, forwardUpdateToView, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, setParent, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageView

public ImageView(Element element)
Creates the image view that represents the given element.

Parameters:
element - the element, represented by this image view.
Method Detail

getAlignment

public float getAlignment(int axis)
Get the image alignment. This method works handling standart alignment attributes in the HTML IMG tag (align = top bottom middle left right). Depending from the parameter, either horizontal or vertical alingment information is returned.

Overrides:
getAlignment in class View
Parameters:
axis - - either X_AXIS or Y_AXIS
Returns:
the alignment of this view along the parents baseline for the specified axis

getAltText

public String getAltText()
Get the text that should be shown as the image replacement and also as the image tool tip text. The method returns the value of the attribute, having the name HTML.Attribute.ALT. If there is no such attribute, the image name from the url is returned. If the URL is not available, the empty string is returned.


getAttributes

public AttributeSet getAttributes()
Returns the combination of the document and the style sheet attributes.

Overrides:
getAttributes in class View

getImage

public Image getImage()
Get the image to render. May return null if the image is not yet loaded.


getImageURL

public URL getImageURL()
Get the URL location of the image to render. If this method returns null, the "no image" icon is rendered instead. By defaul, url must be present as the "src" property of the IMG tag. If it is missing, null is returned and the "no image" icon is rendered.

Returns:
the URL location of the image to render.

getLoadingImageIcon

public Icon getLoadingImageIcon()
Get the icon that should be displayed while the image is loading and hence not yet available.

Returns:
an icon, showing a non broken sheet of paper with image.

getLoadsSynchronously

public boolean getLoadsSynchronously()
Get the image loading strategy.

Returns:
false (default) if the image is loaded when the view is constructed, true if the image is only loaded on demand when rendering.

getNoImageIcon

public Icon getNoImageIcon()
Get the icon that should be displayed when the image is not available.

Returns:
an icon, showing a broken sheet of paper with image.

getPreferredSpan

public float getPreferredSpan(int axis)
Get the preferred span of the image along the axis. The image size is first requested to the attributes HTML.Attribute.WIDTH and HTML.Attribute.HEIGHT. If they are missing, and the image is already loaded, the image size is returned. If there are no attributes, and the image is not loaded, zero is returned.

Specified by:
getPreferredSpan in class View
Parameters:
axis - - either X_AXIS or Y_AXIS
Returns:
either width of height of the image, depending on the axis.

getStyleSheet

protected StyleSheet getStyleSheet()
Get the associated style sheet from the document.

Returns:
the associated style sheet.

getToolTipText

public String getToolTipText(float x,
                             float y,
                             Shape shape)
Get the tool tip text. This is overridden to return the value of the getAltText(). The parameters are ignored.

Overrides:
getToolTipText in class View
Returns:
that is returned by getAltText().

paint

public void paint(Graphics g,
                  Shape bounds)
Paints the image or one of the two image state icons. The image is resized to the shape bounds. If there is no image available, the alternative text is displayed besides the image state icon.

Specified by:
paint in class View
Parameters:
g - the Graphics, used for painting.
bounds - the bounds of the region where the image or replacing icon must be painted.

setLoadsSynchronously

public void setLoadsSynchronously(boolean load_on_demand)
Set if the image should be loaded only when needed (synchronuosly). By default, the image loads asynchronuosly. If the image is not yet ready, the icon, returned by the getLoadingImageIcon(), is displayed.


setPropertiesFromAttributes

protected void setPropertiesFromAttributes()
Update all cached properties from the attribute set, returned by the getAttributes().


viewToModel

public int viewToModel(float x,
                       float y,
                       Shape shape,
                       Position.Bias[] bias)
Maps the picture co-ordinates into the image position in the model. As the image is not divideable, this is currently implemented always to return the start offset.

Specified by:
viewToModel in class View
Parameters:
x - the x coordinate in the view space
y - the y coordinate in the view space
shape - the allocation of this View
bias - the bias to use
Returns:
the position in the document that corresponds to the screen coordinates x, y

modelToView

public Shape modelToView(int pos,
                         Shape area,
                         Position.Bias bias)
                  throws BadLocationException
This is currently implemented always to return the area of the image view, as the image is not divideable by character positions.

Specified by:
modelToView in class View
Parameters:
pos - character position
area - of the image view
bias - bias
Returns:
the shape, where the given character position should be mapped.
Throws:
BadLocationException - if pos is invalid

setSize

public void setSize(float width,
                    float height)
Starts loading the image asynchronuosly. If the image must be loaded synchronuosly instead, the setLoadsSynchronously(boolean) must be called before calling this method. The passed parameters are not used.

Overrides:
setSize in class View