CubeTwister 2.0alpha142 2012-02-11

ch.randelshofer.cubetwister.doc
Class CubeModel

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by ch.randelshofer.cubetwister.doc.EntityModel
          extended by ch.randelshofer.cubetwister.doc.InfoModel
              extended by ch.randelshofer.cubetwister.doc.CubeModel
All Implemented Interfaces:
CubeAttributes, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.event.ChangeListener, javax.swing.event.UndoableEditListener, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class CubeModel
extends InfoModel
implements CubeAttributes, java.beans.PropertyChangeListener, javax.swing.event.ChangeListener

Holds a description of a Cube.

Version:
2.1.2 2010-04-05 Fixed names of side parts.
2.1.1 2010-03-23 Method createCube is now able to create cubes with 6 and 7 layers too.
2.1 2007-08-11 Moved "name" property into superclass.
2.0 2006-01-05 Reworked for CubeTwister 2.0.
1.2 2002-12-27 Part names shortened.
1.1.2 2002-11-14 Coalescing of undoable edit events of setIntScale, setIntExplode, setIntAlpha and setIntBeta removed.
1.1.1 2002-05-12 Renamed the term 'kind' into 'kind'.
1.1 2001-09-23 Now uses Rubik's Cube color scheme.
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
static int COLORS_INDEX
           
static java.lang.String EXPLODE_PROPERTY
           
protected  java.awt.Color frontBgColor
           
protected  DefaultImageWellModel frontBgImageModel
           
protected  boolean frontBgImageVisible
           
static java.lang.String INT_ALPHA_PROPERTY
           
static java.lang.String INT_BETA_PROPERTY
           
static java.lang.String INT_EXPLODE_PROPERTY
           
static java.lang.String INT_SCALE_PROPERTY
           
static java.lang.String KIND_PROPERTY
           
static int PARTS_INDEX
           
protected  java.awt.Color rearBgColor
           
protected  DefaultImageWellModel rearBgImageModel
           
protected  boolean rearBgImageVisible
           
static java.lang.String SCALE_PROPERTY
           
protected  int[] stickerCountPerFace
           
static int STICKERS_INDEX
           
protected  DefaultImageWellModel stickersImageModel
           
protected  boolean stickersImageVisible
           
 
Fields inherited from class ch.randelshofer.cubetwister.doc.InfoModel
author, date, description, name, PROP_AUTHOR, PROP_DATE, PROP_DESCRIPTION, PROP_NAME
 
Fields inherited from class ch.randelshofer.cubetwister.doc.EntityModel
PROP_CHILD_COUNT
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Fields inherited from interface ch.randelshofer.rubik.CubeAttributes
ALPHA_PROPERTY, BETA_PROPERTY, EXPLOSION_FACTOR_PROPERTY, FRONT_BG_COLOR_PROPERTY, FRONT_BG_IMAGE_PROPERTY, FRONT_BG_IMAGE_VISIBLE_PROPERTY, PART_EXPLOSION_PROPERTY, PART_FILL_COLOR_PROPERTY, PART_OUTLINE_COLOR_PROPERTY, PART_VISIBLE_PROPERTY, REAR_BG_COLOR_PROPERTY, REAR_BG_IMAGE_PROPERTY, REAR_BG_IMAGE_VISIBLE_PROPERTY, SCALE_FACTOR_PROPERTY, STICKER_EXPLOSION_PROPERTY, STICKER_FILL_COLOR_PROPERTY, STICKER_OUTLINE_COLOR_PROPERTY, STICKER_VISIBLE_PROPERTY, STICKERS_IMAGE_PROPERTY, STICKERS_IMAGE_VISIBLE_PROPERTY, TWIST_DURATION_PROPERTY, VALUE_IS_ADJUSTING_PROPERTY
 
Constructor Summary
CubeModel()
          Creates new CubeScript
CubeModel(CubeKind kind)
           
 
Method Summary
 void addNotify(EntityModel m)
           
 void basicSetFrontBgImageVisible(boolean newValue)
           
 void basicSetIntAlpha(int value)
           
 void basicSetIntBeta(int value)
           
 void basicSetIntExplode(int value)
           
 void basicSetIntScale(int value)
           
 void basicSetKind(CubeKind value)
           
 void basicSetRearBgImageVisible(boolean newValue)
           
 void basicSetStickersImageVisible(boolean value)
           
 java.lang.Object clone()
          Creates a deep copy of this cube model.
 Cube createCube()
           
 void dispose()
          Gets rid of allocated resources.
 float getAlpha()
          Gets the alpha orientation of the cube.
 float getBeta()
          Gets the beta orientation of the cube.
 EntityModel getColors()
           
 java.lang.Class getCube3DClass()
           
 CubeAttributes getCubeAttributes()
           
 float getExplosionFactor()
          Gets the global explosion factor of the cube.
 int getFaceCount()
           
 java.awt.Color getFrontBgColor()
           
 java.awt.Image getFrontBgImage()
           
 ImageWellModel getFrontBgImageModel()
           
 int getIntAlpha()
           
 int getIntBeta()
           
 int getIntExplode()
           
 int getIntScale()
           
 CubeKind getKind()
           
 int getLayerCount()
           
 int getPartCount()
           
 float getPartExplosion(int index)
          Gets the explosion factor of a single part of the cube.
 java.awt.Color getPartFillColor(int partIndex)
           
 java.awt.Color getPartOutlineColor(int partIndex)
           
 EntityModel getParts()
           
 java.awt.Color getRearBgColor()
           
 java.awt.Image getRearBgImage()
           
 ImageWellModel getRearBgImageModel()
           
 float getScaleFactor()
           
 java.lang.Class getSimpleCube3DClass()
           
 int getStickerCount()
           
 int getStickerCount(int face)
           
 float getStickerExplosion(int index)
          Gets the explosion factor of a single sticker of the cube.
 java.awt.Color getStickerFillColor(int stickerIndex)
           
 int getStickerOffset(int index)
           
 java.awt.Color getStickerOutlineColor(int index)
           
 EntityModel getStickers()
           
 java.awt.Image getStickersImage()
           
 ImageWellModel getStickersImageModel()
           
 int getTwistDuration()
           
 boolean getValueIsAdjusting()
          Returns true if the current changes to the value property are part of a series of changes.
 boolean isDefaultCube()
           
 boolean isFrontBgImageVisible()
           
 boolean isPartVisible(int partIndex)
           
 boolean isRearBgImageVisible()
           
 boolean isRemovable()
          Returns true if the node may be removed from its parent.
 boolean isStickersImageVisible()
           
 boolean isStickerVisible(int stickerIndex)
           
 void propertyChange(java.beans.PropertyChangeEvent evt)
          This method gets called when a bound property is changed.
 void removeNotify(EntityModel m)
           
 void reset()
           
 void setAlpha(double d)
           
 void setBeta(double d)
           
 void setFrontBgColor(java.awt.Color newValue)
           
 void setFrontBgImage(java.awt.Image newValue)
           
 void setFrontBgImageVisible(boolean newValue)
           
 void setIntAlpha(int value)
           
 void setIntBeta(int value)
           
 void setIntExplode(int value)
           
 void setIntScale(int value)
           
 void setKind(CubeKind value)
           
 void setPartVisible(int partIndex, boolean newValue)
           
 void setRearBgColor(java.awt.Color newValue)
           
 void setRearBgImage(java.awt.Image newValue)
           
 void setRearBgImageVisible(boolean newValue)
           
 void setStickersImageVisible(boolean newValue)
           
 void setTo(CubeAttributes that)
          Sets the attributes of this cube to the specified attributes.
 void setTwistDuration(int newValue)
           
 void setValueIsAdjusting(boolean newValue)
          This attribute indicates that any upcoming changes to the value of the model should be considered a single event.
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 
Methods inherited from class ch.randelshofer.cubetwister.doc.InfoModel
basicSetAuthor, basicSetDate, basicSetDescription, basicSetName, getAuthor, getAuthorDocument, getDate, getDateDocument, getDescription, getDescriptionDocument, getName, getNameDocument, getUserObject, setAuthor, setDate, setDescription, setName, setUserObject, toString, undoableEditHappened
 
Methods inherited from class ch.randelshofer.cubetwister.doc.EntityModel
addPropertyChangeListener, children, fireNodeChanged, fireNodeStructureChanged, firePropertyChange, firePropertyChange, firePropertyChange, fireUndoableEditHappened, getDocument, hasPropertyListeners, insert, isDefaultNotation, remove, removePropertyChangeListener, setRemovable
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObjectPath, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ch.randelshofer.rubik.CubeAttributes
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

PARTS_INDEX

public static final int PARTS_INDEX
See Also:
Constant Field Values

STICKERS_INDEX

public static final int STICKERS_INDEX
See Also:
Constant Field Values

COLORS_INDEX

public static final int COLORS_INDEX
See Also:
Constant Field Values

KIND_PROPERTY

public static final java.lang.String KIND_PROPERTY
See Also:
Constant Field Values

SCALE_PROPERTY

public static final java.lang.String SCALE_PROPERTY
See Also:
Constant Field Values

INT_SCALE_PROPERTY

public static final java.lang.String INT_SCALE_PROPERTY
See Also:
Constant Field Values

EXPLODE_PROPERTY

public static final java.lang.String EXPLODE_PROPERTY
See Also:
Constant Field Values

INT_EXPLODE_PROPERTY

public static final java.lang.String INT_EXPLODE_PROPERTY
See Also:
Constant Field Values

INT_ALPHA_PROPERTY

public static final java.lang.String INT_ALPHA_PROPERTY
See Also:
Constant Field Values

INT_BETA_PROPERTY

public static final java.lang.String INT_BETA_PROPERTY
See Also:
Constant Field Values

stickerCountPerFace

protected int[] stickerCountPerFace

frontBgColor

protected java.awt.Color frontBgColor

rearBgColor

protected java.awt.Color rearBgColor

stickersImageModel

protected DefaultImageWellModel stickersImageModel

frontBgImageModel

protected DefaultImageWellModel frontBgImageModel

rearBgImageModel

protected DefaultImageWellModel rearBgImageModel

rearBgImageVisible

protected boolean rearBgImageVisible

frontBgImageVisible

protected boolean frontBgImageVisible

stickersImageVisible

protected boolean stickersImageVisible
Constructor Detail

CubeModel

public CubeModel()
Creates new CubeScript


CubeModel

public CubeModel(CubeKind kind)
Method Detail

createCube

public Cube createCube()

getLayerCount

public int getLayerCount()

getIntScale

public int getIntScale()

setIntScale

public void setIntScale(int value)

basicSetIntScale

public void basicSetIntScale(int value)

getIntExplode

public int getIntExplode()

setIntExplode

public void setIntExplode(int value)

basicSetIntExplode

public void basicSetIntExplode(int value)

getIntAlpha

public int getIntAlpha()

setIntAlpha

public void setIntAlpha(int value)

basicSetIntAlpha

public void basicSetIntAlpha(int value)

getIntBeta

public int getIntBeta()

setIntBeta

public void setIntBeta(int value)

basicSetIntBeta

public void basicSetIntBeta(int value)

getKind

public CubeKind getKind()

setKind

public void setKind(CubeKind value)

basicSetKind

public void basicSetKind(CubeKind value)

getCube3DClass

public java.lang.Class getCube3DClass()

getParts

public EntityModel getParts()

getColors

public EntityModel getColors()

getStickers

public EntityModel getStickers()

getSimpleCube3DClass

public java.lang.Class getSimpleCube3DClass()

getCubeAttributes

public CubeAttributes getCubeAttributes()

addNotify

public void addNotify(EntityModel m)

removeNotify

public void removeNotify(EntityModel m)

setPartVisible

public void setPartVisible(int partIndex,
                           boolean newValue)

clone

public java.lang.Object clone()
Creates a deep copy of this cube model.

Specified by:
clone in interface CubeAttributes
Overrides:
clone in class InfoModel
Returns:
a clone of the attributes.

getPartCount

public int getPartCount()
Specified by:
getPartCount in interface CubeAttributes

getStickerCount

public int getStickerCount()
Specified by:
getStickerCount in interface CubeAttributes

getStickerFillColor

public java.awt.Color getStickerFillColor(int stickerIndex)
Specified by:
getStickerFillColor in interface CubeAttributes

isStickerVisible

public boolean isStickerVisible(int stickerIndex)
Specified by:
isStickerVisible in interface CubeAttributes

getPartOutlineColor

public java.awt.Color getPartOutlineColor(int partIndex)
Specified by:
getPartOutlineColor in interface CubeAttributes

isPartVisible

public boolean isPartVisible(int partIndex)
Specified by:
isPartVisible in interface CubeAttributes

getPartFillColor

public java.awt.Color getPartFillColor(int partIndex)
Specified by:
getPartFillColor in interface CubeAttributes

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
This method gets called when a bound property is changed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - A PropertyChangeEvent object describing the event source and the property that has changed.

getScaleFactor

public float getScaleFactor()
Specified by:
getScaleFactor in interface CubeAttributes

getExplosionFactor

public float getExplosionFactor()
Description copied from interface: CubeAttributes
Gets the global explosion factor of the cube.

Specified by:
getExplosionFactor in interface CubeAttributes

getAlpha

public float getAlpha()
Description copied from interface: CubeAttributes
Gets the alpha orientation of the cube.

Specified by:
getAlpha in interface CubeAttributes

getBeta

public float getBeta()
Description copied from interface: CubeAttributes
Gets the beta orientation of the cube.

Specified by:
getBeta in interface CubeAttributes

setAlpha

public void setAlpha(double d)

setBeta

public void setBeta(double d)

isRemovable

public boolean isRemovable()
Returns true if the node may be removed from its parent.

Overrides:
isRemovable in class EntityModel

reset

public void reset()
Specified by:
reset in interface CubeAttributes

getStickerOffset

public int getStickerOffset(int index)
Specified by:
getStickerOffset in interface CubeAttributes

getFaceCount

public int getFaceCount()
Specified by:
getFaceCount in interface CubeAttributes

getStickerCount

public int getStickerCount(int face)
Specified by:
getStickerCount in interface CubeAttributes

getStickerOutlineColor

public java.awt.Color getStickerOutlineColor(int index)
Specified by:
getStickerOutlineColor in interface CubeAttributes

getStickersImage

public java.awt.Image getStickersImage()
Specified by:
getStickersImage in interface CubeAttributes

setFrontBgColor

public void setFrontBgColor(java.awt.Color newValue)

setFrontBgImage

public void setFrontBgImage(java.awt.Image newValue)

getFrontBgColor

public java.awt.Color getFrontBgColor()
Specified by:
getFrontBgColor in interface CubeAttributes

getFrontBgImage

public java.awt.Image getFrontBgImage()
Specified by:
getFrontBgImage in interface CubeAttributes

setRearBgColor

public void setRearBgColor(java.awt.Color newValue)

setRearBgImage

public void setRearBgImage(java.awt.Image newValue)

getRearBgColor

public java.awt.Color getRearBgColor()
Specified by:
getRearBgColor in interface CubeAttributes

getRearBgImage

public java.awt.Image getRearBgImage()
Specified by:
getRearBgImage in interface CubeAttributes

getStickersImageModel

public ImageWellModel getStickersImageModel()

getRearBgImageModel

public ImageWellModel getRearBgImageModel()

getFrontBgImageModel

public ImageWellModel getFrontBgImageModel()

isFrontBgImageVisible

public boolean isFrontBgImageVisible()
Specified by:
isFrontBgImageVisible in interface CubeAttributes

isRearBgImageVisible

public boolean isRearBgImageVisible()
Specified by:
isRearBgImageVisible in interface CubeAttributes

isStickersImageVisible

public boolean isStickersImageVisible()
Specified by:
isStickersImageVisible in interface CubeAttributes

basicSetFrontBgImageVisible

public void basicSetFrontBgImageVisible(boolean newValue)

setFrontBgImageVisible

public void setFrontBgImageVisible(boolean newValue)

basicSetRearBgImageVisible

public void basicSetRearBgImageVisible(boolean newValue)

setRearBgImageVisible

public void setRearBgImageVisible(boolean newValue)

basicSetStickersImageVisible

public void basicSetStickersImageVisible(boolean value)

setStickersImageVisible

public void setStickersImageVisible(boolean newValue)

stateChanged

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

dispose

public void dispose()
Description copied from interface: CubeAttributes
Gets rid of allocated resources.

Specified by:
dispose in interface CubeAttributes
Overrides:
dispose in class InfoModel

setValueIsAdjusting

public void setValueIsAdjusting(boolean newValue)
Description copied from interface: CubeAttributes
This attribute indicates that any upcoming changes to the value of the model should be considered a single event. This attribute will be set to true at the start of a series of changes to the value, and will be set to false when the value has finished changing. Normally this allows a listener to only take action when the final value change in committed, instead of having to do updates for all intermediate values.

Sliders and scrollbars use this property when a drag is underway.

Specified by:
setValueIsAdjusting in interface CubeAttributes
Parameters:
newValue - true if the upcoming changes to the value property are part of a series

getValueIsAdjusting

public boolean getValueIsAdjusting()
Description copied from interface: CubeAttributes
Returns true if the current changes to the value property are part of a series of changes.

Specified by:
getValueIsAdjusting in interface CubeAttributes
Returns:
the valueIsAdjustingProperty.
See Also:
CubeAttributes.setValueIsAdjusting(boolean)

getPartExplosion

public float getPartExplosion(int index)
Description copied from interface: CubeAttributes
Gets the explosion factor of a single part of the cube.

Specified by:
getPartExplosion in interface CubeAttributes

getStickerExplosion

public float getStickerExplosion(int index)
Description copied from interface: CubeAttributes
Gets the explosion factor of a single sticker of the cube.

Specified by:
getStickerExplosion in interface CubeAttributes

getTwistDuration

public int getTwistDuration()
Specified by:
getTwistDuration in interface CubeAttributes

setTwistDuration

public void setTwistDuration(int newValue)

isDefaultCube

public boolean isDefaultCube()
Overrides:
isDefaultCube in class EntityModel

setTo

public void setTo(CubeAttributes that)
Description copied from interface: CubeAttributes
Sets the attributes of this cube to the specified attributes.

Specified by:
setTo in interface CubeAttributes

(c) Werner Randelshofer.
All rights reserved.