|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.awt.Component
|
+--net.sourceforge.foobase.DisplayBoard
Graphical display of a chess position.
This class is the main component of Foobase applications presenting chess games graphically: a chessboard is drawn, pieces are placed on it and events are generated when a user clicks on a square.
| Inner Class Summary | |
protected class |
DisplayBoard.MouseFilter
|
| Field Summary | |
static java.lang.String |
__version
|
protected Board |
_board
Board setup to draw |
protected java.awt.Color |
_border
Color to use for drawing a border aroung the board |
protected int |
_brcx
Bottom right corner X-coordinate of clipping area |
protected int |
_brcy
Bottom right corner Y-coordinate of clipping area |
protected java.awt.Color |
_dark
Color to use for drawing a dark square |
protected java.util.Vector |
_ears
List of IsFoobaseMouseListener objects that must be
notified in case we generate a FoobaseMouseEvent |
protected int |
_h
Height of each board square. |
protected int |
_hicol
Column number of currently highlighted square (A1 is on column zero) |
protected java.awt.Color |
_high
Color to use for highlighting square |
protected int |
_hirow
Row number of currently highlighted square (A1 is on row zero) |
protected java.awt.Color |
_light
Color to use for drawing a light square |
protected int |
_maxh
Maximum height used for any piece |
protected java.awt.Graphics |
_offgraph
Offscreen Graphics |
protected java.awt.Image |
_offscreen
Offscreen image on which actual drawing takes place. |
protected byte[] |
_oldsetup
Local copy of pieces setup as drawn in offscreen image. |
protected java.awt.Image[] |
_pcs
Images to use for drawing of pieces. |
protected java.awt.Dimension |
_size
Board dimensions. |
protected java.awt.Font |
_txtfont
Font to use for drawing row numbers and column letters |
protected int |
_ulcx
Upper left corner X-coordinate for clipping area |
protected int |
_ulcy
Upper right corner Y-coordinate for clipping area |
protected int |
_w
Width of each board square. |
protected int |
_x0
X-offset of left upper corner of the board inside its border. |
protected int |
_y0
Y-offset of left upper corner of the board inside its border. |
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
| Fields inherited from interface net.sourceforge.foobase.IsFoobaseMouseSource |
__version |
| Constructor Summary | |
DisplayBoard()
Default public constructor. |
|
DisplayBoard(java.awt.Image[] pcs)
Public constructor. |
|
DisplayBoard(java.awt.Image[] pcs,
Board board)
Public constructor. |
|
| Method Summary | |
void |
addFoobaseMouseListener(IsFoobaseMouseListener ear)
Register an IsFoobaseMouseListener client object. |
protected void |
drawBoard(java.awt.Graphics g)
Actual offscreen image drawing method. |
void |
drawSquare(int r,
int c)
(Re)draw the contents of one square. |
protected void |
drawSquare(int r,
int c,
java.awt.Graphics g)
Helper method for drawing the contents of one square. |
protected void |
drawThickRectangle(int x,
int y,
int w,
int h,
int t,
java.awt.Color c,
java.awt.Graphics g)
Helper method for drawing a rectangle with a specified with and color. |
int |
getHighlightColumn()
Get column number of currently highlighted square. |
int |
getHighlightRow()
Get row number of currently highlighted square. |
java.awt.Dimension |
getMaximumSize()
Get maximum size for component. |
java.awt.Dimension |
getMinimumSize()
Get minimum size for component. |
java.awt.Dimension |
getPreferredSize()
Get preferred size for component. |
void |
highLight(int r,
int c)
Highlight one square. |
protected void |
highLight(int r,
int c,
java.awt.Graphics g)
Helper method for highlighting a square. |
void |
markDirty()
Mark that the current offscreen image should be recreated completely. |
protected void |
markRegion(int x,
int y,
int w,
int h)
Update clipping region. |
java.awt.Dimension |
maximumSize()
Get maximum size for component. |
java.awt.Dimension |
minimumSize()
Get minimum size for component. |
protected void |
newOffscreenImage()
Helper method for creating an offscreen image. |
void |
paint(java.awt.Graphics g)
Main drawing method. |
java.awt.Dimension |
preferredSize()
Get preferred size for component. |
void |
removeFoobaseMouseListener(IsFoobaseMouseListener ear)
Unregister an IsFoobaseMouseListener client object. |
protected static void |
say(java.lang.String s)
Log a message. |
void |
setBoard(Board board)
Set new board to use from now on. |
void |
setBounds(int x,
int y,
int w,
int h)
Set new location and size for component. |
void |
setBounds(java.awt.Rectangle r)
Set new location and size for component. |
void |
setFixedSize(int w,
int h)
Set new dimensions for component. |
void |
unHighLight()
Undo any highlighting currently going on. |
void |
update(java.awt.Graphics g)
Update the component. |
| Methods inherited from class java.awt.Component |
action,
add,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener,
addNotify,
addPropertyChangeListener,
addPropertyChangeListener,
bounds,
checkImage,
checkImage,
coalesceEvents,
contains,
contains,
createImage,
createImage,
deliverEvent,
disable,
disableEvents,
dispatchEvent,
doLayout,
enable,
enable,
enableEvents,
enableInputMethods,
firePropertyChange,
getAlignmentX,
getAlignmentY,
getBackground,
getBounds,
getBounds,
getColorModel,
getComponentAt,
getComponentAt,
getComponentOrientation,
getCursor,
getDropTarget,
getFont,
getFontMetrics,
getForeground,
getGraphics,
getHeight,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocation,
getLocationOnScreen,
getName,
getParent,
getPeer,
getSize,
getSize,
getToolkit,
getTreeLock,
getWidth,
getX,
getY,
gotFocus,
handleEvent,
hasFocus,
hide,
imageUpdate,
inside,
invalidate,
isDisplayable,
isDoubleBuffered,
isEnabled,
isFocusTraversable,
isLightweight,
isOpaque,
isShowing,
isValid,
isVisible,
keyDown,
keyUp,
layout,
list,
list,
list,
list,
list,
locate,
location,
lostFocus,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp,
move,
nextFocus,
paintAll,
paramString,
postEvent,
prepareImage,
prepareImage,
print,
printAll,
processComponentEvent,
processEvent,
processFocusEvent,
processInputMethodEvent,
processKeyEvent,
processMouseEvent,
processMouseMotionEvent,
remove,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener,
removeNotify,
removePropertyChangeListener,
removePropertyChangeListener,
repaint,
repaint,
repaint,
repaint,
requestFocus,
reshape,
resize,
resize,
setBackground,
setComponentOrientation,
setCursor,
setDropTarget,
setEnabled,
setFont,
setForeground,
setLocale,
setLocation,
setLocation,
setName,
setSize,
setSize,
setVisible,
show,
show,
size,
toString,
transferFocus,
validate |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
protected java.awt.Image[] _pcs
The first six are white pieces, next six are black pieces.
The order for the pieces per color is:
protected int _maxh
protected java.awt.Color _light
protected java.awt.Color _dark
protected java.awt.Color _high
protected java.awt.Color _border
For now, this color is always black.
protected java.awt.Dimension _size
protected int _x0
If this value is not yet set by a paint operation, it is set to
-1
protected int _y0
If this value is not yet set by a paint operation, it is set to
-1
protected int _w
If this value is not yet set by a paint operation, it is set to
-1
protected int _h
If this value is not yet set by a paint operation, it is set to
-1
protected Board _board
protected java.awt.Font _txtfont
For now, no board decoration is implemented.
protected java.awt.Image _offscreen
protected java.awt.Graphics _offgraph
Graphicsprotected int _hirow
protected int _hicol
protected java.util.Vector _ears
IsFoobaseMouseListener objects that must be
notified in case we generate a FoobaseMouseEventprotected int _ulcx
protected int _ulcy
protected int _brcx
protected int _brcy
protected byte[] _oldsetup
public static final java.lang.String __version
| Constructor Detail |
public DisplayBoard()
public DisplayBoard(java.awt.Image[] pcs)
The pieces image array contains 12 elements: first six white pieces, followed by six black pieces. The order of the pieces for each color is:
Also note that none of the input parameters is actually copied into local properties, but rather a reference to them is stored locally.
One implication of this approach is that if the caller modifies the board later on (e.g. by executing a move on the position), this object will automatically have the new board setup available too.
pcs - Image[] containing the images to use
for drawing the different pieces. Note that the images must be available
for immediate usage, that is: use a MediaTracker to ensure
that all images have been properly loaded.
public DisplayBoard(java.awt.Image[] pcs,
Board board)
The pieces image array contains 12 elements: first six white pieces, followed by six black pieces. The order of the pieces for each color is:
Also note that none of the input parameters is actually copied into local properties, but rather a reference to them is stored locally.
One implication of this approach is that if the caller modifies the board later on (e.g. by executing a move on the position), this object will automatically have the new board setup available too.
pcs - Image[] containing the images to use
for drawing the different pieces. Note that the images must be available
for immediate usage, that is: use a MediaTracker to ensure
that all images have been properly loaded.board - Board containing the pieces setup.| Method Detail |
protected static void say(java.lang.String s)
s - String to logpublic void setBoard(Board board)
board - Board to use from now on.public void paint(java.awt.Graphics g)
g - Graphics to draw the board on.public void update(java.awt.Graphics g)
The main reason for implementing this method is to avoid clearing of the component on screen first.
g - Graphics to draw the board on.public void markDirty()
public void setFixedSize(int w,
int h)
w - int new width for componenth - int new height for component
public void setBounds(int x,
int y,
int w,
int h)
x - int new X-coordinate for componenty - int new Y-coordinate for componentw - int new width for componenth - int new height for componentpublic void setBounds(java.awt.Rectangle r)
r - Rectangle containing the new location and
size for the component.public java.awt.Dimension getPreferredSize()
Dimension containing the preferred size.public java.awt.Dimension preferredSize()
Dimension containing the preferred size.public java.awt.Dimension getMinimumSize()
Dimension containing the minimum size.public java.awt.Dimension minimumSize()
Dimension containing the minimum size.public java.awt.Dimension getMaximumSize()
Dimension containing the maximum size.public java.awt.Dimension maximumSize()
Dimension containing the maximum size.
public void highLight(int r,
int c)
Note that this method does not draw the "normal" contents of the square but only the surrounding highlighting rectangle
r - int containing the row number of the square to
highlight (bottom row is number zero)c - int containing the column number of the square to
highlight (leftmost column is column zero)public void unHighLight()
It is safe to call this method even if nothing is currently being highlighted.
public void drawSquare(int r,
int c)
r - int containing the row number of the square to
highlight (bottom row is number zero)c - int containing the column number of the square to
highlight (leftmost column is column zero)public int getHighlightRow()
int containing the zero-based row number (A1 is on
row zero) of the currently highlighted square, or -1 if no
sqaure is being highlighted.public int getHighlightColumn()
int containing the zero-based column number (A1
is on column zero) of the currently highlighted square, or
-1 if no sqaure is being highlighted.public void addFoobaseMouseListener(IsFoobaseMouseListener ear)
IsFoobaseMouseListener client object.ear - IsFoobaseMouseListener to notify if relevant
events are generated.public void removeFoobaseMouseListener(IsFoobaseMouseListener ear)
IsFoobaseMouseListener client object.ear - IsFoobaseMouseListener to unregisterprotected void drawBoard(java.awt.Graphics g)
g - Graphics to draw the board on.protected void newOffscreenImage()
Implicit input is the _size property and implicit output
are _mis and _pix
Normally, a new image is required after every resizing operation.
protected void markRegion(int x,
int y,
int w,
int h)
x - int X-coordinate of changed regiony - int Y-coordinate of changed regionw - int width of changed regionh - int height of changed region
protected void drawThickRectangle(int x,
int y,
int w,
int h,
int t,
java.awt.Color c,
java.awt.Graphics g)
x - int containing the X-coordinate of the upper left
cornery - int containing the Y-coordinate of the upper left
cornerw - int containing the width of the rectangle (that
is: the outer width of the rectangle, not the thickness of the lines)h - int containing the height of the rectangle (that
is: the outer height of the rectangle, not the thickness of the lines)t - int containing the thickness of the rectangle
to drawc - Color to use for drawingg - Graphics to draw on.
protected void highLight(int r,
int c,
java.awt.Graphics g)
Note that this method does not draw the "normal" contents of the square but only the surrounding highlighting rectangle
r - int containing the row number of the square to
highlight (bottom row is number zero)c - int containing the column number of the square to
highlight (leftmost column is column zero)g - Graphics to draw on
protected void drawSquare(int r,
int c,
java.awt.Graphics g)
r - int containing the row number of the square to
highlight (bottom row is number zero)c - int containing the column number of the square to
highlight (leftmost column is column zero)g - Graphics to draw on
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||