diff options
Diffstat (limited to 'src/esieequest/view/UserInterface.java')
-rw-r--r-- | src/esieequest/view/UserInterface.java | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/src/esieequest/view/UserInterface.java b/src/esieequest/view/UserInterface.java new file mode 100644 index 0000000..10e0c69 --- /dev/null +++ b/src/esieequest/view/UserInterface.java | |||
@@ -0,0 +1,247 @@ | |||
1 | package esieequest.view; | ||
2 | |||
3 | import javax.swing.JPanel; | ||
4 | import javax.swing.JButton; | ||
5 | import javax.swing.JTextPane; | ||
6 | import javax.swing.JLabel; | ||
7 | import javax.swing.border.EmptyBorder; | ||
8 | |||
9 | import esieequest.model.Game; | ||
10 | |||
11 | import java.awt.BorderLayout; | ||
12 | import java.awt.Dimension; | ||
13 | import java.awt.event.ActionListener; | ||
14 | import java.net.URL; | ||
15 | import java.util.HashMap; | ||
16 | import java.util.Observable; | ||
17 | |||
18 | import javax.swing.JTextField; | ||
19 | |||
20 | import net.homelinux.nikiroo.utils.gui.JBackgroundPanel; | ||
21 | |||
22 | import com.wordpress.tipsforjava.swing.StretchIcon; | ||
23 | |||
24 | import java.awt.Font; | ||
25 | import javax.swing.JTabbedPane; | ||
26 | import javax.swing.JEditorPane; | ||
27 | import javax.swing.JLayeredPane; | ||
28 | |||
29 | public abstract class UserInterface implements View { | ||
30 | |||
31 | protected Game aGame; | ||
32 | |||
33 | private JPanel aLayout; | ||
34 | |||
35 | private JTextPane aQuestTextPane; | ||
36 | private JTextPane aInfoTextPane; | ||
37 | |||
38 | private JLabel aImageLabel; | ||
39 | |||
40 | private HashMap<String, JButton> aGameButtons; | ||
41 | private HashMap<String, JButton> aControlButtons; | ||
42 | private JTextField aInputField; | ||
43 | |||
44 | /** | ||
45 | * Create the panel. | ||
46 | */ | ||
47 | public UserInterface() { | ||
48 | |||
49 | this.aLayout = new JPanel(); | ||
50 | this.aLayout.setLayout(new BorderLayout(0, 0)); | ||
51 | |||
52 | JPanel vMenuPanel = new JPanel(); | ||
53 | this.aLayout.add(vMenuPanel, BorderLayout.NORTH); | ||
54 | vMenuPanel.setLayout(new BorderLayout(0, 0)); | ||
55 | |||
56 | JPanel vQuestPanel = new JPanel(); | ||
57 | vMenuPanel.add(vQuestPanel, BorderLayout.CENTER); | ||
58 | |||
59 | this.aQuestTextPane = new JTextPane(); | ||
60 | this.aQuestTextPane.setEditable(false); | ||
61 | this.aQuestTextPane.setText("ESIEEquest"); | ||
62 | vQuestPanel.add(this.aQuestTextPane); | ||
63 | |||
64 | JPanel vGamePanel = new JPanel(); | ||
65 | vMenuPanel.add(vGamePanel, BorderLayout.WEST); | ||
66 | |||
67 | JButton vNewButton = new JButton("New"); | ||
68 | vNewButton.setToolTipText("New game"); | ||
69 | vGamePanel.add(vNewButton); | ||
70 | |||
71 | JButton vSoundButton = new JButton("Sound"); | ||
72 | vSoundButton.setToolTipText("Toggle sound"); | ||
73 | vGamePanel.add(vSoundButton); | ||
74 | |||
75 | JPanel filePanel = new JPanel(); | ||
76 | vMenuPanel.add(filePanel, BorderLayout.EAST); | ||
77 | |||
78 | JButton vLoadButton = new JButton("Load"); | ||
79 | vLoadButton.setToolTipText("Load a game"); | ||
80 | filePanel.add(vLoadButton); | ||
81 | |||
82 | JButton vSaveButton = new JButton("Save"); | ||
83 | vSaveButton.setToolTipText("Save the current game"); | ||
84 | filePanel.add(vSaveButton); | ||
85 | |||
86 | JPanel vImagePanel = new JPanel(); | ||
87 | aLayout.add(vImagePanel, BorderLayout.CENTER); | ||
88 | vImagePanel.setLayout(new BorderLayout(0, 0)); | ||
89 | |||
90 | this.aImageLabel = new JLabel(); | ||
91 | vImagePanel.add(this.aImageLabel); | ||
92 | |||
93 | JPanel vUserPanel = new JPanel(); | ||
94 | this.aLayout.add(vUserPanel, BorderLayout.SOUTH); | ||
95 | vUserPanel.setLayout(new BorderLayout(0, 0)); | ||
96 | |||
97 | JPanel vDispPanel = new JPanel(); | ||
98 | vDispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); | ||
99 | vUserPanel.add(vDispPanel, BorderLayout.CENTER); | ||
100 | vDispPanel.setLayout(new BorderLayout(0, 0)); | ||
101 | |||
102 | this.aInfoTextPane = new JTextPane(); | ||
103 | this.aInfoTextPane.setEditable(false); | ||
104 | this.aInfoTextPane.setText("Welcome to ESIEEquest!"); | ||
105 | vDispPanel.add(this.aInfoTextPane); | ||
106 | |||
107 | aInputField = new JTextField(); | ||
108 | vDispPanel.add(aInputField, BorderLayout.SOUTH); | ||
109 | aInputField.setColumns(10); | ||
110 | |||
111 | JPanel vControlPanel = new JPanel(); | ||
112 | vControlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); | ||
113 | vUserPanel.add(vControlPanel, BorderLayout.EAST); | ||
114 | vControlPanel.setLayout(new BorderLayout(0, 0)); | ||
115 | |||
116 | JPanel vTopControlPanel = new JPanel(); | ||
117 | vControlPanel.add(vTopControlPanel, BorderLayout.NORTH); | ||
118 | vTopControlPanel.setLayout(new BorderLayout(0, 0)); | ||
119 | |||
120 | JButton vForwardButton = new JButton("↥"); | ||
121 | vForwardButton.setFont(new Font("Dialog", Font.BOLD, 19)); | ||
122 | vForwardButton.setToolTipText("Go forward"); | ||
123 | vTopControlPanel.add(vForwardButton, BorderLayout.CENTER); | ||
124 | |||
125 | JButton vInventoryButton = new JButton("⇱"); | ||
126 | vInventoryButton.setFont(new Font("Dialog", Font.BOLD, 19)); | ||
127 | vInventoryButton.setToolTipText("Use item"); | ||
128 | vTopControlPanel.add(vInventoryButton, BorderLayout.WEST); | ||
129 | |||
130 | JButton vActionButton = new JButton("⇲"); | ||
131 | vActionButton.setFont(new Font("Dialog", Font.BOLD, 19)); | ||
132 | vActionButton.setToolTipText("Talk/Take item"); | ||
133 | vTopControlPanel.add(vActionButton, BorderLayout.EAST); | ||
134 | |||
135 | JPanel vBottomControlPanel = new JPanel(); | ||
136 | vControlPanel.add(vBottomControlPanel, BorderLayout.SOUTH); | ||
137 | vBottomControlPanel.setLayout(new BorderLayout(0, 0)); | ||
138 | |||
139 | JButton vBackButton = new JButton("↧"); | ||
140 | vBackButton.setFont(new Font("Dialog", Font.BOLD, 19)); | ||
141 | vBackButton.setToolTipText("Go back"); | ||
142 | vBottomControlPanel.add(vBackButton, BorderLayout.CENTER); | ||
143 | |||
144 | JButton vLeftButton = new JButton("↰"); | ||
145 | vLeftButton.setFont(new Font("Dialog", Font.BOLD, 19)); | ||
146 | vLeftButton.setToolTipText("Turn left"); | ||
147 | vBottomControlPanel.add(vLeftButton, BorderLayout.WEST); | ||
148 | |||
149 | JButton vRightButton = new JButton("↱"); | ||
150 | vRightButton.setFont(new Font("Dialog", Font.BOLD, 19)); | ||
151 | vRightButton.setToolTipText("Turn right"); | ||
152 | vBottomControlPanel.add(vRightButton, BorderLayout.EAST); | ||
153 | |||
154 | Dimension vSquareButton = new Dimension(50, 50); | ||
155 | vForwardButton.setPreferredSize(vSquareButton); | ||
156 | vInventoryButton.setPreferredSize(vSquareButton); | ||
157 | vActionButton.setPreferredSize(vSquareButton); | ||
158 | vBackButton.setPreferredSize(vSquareButton); | ||
159 | vLeftButton.setPreferredSize(vSquareButton); | ||
160 | vRightButton.setPreferredSize(vSquareButton); | ||
161 | |||
162 | vNewButton.setActionCommand("new"); | ||
163 | vSoundButton.setActionCommand("sound"); | ||
164 | vLoadButton.setActionCommand("load"); | ||
165 | vSaveButton.setActionCommand("save"); | ||
166 | |||
167 | vForwardButton.setActionCommand("forward"); | ||
168 | vInventoryButton.setActionCommand("inventory"); | ||
169 | vActionButton.setActionCommand("do"); | ||
170 | vBackButton.setActionCommand("back"); | ||
171 | vLeftButton.setActionCommand("turn left"); | ||
172 | vRightButton.setActionCommand("turn right"); | ||
173 | |||
174 | this.aGameButtons = new HashMap<String, JButton>(); | ||
175 | |||
176 | this.aGameButtons.put("vNewButton", vNewButton); | ||
177 | this.aGameButtons.put("vSoundButton", vSoundButton); | ||
178 | this.aGameButtons.put("vLoadButton", vLoadButton); | ||
179 | this.aGameButtons.put("vSaveButton", vSaveButton); | ||
180 | |||
181 | this.aControlButtons = new HashMap<String, JButton>(); | ||
182 | |||
183 | this.aControlButtons.put("vForwardButton", vForwardButton); | ||
184 | this.aControlButtons.put("vInventoryButton", vInventoryButton); | ||
185 | this.aControlButtons.put("vActionButton", vActionButton); | ||
186 | this.aControlButtons.put("vBackButton", vBackButton); | ||
187 | this.aControlButtons.put("vLeftButton", vLeftButton); | ||
188 | this.aControlButtons.put("vRightButton", vRightButton); | ||
189 | |||
190 | } | ||
191 | |||
192 | @Override | ||
193 | public void update(final Observable pObservable, final Object pArgument) { | ||
194 | // TODO Auto-generated method stub | ||
195 | this.clearInputField(); | ||
196 | this.updateIllustration(); | ||
197 | this.setControlsState(this.aGame.isRunning()); | ||
198 | } | ||
199 | |||
200 | public JPanel getLayout() { | ||
201 | return this.aLayout; | ||
202 | } | ||
203 | |||
204 | private void setActionListener(final HashMap<String, JButton> vHashMap, | ||
205 | final ActionListener pActionListener) { | ||
206 | for (JButton vButton : vHashMap.values()) { | ||
207 | vButton.addActionListener(pActionListener); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | public void setActionListener(final ActionListener pActionListener) { | ||
212 | this.aInputField.addActionListener(pActionListener); | ||
213 | this.setActionListener(this.aGameButtons, pActionListener); | ||
214 | this.setActionListener(this.aControlButtons, pActionListener); | ||
215 | } | ||
216 | |||
217 | private void clearInputField() { | ||
218 | this.aInputField.setText(null); | ||
219 | } | ||
220 | |||
221 | private void setControlsState(final boolean pState) { | ||
222< |