|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
GuiCardProxy
public class GuiCardProxy
The GUI component that represents a card in the compsci 108
Solitaire package. A GuiCardProxy object is a decorator for a "real"
card in that it implements the IGuiCard interface
but also wraps an IGuiCard object, e.g., as set
via this class's setCard method. An object of
this class listen's for mouse events and reports a click as
an event that holds both the card clicked (via it's id) and
the pile the card is in (from the setPile method).
A click generates a Solitaire-semantic event, not a Java/awt
mouseclick event. Listeners to these semantic events receive every
such event, adding a listener is a class-wide/static process using
the addSolitaireListener method. Although all events are
received by each listener, the events encode the card (and the pile)
clicked on when Proxy objects are used properly.
To use a GuiCardProxy for a "real" card in a game,
typically the GuiPileView class does the work. Most
programs will use that class rather than this class. Note that
the rank/suit constructor for this class is private,
GuiCardProxy objects are typically accessed via
the static getProxy method. However, "blank" cards
that report a string when clicked (as opposed to an ID
that conforms to the contract in IGuiCard)
can be constructed directly.
Proxy objects that represent real cards (not blank cards) can
be toggled via the toggleSelected method which
grays-out a card (or sets it to not-grayed-out). Alternatively,
the setSelected method can set a proxy card to display
as gray or not rather than toggling the proxy's state.
See GuiPileView for more information and the sample
Solitaire game in GuiDemo (the latter is not in
this package).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JComponent |
|---|
TOOL_TIP_TEXT_KEY, 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 IGuiCard |
|---|
CLUBS, DIAMONDS, HEARTS, rankPrefixes, SPADES, suitPrefixes |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
GuiCardProxy(java.lang.String s)
Construct a blank-card, e.g., as used on a free-cell pile when there's nothing there. |
|
| Method Summary | |
|---|---|
static void |
addSolitaireListener(ISolitaireListener isl)
Add a listener for every SolitaireEvent generated when some card is clicked. |
void |
fireSolitaireEvent(SolitaireEvent event)
Fire a solitaire event to all listeners. |
java.lang.String |
getCardId()
Return the id of the card this wraps, or the string of a blank card. |
static GuiCardProxy |
getProxy(java.lang.String id)
Return the GuiCardProxy object for a specific
card id --- where the id conforms to the contract
described in IGuiCard |
IGuiCard |
getWrappedCard()
Return the wrapped IGuiCard for this
proxy. |
boolean |
isFaceUp()
Reports state of wrapped card, or true if there is no wrapped card. |
void |
mouseClicked(java.awt.event.MouseEvent e)
Listen for mouse clicks and report them to listeners as semantic events. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Required by MouseListener interface, currently
does nothing. |
void |
mouseExited(java.awt.event.MouseEvent e)
Required by MouseListener interface, currently
does nothing. |
void |
mousePressed(java.awt.event.MouseEvent e)
Required by MouseListener interface, currently
does nothing. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Required by MouseListener interface, currently
does nothing. |
void |
paintComponent(java.awt.Graphics g)
Paint appropriate image (card, grayed-image, blank, or back) when painting is needed, e.g., when game is displayed or cards moved. |
static void |
removeSolitaireListener(ISolitaireListener isl)
Remove a listener from the list of Proxy listeners |
void |
setCard(IGuiCard card)
Set the "real" card for which this card is a Gui/proxy. |
void |
setCoordinates(int x,
int y,
int width,
int height)
Set coordinates for the bounds of this card. |
void |
setPile(GuiPileView pile)
Set the pile in which the card wrapped by this proxy is stored. |
void |
setSelected(boolean selected)
Set selected state (true means gray image). |
void |
toggleSelected()
Change state of selected/gray, e.g., if false, make it true and vice versa. |
java.lang.String |
toString()
|
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, 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, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
|---|
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate |
| Methods inherited from class java.awt.Component |
|---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GuiCardProxy(java.lang.String s)
CardImageFactory) and
reports the string by which it's constructed when it's clicked on.
Proxy cards constructed this way aren't displayed as gray when
the toggleSelected/setSelected methods are called.
s - is the string reported as this proxy's id| Method Detail |
|---|
public static void addSolitaireListener(ISolitaireListener isl)
isl - is the listener addedpublic static void removeSolitaireListener(ISolitaireListener isl)
isl - is the removed listener (previously added)public void fireSolitaireEvent(SolitaireEvent event)
event - is the event sent to all listeners (via there
processSolitaireEvent method).public static GuiCardProxy getProxy(java.lang.String id)
GuiCardProxy object for a specific
card id --- where the id conforms to the contract
described in IGuiCard
id - is the card id
IGuiCardpublic java.lang.String toString()
toString in class java.awt.Componentpublic void setPile(GuiPileView pile)
IGuiPileModel)
in which the wrapped card is stored.
Failure to set the pile appropriately can result in incorrect semantic events being generated when a card is clicked.
pile - is the pile/view in which this proxy's wrapped
IGuiCard card can be found.public void setCard(IGuiCard card)
card - is the card wrapped by this proxypublic java.lang.String getCardId()
getCardId in interface IGuiCardpublic IGuiCard getWrappedCard()
IGuiCard for this
proxy.
public void setCoordinates(int x,
int y,
int width,
int height)
GuiPileView should call this method
directly unless you really know what you're doing
when you call it. This method calls setBounds
so the card is likely redrawn/repainted.
x - coordinate of upper-left of card imagey - coordinate of upper-left of card imagewidth - of card image shownheight - of card image shownpublic void paintComponent(java.awt.Graphics g)
paintComponent in class javax.swing.JComponentpublic boolean isFaceUp()
isFaceUp in interface IGuiCardpublic void setSelected(boolean selected)
selected - determines if card is gray, true means gray.public void toggleSelected()
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked in interface java.awt.event.MouseListenerpublic void mousePressed(java.awt.event.MouseEvent e)
MouseListener interface, currently
does nothing.
mousePressed in interface java.awt.event.MouseListenerpublic void mouseReleased(java.awt.event.MouseEvent e)
MouseListener interface, currently
does nothing.
mouseReleased in interface java.awt.event.MouseListenerpublic void mouseEntered(java.awt.event.MouseEvent e)
MouseListener interface, currently
does nothing.
mouseEntered in interface java.awt.event.MouseListenerpublic void mouseExited(java.awt.event.MouseEvent e)
MouseListener interface, currently
does nothing.
mouseExited in interface java.awt.event.MouseListener
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||