diff options
author | Pacien TRAN-GIRARD | 2014-05-03 20:45:20 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-05-03 20:45:20 +0200 |
commit | 51b8172ae18b9e354e3a97fd26f61b46287e1dcf (patch) | |
tree | 102a0fa17eaf1a0ca6f91524cdba03a9af378daf /src/esieequest/view/app/UserInterface.java | |
parent | 0a845d99117e4d4186d5be5a63cd8719901caafb (diff) | |
download | esieequest-51b8172ae18b9e354e3a97fd26f61b46287e1dcf.tar.gz |
Add placeholder image generation for GUI view
Diffstat (limited to 'src/esieequest/view/app/UserInterface.java')
-rw-r--r-- | src/esieequest/view/app/UserInterface.java | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index ba6d786..66a0af1 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java | |||
@@ -3,8 +3,10 @@ package esieequest.view.app; | |||
3 | import java.awt.BorderLayout; | 3 | import java.awt.BorderLayout; |
4 | import java.awt.Dimension; | 4 | import java.awt.Dimension; |
5 | import java.awt.Font; | 5 | import java.awt.Font; |
6 | import java.awt.Graphics; | ||
6 | import java.awt.event.ActionEvent; | 7 | import java.awt.event.ActionEvent; |
7 | import java.awt.event.ActionListener; | 8 | import java.awt.event.ActionListener; |
9 | import java.awt.image.BufferedImage; | ||
8 | import java.net.URL; | 10 | import java.net.URL; |
9 | import java.util.HashMap; | 11 | import java.util.HashMap; |
10 | 12 | ||
@@ -21,6 +23,7 @@ import esieequest.controller.GameEngine; | |||
21 | import esieequest.controller.commands.Command; | 23 | import esieequest.controller.commands.Command; |
22 | import esieequest.model.events.Quest; | 24 | import esieequest.model.events.Quest; |
23 | import esieequest.model.items.SimpleItem; | 25 | import esieequest.model.items.SimpleItem; |
26 | import esieequest.model.map.Direction; | ||
24 | import esieequest.model.map.Orientation; | 27 | import esieequest.model.map.Orientation; |
25 | import esieequest.model.map.Room; | 28 | import esieequest.model.map.Room; |
26 | import esieequest.model.map.Side; | 29 | import esieequest.model.map.Side; |
@@ -52,6 +55,7 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
52 | public UserInterface() { | 55 | public UserInterface() { |
53 | this.buildUI(); | 56 | this.buildUI(); |
54 | this.inputField.addActionListener(this); | 57 | this.inputField.addActionListener(this); |
58 | this.setActionListener(this); | ||
55 | this.setControlsState(false); | 59 | this.setControlsState(false); |
56 | this.inputField.setEnabled(true); | 60 | this.inputField.setEnabled(true); |
57 | } | 61 | } |
@@ -270,15 +274,21 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
270 | } | 274 | } |
271 | 275 | ||
272 | /** | 276 | /** |
273 | * Updates the room illustration. | 277 | * Updates the room's illustration. |
278 | * | ||
279 | * Placeholder generation from http://stackoverflow.com/a/17802477/1348634 | ||
274 | */ | 280 | */ |
275 | private void updateIllustration(final String locationImageName) { | 281 | private void updateIllustration(final String imageName) { |
276 | String imageName = locationImageName; | 282 | final URL imageURL = this.getClass().getClassLoader().getResource(imageName + ".jpg"); |
277 | if (imageName == null) { | 283 | final StretchIcon imageIcon; |
278 | imageName = "res/img/placeholder.jpg"; | 284 | if (imageURL == null) { |
285 | final BufferedImage bufferedImage = new BufferedImage(240, 135, BufferedImage.TYPE_BYTE_BINARY); | ||
286 | final Graphics graphics = bufferedImage.getGraphics(); | ||
287 | graphics.drawString(imageName, 5, 10 + 5); | ||
288 | imageIcon = new StretchIcon(bufferedImage, true); | ||
289 | } else { | ||
290 | imageIcon = new StretchIcon(imageURL, true); | ||
279 | } | 291 | } |
280 | final URL imageURL = this.getClass().getClassLoader().getResource(imageName); | ||
281 | final StretchIcon imageIcon = new StretchIcon(imageURL, true); | ||
282 | this.imageLabel.setIcon(imageIcon); | 292 | this.imageLabel.setIcon(imageIcon); |
283 | } | 293 | } |
284 | 294 | ||
@@ -314,14 +324,9 @@ abstract class UserInterface implements Viewable, ActionListener { | |||
314 | } | 324 | } |
315 | 325 | ||
316 | @Override | 326 | @Override |
317 | public void updateRoom(final Room room) { | 327 | public void updateLocation(final Room room, final Direction direction, final Side side) { |
318 | // this.updateIllustration(room.getImageName()); | ||
319 | this.echo(room.getInformations()); | 328 | this.echo(room.getInformations()); |
320 | } | 329 | this.updateIllustration(room.name() + "_" + direction.name()); |
321 | |||
322 | @Override | ||
323 | public void updateSide(final Side side) { | ||
324 | // this.updateIllustration(side.getImageName()); | ||
325 | } | 330 | } |
326 | 331 | ||
327 | @Override | 332 | @Override |