javauis/mmapi_qt/baseline/javasrc/com/nokia/microedition/media/animation/VideoControl.java
changeset 35 85266cc22c7f
parent 26 dc7c549001d5
child 48 e0d6e9bd3ca7
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
    27 import javax.microedition.media.MediaException;
    27 import javax.microedition.media.MediaException;
    28 import javax.microedition.media.Player;
    28 import javax.microedition.media.Player;
    29 import javax.microedition.media.PlayerListener;
    29 import javax.microedition.media.PlayerListener;
    30 
    30 
    31 import org.eclipse.ercp.swt.mobile.MobileShell;
    31 import org.eclipse.ercp.swt.mobile.MobileShell;
       
    32 import org.eclipse.swt.events.PaintEvent;
       
    33 import org.eclipse.swt.events.PaintListener;
    32 import org.eclipse.swt.graphics.Point;
    34 import org.eclipse.swt.graphics.Point;
    33 import org.eclipse.swt.graphics.Rectangle;
    35 import org.eclipse.swt.graphics.Rectangle;
       
    36 import org.eclipse.swt.widgets.Composite;
    34 import org.eclipse.swt.widgets.Control;
    37 import org.eclipse.swt.widgets.Control;
    35 import org.eclipse.swt.widgets.Display;
    38 import org.eclipse.swt.widgets.Display;
    36 import org.eclipse.swt.widgets.ProxyControl;
    39 import org.eclipse.swt.widgets.ProxyControl;
    37 import org.eclipse.swt.widgets.Shell;
    40 import org.eclipse.swt.widgets.Shell;
    38 
    41 
    48 import com.nokia.mj.impl.rt.support.ApplicationUtils;
    51 import com.nokia.mj.impl.rt.support.ApplicationUtils;
    49 import com.nokia.mj.impl.utils.Logger;
    52 import com.nokia.mj.impl.utils.Logger;
    50 
    53 
    51 
    54 
    52 public class VideoControl extends ControlImpl implements
    55 public class VideoControl extends ControlImpl implements
    53 		javax.microedition.media.control.VideoControl , ItemControlStateChangeListener{
    56         javax.microedition.media.control.VideoControl , ItemControlStateChangeListener
    54 
    57 {
    55 	//	Following variable has been taken from VideoControl class
    58 
    56 	private static final String GUI_OBJECT_CLASS_NAME =
    59     //  Following variable has been taken from VideoControl class
       
    60     private static final String GUI_OBJECT_CLASS_NAME =
    57         "javax.microedition.lcdui.Item";
    61         "javax.microedition.lcdui.Item";
    58 	// lcdui package used with UiToolkitRegister
    62     // lcdui package used with UiToolkitRegister
    59     private static String LCDUI_PACKAGE =
    63     private static String LCDUI_PACKAGE =
    60         "javax.microedition.lcdui";
    64         "javax.microedition.lcdui";
    61     // eswt package used with UiToolkitRegister
    65     // eswt package used with UiToolkitRegister
    62     private static String ESWT_PACKAGE = "org.eclipse.swt.widgets";
    66     private static String ESWT_PACKAGE = "org.eclipse.swt.widgets";
    63     // ToolkitRegister class name used with eswt and lcdui
    67     // ToolkitRegister class name used with eSWT and LCDUI
    64     private static String DISPLAY = ".Display";
    68     private static String DISPLAY = ".Display";
    65 
    69 
    66     // class name used to check if eswt is included
    70     // class name used to check if eswt is included
    67     private static String LISTENER = ".Listener";
    71     private static String LISTENER = ".Listener";
    68 
    72 
    69     // class name used to check if eswt is included
    73     // class name used to check if eswt is included
    70     private static String ESWT_CONTROL = ".control";
    74     private static String ESWT_CONTROL = ".control";
    71     
    75 
    72 	private static final int NOT_INITIALIZED = -1;
    76     private static final int NOT_INITIALIZED = -1;
    73 	protected int iStatus = NOT_INITIALIZED;
    77     protected int iStatus = NOT_INITIALIZED;
    74 	private static final int UNDEFINED_RETURN_VALUE=0;
    78     private static final int UNDEFINED_RETURN_VALUE=0;
    75 	// For integrating with eSWT API  
    79     // For integrating with eSWT API
    76 	private Display iDisplay; 
    80     private Display iDisplay;
    77 	// This is reference of eSWT Control, don't get confused with the Player Control 
    81     // This is reference of eSWT Control, don't get confused with the Player Control
    78 	private Control iControl;
    82     private Control iControl;
    79 	/**
    83     /**
    80 	* When video display is set to full screen mode, old
    84     * When video display is set to full screen mode, old
    81     * video position & size is stored to this member. When
    85     * video position & size is stored to this member. When
    82     * full screen mode is turned off, this member is used to
    86     * full screen mode is turned off, this member is used to
    83     * find out if display size has been changed during full
    87     * find out if display size has been changed during full
    84     * screen mode. This is needed to generate a SIZE_CHANGED
    88     * screen mode. This is needed to generate a SIZE_CHANGED
    85     * event.
    89     * event.
    86     */
    90     */
    87 	private Point iOldDisplaySize;
    91     private Point iOldDisplaySize;
    88 	/**
    92     /**
    89 	 * A CustomItem which needs to be returned in case USE_GUI_PRIMITIVE and null to MIDlet
    93      * A CustomItem which needs to be returned in case USE_GUI_PRIMITIVE and null to MIDlet
    90 	 * from initDisplayMode function. 
    94      * from initDisplayMode function.
    91 	 */
    95      */
    92 	// Global??? yes because we need to remove it from player listener, while finalizer will be called
    96     // Global??? yes because we need to remove it from player listener, while finalizer will be called
    93 	private VideoItem iVideoItem;
    97     private VideoItem iVideoItem;
    94 	
    98 
    95 	
    99 
    96 	/**
   100     /**
    97 	 * Constructor of VideoControl  
   101      * Constructor of VideoControl
    98 	 * @param player
   102      * @param player
    99 	 */
   103      */
   100 	public VideoControl(Player player){
   104     public VideoControl(Player player)
   101 		this.iPlayer=player;
   105     {
   102 	}
   106         this.iPlayer=player;
   103 	/**
   107     }
   104 	 * 
   108     /**
   105 	 */
   109      *
   106 	private Finalizer mFinalizer = new Finalizer(){
   110      */
   107         public void finalizeImpl(){
   111     private Finalizer mFinalizer = new Finalizer()
       
   112     {
       
   113         public void finalizeImpl()
       
   114         {
   108             doFinalize();
   115             doFinalize();
   109         }
   116         }
   110     };
   117     };
   111 	/**
   118     /**
   112 	 * 
   119      *
   113 	 */
   120      */
   114 	final void registeredFinalize() {
   121     final void registeredFinalize()
   115 		if (iVideoItem != null) {
   122     {
   116 			iPlayer.removePlayerListener(iVideoItem);
   123         if (iVideoItem != null)
   117 		}
   124         {
   118 	}
   125             iPlayer.removePlayerListener(iVideoItem);
   119 
   126         }
   120 	/**
   127     }
   121 	 * 
   128 
   122 	 */
   129     /**
   123 	private void doFinalize() {
   130      *
   124 		if (mFinalizer != null) {
   131      */
   125 			registeredFinalize();
   132     private void doFinalize()
   126 			mFinalizer = null;
   133     {
   127 		}
   134         if (mFinalizer != null)
   128 	}
   135         {
   129 	
   136             registeredFinalize();
   130 	/**
   137             mFinalizer = null;
   131 	 * Return the actual height of the current render video. 
   138         }
   132 	 * @return height of the display video 
   139     }
   133 	 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. 
   140 
   134 	 */
   141     /**
   135 	public int getDisplayHeight() {
   142      * Return the actual height of the current render video.
   136 		// this function can't be called, when the player is in closed state
   143      * @return height of the display video
   137 		// or until initDisplayMode function is not called
   144      * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called.
   138 		checkState();
   145      */
   139 		if (iStatus == NOT_INITIALIZED) {
   146     public int getDisplayHeight()
   140 			throw new IllegalStateException(
   147     {
   141 					"VideoControl.initDisplayMode() not called yet");
   148         // this function can't be called, when the player is in closed state
   142 		}
   149         // or until initDisplayMode function is not called
   143 		// Following function will always return Player's current height
   150         checkState();
   144 		return ((AnimationPlayer) iPlayer).getImageDimension().x;
   151         if (iStatus == NOT_INITIALIZED)
   145 	}
   152         {
   146 
   153             throw new IllegalStateException(
   147 	/**
   154                 "VideoControl.initDisplayMode() not called yet");
   148 	 * Return the actual width of the current render video. 
   155         }
   149 	 * @return width of the display video 
   156         // Following function will always return Player's current height
   150 	 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called.
   157         return ((AnimationPlayer) iPlayer).getImageDimension().x;
   151 	 */
   158     }
   152 	public int getDisplayWidth() {
   159 
   153 		checkState();
   160     /**
   154 		if (iStatus == NOT_INITIALIZED) {
   161      * Return the actual width of the current render video.
   155 			throw new IllegalStateException(
   162      * @return width of the display video
   156 					"VideoControl.initDisplayMode() not called yet");
   163      * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called.
   157 		}
   164      */
   158 		return ((AnimationPlayer) iPlayer).getImageDimension().x;
   165     public int getDisplayWidth()
   159 	}
   166     {
   160 
   167         checkState();
   161 	/**
   168         if (iStatus == NOT_INITIALIZED)
   162 	 * Return the X-coordinate of the video with respect to the GUI object where the video is displayed.
   169         {
   163 	 * The coordinate is specified in pixel values relative to the upper left hand corner of the GUI object.
   170             throw new IllegalStateException(
   164 	 * The return value is undefined if initDisplayMode has not been called.
   171                 "VideoControl.initDisplayMode() not called yet");
   165 	 * @return the X-coordinate of the video. 
   172         }
   166 	 */
   173         return ((AnimationPlayer) iPlayer).getImageDimension().x;
   167 	public int getDisplayX() {
   174     }
   168 		checkState();
   175 
   169 		if (iStatus == NOT_INITIALIZED) {
   176     /**
   170 			return UNDEFINED_RETURN_VALUE;
   177      * Return the X-coordinate of the video with respect to the GUI object where the video is displayed.
   171 		}
   178      * The coordinate is specified in pixel values relative to the upper left hand corner of the GUI object.
   172 		return ((AnimationPlayer) iPlayer).getiDisplayLocation().x;
   179      * The return value is undefined if initDisplayMode has not been called.
   173 	}
   180      * @return the X-coordinate of the video.
   174 
   181      */
   175 	/** 
   182     public int getDisplayX()
   176 	 * Return the Y-coordinate of the video with respective to the GUI object where the video is displayed.
   183     {
   177 	 * The coordinate is specified in pixel values relative to the upper left hand corner of the GUI object.
   184         checkState();
   178 	 * The return value is undefined if initDisplayMode has not been called.
   185         if (iStatus == NOT_INITIALIZED)
   179 	 * @return the Y-coordinate of the video.
   186         {
   180  	 */
   187             return UNDEFINED_RETURN_VALUE;
   181 	public int getDisplayY() {
   188         }
   182 		checkState();
   189         return ((AnimationPlayer) iPlayer).getiDisplayLocation().x;
   183 		if (iStatus == NOT_INITIALIZED) {
   190     }
   184 			return UNDEFINED_RETURN_VALUE;
   191 
   185 		}
   192     /**
   186 		return ((AnimationPlayer) iPlayer).getiDisplayLocation().y;
   193      * Return the Y-coordinate of the video with respective to the GUI object where the video is displayed.
   187 	}
   194      * The coordinate is specified in pixel values relative to the upper left hand corner of the GUI object.
   188 
   195      * The return value is undefined if initDisplayMode has not been called.
   189 	/**
   196      * @return the Y-coordinate of the video.
   190 	 * Get a snapshot of the displayed content. Features and format of the captured image are specified by
   197      */
   191 	 * imageType. Supported formats can be queried from System.getProperty with  video.snapshot.encodings
   198     public int getDisplayY()
   192 	 * as the key. The first format in the supported list is the default capture format. 
   199     {
   193 	 * @param imageType - Format and resolution of the returned image.
   200         checkState();
   194 	 *  If null is given, the default capture format is used.
   201         if (iStatus == NOT_INITIALIZED)
   195 	 *  
   202         {
   196 	 * @return image as a byte array in required format. 
   203             return UNDEFINED_RETURN_VALUE;
   197 	 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. 
   204         }
   198 	 * @throws MediaException - Thrown if the requested format is not supported or the Player does not support snapshots.
   205         return ((AnimationPlayer) iPlayer).getiDisplayLocation().y;
   199 	 * @throws java.lang.SecurityException - Thrown if the caller does not have the security permission to take the snapshot. 
   206     }
   200 	 */
   207 
   201 	//TODO Implementation pending, need discussion with UI team
   208     /**
   202 	public byte[] getSnapshot(String aImageType) throws MediaException {
   209      * Get a snapshot of the displayed content. Features and format of the captured image are specified by
   203 		checkState();
   210      * imageType. Supported formats can be queried from System.getProperty with  video.snapshot.encodings
   204 		if (iStatus == NOT_INITIALIZED) {
   211      * as the key. The first format in the supported list is the default capture format.
   205 			throw new IllegalStateException(
   212      * @param imageType - Format and resolution of the returned image.
   206 					"VideoControl.initDisplayMode() not called yet");
   213      *  If null is given, the default capture format is used.
   207 		}
   214      *
   208 		Image image=((AnimationPlayer)iPlayer).getCurrentFrame(aImageType);
   215      * @return image as a byte array in required format.
   209 		byte bytArry[]= null;//getByteArray(image);
   216      * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called.
   210 		// TODO Enable the permission check 
   217      * @throws MediaException - Thrown if the requested format is not supported or the Player does not support snapshots.
   211 		// Commented out below line, because I was getting exception 
   218      * @throws java.lang.SecurityException - Thrown if the caller does not have the security permission to take the snapshot.
       
   219      */
       
   220     //TODO Implementation pending, need discussion with UI team
       
   221     public byte[] getSnapshot(String aImageType) throws MediaException
       
   222     {
       
   223         checkState();
       
   224         if (iStatus == NOT_INITIALIZED)
       
   225         {
       
   226             throw new IllegalStateException(
       
   227                 "VideoControl.initDisplayMode() not called yet");
       
   228         }
       
   229         Image image=((AnimationPlayer)iPlayer).getCurrentFrame(aImageType);
       
   230         byte bytArry[]= null;//getByteArray(image);
       
   231         // TODO Enable the permission check
       
   232         // Commented out below line, because I was getting exception
   212         // Check the permission here, so 'the moment' is not lost?
   233         // Check the permission here, so 'the moment' is not lost?
   213         //Security.ensurePermission(PERMISSION, PERMISSION, PERM_ARGS);
   234         //Security.ensurePermission(PERMISSION, PERMISSION, PERM_ARGS);
   214 //        ApplicationUtils appUtils = ApplicationUtils.getInstance();
   235 //        ApplicationUtils appUtils = ApplicationUtils.getInstance();
   215 //        PlayerPermission per = new PlayerPermission("audio/video recording","snapshot");
   236 //        PlayerPermission per = new PlayerPermission("audio/video recording","snapshot");
   216 //        appUtils.checkPermission(per);
   237 //        appUtils.checkPermission(per);
   217 		return bytArry;
   238         return bytArry;
   218 	}
   239     }
   219 
   240 
   220 	/**
   241     /**
   221 	 * Return the height of the source video. The height must be a positive number. 
   242      * Return the height of the source video. The height must be a positive number.
   222 	 * @return the height of the source video. 
   243      * @return the height of the source video.
   223 	 */
   244      */
   224 	public int getSourceHeight() {
   245     public int getSourceHeight()
   225 		checkState();
   246     {
   226 		return ((AnimationPlayer)iPlayer).getSourceDimension().y;
   247         checkState();
   227 	}
   248         return ((AnimationPlayer)iPlayer).getSourceDimension().y;
   228 
   249     }
   229 	/**
   250 
   230 	 * Return the width of the source video. The width must be a positive number.  
   251     /**
   231 	 * @return the width of the source video
   252      * Return the width of the source video. The width must be a positive number.
   232 	 */
   253      * @return the width of the source video
   233 	public int getSourceWidth() {
   254      */
   234 		checkState();
   255     public int getSourceWidth()
   235 		return ((AnimationPlayer)iPlayer).getSourceDimension().x;
   256     {
   236 	}
   257         checkState();
   237 
   258         return ((AnimationPlayer)iPlayer).getSourceDimension().x;
   238 	/**
   259     }
   239 	 * Initialize the mode on how the video is displayed. 
   260 
   240 	 * This method must be called before video can be displayed.
   261     /**
   241 	 * Two modes are defined:
   262      * Initialize the mode on how the video is displayed.
       
   263      * This method must be called before video can be displayed.
       
   264      * Two modes are defined:
   242      * USE_GUI_PRIMITIVE (inherited from GUIControl)
   265      * USE_GUI_PRIMITIVE (inherited from GUIControl)
   243      * USE_DIRECT_VIDEO   
   266      * USE_DIRECT_VIDEO
   244 	 * @see javax.microedition.media.control.VideoControl#initDisplayMode(int, java.lang.Object)
   267      * @see javax.microedition.media.control.VideoControl#initDisplayMode(int, java.lang.Object)
   245 	 */
   268      */
   246 	public Object initDisplayMode(int aMode, Object aArg) {
   269     public Object initDisplayMode(int aMode, Object aArg)
   247 		final String DEBUG_STRING = "VideoControl::initDisplayMode(int, Object)";
   270     {
   248 		Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING + "+");
   271         final String DEBUG_STRING = "VideoControl::initDisplayMode(int, Object)";
   249 		// To check if state is in not closed state
   272         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING + "+");
   250 		checkState();
   273         // To check if state is in not closed state
   251 		if (iStatus != NOT_INITIALIZED) {
   274         checkState();
   252 			// IllegalStateException - Thrown if initDisplayMode is
   275         if (iStatus != NOT_INITIALIZED)
   253 			// called again after it has previously been called successfully.
   276         {
   254 			throw new IllegalStateException(
   277             // IllegalStateException - Thrown if initDisplayMode is
   255 					"initDisplayMode() already called successfully");
   278             // called again after it has previously been called successfully.
   256 		}
   279             throw new IllegalStateException(
   257 		Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING+"Mode = "+aMode+" Argument = "+aArg);
   280                 "initDisplayMode() already called successfully");
   258 		// if the aArg is equal to the name of eSWT Control class name
   281         }
   259 		// create the Display object in following, assuming Display 
   282         // if the aArg is equal to the name of eSWT Control class name
   260 		// object is already created in MIDlet. 
   283         // create the Display object in following, assuming Display
   261 		if(aArg!=null && aArg.equals(Control.class.getName())){
   284         // object is already created in MIDlet.
   262 			// Following line will return the same Display object
   285         if (aArg!=null && aArg.equals(Control.class.getName()))
   263 			// Which is created in Midlet
   286         {
   264 			iDisplay =Display.getDefault();	
   287             // Following line will return the same Display object
   265 		}else{
   288             // Which is created in Midlet
   266 			// Get the Display object of ESWT
   289             iDisplay =Display.getDefault();
   267 			iDisplay = com.nokia.mj.impl.nokialcdui.LCDUIInvoker.getEswtDisplay();
   290         }
   268 		}
   291         else
   269 		if (aMode == USE_GUI_PRIMITIVE) {
   292         {
   270 			Object guiObject = null;
   293             // Get the Display object of ESWT
   271 			if (aArg == null) {
   294             iDisplay = com.nokia.mj.impl.nokialcdui.LCDUIInvoker.getEswtDisplay();
   272 				guiObject = initNullMode();
   295         }
   273 			} else {
   296         if (aMode == USE_GUI_PRIMITIVE)
   274 				if (aArg.equals(GUI_OBJECT_CLASS_NAME)) {
   297         {
   275 					guiObject = initLCDUI();
   298             Object guiObject = null;
   276 				} else // try load dynamic display mode
   299             if (aArg == null)
   277 				{
   300             {
   278 					guiObject = initDynamicDisplayMode(aArg);
   301                 guiObject = initNullMode();
   279 					// Since it is eswtControl itself so no need of LCDUIInvoker here
   302             }
   280 					// assign it in iControl and return immediately from here
   303             else
   281 					iControl=(Control)guiObject;
   304             {
   282 					// Now we will change the status, when MIDlet developer will call the setParent
   305                 if (aArg.equals(GUI_OBJECT_CLASS_NAME))
   283 					iStatus = USE_GUI_PRIMITIVE;
   306                 {
   284 					return iControl;
   307                     guiObject = initLCDUI();
   285 				}
   308                 }
   286 			}
   309                 else // try load dynamic display mode
   287 			// this will return the control as null, because the item might not
   310                 {
   288 			// have been appended in form
   311                     guiObject = initDynamicDisplayMode(aArg);
   289 			// Solution to this is as:- Add the listener through LCDUIInvoker
   312                     // Since it is eswtControl itself so no need of LCDUIInvoker here
   290 			// and when item will be appended
   313                     // assign it in iControl and return immediately from here
   291 			// by midlet developer, notifyControlAvailable function of
   314                     iControl=(Control)guiObject;
   292 			// ItemStateChangeListener will be called
   315                     // Now we will change the status, when MIDlet developer will call the setParent
   293 			iControl = com.nokia.mj.impl.nokialcdui.LCDUIInvoker
   316                     iStatus = USE_GUI_PRIMITIVE;
   294 					.getEswtControl(guiObject);
   317                     return iControl;
   295 			// add this class as item state change listener
   318                 }
   296 			com.nokia.mj.impl.nokialcdui.LCDUIInvoker
   319             }
   297 					.setItemControlStateChangeListener(this, (Item)guiObject);
   320             // this will return the control as null, because the item might not
   298 			iStatus = USE_GUI_PRIMITIVE;
   321             // have been appended in form
   299 			return guiObject;
   322             // Solution to this is as:- Add the listener through LCDUIInvoker
   300 		} else if (aMode == USE_DIRECT_VIDEO) {
   323             // and when item will be appended
   301 			if (aArg != null) {
   324             // by MIDlet developer, notifyControlAvailable function of
   302 				if (!(aArg instanceof javax.microedition.lcdui.Canvas)) {
   325             // ItemStateChangeListener will be called
   303 					throw new java.lang.IllegalArgumentException(
   326             iControl = com.nokia.mj.impl.nokialcdui.LCDUIInvoker
   304 							"For USE_DIRECT_VIDEO mode argument should be of type Canvas");
   327                        .getEswtControl(guiObject);
   305 				}
   328             // add this class as item state change listener
   306 			} else {
   329             com.nokia.mj.impl.nokialcdui.LCDUIInvoker
   307 				throw new java.lang.IllegalArgumentException(
   330             .setItemControlStateChangeListener(this, (Item)guiObject);
   308 						"For USE_DIRECT_VIDEO mode argument should not be null");
   331             iStatus = USE_GUI_PRIMITIVE;
   309 			}
   332             return guiObject;
   310 			iControl = com.nokia.mj.impl.nokialcdui.LCDUIInvoker
   333         }
   311 					.getEswtControl(aArg);
   334         else if (aMode == USE_DIRECT_VIDEO)
   312 			Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING
   335         {
   313 					+ "This is USE_DIRECT_VIDEO mode, control is " + iControl);
   336             if (aArg != null)
   314 			iStatus = USE_DIRECT_VIDEO;
   337             {
   315 		} else {
   338                 if (!(aArg instanceof javax.microedition.lcdui.Canvas))
   316 			throw new java.lang.IllegalArgumentException(
   339                 {
   317 					"Mode not supported or invalid, "
   340                     throw new java.lang.IllegalArgumentException(
   318 							+ "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE");
   341                         "For USE_DIRECT_VIDEO mode argument should be of type Canvas");
   319 		}
   342                 }
   320 		Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING + "-");
   343             }
   321 		return null;
   344             else
   322 	}
   345             {
   323 	/**
   346                 throw new java.lang.IllegalArgumentException(
   324 	 * Creates the VideoItem object of size of image(gif)
   347                     "For USE_DIRECT_VIDEO mode argument should not be null");
   325 	 * @return VideoItem(a CustomItem ) object
   348             }
   326 	 */
   349             iControl = com.nokia.mj.impl.nokialcdui.LCDUIInvoker
   327 	private Object initLCDUI(){
   350                        .getEswtControl(aArg);
   328 		final String DEBUG_STR="VideoControl::initLCDUI()";
   351 
   329 		Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+");
   352             //If USE_DIRECT_VIDEO is set, the video by default is not
   330 		iVideoItem = new VideoItem(((AnimationPlayer)iPlayer).getImageDimension());
   353             //shown when the canvas is displayed until setVisible(true) is called
       
   354             //iIsControlVisible variable of AnimationPlayer class decides, whether
       
   355             //animation should be visible or not, and by default it is true;
       
   356             //So making it false here.
       
   357             ((AnimationPlayer)iPlayer).setiIsControlVisible(false);
       
   358             iStatus = USE_DIRECT_VIDEO;
       
   359         }
       
   360         else
       
   361         {
       
   362             throw new java.lang.IllegalArgumentException(
       
   363                 "Mode not supported or invalid, "
       
   364                 + "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE");
       
   365         }
       
   366         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STRING + "-");
       
   367         return null;
       
   368     }
       
   369     /**
       
   370      * Creates the VideoItem object of size of image(gif)
       
   371      * @return VideoItem(a CustomItem ) object
       
   372      */
       
   373     private Object initLCDUI()
       
   374     {
       
   375         final String DEBUG_STR="VideoControl::initLCDUI()";
       
   376         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"+");
       
   377         iVideoItem = new VideoItem(((AnimationPlayer)iPlayer).getImageDimension());
   331         iPlayer.addPlayerListener(iVideoItem);
   378         iPlayer.addPlayerListener(iVideoItem);
   332         iStatus = USE_GUI_PRIMITIVE;
   379         iStatus = USE_GUI_PRIMITIVE;
   333         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-");
   380         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR+"-");
   334         return iVideoItem;
   381         return iVideoItem;
   335 	}
   382     }
   336 
   383 
   337 		/**
   384     /**
   338 	    * Initializes USE_GUI_PRIMITIVE mode when null parameter is given to
   385     * Initializes USE_GUI_PRIMITIVE mode when null parameter is given to
   339 	    * initDisplayMode method.
   386     * initDisplayMode method.
   340 	    * UI toolkit gets selected when application uses UI toolkit
   387     * UI toolkit gets selected when application uses UI toolkit
   341 	    * first time. After this selection null parameter must be
   388     * first time. After this selection null parameter must be
   342 	    * interpreted as the selected UI toolkit. initDisplayMode call
   389     * interpreted as the selected UI toolkit. initDisplayMode call
   343 	    * with null parameter before the selection must cause
   390     * with null parameter before the selection must cause
   344 	    * IllegalArgumentException if there are several toolkits.
   391     * IllegalArgumentException if there are several toolkits.
   345 	    * @return GUI object
   392     * @return GUI object
   346 	    */
   393     */
   347 	private Object initNullMode() {
   394     private Object initNullMode()
   348 		String DEBUG_STR = "VideoControl::initNullMode()";
   395     {
   349 		// Removing following line as per new requirement. 
   396         String DEBUG_STR = "VideoControl::initNullMode()";
   350 		// there won't be any toolkit 
   397         // TODO remove this 'toolkit' variable
   351 //		UiToolkitRegister uiRegister = RuntimeInfoFactory.getRuntimeInfo()
   398         String toolkit = null;
   352 //				.getUiToolkitRegister();
   399         Object guiObject = null;
   353 //		// returns always non null array with zero or more strings
   400 
   354 //		String[] toolkits = uiRegister.getRegisteredUiToolkits();
   401         // If LCDUI was selected init it even if there might be several
   355 		// selected toolkit or null if not selected
   402         // toolkits. This is done to support existing applications.
   356 		//String toolkit = (toolkits.length > 0) ? toolkits[0] : null;
   403         if ((LCDUI_PACKAGE + DISPLAY).equals(toolkit))
   357 		// TODO remove this 'toolkit' variable 
   404         {
   358 		String toolkit = null;
   405             Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR + "going to use initLCDUI function ");
   359 		Object guiObject = null;
   406             guiObject = initLCDUI();
   360 
   407         }
   361 		// If lcdui was selected init it even if there might be several
   408         else
   362 		// toolkits. This is done to support existing applications.
   409         {
   363 		if ((LCDUI_PACKAGE + DISPLAY).equals(toolkit)) {
   410             try
   364 			Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR + "going to use initLCDUI function ");
   411             {
   365 			guiObject = initLCDUI();
   412                 // Several UI toolkits are supported if there are eSWT classes
   366 		} else {
   413                 // and eSWT direct content component
   367 			try {
   414                 // Trying to load eSWT Listener interface or eSWT GUI factory
   368 				// Several UI toolkits are supported if there are eSWT classes
   415                 // does not cause any initialization to eSWT.
   369 				// and eSWT direct content component
   416                 Class.forName(ESWT_PACKAGE + LISTENER);
   370 				// Trying to load eSWT Listener interface or eSWT GUI factory
   417                 // check if eSWT was selected
   371 				// does not cause any initialization to eSWT.
   418                 if ((ESWT_PACKAGE + DISPLAY).equals(toolkit))
   372 				Class.forName(ESWT_PACKAGE + LISTENER);
   419                 {
   373 				// check if eSWT was selected
   420                     Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR
   374 				if ((ESWT_PACKAGE + DISPLAY).equals(toolkit))
   421                                + "It is eswtPackage going to call initDynamicDisplay ");
   375 				{
   422                     guiObject = initDynamicDisplayMode(ESWT_PACKAGE
   376 					Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo,DEBUG_STR
   423                                                        + ESWT_CONTROL);
   377 									+ "It is eswtPackage going to call initDynamicDisplay ");
   424 
   378 					guiObject = initDynamicDisplayMode(ESWT_PACKAGE
   425                 }
   379 					+ ESWT_CONTROL);
   426                 else
   380 
   427                 {
   381 				} else {
   428                     // If no toolkit is registered and if LCDUI library exists
   382 					// If no toolkit is registered and if LCDUI library exists
   429                     // select it
   383 					// select it
   430                     try
   384 					try {
   431                     {
   385 						Class.forName(LCDUI_PACKAGE + DISPLAY);
   432                         Class.forName(LCDUI_PACKAGE + DISPLAY);
   386 						guiObject = initLCDUI();
   433                         guiObject = initLCDUI();
   387 					} catch (ClassNotFoundException cnfe) {
   434                     }
   388 						// If there are several toolkits and none is selected
   435                     catch (ClassNotFoundException cnfe)
   389 						// IllegalArgumentException must be thrown
   436                     {
   390 						throw new IllegalArgumentException(
   437                         // If there are several toolkits and none is selected
   391 								"UI toolkit is not available or found.");
   438                         // IllegalArgumentException must be thrown
   392 					}
   439                         throw new IllegalArgumentException(
   393 				}
   440                             "UI toolkit is not available or found.");
   394 			} catch (ClassNotFoundException cnfe) {
   441                     }
   395 				Logger.LOG(Logger.EJavaMMAPI, Logger.EError,DEBUG_STR
   442                 }
   396 						+ "Exception caought, going to call initLCDUI funtion");
   443             }
   397 				// Only lcdui is supported
   444             catch (ClassNotFoundException cnfe)
   398 				guiObject = initLCDUI();
   445             {
   399 			}
   446                 Logger.LOG(Logger.EJavaMMAPI, Logger.EError,DEBUG_STR
   400 		}
   447                            + "Exception caought, going to call initLCDUI funtion");
   401 		return guiObject;
   448                 // Only lcdui is supported
   402 	}
   449                 guiObject = initLCDUI();
   403 	    
   450             }
   404 	    /**
   451         }
   405 	     * 
   452         return guiObject;
   406 	     * @param aMode class name of the component 
   453     }
   407 	     * @return
   454 
   408 	     */
   455     /**
   409 	// TODO this ProxyControl object should not be used as member variable of VC. 
   456      *
   410 	private ProxyControl control=null;
   457      * @param aMode class name of the component
   411 	private Object initDynamicDisplayMode(Object aMode) {
   458      * @return
   412 		final String DEBUG_STR="VideoControl::initDynamicDisplayMode()";
   459      */
   413 		try {
   460     // TODO this ProxyControl object should not be used as member variable of VC.
   414 			// Following line make sure that class name provided in aMode is proper
   461     private ProxyControl control=null;
   415 			// TODO is it necessary to load the class name 
   462     private Object initDynamicDisplayMode(Object aMode)
   416 			Class guiClass = Class.forName((String)aMode);
   463     {
   417 			iDisplay.syncExec(new Runnable() {
   464         try
   418 				public void run() {
   465         {
   419 					control=new ProxyControl(((AnimationPlayer)iPlayer).getImageDimension());
   466             // Following line make sure that class name provided in aMode is proper
   420 				}
   467             // TODO is it necessary to load the class name
   421 			});
   468             Class guiClass = Class.forName((String)aMode);
   422 		} catch (ClassNotFoundException cnfe) {
   469             iDisplay.syncExec(new Runnable()
   423 			// if the class could not be found
   470             {
   424 			throw new IllegalArgumentException(
   471                 public void run()
   425 					"Mode not supported or invalid, "
   472                 {
   426 							+ "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE");
   473                     control=new ProxyControl(((AnimationPlayer)iPlayer).getImageDimension());
   427 //		} catch (IllegalAccessException iae) {
   474                 }
   428 //			// if the class or initializer is not accessible
   475             });
   429 //			throw new IllegalArgumentException("Mode: " + aMode + " caused "
   476         }
   430 //					+ iae);
   477         catch (ClassNotFoundException cnfe)
   431 //		} catch (InstantiationException ie) {
   478         {
   432 //			// if an application tries to instantiate an abstract class or an
   479             // if the class could not be found
   433 //			// interface, or if the instantiation fails for some other reason
   480             throw new IllegalArgumentException(
   434 //			throw new IllegalArgumentException("Mode: " + aMode + " caused "
   481                 "Mode not supported or invalid, "
   435 //					+[= ie);
   482                 + "valid modes are USE_DIRECT_VIDEO and USE_GUI_PRIMITIVE");
   436 		} catch (ClassCastException cce) {
   483 //      } catch (IllegalAccessException iae) {
   437 			// Thrown to indicate that the code has attempted to cast an
   484 //          // if the class or initializer is not accessible
   438 			// object to a subclass of which it is not an instance.
   485 //          throw new IllegalArgumentException("Mode: " + aMode + " caused "
   439 			throw new IllegalArgumentException("Mode: " + aMode + " caused "
   486 //                  + iae);
   440 					+ cce);
   487 //      } catch (InstantiationException ie) {
   441 		}
   488 //          // if an application tries to instantiate an abstract class or an
   442 		// TODO remove this catch(Exception) block, it is added for testing purpose  
   489 //          // interface, or if the instantiation fails for some other reason
   443 		catch(Exception e){
   490 //          throw new IllegalArgumentException("Mode: " + aMode + " caused "
   444 			Logger.LOG(Logger.EJavaMMAPI, Logger.EError,"Exception thrown while creating the control object"+e);
   491 //                  +[= ie);
   445 			e.printStackTrace();
   492         }
   446 		}
   493         catch (ClassCastException cce)
   447 		return control;
   494         {
   448 	}
   495             // Thrown to indicate that the code has attempted to cast an
   449 	    
   496             // object to a subclass of which it is not an instance.
   450 	/* (non-Javadoc)
   497             throw new IllegalArgumentException("Mode: " + aMode + " caused "
   451 	 * @see javax.microedition.media.control.VideoControl#setDisplayFullScreen(boolean)
   498                                                + cce);
   452 	 */
   499         }
   453 	public void setDisplayFullScreen(final boolean aFullScreenMode)
   500         // TODO remove this catch(Exception) block, it is added for testing purpose
   454 			throws MediaException {
   501         catch (Exception e)
   455 		if (iStatus == NOT_INITIALIZED) {
   502         {
   456 			throw new IllegalStateException(
   503             Logger.LOG(Logger.EJavaMMAPI, Logger.EError,"Exception thrown while creating the control object"+e);
   457 					"VideoControl.initDisplayMode() not called yet");
   504             e.printStackTrace();
   458 		}
   505         }
   459 		//if this is in case of form, return silently 
   506         return control;
   460 		//This is as per earlier NOKIA implementation, 
   507     }
   461 		// however MMAPI documentation is saying something different 
   508 
   462 		// if Full screen mode is not supported, it should throw MediaException
   509     /* (non-Javadoc)
   463 		// TODO further check and discuss....
   510      * @see javax.microedition.media.control.VideoControl#setDisplayFullScreen(boolean)
   464 		if(iVideoItem!=null) {
   511      */
   465 			return;
   512     public void setDisplayFullScreen(final boolean aFullScreenMode)
   466 		}
   513     throws MediaException
   467 		if(aFullScreenMode){
   514     {
   468 			// Before going to full screen mode, we need to store the current display size;
   515         if (iStatus == NOT_INITIALIZED)
   469 			// so that when user will exit from the full screen,
   516         {
   470 			// it will return to it's previous size
   517             throw new IllegalStateException(
   471 			iOldDisplaySize = ((AnimationPlayer)iPlayer).getImageDimension();
   518                 "VideoControl.initDisplayMode() not called yet");
   472 			Rectangle displayDimension=calculateFullScreenDimension(); 
   519         }
   473 			((AnimationPlayer)iPlayer).updateImageData(displayDimension.width, displayDimension.height);
   520         //if this is in case of form, return silently
   474 			setDisplayLocation(displayDimension.x, displayDimension.y);
   521         //This is as per earlier NOKIA implementation,
   475 			((AnimationPlayer)iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this);
   522         if (iVideoItem!=null)
   476 		}else{
   523         {
   477 			// user may call setFullScreen(false), prior to setting it full screen 
   524             return;
   478 			if(iOldDisplaySize!=null){
   525         }
   479 				((AnimationPlayer)iPlayer).updateImageData(iOldDisplaySize);
   526         if (aFullScreenMode)
   480 				// Do we need to make it null?
   527         {
   481 				iOldDisplaySize=null;
   528             // Before going to full screen mode, we need to store the current display size;
   482 				// post event to player Listener 
   529             // so that when user will exit from the full screen,
   483 				((AnimationPlayer)iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this);
   530             // it will return to it's previous size
   484 			}
   531             iOldDisplaySize = ((AnimationPlayer)iPlayer).getImageDimension();
   485 		}
   532             Rectangle displayDimension=calculateFullScreenDimension();
   486 	}
   533             ((AnimationPlayer)iPlayer).updateImageData(displayDimension.width, displayDimension.height);
   487 
   534             setDisplayLocation(displayDimension.x, displayDimension.y);
   488 	/* (non-Javadoc)
   535             ((AnimationPlayer)iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this);
   489 	 * @see javax.microedition.media.control.VideoControl#setDisplayLocation(int, int)
   536         }
   490 	 */
   537         else
   491 	public void setDisplayLocation(int aX, int aY) {
   538         {
   492 		// in case of customItem, we are getting canvasExtension as control 
   539             // user may call setFullScreen(false), prior to setting it full screen
   493 		// and in this case we need to ignore the setDisplayLocation call.
   540             // so making it sure here that iOldDisplaySize is not null
   494 		// it is also possible that iControl may be null( it will be null until and unless
   541             if (iOldDisplaySize!=null)
   495 		// notifyControlAvailable function is not get called)
   542             {
   496 		if(iControl==null || (iControl instanceof org.eclipse.swt.internal.extension.CanvasExtension))
   543                 ((AnimationPlayer)iPlayer).updateImageData(iOldDisplaySize);
   497 			return ;
   544                 // Do we need to make it null?
   498 		((AnimationPlayer)iPlayer).setDisplayLocation(aX, aY);
   545                 iOldDisplaySize=null;
   499 	}
   546                 // post event to player Listener
   500 
   547                 ((AnimationPlayer)iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this);
   501 	/** 
   548             }
   502 	 * (non-Javadoc)
   549         }
   503 	 * @see javax.microedition.media.control.VideoControl#setDisplaySize(int, int)
   550     }
   504 	 */
   551 
   505 	// TODO we need to handle here the following scenario
   552     /* (non-Javadoc)
   506 	// if the player is in FULL_SCREEN mode, just change the display size in background(means do not exit from 
   553      * @see javax.microedition.media.control.VideoControl#setDisplayLocation(int, int)
   507 	// the full screen mode and don't send event to player Listener the player size changed )
   554      */
   508 	// and changed side should take effect 
   555     public void setDisplayLocation(int aX, int aY)
   509 	public void setDisplaySize(int aWidth, int aHeight) throws MediaException {
   556     {
   510 		if (iStatus == NOT_INITIALIZED) {
   557         // Need to ignore this call in case of USE_GUI_PRIMITIVE
   511 			throw new IllegalStateException(
   558         // in case of customItem, we are getting canvasExtension as control
   512 					"VideoControl.initDisplayMode() not called yet");
   559         // and in this case we need to ignore the setDisplayLocation call.
   513 		}
   560         // it is also possible that iControl may be null( it will be null until and unless
   514 		if (aWidth <= 0 || aHeight <= 0) {
   561         // notifyControlAvailable function is not get called)
   515 			throw new IllegalArgumentException(
   562         System.out.println("VideoControl::setDisplayLocation() curretn status is "+iStatus);
   516 					"Width and height must be positive");
   563         if (iControl==null || (iControl instanceof org.eclipse.swt.internal.extension.CanvasExtension))
   517 		}
   564             return ;
   518 		// resize the all frames 
   565         ((AnimationPlayer)iPlayer).setDisplayLocation(aX, aY);
   519 		((AnimationPlayer) iPlayer).updateImageData(aWidth, aHeight);
   566     }
   520 		// Since the DisplaySize is being changed, we need to change the
   567 
   521 		// size of VideoItem as well
   568     /**
   522 		// if the videoItem is not null, it means currently we are playing
   569      * (non-Javadoc)
   523 		// animation on form
   570      * @see javax.microedition.media.control.VideoControl#setDisplaySize(int, int)
   524 		if (iVideoItem != null)// means it is for customItem
   571      */
   525 			iVideoItem.setPreferredSize(aWidth, aHeight);
   572     // TODO we need to handle here the following scenario
   526 		// Notify to all player listener that video Size has been changed
   573     // if the player is in FULL_SCREEN mode, just change the display size in background(means do not exit from
   527 		((AnimationPlayer) iPlayer).getiPlayerListenerImpl().postEvent(
   574     // the full screen mode and don't send event to player Listener the player size changed )
   528 				PlayerListener.SIZE_CHANGED, this);
   575     // and changed side should take effect
   529 	}
   576     public void setDisplaySize(int aWidth, int aHeight) throws MediaException
   530 
   577     {
   531 	/**
   578         if (iStatus == NOT_INITIALIZED)
   532 	 * Show or hide the video.
   579         {
   533 	 * If USE_GUI_PRIMITIVE is set, the video by default is shown when the GUI primitive is displayed.
   580             throw new IllegalStateException(
   534  	 * If USE_DIRECT_VIDEO is set, the video by default is not shown when the canvas is displayed until
   581                 "VideoControl.initDisplayMode() not called yet");
   535  	 * setVisible(true) is called. If the canvas is removed from the screen, the video will not be displayed.
   582         }
   536  	 * 
   583         if (aWidth <= 0 || aHeight <= 0)
   537  	 * @return visible - Show the video if true, hide it otherwise.
   584         {
   538  	 * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called. 
   585             throw new IllegalArgumentException(
   539 	 */
   586                 "Width and height must be positive");
   540 	public void setVisible(final boolean aVisible) {
   587         }
   541 		if (iStatus == NOT_INITIALIZED) {
   588         // resize the all frames
   542 			throw new IllegalStateException(
   589         ((AnimationPlayer) iPlayer).updateImageData(aWidth, aHeight);
   543 					"VideoControl.initDisplayMode() not called yet");
   590         // Since the DisplaySize is being changed, we need to change the
   544 		}
   591         // size of VideoItem as well
   545 		// if this is in case of Form and eSWT Control then this implementation is OK
   592         // if the videoItem is not null, it means currently we are playing
   546 		// but in case of Canvas, entire Canvas is getting invisible, which is not OK.
   593         // animation on form
   547 		// TODO handle the case of Canvas case as well
   594         if (iVideoItem != null)// means it is for customItem
   548 		//TODO in case of Canvas visiblity should be false by default
   595             iVideoItem.setPreferredSize(aWidth, aHeight);
   549 		// while in case of Form it should be true. 
   596         // Notify to all player listener that video Size has been changed
   550 		if (iControl != null) {
   597         ((AnimationPlayer) iPlayer).getiPlayerListenerImpl().postEvent(
   551 			iDisplay.syncExec(new Runnable() {
   598             PlayerListener.SIZE_CHANGED, this);
   552 				public void run() {
   599     }
   553 					iControl.setVisible(aVisible);
   600 
   554 				}
   601     /**
   555 			});
   602      * Show or hide the video.
   556 		}
   603      * If USE_GUI_PRIMITIVE is set, the video by default is shown when the GUI primitive is displayed.
   557 	}
   604      * If USE_DIRECT_VIDEO is set, the video by default is not shown when the canvas is displayed until
   558 	/*******************************FOLLOWING FUNCTIONS ARE USED FOR INTERNAL PURPOSE***********************/
   605      * setVisible(true) is called. If the canvas is removed from the screen, the video will not be displayed.
   559 	/**
   606      *
   560 	 * 
   607      * @return visible - Show the video if true, hide it otherwise.
   561 	 * @return Display object retrieved from ESWT
   608      * @throws java.lang.IllegalStateException - Thrown if initDisplayMode has not been called.
   562 	 */
   609      */
   563 	Display getiDisplay() {
   610     public void setVisible(final boolean aVisible)
   564 		return iDisplay;
   611     {
   565 	}
   612         if (iStatus == NOT_INITIALIZED)
   566 	
   613         {
   567 	/**
   614             throw new IllegalStateException(
   568 	 * 
   615                 "VideoControl.initDisplayMode() not called yet");
   569 	 * @return
   616         }
   570 	 */
   617         if (iControl != null)
   571 	Control getControl() {
   618         {
   572 		return iControl;
   619             ((AnimationPlayer)iPlayer).setiIsControlVisible(aVisible);
   573 	}
   620             // even if the player is stopped, need to give the effect of
   574 	/**
   621             // setVisible
   575 	 * Function of ItemStateChangeListener
   622             iDisplay.syncExec(new Runnable()
   576 	 * Notified by LCDUI implementation  
   623             {
   577 	 * @param ctrl
   624                 public void run()
   578 	 * @param item
   625                 {
   579 	 */
   626                     iControl.redraw();//setVisible(aVisible);
   580 	public void notifyControlAvailable(Control ctrl,Item item){
   627                 }
   581 		final String DEBUG_STR= "VideoControl::notifyControlAvailable(Control ctrl,Item item)";
   628             });
   582 		iControl=ctrl;
   629         }
   583 		Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, DEBUG_STR+"Control is "+ctrl.hashCode()+ " Item is "+item);
   630     }
   584 		//TODO is it proper here to put the below line in try/catch?, remove if we can.
   631     /*******************************FOLLOWING FUNCTIONS ARE USED FOR INTERNAL PURPOSE***********************/
   585 		// Otherwise it may deteriorate the performance, as in case of CustomItem on each 
   632     /**
   586 		// repaint, eSWT control is getting destroyed, and reconstructed
   633      *
   587 		try {
   634      * @return Display object retrieved from ESWT
   588 			((AnimationPlayer)iPlayer).addPaintListener(iControl);
   635      */
   589 		} catch (MediaException e) {
   636     Display getiDisplay()
   590 			// TODO What to do here
   637     {
   591 			e.printStackTrace();
   638         return iDisplay;
   592 		}
   639     }
   593 	}
   640 
   594 	/**
   641     /**
   595 	 * Function of ItemStateChangeListener
   642      *
   596 	 * We don't need to do anything in this function
   643      * @return
   597 	 * 
   644      */
   598 	 * @param item
   645     Control getControl()
   599 	 */
   646     {
   600 	 public void notifyControlDisposed(Item item){
   647         return iControl;
   601 		final String DEBUG_STR= "VideoControl::notifyControlDisposed(Item item)";
   648     }
   602 		Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, DEBUG_STR+"Item Disposed is "+item);
   649     /**
   603 	}
   650      * Function of ItemStateChangeListener
   604 	
   651      * Notified by LCDUI implementation
   605 	/**
   652      * @param ctrl
   606 	 * This function calculate the size and location of the image in case of full screen
   653      * @param item
   607 	 * So that Aspect ratio should be maintained 
   654      */
   608 	 * @return Rectangle, After calculating the size of the Video(image) in full screen mode 
   655     public void notifyControlAvailable(Control ctrl,Item item)
   609 	 */
   656     {
   610 	// It is not the proper way to declare the variable as global variable 
   657         final String DEBUG_STR= "VideoControl::notifyControlAvailable(Control ctrl,Item item)";
   611 	// only for the reason that it should be accessible in inner class.
   658         iControl=ctrl;
   612 	// Following variable(deviceDimension) declared shouldn't be the part of VideoControl object. 
   659         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, DEBUG_STR+"Control is "+ctrl.hashCode()+ " Item is "+item);
   613 	// My suggestion:- Move it to some utility class 
   660         //TODO is it proper here to put the below line in try/catch?, remove if we can.
   614 	// TODO let's discuss 
   661         // Otherwise it may deteriorate the performance, as in case of CustomItem on each
   615 	private Rectangle deviceDimension;
   662         // repaint, eSWT control is getting destroyed, and reconstructed
   616 	private Rectangle calculateFullScreenDimension(){
   663         ((AnimationPlayer)iPlayer).addPaintListener(iControl);
   617 		Point actualImageSize = ((AnimationPlayer)iPlayer).getImageDimension();
   664     }
   618 		// initialize the deviceDimension, in local variable
   665     /**
   619 		iDisplay.syncExec(new Runnable() {
   666      * Function of ItemStateChangeListener
   620 			public void run() {
   667      * We don't need to do anything in this function
   621 				//deviceDimension=iDisplay.getBounds();
   668      *
   622 				deviceDimension=iDisplay.getClientArea();
   669      * @param item
   623 			}
   670      */
   624 		});
   671     public void notifyControlDisposed(Item item)
   625 		int deviceWidth=deviceDimension.width;
   672     {
   626 		int deviceHeight=deviceDimension.height;
   673         final String DEBUG_STR= "VideoControl::notifyControlDisposed(Item item)";
   627 		//Returning the following rectangle after alteration 
   674         Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, DEBUG_STR+"Item Disposed is "+item);
   628 		Rectangle rect= new Rectangle (0,0,deviceWidth,deviceHeight);
   675     }
   629 
   676 
   630 		// to handle the divide by zero 
   677     /**
   631 		if(actualImageSize.x==0 && actualImageSize.y==0)
   678      * This function calculate the size and location of the image in case of full screen
   632 			return rect;
   679      * So that Aspect ratio should be maintained
   633 		// Following logic has been copied from 
   680      * @return Rectangle, After calculating the size of the Video(image) in full screen mode
   634 		 //earlier native implementation ( from cmmadisplay.cpp::ScaleToFullScreen)
   681      */
   635 		// Smaller dimension scale ratio will be scaled.
   682     // It is not the proper way to declare the variable as global variable
   636 	    // Changed to area calculation to avoid reals and dimension
   683     // only for the reason that it should be accessible in inner class.
   637 	    // with smaller area will be scaled.
   684     // Following variable(deviceDimension) declared shouldn't be the part of VideoControl object.
   638 		// remember that the argument received in this function is a point
   685     // My suggestion:- Move it to some utility class
   639 		// and it's x and y coordinate represent the width and height of the image respectively
   686     // TODO let's discuss
   640 		int vDiff=(deviceWidth - actualImageSize.x)* actualImageSize.y;
   687     private Rectangle deviceDimension;
   641 		int hDiff= (deviceHeight - actualImageSize.y) * actualImageSize.x;
   688     private Rectangle calculateFullScreenDimension()
   642 		// Check which side to scale to full screen size.
   689     {
   643 		// Width or Height will be full size.
   690         Point actualImageSize = ((AnimationPlayer)iPlayer).getImageDimension();
   644 		if(hDiff > vDiff){
   691         // initialize the deviceDimension, in local variable
   645 			rect.height = (deviceWidth * actualImageSize.y)/actualImageSize.x;
   692         iDisplay.syncExec(new Runnable()
   646 			rect.y= (deviceHeight -  rect.height)>>1;// divide by 2
   693         {
   647 		}else {
   694             public void run()
   648 			rect.width = (deviceHeight * actualImageSize.x)/actualImageSize.y;
   695             {
   649 			rect.x= (deviceWidth - rect.width)>>1;
   696                 //deviceDimension=iDisplay.getBounds();
   650 		}
   697                 deviceDimension=iDisplay.getClientArea();
   651 		return rect; 
   698             }
   652 	}
   699         });
   653 	
   700         int deviceWidth=deviceDimension.width;
       
   701         int deviceHeight=deviceDimension.height;
       
   702         //Returning the following rectangle after alteration
       
   703         Rectangle rect= new Rectangle(0,0,deviceWidth,deviceHeight);
       
   704 
       
   705         // to handle the divide by zero
       
   706         if (actualImageSize.x==0 && actualImageSize.y==0)
       
   707             return rect;
       
   708         // Following logic has been copied from
       
   709         //earlier native implementation ( from cmmadisplay.cpp::ScaleToFullScreen)
       
   710         // Smaller dimension scale ratio will be scaled.
       
   711         // Changed to area calculation to avoid reals and dimension
       
   712         // with smaller area will be scaled.
       
   713         // remember that the argument received in this function is a point
       
   714         // and it's x and y coordinate represent the width and height of the image respectively
       
   715         int vDiff=(deviceWidth - actualImageSize.x)* actualImageSize.y;
       
   716         int hDiff= (deviceHeight - actualImageSize.y) * actualImageSize.x;
       
   717         // Check which side to scale to full screen size.
       
   718         // Width or Height will be full size.
       
   719         if (hDiff > vDiff)
       
   720         {
       
   721             rect.height = (deviceWidth * actualImageSize.y)/actualImageSize.x;
       
   722             rect.y= (deviceHeight -  rect.height)>>1;// divide by 2
       
   723         }
       
   724         else
       
   725         {
       
   726             rect.width = (deviceHeight * actualImageSize.x)/actualImageSize.y;
       
   727             rect.x= (deviceWidth - rect.width)>>1;
       
   728         }
       
   729         return rect;
       
   730     }
       
   731 
   654 }
   732 }