ks.common.view
Class RowView

java.lang.Object
  extended byks.common.view.Widget
      extended byks.common.view.RowView
All Implemented Interfaces:
ElementListener
Direct Known Subclasses:
FanPileView

public class RowView
extends Widget
implements ElementListener

Represents a row of cards on the screen. Note: This defaults to a row of thirteen cards. If more cards are necessary, the RowView simply expands to show them all.

A RowView is based on a Column model element, because the only difference is the orientation on the screen. From this Column of cards, the first card drawn on the screen is determined by the method firstDrawn (which defaults to 0 but can be overridden by subclasses). The remaining cards in the column after this index value are all drawn. The method numCoveredCards() returns the number of covered cards in a RowView.

Since V1.6.10, a RowView can be justified LEFT or RIGHT. Put together with the direction, there are now four possibilities. For example, a LEFT oriented RowView could be flushed with the RIGHT edge of the Widget boundaries. TODO: WHEN EMPTY, DRAW BASED on JUSTIFICATION/DIRECTION


Field Summary
static int LEFT
          LEFT direction for the row.
static int RIGHT
          RIGHT direction for the row.
 
Constructor Summary
RowView(Column col)
          RowView constructor.
 
Method Summary
 CardView getCardViewForTopCard(java.awt.event.MouseEvent me)
          If the MouseEvent falls on the top card of this Column, remove the top card from the Model and return a CardView widget to manage the card as it is dragged on the screen.
 int getDirection()
          Gets the direction of the row (either LEFT or RIGHT)
 int getJustification()
          Gets the justification of the row (either flush LEFT or flush RIGHT)
 RowView getRowView(java.awt.event.MouseEvent me)
          If the MouseEvent falls within this row, return a Column of cards from the Model and return a RowView widget to manage these cards as they are dragged on the screen.
 void redraw()
          Redraw a row.
 boolean returnWidget(Widget w)
          Return the CardView widget's model element back onto the underlying Column.
 void setDirection(int newDirection)
          Sets the direction of the row (facing LEFT or RIGHT).
 void setJustification(int newJustification)
          Sets the justification of the row (flush LEFT or flush RIGHT).
 
Methods inherited from class ks.common.view.Widget
getBounds, getCardImages, getContainer, getHeight, getImage, getModelElement, getMouseManager, getName, getWidth, getX, getXY, getY, inBounds, isDirty, modelChanged, paint, paint, paint, refresh, refresh, setBounds, setBounds, setContainer, setDirty, setHeight, setImage, setMouseAdapter, setMouseManager, setMouseMotionAdapter, setName, setUndoAdapter, setWidth, setX, setXY, setY, toString, translate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ks.common.model.ElementListener
modelChanged
 

Field Detail

LEFT

public static final int LEFT
LEFT direction for the row.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
RIGHT direction for the row.

See Also:
Constant Field Values
Constructor Detail

RowView

public RowView(Column col)
RowView constructor.

Method Detail

getCardViewForTopCard

public CardView getCardViewForTopCard(java.awt.event.MouseEvent me)
If the MouseEvent falls on the top card of this Column, remove the top card from the Model and return a CardView widget to manage the card as it is dragged on the screen.

Note: the Column Model will be altered by this method if the mouseEvent maps to the top card in the Column View.

Parameters:
me - java.awt.event.MouseEvent

getDirection

public int getDirection()
Gets the direction of the row (either LEFT or RIGHT)

Returns:
int

getJustification

public int getJustification()
Gets the justification of the row (either flush LEFT or flush RIGHT)

Returns:
int

getRowView

public RowView getRowView(java.awt.event.MouseEvent me)
If the MouseEvent falls within this row, return a Column of cards from the Model and return a RowView widget to manage these cards as they are dragged on the screen.

Note: the Column Model will be altered by this method.

Parameters:
me - java.awt.event.MouseEvent

redraw

public void redraw()
Redraw a row. Note that redraw must only be called Image.

This redraw algorithm uses the values returned by firstDrawn and lastDrawn. In particular, for the default case, [0, size] form the boundaries, but other subclasses may choose a different subset of cards to draw (in particular FanPile).

Because RowView objects may fluctuate in size, we never know our maximal width when creating the image: we start with a default size, but then this may grow... While we can't expand larger than our original Widget size, we should still accommodate as much as we can. Thus, we keep a "high water mark" for the largest width value seen so far, and grow our offscreenImage accordingly.

To make programming easier, the smallest size a RowView image can be is 13 cards...

A finely drawn frame is drawn around an empty RowView image. Also see FanPile

Specified by:
redraw in class Widget

returnWidget

public boolean returnWidget(Widget w)
Return the CardView widget's model element back onto the underlying Column. From a RowView object, it is possible to generate both CardView and RowView objects.

Overrides:
returnWidget in class Widget
Parameters:
w - ks.common.view.Widget
Returns:
boolean

setDirection

public void setDirection(int newDirection)
Sets the direction of the row (facing LEFT or RIGHT).

Parameters:
newDirection - LEFT or RIGHT direction for widget.

setJustification

public void setJustification(int newJustification)
Sets the justification of the row (flush LEFT or flush RIGHT).

Parameters:
newJustification - flush LEFT or RIGHT