com.objectplanet.chart
Class ChartApplet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by com.objectplanet.chart.ChartApplet
All Implemented Interfaces:
java.awt.event.ItemListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class ChartApplet
extends java.applet.Applet
implements java.awt.event.ItemListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

This is the superclass for all the chart applets, and reads the default parameters.

Author:
Bjorn J. Kvande.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 BarChart barChart
          Reference to the BarChart component of the applet.
 Chart chart
          The chart component of the applet.
 ChartDataLoader dataLoader
          The ChartDataLoader is used to load data read by the ChartApplet to the Chart.
 java.awt.Component gaugeChart
          Reference to the GaugeChart component of the applet.
protected  java.lang.String labelDelimiter
          Used as the label delimiter for label string "arrays".
 LineChart lineChart
          Reference to the LineChart component of the applet.
 PieChart pieChart
          Reference to the PieChart component of the applet.
 GenericChart plotterChart
          Reference to the PlotterChart component of the applet.
protected  int sampleCountRead
          This is set after loadParameters() has been called in this class.
protected  int seriesCountRead
          This is set after loadParameters() has been called in this class.
 Chart theChart
          The chart component of the applet.Use this reference to access the charts methods directly via JavaScript or subclasses.
protected  java.util.Hashtable timePlots
          The list of time plots in the TimeLineChart.
 
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
ChartApplet()
          Creates the chart applet.
ChartApplet(java.lang.String type)
          Creates the chart applet.
 
Method Summary
 void callJavaScript(java.lang.String javascript)
          Calls a javascript function in the applet page.
 java.lang.String createArrayString(int[] array)
          Creates a separated string from the array.
protected  Chart createChart(java.lang.String type, java.lang.String className)
          This is called by init() and creates the chart of the specified type used for the applet.
static java.awt.Color createColor(java.lang.String color)
          Creates a color based on the string.
 java.awt.Font createFont(java.lang.String value, java.lang.String name, int type, int size)
          Creates a font based on the information in the specified string.
 void destroy()
          Releases all the resources claimed by the applet.
 void doLayout()
          Sets the proper size of the chart.
 java.applet.AppletContext getAppletContext()
          Gets the applet context.
protected  java.awt.Color[] getColorValues(java.lang.String string)
          Converts a comma seperated string to a color array.
 java.net.URL getDocumentBase()
          Gets the document base.
protected static java.lang.Double[] getDoubleValues(java.lang.String string)
          Convers a string parameter to an array of double values.
 java.lang.String getParameter(java.lang.String parameter)
          Gets the value of the specified applet parameter.
 java.lang.String getParameterPrefix()
          Gets the prefix used when reading applet parameters.
protected static java.lang.String[] getStringValues(java.lang.String string, java.lang.String delimiter)
          Converts a comma seperated string to an array of strings.
 void init()
          Initializes the default applet parameters.
 void itemStateChanged(java.awt.event.ItemEvent e)
          Called when a sample is selected.
 void loadOverlayParameters()
          Loads the overlay parameters.
 void loadParameters(java.util.Hashtable parameters)
          Loads the parameters into the specified hashtable.
 void loadURLParameters(java.lang.String url, java.util.Hashtable parameters)
          Loads the parameters from the specified url.
 void mouseClicked(java.awt.event.MouseEvent event)
          Checks if we clicked the URL label.
 void mouseDragged(java.awt.event.MouseEvent event)
          Required by the MouseMotionListener, does nothing.
 void mouseEntered(java.awt.event.MouseEvent event)
          Required by the MouseListener, does nothing.
 void mouseExited(java.awt.event.MouseEvent event)
          Required by the MouseListener, does nothing.
 void mouseMoved(java.awt.event.MouseEvent event)
          Checks of the mouse is over a sample with a URL.
 void mousePressed(java.awt.event.MouseEvent event)
          Required by the MouseListener, does nothing.
 void mouseReleased(java.awt.event.MouseEvent event)
          Required by the MouseListener, does nothing.
 void print(java.awt.Graphics g)
          Called when a print request is issued.
 void reset()
          Resets the chart data and features.
 void setParameter(java.lang.String name, java.lang.String value)
          Sets a parameter in the chart.
 void setParameterPrefix(java.lang.String prefix)
          Sets the parameter prefix for this chart.
 void setParameters(java.util.Hashtable parameters)
          Sets the applet parameters.
 void setParentApplet(java.applet.Applet parent)
          Sets the parent applet.
 void start()
          Starts the automatic refresh thread.
 void stop()
          Stops the automatic refresh thread.
 java.lang.String toString()
          Returns the title of the chart.
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getImage, getImage, getLocale, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

barChart

public BarChart barChart
Reference to the BarChart component of the applet. Use it to access the BarChart methods directly via JavaScript or subclasses.


chart

public Chart chart
The chart component of the applet. Use this reference to access the charts methods directly via JavaScript or subclasses.


dataLoader

public ChartDataLoader dataLoader
The ChartDataLoader is used to load data read by the ChartApplet to the Chart.


gaugeChart

public java.awt.Component gaugeChart
Reference to the GaugeChart component of the applet. Use it to access the GaugeChart methods directly via JavaScript or subclasses.


labelDelimiter

protected java.lang.String labelDelimiter
Used as the label delimiter for label string "arrays".


lineChart

public LineChart lineChart
Reference to the LineChart component of the applet. Use it to access the LineChart methods directly via JavaScript or subclasses.


pieChart

public PieChart pieChart
Reference to the PieChart component of the applet. Use it to access the PieChart methods directly via JavaScript or subclasses.


plotterChart

public GenericChart plotterChart
Reference to the PlotterChart component of the applet. Use it to access the PlotterChart methods directly via JavaScript or subclasses.


sampleCountRead

protected int sampleCountRead
This is set after loadParameters() has been called in this class.


seriesCountRead

protected int seriesCountRead
This is set after loadParameters() has been called in this class.


theChart

public Chart theChart
The chart component of the applet.Use this reference to access the charts methods directly via JavaScript or subclasses.


timePlots

protected java.util.Hashtable timePlots
The list of time plots in the TimeLineChart. Allows use of r URL_serie_timestamp parameters.

Constructor Detail

ChartApplet

public ChartApplet()
Creates the chart applet.


ChartApplet

public ChartApplet(java.lang.String type)
Creates the chart applet.

Method Detail

callJavaScript

public void callJavaScript(java.lang.String javascript)
Calls a javascript function in the applet page.

Parameters:
javascript - The javascript URL.

createArrayString

public java.lang.String createArrayString(int[] array)
Creates a separated string from the array. This method is useful when you want to create arrays using javascript, since javasript can not use java arrays directly.

In javascript you can use it like this:

visible = document.Chart1.getVisibleSamples();
visible = document.Table1.createArrayString(visible);
array = selected.split(',');
for (i = 0; i < array.length; i++) {
   index = array[i];
   //....
}

Parameters:
array - The array to convert.
Returns:
A comma separated string of numbers.

createChart

protected Chart createChart(java.lang.String type,
                            java.lang.String className)
This is called by init() and creates the chart of the specified type used for the applet. It can be overridden by a subclass to use a specialized classes for the chart applet.

Parameters:
type - The type of the chart.
className - The class name of the chart.
Returns:
The chart of the specified type.

createColor

public static java.awt.Color createColor(java.lang.String color)
Creates a color based on the string. The string can either be the name of a java defined color, a comma seperated RGB string (255,255,255), or a 6-digit hex-string (#af10cd).

Returns:
The color object, or null if string is invalid.

createFont

public java.awt.Font createFont(java.lang.String value,
                                java.lang.String name,
                                int type,
                                int size)
Creates a font based on the information in the specified string.

Parameters:
value - The font string value.
name - The name of the default font.
type - The default type (Font.PLAIN, Font.BOLD, Font.ITALIC).
size - The default size.

destroy

public void destroy()
Releases all the resources claimed by the applet.

Overrides:
destroy in class java.applet.Applet

doLayout

public void doLayout()
Sets the proper size of the chart.

Overrides:
doLayout in class java.awt.Container

getAppletContext

public java.applet.AppletContext getAppletContext()
Gets the applet context. If the the table is used in another component and the parent applet has been set, the parent applets context is gotten.

Overrides:
getAppletContext in class java.applet.Applet

getColorValues

protected java.awt.Color[] getColorValues(java.lang.String string)
Converts a comma seperated string to a color array.

Parameters:
string - The comma seperated string.
Returns:
A color array with the values, or null if not found.

getDocumentBase

public java.net.URL getDocumentBase()
Gets the document base.

Overrides:
getDocumentBase in class java.applet.Applet

getDoubleValues

protected static java.lang.Double[] getDoubleValues(java.lang.String string)
Convers a string parameter to an array of double values.

Parameters:
string - The array of string numbers.
Returns:
An array with the values, or null if not found.

getParameter

public java.lang.String getParameter(java.lang.String parameter)
Gets the value of the specified applet parameter. If a prefix is specified, this is added in front of the specified parameter name.

Overrides:
getParameter in class java.applet.Applet
Parameters:
parameter - The name of the parameter.
Returns:
The value of the parameter, or null if parameter is not specified.

getParameterPrefix

public java.lang.String getParameterPrefix()
Gets the prefix used when reading applet parameters.

Returns:
The prefix used, or null if no prefix is used.

getStringValues

protected static java.lang.String[] getStringValues(java.lang.String string,
                                                    java.lang.String delimiter)
Converts a comma seperated string to an array of strings.

Parameters:
string - The string parameter to return the values from.
delimiter - The field delimiter.
Returns:
A string array.

init

public void init()
Initializes the default applet parameters.

Overrides:
init in class java.applet.Applet

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
Called when a sample is selected.

Specified by:
itemStateChanged in interface java.awt.event.ItemListener

loadOverlayParameters

public void loadOverlayParameters()
Loads the overlay parameters.


loadParameters

public void loadParameters(java.util.Hashtable parameters)
Loads the parameters into the specified hashtable. Subclasses should override this method, call super.loadParameters() and add it's own parameters before they are set using the setParameters() method.

Parameters:
parameters - The hashtable where the parameters should be loaded.

loadURLParameters

public void loadURLParameters(java.lang.String url,
                              java.util.Hashtable parameters)
Loads the parameters from the specified url.

Parameters:
url - The url to load the data from.
parameters - Read the parameters into this hashtable.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Checks if we clicked the URL label. If so it opens an URL.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
event - The mouse event.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Required by the MouseMotionListener, does nothing.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
Required by the MouseListener, does nothing.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Required by the MouseListener, does nothing.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
Checks of the mouse is over a sample with a URL. If so it changes the cursor to a hand.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
event - The mouse event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Required by the MouseListener, does nothing.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Required by the MouseListener, does nothing.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

print

public void print(java.awt.Graphics g)
Called when a print request is issued.

Overrides:
print in class java.awt.Container

reset

public void reset()
Resets the chart data and features.


setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
Sets a parameter in the chart. The parameters set here are the default ones for all the chart types.

Parameters:
name - The name of the parameter.
value - The value of the parameter as a string.

setParameterPrefix

public void setParameterPrefix(java.lang.String prefix)
Sets the parameter prefix for this chart.

Parameters:
prefix - The prefix to use when reading applet parameters.

setParameters

public void setParameters(java.util.Hashtable parameters)
Sets the applet parameters. All the parameter keys are assumes to be lower case letter.

Parameters:
parameters - The parameters to be set.

setParentApplet

public void setParentApplet(java.applet.Applet parent)
Sets the parent applet. This is necessary if this applet is contained within another applet, and we need to call the init() method of this applet and/or read applet parameters.

Parameters:
parent - The parent applet, use null for ourselves.

start

public void start()
Starts the automatic refresh thread.

Overrides:
start in class java.applet.Applet

stop

public void stop()
Stops the automatic refresh thread.

Overrides:
stop in class java.applet.Applet

toString

public java.lang.String toString()
Returns the title of the chart.

Overrides:
toString in class java.awt.Component