|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jhotdraw.standard.AbstractFigure
org.jhotdraw.figures.AttributeFigure
org.jhotdraw.contrib.TextAreaFigure
org.jhotdraw.contrib.html.HTMLTextAreaFigure
An HTMLTextAreaFigure contains HTML formatted text.
Formatting is done internally by a JLabel component, so all display features
and constrains that apply for a JLabel apply also for an HTMLTextAreaFigure,
including text and images, as in any Web browser, even allowing for contents
residing on external Web sources. But don't forget that this is NOT a Web
browser, so HTML contents cannot be standard Web pages with headers, stylesheets,
javascript and who knows what else, just plain down to earth HTML code.
In order to automatically integrate "external" attributes like FillColor,
FontName, etc, HTMLTextAreaFigure encapsulates the text the user types in the
editor within a table with a single cell occupying the whole area.
Here is what the HTML code passed to the JLabel looks like:
<html>
<table border='0' width='area.width' height='area.height'
cellpadding='0' cellspacing='0' bgcolor='&FillColor;'>
<tr>
<td width='100%'>
<font face='&FontName;' color='&TextColor;' size='&FontSize;'>
<!-- add italic and bold attributes if required-->
<i>
<b>
============>> User's contents go here <============
<!-- close italic and bold attributes if required -->
</b>
</i>
</font>
</td>
</tr>
</table>
</html>
It is possible to write raw HTML code by calling
setRawHTML(true)
. In that case no tags are issued.
The user is then responsible for applying the figure attributes and in
general is responsible for the whole display.
This setting can be dynamically toggled as needed.
Note that JLabel resets the font to its own default whenever it encounters
an HTML structure, like a table or a header tag. I couldn't find a workaround
for what can/should be called a bug. Normal browsers do not behave like this.
Internal attributes like FillColor or FontName are exposed as special SGML
entities using the standard SGML entity notation, ex: &FillColor;
.
Any attribute associated to the figure can be used and will be replaced with
an appropriate value from a ContentsProducer (see below) or its
toString() value if no specific ContentProducer is defined.
The HTML display and layouting can be time consuming, quite fast in most cases,
unless the HTML structure is complicated. This can become a serious penalty
when working with a large number of complicated figures.
To help in this issue HTMLTextAreaFigure offers two display modes, DirectDraw,
where the HTML layout logic is executed every time the figure is displayed, and
BufferedDraw, where HTMLTextAreaFigure creates an in-memory image of the
resulting layout and uses the image for fast display until a change requires
to regenerate the image.
The BufferedDraw mode is as fast as an image display can be, but it consumes
more memory than the DirectDraw mode, which in turn is slower.
The setting is specific to each figure instance and it can be dynamically
toggled at any time, so it is possible to fine tune when and which figures
use either one of the drawing modes.
Remember the attributes based SGML entities?
If you set the figure to be read only, so not allowing the user to directly
edit the HTML contens, then it is possible to use HTMLTextAreaFigures to
produce very elaborate and complex information layout.
You create HTML templates for each figure layout you want to use and set them
as the text of the figure. Within the template text you place field names
wherever needed as you would for a Web page, then each figure using the template
associates the field values as attributes of the figure. The attribute exposure
feature will substitute the entity names with the current attribute's value.
Please refer to the accompanying sample program to see in detail the multiple
ways this feature can enhance your drawings.
ContentProducers
As stated above, entities referenced in the HTML template code are replaced by
their current value in the drawn figure. The values themselves are provided
by ContentProducers.
For a detailed description of ContentProducers please refer to their
own documentation, but to make it simple, a ContentProducer is an object that
implements the method getContent
and is registered to produce
content for either specific entities, or entity classes.
An entity class is the class of the attribute containing its value, ie: an
attribute containing a URL has class URL (attribute.getClass()
),
and an URLContentProducer can be associated to it so that when the layout
needs the entity's value, the producer's getContent() method is called and the
returned value (ex: contents from a Web page, FTP file or disk file) is used
to replace the entity in the displayed figure.
The ContentProducer can return either a String, in which case it is used
as is, or another Object. In the later case HTMLTextAreaFigure will
continue calling registered ContentProviders depending on the class of the
returned Object until it either gets a final String, or null. If null then
the entity is considered as unknown and left as is in the displayed text. To
make it dissapear alltogether the producer should return an empty String.
HTMLTextAreaFigure registers default ContentProducers:
AttributeFigureContentProducer for the intrinsic attributes of the figure
(height, width, font name, etc.), URLContentProducer for URL attributes,
HTMLColorContentProducer for HTML color encoding and for embedded
TextAreaFigure and HTMLTextAreaFigure classes. That's right, you can embed
a TextAreaFigure or HTMLTextAreaFigure contents inside an HTMLTextAreaFigure
recursively for as many levels as your CPU and memory will allow.
For instance, the main figure can consists of an HTML table where each
cell's contents come from a different HTMLTextAreaFigure.
Field Summary | |
static char |
END_ENTITY_CHAR
End marker for embedded attribute values |
static char |
ESCAPE_CHAR
Marker escape character |
static char |
START_ENTITY_CHAR
Start marker for embedded attribute values |
Fields inherited from class org.jhotdraw.contrib.TextAreaFigure |
attributesMap, fFont, fFontIsDirty, fFontWidth, fIsReadOnly, fLocator, fObservedFigure, fParagraphs, fSizeIsDirty, fText, fTextIsDirty |
Fields inherited from interface org.jhotdraw.framework.Figure |
POPUP_MENU |
Constructor Summary | |
HTMLTextAreaFigure()
Constructor for the HTMLTextAreaFigure object |
Method Summary | |
protected void |
addPopupMenuItems(javax.swing.JPopupMenu popupMenu)
Adds items to the popup menu |
void |
basicDisplayBox(java.awt.Point origin,
java.awt.Point corner)
Sets the display box for the figure |
java.lang.Object |
clone()
Clones a figure and initializes it |
boolean |
containsPoint(int x,
int y)
True if the figure contains the point. |
protected void |
createImage(int width,
int height)
Creates the cached image, unless there is already one and it is compatible with new request, in which case we reuse it |
protected javax.swing.JPopupMenu |
createPopupMenu()
Factory method to create a popup menu which allows to set options |
void |
draw(java.awt.Graphics g)
Draws the figure in the given graphics. |
void |
drawBackground(java.awt.Graphics g)
Draws the background for the figure. |
void |
drawFrame(java.awt.Graphics g)
Draws the frame around the text. |
protected float |
drawText(java.awt.Graphics g,
java.awt.Rectangle displayBox)
Formats and draws the text for the figure |
protected void |
drawTextDirect(java.awt.Graphics2D g2,
java.awt.Rectangle drawingBox)
Draws the text directly onto the drawing, without using the cached figure |
void |
figureChanged(FigureChangeEvent e)
handles frame figure's changed events. |
void |
figureInvalidated(FigureChangeEvent e)
handles frame figure's invalidated events |
void |
figureRemoved(FigureChangeEvent e)
handles frame figure's invalidatedremoved events. |
void |
figureRequestRemove(FigureChangeEvent e)
handles frame figure's remove requests events. |
void |
figureRequestUpdate(FigureChangeEvent e)
handles frame figure's update requests events. |
protected void |
generateImage(java.awt.Rectangle drawingBox)
Generates the HTML image to be used for fast BufferedDrawing |
protected java.awt.Shape |
getClippingShape()
Gets the clippingShape attribute of the HTMLTextAreaFigure object |
protected javax.swing.JPanel |
getContainerPanel(java.awt.Component drawingDelegate,
java.awt.Rectangle displayBox)
Builds the container for the drawing delegate |
protected ContentProducer |
getContentProducer(java.lang.Class targetClass)
Retrieves a suitable content producer for the target class |
protected javax.swing.JLabel |
getDisplayDelegate()
Gets the displayDelegate attribute of the HTMLTextAreaFigure object |
protected java.lang.String |
getEntityHTMLRepresentation(java.lang.String attrName)
Returns a string representation of the attribute according to its type |
protected Figure |
getFrameFigure()
Gets the frameFigure attribute of the HTMLTextAreaFigure object |
protected java.lang.String |
getHTMLText(java.lang.String text,
java.awt.Font font,
java.lang.String textColor,
java.lang.String backColor,
java.awt.Rectangle displayBox)
Returns a string that is valid HTML contents for a JLabel. |
protected java.awt.image.BufferedImage |
getImage()
Gets the image. |
protected ContentProducer |
getIntrinsicContentProducer()
Gets the IntrinsicContentProducer attribute of the HTMLTextAreaFigure object. |
java.awt.Polygon |
getPolygon()
Makes a polygon with the same shape and dimensions as the current figure |
Figure |
getRepresentingFigure()
Usually, a TextHolders is implemented by a Figure subclass. |
HandleEnumeration |
handles()
Returns an iterator of standard sizing handles to manipulate the figure |
protected void |
initialize()
Initializes the figure |
protected boolean |
isImageDirty()
True if the image should be regenerated |
boolean |
isRawHTML()
Gets the rawHTML attribute of the HTMLTextAreaFigure object. |
protected java.awt.Rectangle |
makeDrawingBox(java.awt.Rectangle displayBox)
Builds the drawing box using the margins |
protected void |
markFontDirty()
Called whenever the something changes that requires font recomputing |
protected void |
markImageDirty()
Disposes of the image so it will be regenerated next time it is displayed |
protected void |
markSizeDirty()
Called whenever the something changes that requires size recomputing |
protected void |
markTextDirty()
Called whenever the something changes that requires text recomputing |
void |
moveBy(int dx,
int dy)
Moves the figure by the specified displacement |
void |
read(StorableInput dr)
Reads the figure from StorableInput |
ContentProducer |
registerContentProducer(java.lang.Class targetClass,
ContentProducer producer)
Registers a specific content producer for the target class |
protected float |
renderText(java.awt.Graphics2D g2,
java.awt.Rectangle drawingBox)
Renders the HTML formatted text onto the supplied Graphics. |
void |
setAttribute(FigureAttributeConstant name,
java.lang.Object value)
A text area figure uses the "LeftMargin", "RightMargin", "TopMargin", "BottomMargin", "TabSize", "FontSize", "FontStyle", and "FontName" attributes |
void |
setFrameFigure(Figure newFrameFigure)
Sets the frameFigure attribute of the HTMLTextAreaFigure object |
protected void |
setImage(java.awt.image.BufferedImage newImage)
Sets the image attribute of the HTMLTextAreaFigure object |
void |
setIntrinsicContentProducer(ContentProducer newIntrinsicContentProducer)
Sets the IntrinsicContentProducer attribute of the HTMLTextAreaFigure object |
void |
setRawHTML(boolean newRawHTML)
Sets the rawHTML attribute of the HTMLTextAreaFigure object |
void |
setUseBufferedDraw(boolean newUseBufferedDraw)
Sets the useBufferedDraw attribute of the HTMLTextAreaFigure object |
void |
setUseDirectDraw(boolean newUseDirectDraw)
Sets the useDirectDraw attribute of the HTMLTextAreaFigure object |
protected java.lang.String |
substituteEntityKeywords(java.lang.String template)
Returns a new String with the entity keywords replaced by their current attribute value. |
void |
unregisterContentProducer(java.lang.Class targetClass,
ContentProducer producer)
Unregisters a registered content producer. |
boolean |
usesBufferedDraw()
Gets the usesBufferedDraw attribute of the HTMLTextAreaFigure object |
boolean |
usesDirectDraw()
Gets the usesDirectDraw status of the HTMLTextAreaFigure object |
void |
write(StorableOutput dw)
Writes the figure to StorableOutput |
Methods inherited from class org.jhotdraw.contrib.TextAreaFigure |
acceptsTyping, basicMoveBy, connect, createFont, disconnect, displayBox, getAttribute, getFont, getFontWidth, getNextParagraph, getText, getTextColor, isEmpty, isFontDirty, isReadOnly, isSizeDirty, isTextDirty, overlayColumns, prepareText, readObject, setAttribute, setFont, setFontDirty, setReadOnly, setSizeDirty, setText, setTextDirty, textDisplayBox, updateFontInfo, updateLocation |
Methods inherited from class org.jhotdraw.figures.AttributeFigure |
getAttribute, getDefaultAttribute, getDefaultAttribute, getFillColor, getFrameColor, initDefaultAttribute, setDefaultAttribute |
Methods inherited from class org.jhotdraw.standard.AbstractFigure |
addDependendFigure, addFigureChangeListener, addToContainer, canConnect, center, changed, connectedTextLocator, connectionInsets, connectorAt, connectorVisibility, decompose, displayBox, displayBox, figures, findFigureInside, getDecoratedFigure, getDependendFigures, getTextHolder, getZValue, includes, invalidate, invalidateRectangle, listener, release, removeDependendFigure, removeFigureChangeListener, removeFromContainer, setZValue, size, visit, willChange |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.jhotdraw.contrib.html.AttributeContentProducerContext |
getAttribute |
Methods inherited from interface org.jhotdraw.contrib.html.FigureContentProducerContext |
displayBox, getFont |
Field Detail |
public static final char START_ENTITY_CHAR
public static final char END_ENTITY_CHAR
public static final char ESCAPE_CHAR
Constructor Detail |
public HTMLTextAreaFigure()
Method Detail |
public java.lang.Object clone()
clone
in interface Figure
clone
in class AbstractFigure
Figure.clone()
public void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
basicDisplayBox
in interface Figure
basicDisplayBox
in class TextAreaFigure
origin
- origin pointcorner
- corner pointFigure
public HandleEnumeration handles()
handles
in interface Figure
handles
in class TextAreaFigure
public boolean containsPoint(int x, int y)
containsPoint
in interface Figure
containsPoint
in class AbstractFigure
x
- Description of the Parametery
- Description of the Parameter
public void moveBy(int dx, int dy)
moveBy
in interface Figure
moveBy
in class TextAreaFigure
dx
- Description of the Parameterdy
- Description of the Parameterprotected void initialize()
protected void markSizeDirty()
markSizeDirty
in class TextAreaFigure
protected void markTextDirty()
markTextDirty
in class TextAreaFigure
protected void markFontDirty()
markFontDirty
in class TextAreaFigure
public void draw(java.awt.Graphics g)
draw
in interface Figure
draw
in class TextAreaFigure
g
- Description of the Parameterpublic void drawFrame(java.awt.Graphics g)
drawFrame
in class TextAreaFigure
g
- The graphics to use for the drawingpublic void drawBackground(java.awt.Graphics g)
drawBackground
in class TextAreaFigure
g
- The graphics to use for the drawingprotected float drawText(java.awt.Graphics g, java.awt.Rectangle displayBox)
drawText
in class TextAreaFigure
g
- the graphics for the drawing. It can be null when
called just to compute the sizedisplayBox
- the display box within which the text should be formatted and drawn
protected void generateImage(java.awt.Rectangle drawingBox)
drawingBox
- Description of the Parameterprotected void drawTextDirect(java.awt.Graphics2D g2, java.awt.Rectangle drawingBox)
g2
- Description of the ParameterdrawingBox
- Description of the Parameterprotected float renderText(java.awt.Graphics2D g2, java.awt.Rectangle drawingBox)
g2
- Description of the ParameterdrawingBox
- Description of the Parameter
protected java.awt.Rectangle makeDrawingBox(java.awt.Rectangle displayBox)
displayBox
- Description of the Parameter
protected javax.swing.JLabel getDisplayDelegate()
protected void createImage(int width, int height)
width
- Description of the Parameterheight
- Description of the Parameterprotected javax.swing.JPanel getContainerPanel(java.awt.Component drawingDelegate, java.awt.Rectangle displayBox)
drawingDelegate
- The delegatedisplayBox
- The bounding box
protected java.lang.String getHTMLText(java.lang.String text, java.awt.Font font, java.lang.String textColor, java.lang.String backColor, java.awt.Rectangle displayBox)
text
- The textfont
- The fonttextColor
- The text color HTML codebackColor
- The background's color HTML codedisplayBox
- Description of the Parameter
protected java.lang.String substituteEntityKeywords(java.lang.String template)
>font face='&FontName;' color='&FillColor;'<
template
- The template text
protected java.lang.String getEntityHTMLRepresentation(java.lang.String attrName)
attrName
- The name of the attribute
protected java.awt.image.BufferedImage getImage()
protected void setImage(java.awt.image.BufferedImage newImage)
newImage
- The new image valueprotected javax.swing.JPopupMenu createPopupMenu()
protected void addPopupMenuItems(javax.swing.JPopupMenu popupMenu)
popupMenu
- The popup menu to add items topublic boolean usesDirectDraw()
public void setUseDirectDraw(boolean newUseDirectDraw)
newUseDirectDraw
- The new useDirectDraw valuepublic void setUseBufferedDraw(boolean newUseBufferedDraw)
newUseBufferedDraw
- The new useBufferedDraw valuepublic boolean usesBufferedDraw()
protected void markImageDirty()
protected boolean isImageDirty()
public void read(StorableInput dr) throws java.io.IOException
read
in interface Storable
read
in class TextAreaFigure
dr
- Description of the Parameter
java.io.IOException
- the inout storablepublic void write(StorableOutput dw)
write
in interface Storable
write
in class TextAreaFigure
dw
- the output storablepublic void setAttribute(FigureAttributeConstant name, java.lang.Object value)
setAttribute
in interface Figure
setAttribute
in class AttributeFigure
name
- The new attribute namevalue
- The new attribute valuepublic boolean isRawHTML()
public void setRawHTML(boolean newRawHTML)
newRawHTML
- The new rawHTML valueprotected ContentProducer getIntrinsicContentProducer()
public void setIntrinsicContentProducer(ContentProducer newIntrinsicContentProducer)
newIntrinsicContentProducer
- The new IntrinsicContentProducer valuepublic ContentProducer registerContentProducer(java.lang.Class targetClass, ContentProducer producer)
targetClass
- the target classproducer
- the producer
public void unregisterContentProducer(java.lang.Class targetClass, ContentProducer producer)
producer
- Description of the ParametertargetClass
- Description of the Parameterprotected ContentProducer getContentProducer(java.lang.Class targetClass)
targetClass
- the target class
public java.awt.Polygon getPolygon()
protected Figure getFrameFigure()
public void setFrameFigure(Figure newFrameFigure)
newFrameFigure
- The new frameFigure valueprotected java.awt.Shape getClippingShape()
public void figureInvalidated(FigureChangeEvent e)
figureInvalidated
in interface FigureChangeListener
figureInvalidated
in class TextAreaFigure
e
- Description of the Parameterpublic void figureChanged(FigureChangeEvent e)
figureChanged
in interface FigureChangeListener
figureChanged
in class TextAreaFigure
e
- Description of the Parameterpublic void figureRemoved(FigureChangeEvent e)
figureRemoved
in interface FigureChangeListener
figureRemoved
in class TextAreaFigure
e
- Description of the Parameterpublic void figureRequestRemove(FigureChangeEvent e)
figureRequestRemove
in interface FigureChangeListener
figureRequestRemove
in class TextAreaFigure
e
- Description of the Parameterpublic void figureRequestUpdate(FigureChangeEvent e)
figureRequestUpdate
in interface FigureChangeListener
figureRequestUpdate
in class TextAreaFigure
e
- Description of the Parameterpublic Figure getRepresentingFigure()
getRepresentingFigure
in interface TextHolder
getRepresentingFigure
in class TextAreaFigure
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |