javauis/lcdui_qt/src/javax/microedition/lcdui/ImageItem.java
changeset 57 59b3b4473dc8
parent 23 98ccebc37403
--- a/javauis/lcdui_qt/src/javax/microedition/lcdui/ImageItem.java	Fri Jul 23 12:27:20 2010 +0300
+++ b/javauis/lcdui_qt/src/javax/microedition/lcdui/ImageItem.java	Thu Aug 05 16:07:57 2010 +0300
@@ -26,7 +26,6 @@
  */
 public class ImageItem extends Item
 {
-
     /**
      * Left here for source compatibility purposes. Use layout directives from
      * Item class instead.
@@ -63,6 +62,13 @@
      */
     public static final int LAYOUT_NEWLINE_AFTER = Item.LAYOUT_NEWLINE_AFTER;
 
+    /**
+     * If ImageItem is changed, reasons for Re-layouting.
+     */
+	static final int UPDATE_ALTTEXT = UPDATE_ITEM_MAX << 1;
+	static final int UPDATE_IMAGE = UPDATE_ITEM_MAX << 2;
+
+
     private Image image;
     private int appearanceMode;
     private String alternateText;
@@ -129,8 +135,12 @@
      */
     public void setImage(Image image)
     {
+    	if((image == null) && (this.image == null))
+		{
+			return;
+		}
         this.image = image;
-        updateParent(UPDATE_SIZE_CHANGED);
+        updateParent(UPDATE_IMAGE | UPDATE_SIZE_CHANGED);
     }
 
     /**
@@ -151,7 +161,7 @@
     public void setAltText(String newAltText)
     {
         alternateText = newAltText;
-        updateParent(UPDATE_SIZE_CHANGED);
+        updateParent(UPDATE_ALTTEXT);
     }
 
     /**
@@ -173,6 +183,44 @@
     }
 
     /**
+     * Adds command to this ImageItem. If same command is already added to this item,
+     * nothing happens.
+     *
+     * @param command A command to be added.
+     * @throws NullPointerException if cmd is null.
+     */
+    public void addCommand(Command command)
+    {
+    	int numCmds = getNumCommands();
+
+    	super.addCommand(command);
+		
+		if((getNumCommands() != numCmds) && (getNumCommands() == 1))
+		{
+			updateParent(UPDATE_SIZE_CHANGED);
+		}
+    }
+
+    /**
+     * Removes command from the ImageItem. If command doesn't exists in this item,
+     * nothing happens.
+     *
+     * @param command The command to be removed.
+     */
+    public void removeCommand(Command command)
+    {
+    	int numCmds = getNumCommands();
+
+    	super.removeCommand(command);
+		
+		if((getNumCommands() != numCmds) && (getNumCommands() == 0))
+
+		{
+			updateParent(UPDATE_SIZE_CHANGED);
+		}
+    }
+
+    /**
      * Calculates minimum size of this item.
      *
      * @return Minimum size.