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) classprivate final class(package private) class(package private) class(package private) class(package private) classNested classes/interfaces inherited from class JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate AbstractActionprivate MasterBoard.BottomBarour own little bar implementationprivate Stringprivate Map<String, JCheckBoxMenuItem> private AbstractActionprivate static final Stringprivate AbstractActionprivate AbstractActionprivate static final Stringprivate AbstractActionprivate Clientprivate AbstractActionprivate final Containerprivate booleanIn 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 Stringprivate AbstractAction(package private) EditLegionprivate JMenuprivate AbstractActionprivate MasterHexengage() 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 Stringprivate AbstractActionprivate booleanprivate final ClientGUIprivate GUIMasterHex[][]private MasterBoard.InfoPopupHandlerprivate ItemListenerprivate static final Stringprivate AbstractActionprivate PointLast 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 AbstractActionprivate static final Loggerprivate KFrameprivate final MasterBoard.MasterBoardWindowHandlerprivate AbstractActionprivate static final Stringprivate AbstractActionprivate Imageprivate booleanprivate JMenuprivate booleanprivate JPopupMenuprivate JPopupMenuprivate static final Stringprivate AbstractActionprivate AbstractAction(package private) EditLegionprivate booleanShow the message that "saving during engagement/battle will store the last commit point" only once each game - flag that it has been shownprivate AbstractActionprivate static final Stringprivate AbstractActionprivate SaveWindowprivate JScrollPaneThe scrollbarspanel, needed to correct lastPoint.private ShowHelpDocprivate ShowReadmeprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionprivate static final Stringprivate AbstractActionFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidactivateNextLegionAndPlaceMouse(Legion nextLegion) voidactOnEditLegionMaybe(Legion legion) private voidprivate voidactOnLegion(LegionClientSide legion, MasterHex hex) (package private) voidprivate JCheckBoxMenuItemaddCheckBox(JMenu menu, String name, int mnemonic) private voidaddPossibleRecruitChits(List<CreatureType> imageNameList, MasterHex masterHex) voidaddPossibleRecruitChits(LegionClientSide legion, Set<MasterHex> hexes) (package private) voidaddRecruitedChit(Legion legion) (package private) voidadjustCheckboxIfNeeded(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) voidThis is incredibly inefficient.private voidalignLegions(Set<MasterHex> hexes) (package private) voidalignLegions(MasterHex masterHex) private voidattemptEngage(MasterHex hex) private voidprivate void(package private) voidcleanRecruitedChit(LegionClientSide legion) voidWe got showConcede or showNegotiate messages, i.e.voidtellEngagement calls this, now "engaging" is not pending, instead there is a real engagement to be resolved.voidvoidprivate Constants.ConfirmValsconfirmDialog(String text, int count) (package private) voidvoiddisableDoneAction(String reason) Disable the Done action, and update the reason text in bottomBarprivate voiddisableDoneActionActivePlayerDoes(String doesWhat) Clear bottomBar phase text and call disableDoneAction, as reason the standard text "<active player> doesWhat"voiddispose()private voidFinishes the current phase.voidvoidvoidvoid(package private) void(package private) KFramegetFrame()(package private) GUIMasterHexgetGUIHexByMasterHex(MasterHex masterHex) Do a brute-force search through the hex array, looking for a match.private GUIMasterHexgetHexContainingPoint(Point point) Return the MasterHex that contains the given point, or null if none does.private Stringprivate MarkergetMarkerAtPoint(Point point) Return the topmost Marker that contains the given point, or null if none does.private MasterBoardTODO this should probably be stored as member, possibly instead of the client class.(package private) voidprivate voidhighlightMoves(LegionClientSide legion) Select hexes where this legion can move.(package private) voidHighlight all hexes with legions that (still) can do recruiting(package private) void(package private) voidprivate static booleanReturn true if the MouseEvent e came from button 2 or 3.private voiduser pressed "N".private voidvoid(package private) voidIf and only if stealFocus option is enabled, this does both requestFocus and getFrame().toFront().(package private) void(package private) voidpack()voidprivate voidprivate voidprivate voidPaint markers in z-order.private voidprivate voidprivate voidvoidCreate new markers in response to a rescale.(package private) voidremoveMarkerForLegion(Legion legion) (package private) void(package private) voidrescale()private booleanInform 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) voidprivate voidselectHexes(Set<MasterHex> hexes) private voidselectHexes(Set<MasterHex> hexes, Color color) voidsetBoardActive(boolean val) voidsetEditOngoing(EditLegion editLegion) voidsetGameOverState(String message) (package private) voidsetMarkerForLegion(Legion legion, Marker marker) void(package private) voidsetPendingText(String text) voidsetPhaseInfo(String message) voidvoidsetRelocateOngoing(EditLegion editLegion) voidvoidsetServerClosedMessage(boolean gameOver) voidsetTempDisconnectedState(String message) private voidsetTitleInfoText(String text) private voidprivate voidsetupAsInactivePlayer(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) voidprivate voidprivate void(package private) void(package private) voidprivate voidsetupPhasePreparations(String titleText) (package private) voidShow which player owns this board.private void(package private) void(package private) voidsetupTitleForMovementRoll(int roll) private voidvoid(package private) void(package private) voidvoidvoidupdateLegionsLeftToMoveText(boolean have_roll) voidvoidupdateReplayText(int currTurn, int maxTurn) voidviewEditLegion(LegionClientSide legion) voidviewLegions(Point point) Methods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class 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, updateMethods inherited from class 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, validateTreeMethods inherited from class 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
-
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:
paintComponentin 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:
getMinimumSizein classJComponent
-
getPreferredSize
- Overrides:
getPreferredSizein 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
-