Package net.sf.colossus.gui
Class MasterBoard
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
net.sf.colossus.gui.MasterBoard
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
Class MasterBoard implements the GUI for a Titan masterboard.
- Author:
- David Ripton, Romain Dolbeau
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
private final class
(package private) class
(package private) class
(package private) class
(package private) class
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private AbstractAction
private MasterBoard.BottomBar
our own little bar implementationprivate String
private Map
<String, JCheckBoxMenuItem> private AbstractAction
private static final String
private AbstractAction
private AbstractAction
private static final String
private AbstractAction
private Client
private AbstractAction
private final Container
private boolean
In that time while we got tellEngagement but nothing else (bottom bar just tells engaged, but no other visible notice of what's going on), we might be waiting for the opponent to think about whether to flee or not.private static final String
private AbstractAction
(package private) EditLegion
private JMenu
private AbstractAction
private MasterHex
engage() has been sent to server but answer (tellEngagement()) not received yet; mostly we have this, to be able to react properly when user clicks on an engagement while there is still the server response missing for the last oneprivate static final String
private AbstractAction
private boolean
private final ClientGUI
private GUIMasterHex[][]
private MasterBoard.InfoPopupHandler
private ItemListener
private static final String
private AbstractAction
private Point
Last point clicked is needed for popup menus.private JPanel[]
private final LinkedHashMap
<Legion, Marker> List of markers which are currently on the board, for painting in z-order => the end of the list is on top.private AbstractAction
private static final Logger
private KFrame
private final MasterBoard.MasterBoardWindowHandler
private AbstractAction
private static final String
private AbstractAction
private Image
private boolean
private JMenu
private boolean
private JPopupMenu
private JPopupMenu
private static final String
private AbstractAction
private AbstractAction
(package private) EditLegion
private boolean
Show the message that "saving during engagement/battle will store the last commit point" only once each game - flag that it has been shownprivate AbstractAction
private static final String
private AbstractAction
private SaveWindow
private JScrollPane
The scrollbarspanel, needed to correct lastPoint.private ShowHelpDoc
private ShowReadme
private static final String
private AbstractAction
private static final String
private AbstractAction
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
private static final String
private AbstractAction
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
activateNextLegionAndPlaceMouse
(Legion nextLegion) void
actOnEditLegionMaybe
(Legion legion) private void
private void
actOnLegion
(LegionClientSide legion, MasterHex hex) (package private) void
private JCheckBoxMenuItem
addCheckBox
(JMenu menu, String name, int mnemonic) private void
addPossibleRecruitChits
(List<CreatureType> imageNameList, MasterHex masterHex) void
addPossibleRecruitChits
(LegionClientSide legion, Set<MasterHex> hexes) (package private) void
addRecruitedChit
(Legion legion) (package private) void
adjustCheckboxIfNeeded
(String name, boolean enable) Find the checkbox for the given (boolean) option name; set it to the new given value (only if different that previous value).(package private) void
This is incredibly inefficient.private void
alignLegions
(Set<MasterHex> hexes) (package private) void
alignLegions
(MasterHex masterHex) private void
attemptEngage
(MasterHex hex) private void
private void
(package private) void
cleanRecruitedChit
(LegionClientSide legion) void
We got showConcede or showNegotiate messages, i.e.void
tellEngagement calls this, now "engaging" is not pending, instead there is a real engagement to be resolved.void
void
private Constants.ConfirmVals
confirmDialog
(String text, int count) (package private) void
void
disableDoneAction
(String reason) Disable the Done action, and update the reason text in bottomBarprivate void
disableDoneActionActivePlayerDoes
(String doesWhat) Clear bottomBar phase text and call disableDoneAction, as reason the standard text "<active player> doesWhat"void
dispose()
private void
Finishes the current phase.void
void
void
void
(package private) void
(package private) KFrame
getFrame()
(package private) GUIMasterHex
getGUIHexByMasterHex
(MasterHex masterHex) Do a brute-force search through the hex array, looking for a match.private GUIMasterHex
getHexContainingPoint
(Point point) Return the MasterHex that contains the given point, or null if none does.private String
private Marker
getMarkerAtPoint
(Point point) Return the topmost Marker that contains the given point, or null if none does.private MasterBoard
TODO this should probably be stored as member, possibly instead of the client class.(package private) void
private void
highlightMoves
(LegionClientSide legion) Select hexes where this legion can move.(package private) void
Highlight all hexes with legions that (still) can do recruiting(package private) void
(package private) void
private static boolean
Return true if the MouseEvent e came from button 2 or 3.private void
user pressed "N".private void
void
(package private) void
If and only if stealFocus option is enabled, this does both requestFocus and getFrame().toFront().(package private) void
(package private) void
pack()
void
private void
private void
private void
Paint markers in z-order.private void
private void
private void
void
Create new markers in response to a rescale.(package private) void
removeMarkerForLegion
(Legion legion) (package private) void
(package private) void
rescale()
private boolean
Inform the user that saving during an engagement will save the last commit point, so loading it will re-set game to just before the engagement was started.(package private) void
private void
selectHexes
(Set<MasterHex> hexes) private void
selectHexes
(Set<MasterHex> hexes, Color color) void
setBoardActive
(boolean val) void
setEditOngoing
(EditLegion editLegion) void
setGameOverState
(String message) (package private) void
setMarkerForLegion
(Legion legion, Marker marker) void
(package private) void
setPendingText
(String text) void
setPhaseInfo
(String message) void
void
setRelocateOngoing
(EditLegion editLegion) void
void
setServerClosedMessage
(boolean gameOver) void
setTempDisconnectedState
(String message) private void
setTitleInfoText
(String text) private void
private void
setupAsInactivePlayer
(String text) Do the setup needed for an inactive player: set the actions which are allowed only for active player to inactive, and update the bottomBar info why "Done" is disabled accordingly(package private) void
private void
private void
(package private) void
(package private) void
private void
setupPhasePreparations
(String titleText) (package private) void
Show which player owns this board.private void
(package private) void
(package private) void
setupTitleForMovementRoll
(int roll) private void
void
(package private) void
(package private) void
void
void
updateLegionsLeftToMoveText
(boolean have_roll) void
void
updateReplayText
(int currTurn, int maxTurn) void
viewEditLegion
(LegionClientSide legion) void
viewLegions
(Point point) Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
LOGGER
-
offScreenBuffer
-
overlayChanged
private boolean overlayChanged -
guiHexArray
-
client
-
gui
-
masterFrame
-
showReadme
-
showHelpDoc
-
editMenu
-
phaseMenu
-
popupMenu
-
popupMenuWithLegions
-
checkboxes
-
legionFlyouts
-
mbwh
-
iph
-
lastPoint
Last point clicked is needed for popup menus. -
engagingPendingHex
engage() has been sent to server but answer (tellEngagement()) not received yet; mostly we have this, to be able to react properly when user clicks on an engagement while there is still the server response missing for the last one -
defenderFleePhase
private boolean defenderFleePhaseIn that time while we got tellEngagement but nothing else (bottom bar just tells engaged, but no other visible notice of what's going on), we might be waiting for the opponent to think about whether to flee or not. So if user is impatient and clicks a hex with any (same, or other) engagement, inform him we are already engaged right now and probably opponent is currently thinking about whether to flee or not. Once we receive showConcede or showNegotiate messages, this time window is over, after that we don't say this about the "perhaps opponent is currently thinking whether to flee" any more. -
saveDuringEngagementDialogMessageShown
private boolean saveDuringEngagementDialogMessageShownShow the message that "saving during engagement/battle will store the last commit point" only once each game - flag that it has been shown -
legionToMarkerMap
List of markers which are currently on the board, for painting in z-order => the end of the list is on top. Now synchronized access to prevent NPEs when EDT wants to paint a marker and asks for the legion for it, and legion has just been removed. I don't use a synchronizedList, because then I get into trouble in the recreateMarkers method. -
recruitedChits
-
possibleRecruitChits
-
scrollPane
The scrollbarspanel, needed to correct lastPoint. -
contentPane
-
bottomBar
our own little bar implementation -
gameOverStateReached
private boolean gameOverStateReached -
saveGameAs
- See Also:
-
clearRecruitChits
- See Also:
-
skipLegion
- See Also:
-
nextLegion
- See Also:
-
undoLast
- See Also:
-
undoAll
- See Also:
-
doneWithPhase
- See Also:
-
forcedDoneWithPhase
- See Also:
-
kickPhase
- See Also:
-
takeMulligan
- See Also:
-
withdrawFromGame
- See Also:
-
viewWebClient
- See Also:
-
viewFullRecruitTree
- See Also:
-
viewHexRecruitTree
- See Also:
-
viewBattleMap
- See Also:
-
viewLegions
- See Also:
-
chooseScreen
- See Also:
-
preferences
- See Also:
-
about
- See Also:
-
viewReadme
- See Also:
-
viewHelpDoc
- See Also:
-
viewWelcome
- See Also:
-
newGameAction
-
loadGameAction
-
saveGameAction
-
saveGameAsAction
-
closeBoardAction
-
quitGameAction
-
cleanDisconnectAction
-
enforcedDisconnectByServerAction
-
tryReconnectAction
-
checkConnectionAction
-
clearRecruitChitsAction
-
skipLegionAction
-
nextLegionAction
-
undoLastAction
-
undoAllAction
-
doneWithPhaseAction
-
forcedDoneWithPhaseAction
-
kickPhaseAction
-
takeMulliganAction
-
withdrawFromGameAction
-
viewWebClientAction
-
viewFullRecruitTreeAction
-
viewHexRecruitTreeAction
-
viewBattleMapAction
-
viewLegionsAction
-
chooseScreenAction
-
preferencesAction
-
aboutAction
-
viewReadmeAction
-
viewHelpDocAction
-
viewWelcomeAction
-
playerLabelDone
private boolean playerLabelDone -
saveWindow
-
cachedPlayerName
-
editLegionOngoing
EditLegion editLegionOngoing -
relocateOngoing
EditLegion relocateOngoing -
itemHandler
-
-
Constructor Details
-
MasterBoard
-
-
Method Details
-
setBoardActive
public void setBoardActive(boolean val) -
enableSaveActions
public void enableSaveActions() -
saveDuringEngagementDialog
private boolean saveDuringEngagementDialog()Inform the user that saving during an engagement will save the last commit point, so loading it will re-set game to just before the engagement was started. Only if user closes the dialog, no save will be done.- Returns:
- True if saving shall be done anyway
-
confirmDialog
-
setupActions
private void setupActions() -
getLogDirectory
-
doQuitGameAction
public void doQuitGameAction() -
showBattleMap
-
setupPopupMenus
private void setupPopupMenus() -
viewLegions
-
addCheckBox
-
cleanCBListeners
private void cleanCBListeners() -
setupTopMenu
private void setupTopMenu() -
adjustCheckboxIfNeeded
Find the checkbox for the given (boolean) option name; set it to the new given value (only if different that previous value).- Parameters:
name
- The option name to adjust the checkbox forenable
- The should-be state of the checkbox
-
setupPlayerLabel
void setupPlayerLabel()Show which player owns this board. -
setupGUIHexes
private void setupGUIHexes() -
getMasterBoard
TODO this should probably be stored as member, possibly instead of the client class. -
cleanGUIHexes
private void cleanGUIHexes() -
doneWithPhase
private void doneWithPhase()Finishes the current phase. Depending on the current phase this method dispatches to the different done methods.- See Also:
-
setupPhasePreparations
-
setupAsInactivePlayer
Do the setup needed for an inactive player: set the actions which are allowed only for active player to inactive, and update the bottomBar info why "Done" is disabled accordingly- Parameters:
text
- What the active player is doing right now
-
setupSplitMenu
void setupSplitMenu() -
setupMoveMenu
void setupMoveMenu() -
setMovementPhase
public void setMovementPhase() -
setupTitleForMovementRoll
void setupTitleForMovementRoll(int roll) -
setupFightMenu
void setupFightMenu() -
updateEngagementsLeftText
public void updateEngagementsLeftText() -
setupMusterMenu
void setupMusterMenu() -
highlightPossibleRecruitLegionHexes
void highlightPossibleRecruitLegionHexes()Highlight all hexes with legions that (still) can do recruiting -
getFrame
KFrame getFrame() -
alignAllLegions
void alignAllLegions()This is incredibly inefficient. -
alignLegions
-
alignLegions
-
highlightTallLegions
void highlightTallLegions() -
highlightUnmovedLegions
void highlightUnmovedLegions() -
setPendingText
-
highlightMoves
Select hexes where this legion can move. -
highlightEngagements
void highlightEngagements() -
setupIcon
private void setupIcon() -
getGUIHexByMasterHex
Do a brute-force search through the hex array, looking for a match. Return the hex, or null if none is found. -
getHexContainingPoint
Return the MasterHex that contains the given point, or null if none does. -
setMarkerForLegion
-
removeMarkerForLegion
-
recreateMarkers
public void recreateMarkers()Create new markers in response to a rescale. -
getMarkerAtPoint
Return the topmost Marker that contains the given point, or null if none does. -
unselectAllHexes
void unselectAllHexes() -
selectHex
-
selectHexes
-
selectHexes
-
focusBackToMasterboard
public void focusBackToMasterboard() -
actOnMisclick
void actOnMisclick() -
isPopupButton
Return true if the MouseEvent e came from button 2 or 3. In theory, isPopupTrigger() is the right way to check for this. In practice, the poor design choice of only having isPopupTrigger() fire on mouse release on Windows makes it useless here. -
actOnLegion
-
actOnHex
-
actOnEditLegionMaybe
-
setEditOngoing
-
setRelocateOngoing
-
viewEditLegion
- Parameters:
legion
- the legion which shall be edited
-
clearEngagingPending
public void clearEngagingPending()tellEngagement calls this, now "engaging" is not pending, instead there is a real engagement to be resolved. -
clearDefenderFlee
public void clearDefenderFlee()We got showConcede or showNegotiate messages, i.e. the phase in which defender might flee is over, thus the message dialog should not tell that any more. This client here should now have some dialog or even the actual battle map anyway. -
attemptEngage
-
repaintAfterOverlayChanged
void repaintAfterOverlayChanged() -
paintComponent
- Overrides:
paintComponent
in classJComponent
-
paintHexes
-
paintHighlights
-
paintMarkers
Paint markers in z-order. -
paintRecruitedChits
-
addPossibleRecruitChits
-
addRecruitedChit
-
cleanRecruitedChit
-
addPossibleRecruitChits
-
clearRecruitedChits
public void clearRecruitedChits() -
clearPossibleRecruitChits
public void clearPossibleRecruitChits() -
paintPossibleRecruitChits
-
paintMovementDie
-
markLegionSkip
public void markLegionSkip() -
jumpToNextUnhandledLegion
private void jumpToNextUnhandledLegion()user pressed "N". Find the next legion that "deserves" handling, activate (as if user had clicked it), and position the mouse cursor over it. -
activateNextLegionAndPlaceMouse
- Parameters:
nextLegion
-
-
getMinimumSize
- Overrides:
getMinimumSize
in classJComponent
-
getPreferredSize
- Overrides:
getPreferredSize
in classJComponent
-
rescale
void rescale() -
deiconify
void deiconify() -
dispose
public void dispose() -
pack
void pack() -
updateComponentTreeUI
void updateComponentTreeUI() -
fullRepaint
void fullRepaint() -
maybeRequestFocusAndToFront
void maybeRequestFocusAndToFront()If and only if stealFocus option is enabled, this does both requestFocus and getFrame().toFront(). -
myTurnStartsActions
void myTurnStartsActions() -
updateLegionsLeftToMusterText
public void updateLegionsLeftToMusterText() -
updateLegionsLeftToMoveText
public void updateLegionsLeftToMoveText(boolean have_roll) -
enableDoneAction
public void enableDoneAction() -
disableDoneAction
Disable the Done action, and update the reason text in bottomBar- Parameters:
reason
- Information why one is not ready to be Done
-
disableDoneActionActivePlayerDoes
Clear bottomBar phase text and call disableDoneAction, as reason the standard text "<active player> doesWhat"- Parameters:
doesWhat
- Information what the active player currently does
-
makeDoneCloseWindow
private void makeDoneCloseWindow() -
setServerClosedMessage
public void setServerClosedMessage(boolean gameOver) -
setReconnectedMessage
public void setReconnectedMessage() -
setReplayMode
public void setReplayMode() -
updateReplayText
public void updateReplayText(int currTurn, int maxTurn) -
setTitleInfoText
-
setTempDisconnectedState
-
setGameOverState
-
setPhaseInfo
-