fi.hut.tml.xsmiles.content
Interface XSmilesContentHandler

All Superinterfaces:
Media
All Known Implementing Classes:
AWTMediaContentHandler, BaseContentHandler, HTMLContentHandler, MediaContentHandler, UnknownContentHandler, XMLContentHandler

public interface XSmilesContentHandler
extends Media

ContentHandler is an interface to a class that handles certain kind of content distinguished by the content type. E.g. application/xml would be handled by a content handler specialized in XML documents

Author:
Mikko Honkala

Method Summary
 void addMediaListener(MediaListener listener)
          Adds a MediaListener for this media.
 void close()
          This will freeze all memory and references to this media.
 XSmilesConnection get(java.net.URL dest, short type)
          Retrieve a resource via an URL using authenticated HTTP get and store it as a resource under this contenthandler
 java.io.InputStream getContentStream()
          get a stream to the content if possible This should read the contents from a cache if possible.
 int getOriginalDuration()
          Get the duration of media.
 int getOriginalHeight()
          Get the real height of the media.
 int getOriginalWidth()
          Get the real width of the media.
 boolean getPrimary()
          get the primary property for this content
 ResourceReferencer getResourceReferencer()
          get the list of referenced resources
 java.lang.String getTitle()
          get the possible title (can be null)
 XMLDocument getXMLDocument()
          for XML type of media, this returns the XML content holder object XMLDocument, otherwise null
 boolean isStatic()
          Checks if this media is static or continuous.
 void pause()
          Pauses the media.
 void play()
          Plays the media.
 void prefetch()
          Prefetches media.
 void setBounds(int x, int y, int width, int height)
          Set the coordinates for the media.
 void setBrowserWindow(BrowserWindow browser)
          sets the browser window instance.
 void setConnection(XSmilesConnection conn)
          the connection object, that should be manually closed ASAP
 void setContainer(java.awt.Container container)
          Sets the container the media will be rendered in.
 void setInputStream(java.io.InputStream stream)
          sets the input stream where the media is fetched from.
 void setMediaTime(int millisecs)
          This moves the time position in media.
 void setMLFCListener(MLFCListener listener)
          All traffic to the browser, such as ComponentFactory, etc goes through this listener.
 void setPrimary(boolean primary)
          set this content as primary or secondary.
 void setSoundVolume(int percentage)
          Set the sound volume for media.
 void setUrl(java.net.URL url)
          sets the XLink (url) for this media if only the link is set, then the input stream should be automatically opened by the media
 void setURL(XLink url)
          sets the XLink (url) for this media if only the link is set, then the input stream should be automatically opened by the media
 void setZoom(double zoom)
          notify that the zoom level has changed.
 void showControls(boolean visible)
          Requests the media player to display a control panel for media.
 void stop()
          Stops the media.
 

Method Detail

setBrowserWindow

public void setBrowserWindow(BrowserWindow browser)
sets the browser window instance. This is needed mainly by the XMLContentHandler


setMLFCListener

public void setMLFCListener(MLFCListener listener)
All traffic to the browser, such as ComponentFactory, etc goes through this listener. If no listener supplied, the content should still function with some basic level.

Specified by:
setMLFCListener in interface Media
Parameters:
listener - The MLFCListener supplied by the browser
See Also:
MLFCListener

setConnection

public void setConnection(XSmilesConnection conn)
the connection object, that should be manually closed ASAP

Parameters:
conn -

addMediaListener

public void addMediaListener(MediaListener listener)
Adds a MediaListener for this media. The listener will be called
  1. When the media has been prefetched. (NOT IMPLEMENTED YET).
  2. When the media ends. (continuous media, video/audio)
Static media, such as text and images will end immediately, notifying immediately about the end of media.

Specified by:
addMediaListener in interface Media

setPrimary

public void setPrimary(boolean primary)
set this content as primary or secondary. Primary handler is usually the main content in a browser window, while secondary content is usually contained within the primary content

Parameters:
primary - boolean value denoting whether this content is primary or not

getPrimary

public boolean getPrimary()
get the primary property for this content


setInputStream

public void setInputStream(java.io.InputStream stream)
sets the input stream where the media is fetched from. If the inputstream is set, then the media should not re-open the URL


setURL

public void setURL(XLink url)
sets the XLink (url) for this media if only the link is set, then the input stream should be automatically opened by the media


setUrl

public void setUrl(java.net.URL url)
sets the XLink (url) for this media if only the link is set, then the input stream should be automatically opened by the media

Specified by:
setUrl in interface Media
Parameters:
url - URL for media

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Set the coordinates for the media. These are relative to the given container, set using setContainer(). Setting the bounds will always immediately move the media to a new location, if it is visible.

Specified by:
setBounds in interface Media

setSoundVolume

public void setSoundVolume(int percentage)
Set the sound volume for media. Only applicable for sound media formats.

Specified by:
setSoundVolume in interface Media
Parameters:
percentage - Sound volume, 0-100- (0 is quiet, 100 is original loudness, 200 twice as loud; dB change in signal level = 20 log10(percentage / 100) )

prefetch

public void prefetch()
              throws java.lang.Exception
Prefetches media. The URL must have been set using setUrl(). The data will be downloaded from the URL. After calling this method, the media will be in memory and can be played. This is a blocking method.

Specified by:
prefetch in interface Media
Throws:
java.lang.Exception

play

public void play()
          throws java.lang.Exception
Plays the media. The media will be added to the container set using setContainer(). It will be visible. It will also play any animation it possibly has. Also, audio media is started using this method.

If the media is not yet prefetched, it will first be prefetched.

Specified by:
play in interface Media
Throws:
java.lang.Exception

pause

public void pause()
Pauses the media. The media will stay visible, but any animations will be paused. Audio media will be silent. NOT IMPLEMENTED YET. ?How to restart paused media?

Specified by:
pause in interface Media

stop

public void stop()
Stops the media. The media will be stopped and it will be invisible. Audio will be silent. It is possible to call start() after stop()

Specified by:
stop in interface Media

close

public void close()
This will freeze all memory and references to this media. If the media is not yet stopped, it will first be stopped. It is not possible to call start() after close() has been called.

Specified by:
close in interface Media

setMediaTime

public void setMediaTime(int millisecs)
This moves the time position in media. Works only for continuous media (video/audio).

Specified by:
setMediaTime in interface Media
Parameters:
millisecs - Time in millisecs

getContentStream

public java.io.InputStream getContentStream()
get a stream to the content if possible This should read the contents from a cache if possible. This is used for instance to save the content to a file Note that this could re-open the URL connection


showControls

public void showControls(boolean visible)
Requests the media player to display a control panel for media. For audio and video, these can be a volume/play/stop controls, for images, these can be zoom controls etc. The controls are GUI dependent, generated through ComponentFactory.

Specified by:
showControls in interface Media
Parameters:
visible - true=Display controls, false=don't display controls.

getXMLDocument

public XMLDocument getXMLDocument()
for XML type of media, this returns the XML content holder object XMLDocument, otherwise null


isStatic

public boolean isStatic()
Checks if this media is static or continuous.

Specified by:
isStatic in interface Media
Returns:
true if media is static (duration is zero, see getOriginalDuration().

getOriginalDuration

public int getOriginalDuration()
Get the duration of media. Only applicable for continuous media (audio, video).

Specified by:
getOriginalDuration in interface Media
Returns:
The duration of media in millisecs. zero for static media (images, text) -1 means indefinite (infinite streamed media or unknown duration).

getOriginalWidth

public int getOriginalWidth()
Get the real width of the media. If not visible, or size is unknown, then returns -1.

Specified by:
getOriginalWidth in interface Media
Returns:
Original width of the media. -1 means no particular width (audio) or unknown width (text, XML media...)

getOriginalHeight

public int getOriginalHeight()
Get the real height of the media. If not visible, or size is unknown, then returns -1.

Specified by:
getOriginalHeight in interface Media
Returns:
Original height of the media. -1 means no particular height (audio) or unknown height (text, XML media...)

setContainer

public void setContainer(java.awt.Container container)
Sets the container the media will be rendered in. If media is audio, this can be null. Can be called if media is already visible in one container, it will then move to the new container.

Specified by:
setContainer in interface Media
Parameters:
container - This container will contain the media.

setZoom

public void setZoom(double zoom)
notify that the zoom level has changed. Note that some content may choose to not implement zooming.


get

public XSmilesConnection get(java.net.URL dest,
                             short type)
                      throws java.lang.Exception
Retrieve a resource via an URL using authenticated HTTP get and store it as a resource under this contenthandler

Throws:
java.lang.Exception

getResourceReferencer

public ResourceReferencer getResourceReferencer()
get the list of referenced resources


getTitle

public java.lang.String getTitle()
get the possible title (can be null)



X-Smiles 1.2