|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Canvas
soc.client.ColorSquare
public class ColorSquare
This is a square box with a background color and possibly a number, checkmark, or text in it. This box can be interactive, or non-interactive. The possible colors of the box correspond to resources in SoC.
Default size is WIDTH
by HEIGHT
pixels.
Most colorsquares in JSettlers are actually
ColorSquareLarger
instances.
This was easier than changing the values of WIDTH
and HEIGHT
,
which are used for setting the size of many GUI elements.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Canvas |
---|
java.awt.Canvas.AccessibleAWTCanvas |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
(package private) boolean |
boolValue
|
private java.awt.Color |
borderColor
Border color, BLACK by default |
static int |
BOUNDED_DEC
|
static int |
BOUNDED_INC
|
static int |
CHECKBOX
|
static java.awt.Color |
CLAY
The color constants are used by ColorSquare, and also used for the robber's "ghost" when moving the robber, and fallback for missing hex graphics. |
static java.awt.Color |
DESERT
|
static java.awt.Color |
FOG
Fog hex color. |
static java.awt.Color |
GOLD
Gold hex color. |
static java.awt.Color |
GREY
|
protected boolean |
hasWarnHigh
Low-level or high-level warning level has been set (intValue). |
protected boolean |
hasWarnLow
Low-level or high-level warning level has been set (intValue). |
static int |
HEIGHT
|
(package private) boolean |
interactive
|
(package private) int |
intValue
|
protected boolean |
isWarnHigh
At high-level warning. |
protected boolean |
isWarnLow
At low-level warning, or at zero if ttip_text_zero was set. |
(package private) int |
kind
|
(package private) int |
lowerBound
|
static int |
NUMBER
|
static java.awt.Color |
ORE
|
static java.awt.Color[] |
RESOURCE_COLORS
Array of resource colors. |
static java.awt.Color |
SHEEP
|
protected ColorSquareListener |
sqListener
|
protected int |
squareH
Size per instance, for ColorSquareLarger |
protected java.awt.Dimension |
squareSize
|
protected int |
squareW
Size per instance, for ColorSquareLarger |
private static SOCStringManager |
strings
i18n text strings |
static int |
TEXT
Colorsquare type TEXT displays a short message. |
private java.lang.String |
textValue
|
protected AWTToolTip |
ttip
|
protected java.lang.String |
ttip_text
Text for normal vs low-warning-level. |
protected java.lang.String |
ttip_text_warnHigh
Optional text for low-warning-level and high-warning-level (intValue). |
protected java.lang.String |
ttip_text_warnLow
Optional text for low-warning-level and high-warning-level (intValue). |
protected java.lang.String |
ttip_text_zero
Optional text for zero level (intValue). |
(package private) int |
upperBound
|
(package private) boolean |
valueVis
|
protected boolean |
warn_bg_grey
Normal background color is GREY (when not high or low "warning" color). |
static java.awt.Color |
WARN_LEVEL_COLOR
The warning-level text color (high, low, or zero) |
static java.awt.Color |
WARN_LEVEL_COLOR_BG_FROMGREY
Background color for warning-level, if grey normally |
protected int |
warnHighBound
|
protected int |
warnLowBound
|
static java.awt.Color |
WATER
Water hex color, for fallback if graphic is missing. |
static java.awt.Color |
WHEAT
|
static int |
WIDTH
|
static java.awt.Color |
WOOD
|
static int |
YES_NO
|
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, PROPERTIES, SOMEBITS |
Constructor Summary | |
---|---|
ColorSquare()
Creates a new grey ColorSquare object without a visible value. |
|
ColorSquare(java.awt.Color c)
Creates a new ColorSquare object with specified background color. |
|
ColorSquare(java.awt.Color c,
int v)
Creates a new ColorSquare object with specified background color and initial value. |
|
ColorSquare(java.awt.Color c,
java.lang.String v)
Creates a new ColorSquare object with specified background color and initial value. |
|
ColorSquare(int k,
boolean in,
java.awt.Color c)
Creates a new ColorSquare of the specified kind and background color. |
|
ColorSquare(int k,
boolean in,
java.awt.Color c,
int upper,
int lower)
Creates a new ColorSquare of the specified kind and background color. |
Method Summary | |
---|---|
void |
addValue(int v)
DOCUMENT ME! |
void |
clearHighWarningLevel()
If a tooltip high-warning has been set, it is also cleared TODO docu |
void |
clearLowWarningLevel()
If a tooltip low-warning has been set, it is also cleared TODO docu |
boolean |
getBoolValue()
DOCUMENT ME! |
int |
getIntValue()
DOCUMENT ME! |
java.awt.Dimension |
getMinimumSize()
DOCUMENT ME! |
java.awt.Dimension |
getPreferredSize()
DOCUMENT ME! |
ColorSquareListener |
getSquareListener()
Optionally, a square listener can be called when the value changes. |
java.lang.String |
getTooltipText()
If we have a tooltip, return its text. |
void |
mouseClicked(java.awt.event.MouseEvent e)
DOCUMENT ME! |
void |
mouseEntered(java.awt.event.MouseEvent e)
DOCUMENT ME! |
void |
mouseExited(java.awt.event.MouseEvent e)
DOCUMENT ME! |
void |
mousePressed(java.awt.event.MouseEvent evt)
DOCUMENT ME! If a ColorSquareListener is attached, and value changes,
the listener will be called. |
void |
mouseReleased(java.awt.event.MouseEvent e)
DOCUMENT ME! |
void |
paint(java.awt.Graphics g)
DOCUMENT ME! |
void |
setBackground(java.awt.Color c)
Overrides standard to allow special warning behavior for GREY . |
void |
setBoolValue(boolean v)
DOCUMENT ME! If a ColorSquareListener is attached, and value changes,
the listener will be called. |
void |
setBorderColor(java.awt.Color c)
Set this square's border color. |
void |
setBounds(int x,
int y,
int w,
int h)
Set bounds (position and size). |
void |
setColor(java.awt.Color c)
Set this square's background color. |
void |
setHighWarningLevel(int warnLevel)
Set high-level warning (TODO docu text) |
void |
setIntValue(int v)
DOCUMENT ME! If a ColorSquareListener is attached, and value changes,
the listener will be called. |
void |
setLowWarningLevel(int warnLevel)
Set low-level warning (TODO docu text) |
void |
setSize(int w,
int h)
Set the width and height of this ColorSquare. |
void |
setSquareListener(ColorSquareListener sp)
Optionally, a square listener can be called when the value changes. |
void |
setTooltipHighWarningLevel(java.lang.String warnTip,
int warnLevel)
Set high-level warning, and set or clear its tooltip text. |
void |
setTooltipLowWarningLevel(java.lang.String warnTip,
int warnLevel)
Set low-level warning, and set or clear its tooltip text. |
void |
setTooltipText(java.lang.String tip)
Change tooltip text or show or hide tooltip. |
void |
setTooltipZeroText(java.lang.String zeroTip)
Set or clear zero-level tooltip text. |
void |
setVisible(boolean newVis)
Show or hide the colorsquare. |
void |
subtractValue(int v)
DOCUMENT ME! |
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, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, 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, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, 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, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.awt.Color CLAY
SOCBoardPanel.drawRobber(Graphics, int, boolean, boolean)
,
SOCBoardPanel.drawHex(Graphics, int)
public static final java.awt.Color ORE
public static final java.awt.Color SHEEP
public static final java.awt.Color WHEAT
public static final java.awt.Color WOOD
public static final java.awt.Color GREY
public static final java.awt.Color DESERT
public static final java.awt.Color GOLD
Gold hex
color.
public static final java.awt.Color FOG
Fog hex
color.
public static final java.awt.Color WATER
public static final java.awt.Color[] RESOURCE_COLORS
CLAY
, 1 is ORE
, SHEEP, WHEAT, 4 is ORE
.
Because this array has the resource types a player can hold or trade,
it does not contain GOLD
.
public static final int NUMBER
public static final int YES_NO
public static final int CHECKBOX
public static final int BOUNDED_INC
public static final int BOUNDED_DEC
public static final int TEXT
public static final int WIDTH
public static final int HEIGHT
public static java.awt.Color WARN_LEVEL_COLOR
setHighWarningLevel(int)
,
setLowWarningLevel(int)
,
setTooltipZeroText(String)
,
WARN_LEVEL_COLOR_BG_FROMGREY
public static java.awt.Color WARN_LEVEL_COLOR_BG_FROMGREY
WARN_LEVEL_COLOR
int intValue
boolean boolValue
private java.lang.String textValue
boolean valueVis
int kind
int upperBound
int lowerBound
boolean interactive
private java.awt.Color borderColor
protected ColorSquareListener sqListener
protected AWTToolTip ttip
protected boolean warn_bg_grey
WARN_LEVEL_COLOR_BG_FROMGREY
protected java.lang.String ttip_text
protected java.lang.String ttip_text_warnLow
protected java.lang.String ttip_text_warnHigh
protected java.lang.String ttip_text_zero
protected boolean hasWarnLow
protected boolean hasWarnHigh
protected boolean isWarnLow
protected boolean isWarnHigh
protected int warnLowBound
protected int warnHighBound
protected int squareW
protected int squareH
protected java.awt.Dimension squareSize
private static final SOCStringManager strings
Constructor Detail |
---|
public ColorSquare()
ColorSquare(int, boolean, Color, int, int)
public ColorSquare(java.awt.Color c)
NUMBER
, non-interactive, upper=99, lower=0.
A tooltip with the resource name is created if c is one of the resource colors defined in ColorSquare (CLAY, WHEAT, etc).
c
- background colorColorSquare(int, boolean, Color, int, int)
public ColorSquare(java.awt.Color c, int v)
NUMBER
, non-interactive, upper=99,
lower=0.
A tooltip with the resource name is created if c is one of the resource colors defined in ColorSquare (CLAY, WHEAT, etc).
c
- background colorv
- initial int valueColorSquare(int, boolean, Color, int, int)
public ColorSquare(java.awt.Color c, java.lang.String v)
TEXT
, non-interactive.
The colorsquare's size is small by default and not changed here, so
be sure to call setSize
or
setBounds
to make the square
large enough to display your text.
A tooltip with the resource name is created if c is one of the resource colors defined in ColorSquare (CLAY, WHEAT, etc).
c
- background colorv
- initial string valuepublic ColorSquare(int k, boolean in, java.awt.Color c)
A tooltip with the resource name is created if c is one of the resource colors defined in ColorSquare (CLAY, WHEAT, etc).
k
- Kind: NUMBER
, YES_NO, CHECKBOX, BOUNDED_INC, BOUNDED_DECin
- interactive flag allowing user interactionc
- background colorColorSquare(int, boolean, Color, int, int)
public ColorSquare(int k, boolean in, java.awt.Color c, int upper, int lower)
A tooltip with the resource name is created if c is one of the resource colors defined in ColorSquare (CLAY, WHEAT, etc).
k
- Kind: NUMBER, YES_NO, CHECKBOX, BOUNDED_INC, BOUNDED_DECin
- interactive flag allowing user interactionc
- background colorupper
- upper bound if k == NUMBERlower
- lower bound if k == NUMBERMethod Detail |
---|
public void setBackground(java.awt.Color c)
GREY
.
Only grey squares change background color when a warning-level
threshold is reached (setHighWarningLevel(int)
or setLowWarningLevel(int)
).
TODO DOCU - what do other squares do?
setBackground
in class java.awt.Component
c
- New background colorpublic void setColor(java.awt.Color c)
setBackground(Color)
for special behavior with warning-level.
thresholds.
c
- New background colorpublic void setBorderColor(java.awt.Color c) throws java.lang.IllegalArgumentException
c
- New color; the default is Color.BLACK
java.lang.IllegalArgumentException
- if c is nullpublic void setSize(int w, int h)
setSize
in class java.awt.Component
w
- width in pixelsh
- height in pixelspublic java.lang.String getTooltipText()
public void setTooltipText(java.lang.String tip)
tip
- New tip text; will create tooltip if needed.
If tip is null, tooltip is removed, and any warning-level tip text
or zero-level text is also set to null.setTooltipHighWarningLevel(String, int)
,
setTooltipLowWarningLevel(String, int)
,
setTooltipZeroText(String)
public void setLowWarningLevel(int warnLevel) throws java.lang.IllegalArgumentException
warnLevel
- If the colorsquare value is at warnLevel or lower,
indicate with the warning color.
java.lang.IllegalArgumentException
- if warnLevel is above high level, or is zero.
To set text for value 0, use setTooltipZeroText(String)
instead.
To clear the warning level, use clearLowWarningLevel()
instead.clearLowWarningLevel()
,
setTooltipZeroText(String)
public void clearLowWarningLevel()
public void setTooltipLowWarningLevel(java.lang.String warnTip, int warnLevel) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
warnTip
- TODO docu - or null to clear tip textwarnLevel
- TODO docu - at or below
java.lang.IllegalStateException
- if setTooltipText has not yet been called,
and warnTip is not null
java.lang.IllegalArgumentException
- if warnLevel is above high level, or is zero.
To set text for value 0, use setTooltipZeroText(String)
instead.
To clear the warning level, use clearLowWarningLevel()
instead.setHighWarningLevel(int)
,
setLowWarningLevel(int)
,
setTooltipText(String)
,
setTooltipZeroText(String)
public void setHighWarningLevel(int warnLevel) throws java.lang.IllegalArgumentException
warnLevel
- If the colorsquare value is at warnLevel or higher,
indicate with the warning color.
java.lang.IllegalArgumentException
- if warnLevel is below low-warning level.clearHighWarningLevel()
public void clearHighWarningLevel()
public void setTooltipHighWarningLevel(java.lang.String warnTip, int warnLevel) throws java.lang.IllegalStateException, java.lang.IllegalArgumentException
warnTip
- TODO docu - or null to clear tip textwarnLevel
- TODO docu - at or above
java.lang.IllegalStateException
- if setTooltipText has not yet been called,
and warnTip is not null
java.lang.IllegalArgumentException
- if warnLevel is below low-warning level.setHighWarningLevel(int)
,
setLowWarningLevel(int)
,
setTooltipText(String)
public void setTooltipZeroText(java.lang.String zeroTip) throws java.lang.IllegalStateException
zeroTip
- TODO docu - or null to clear tip text
java.lang.IllegalStateException
- if setTooltipText has not yet been called,
and zeroTip is not nullsetTooltipText(String)
,
setTooltipHighWarningLevel(String, int)
,
setTooltipLowWarningLevel(String, int)
,
setTooltipZeroText(String)
public void setVisible(boolean newVis)
setVisible
in class java.awt.Component
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class java.awt.Component
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class java.awt.Component
public void setBounds(int x, int y, int w, int h)
setBounds
in class java.awt.Component
x
- x-positiony
- y-positionw
- width in pixelsh
- height in pixelsComponent.setBounds(int, int, int, int)
public void paint(java.awt.Graphics g)
paint
in class java.awt.Canvas
g
- DOCUMENT ME!public void addValue(int v)
v
- DOCUMENT ME!public void subtractValue(int v)
v
- DOCUMENT ME!public void setIntValue(int v)
ColorSquareListener
is attached, and value changes,
the listener will be called.
v
- DOCUMENT ME!public int getIntValue()
public void setBoolValue(boolean v)
ColorSquareListener
is attached, and value changes,
the listener will be called.
v
- DOCUMENT ME!public boolean getBoolValue()
public ColorSquareListener getSquareListener()
SquaresPanel
, that panel is the listener.
public void setSquareListener(ColorSquareListener sp)
sp
- Square listener, or null to clearpublic void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
e
- DOCUMENT ME!public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
e
- DOCUMENT ME!public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
e
- DOCUMENT ME!public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
e
- DOCUMENT ME!public void mousePressed(java.awt.event.MouseEvent evt)
ColorSquareListener
is attached, and value changes,
the listener will be called.
mousePressed
in interface java.awt.event.MouseListener
evt
- DOCUMENT ME!
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |