|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.event.MouseInputAdapter
UserInteraction
public class UserInteraction
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 |
|---|
CLIPFrame parentFrame
javax.swing.JPanel theMainPanel
Grid and TileBin
Grid theGrid
Grid that uses this mouse adapter
TileBin theTileBin
TileBin that uses this mouse adapter
MiniMapPanel theMiniMap
MiniMapPanel that uses this mouse adapter
final java.awt.Dimension DefaultTileSize
final java.awt.Point DefaultTileLocation
int curTile
boolean dragging
true if a tile is currently being dragged
java.awt.Point mouseOffset
javax.swing.JLabel draggedTile
javax.swing.ImageIcon tileIcon
draggedTile
int mouseLastX
int mouseLastY
int dragButton
boolean gridScrolling
true if the user is dragging the grid (or tilebin)
boolean mapScrolling
true if the user is dragging in the MiniMap
Record moveLog
javax.swing.JPopupMenu contextMenu
javax.swing.JCheckBoxMenuItem gridLinesMenuItem
javax.swing.JMenuItem addBlankMenuItem
javax.swing.JMenuItem editBlankMenuItem
javax.swing.JMenu tileBinPositionMenu
javax.swing.JRadioButtonMenuItem tileBinLeftMenuItem
javax.swing.JRadioButtonMenuItem tileBinRightMenuItem
javax.swing.ButtonGroup tbPositionButtonGroup
javax.swing.JMenu helpMenu
javax.swing.JMenuItem setInstructionsMenuItem
javax.swing.JMenuItem helpSystemMenuItem
javax.swing.JCheckBoxMenuItem minimapMenuItem
boolean popupOnClick
true if the trigger for the context menu has occured
int popupButton
int editTileID
int oldNumTilesWide
java.awt.Point addBlankLoc
java.lang.String addBlankArea
| Constructor Detail |
|---|
public UserInteraction(CLIPFrame parent)
parent - Frame that the application runs in| Method Detail |
|---|
public void initialize(javax.swing.JPanel mainPanel,
Grid grid,
TileBin tileBin)
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.
mainPanel - The panel that holds the Grid and the TileBingrid - The Grid being usedtileBin - The TileBin being usedpublic void beginTileArrangement()
Record object and starts recording.
Recordpublic void setDraggedTileSize(java.awt.Dimension newSize)
newSize - New size for the dragged tile (should match tile size of set)draggedTilepublic void setMiniMap(MiniMapPanel mm)
MiniMapPanel that the
mouse adapter is attached to.
mm - The MiniMapPanel that the
listener is attached topublic void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked in interface java.awt.event.MouseListenermouseClicked in class javax.swing.event.MouseInputAdaptere - The mouse event that fired this methodpublic void mousePressed(java.awt.event.MouseEvent e)
MiniMapPanel. If the user
clicks on the split pane divider, it sets the oldNumTilesWide
variable to the current tile width of the TileBin.
mousePressed in interface java.awt.event.MouseListenermousePressed in class javax.swing.event.MouseInputAdaptere - The mouse event that fired this methodgetCurTile(MouseEvent),
startDraggingTile(MouseEvent),
startGridDragging(MouseEvent)public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased in interface java.awt.event.MouseListenermouseReleased in class javax.swing.event.MouseInputAdaptere - Mouse event that fired this methoddropTileInGrid(Point, MouseEvent),
dropTileInTileBin(Point, MouseEvent),
stopDraggingTile(),
stopDraggingGrid()public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered in interface java.awt.event.MouseListenermouseEntered in class javax.swing.event.MouseInputAdaptere - The mouse event that fired this methodpublic void mouseExited(java.awt.event.MouseEvent e)
mouseExited in interface java.awt.event.MouseListenermouseExited in class javax.swing.event.MouseInputAdaptere - The mouse event that fired this methodpublic void mouseDragged(java.awt.event.MouseEvent e)
Grid, dragging the TileBin, and dragging the
MiniMap.
mouseDragged in interface java.awt.event.MouseMotionListenermouseDragged in class javax.swing.event.MouseInputAdaptere - The mouse event that fired this methodpublic void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved in interface java.awt.event.MouseMotionListenermouseMoved in class javax.swing.event.MouseInputAdaptere - The mouse event that fired this methodprivate java.awt.Point getAbsoluteLoc(java.awt.event.MouseEvent e)
theMainPanel
e - Mouse event to get coordinates from
Point representing the location of the mouse
event relative to theMainPanelUserInterface.theMainPanel
private java.awt.Point getRelativeLoc(java.awt.Point p,
javax.swing.JPanel panel)
p - Point to calculate the position ofpanel - Component that the returned point will be relative to
Point relative to the visible portion
of the panel.private java.awt.Rectangle getPanelBounds(javax.swing.JPanel panel)
theMainPanel
panel - Panel to get the bounds of
UserInterface.theMainPanel
private boolean pointInRectangle(java.awt.Rectangle rect,
java.awt.Point p)
Point and Rectangle and
returns true if the point is in the rectangle.
rect - Rectangle to find if the point is withinp - Point to determine if located in the rectangle
true if the point is in the rectangle;
false otherwise.public boolean inTileArrangementMode()
true if the system is in
Tile Arrangement Mode.
true if the system
is in Tile Arrangement Mode;
false otherwise.CLIPFrame.Modepublic boolean inPlaybackMode()
true if the system is in
Playback Mode.
true if the system
is in Playback Mode;
false otherwise.CLIPFrame.Modeprivate int getCurTile(java.awt.event.MouseEvent e)
MouseEvent occured over
a tile in the Grid or TileBin and returns
that tile's ID.
e - MouseEvent to check for tile at
private void startDraggingTile(java.awt.event.MouseEvent e)
curTile at the
specified MouseEvent
e - draggedTileprivate void stopDraggingTile()
private void startGridDragging(java.awt.event.MouseEvent e)
e - MouseEvent where the dragging began atprivate void stopDraggingGrid()
private void dropTileInGrid(java.awt.Point tileCenter,
java.awt.event.MouseEvent e)
Grid from the Grid
or from the TileBin. It is also responsible for
recording the move.
tileCenter - Center position of the tile to drope - MouseEvent responsible for dropping the tiledropTileInTileBin(Point, MouseEvent)
private void dropTileInTileBin(java.awt.Point tileCenter,
java.awt.event.MouseEvent e)
TileBin from the
TileBin or from the Grid. It is also responsible
for recording the move.
tileCenter - Center position of the tile to drope - MouseEvent responsible for dropping the tiledropTileInGrid(Point, MouseEvent)
private void showPopup(java.awt.event.MouseEvent e,
java.lang.String locName)
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.public void createContextMenu()
ActionListeners
to each option, and defines the events that occur when each
item in the menu is activated.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||