sferyx.administration.renderers
Class CustomImageView

java.lang.Object
  extended by javax.swing.text.View
      extended by sferyx.administration.renderers.CustomImageView
All Implemented Interfaces:
javax.swing.SwingConstants, CSSLayoutViews
Direct Known Subclasses:
CustomObjectView

public class CustomImageView
extends javax.swing.text.View
implements CSSLayoutViews

CustomImageView paints the images inside the editor, fixing the Sun's API bug when painting resized gif images.


Field Summary
protected  java.awt.Rectangle fBounds
           
 int height
           
protected  java.awt.Image image
           
protected static java.lang.String IMAGE_CACHE_PROPERTY
          Document property for image cache.
protected static java.util.Hashtable imageCache
           
 int width
           
 
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
CustomImageView(javax.swing.text.Element elem)
          Creates a new view that represents an IMG element.
 
Method Summary
 void changedUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)
          Invoked when the Elements attributes have changed.
 boolean containsImageMap()
           
protected  void finalize()
           
 int getAbsoluteX()
           
 int getAbsoluteY()
           
 float getAlignment(int axis)
          Determines the desired alignment for this view along an axis.
 java.lang.String getAltText()
          Returns the text to display if the image can't be loaded.
 javax.swing.text.AttributeSet getAttributes()
          Fetches the attributes to use when rendering.
 int getBottomMargin()
           
 int getBottomPadding()
           
 int getBreakWeight(int axis, float pos, float len)
           
 float getHeightCSSValue()
           
 HTMLBrowser getHTMLEditor()
           
 java.awt.Image getImage()
          Returns the image to render.
 sferyx.administration.renderers.EditorHTMLDocument.CustomMap getImageMap()
           
 java.net.URL getImageURL()
          Return a URL for the image source, or null if it could not be determined.
 int getLeftMargin()
           
 int getLeftPadding()
           
 javax.swing.Icon getLoadingImageIcon()
          Returns the icon to use while in the process of loading the image.
 boolean getLoadsSynchronously()
          Returns true if the image should be loaded when first asked for.
 float getMaxHeightCSSValue()
           
 float getMaximumSpan_(int axis)
           
 float getMaximumSpan(int axis)
           
 float getMaximumSpanNew(int axis)
           
 float getMaxWidthCSSValue()
           
 float getMinimumSpan_(int axis)
           
 float getMinimumSpan(int axis)
           
 float getMinWidthCSSValue()
           
 javax.swing.Icon getNoImageIcon()
          Returns the icon to use if the image couldn't be found.
 float getPreferredSpan_(int axis)
           
 float getPreferredSpan(int axis)
          Determines the preferred span for this view along an axis.
 int getResizeWeight(int axis)
           
 int getRightMargin()
           
 int getRightPadding()
           
protected  javax.swing.text.html.StyleSheet getStyleSheet()
          Convenience method to get the StyleSheet.
 java.lang.String getToolTipText(float x, float y, java.awt.Shape allocation)
          For images the tooltip text comes from text specified with the ALT attribute.
 int getTopMargin()
           
 int getTopPadding()
           
 float getWidthCSSValue()
           
 boolean isAbsolutePositioning()
           
 boolean isFillSelected()
           
 boolean isRelativePositioning()
           
 boolean isSelected()
           
protected  void loadImage()
           
 java.awt.Shape modelToView(int pos, java.awt.Shape a, javax.swing.text.Position.Bias b)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 void paint(java.awt.Graphics g, java.awt.Shape a)
           
 void setLoadsSynchronously(boolean newValue)
          Sets how the image is loaded.
 void setParent(javax.swing.text.View parent)
          Establishes the parent view for this view.
protected  void setPropertiesFromAttributes()
          Update any cached values that come from attributes.
 void setSize(float width, float height)
          Sets the size of the view.
static java.awt.image.BufferedImage toBufferedImage(java.awt.Image img)
           
 int viewToModel(float x, float y, java.awt.Shape a, javax.swing.text.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, breakView, createFragment, forwardUpdate, forwardUpdateToView, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getNextVisualPositionFrom, getParent, getStartOffset, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, removeUpdate, replace, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMAGE_CACHE_PROPERTY

protected static final java.lang.String IMAGE_CACHE_PROPERTY
Document property for image cache.

See Also:
Constant Field Values

image

protected java.awt.Image image

width

public int width

height

public int height

fBounds

protected java.awt.Rectangle fBounds

imageCache

protected static java.util.Hashtable imageCache
Constructor Detail

CustomImageView

public CustomImageView(javax.swing.text.Element elem)
Creates a new view that represents an IMG element.

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

getResizeWeight

public int getResizeWeight(int axis)
Overrides:
getResizeWeight in class javax.swing.text.View

getBreakWeight

public int getBreakWeight(int axis,
                          float pos,
                          float len)
Overrides:
getBreakWeight in class javax.swing.text.View

isAbsolutePositioning

public boolean isAbsolutePositioning()
Specified by:
isAbsolutePositioning in interface CSSLayoutViews

isRelativePositioning

public boolean isRelativePositioning()
Specified by:
isRelativePositioning in interface CSSLayoutViews

getAbsoluteX

public int getAbsoluteX()
Specified by:
getAbsoluteX in interface CSSLayoutViews

getAbsoluteY

public int getAbsoluteY()
Specified by:
getAbsoluteY in interface CSSLayoutViews

getHTMLEditor

public HTMLBrowser getHTMLEditor()

isFillSelected

public boolean isFillSelected()

isSelected

public boolean isSelected()

getAltText

public java.lang.String getAltText()
Returns the text to display if the image can't be loaded. This is obtained from the Elements attribute set with the attribute name HTML.Attribute.ALT.


getImageURL

public java.net.URL getImageURL()
Return a URL for the image source, or null if it could not be determined.


getNoImageIcon

public javax.swing.Icon getNoImageIcon()
Returns the icon to use if the image couldn't be found.


getLoadingImageIcon

public javax.swing.Icon getLoadingImageIcon()
Returns the icon to use while in the process of loading the image.


getImage

public java.awt.Image getImage()
Returns the image to render.


setLoadsSynchronously

public void setLoadsSynchronously(boolean newValue)
Sets how the image is loaded. If newValue is true, the image we be loaded when first asked for, otherwise it will be loaded asynchronously. The default is to not load synchronously, that is to load the image asynchronously.


getLoadsSynchronously

public boolean getLoadsSynchronously()
Returns true if the image should be loaded when first asked for.


getStyleSheet

protected javax.swing.text.html.StyleSheet getStyleSheet()
Convenience method to get the StyleSheet.


getAttributes

public javax.swing.text.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 javax.swing.text.View

getToolTipText

public java.lang.String getToolTipText(float x,
                                       float y,
                                       java.awt.Shape allocation)
For images the tooltip text comes from text specified with the ALT attribute. This is overriden to return getAltText.

Overrides:
getToolTipText in class javax.swing.text.View
See Also:
JTextComponent.getToolTipText(java.awt.event.MouseEvent)

setPropertiesFromAttributes

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


getRightMargin

public int getRightMargin()
Specified by:
getRightMargin in interface CSSLayoutViews

getLeftMargin

public int getLeftMargin()
Specified by:
getLeftMargin in interface CSSLayoutViews

getTopMargin

public int getTopMargin()
Specified by:
getTopMargin in interface CSSLayoutViews

getBottomMargin

public int getBottomMargin()
Specified by:
getBottomMargin in interface CSSLayoutViews

getRightPadding

public int getRightPadding()

getLeftPadding

public int getLeftPadding()

getTopPadding

public int getTopPadding()

getBottomPadding

public int getBottomPadding()

setParent

public void setParent(javax.swing.text.View parent)
Establishes the parent view for this view. Seize this moment to cache the AWT Container I'm in.

Overrides:
setParent in class javax.swing.text.View

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e,
                          java.awt.Shape a,
                          javax.swing.text.ViewFactory f)
Invoked when the Elements attributes have changed. Recreates the image.

Overrides:
changedUpdate in class javax.swing.text.View

paint

public void paint(java.awt.Graphics g,
                  java.awt.Shape a)
Specified by:
paint in class javax.swing.text.View

getImageMap

public sferyx.administration.renderers.EditorHTMLDocument.CustomMap getImageMap()

containsImageMap

public boolean containsImageMap()

getMaximumSpanNew

public float getMaximumSpanNew(int axis)

getMaximumSpan

public float getMaximumSpan(int axis)
Overrides:
getMaximumSpan in class javax.swing.text.View

getMaximumSpan_

public float getMaximumSpan_(int axis)

getMaxWidthCSSValue

public float getMaxWidthCSSValue()

getMaxHeightCSSValue

public float getMaxHeightCSSValue()

getMinWidthCSSValue

public float getMinWidthCSSValue()

getMinimumSpan

public float getMinimumSpan(int axis)
Overrides:
getMinimumSpan in class javax.swing.text.View

getMinimumSpan_

public float getMinimumSpan_(int axis)

getPreferredSpan

public float getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.

Specified by:
getPreferredSpan in class javax.swing.text.View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the span the view would like to be rendered into; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view

getPreferredSpan_

public float getPreferredSpan_(int axis)

getHeightCSSValue

public float getHeightCSSValue()

getWidthCSSValue

public float getWidthCSSValue()

getAlignment

public float getAlignment(int axis)
Determines the desired alignment for this view along an axis. This is implemented to give the alignment to the bottom of the icon along the y axis, and the default along the x axis.

Overrides:
getAlignment in class javax.swing.text.View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the desired alignment; this should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin; an alignment of 0.5 would be the center of the view

modelToView

public java.awt.Shape modelToView(int pos,
                                  java.awt.Shape a,
                                  javax.swing.text.Position.Bias b)
                           throws javax.swing.text.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 javax.swing.text.View
Parameters:
pos - the position to convert
a - the allocated region to render into
Returns:
the bounding box of the given position
Throws:
javax.swing.text.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,
                       java.awt.Shape a,
                       javax.swing.text.Position.Bias[] bias)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Specified by:
viewToModel in class javax.swing.text.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[])

setSize

public void setSize(float width,
                    float height)
Sets the size of the view. This should cause layout of the view if it has any layout duties.

Overrides:
setSize in class javax.swing.text.View
Parameters:
width - the width >= 0
height - the height >= 0

toBufferedImage

public static java.awt.image.BufferedImage toBufferedImage(java.awt.Image img)

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

loadImage

protected void loadImage()