edu.davidson.tools
Class SApplet

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byjava.applet.Applet
                  extended byedu.davidson.tools.SApplet
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
Angular, Animator, Bar, BField, BlackBody, CircuitApplet, DataGraph, DataTable, Density, Diatomic, Doppler, EField, EMWave, EnergyEigenvalue, Faraday, ImpAppl, IVApplet, LoadApplet, Lorentz, LRCApplet, Minkowski, MolecularApplet, MolecularMembrane, MolecularPiston, OpticsApplet, Poisson, QTime, Radial, RCApplet, ReflectionApplet, Ripple, SliderApplet, Superposition, Sync

public class SApplet
extends java.applet.Applet

SApplet is designed to provide inter-applet communication and common functionality for Physlets. Physlets usually subclass from SApplet in order to access the animation clock, to register data sources and data listeners, and to enable JavaScript for data-connections.

See Also:
Serialized Form

Field Summary
 boolean destroyed
           
 
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
 
Method Summary
static void addDataListener(java.lang.Object dl)
          Method addDataListener
static void addDataSource(java.lang.Object ds)
          Add a data source to the list.
 boolean checkAppletNames(java.lang.String names)
          Checks a list of names to determine if the applets in this list have started.
 void cleanupDataConnections()
          Removes dataConnections if either the source or the listener no longer exist.
 void clearAllData()
          Delete all the data that has been sent to the DataConnections.
 void clearData(int id)
          Delete all the data that has been sent to the DataConnections.
 void deleteDataConnection(int id)
          Break the data connection identified by the id.
 void deleteDataConnections()
          Break all data connections for this applet.
 java.lang.String formatValue(double val, double chop, java.lang.String str)
          Convert a number to a string.
 void forward()
          Start clock.
 java.lang.String getAppletName()
          Gets the name that was used to embed this applet in the html page.
 int getClockID()
          Get the clock id for use as a data source.
 double getClockTime()
          Get the time from the animation clock.
 java.lang.String getDataFromDS(int id)
          Return the data as a string.
static edu.davidson.tools.SDataListener getDataListener(java.lang.String key)
          Gets the data listener from the key.
static edu.davidson.tools.SDataSource getDataSource(int id)
          Find the data source with the given id.
static edu.davidson.tools.SDataSource getDataSource(java.lang.String key)
          Find the data source with the given key.
 int getDebugLevel()
          Get the debug level.
 int getID()
          Method object identifier.
 java.lang.String getSourceData(int id, java.lang.String vStr)
          Returns a comma delimited list of the datasource data.
 java.lang.String getSourceVariables(int id)
          Return a comma delimited list of the data source variables.
 boolean isClockRunning()
          Test to see if the clock is running.
 boolean isValidFunction(java.lang.String func, java.lang.String vars)
          Check to see if a function is syntactically correct.
 int makeDataConnection(int sourceID, int listenerID, int seriesID, java.lang.String xStr, java.lang.String yStr)
          Have the applet make a new data connection.
 void pause()
          Pause the clock.
 void removeDataListener(int id)
          Method removeDataListener
 void removeDataSource(int id)
          Remove the data source with the given id.
 void reset()
          Reset the clock to time=0.
 void reverse()
          Stop the clock.
 void sendDataToListener(int listenerID, int sid, double x, double y)
          Sends an (x,y) data point to the listener.
 void setAutoRefresh(boolean ar)
          Repaint whenevers the system parameters are changed.
 void setClockContinous()
          Set the clock to run continously.
 void setClockCycle(double minTime, double maxTime)
          Set the clock to cycle between the minTime and maxTime.
 void setClockOneShot(double minTime, double maxTime)
          Set the clock to run from minTime to maxTime and stop.
 void setClockTime(double t)
          Set the clock time.
 boolean setConnectionBlock(int id, boolean block)
          Block data from passing through the data connection.
 boolean setConnectionListener(int id)
          Set the data listener for the data connection.
 boolean setConnectionSmoothing(int id, int num)
          Have the data connection smooth the data before it is sent to the data listener.
 boolean setConnectionSource(int id)
          Set the data source for the data connection.
 boolean setConnectionStride(int id, int num)
          Have the data connection skip every num-1 data points.
 boolean setConnectionWindowX(int id, double xmin, double xmax)
          Have the data connection reject data unless xmin <= x <= xmax.
 boolean setConnectionWindowY(int id, double ymin, double ymax)
          Have the data connection reject data unless ymin <= y <= ymax.
 void setDebugLevel(int level)
          Set the debug leve.
 void setDefault()
          Reset the clock to time=0.
 void setDt(double dt)
          Set the time increment.
 boolean setExternalClock(int id)
          Sets the animatation clock to the clock in another applet.
 void setFPS(double fps)
          Set the frames per second.
 void setIndependentClock(boolean independent)
          Sets the clock so that this applet does not stop running when another applet starts running.
 void setTimeContinuous()
          Set the time increment.
 void setTimeCycle(double maxTime)
          Set the clock to cycle between the 0 and maxTime.
 void setTimeOneShot(double maxTime, java.lang.String msg)
          Set the clock to run from minTime to maxTime and stop.
 void startClock()
          Starts the clock
 void stepClock()
          Step the clock by one tick, dt.
 void stepTime()
          Step the clock by dt.
 void stepTimeBack()
          Step the clock back by dt.
 void stepTimeForward()
          Step the clock forward by dt.
 void stop()
          Invoked by the browser when the html page is exited.
 void stopClock()
          Stop the clock
 void updateDataConnection(int id)
          Have a single data source update its data connections.
 void updateDataConnections()
          Have all data sources update their data connections.
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, init, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, 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, 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, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

destroyed

public boolean destroyed
Method Detail

sendDataToListener

public void sendDataToListener(int listenerID,
                               int sid,
                               double x,
                               double y)
Sends an (x,y) data point to the listener.


makeDataConnection

public int makeDataConnection(int sourceID,
                              int listenerID,
                              int seriesID,
                              java.lang.String xStr,
                              java.lang.String yStr)
Have the applet make a new data connection.

Parameters:
sourceID - The id of the data source.
listenerID - The id of the data listener. This is usually an applet.
seriesID - The id of the series in the data listener.
xStr - The function of the data source variables to be plotted on the horizontal axis.
yStr -
Returns:
SDataConnection The hasCode id of the newly created data connection.

clearAllData

public void clearAllData()
Delete all the data that has been sent to the DataConnections.


clearData

public void clearData(int id)
Delete all the data that has been sent to the DataConnections.

Parameters:
id - int The hashCode id of the data source.

updateDataConnection

public void updateDataConnection(int id)
Have a single data source update its data connections.

Parameters:
id - The integer id of the data source.

updateDataConnections

public void updateDataConnections()
Have all data sources update their data connections.


deleteDataConnections

public void deleteDataConnections()
Break all data connections for this applet.


deleteDataConnection

public void deleteDataConnection(int id)
Break the data connection identified by the id.

Parameters:
id - The data connection id.

getDataFromDS

public java.lang.String getDataFromDS(int id)
Return the data as a string.

Parameters:
id -
Returns:

isValidFunction

public final boolean isValidFunction(java.lang.String func,
                                     java.lang.String vars)
Check to see if a function is syntactically correct.

Parameters:
func -
vars -
Returns:

getAppletName

public java.lang.String getAppletName()
Gets the name that was used to embed this applet in the html page.

Returns:
the name

checkAppletNames

public boolean checkAppletNames(java.lang.String names)
Checks a list of names to determine if the applets in this list have started.

Parameters:
names - a comma delimited list of applet names
Returns:
true if the names match

cleanupDataConnections

public final void cleanupDataConnections()
Removes dataConnections if either the source or the listener no longer exist.


getDebugLevel

public final int getDebugLevel()
Get the debug level. A debug level of 1 turns off all debugging. Higher levels produce more error messages.

Returns:
the debug level

setDebugLevel

public final void setDebugLevel(int level)
Set the debug leve. A debug level of 1 turns off all debugging. Higher levels produce more error messages.

Parameters:
level -

getID

public final int getID()
Method object identifier. The id is usually the hash code of the object.

Returns:
the id

setConnectionSmoothing

public final boolean setConnectionSmoothing(int id,
                                            int num)
Have the data connection smooth the data before it is sent to the data listener.

Parameters:
id - int The id of of the data connection.
num - int The number of data points to smooth.
Returns:
boolean Return true if data connection found.

setConnectionWindowX

public final boolean setConnectionWindowX(int id,
                                          double xmin,
                                          double xmax)
Have the data connection reject data unless xmin <= x <= xmax.

Parameters:
id - the id of of the data connection
xmin - the minimum value to pass
xmax - the maximum value to pass
Returns:
boolean true if data connection found.

setConnectionWindowY

public final boolean setConnectionWindowY(int id,
                                          double ymin,
                                          double ymax)
Have the data connection reject data unless ymin <= y <= ymax.

Parameters:
id - the id of of the data connection
ymin - the minimum value to pass
ymax - the maximum value to pass
Returns:
boolean true if data connection found.

setConnectionStride

public final boolean setConnectionStride(int id,
                                         int num)
Have the data connection skip every num-1 data points.

Parameters:
id -
num -
Returns:

setConnectionBlock

public final boolean setConnectionBlock(int id,
                                        boolean block)
Block data from passing through the data connection.

Parameters:
id -
block -
Returns:

setConnectionSource

public final boolean setConnectionSource(int id)
Set the data source for the data connection.

Parameters:
id -
Returns:

setConnectionListener

public final boolean setConnectionListener(int id)
Set the data listener for the data connection.

Parameters:
id -
Returns:

setAutoRefresh

public void setAutoRefresh(boolean ar)
Repaint whenevers the system parameters are changed.

Parameters:
ar -

formatValue

public java.lang.String formatValue(double val,
                                    double chop,
                                    java.lang.String str)
Convert a number to a string. Use Unix printf format convention.

Parameters:
val - the number to format
chop - return zero if abs(val) < chop.
str - the new format string
Returns:
the string

forward

public void forward()
Start clock.


reverse

public void reverse()
Stop the clock.


pause

public void pause()
Pause the clock.


reset

public void reset()
Reset the clock to time=0.


setDefault

public void setDefault()
Reset the clock to time=0.


setDt

public void setDt(double dt)
Set the time increment.

Parameters:
dt -

setFPS

public void setFPS(double fps)
Set the frames per second.

Parameters:
fps -

setTimeContinuous

public void setTimeContinuous()
Set the time increment.


getClockID

public final int getClockID()
Get the clock id for use as a data source.

Returns:

setIndependentClock

public void setIndependentClock(boolean independent)
Sets the clock so that this applet does not stop running when another applet starts running.

Parameters:
independent - true will make clock independent; false otherwise

setExternalClock

public final boolean setExternalClock(int id)
Sets the animatation clock to the clock in another applet.

Parameters:
id - the clock in another applet.
Returns:
true if successful, false otherwise

stepClock

public void stepClock()
Step the clock by one tick, dt.


stepTimeForward

public void stepTimeForward()
Step the clock forward by dt.


stepTimeBack

public void stepTimeBack()
Step the clock back by dt.


stepTime

public void stepTime()
Step the clock by dt.


getClockTime

public double getClockTime()
Get the time from the animation clock.

Returns:
double the time

setClockTime

public void setClockTime(double t)
Set the clock time.

Parameters:
t - The clock time.

setTimeOneShot

public void setTimeOneShot(double maxTime,
                           java.lang.String msg)
Set the clock to run from minTime to maxTime and stop.

Parameters:
maxTime - The maximum time.
msg -

setClockOneShot

public void setClockOneShot(double minTime,
                            double maxTime)
Set the clock to run from minTime to maxTime and stop.

Parameters:
minTime - The maximum time.
maxTime - The maximum time.

setClockContinous

public void setClockContinous()
Set the clock to run continously.

See Also:
SApplet.setClockOneShot(double, double), SApplet.setClockCycle(double, double)

setTimeCycle

public void setTimeCycle(double maxTime)
Set the clock to cycle between the 0 and maxTime.

Parameters:
maxTime - The maximum time.

setClockCycle

public void setClockCycle(double minTime,
                          double maxTime)
Set the clock to cycle between the minTime and maxTime.

Parameters:
minTime - The maximum time.
maxTime - The maximum time.

stop

public void stop()
Invoked by the browser when the html page is exited.


startClock

public void startClock()
Starts the clock


isClockRunning

public boolean isClockRunning()
Test to see if the clock is running.

Returns:
true if clock is running.

stopClock

public void stopClock()
Stop the clock


addDataSource

public static final void addDataSource(java.lang.Object ds)
Add a data source to the list.

Parameters:
ds - The data source object.

removeDataSource

public final void removeDataSource(int id)
Remove the data source with the given id. Look for and remove data connections to this data source.

Parameters:
id - The integer id that identifies the data source.

getDataSource

public static final edu.davidson.tools.SDataSource getDataSource(java.lang.String key)
Find the data source with the given key. The key is the String representation of the hash code.

Parameters:
key - The string id that identifies the data source.
Returns:

getDataSource

public static final edu.davidson.tools.SDataSource getDataSource(int id)
Find the data source with the given id.

Parameters:
id - The integer id that identifies the data source.
Returns:

getSourceVariables

public java.lang.String getSourceVariables(int id)
Return a comma delimited list of the data source variables.

Parameters:
id - the integer identifier of the data source.
Returns:
string a list of variables

getSourceData

public java.lang.String getSourceData(int id,
                                      java.lang.String vStr)
Returns a comma delimited list of the datasource data.

Parameters:
id - the integer identifier of the data source.
vStr -
Returns:
string a list of doubles

removeDataListener

public final void removeDataListener(int id)
Method removeDataListener

Parameters:
id - the hash code of the data listener

addDataListener

public static final void addDataListener(java.lang.Object dl)
Method addDataListener

Parameters:
dl -

getDataListener

public static final edu.davidson.tools.SDataListener getDataListener(java.lang.String key)
Gets the data listener from the key.

Parameters:
key -
Returns:
the data listener


Visit the Davidson College Physlet Site for additional information.