Class UserInteraction

java.lang.Object
  extended by javax.swing.event.MouseInputAdapter
      extended by UserInteraction
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class UserInteraction
extends javax.swing.event.MouseInputAdapter

This is a MouseInputAdapter for the CLIP application. It handles the majority of the input from the mouse including interactions with the Grid, TileBin, Split Pane Divider, and MiniMap.


Field Summary
(package private)  java.lang.String addBlankArea
          The area a user created the context menu in
(package private)  java.awt.Point addBlankLoc
          A point in the grid where a blank tile would be added through the context menu
(package private)  javax.swing.JMenuItem addBlankMenuItem
          Add Blank Tile option in the context menu
(package private)  javax.swing.JPopupMenu contextMenu
          The context menu
(package private)  int curTile
          ID of the current tile being dragged
(package private)  java.awt.Point DefaultTileLocation
          The default location of tiles
(package private)  java.awt.Dimension DefaultTileSize
          The default size of tiles
(package private)  int dragButton
          The current mouse button being used to drag the grid (or tilebin)
(package private)  javax.swing.JLabel draggedTile
          A Label that holds an image which is used as the dragged tile for any tile
(package private)  boolean dragging
          true if a tile is currently being dragged
(package private)  javax.swing.JMenuItem editBlankMenuItem
          Edit Blank Tile option in the context menu
(package private)  int editTileID
          Tile ID of the blank tile the user created the context menu on
(package private)  javax.swing.JCheckBoxMenuItem gridLinesMenuItem
          Gridlines option in the context menu
(package private)  boolean gridScrolling
          true if the user is dragging the grid (or tilebin)
(package private)  javax.swing.JMenu helpMenu
          Help menu in the context menu
(package private)  javax.swing.JMenuItem helpSystemMenuItem
          The Help System Menu Item
(package private)  boolean mapScrolling
          true if the user is dragging in the MiniMap
(package private)  javax.swing.JCheckBoxMenuItem minimapMenuItem
          MiniMap option in the context menu
(package private)  int mouseLastX
          Last X position of the mouse
(package private)  int mouseLastY
          Last Y position of the mouse
(package private)  java.awt.Point mouseOffset
          Distance from the mouse to the upper left corner of the dragged tile
(package private)  Record moveLog
          The record object responsible for recording user moves and actions
(package private)  int oldNumTilesWide
          Tile width of the TileBin before the user moved the divider bar
(package private)  CLIPFrame parentFrame
          The frame that the application runs in
(package private)  int popupButton
          Button used to trigger popup menus
(package private)  boolean popupOnClick
          true if the trigger for the context menu has occured
(package private)  javax.swing.JMenuItem setInstructionsMenuItem
          Set Instructions option in the context menu
(package private)  javax.swing.ButtonGroup tbPositionButtonGroup
          ButtonGroup for the TileBin position options
(package private)  Grid theGrid
          The Grid that uses this mouse adapter
(package private)  javax.swing.JPanel theMainPanel
          The panel that holds the Grid and TileBin
(package private)  MiniMapPanel theMiniMap
          The MiniMapPanel that uses this mouse adapter
(package private)  TileBin theTileBin
          The TileBin that uses this mouse adapter
(package private)  javax.swing.JRadioButtonMenuItem tileBinLeftMenuItem
          Set TileBin on Left option in the context menu
(package private)  javax.swing.JMenu tileBinPositionMenu
          TileBin position menu in the context menu
(package private)  javax.swing.JRadioButtonMenuItem tileBinRightMenuItem
          Set TileBin on Right option in the context menu
(package private)  javax.swing.ImageIcon tileIcon
          Image currently attached to the draggedTile
 
Constructor Summary
UserInteraction(CLIPFrame parent)
          The constructor initializes fields to default values, sets up the dragged tile and creates the context menu.
 
Method Summary
 void beginTileArrangement()
          Creates a new Record object and starts recording.
 void createContextMenu()
          Creates the context menu, attaches ActionListeners to each option, and defines the events that occur when each item in the menu is activated.
private  void dropTileInGrid(java.awt.Point tileCenter, java.awt.event.MouseEvent e)
          Handles dropping a tile in the Grid from the Grid or from the TileBin.
private  void dropTileInTileBin(java.awt.Point tileCenter, java.awt.event.MouseEvent e)
          Handles dropping a tile in the TileBin from the TileBin or from the Grid.
private  java.awt.Point getAbsoluteLoc(java.awt.event.MouseEvent e)
          Calculates and returns the absolute coordinates of the mouse relateive to theMainPanel
private  int getCurTile(java.awt.event.MouseEvent e)
          Determines if a the MouseEvent occured over a tile in the Grid or TileBin and returns that tile's ID.
private  java.awt.Rectangle getPanelBounds(javax.swing.JPanel panel)
          Returns the bounds of the passed in panel within theMainPanel
private  java.awt.Point getRelativeLoc(java.awt.Point p, javax.swing.JPanel panel)
          Calculates the position of the passed in point relative to the visible portion of the passed in panel.
 void initialize(javax.swing.JPanel mainPanel, Grid grid, TileBin tileBin)
          Sets the variables for the theMainPanel, Grid, and TileBin.
 boolean inPlaybackMode()
          Returns true if the system is in Playback Mode.
 boolean inTileArrangementMode()
          Returns true if the system is in Tile Arrangement Mode.
 void mouseClicked(java.awt.event.MouseEvent e)
          Event that fires on user mouse click.
 void mouseDragged(java.awt.event.MouseEvent e)
          This event continually fires when the user drags the mouse.
 void mouseEntered(java.awt.event.MouseEvent e)
          This event fires when the user enters an area.
 void mouseExited(java.awt.event.MouseEvent e)
          This event fires when the user leaves an area.
 void mouseMoved(java.awt.event.MouseEvent e)
          This event fires when the user moves the mouse.
 void mousePressed(java.awt.event.MouseEvent e)
          This event fires when the user presses a mouse button.
 void mouseReleased(java.awt.event.MouseEvent e)
          This event fires when the user releases a mouse button.
private  boolean pointInRectangle(java.awt.Rectangle rect, java.awt.Point p)
          Takes a Point and Rectangle and returns true if the point is in the rectangle.
 void setDraggedTileSize(java.awt.Dimension newSize)
          Sets the size of the dragged tile label.
 void setMiniMap(MiniMapPanel mm)
          Sets the MiniMapPanel that the mouse adapter is attached to.
private  void showPopup(java.awt.event.MouseEvent e, java.lang.String locName)
          This handles the enabling and disabling of context menu options and then displays the context menu.
private  void startDraggingTile(java.awt.event.MouseEvent e)
          Starts dragging the curTile at the specified MouseEvent
private  void startGridDragging(java.awt.event.MouseEvent e)
          Starts dragging the grid.
private  void stopDraggingGrid()
          Stops dragging the grid.
private  void stopDraggingTile()
          Stops tile dragging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parentFrame

CLIPFrame parentFrame
The frame that the application runs in


theMainPanel

javax.swing.JPanel theMainPanel
The panel that holds the Grid and TileBin


theGrid

Grid theGrid
The Grid that uses this mouse adapter


theTileBin

TileBin theTileBin
The TileBin that uses this mouse adapter


theMiniMap

MiniMapPanel theMiniMap
The MiniMapPanel that uses this mouse adapter


DefaultTileSize

final java.awt.Dimension DefaultTileSize
The default size of tiles


DefaultTileLocation

final java.awt.Point DefaultTileLocation
The default location of tiles


curTile

int curTile
ID of the current tile being dragged


dragging

boolean dragging
true if a tile is currently being dragged


mouseOffset

java.awt.Point mouseOffset
Distance from the mouse to the upper left corner of the dragged tile


draggedTile

javax.swing.JLabel draggedTile
A Label that holds an image which is used as the dragged tile for any tile


tileIcon

javax.swing.ImageIcon tileIcon
Image currently attached to the draggedTile


mouseLastX

int mouseLastX
Last X position of the mouse


mouseLastY

int mouseLastY
Last Y position of the mouse


dragButton

int dragButton
The current mouse button being used to drag the grid (or tilebin)


gridScrolling

boolean gridScrolling
true if the user is dragging the grid (or tilebin)


mapScrolling

boolean mapScrolling
true if the user is dragging in the MiniMap


moveLog

Record moveLog
The record object responsible for recording user moves and actions


contextMenu

javax.swing.JPopupMenu contextMenu
The context menu


gridLinesMenuItem

javax.swing.JCheckBoxMenuItem gridLinesMenuItem
Gridlines option in the context menu


addBlankMenuItem

javax.swing.JMenuItem addBlankMenuItem
Add Blank Tile option in the context menu


editBlankMenuItem

javax.swing.JMenuItem editBlankMenuItem
Edit Blank Tile option in the context menu


tileBinPositionMenu

javax.swing.JMenu tileBinPositionMenu
TileBin position menu in the context menu


tileBinLeftMenuItem

javax.swing.JRadioButtonMenuItem tileBinLeftMenuItem
Set TileBin on Left option in the context menu


tileBinRightMenuItem

javax.swing.JRadioButtonMenuItem tileBinRightMenuItem
Set TileBin on Right option in the context menu


tbPositionButtonGroup

javax.swing.ButtonGroup tbPositionButtonGroup
ButtonGroup for the TileBin position options


helpMenu

javax.swing.JMenu helpMenu
Help menu in the context menu


setInstructionsMenuItem

javax.swing.JMenuItem setInstructionsMenuItem
Set Instructions option in the context menu


helpSystemMenuItem

javax.swing.JMenuItem helpSystemMenuItem
The Help System Menu Item


minimapMenuItem

javax.swing.JCheckBoxMenuItem minimapMenuItem
MiniMap option in the context menu


popupOnClick

boolean popupOnClick
true if the trigger for the context menu has occured


popupButton

int popupButton
Button used to trigger popup menus


editTileID

int editTileID
Tile ID of the blank tile the user created the context menu on


oldNumTilesWide

int oldNumTilesWide
Tile width of the TileBin before the user moved the divider bar


addBlankLoc

java.awt.Point addBlankLoc
A point in the grid where a blank tile would be added through the context menu


addBlankArea

java.lang.String addBlankArea
The area a user created the context menu in

Constructor Detail

UserInteraction

public UserInteraction(CLIPFrame parent)
The constructor initializes fields to default values, sets up the dragged tile and creates the context menu.

Parameters:
parent - Frame that the application runs in
Method Detail

initialize

public void initialize(javax.swing.JPanel mainPanel,
                       Grid grid,
                       TileBin tileBin)
Sets the variables for the theMainPanel, Grid, and TileBin. Must be called after those objects have been created. It also adds the dragged tile and the insertion line to theMainPanel.

Parameters:
mainPanel - The panel that holds the Grid and the TileBin
grid - The Grid being used
tileBin - The TileBin being used

beginTileArrangement

public void beginTileArrangement()
Creates a new Record object and starts recording.

See Also:
Record

setDraggedTileSize

public void setDraggedTileSize(java.awt.Dimension newSize)
Sets the size of the dragged tile label.

Parameters:
newSize - New size for the dragged tile (should match tile size of set)
See Also:
draggedTile

setMiniMap

public void setMiniMap(MiniMapPanel mm)
Sets the MiniMapPanel that the mouse adapter is attached to.

Parameters:
mm - The MiniMapPanel that the listener is attached to

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Event that fires on user mouse click. This handles showing the popup menu and showing the edit blank tile dialog if the user double clicked on a blank tile.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Overrides:
mouseClicked in class javax.swing.event.MouseInputAdapter
Parameters:
e - The mouse event that fired this method

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
This event fires when the user presses a mouse button. It handles initiating tile dragging if a tile was clicked on or grid dragging if a tile was not found at the click position. It also handles clicks in the MiniMapPanel. If the user clicks on the split pane divider, it sets the oldNumTilesWide variable to the current tile width of the TileBin.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class javax.swing.event.MouseInputAdapter
Parameters:
e - The mouse event that fired this method
See Also:
getCurTile(MouseEvent), startDraggingTile(MouseEvent), startGridDragging(MouseEvent)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
This event fires when the user releases a mouse button. It handles the dropping of tiles and tile bin width changes. It also ends tile dragging, grid dragging, and minimap dragging if needed

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class javax.swing.event.MouseInputAdapter
Parameters:
e - Mouse event that fired this method
See Also:
dropTileInGrid(Point, MouseEvent), dropTileInTileBin(Point, MouseEvent), stopDraggingTile(), stopDraggingGrid()

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
This event fires when the user enters an area. It is unused by the CLIP application.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Overrides:
mouseEntered in class javax.swing.event.MouseInputAdapter
Parameters:
e - The mouse event that fired this method

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
This event fires when the user leaves an area. It is unused by the CLIP application.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class javax.swing.event.MouseInputAdapter
Parameters:
e - The mouse event that fired this method

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
This event continually fires when the user drags the mouse. It is used when the user is dragging a tile, dragging the Grid, dragging the TileBin, and dragging the MiniMap.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class javax.swing.event.MouseInputAdapter
Parameters:
e - The mouse event that fired this method

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
This event fires when the user moves the mouse. It is unused by the CLIP application.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Overrides:
mouseMoved in class javax.swing.event.MouseInputAdapter
Parameters:
e - The mouse event that fired this method

getAbsoluteLoc

private java.awt.Point getAbsoluteLoc(java.awt.event.MouseEvent e)
Calculates and returns the absolute coordinates of the mouse relateive to theMainPanel

Parameters:
e - Mouse event to get coordinates from
Returns:
A Point representing the location of the mouse event relative to theMainPanel
See Also:
UserInterface.theMainPanel

getRelativeLoc

private java.awt.Point getRelativeLoc(java.awt.Point p,
                                      javax.swing.JPanel panel)
Calculates the position of the passed in point relative to the visible portion of the passed in panel.

Parameters:
p - Point to calculate the position of
panel - Component that the returned point will be relative to
Returns:
A Point relative to the visible portion of the panel.

getPanelBounds

private java.awt.Rectangle getPanelBounds(javax.swing.JPanel panel)
Returns the bounds of the passed in panel within theMainPanel

Parameters:
panel - Panel to get the bounds of
Returns:
The bounds of the panel within theMainPanel
See Also:
UserInterface.theMainPanel

pointInRectangle

private boolean pointInRectangle(java.awt.Rectangle rect,
                                 java.awt.Point p)
Takes a Point and Rectangle and returns true if the point is in the rectangle.

Parameters:
rect - Rectangle to find if the point is within
p - Point to determine if located in the rectangle
Returns:
true if the point is in the rectangle; false otherwise.

inTileArrangementMode

public boolean inTileArrangementMode()
Returns true if the system is in Tile Arrangement Mode.

Returns:
true if the system is in Tile Arrangement Mode; false otherwise.
See Also:
CLIPFrame.Mode

inPlaybackMode

public boolean inPlaybackMode()
Returns true if the system is in Playback Mode.

Returns:
true if the system is in Playback Mode; false otherwise.
See Also:
CLIPFrame.Mode

getCurTile

private int getCurTile(java.awt.event.MouseEvent e)
Determines if a the MouseEvent occured over a tile in the Grid or TileBin and returns that tile's ID.

Parameters:
e - MouseEvent to check for tile at
Returns:
ID of the tile that the mouse event occured over. Returns 0 if no tile was found.

startDraggingTile

private void startDraggingTile(java.awt.event.MouseEvent e)
Starts dragging the curTile at the specified MouseEvent

Parameters:
e -
See Also:
draggedTile

stopDraggingTile

private void stopDraggingTile()
Stops tile dragging.


startGridDragging

private void startGridDragging(java.awt.event.MouseEvent e)
Starts dragging the grid.

Parameters:
e - MouseEvent where the dragging began at

stopDraggingGrid

private void stopDraggingGrid()
Stops dragging the grid.


dropTileInGrid

private void dropTileInGrid(java.awt.Point tileCenter,
                            java.awt.event.MouseEvent e)
Handles dropping a tile in the Grid from the Grid or from the TileBin. It is also responsible for recording the move.

Parameters:
tileCenter - Center position of the tile to drop
e - MouseEvent responsible for dropping the tile
See Also:
dropTileInTileBin(Point, MouseEvent)

dropTileInTileBin

private void dropTileInTileBin(java.awt.Point tileCenter,
                               java.awt.event.MouseEvent e)
Handles dropping a tile in the TileBin from the TileBin or from the Grid. It is also responsible for recording the move.

Parameters:
tileCenter - Center position of the tile to drop
e - MouseEvent responsible for dropping the tile
See Also:
dropTileInGrid(Point, MouseEvent)

showPopup

private void showPopup(java.awt.event.MouseEvent e,
                       java.lang.String locName)
This handles the enabling and disabling of context menu options and then displays the context menu.

Parameters:
e - MouseEvent that called this function.
locName - Name of the location that the MouseEvent occured at. Should be set to either Grid.GridName or TileBin.TileBinName.

createContextMenu

public void createContextMenu()
Creates the context menu, attaches ActionListeners to each option, and defines the events that occur when each item in the menu is activated.