CubeTwister 2.0alpha141 2011-10-13

ch.randelshofer.rubik
Class AbstractCube3D

java.lang.Object
  extended by ch.randelshofer.rubik.AbstractCube3D
All Implemented Interfaces:
Cube3D, CubeListener, java.beans.PropertyChangeListener, java.util.EventListener, javax.swing.event.ChangeListener
Direct Known Subclasses:
AbstractCubeGeom3D, AbstractCubeIdx3D

public abstract class AbstractCube3D
extends java.lang.Object
implements Cube3D, CubeListener, java.beans.PropertyChangeListener, javax.swing.event.ChangeListener

Abstract base class for classes which implement the Cube3D interface.

Version:
8.1.1 2009-01-09 Added workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6634290
8.1 2008-04-28 Added method setAnimator.
8.0 2007-11-15 Upgraded to Java 1.4.
7.1 2007-09-10 Use SplineInterpolator instead of linear Interpolator.
7.0 2007-08-28 PartAction is now also a MouseListener.
6.0 2005-03-06 Reworked.
1.0 December 21, 2003 Created.
Author:
Werner Randelshofer

Nested Class Summary
protected  class AbstractCube3D.PartAction
          This action is used to forward user actions on the cube parts to Cube3DListeners.
protected  class AbstractCube3D.SwipeAction
           
 
Field Summary
protected  CubeAttributes attributes
           
protected  javax.swing.event.ChangeEvent changeEvent
           
protected  Dispatcher dispatcher
           
protected  boolean isAnimated
           
protected  int layerCount
           
protected  javax.swing.event.EventListenerList listenerList
           
 
Constructor Summary
AbstractCube3D(int layerCount)
          Creates a new instance.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener listener)
          Adds a change listener.
 void addCube3DListener(Cube3DListener listener)
           
protected abstract  CubeAttributes createAttributes()
          Creates cube attributes (e.g.
 void cubeChanged(CubeEvent evt)
           
 void cubeTwisted(CubeEvent evt)
           
 void dispatch(org.mmonte.media.Interpolator interpolator)
           
 void dispose()
           
protected  void fireActionPerformed(Cube3DEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireMouseEntered(Cube3DEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireMouseExited(Cube3DEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireMousePressed(Cube3DEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireMouseReleased(Cube3DEvent event)
          Notify all listeners that have registered interest for notification on this event type.
protected  void fireStateChanged()
          Notify all listeners that have registered interest for notification on this event type.
 org.mmonte.media.Animator getAnimator()
           
 CubeAttributes getAttributes()
          Gets cube attributees.
 Cube getCube()
          Gets the underlying permutation model.
 Dispatcher getDispatcher()
          Gets the dispatcher used to process animations of the 3D geometry.
 java.lang.Object getLock()
          Returns the lock object used for synchronizing model and view changes.
protected abstract  int getPartFaceIndexForStickerIndex(int stickerIndex)
           
abstract  int getPartIndexForStickerIndex(int stickerIndex)
           
abstract  java.lang.Object getScene()
          Returns the 3D scene of the cube.
protected abstract  int getStickerCount()
           
protected  boolean isAdjusting()
           
 boolean isAnimated()
          Returns true when the 3D geometry animates permutation changes.
 boolean isAnimating()
          Returns true if the cube is currently performing an animation.
 boolean isShowGhostParts()
           
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 void removeChangeListener(javax.swing.event.ChangeListener listener)
          Removes a change listener.
 void removeCube3DListener(Cube3DListener listener)
           
 void setAnimated(boolean b)
          Sets whether changes in the permutation model shall cause an animated (multi-frame) change in the 3D geometry or whether they shall be reflected immediately.
 void setAnimator(org.mmonte.media.Animator newValue)
           
 void setAttributes(CubeAttributes attributes)
          Sets cube attributees.
 void setCube(Cube cube)
          Sets the underlying permutation model.
 void setDispatcher(Dispatcher dispatcher)
          Sets the dispatcher used to process animations of the 3D geometry.
 void setLock(java.lang.Object o)
          Sets the lock object used for synchronizing model and view changes.
 void setShowGhostParts(boolean b)
           
 void stateChanged(javax.swing.event.ChangeEvent event)
           
 void stopAnimation()
          Stops all currently running animations.
protected abstract  void updateAlphaBeta()
           
protected abstract  void updateAttributes()
           
protected abstract  void updateCube()
           
protected abstract  void updateExplosionFactor(float factor)
           
protected abstract  void updatePartVisibility(int index, float alpha)
          Updates the fill color of a part.
protected abstract  void updateScaleFactor(float factor)
           
protected abstract  void updateStickersImage()
          Updates the sticker imagery.
protected abstract  void updateStickerVisibility(int index, float alpha)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.randelshofer.rubik.Cube3D
getKind, getPartCount, isInStartedPlayer, setInStartedPlayer, setStickerBeveling
 

Field Detail

listenerList

protected javax.swing.event.EventListenerList listenerList

changeEvent

protected javax.swing.event.ChangeEvent changeEvent

attributes

protected CubeAttributes attributes

isAnimated

protected boolean isAnimated

dispatcher

protected Dispatcher dispatcher

layerCount

protected int layerCount
Constructor Detail

AbstractCube3D

public AbstractCube3D(int layerCount)
Creates a new instance.

Method Detail

getScene

public abstract java.lang.Object getScene()
Returns the 3D scene of the cube. We return an Object type here, because the type of the 3D scene depends on the 3D engine used.

Specified by:
getScene in interface Cube3D

getLock

public java.lang.Object getLock()
Returns the lock object used for synchronizing model and view changes.

Specified by:
getLock in interface Cube3D

setLock

public void setLock(java.lang.Object o)
Sets the lock object used for synchronizing model and view changes.

Specified by:
setLock in interface Cube3D

setDispatcher

public void setDispatcher(Dispatcher dispatcher)
Sets the dispatcher used to process animations of the 3D geometry.

Specified by:
setDispatcher in interface Cube3D

getDispatcher

public Dispatcher getDispatcher()
Gets the dispatcher used to process animations of the 3D geometry.

Specified by:
getDispatcher in interface Cube3D

updateStickersImage

protected abstract void updateStickersImage()
Updates the sticker imagery.


setAnimated

public void setAnimated(boolean b)
Sets whether changes in the permutation model shall cause an animated (multi-frame) change in the 3D geometry or whether they shall be reflected immediately.

Specified by:
setAnimated in interface Cube3D

setAnimator

public void setAnimator(org.mmonte.media.Animator newValue)
Specified by:
setAnimator in interface Cube3D

getAnimator

public org.mmonte.media.Animator getAnimator()
Specified by:
getAnimator in interface Cube3D

isAnimated

public boolean isAnimated()
Returns true when the 3D geometry animates permutation changes.

Specified by:
isAnimated in interface Cube3D

isAdjusting

protected boolean isAdjusting()

stopAnimation

public void stopAnimation()
Stops all currently running animations.

Specified by:
stopAnimation in interface Cube3D

setCube

public void setCube(Cube cube)
Sets the underlying permutation model.

Specified by:
setCube in interface Cube3D

getCube

public Cube getCube()
Gets the underlying permutation model.

Specified by:
getCube in interface Cube3D

createAttributes

protected abstract CubeAttributes createAttributes()
Creates cube attributes (e.g. colors, sticker pictures, ...).


setAttributes

public void setAttributes(CubeAttributes attributes)
Sets cube attributees.

Specified by:
setAttributes in interface Cube3D

getAttributes

public CubeAttributes getAttributes()
Gets cube attributees.

Specified by:
getAttributes in interface Cube3D

getStickerCount

protected abstract int getStickerCount()

getPartIndexForStickerIndex

public abstract int getPartIndexForStickerIndex(int stickerIndex)
Specified by:
getPartIndexForStickerIndex in interface Cube3D

getPartFaceIndexForStickerIndex

protected abstract int getPartFaceIndexForStickerIndex(int stickerIndex)

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener listener)
Adds a change listener. The change listener is notified about geometry changes. This is useful for a 3D canvas interested to know when to repaint.

Specified by:
addChangeListener in interface Cube3D

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener listener)
Removes a change listener.

Specified by:
removeChangeListener in interface Cube3D

updatePartVisibility

protected abstract void updatePartVisibility(int index,
                                             float alpha)
Updates the fill color of a part. The part Index is interpreted according to the scheme used by method getPart(int);


updateStickerVisibility

protected abstract void updateStickerVisibility(int index,
                                                float alpha)

updateExplosionFactor

protected abstract void updateExplosionFactor(float factor)

updateScaleFactor

protected abstract void updateScaleFactor(float factor)

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

cubeChanged

public void cubeChanged(CubeEvent evt)
Specified by:
cubeChanged in interface CubeListener

cubeTwisted

public void cubeTwisted(CubeEvent evt)
Specified by:
cubeTwisted in interface CubeListener

dispatch

public void dispatch(org.mmonte.media.Interpolator interpolator)

updateAttributes

protected abstract void updateAttributes()

updateCube

protected abstract void updateCube()

updateAlphaBeta

protected abstract void updateAlphaBeta()

fireStateChanged

protected void fireStateChanged()
Notify all listeners that have registered interest for notification on this event type.


fireActionPerformed

protected void fireActionPerformed(Cube3DEvent event)
Notify all listeners that have registered interest for notification on this event type.


fireMouseEntered

protected void fireMouseEntered(Cube3DEvent event)
Notify all listeners that have registered interest for notification on this event type.


fireMouseExited

protected void fireMouseExited(Cube3DEvent event)
Notify all listeners that have registered interest for notification on this event type.


fireMousePressed

protected void fireMousePressed(Cube3DEvent event)
Notify all listeners that have registered interest for notification on this event type.


fireMouseReleased

protected void fireMouseReleased(Cube3DEvent event)
Notify all listeners that have registered interest for notification on this event type.


addCube3DListener

public void addCube3DListener(Cube3DListener listener)
Specified by:
addCube3DListener in interface Cube3D

removeCube3DListener

public void removeCube3DListener(Cube3DListener listener)
Specified by:
removeCube3DListener in interface Cube3D

isAnimating

public boolean isAnimating()
Description copied from interface: Cube3D
Returns true if the cube is currently performing an animation.

Specified by:
isAnimating in interface Cube3D

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent event)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

isShowGhostParts

public boolean isShowGhostParts()
Specified by:
isShowGhostParts in interface Cube3D

setShowGhostParts

public void setShowGhostParts(boolean b)
Specified by:
setShowGhostParts in interface Cube3D

dispose

public void dispose()
Specified by:
dispose in interface Cube3D

(c) Werner Randelshofer.
All rights reserved.