fi.hut.tml.xsmiles.content
Class BaseContentHandler

java.lang.Object
  extended byfi.hut.tml.xsmiles.content.BaseContentHandler
All Implemented Interfaces:
Media, ResourceReferencer, XSmilesContentHandler
Direct Known Subclasses:
AWTMediaContentHandler, UnknownContentHandler, XMLContentHandler

public abstract class BaseContentHandler
extends java.lang.Object
implements XSmilesContentHandler, ResourceReferencer

Base class for content handlers This class should be reusable for optimization purposes

Author:
Mikko Honkala

Field Summary
protected  XSmilesConnection connection
          the HTTP connection object (can be null)
protected  BrowserWindow fBrowser
           
protected  boolean fClosed
          has close() been called on this object
protected  java.awt.Container fContainer
           
protected  XMLDocument fDoc
           
protected  java.io.InputStream fInputStream
          the possible input stream for this content object
protected  XLink fLink
          the XLink for this content object
protected  MLFCListener fMLFCListener
           
protected  boolean fPrefetched
          has prefetch() been called on this object
protected  boolean fPrimary
           
protected  boolean fShowControls
          whether or not this content should show controls
protected  boolean fStopped
          has stop() been called on this object
protected  java.util.Hashtable referencedResources
           
 
Constructor Summary
BaseContentHandler()
           
 
Method Summary
 void addMediaListener(MediaListener listener)
          Adds a MediaListener for this media.
 void addResource(Resource r)
           
 void close()
          This will freeze all memory and references to this media.
protected  void closeConnection()
           
 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.awt.Container getContainer()
           
 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
 int getResourceCount()
           
 ResourceReferencer getResourceReferencer()
          get the list of referenced resources
 java.util.Enumeration getResources()
           
 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 cont)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fi.hut.tml.xsmiles.content.XSmilesContentHandler
getTitle
 

Field Detail

fBrowser

protected BrowserWindow fBrowser

fMLFCListener

protected MLFCListener fMLFCListener

fDoc

protected XMLDocument fDoc

fContainer

protected java.awt.Container fContainer

fPrimary

protected boolean fPrimary

fPrefetched

protected boolean fPrefetched
has prefetch() been called on this object


fStopped

protected boolean fStopped
has stop() been called on this object


fClosed

protected boolean fClosed
has close() been called on this object


fLink

protected XLink fLink
the XLink for this content object


fInputStream

protected java.io.InputStream fInputStream
the possible input stream for this content object


fShowControls

protected boolean fShowControls
whether or not this content should show controls


connection

protected XSmilesConnection connection
the HTTP connection object (can be null)


referencedResources

protected java.util.Hashtable referencedResources
Constructor Detail

BaseContentHandler

public BaseContentHandler()
Method Detail

setConnection

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

Specified by:
setConnection in interface XSmilesContentHandler
Parameters:
conn -

closeConnection

protected void closeConnection()

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

Specified by:
getContentStream in interface XSmilesContentHandler

setBrowserWindow

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

Specified by:
setBrowserWindow in interface XSmilesContentHandler

getXMLDocument

public XMLDocument getXMLDocument()
Description copied from interface: XSmilesContentHandler
for XML type of media, this returns the XML content holder object XMLDocument, otherwise null

Specified by:
getXMLDocument in interface XSmilesContentHandler

setContainer

public void setContainer(java.awt.Container cont)
Description copied from interface: XSmilesContentHandler
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 XSmilesContentHandler
Parameters:
cont - This container will contain the media.

getContainer

public java.awt.Container getContainer()

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

Specified by:
setPrimary in interface XSmilesContentHandler
Parameters:
primary - boolean value denoting whether this content is primary or not

getPrimary

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

Specified by:
getPrimary in interface XSmilesContentHandler

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 XSmilesContentHandler
Parameters:
listener - The MLFCListener supplied by the browser
See Also:
MLFCListener

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

Specified by:
setInputStream in interface XSmilesContentHandler

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

Specified by:
setURL in interface XSmilesContentHandler

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 XSmilesContentHandler

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 XSmilesContentHandler
Parameters:
visible - true=Display controls, false=don't display controls.

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 XSmilesContentHandler
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 XSmilesContentHandler
Throws:
java.lang.Exception

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 XSmilesContentHandler

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 XSmilesContentHandler

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 XSmilesContentHandler
Parameters:
millisecs - Time in millisecs

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 XSmilesContentHandler

isStatic

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

Specified by:
isStatic in interface XSmilesContentHandler
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 XSmilesContentHandler
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 XSmilesContentHandler
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 XSmilesContentHandler
Returns:
Original height of the media. -1 means no particular height (audio) or unknown height (text, XML 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 XSmilesContentHandler

setSoundVolume

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

Specified by:
setSoundVolume in interface XSmilesContentHandler
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) )

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 XSmilesContentHandler

setZoom

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

Specified by:
setZoom in interface XSmilesContentHandler

addResource

public void addResource(Resource r)
Specified by:
addResource in interface ResourceReferencer

getResourceCount

public int getResourceCount()

getResources

public java.util.Enumeration getResources()
Specified by:
getResources in interface ResourceReferencer

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

Specified by:
get in interface XSmilesContentHandler
Throws:
java.lang.Exception

getResourceReferencer

public ResourceReferencer getResourceReferencer()
get the list of referenced resources

Specified by:
getResourceReferencer in interface XSmilesContentHandler


X-Smiles 1.2