CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.rubik.player
Class AbstractPlayerApplet

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 ch.randelshofer.rubik.player.AbstractPlayerApplet
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
AbstractCubeGeom3DPlayerApplet, AbstractCubeIdx3DPlayerApplet

public abstract class AbstractPlayerApplet
extends javax.swing.JApplet
implements java.lang.Runnable

This is the base class for Applets featuring a Rubik's Cube like puzzle which can play back scripts.

Version:
6.3 2011-06-29 Adds setScriptType/getScriptType methods to JavaScript API.
6.2 2010-08-03 "stickersFront", "stickersLeft", ... parameters could only access the first six colors in the color list. Adds applet parameter "locale".
6.1.2 2010-03-27 Test if player != null in the JavaScript API methods.
6.1.1 2010-02-12 Get default twist duration from model.
6.1 2010-02-09 Added support for zip-compressed resource file.
6.0 2010-01-24 Load stickers image from the .jar file, if a file named StickersImage.png, .jpg or .gif is in the .jar file.
5.5.1 2010-01-01 Adding an additional color to the cube in the resource XML file caused one complete face to be in this color.
5.5 2009-12-02 Added "scaleFactor" parameter.
5.4.2 2009-11-28 Flush memory when applet is stopped.
5.4.1 2009-07-04 Catch all throwables when getting an image.
5.4 2009-04-13 Added method getAPIInfo(), fixed method getParameterInfo().
5.3 Added methods setPermutation/getPermutation.
5.2 2009-03-08 Added "stickerBevel" parameter. The script field is now always displayed, if the "displayLines" parameter has a value different from 0.
5.0 2009-01-06 Added public methods for controlling playback using JavaScript. Changed case of 'scriptType' parameter values.
4.5 2009-01-04 Bail if notation parameter is for a different cube.
4.4 2008-12-20 Only read cube atributes from resource file if kind matches. "colorMap" attribute was wrongly used instead of "colorList". "colorTable" was not applied to colorMap. Fixed class-cast exceptions when reading "colorTable" and "colorList" parameters.
4.3 2008-09-13 Read cube attributes from resource file.
4.2 2008-06-14 Print all read parameters when debugging mode is turned on.
4.1 2008-04-03 Added parameter showController.
4.0 2008-02-02 Rewrote parameters. Now, an empty parameter has the same effect like not specifying this parameter at all.
3.0 2007-12-25 Rewritten for Swing.
2.0 2007-11-15 Upgraded to Java 1.4.
1.0.2 2007-11-14 Compute version string dynamically.
1.0.1 2007-03-04 Updated version string.
1.0 2005-03-03 Created.
Author:
Werner Randelshofer
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  Cube3DCanvas frontCanvas
           
protected  boolean isRearViewVisible
           
protected  CubeMarkupNotation notation
           
protected  ScriptPlayer player
           
protected  Cube3DCanvas rearCanvas
           
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AbstractPlayerApplet()
           
 
Method Summary
protected  void configurePlayer(ScriptPlayer p)
           
protected abstract  ScriptPlayer createPlayer()
           
protected  Cube3DCanvas createRearCanvas()
           
protected  java.awt.Image decodeBase64Image(java.lang.String base64)
           
 void destroy()
           
 java.lang.String[][] getAPIInfo()
          Returns information about the JavaScript API supported by this applet.
 java.lang.String getAppletCopyright()
           
 java.lang.String getAppletInfo()
          Returns version and copyright information.
 java.lang.String getAppletName()
           
protected  java.lang.String getAppletVersion()
           
protected  Cube getCube()
           
 int getCurrentPosition()
          JavaScript API: Gets the current position of the playhead.
 int getEndPosition()
          JavaScript API: Gets the start position of the playhead.
protected abstract  int getLayerCount()
           
 java.lang.String getParameter(java.lang.String name)
           
 java.lang.String[][] getParameterInfo()
          Returns information about the parameters supported by this applet.
 java.lang.String getPermutation()
          JavaScript API: Gets the current permutation of the cube.
protected  java.io.InputStream getPlayerResources()
          Returns the Default XML Resource Data of this Applet as an Input Stream.
 java.lang.String getScript()
          JavaScript API: Gets a script.
 java.lang.String getScriptType()
          JavaScript API: Gets the script type.
 int getStartPosition()
          JavaScript API: Gets the end position of the playhead.
 void init()
          Initializes the applet.
 boolean isPlaying()
          JavaScript API: Returns true, if a script is currently being played.
static void main(AbstractPlayerApplet applet, java.lang.String[] args)
           
 void pause()
          JavaScript API: Pauses playback of a script.
 void play()
          JavaScript API: Starts/continues playback of a script.
protected  void printWarning(java.lang.String message)
           
protected  void readCubeAttributes(nanoxml.XMLElement resources, CubeKind kind, DefaultCubeAttributes attr)
          Reads cube attributes from the specified XML Element.
protected  void readParameters()
           
 void reset()
          JavaScript API: Pauses playback, moves playback position to the beginning of a script and resets the cube.
 void resetCube()
          JavaScript API: Resets the cube.
 void run()
          This method is public due to a side effect of the implementation.
protected  void selectCurrentSymbol()
           
 void setCurrentPosition(int newValue)
          JavaScript API: Sets the current position of the playhead.
 void setPermutation(java.lang.String newValue)
          JavaScript API: Sets the current permutation of the cube.
protected  void setRearViewVisible(boolean newValue)
           
 void setScript(java.lang.String newValue)
          JavaScript API: Sets a script.
 void setScriptType(java.lang.String newValue)
          JavaScript API: Sets the script type.
protected  void setSettingsPanelVisible(boolean b)
           
 void stop()
          Stops all background threads.
protected  void updateInfo()
           
 
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, update
 
Methods inherited from class java.applet.Applet
getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, 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, 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

player

protected ScriptPlayer player

frontCanvas

protected Cube3DCanvas frontCanvas

rearCanvas

protected Cube3DCanvas rearCanvas

notation

protected CubeMarkupNotation notation

isRearViewVisible

protected boolean isRearViewVisible
Constructor Detail

AbstractPlayerApplet

public AbstractPlayerApplet()
Method Detail

init

public void init()
Initializes the applet.

Overrides:
init in class java.applet.Applet

stop

public void stop()
Stops all background threads.

Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Overrides:
destroy in class java.applet.Applet

main

public static void main(AbstractPlayerApplet applet,
                        java.lang.String[] args)

getAppletVersion

protected java.lang.String getAppletVersion()

createPlayer

protected abstract ScriptPlayer createPlayer()

getLayerCount

protected abstract int getLayerCount()

createRearCanvas

protected Cube3DCanvas createRearCanvas()

configurePlayer

protected void configurePlayer(ScriptPlayer p)

run

public void run()
This method is public due to a side effect of the implementation. Never call this method explicitly.

Initialises the applet. This is done on a background thread, because it may take a while.

Specified by:
run in interface java.lang.Runnable
See Also:
init()

setSettingsPanelVisible

protected void setSettingsPanelVisible(boolean b)

setRearViewVisible

protected void setRearViewVisible(boolean newValue)

selectCurrentSymbol

protected void selectCurrentSymbol()

getCube

protected Cube getCube()

printWarning

protected void printWarning(java.lang.String message)

readParameters

protected void readParameters()
                       throws AppletParameterException
Throws:
AppletParameterException

getPlayerResources

protected java.io.InputStream getPlayerResources()
Returns the Default XML Resource Data of this Applet as an Input Stream.


getAppletInfo

public java.lang.String getAppletInfo()
Returns version and copyright information.

Overrides:
getAppletInfo in class java.applet.Applet

getAppletCopyright

public java.lang.String getAppletCopyright()

getAppletName

public java.lang.String getAppletName()

readCubeAttributes

protected void readCubeAttributes(nanoxml.XMLElement resources,
                                  CubeKind kind,
                                  DefaultCubeAttributes attr)
Reads cube attributes from the specified XML Element. The XMLElement must be the root of a CubeTwister document.

Parameters:
resources - The XML element which holds the attribute data.
attr - The CubeAttributes onto which we store the attribute values.

decodeBase64Image

protected java.awt.Image decodeBase64Image(java.lang.String base64)

getParameter

public java.lang.String getParameter(java.lang.String name)
Overrides:
getParameter in class java.applet.Applet

getParameterInfo

public java.lang.String[][] getParameterInfo()
Returns information about the parameters supported by this applet.

Overrides:
getParameterInfo in class java.applet.Applet

getAPIInfo

public java.lang.String[][] getAPIInfo()
Returns information about the JavaScript API supported by this applet.


updateInfo

protected void updateInfo()

play

public void play()
JavaScript API: Starts/continues playback of a script.


pause

public void pause()
JavaScript API: Pauses playback of a script.


isPlaying

public boolean isPlaying()
JavaScript API: Returns true, if a script is currently being played.


reset

public void reset()
JavaScript API: Pauses playback, moves playback position to the beginning of a script and resets the cube.


resetCube

public void resetCube()
JavaScript API: Resets the cube.


setScript

public void setScript(java.lang.String newValue)
JavaScript API: Sets a script.


getScript

public java.lang.String getScript()
JavaScript API: Gets a script.


setScriptType

public void setScriptType(java.lang.String newValue)
JavaScript API: Sets the script type.


getScriptType

public java.lang.String getScriptType()
JavaScript API: Gets the script type.


getPermutation

public java.lang.String getPermutation()
JavaScript API: Gets the current permutation of the cube.


setPermutation

public void setPermutation(java.lang.String newValue)
JavaScript API: Sets the current permutation of the cube.


getCurrentPosition

public int getCurrentPosition()
JavaScript API: Gets the current position of the playhead.


setCurrentPosition

public void setCurrentPosition(int newValue)
JavaScript API: Sets the current position of the playhead.


getEndPosition

public int getEndPosition()
JavaScript API: Gets the start position of the playhead.


getStartPosition

public int getStartPosition()
JavaScript API: Gets the end position of the playhead.


(c) Werner Randelshofer.
All rights reserved.