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   // #if includeCopyPhoto || includeSmsFeature 
 29   public static final Command copyCommand = new Command("Copy", Command.ITEM, 1); 
 30   // #endif 
 31    
 32   // #ifdef includeSmsFeature 
 33   public static final Command smscopyCommand = new Command("Send Photo by SMS", Command.ITEM, 1); 
 34   private boolean fromSMS = false; 
 35   // #endif 
 36  
 37   /** 
 38    * Constructor 
 39    * @param img 
 40    */ 
 41   public PhotoViewScreen(Image img) { 
 42  
 43     //Instead of loading it from a list, pass the image in directly 
 44     image = img; 
 45     this.addCommand(backCommand); 
 46      
 47     // #if includeCopyPhoto  || includeSmsFeature 
 48     this.addCommand(copyCommand); 
 49     // #endif 
 50      
 51     //#ifdef includeSmsFeature 
 52     this.addCommand(smscopyCommand); 
 53     // #endif 
 54   } 
 55    
 56   /** 
 57    * Constructor 
 58    * @param mod 
 59    * @param name 
 60    */ 
 61   public PhotoViewScreen(AlbumData mod, String name) { 
 62     imageName = name; 
 63     model = mod; 
 64     try { 
 65       loadImage(); 
 66     } catch (ImageNotFoundException e) { 
 67       Alert alert = new Alert( "Error", "The selected image can not be found", null, AlertType.ERROR); 
 68           alert.setTimeout(5000); 
 69     } catch (PersistenceMechanismException e) { 
 70       Alert alert = new Alert( "Error", "It was not possible to recovery the selected image", null, AlertType.ERROR); 
 71           alert.setTimeout(5000); 
 72     }     
 73     this.addCommand(backCommand); 
 74   } 
 75  
 76   /** 
 77    * Get the current image from the hashtable stored in the parent midlet. 
 78    * @throws PersistenceMechanismException  
 79    * @throws ImageNotFoundException  
 80    */ 
 81   public void loadImage() throws ImageNotFoundException, PersistenceMechanismException { 
 82     // #ifdef includeSmsFeature 
 83       if (fromSMS) 
 84         return; 
 85     //#endif 
 86       image = model.getImageFromRecordStore(null, imageName); 
 87   } 
 88    
 89   /* 
 90    *  (non-Javadoc) 
 91    * @see javax.microedition.lcdui.Canvas#paint(javax.microedition.lcdui.Graphics) 
 92    */ 
 93   protected void paint(Graphics g) { 
 94      
 95       g.setGrayScale (255); 
 96  
 97       //Draw the image - for now start drawing in top left corner of screen 
 98       g.fillRect (0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT); 
 99       System.out.println("Screen size:"+Constants.SCREEN_WIDTH+":"+ Constants.SCREEN_HEIGHT); 
100  
101       if (image == null)  
102         System.out.println("PhotoViewScreen::paint(): Image object was null."); 
103          
104       g.drawImage (image, 0, 0, Graphics.TOP | Graphics.LEFT); 
105        
106   } 
107  
108   // #ifdef includeSmsFeature 
109   public Image getImage(){ 
110     return image; 
111   } 
112   public boolean isFromSMS() { 
113     return fromSMS; 
114   } 
115   public void setFromSMS(boolean fromSMS) { 
116     this.fromSMS = fromSMS; 
117   } 
118   // #endif 
119 }    
    |