Class TileBin

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by TileBin
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class TileBin
extends javax.swing.JPanel

The TileBin hold tiles not currently placed on the grid. It can accommodate multiple tiles wide. Tiles are stored in a linear fashion and 'wrap' in the tilebin. In otherwords, its behaves like a string of text in a word-wrap textbox. Tiles always shift up (or to the left) to fill in gaps in the TileBin. It implements interface functions used by the UserInteraction and Playback classes to manipulate tiles in the TileBin.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private)  javax.swing.JLabel insertLine
          Black line drawn to represent where a tile will be inserted
(package private)  int InsertLineThickness
          Thickness of the insertion line
(package private)  int LEFT
          Defines the TileBin being located on the left side of the grid
(package private)  UserInteraction mouseInput
          CLIP's mouse adapter
(package private)  int numTilesWide
          Current number of Tiles the TileBin displays horizontally per row
(package private)  CLIPFrame parentFrame
          The frame the application runs in
(package private)  int RIGHT
          Defines the TileBin being located on the right side of the grid
private static long serialVersionUID
           
(package private)  java.util.ArrayList tbList
          List of tiles in the TileBin (Stores integer IDs corresponding to TileIDs in the current TileSet)
(package private)  int tbSide
          Current side of the grid that the TileBin is located on (LEFT or RIGHT)
(package private)  TileSet theTileSet
          The current TileSet being used
(package private)  java.awt.Dimension TileBinDefaultSize
          Default size of the tilebin
(package private)  java.lang.String TileBinName
          Name of the tilebin
(package private)  java.awt.Dimension TileBinSize
          Current size of the TileBin
(package private)  int tilePixTall
          Number of pixels tall of each Tile in the current TileSet
(package private)  int tilePixWide
          Number of pixels wide of each Tile in the current TileSet
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
TileBin(UserInteraction mInput, CLIPFrame parent)
          The constructor sets defaults values, initializes the insertion line, creates a new tbList, and registers the mouse listeners.
 
Method Summary
 void addBlankTile(int tileID)
          Adds the tile of the passed in tileID to the end of the TileBin and scrolls to make it visible if needed.
 void adjustSize()
          Adjusts the size of the TileBin and location of the split pane divider based on the number of tiles visible per row.
 void drawInsertionBar(java.awt.Point tileCenter, java.awt.Rectangle binOffset)
          Draws the insertion bar for the tile bin based off the center position of the tile being dragged.
private  void drawTiles(java.awt.Graphics g)
          Draws the tiles at thier proper pixel coordinates in the TileBin.
 void eraseTilePosition(int tileToErase)
          Remove a tile from the TileBin and shifts the remaining tiles over to fill in the gap that was created (if necessary).
 java.awt.Dimension findPreferredSize()
          Finds the preferred size of the TileBin based on the number of tiles currently visible per row.
 int findTileAt(int index)
          Returns the TileID of the tile at the specified index in the list of tiles.
 int getIndexOfInsertion(int x, int y)
          Takes x and y coordinates and calculates the index of the tbList that the coordinates are located over.
 java.awt.Point getMouseOffset(int x, int y, int tileID)
          Takes mouse coordinates and a tileID and calculates the mouse offset from that tile and returns it.
 int getTileBinSquareAt(int x, int y)
          Takes the passed in coordinates of the mouse relative to the TileBin and caculates the index of the tbList at that position.
 void hideInsertLine()
          Hides the insertion line.
 void insertTile(int tileIndex, int tileToInsert)
          Inserts the tile with the passed in ID to the passed in index in the tbList.
 void LoadTileSet(TileSet curSet)
          Loads up the passed in TileSet and fills the TileBin with its tiles.
 void paintComponent(java.awt.Graphics g)
          Paints the Tiles in the tilebin.
 void printArray()
          Debug function that prints the list of tile IDs in the tilebin to the console window.
 void scrollToTile(int tileID)
          Scrolls the TileBin to bring the tile with the passed in ID to be visible if it isn't already.
 void setSideLeft()
          Sets the TileBin to the left side of the grid.
 void setSideRight()
          Sets the TileBin ot the right side of the grid.
 void setTileSet(TileSet curSet)
          Initializes the TileBin to use the passed in TileSet
 void updateTileID(int newID, int y)
          Sets the value in the tbList at the passed in index to the passed in value.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, 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

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

TileBinDefaultSize

final java.awt.Dimension TileBinDefaultSize
Default size of the tilebin


TileBinName

final java.lang.String TileBinName
Name of the tilebin

See Also:
Constant Field Values

mouseInput

UserInteraction mouseInput
CLIP's mouse adapter


parentFrame

CLIPFrame parentFrame
The frame the application runs in


theTileSet

TileSet theTileSet
The current TileSet being used


insertLine

javax.swing.JLabel insertLine
Black line drawn to represent where a tile will be inserted


InsertLineThickness

final int InsertLineThickness
Thickness of the insertion line

See Also:
Constant Field Values

TileBinSize

java.awt.Dimension TileBinSize
Current size of the TileBin


numTilesWide

int numTilesWide
Current number of Tiles the TileBin displays horizontally per row


tilePixWide

int tilePixWide
Number of pixels wide of each Tile in the current TileSet


tilePixTall

int tilePixTall
Number of pixels tall of each Tile in the current TileSet


tbSide

int tbSide
Current side of the grid that the TileBin is located on (LEFT or RIGHT)


LEFT

final int LEFT
Defines the TileBin being located on the left side of the grid

See Also:
Constant Field Values

RIGHT

final int RIGHT
Defines the TileBin being located on the right side of the grid

See Also:
Constant Field Values

tbList

java.util.ArrayList tbList
List of tiles in the TileBin (Stores integer IDs corresponding to TileIDs in the current TileSet)

Constructor Detail

TileBin

public TileBin(UserInteraction mInput,
               CLIPFrame parent)
The constructor sets defaults values, initializes the insertion line, creates a new tbList, and registers the mouse listeners.

Parameters:
mInput - CLIP's mouse adapter to attach to the TileBin
parent - The frame that the application runs in
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints the Tiles in the tilebin. This is also responsible for setting the numTilesWide variable.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - The graphics object to draw on
See Also:
drawTiles(Graphics)

drawTiles

private void drawTiles(java.awt.Graphics g)
Draws the tiles at thier proper pixel coordinates in the TileBin. Tiles are stored in the tbList by Y values only so the actual row/column position must be determined in this function for each tile drawn.

Parameters:
g - The graphics object to draw the tiles on
See Also:
paintComponent(Graphics)

printArray

public void printArray()
Debug function that prints the list of tile IDs in the tilebin to the console window.


findPreferredSize

public java.awt.Dimension findPreferredSize()
Finds the preferred size of the TileBin based on the number of tiles currently visible per row.

Returns:
The preferred size of the TileBin

adjustSize

public void adjustSize()
Adjusts the size of the TileBin and location of the split pane divider based on the number of tiles visible per row. The adjustments are made to leave no blank space on either side of the tiles in the bin. The repetitiveness in this code is due to the fact that if the user moves the divider bar quickly enough, the location won't adjust properly. To solve this issue, this code is basically repeated once if needed to finish the job it was supposed to do the first time.


setTileSet

public void setTileSet(TileSet curSet)
Initializes the TileBin to use the passed in TileSet

Parameters:
curSet - The TileSet to use for the TileBin

LoadTileSet

public void LoadTileSet(TileSet curSet)
Loads up the passed in TileSet and fills the TileBin with its tiles.

Parameters:
curSet - The TileSet to load

findTileAt

public int findTileAt(int index)
Returns the TileID of the tile at the specified index in the list of tiles.

Parameters:
index - Index in the tbList to get the ID of
Returns:
TileID of the tile found; 0 if index is out of bounds

getTileBinSquareAt

public int getTileBinSquareAt(int x,
                              int y)
Takes the passed in coordinates of the mouse relative to the TileBin and caculates the index of the tbList at that position.

Parameters:
x - X coordinate of the mouse relative to the TileBin
y - Y coordinate of the mouse relative to the TileBin
Returns:
Returns the tbList index of the mouse coordinate. Returns -1 if the index is out of bounds.

getMouseOffset

public java.awt.Point getMouseOffset(int x,
                                     int y,
                                     int tileID)
Takes mouse coordinates and a tileID and calculates the mouse offset from that tile and returns it. In other words, if the user clicked in the center of a 100x100 tile and passed that information to this function, it would return a point of x=50 and y=50.

Parameters:
x - X coordinate of the mouse
y - Y coordinate of the mouse
tileID - TileID to get the mouse offset of
Returns:
A point representing the distance from the coordinates to the upper left corner of the tile with the TileID.

eraseTilePosition

public void eraseTilePosition(int tileToErase)
Remove a tile from the TileBin and shifts the remaining tiles over to fill in the gap that was created (if necessary).

Parameters:
tileToErase - ID of the tile to remove

drawInsertionBar

public void drawInsertionBar(java.awt.Point tileCenter,
                             java.awt.Rectangle binOffset)
Draws the insertion bar for the tile bin based off the center position of the tile being dragged. Any position in the upper 1/4 of the tile inserts above. Any position in lower 1/4 inserts below. Any position in the left 1/4 between the upper and lower y values inserts left. Any position in the right 1/4 between the upper and lower y values inserts right. All other values in the upper portion of the tile insert up, and all lower insert below.

Parameters:
tileCenter - The center position of the tile relative to the TileBin
binOffset - Location of the TileBin relative to theMainPanel

hideInsertLine

public void hideInsertLine()
Hides the insertion line.

See Also:
insertLine

addBlankTile

public void addBlankTile(int tileID)
Adds the tile of the passed in tileID to the end of the TileBin and scrolls to make it visible if needed.

Parameters:
tileID - TileID of the tile to add

scrollToTile

public void scrollToTile(int tileID)
Scrolls the TileBin to bring the tile with the passed in ID to be visible if it isn't already.

Parameters:
tileID - ID of the tile to scroll to

getIndexOfInsertion

public int getIndexOfInsertion(int x,
                               int y)
Takes x and y coordinates and calculates the index of the tbList that the coordinates are located over. Future efforts could expand upon this to get the tile placements to occur in two dimensions. One must be careful however because if arrangements in the TileBin were to become too pleasant, it could cause the user to arrange the tiles here rather than in the grid without realizing the need to do otherwise.

Parameters:
x - X coordinate to insert at (relative to the TileBin)
y - Y coordinate to insert at (relative to the TileBin)
Returns:
The index of insertion in the tbList

insertTile

public void insertTile(int tileIndex,
                       int tileToInsert)
Inserts the tile with the passed in ID to the passed in index in the tbList.

Parameters:
tileIndex - Index to place the tile in the tbList.
tileToInsert - ID of the tile to insert

updateTileID

public void updateTileID(int newID,
                         int y)
Sets the value in the tbList at the passed in index to the passed in value.

Parameters:
newID - New value in the tbList at the specified location
y - Index in the tbList to modify

setSideLeft

public void setSideLeft()
Sets the TileBin to the left side of the grid.

See Also:
tbSide

setSideRight

public void setSideRight()
Sets the TileBin ot the right side of the grid.

See Also:
tbSide