edu.princeton.cs.algs4.growingtree.framework
Class DrawingKey

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.framework.DrawingKey
All Implemented Interfaces:
DrawableKey, java.lang.Cloneable

public class DrawingKey
extends java.lang.Object
implements DrawableKey

DrawingKey implements DrawableKey for it is a specific type that draws Object keys. Its constructor needs the Object key it will draw.

Version:
2.1 9/15/01
Author:
Corey Sanders
See Also:
DrawableKey

Constructor Summary
DrawingKey(int k)
          Constructor that instantiates the DrawingIntegerKey using the given Object k.
DrawingKey(KeyType k)
           
 
Method Summary
 java.lang.Object clone()
          Returns a copy of this AffineTransform object.
 void drawKey(java.awt.Graphics2D g2)
          Draws the key, first setting all values for the Graphics2D g2.
 void drawKey(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a)
          Draws the key in the given Graphics2D, using the AffineTransform passed to it.
 void drawKeyLowerLeft(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a, int width)
           
 void drawKeyLowerRight(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a, int width)
           
 void drawKeyScaled(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a, int width)
           
 void drawKeyUpperLeft(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a, int width)
           
 void drawKeyUpperRight(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a, int width)
           
 void fillKey(java.awt.Graphics2D g2)
          Draws the key filling the given Graphics2D.
 KeyType getKey()
          Gets the Object key of the DrawableKey.
 KeySettings getSettings()
          Gets the KeySettings of the key.
 boolean isSettingsSaved()
          Returns true if the KeySettings are currently saved for the DrawingTree.
 void restoreSettings()
          Restores the settings for the tree, decrementing the count of saves by one.
 void saveSettings()
          Saves the settings for the tree, incrementing the count of saves by one and setting the previous settings accordingly.
 void setKey(KeyType k)
          Sets the Object key of the DrawableKey.
 void setKeySettings(KeySettings s)
          Sets the KeySettings of the DrawableKey.
 void setSettings(KeySettings s)
          Sets the KeySettings of the DrawableKey.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DrawingKey

public DrawingKey(int k)
Constructor that instantiates the DrawingIntegerKey using the given Object k.

Parameters:
k - the Object drawn to the screen.

DrawingKey

public DrawingKey(KeyType k)
Method Detail

clone

public java.lang.Object clone()
Returns a copy of this AffineTransform object.

Specified by:
clone in interface DrawableKey
Overrides:
clone in class java.lang.Object
Returns:
an Object that is a copy of this AffineTransform object.

setKey

public void setKey(KeyType k)
Sets the Object key of the DrawableKey.

Parameters:
k - Object key for use in drawing the key.

getKey

public KeyType getKey()
Gets the Object key of the DrawableKey.

Returns:
Object key used for drawing the key.

setSettings

public void setSettings(KeySettings s)
Sets the KeySettings of the DrawableKey. These settings are used for drawing the key in a given Graphics2D.

Specified by:
setSettings in interface DrawableKey
Parameters:
s - KeySettings for use in drawing the key.

setKeySettings

public void setKeySettings(KeySettings s)
Sets the KeySettings of the DrawableKey. These settings are used for drawing the key in a given Graphics2D.

Specified by:
setKeySettings in interface DrawableKey
Parameters:
s - KeySettings for use in drawing the key.

getSettings

public KeySettings getSettings()
Gets the KeySettings of the key.

Specified by:
getSettings in interface DrawableKey
Returns:
KeySettings for use in drawing the key.

isSettingsSaved

public boolean isSettingsSaved()
Returns true if the KeySettings are currently saved for the DrawingTree.

Specified by:
isSettingsSaved in interface DrawableKey
Returns:
true if the settings are saved.

saveSettings

public void saveSettings()
Saves the settings for the tree, incrementing the count of saves by one and setting the previous settings accordingly.

Specified by:
saveSettings in interface DrawableKey

restoreSettings

public void restoreSettings()
Restores the settings for the tree, decrementing the count of saves by one. If the settings have been restored completely, than the KeySettings for the tree are set accordingly.

Specified by:
restoreSettings in interface DrawableKey

fillKey

public void fillKey(java.awt.Graphics2D g2)
Description copied from interface: DrawableKey
Draws the key filling the given Graphics2D. The method completely fills the Graphics2D passed to it, setting the transform as the one necessary to fill and center in the Graphics2D.

Specified by:
fillKey in interface DrawableKey
Parameters:
g2 - Graphics2D that fills with the key.

drawKeyUpperLeft

public void drawKeyUpperLeft(java.awt.Graphics2D g2,
                             java.awt.geom.AffineTransform a,
                             int width)

drawKeyUpperRight

public void drawKeyUpperRight(java.awt.Graphics2D g2,
                              java.awt.geom.AffineTransform a,
                              int width)

drawKeyLowerRight

public void drawKeyLowerRight(java.awt.Graphics2D g2,
                              java.awt.geom.AffineTransform a,
                              int width)

drawKeyLowerLeft

public void drawKeyLowerLeft(java.awt.Graphics2D g2,
                             java.awt.geom.AffineTransform a,
                             int width)

drawKey

public void drawKey(java.awt.Graphics2D g2,
                    java.awt.geom.AffineTransform a)
Draws the key in the given Graphics2D, using the AffineTransform passed to it. The method uses the AffineTransform using no previous transforms.

Specified by:
drawKey in interface DrawableKey
Parameters:
g2 - Graphics2D that this fills with the key.
a - AffineTransform that transforms the key, assuming no previous transforms occur.

drawKeyScaled

public void drawKeyScaled(java.awt.Graphics2D g2,
                          java.awt.geom.AffineTransform a,
                          int width)

drawKey

public void drawKey(java.awt.Graphics2D g2)
Draws the key, first setting all values for the Graphics2D g2. The drawing is done using the current Shape, defined generally in drawKey or fillKey.

Specified by:
drawKey in interface DrawableKey
Parameters:
g2 - Graphics2D that the key is painted to.