soc.client
Class TradeOfferPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by soc.client.TradeOfferPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class TradeOfferPanel
extends java.awt.Panel

Two-mode panel to display either a short status message, or a resource trade offer (and counter-offer) from another player.

The status message mode is used for tasks such as:

To use message mode, call setMessage(String). To use trade offer mode, show setOffer(SOCTradeOffer). To show or hide the panel in either mode, call Component.setVisible(boolean).

To set this panel's position or size, please use setBounds(int, int, int, int), because it is overridden to also update a "compact mode" flag for counter-offer layout.

See Also:
Serialized Form

Nested Class Summary
private  class TradeOfferPanel.MessagePanel
          Panel to show when in MESSAGE_MODE, not OFFER_MODE.
private  class TradeOfferPanel.OfferPanel
          Panel to show a trade offer when in OFFER_MODE, not MESSAGE_MODE.
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
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) static java.lang.String ACCEPT
           
(package private) static java.lang.String CANCEL
           
(package private)  java.awt.CardLayout cardLayout
          Layout which shows either messagePanel or offerPanel.
(package private) static java.lang.String CLEAR
           
private  boolean counterCompactMode
          If true, display counter-offer in a "compact mode" layout because the panel's height is too short for the normal arrangement.
private  boolean counterHidesBalloonPoint
          If true, hide the original offer's balloon point (see SpeechBalloon.setBalloonPoint(boolean)) when the counter-offer is visible.
(package private)  int from
           
(package private)  SOCHandPanel hp
           
(package private) static java.awt.Color insideBGColor
           
static java.lang.String MESSAGE_MODE
          Mode to show a message, not a trade offer.
(package private)  TradeOfferPanel.MessagePanel messagePanel
           
(package private)  java.lang.String mode
          Current mode: MESSAGE_MODE to show messagePanel, or OFFER_MODE to show offerPanel.
(package private) static java.lang.String OFFER
           
static int OFFER_BUTTONS_HEIGHT
          Additional height of offer (part of OFFER_HEIGHT) when the "offer"/"accept"/"reject" buttons are showing.
static int OFFER_COUNTER_HEIGHT
          Typical height of counter-offer panel, when visible.
static int OFFER_HEIGHT
          Typical height of offer panel, when visible.
static java.lang.String OFFER_MODE
          Mode to show a trade offer, not a message.
(package private)  TradeOfferPanel.OfferPanel offerPanel
           
(package private)  SOCPlayerInterface pi
           
(package private) static java.lang.String REJECT
           
(package private) static java.lang.String SEND
           
private static SOCStringManager strings
          i18n text strings; will use same locale as SOCPlayerClient's string manager.
protected static int[] zero
           
 
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
TradeOfferPanel(SOCHandPanel hp, int from)
          Creates a new TradeOfferPanel object.
 
Method Summary
 void clearOffer()
          Set the offer and counter-offer contents to zero.
 boolean doesCounterHideBalloonPoint()
          If true, hide the original offer's balloon point (see SpeechBalloon.setBalloonPoint(boolean)) when the counter-offer is visible.
 java.lang.String getMode()
          Returns current mode of OFFER_MODE, or MESSAGE_MODE, which has been set by using setOffer(soc.game.SOCTradeOffer) or setMessage(java.lang.String)
 boolean isCounterOfferMode()
          Is this offerpanel in counteroffer mode, with a trade offer and counter-offer showing?
 void setBounds(int x, int y, int width, int height)
          Move and/or resize this panel.
 void setCounterHidesBalloonPoint(boolean hide)
          If true, hide the original offer's balloon point (see SpeechBalloon.setBalloonPoint(boolean)) when the counter-offer is visible.
 void setMessage(java.lang.String message)
          Switch to the Message from another player, or clear its most recent contents.
 void setOffer(SOCTradeOffer currentOffer)
          Update to view the of an offer from another player.
 void updateOfferButtons()
          If an offer is currently showing, show or hide Accept button based on the client player's current resources.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strings

private static final SOCStringManager strings
i18n text strings; will use same locale as SOCPlayerClient's string manager.

Since:
2.0.00

OFFER_MODE

public static final java.lang.String OFFER_MODE
Mode to show a trade offer, not a message. Made visible via setOffer(SOCTradeOffer).

See Also:
MESSAGE_MODE, Constant Field Values

MESSAGE_MODE

public static final java.lang.String MESSAGE_MODE
Mode to show a message, not a trade offer. Made visible via setMessage(String).

See Also:
OFFER_MODE, Constant Field Values

OFFER_HEIGHT

public static final int OFFER_HEIGHT
Typical height of offer panel, when visible. (Includes OFFER_BUTTONS_HEIGHT, but not OFFER_COUNTER_HEIGHT.) For convenience of other classes' layout calculations. Actual height (buttons' y-positions + height) is set dynamically in OfferPanel.doLayout.

Since:
1.1.08
See Also:
Constant Field Values

OFFER_BUTTONS_HEIGHT

public static final int OFFER_BUTTONS_HEIGHT
Additional height of offer (part of OFFER_HEIGHT) when the "offer"/"accept"/"reject" buttons are showing. That is, when not in counter-offer mode. For convenience of other classes' layout calculations. Based on calculations within OfferPanel.doLayout.

Since:
1.1.08
See Also:
Constant Field Values

OFFER_COUNTER_HEIGHT

public static final int OFFER_COUNTER_HEIGHT
Typical height of counter-offer panel, when visible. For convenience of other classes' layout calculations. Actual height of counter-offer (offerBox) is set dynamically in OfferPanel.doLayout.

Since:
1.1.08
See Also:
Constant Field Values

zero

protected static final int[] zero

OFFER

static final java.lang.String OFFER
See Also:
Constant Field Values

ACCEPT

static final java.lang.String ACCEPT
See Also:
Constant Field Values

REJECT

static final java.lang.String REJECT
See Also:
Constant Field Values

SEND

static final java.lang.String SEND
See Also:
Constant Field Values

CLEAR

static final java.lang.String CLEAR
See Also:
Constant Field Values

CANCEL

static final java.lang.String CANCEL
See Also:
Constant Field Values

insideBGColor

static final java.awt.Color insideBGColor

from

int from

hp

SOCHandPanel hp

pi

SOCPlayerInterface pi

mode

java.lang.String mode
Current mode: MESSAGE_MODE to show messagePanel, or OFFER_MODE to show offerPanel.


cardLayout

java.awt.CardLayout cardLayout
Layout which shows either messagePanel or offerPanel.


messagePanel

TradeOfferPanel.MessagePanel messagePanel

offerPanel

TradeOfferPanel.OfferPanel offerPanel

counterCompactMode

private boolean counterCompactMode
If true, display counter-offer in a "compact mode" layout because the panel's height is too short for the normal arrangement. Calculated using OFFER_HEIGHT + OFFER_COUNTER_HEIGHT - OFFER_BUTTONS_HEIGHT.

Since:
1.1.08

counterHidesBalloonPoint

private boolean counterHidesBalloonPoint
If true, hide the original offer's balloon point (see SpeechBalloon.setBalloonPoint(boolean)) when the counter-offer is visible.

Since:
1.1.08
Constructor Detail

TradeOfferPanel

public TradeOfferPanel(SOCHandPanel hp,
                       int from)
Creates a new TradeOfferPanel object.

Method Detail

setMessage

public void setMessage(java.lang.String message)
Switch to the Message from another player, or clear its most recent contents. If message is null, only clear the message text, don't change the visibility. Otherwise, set the message text and show the Message. If an offer/counteroffer were visible, they are not lost; call setOffer(SOCTradeOffer) to show them again.

Parameters:
message - the message message to show, or null. Null does not show or hide the panel, only clears the label text. Message can be 1 line, or 2 lines with '\n'; will not automatically wrap based on message length.

setOffer

public void setOffer(SOCTradeOffer currentOffer)
Update to view the of an offer from another player. If counter-offer was previously shown, show it again. This lets us restore the offer view after message mode.

To update buttons after setOffer if the client player's resources change, call updateOfferButtons().

To clear values to zero, and hide the counter-offer box, call clearOffer().

Parameters:
currentOffer - the trade being proposed
See Also:
setMessage(String)

updateOfferButtons

public void updateOfferButtons()
If an offer is currently showing, show or hide Accept button based on the client player's current resources. Call this after client player receives, loses, or trades resources.

Since:
1.1.20

clearOffer

public void clearOffer()
Set the offer and counter-offer contents to zero. Clear counteroffer mode.


isCounterOfferMode

public boolean isCounterOfferMode()
Is this offerpanel in counteroffer mode, with a trade offer and counter-offer showing?

Returns:
true if in counter-offer mode
Since:
1.1.08

getMode

public java.lang.String getMode()
Returns current mode of OFFER_MODE, or MESSAGE_MODE, which has been set by using setOffer(soc.game.SOCTradeOffer) or setMessage(java.lang.String)


doesCounterHideBalloonPoint

public boolean doesCounterHideBalloonPoint()
If true, hide the original offer's balloon point (see SpeechBalloon.setBalloonPoint(boolean)) when the counter-offer is visible.

Since:
1.1.08

setCounterHidesBalloonPoint

public void setCounterHidesBalloonPoint(boolean hide)
If true, hide the original offer's balloon point (see SpeechBalloon.setBalloonPoint(boolean)) when the counter-offer is visible.

Parameters:
hide - Hide it during counter-offer?
Since:
1.1.08

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Move and/or resize this panel. Overriden to also update "compact mode" flag for counter-offer.

Overrides:
setBounds in class java.awt.Component
Since:
1.1.08