Skip to content

Commit

Permalink
EDIT: Smaller changes to enable key bindings in the game statistics UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaglam committed May 16, 2020
1 parent 0ebd680 commit 9d53473
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/main/java/carcassonne/control/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MainController {
private final Map<Class<? extends AbstractControllerState>, AbstractControllerState> stateMap;
private AbstractControllerState currentState;
private final GameSettings settings;
private final GlobalKeyBindingManager keyBindings;

/**
* Basic constructor. Creates the view and the model of the game.
Expand All @@ -43,7 +44,7 @@ public MainController() {
mainGUI = new MainGUI(this);
rotationGUI = new RotationGUI(this, mainGUI);
placementGUI = new PlacementGUI(this, mainGUI);
GlobalKeyBindingManager keyBindings = new GlobalKeyBindingManager(this, mainGUI, rotationGUI);
keyBindings = new GlobalKeyBindingManager(this, mainGUI, rotationGUI);
mainGUI.addKeyBindings(keyBindings);
rotationGUI.addKeyBindings(keyBindings);
placementGUI.addKeyBindings(keyBindings);
Expand Down Expand Up @@ -138,6 +139,14 @@ public void updateStates(Round newRound, Grid newGrid) {
}
}

/**
* Getter for the global key binding manager.
* @return the global key bindings.
*/
public GlobalKeyBindingManager getKeyBindings() {
return keyBindings;
}

/**
* Getter for the {@link GameSettings}, which grants access to the games settings.
* @return the {@link GameSettings} instance.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/carcassonne/control/state/StateGameOver.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ protected void entry() {
updateStackSize();
mainGUI.resetMenuState();
GameMessage.showMessage(GAME_OVER_MESSAGE + round.getWinningPlayers());
gameStatistics = new GameStatisticsGUI(mainGUI, controller, round); // TODO (HIGH) key bindings for this UI?
gameStatistics = new GameStatisticsGUI(mainGUI, controller, round);
gameStatistics.addKeyBindings(controller.getKeyBindings());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package carcassonne.view.main;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

Expand Down Expand Up @@ -28,7 +29,7 @@ public WindowMaximizationAdapter(JFrame frame) {
public void windowActivated(WindowEvent event) {
if (!maximized) {
maximized = true;
frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
frame.setExtendedState(frame.getExtendedState() | Frame.MAXIMIZED_BOTH);
}

}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/carcassonne/view/tertiary/GameStatisticsGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;

import carcassonne.control.MainController;
import carcassonne.model.Round;
import carcassonne.view.GlobalKeyBindingManager;
import carcassonne.view.main.MainGUI;

/**
Expand Down Expand Up @@ -60,6 +64,16 @@ private void buildTable(Round round) {
table.setBackground(BODY_COLOR);
}

/**
* Adds the global key bindings to this UI.
* @param keyBindings are the global key bindings.
*/
public void addKeyBindings(GlobalKeyBindingManager keyBindings) {
InputMap inputMap = table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = table.getActionMap();
keyBindings.addKeyBindingsToMaps(inputMap, actionMap);
}

/**
* Hides and disposes the GUI.
*/
Expand Down

0 comments on commit 9d53473

Please sign in to comment.