|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JLayeredPane uic.widgets.html.HTMLPane
public class HTMLPane
A component class which has the capacity to display HTML-formatted content.
The default rendering style of the Pane and other aspects of its operation
are controlled by a Config
object. The Pane
communicates internal events (e.g. a selected hyperlink) to a
HTMLObserver
object so that futher processing of such events
can be handled by the programmer.
Documents are displayed in the JLayeredPane.DEFAULT_LAYER
.
The Pane's messageViewer (if used) is displayed in the JLayeredPane.MODAL_LAYER
.
The Pane's test navigation bar (if used) is displayed in the JLayeredPane.PALETTE_LAYER
.
See the README.TXT file accompanying this document for further details on how to use this class.
HTMLConfig
,
HTMLObserver
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JLayeredPane |
---|
JLayeredPane.AccessibleJLayeredPane |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static String |
PROPERTY_URL
Each time a link is followed or a form is submitted this property is fired with the old and new URL objects |
static short |
SCROLLBARS_AUTO
|
static short |
SCROLLBARS_NO
|
static short |
SCROLLBARS_VIEWER
|
static short |
SCROLLBARS_YES
|
Fields inherited from class javax.swing.JLayeredPane |
---|
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
HTMLPane()
Constructs a HTMLPane with default Config ,
a default HTMLObserver and default top-level frame name. |
|
HTMLPane(HTMLConfig prefs,
HTMLObserver obs,
String name)
Constucts a HTMLPane with the specified HTMLObserver ,
Config and top-level frame name. |
Method Summary | |
---|---|
void |
closeMessageViewer()
Closes the Pane's messageViewereViewer if it is currently visible. |
URL |
getCurrentPage()
Return the URL of the currently viewing remote page. |
URL |
getCurrentPage(String frameName)
Return the URL of the currently viewing remote page in the target (child) frame. |
HTMLDocument |
getDocument()
|
Hashtable |
getIDComponents(String targetFrame)
Returns a Hashtable containing all components in the target frame which have the HTML 'id' attribute. |
void |
goBack()
Show the previous document in the Pane's history list. |
void |
goForward()
Show the next document in the Pane's history list. |
boolean |
isFocusTraversable()
Overrides JComponent isFocusTraversable() . |
boolean |
isLoadSynchronouslyEnabled()
Returns whether documents will be loaded by the HTMLPane synchronously or asynchronously. |
boolean |
isManagingFocus()
Overrides JComponent isManagingFocus() . |
void |
keyPressed(KeyEvent e)
Public due to implementation requirements. |
void |
keyReleased(KeyEvent e)
Public due to implementation requirements. |
void |
keyTyped(KeyEvent e)
Public due to implementation requirements. |
void |
reloadDocument()
Reloads the current document. |
void |
scrollToReference(String ref,
String targetFrame)
Scrolls the document view to the specified anchor reference in the named target frame. |
void |
setBounds(int x,
int y,
int w,
int h)
Public due to inheritance. |
void |
setLoadSynchronously(boolean b)
Enables/disables the synchronous loading of documents. |
boolean |
setScrollBarPolicy(int policy)
Sets the scrollbar policy of the Pane. |
void |
setText(String s)
|
void |
showHTMLDocument(String s)
Formats and displays the specified String as an HTML document in the top level frame of the Pane. |
void |
showHTMLDocument(String s,
String targetFrame)
Formats and displays the specified String as an HTML document in the named target frame. |
void |
showHTMLDocument(URL url)
Shows the contents of the specified URL in the top level frame of
the Pane. |
void |
showHTMLDocument(URL url,
String targetFrame,
boolean reload)
Shows the contents of the specified URL in the named
target frame. |
void |
showMessageViewer(String message)
Parses the sent message as HTML and displays the result in the Pane's messageViewer. |
void |
showMessageViewer(String message,
String messageName,
int x,
int y,
int w,
int h)
Parses the sent message as HTML and displays the result in the Pane's messageViewer. |
void |
stopAll()
Stops all processes within the Pane. |
Methods inherited from class javax.swing.JLayeredPane |
---|
addImpl, getAccessibleContext, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, paramString, putLayer, remove, removeAll, setLayer, setLayer, setPosition |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String PROPERTY_URL
public static final short SCROLLBARS_YES
setScrollBarPolicy(int)
,
Constant Field Valuespublic static final short SCROLLBARS_VIEWER
setScrollBarPolicy(int)
,
Constant Field Valuespublic static final short SCROLLBARS_NO
setScrollBarPolicy(int)
,
Constant Field Valuespublic static final short SCROLLBARS_AUTO
setScrollBarPolicy(int)
,
Constant Field ValuesConstructor Detail |
---|
public HTMLPane()
HTMLPane
with default Config
,
a default HTMLObserver
and default top-level frame name.
public HTMLPane(HTMLConfig prefs, HTMLObserver obs, String name)
HTMLPane
with the specified HTMLObserver
,
Config
and top-level frame name. If any of the arguments are
null
then a default will be used.
prefs
- the Config
which determines the Pane's behaviour.obs
- the HTMLObserver
that will receive updates from the Pane.name
- the name of the Pane's top-level frame.Method Detail |
---|
public void setBounds(int x, int y, int w, int h)
super.setBounds(x, y, w, h)
.
setBounds
in class Component
public void showHTMLDocument(URL url)
URL
in the top level frame of
the Pane. A cached document will be used if one is available and caching is enabled.
url
- the URL of the document to be displayed.public void showHTMLDocument(URL url, String targetFrame, boolean reload)
URL
in the named
target frame. If the target frame is null the document will be displayed in the top level
frame of the Pane. If the target frame is not a currently recognised frame:
handleNewFrames
is enabled in the
Config
controlling the Pane then a new HTMLPane
will be created to show the document.
handleNewFrames
is not enabled
then a showNewFrameRequest
will be sent to the Pane's resident
HTMLObserver
.
If reload
is false
a cached document will be used if one is
available and caching is enabled. Otherwise the document will be reloaded from the
specified URL.
url
- the URL of the document to be displayed.targetFrame
- the HTML frame that the document should be displayed in.reload
- if true
forces the document to be reloaded even if a cached
version is available.public void showHTMLDocument(String s)
s
- a String to be formatted as an HTML document.public void setText(String s)
public URL getCurrentPage()
public URL getCurrentPage(String frameName)
frameName
- the name of the frame
public void showHTMLDocument(String s, String targetFrame)
handleNewFrames
is enabled in the
Config
controlling the Pane then a new HTMLPane
will be created to show the document.
handleNewFrames
is not enabled
then a showNewFrameRequest
will be sent to the Pane's resident
HTMLObserver
.
s
- a String to be formatted as an HTML document.targetFrame
- the HTML frame that the document should be displayed in.public HTMLDocument getDocument()
public void scrollToReference(String ref, String targetFrame)
targetFrame
argument is null
then the reference will be
looked for in the document in the HTMLPane's top level frame.
This method has been incorporated to assist programmers who are displaying HTML Strings
and who wish to navigate to internal links in their String HTML documents. For example, if
there is an anchor in your String such as: <A name="contactinfo"> then you can call
this method with scrollToReference("contactinfo", null)
.
Note that you will need to ensure that the String document has been parsed/loaded before
attempting to navigate to anchors within it. Calling showHTMLDocument(String s)
and then immediately calling this method may fail because the String is still being asynchronously
parsed and the reference has not been encountered. You can use the HTMLObserver
class to determine when the String has been fully parsed, or you could set the HTMLPane's
loading policy to synchronous loading.
Programmers using URL documents need not use this method. They can create a new URL which
incorporates the anchor reference and call showHTMLDocument(URL)
instead, which has
the advantage that no check need be made to see if the document has loaded - the HTMLPane will
automatically navigate to the anchor as soon as it is available.
ref
- a named anchor reference within a document.targetFrame
- the HTML frame that contains the document with the anchor reference.public void goBack()
public void goForward()
public void reloadDocument()
public void stopAll()
Some document authors do not specify widths and heights for images in their documents. This presents a problem when parsing/loading. A temporary default image size could be used so that the document could be displayed 'on the fly', but this means reformatting the whole document once the true image size becomes available. This can considerably lengthen parsing time and is disconcerting for the document reader. The alternative is to delay the display of the document until all image sizes are known.The latter policy is followed by the HTMLPane. On occasions however the image data fails to arrive, and the parsing thread then becomes 'locked' as it waits for this data, even though the rest of the document has been parsed and is ready to be formatted. When this method is called (usually by the user pressing a 'STOP' button) a thread which is looping in this way will be freed and document parsing will continue, with default sizes being used for images with incomplete data.
public boolean setScrollBarPolicy(int policy)
SCROLLBARS_VIEWER
(The default setting)ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
SCROLLBARS_YES
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
SCROLLBARS_NO
ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
SCROLLBARS_AUTO
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
Note that unless scrolling policy is set to SCROLLBARS_NO
, documents will
always be formatted
on the assumption that a vertical scrollbar is present, even if one is not currently visible.
This is due to the asynchronous loading of documents. When a Pane loads a document it cannot 'know'
whether or not a vertical scrollbar is going to be required, and adjusting for the sudden appearance
of one would necessitate a reformat of the whole document.
policy
- a value which dictates the scrollbar policy for the Pane.
true
if a supported scrollbar policy was sent to this methodpublic boolean isManagingFocus()
JComponent isManagingFocus()
. Programmers are advised not to
override this method.
isManagingFocus
in class JComponent
public boolean isFocusTraversable()
JComponent isFocusTraversable()
. Programmers are advised not to
override this method.
isFocusTraversable
in class Component
public void keyPressed(KeyEvent e)
keyPressed
in interface KeyListener
public void keyReleased(KeyEvent e)
keyReleased
in interface KeyListener
public void keyTyped(KeyEvent e)
keyTyped
in interface KeyListener
public void showMessageViewer(String message)
message
- a String to be formatted as HTML in the Pane's messageViewer.public void showMessageViewer(String message, String messageName, int x, int y, int w, int h)
null
if the messageName is not null
;
If x >= 0 the Pane will use this value as a guide to the left-horizontal coordinate
for setting the messageViewer's bounds.
If y >= 0 the Pane will use this value as a guide to the top-vertical coordinate
for setting the messageViewer's bounds.
If w > 0 the Pane will use this value as a guide to the width of the messageViewer.
If h > 0 the Pane will use this value as a guide to the height of the messageViewer.
The Pane will honour any sent bounds values where it can, but it will always try and ensure that the messageViewereViewer is fully visible and that the messageViewereViewer's contents fit properly within its bounds.
See the README.TXT file accompanying this documentation for more details on programming the Pane's messageViewer.
message
- a String to be formatted as HTML in the Pane's messageViewer.messageName
- a name given to the message for caching purposes.x
- the left-horizontal coordinate of the messageViewer's bounds.y
- the top-vertical coordinate of the messageViewer's bounds.w
- the width of the messageViewer.h
- the height of the messageViewer.public void closeMessageViewer()
public Hashtable getIDComponents(String targetFrame)
An example component would be one created with the following HTML:
<INPUT type=text name=username id=username>
The keys in the Hashtable are the id values of the components. This method allows programmers to get handles to HTML components after they have been created, either to monitor/manipulate their state or, for example, to programmatically fire a form submission.
Note that programmers should ensure that a document has finished loading before trying to access any components within it, otherwise this method may return before the components have been created.
targetFrame
- the name of the frame containing the components, or all frames if null
Hashtable
of components, with their HTML 'id' values as keyspublic void setLoadSynchronously(boolean b)
loadSynchronously
is enabled then showHTMLDocument()
methods
will not return until a document has loaded. In addition documents
loading from activated hyperlinks will also load synchronously.
Loading synchronously effectively blocks the current AWT thread
which will reduce the responsiveness of the HTMLPane
(and will freeze the rest of
your application), but it can be useful
for programmers who want to be sure that a document has loaded before proceeding with another
operation. Generally it is better to use the callback methods in HTMLObserver
to determine when a document has finished loading.
The default policy is to load documents asynchronously.
public boolean isLoadSynchronouslyEnabled()
HTMLPane
synchronously or asynchronously.
true
if documents will load synchronously.setLoadSynchronously(boolean)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |