|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Canvas
ks.common.view.Container
The container provides the environment within which all Solitare plug-ins execute.
The container is initialized with a Solitare Plug-in, and manages the interaction between the user and the game. All mouse events pass through the container, and are delivered to the appropriate widget based upon the (x,y) point of the mouse event.
All Undo requests (right mouse clicks) are first identified by the container, and are passed along to the solitaire game.
The container manages any Widgets that are being dragged on the screen. Typically,
these are CardView
widgets, but there is no limitation on this, and
conceivably any widget could be dragged. The container also manages the Widget that
initiated the drag event, called the dragSource
.
Note: Container must be a java.awt.Component because many of the low-level image routines expect an ImageObserver, satisfied by java.awt.Canvas. In addition, this class implements key methods enabling events to be interpreted and delivered to the Solitaire subclass being viewed.
Note: Since V1.6, the container also is capable of remembering the source widget
from which a drag originates, if the Controller invokes setDragSource
(Widget w)
accordingly. This source widget can then be asked to
returnWidget(Widget w)
a widget extracted from the source as
part of the dragging procedure.
Note: Since V2.2, there is additional logic to enable 'shared state' model elements to exist. That is, there is some server-side state that stores information about shared state that is only accessed
Field Summary |
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 | |
Container()
Creates an empty container with no widgets. |
Method Summary | |
void |
addUser(java.lang.String newUser)
Containers now need to know when users are entering, exiting |
boolean |
addWidget(Widget w)
Adds the widget to the Container. |
void |
announce()
Announces to GameInterface (if one is assigned) our current Status. |
void |
forceNextHand()
Move on to play the next hand for this game. |
Widget |
getActiveDraggingObject()
Returns the object being dragged. |
RectangleHierarchy |
getBackgroundImage()
Return the background RectangleHierarchy representing the non-widget areas in container. |
CardImages |
getCardImages()
Return the card images associated with this container. |
java.lang.String |
getCurrentUser()
Return the current user for this container. |
java.awt.Point |
getDraggingAnchor()
Return the offset within the dragging Widget for where the mouse was initially clicked. |
Widget |
getDragSource()
Gets the source widget from which a drag originated. |
IGameInterface |
getGameInterface()
Expose entity to whom container speaks. |
java.awt.Point |
getLastDrag()
Returns the last Drag point, or null if no drag is in process. |
java.util.Enumeration |
getModelElements()
Return the Model elements associated with the container's game as an Enumeration. |
static Widget |
getNothingBeingDragged()
Returns a 'sentinel' object that represents the fact that nothing is being dragged. |
Status |
getStatus()
Return the current status of the game being played. |
RectangleHierarchyVisitor |
getVisitor()
Return visitor being used to draw background skin. |
Widget |
getWidget(java.awt.event.MouseEvent me)
Return the widget (or null if none exist) that includes given mouse location. |
java.util.Enumeration |
getWidgets()
Return the View Widgets in the container as an Enumeration. |
boolean |
hasWon()
Check with plugin to see if the game has been won. |
void |
initialize(Solitaire myGame)
Initialize using a Solitaire game that was already constructed elsewhere. |
Widget |
intersectsWidget(java.awt.Rectangle r)
Returns the first Widget that intersects the given Rectangle (or null if none exist). |
boolean |
isActive()
Determine whether the Container is active and ready to process events. |
void |
leaveTable()
When a player wishes to leave the entire table. |
void |
paint(java.awt.Graphics g)
Force all model elements to be redrawn. |
void |
processMessage(Message msg)
Ability to process messages from the server is necessary for some versions of solitaire (like multi-solitaire). |
void |
processMouseEvent(java.awt.event.MouseEvent me)
Container must send this mouse event to the appropriate controller for processing. |
void |
recalculateBackground()
If container is resized, or its bounds are otherwise manipulated, this method recalculates the background RectangleHierarchy. |
void |
refreshAll()
Refresh widgets in container. |
void |
refreshWidgets()
Refresh widgets in container. |
void |
refreshWidgets(java.awt.Rectangle clip)
Refresh widgets in container. |
void |
releaseDraggingObject()
Releases the object being dragged by the container. |
void |
removeAllWidgets()
Remove all widgets from this container to start fresh. |
void |
removeUser(java.lang.String exitingUser)
Containers now need to know when users are entering, exiting |
void |
repaintAll()
Force a repaint of all Widgets, whether they are dirty or not. |
void |
repaintAll(java.awt.Rectangle clip)
Force a repaint of all Widgets, whether they are dirty or not. |
void |
repaintBackground()
Refresh the background screen which is a hierarchy of rectangles to be filled using background image. |
void |
repaintBackground(java.awt.Rectangle clip)
Refresh the background screen which is a hierarchy of rectangles to be filled using background image. |
void |
repaintWidgets(java.awt.Rectangle clip)
Force a repaint of all Widgets that intersect given clip region, whether they are dirty or not. |
void |
resetHand()
Reset existing game to redeal cards exactly as it was started. |
void |
resetStatus()
Clears all stats for this container |
void |
setActive(boolean newActive)
Activate the container (or deactivate it) to be able to process events. |
void |
setActiveDraggingObject(Widget newActiveDraggingObject,
java.awt.event.MouseEvent me)
Specifies the Widget being dragged. |
void |
setCurrentUser(java.lang.String user)
Tell Container who the current user player is |
void |
setDragSource(Widget newDragSource)
Sets the source widget from which a drag originated. |
void |
setGameInterface(IGameInterface gi)
Container must speak to an outside entity about game results. |
void |
setLastDrag(java.awt.Point p)
Tell container of last drag point (or null if ending a drag). |
void |
setMouseAdapter(java.awt.event.MouseAdapter ma)
Alters the way in which this Container reacts to MouseEvents. |
void |
setMouseMotionAdapter(java.awt.event.MouseMotionAdapter ma)
Alters the way in which this Container reacts to MouseMotion events. |
void |
setUndoAdapter(UndoAdapter ua)
Alters the way in which this Container reacts to UndoRequested |
void |
setVisitor(RectangleHierarchyVisitor v)
Sets the entity responsible for updating background skin of the container |
java.util.Iterator |
users()
Containers now are able to expose the users playing on the table. |
void |
wonGame()
The game has been won. |
Methods inherited from class java.awt.Canvas |
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Container()
Method Detail |
public void setCurrentUser(java.lang.String user)
user
- public java.lang.String getCurrentUser()
public boolean addWidget(Widget w)
This method can only be called after the Container has been initialized. The Widget is added to the set of widgets, and a MouseManager is assigned, if one is not already in place.
The Boundary of the Widget is then added to the backgroundImage to maintain the background real estate that needs its own painting routines.
If the proposed widget intersects with an existing widget, a message is sent to stderr.
w
- ks.common.view.Widget
public void announce()
public void forceNextHand()
Note: This is directly invoked by the user and signifies that they have given up for the given hand. If the user wins, call wonGame() instead.
public Widget getActiveDraggingObject()
getNothingBeingDragged() object is the value
of this method.
- Returns:
- ks.common.view.Widget
public RectangleHierarchy getBackgroundImage()
public java.awt.Point getDraggingAnchor()
public java.util.Iterator users()
public void removeUser(java.lang.String exitingUser)
exitingUser
- public void addUser(java.lang.String newUser)
newUser
- public Widget getDragSource()
Note: dragSource must be manually set by the controller of the widget since there is no obvious way for the container to know the object for which the drag originates.
public java.awt.Point getLastDrag()
This class variable is kept up-to-date by the various MouseManagers associated with each widget, as well as the MouseManagers with the Container itself that represents the background.
If this ever returns null, it means nothing is being dragged.
public static Widget getNothingBeingDragged()
public Status getStatus()
This may include: score, number of cards left, number of wins, number of undo, number of times new game was pressed, number of times the game was reset.
public RectangleHierarchyVisitor getVisitor()
public Widget getWidget(java.awt.event.MouseEvent me)
me
- java.awt.event.MouseEvent
public java.util.Enumeration getWidgets()
public boolean hasWon()
hasWon
.public void initialize(Solitaire myGame)
myGame
- the plugin to be instantiated and activated.After this method, the Container is active.
public Widget intersectsWidget(java.awt.Rectangle r)
r
- java.awt.Rectangle
public boolean isActive()
Note: When a container is active, all mouse events are processed.
public void leaveTable()
public void paint(java.awt.Graphics g)
Paint is an imperative command that forces the Container to draw itself.
The dragging of objects is managed separately.
g
- java.awt.Graphicspublic void processMouseEvent(java.awt.event.MouseEvent me)
If the container is inactive, no action is taken. The following mouse events can be global and do not apply to a specific Widget (not even handled yet):
MouseExited
MouseEntered
me
- java.awt.event.MouseEventpublic void recalculateBackground()
public void refreshAll()
public void refreshWidgets()
public void refreshWidgets(java.awt.Rectangle clip)
Clip to the specified rectangle. Clip is unaffected by this method.
clip
- java.awt.Rectanglepublic void releaseDraggingObject()
Note: this will also reset the dragSource and lastDrag to null.
public void removeAllWidgets()
public void repaintAll()
This method repaints background also.
public void repaintAll(java.awt.Rectangle clip)
Restrict drawing to the clip rectangle. [clip is unaffected by this invocation.]
This method avoids the default fillRect over the whole background (which flickers the screen).
clip
- java.awt.Rectanglepublic void repaintBackground()
public void repaintBackground(java.awt.Rectangle clip)
Restrict to the clip Rectangular region. [clip is unaffected by this invocation.]
clip
- java.awt.Rectanglepublic void repaintWidgets(java.awt.Rectangle clip)
Restrict drawing to the clip rectangle [clip is unaffected].
This method avoids the default fillRect over the whole background (which flickers the screen).
clip
- java.awt.Rectanglepublic void resetHand()
public void resetStatus()
public void setActive(boolean newActive)
newActive
- booleanpublic void setActiveDraggingObject(Widget newActiveDraggingObject, java.awt.event.MouseEvent me)
We also take as input the MouseEvent associated with this dragging object; this enables us to calculate the anchor.
Take some care if MouseEvent is null.
newActiveDraggingObject
- ks.common.view.Widgetme
- MouseEventpublic void setDragSource(Widget newDragSource)
Note: dragSource must be manually set by the controller of the widget since there is no obvious way for the container to know the object for which the drag originates.
Passing in null simply means that the drag is released.
newDragSource
- ks.common.view.Widgetpublic void setGameInterface(IGameInterface gi)
gi
- ks.games.GameInterfacepublic IGameInterface getGameInterface()
public void setLastDrag(java.awt.Point p)
p
- java.awt.Pointpublic void setMouseAdapter(java.awt.event.MouseAdapter ma)
ma
- java.awt.event.MouseAdapterpublic void setMouseMotionAdapter(java.awt.event.MouseMotionAdapter ma)
ma
- java.awt.event.MouseMotionAdapterpublic void setUndoAdapter(UndoAdapter ua)
ua
- UndoAdapterpublic void setVisitor(RectangleHierarchyVisitor v)
v
- the RectangleHierarchyVisitor to be used.public void wonGame()
public java.util.Enumeration getModelElements()
This method is not used during play. It is being provided to anticipate the need of a sophisticated Beta-testing GUI application that can inspect and manipulate the state of a solitaire plug-in.
public CardImages getCardImages()
public void processMessage(Message msg)
msg
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |