CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.rubik.virtual
Class AbstractVirtualCubeApplet

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.virtual.AbstractVirtualCubeApplet
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
VirtualCube6Applet, VirtualCube7Applet, VirtualPocketCubeApplet, VirtualProfessorCubeApplet, VirtualRevengeCubeApplet, VirtualRubiksBarrelApplet, VirtualRubiksCubeApplet, VirtualRubiksCuboctahedronApplet, VirtualRubiksDiamondApplet, VirtualVCube6Applet, VirtualVCube7Applet

public abstract class AbstractVirtualCubeApplet
extends javax.swing.JApplet

This is the base class for Applets featuring a Rubik's Cube like puzzle which can be taken apart.

Version:
2.8 2010-05-02 Alt- or Ctrl-Click on reset button only resets the canvas but not the cube.
2.7.6 2010-04-06 Replaced Random2 class by java.util.Random.
2.7.5 2010-03-08 Adjusted layout, so that buttons are cut off instead of disappearing when the applet is sized too small.
2.7.4 2010-02-09 Added support for zip-compressed resource file.
2.7.3 2010-01-01 Adding an additional color to the cube in the resource XML file caused one complete face to be in this color.
2.7.2 2009-11-28 Flush resources when applet is stopped.
2.7.1 2009-07-04 Catch all throwables when loading images.
2.7 2009-01-09 Use modifiersEx instead of modifiers.
2.6 2009-01-07 Added applet parameter selectTool.
2.5 2009-01-05 Avoid cursor update conflicts with idx3d_JCanvas.
2.4 2009-01-03 Use hand cursor do indicate that the cube can be rotated.
2.3 2008-04-03 Use system look and feel.
2.2 2008-01-03 Implemented base64 image decoder. Fixed implementation of reset function.
2.1 2007-11-18 Added applet parameters: resourceFile, resourceData, cube.
2.0.1 2007-11-14 Method scramble only worked for 3x3 cube.
2.0 2007-09-10 Rewritten for Swing instead of AWT:
1.2 2007-09-09 Use SplineInterpolator to reset explosion factor. Use Shift-key for 180 degree twists.
1.1 2007-08-31 Dispose of resources when method destroy is called.
1.0 25. August 2007 Created.
Author:
Werner Randelshofer
See Also:
Serialized Form

Nested Class Summary
 class AbstractVirtualCubeApplet.EventHandler
           
 
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  idx3d_JCanvas canvas
           
protected  AbstractCubeIdx3D cube3d
           
protected  AbstractVirtualCubeApplet.EventHandler cube3DHandler
           
protected  float defaultScaleFactor
           
protected  java.util.ResourceBundle labels
           
protected  AbstractVirtualCubeApplet.EventHandler linkHandler
           
protected  java.lang.String linkTarget
          Target frame for sticker links.
protected  AbstractVirtualCubeApplet.EventHandler partsHandler
           
protected  java.util.Random random
           
protected  idx3d_Scene scene
           
protected  java.lang.String[] stickerLinks
          Each array element holds a link on a sticker of the cube.
protected  AbstractVirtualCubeApplet.EventHandler stickersHandler
           
protected  int tool
           
protected  AbstractVirtualCubeApplet.EventHandler twistHandler
           
 
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
AbstractVirtualCubeApplet()
           
 
Method Summary
protected  boolean canBeDisassembled()
           
protected abstract  AbstractCubeIdx3D createCube3D()
           
protected  java.awt.Image decodeBase64Image(java.lang.String base64)
           
 void destroy()
          Destroys the applet.
protected  void doInit()
          Initializes the applet.
 java.lang.String getAppletInfo()
          Returns information about this applet.
protected  java.lang.String getAppletVersion()
           
protected  AbstractVirtualCubeApplet.EventHandler getCube3DHandler()
           
protected  AbstractVirtualCubeApplet.EventHandler getLinkHandler()
           
 java.lang.String getParameter(java.lang.String name)
           
 java.lang.String[][] getParameterInfo()
          Returns information about the parameters that are understood by this applet.
protected  AbstractVirtualCubeApplet.EventHandler getPartsHandler()
           
protected  AbstractVirtualCubeApplet.EventHandler getStickersHandler()
           
protected  AbstractVirtualCubeApplet.EventHandler getTwistHandler()
           
 void init()
          Initializes the applet.
static void main(AbstractVirtualCubeApplet applet)
           
protected  void readCubeAttributes(nanoxml.XMLElement resources, DefaultCubeAttributes attr)
          Reads cube attributes from the specified XML Element.
protected  void readParameters()
           
protected  void readStateFromCookies()
           
protected  void reset()
           
protected  void resetCanvas()
           
protected  void scramble()
           
 void stop()
          Flush resources used by the applet.
protected  void writeStateToCookies()
           
 
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

cube3d

protected AbstractCubeIdx3D cube3d

tool

protected int tool

canvas

protected idx3d_JCanvas canvas

random

protected java.util.Random random

scene

protected idx3d_Scene scene

labels

protected java.util.ResourceBundle labels

defaultScaleFactor

protected float defaultScaleFactor

cube3DHandler

protected AbstractVirtualCubeApplet.EventHandler cube3DHandler

twistHandler

protected AbstractVirtualCubeApplet.EventHandler twistHandler

linkHandler

protected AbstractVirtualCubeApplet.EventHandler linkHandler

stickersHandler

protected AbstractVirtualCubeApplet.EventHandler stickersHandler

partsHandler

protected AbstractVirtualCubeApplet.EventHandler partsHandler

stickerLinks

protected java.lang.String[] stickerLinks
Each array element holds a link on a sticker of the cube. If an element is null, the sticker does not represent a link.


linkTarget

protected java.lang.String linkTarget
Target frame for sticker links. Is not null, when sticker links are present.

Constructor Detail

AbstractVirtualCubeApplet

public AbstractVirtualCubeApplet()
Method Detail

init

public void init()
Initializes the applet.

Overrides:
init in class java.applet.Applet

stop

public void stop()
Flush resources used by the applet.

Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Destroys the applet.

Overrides:
destroy in class java.applet.Applet

getParameter

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

doInit

protected void doInit()
               throws AppletParameterException
Initializes the applet. This method must be called on a worker thread.

Throws:
AppletParameterException

readParameters

protected void readParameters()
                       throws AppletParameterException
Throws:
AppletParameterException

readStateFromCookies

protected void readStateFromCookies()

writeStateToCookies

protected void writeStateToCookies()

readCubeAttributes

protected void readCubeAttributes(nanoxml.XMLElement resources,
                                  DefaultCubeAttributes attr)
Reads cube attributes from the specified XML Element.

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

decodeBase64Image

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

createCube3D

protected abstract AbstractCubeIdx3D createCube3D()

canBeDisassembled

protected boolean canBeDisassembled()

getCube3DHandler

protected AbstractVirtualCubeApplet.EventHandler getCube3DHandler()

getTwistHandler

protected AbstractVirtualCubeApplet.EventHandler getTwistHandler()

getLinkHandler

protected AbstractVirtualCubeApplet.EventHandler getLinkHandler()

getStickersHandler

protected AbstractVirtualCubeApplet.EventHandler getStickersHandler()

getPartsHandler

protected AbstractVirtualCubeApplet.EventHandler getPartsHandler()

scramble

protected void scramble()

resetCanvas

protected void resetCanvas()

reset

protected void reset()

getParameterInfo

public java.lang.String[][] getParameterInfo()
Returns information about the parameters that are understood by this applet. An applet should override this method to return an array of Strings describing these parameters.

Each element of the array should be a set of three Strings containing the name, the type, and a description. For example:

 String pinfo[][] = {
         {"fps",    "1-10",    "frames per second"},
         {"repeat", "boolean", "repeat image loop"},
         {"imgs",   "url",     "images directory"}
 };
 

The implementation of this method provided by the Applet class returns null.

Overrides:
getParameterInfo in class java.applet.Applet
Returns:
an array describing the parameters this applet looks for.

getAppletVersion

protected java.lang.String getAppletVersion()

getAppletInfo

public java.lang.String getAppletInfo()
Returns information about this applet. An applet should override this method to return a String containing information about the author, version, and copyright of the applet.

The implementation of this method provided by the Applet class returns null.

Overrides:
getAppletInfo in class java.applet.Applet
Returns:
a string containing information about the author, version, and copyright of the applet.

main

public static void main(AbstractVirtualCubeApplet applet)

(c) Werner Randelshofer.
All rights reserved.