com.rubecula.darwin.visualization.swing
Class EvolutionaryApplet

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 javax.swing.JApplet
                      extended by com.rubecula.darwin.visualization.swing.EvolutionaryApplet
All Implemented Interfaces:
GenerationListener, Evolutionary, ControlAction, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
VisualizingEvolutionaryApplet

public abstract class EvolutionaryApplet
extends javax.swing.JApplet
implements GenerationListener, ControlAction, Evolutionary

This subclass of JApplet understands how to interact with an Evolution, by virtue of implementing GenerationListener and ControlAction.

It expects that the Evolution object has the property "ui" set to this applet in the bean configuration file (otherwise, the field evolution will not be set when it needs to be).

The init() method is marked as final (see comments) and thus all preparatory UI work must be done in the setup() method implementations.

This applet has optional censusing capability.

This applet controls a Taxon evolutionary computation system. Essentially, this applet defines a panel with border layout (N,E,S,W, center). The E/W panels are unused. The N panel contains a title and the S panel contains a control panel. The center panel delegates its functionality to an instance of the VisualizerTabs class.

Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  Title _title
           
protected static java.lang.String APPLET_PARAM_ENABLE_SLIDER
          enableSlider
protected  javax.swing.JPanel controlPanel
          This is the control panel which allows the user to adjust settings.
protected static java.lang.String DEFAULT_PROPERTIES_URL
          TODO need to fix this.
protected  Evolution evolution
           
protected static java.lang.String LBL_VERSION
          Version
protected static org.apache.commons.logging.Log LOG
          The logger for this class.
static java.lang.String P_TITLE_APPLICATION
          TitleApplication
protected static java.lang.String PROPERTIES_URL
           
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.rubecula.darwin.domain.helper.GenerationListener
$1_SECOND
 
Fields inherited from interface com.rubecula.darwin.visualization.ControlAction
NEXT, QUIT, START, STOP, TIME_DELAY
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected EvolutionaryApplet()
          Instantiate the applet, retrieving the title for the applet from the message.properties file (property Applet_Darwinian.0)
 
Method Summary
protected  javax.swing.JPanel createControlPanel(ControlAction controlAction)
           
protected  javax.swing.JLabel createEastPanel()
           
protected  javax.swing.JPanel createNorthPanel(boolean opaque)
           
protected abstract  java.util.Map<java.lang.String,java.awt.Component> createOptionsComponentMap()
          Needs to be overridden by extenders.
protected  javax.swing.JPanel createSouthPanel()
           
protected  javax.swing.JLabel createWestPanel()
           
 void destroy()
          shut down the evolution.
protected  boolean getBooleanParameter(java.lang.String parameterName, boolean defaultValue)
           
protected  javax.swing.JPanel getControlPanel()
           
protected  java.lang.String getDefaultBeansFilename()
          Subclasses should override this as appropriate.
 Evolution getEvolution()
           
 java.lang.String getParameter(java.lang.String parameterName, java.lang.String defaultValue)
           
protected  Title getTitle()
           
 void init()
           Final implementation of init().
 void onGeneration(Evolvable evolvable)
          This method is called whenever the Evolvable implementer completes a new generation or when the Evolution itself is completely exhausted (has no more evolvables to work with).
 void setAppletTitle(java.lang.String title)
           
 void setControlPanel(ControlPanel_ controlPanel)
           
 void setEvolution(Evolution evolution)
           
 void setProperty(java.lang.String name, java.lang.Object value)
          Update the system according to a user-interface property change.
 void setState(java.lang.String state)
          Method to set a state.
 boolean settable(java.lang.String propertyName)
           
protected abstract  void setup()
          Method which is called by invoked by init(), after invoking the super-method.
protected  void setupLayout()
           
 void start()
          Initialize the evolution.
 void stop()
          Cleanup the evolution
 void update(java.awt.Graphics graphics)
          This is required for double-buffering to work correctly.
protected abstract  void updateModel(java.lang.String name, java.lang.Object value)
           
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler
 
Methods inherited from class java.applet.Applet
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, 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, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, 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, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, 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, 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, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PROPERTIES_URL

protected static final java.lang.String DEFAULT_PROPERTIES_URL
TODO need to fix this. This URL is good for development: file:../config/pepperedMoth.properties But to deploy as an applet you will have to set the parameter PROPERTIES_URL as an applet (embed) parameter in the HTML.

See Also:
Constant Field Values

PROPERTIES_URL

protected static final java.lang.String PROPERTIES_URL
See Also:
Constant Field Values

evolution

protected Evolution evolution

controlPanel

protected javax.swing.JPanel controlPanel
This is the control panel which allows the user to adjust settings.


_title

protected final transient Title _title

P_TITLE_APPLICATION

public static final java.lang.String P_TITLE_APPLICATION
TitleApplication

See Also:
Constant Field Values

LOG

protected static final org.apache.commons.logging.Log LOG
The logger for this class.


APPLET_PARAM_ENABLE_SLIDER

protected static final java.lang.String APPLET_PARAM_ENABLE_SLIDER
enableSlider

See Also:
Constant Field Values

LBL_VERSION

protected static final java.lang.String LBL_VERSION
Version

See Also:
Constant Field Values
Constructor Detail

EvolutionaryApplet

protected EvolutionaryApplet()
                      throws java.awt.HeadlessException
Instantiate the applet, retrieving the title for the applet from the message.properties file (property Applet_Darwinian.0)

Throws:
java.awt.HeadlessException
Method Detail

destroy

public void destroy()
shut down the evolution. TODO we should also break down all of the user interface components.

Overrides:
destroy in class java.applet.Applet
See Also:
Applet.destroy()

getEvolution

public Evolution getEvolution()
Specified by:
getEvolution in interface Evolutionary
Returns:
the evolution
See Also:
Evolutionary.getEvolution()

getParameter

public java.lang.String getParameter(java.lang.String parameterName,
                                     java.lang.String defaultValue)
Parameters:
parameterName -
defaultValue -
Returns:
a String which is either the parameter value specified in the applet parameter list, or if that is missing, then the default value.

init

public final void init()

Final implementation of init(). This is final in order to avoid the inevitable confusion caused by overriding this method. All of the user interface work that would normally appear in the init() method is actually defined in the setup() method which is called from within this method (after the call to the super-method and the beans configuration).

Here is the sequence:

The beans used by this EvolutionaryApplet are instantiated and configured here (after the super.init() method is invoked). The reference to this Applet is typically dependency-injected into at least some of the beans. Note that the configuration includes all pre- and post-configuration processing.

The filename of the beans definition is provided by the "beans" applet parameter. If the "beans" parameter is unset, then the filename defaults to getDefaultBeansFilename(). Assuming that the filename is a relative name, beans file should reside in the resources directory, under the package of the concrete class being instantiated (not typically in the package that this class resides in).

Overrides:
init in class java.applet.Applet
See Also:
Applet.init()

onGeneration

public void onGeneration(Evolvable evolvable)
Description copied from interface: GenerationListener
This method is called whenever the Evolvable implementer completes a new generation or when the Evolution itself is completely exhausted (has no more evolvables to work with).

Specified by:
onGeneration in interface GenerationListener
Parameters:
evolvable - the implementer of Evolvable which has completed a generation or null if the Evolution itself has completed. NOTE: implementers of this method must be prepared to accept null as the parameter.
See Also:
GenerationListener.onGeneration(com.rubecula.darwin.foundation.Evolvable)

setAppletTitle

public void setAppletTitle(java.lang.String title)
Parameters:
title -
See Also:
JLabel.setText(java.lang.String)

setControlPanel

public void setControlPanel(ControlPanel_ controlPanel)
Parameters:
controlPanel - the controlPanel to set

setEvolution

public void setEvolution(Evolution evolution)
Specified by:
setEvolution in interface Evolutionary
Parameters:
evolution - the evolution to set
See Also:
Evolutionary.setEvolution(com.rubecula.darwin.evolution.Evolution)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws VisualizationException
Update the system according to a user-interface property change. If the property relates to the evolution process itself, we invoke changeEvolution(String, Object). Otherwise, we invoke updateModel(String, Object) and then Component.repaint().

Specified by:
setProperty in interface ControlAction
Throws:
VisualizationException - XXX
See Also:
ControlAction.setProperty(java.lang.String, java.lang.Object)

setState

public void setState(java.lang.String state)
              throws VisualizationException
Description copied from interface: ControlAction
Method to set a state.

Specified by:
setState in interface ControlAction
Throws:
VisualizationException - XXX
See Also:
ControlAction.setState(java.lang.String)

settable

public boolean settable(java.lang.String propertyName)
Specified by:
settable in interface ControlAction
Returns:
true if the property named is settable
See Also:
ControlAction.settable(java.lang.String)

start

public void start()
Initialize the evolution.

Overrides:
start in class java.applet.Applet
See Also:
Applet.start()

stop

public void stop()
Cleanup the evolution

Overrides:
stop in class java.applet.Applet
See Also:
Applet.stop()

update

public void update(java.awt.Graphics graphics)
This is required for double-buffering to work correctly.

Overrides:
update in class javax.swing.JApplet
See Also:
Container.update(java.awt.Graphics)

createControlPanel

protected javax.swing.JPanel createControlPanel(ControlAction controlAction)
Parameters:
controlAction - the object to implement the control actions
Returns:
a newly created ControlPanel_Default object. TODO consider using factory class.

createEastPanel

protected javax.swing.JLabel createEastPanel()
Returns:
a new empty JLabel

createNorthPanel

protected javax.swing.JPanel createNorthPanel(boolean opaque)
Parameters:
opaque - true if this panel should be opaque
Returns:
a the _title with opaque property set accordingly.

createOptionsComponentMap

protected abstract java.util.Map<java.lang.String,java.awt.Component> createOptionsComponentMap()
Needs to be overridden by extenders.

Returns:
the newly fabricated options component map

createSouthPanel

protected javax.swing.JPanel createSouthPanel()
Returns:
getControlPanel().

createWestPanel

protected javax.swing.JLabel createWestPanel()
Returns:
a new empty JLabel

getBooleanParameter

protected boolean getBooleanParameter(java.lang.String parameterName,
                                      boolean defaultValue)
Parameters:
parameterName -
defaultValue -
Returns:
the value of the applet parameter specified or the default value.
See Also:
getParameter(String, String)

getControlPanel

protected javax.swing.JPanel getControlPanel()
Returns:
the controlPanel

getDefaultBeansFilename

protected java.lang.String getDefaultBeansFilename()
Subclasses should override this as appropriate.

Returns:
FILENAME_BEANS_XML.

getTitle

protected Title getTitle()

setup

protected abstract void setup()
Method which is called by invoked by init(), after invoking the super-method.


setupLayout

protected void setupLayout()

updateModel

protected abstract void updateModel(java.lang.String name,
                                    java.lang.Object value)
                             throws VisualizationException
Throws:
VisualizationException


Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.