aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/view/app/UserInterface.java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-03-10 15:55:25 +0100
committerPacien TRAN-GIRARD2014-03-10 15:55:25 +0100
commit67503963112b3d3a225ae00ebc899a34e54b6519 (patch)
treeefc2f288fd57e742c6921b5713695c54364d333f /src/esieequest/view/app/UserInterface.java
parent44260a59df288b2c1225ec0a70cb02c215844f69 (diff)
downloadesieequest-67503963112b3d3a225ae00ebc899a34e54b6519.tar.gz
Refactoring (structure + doc)
Diffstat (limited to 'src/esieequest/view/app/UserInterface.java')
-rw-r--r--src/esieequest/view/app/UserInterface.java164
1 files changed, 108 insertions, 56 deletions
diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java
index 4f87ef6..b6035c5 100644
--- a/src/esieequest/view/app/UserInterface.java
+++ b/src/esieequest/view/app/UserInterface.java
@@ -1,29 +1,32 @@
1package esieequest.view.app; 1package esieequest.view.app;
2 2
3import javax.swing.JPanel;
4import javax.swing.JButton;
5import javax.swing.JTextPane;
6import javax.swing.JLabel;
7import javax.swing.border.EmptyBorder;
8
9import esieequest.controller.GameEngine;
10import esieequest.model.Game;
11import esieequest.view.View;
12
13import java.awt.BorderLayout; 3import java.awt.BorderLayout;
14import java.awt.Dimension; 4import java.awt.Dimension;
5import java.awt.Font;
15import java.awt.event.ActionEvent; 6import java.awt.event.ActionEvent;
16import java.awt.event.ActionListener; 7import java.awt.event.ActionListener;
17import java.net.URL; 8import java.net.URL;
18import java.util.HashMap; 9import java.util.HashMap;
19 10
11import javax.swing.JButton;
12import javax.swing.JLabel;
13import javax.swing.JPanel;
20import javax.swing.JTextField; 14import javax.swing.JTextField;
15import javax.swing.JTextPane;
16import javax.swing.border.EmptyBorder;
21 17
22import com.wordpress.tipsforjava.swing.StretchIcon; 18import com.wordpress.tipsforjava.swing.StretchIcon;
23 19
24import java.awt.Font; 20import esieequest.controller.GameEngine;
21import esieequest.model.Game;
22import esieequest.view.View;
25 23
26public abstract class UserInterface implements View, ActionListener { 24/**
25 * The Swing based graphical user interface.
26 *
27 * @author Pacien TRAN-GIRARD
28 */
29abstract class UserInterface implements View, ActionListener {
27 30
28 protected Game game; 31 protected Game game;
29 private GameEngine gameEngine; 32 private GameEngine gameEngine;
@@ -40,24 +43,27 @@ public abstract class UserInterface implements View, ActionListener {
40 private JTextField inputField; 43 private JTextField inputField;
41 44
42 /** 45 /**
43 * Create the panel. 46 * The default constructor.
44 */ 47 */
45 public UserInterface() { 48 public UserInterface() {
46 this.buildUI(); 49 this.buildUI();
47 this.inputField.addActionListener(this); 50 this.inputField.addActionListener(this);
48 this.setControlsState(false); 51 this.setControlsState(false);
49 inputField.setEnabled(true); 52 this.inputField.setEnabled(true);
50 } 53 }
51 54
55 /**
56 * Creates the interface widgets.
57 */
52 private void buildUI() { 58 private void buildUI() {
53 this.layout = new JPanel(); 59 this.layout = new JPanel();
54 this.layout.setLayout(new BorderLayout(0, 0)); 60 this.layout.setLayout(new BorderLayout(0, 0));
55 61
56 JPanel menuPanel = new JPanel(); 62 final JPanel menuPanel = new JPanel();
57 this.layout.add(menuPanel, BorderLayout.NORTH); 63 this.layout.add(menuPanel, BorderLayout.NORTH);
58 menuPanel.setLayout(new BorderLayout(0, 0)); 64 menuPanel.setLayout(new BorderLayout(0, 0));
59 65
60 JPanel questPanel = new JPanel(); 66 final JPanel questPanel = new JPanel();
61 menuPanel.add(questPanel, BorderLayout.CENTER); 67 menuPanel.add(questPanel, BorderLayout.CENTER);
62 68
63 this.questTextPane = new JTextPane(); 69 this.questTextPane = new JTextPane();
@@ -65,40 +71,40 @@ public abstract class UserInterface implements View, ActionListener {
65 this.questTextPane.setText("ESIEEquest"); 71 this.questTextPane.setText("ESIEEquest");
66 questPanel.add(this.questTextPane); 72 questPanel.add(this.questTextPane);
67 73
68 JPanel gamePanel = new JPanel(); 74 final JPanel gamePanel = new JPanel();
69 menuPanel.add(gamePanel, BorderLayout.WEST); 75 menuPanel.add(gamePanel, BorderLayout.WEST);
70 76
71 JButton newButton = new JButton("New"); 77 final JButton newButton = new JButton("New");
72 newButton.setToolTipText("New game"); 78 newButton.setToolTipText("New game");
73 gamePanel.add(newButton); 79 gamePanel.add(newButton);
74 80
75 JButton soundButton = new JButton("Sound"); 81 final JButton soundButton = new JButton("Sound");
76 soundButton.setToolTipText("Toggle sound"); 82 soundButton.setToolTipText("Toggle sound");
77 gamePanel.add(soundButton); 83 gamePanel.add(soundButton);
78 84
79 JPanel filePanel = new JPanel(); 85 final JPanel filePanel = new JPanel();
80 menuPanel.add(filePanel, BorderLayout.EAST); 86 menuPanel.add(filePanel, BorderLayout.EAST);
81 87
82 JButton loadButton = new JButton("Load"); 88 final JButton loadButton = new JButton("Load");
83 loadButton.setToolTipText("Load a game"); 89 loadButton.setToolTipText("Load a game");
84 filePanel.add(loadButton); 90 filePanel.add(loadButton);
85 91
86 JButton saveButton = new JButton("Save"); 92 final JButton saveButton = new JButton("Save");
87 saveButton.setToolTipText("Save the current game"); 93 saveButton.setToolTipText("Save the current game");
88 filePanel.add(saveButton); 94 filePanel.add(saveButton);
89 95
90 JPanel imagePanel = new JPanel(); 96 final JPanel imagePanel = new JPanel();
91 layout.add(imagePanel, BorderLayout.CENTER); 97 this.layout.add(imagePanel, BorderLayout.CENTER);
92 imagePanel.setLayout(new BorderLayout(0, 0)); 98 imagePanel.setLayout(new BorderLayout(0, 0));
93 99
94 this.imageLabel = new JLabel(); 100 this.imageLabel = new JLabel();
95 imagePanel.add(this.imageLabel); 101 imagePanel.add(this.imageLabel);
96 102
97 JPanel userPanel = new JPanel(); 103 final JPanel userPanel = new JPanel();
98 this.layout.add(userPanel, BorderLayout.SOUTH); 104 this.layout.add(userPanel, BorderLayout.SOUTH);
99 userPanel.setLayout(new BorderLayout(0, 0)); 105 userPanel.setLayout(new BorderLayout(0, 0));
100 106
101 JPanel dispPanel = new JPanel(); 107 final JPanel dispPanel = new JPanel();
102 dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); 108 dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0));
103 userPanel.add(dispPanel, BorderLayout.CENTER); 109 userPanel.add(dispPanel, BorderLayout.CENTER);
104 dispPanel.setLayout(new BorderLayout(0, 0)); 110 dispPanel.setLayout(new BorderLayout(0, 0));
@@ -108,54 +114,54 @@ public abstract class UserInterface implements View, ActionListener {
108 this.infoTextPane.setText("Welcome to ESIEEquest!"); 114 this.infoTextPane.setText("Welcome to ESIEEquest!");
109 dispPanel.add(this.infoTextPane); 115 dispPanel.add(this.infoTextPane);
110 116
111 inputField = new JTextField(); 117 this.inputField = new JTextField();
112 dispPanel.add(inputField, BorderLayout.SOUTH); 118 dispPanel.add(this.inputField, BorderLayout.SOUTH);
113 inputField.setColumns(10); 119 this.inputField.setColumns(10);
114 120
115 JPanel controlPanel = new JPanel(); 121 final JPanel controlPanel = new JPanel();
116 controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); 122 controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
117 userPanel.add(controlPanel, BorderLayout.EAST); 123 userPanel.add(controlPanel, BorderLayout.EAST);
118 controlPanel.setLayout(new BorderLayout(0, 0)); 124 controlPanel.setLayout(new BorderLayout(0, 0));
119 125
120 JPanel topControlPanel = new JPanel(); 126 final JPanel topControlPanel = new JPanel();
121 controlPanel.add(topControlPanel, BorderLayout.NORTH); 127 controlPanel.add(topControlPanel, BorderLayout.NORTH);
122 topControlPanel.setLayout(new BorderLayout(0, 0)); 128 topControlPanel.setLayout(new BorderLayout(0, 0));
123 129
124 JButton forwardButton = new JButton("↥"); 130 final JButton forwardButton = new JButton("↥");
125 forwardButton.setFont(new Font("Dialog", Font.BOLD, 19)); 131 forwardButton.setFont(new Font("Dialog", Font.BOLD, 19));
126 forwardButton.setToolTipText("Go forward"); 132 forwardButton.setToolTipText("Go forward");
127 topControlPanel.add(forwardButton, BorderLayout.CENTER); 133 topControlPanel.add(forwardButton, BorderLayout.CENTER);
128 134
129 JButton inventoryButton = new JButton("⇱"); 135 final JButton inventoryButton = new JButton("⇱");
130 inventoryButton.setFont(new Font("Dialog", Font.BOLD, 19)); 136 inventoryButton.setFont(new Font("Dialog", Font.BOLD, 19));
131 inventoryButton.setToolTipText("Use item"); 137 inventoryButton.setToolTipText("Use item");
132 topControlPanel.add(inventoryButton, BorderLayout.WEST); 138 topControlPanel.add(inventoryButton, BorderLayout.WEST);
133 139
134 JButton actionButton = new JButton("⇲"); 140 final JButton actionButton = new JButton("⇲");
135 actionButton.setFont(new Font("Dialog", Font.BOLD, 19)); 141 actionButton.setFont(new Font("Dialog", Font.BOLD, 19));
136 actionButton.setToolTipText("Talk/Take item"); 142 actionButton.setToolTipText("Talk/Take item");
137 topControlPanel.add(actionButton, BorderLayout.EAST); 143 topControlPanel.add(actionButton, BorderLayout.EAST);
138 144
139 JPanel bottomControlPanel = new JPanel(); 145 final JPanel bottomControlPanel = new JPanel();
140 controlPanel.add(bottomControlPanel, BorderLayout.SOUTH); 146 controlPanel.add(bottomControlPanel, BorderLayout.SOUTH);
141