soc.client
Class SOCHandPanel.ResourceTradeTypeMenu

java.lang.Object
  extended by java.awt.MenuComponent
      extended by java.awt.MenuItem
          extended by java.awt.Menu
              extended by java.awt.PopupMenu
                  extended by soc.client.SOCHandPanel.ResourceTradePopupMenu
                      extended by soc.client.SOCHandPanel.ResourceTradeTypeMenu
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Enclosing class:
SOCHandPanel

static class SOCHandPanel.ResourceTradeTypeMenu
extends SOCHandPanel.ResourceTradePopupMenu
implements java.awt.event.MouseListener, java.awt.event.ActionListener

Menu for right-click on resource square to trade one resource type with bank/port.

Author:
Jeremy D Monin

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.PopupMenu
java.awt.PopupMenu.AccessibleAWTPopupMenu
 
Nested classes/interfaces inherited from class java.awt.Menu
java.awt.Menu.AccessibleAWTMenu
 
Nested classes/interfaces inherited from class java.awt.MenuItem
java.awt.MenuItem.AccessibleAWTMenuItem
 
Nested classes/interfaces inherited from class java.awt.MenuComponent
java.awt.MenuComponent.AccessibleAWTMenuComponent
 
Field Summary
private  int costFrom
           
(package private)  boolean isForThree1
           
private  ColorSquare resSq
           
private  int resTypeFrom
           
private  SOCHandPanel.ResourceTradeMenuItem[] tradeForItems
           
 
Fields inherited from class soc.client.SOCHandPanel.ResourceTradePopupMenu
hpan
 
Constructor Summary
SOCHandPanel.ResourceTradeTypeMenu(SOCHandPanel hp, int typeFrom, boolean forThree1)
          One-time-use menu for board popup menu.
SOCHandPanel.ResourceTradeTypeMenu(SOCHandPanel hp, int typeFrom, ColorSquare sq, int numFrom)
          Menu attached to a resource colorsquare in the client player's handpanel
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Handling the menu item
 void destroy()
          Cleanup, for removing this menu.
 int getResourceCost()
           
 int getResourceType()
           
private  void init(int typeFrom, SOCGame ga, ColorSquare sq, int numFrom, boolean forThree1)
          Common to both constructors
 void mouseClicked(java.awt.event.MouseEvent evt)
          Handle popup-click on resource colorsquare.
 void mouseEntered(java.awt.event.MouseEvent evt)
          Stub required for MouseListener
 void mouseExited(java.awt.event.MouseEvent evt)
          Stub required for MouseListener
 void mousePressed(java.awt.event.MouseEvent evt)
          Handle popup-click on resource colorsquare.
 void mouseReleased(java.awt.event.MouseEvent evt)
          Handle popup-click on resource colorsquare.
 void setEnabledIfCanTrade(boolean itemsOnly)
          Enable or disable based on gamestate and player's resources.
 void show(int x, int y)
          Show menu at this position.
 void updateCost(int newCost)
          Update cost of trade; update menu item text.
 
Methods inherited from class java.awt.PopupMenu
addNotify, getAccessibleContext, getParent, show
 
Methods inherited from class java.awt.Menu
add, add, addSeparator, countItems, getItem, getItemCount, insert, insert, insertSeparator, isTearOff, paramString, remove, remove, removeAll, removeNotify
 
Methods inherited from class java.awt.MenuItem
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getListeners, getShortcut, isEnabled, processActionEvent, processEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcut
 
Methods inherited from class java.awt.MenuComponent
dispatchEvent, getFont, getName, getPeer, getTreeLock, postEvent, setFont, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

resSq

private ColorSquare resSq

resTypeFrom

private int resTypeFrom

costFrom

private int costFrom

isForThree1

boolean isForThree1

tradeForItems

private SOCHandPanel.ResourceTradeMenuItem[] tradeForItems
Constructor Detail

SOCHandPanel.ResourceTradeTypeMenu

public SOCHandPanel.ResourceTradeTypeMenu(SOCHandPanel hp,
                                          int typeFrom,
                                          ColorSquare sq,
                                          int numFrom)
Menu attached to a resource colorsquare in the client player's handpanel


SOCHandPanel.ResourceTradeTypeMenu

public SOCHandPanel.ResourceTradeTypeMenu(SOCHandPanel hp,
                                          int typeFrom,
                                          boolean forThree1)
                                   throws java.lang.IllegalStateException
One-time-use menu for board popup menu.

Parameters:
hp - Handpanel with player's information (including trade costs)
typeFrom - Resource type from which to trade
forThree1 - Is part of a 3-for-1 port trade menu, with all resource types
Throws:
java.lang.IllegalStateException - If client not current player
Method Detail

init

private void init(int typeFrom,
                  SOCGame ga,
                  ColorSquare sq,
                  int numFrom,
                  boolean forThree1)
Common to both constructors


show

public void show(int x,
                 int y)
Show menu at this position. Before showing, enable or disable based on gamestate and player's resources.

Specified by:
show in class SOCHandPanel.ResourceTradePopupMenu
Parameters:
x - Mouse x-position relative to colorsquare
y - Mouse y-position relative to colorsquare
See Also:
SOCHandPanel.ResourceTradePopupMenu.setEnabledIfCanTrade(boolean)

setEnabledIfCanTrade

public void setEnabledIfCanTrade(boolean itemsOnly)
Enable or disable based on gamestate and player's resources.

Specified by:
setEnabledIfCanTrade in class SOCHandPanel.ResourceTradePopupMenu
Parameters:
itemsOnly - If true, enable/disable items, instead of the menu itself.

updateCost

public void updateCost(int newCost)
Update cost of trade; update menu item text.


getResourceType

public int getResourceType()
Returns:
the resource type number from which this menu trades

getResourceCost

public int getResourceCost()
Returns:
the cost to trade this resource (3-for-1 returns 3, etc)

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Handling the menu item

Specified by:
actionPerformed in interface java.awt.event.ActionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent evt)
Handle popup-click on resource colorsquare. mousePressed has xwindows/OS-X popup trigger.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent evt)
Handle popup-click on resource colorsquare.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent evt)
Handle popup-click on resource colorsquare. mouseReleased has win32 popup trigger.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent evt)
Stub required for MouseListener

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent evt)
Stub required for MouseListener

Specified by:
mouseExited in interface java.awt.event.MouseListener

destroy

public void destroy()
Cleanup, for removing this menu.

Specified by:
destroy in class SOCHandPanel.ResourceTradePopupMenu