1 /*
2 */
3
4 package ubc.midp.mobilephoto.core.ui.screens;
5 import javax.microedition.lcdui.Alert;
6 import javax.microedition.lcdui.AlertType;
7 import javax.microedition.lcdui.Canvas;
8 import javax.microedition.lcdui.Command;
9 import javax.microedition.lcdui.Graphics;
10 import javax.microedition.lcdui.Image;
11
12 import lancs.midp.mobilephoto.lib.exceptions.ImageNotFoundException;
13 import lancs.midp.mobilephoto.lib.exceptions.PersistenceMechanismException;
14 import ubc.midp.mobilephoto.core.ui.datamodel.AlbumData;
15 import ubc.midp.mobilephoto.core.util.Constants;
16
17 /**
18 * This screen displays a selected image.
19 */
20 public class PhotoViewScreen extends Canvas {
21
22 String imageName = "";
23 Image image;
24 AlbumData model = null;
25
26 public static final Command backCommand = new Command("Back", Command.BACK, 0);
27
28 public static final Command copyCommand = new Command("Copy", Command.ITEM, 1);
29
30 public static final Command smscopyCommand = new Command("Send Photo by SMS", Command.ITEM, 1);
31 private boolean fromSMS = false;
32
33 /**
34 * Constructor
35 * @param img
36 */
37 public PhotoViewScreen(Image img) {
38
39 //Instead of loading it from a list, pass the image in directly
40 image = img;
41 this.addCommand(backCommand);
42
43 this.addCommand(copyCommand);
44
45 this.addCommand(smscopyCommand);
46 }
47
48 /**
49 * Constructor
50 * @param mod
51 * @param name
52 */
53 public PhotoViewScreen(AlbumData mod, String name) {
54 imageName = name;
55 model = mod;
56 try {
57 loadImage();
58 } catch (ImageNotFoundException e) {
59 Alert alert = new Alert( "Error", "The selected image can not be found", null, AlertType.ERROR);
60 alert.setTimeout(5000);
61 } catch (PersistenceMechanismException e) {
62 Alert alert = new Alert( "Error", "It was not possible to recovery the selected image", null, AlertType.ERROR);
63 alert.setTimeout(5000);
64 }
65 this.addCommand(backCommand);
66 }
67
68 /**
69 * Get the current image from the hashtable stored in the parent midlet.
70 * @throws PersistenceMechanismException
71 * @throws ImageNotFoundException
72 */
73 public void loadImage() throws ImageNotFoundException, PersistenceMechanismException {
74 if (fromSMS)
75 return;
76 image = model.getImageFromRecordStore(null, imageName);
77 }
78
79 /*
80 * (non-Javadoc)
81 * @see javax.microedition.lcdui.Canvas#paint(javax.microedition.lcdui.Graphics)
82 */
83 protected void paint(Graphics g) {
84
85 g.setGrayScale (255);
86
87 //Draw the image - for now start drawing in top left corner of screen
88 g.fillRect (0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
89 System.out.println("Screen size:"+Constants.SCREEN_WIDTH+":"+ Constants.SCREEN_HEIGHT);
90
91 if (image == null)
92 System.out.println("PhotoViewScreen::paint(): Image object was null.");
93
94 g.drawImage (image, 0, 0, Graphics.TOP | Graphics.LEFT);
95
96 }
97
98 public Image getImage(){
99 return image;
100 }
101 public boolean isFromSMS() {
102 return fromSMS;
103 }
104 public void setFromSMS(boolean fromSMS) {
105 this.fromSMS = fromSMS;
106 }
107 }
|