javauis/lcdui_qt/src/javax/microedition/lcdui/ImageItem.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
child 57 59b3b4473dc8
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 package javax.microedition.lcdui;
    17 package javax.microedition.lcdui;
    18 
    18 
    19 import org.eclipse.swt.graphics.Point;
    19 import org.eclipse.swt.graphics.Point;
    22  * An item containing image. Image used will be copy of original image, so if
    22  * An item containing image. Image used will be copy of original image, so if
    23  * application modifies image after setting it to ImageItem, the Application
    23  * application modifies image after setting it to ImageItem, the Application
    24  * must call setImage()-method again if modifications need to appear in
    24  * must call setImage()-method again if modifications need to appear in
    25  * ImageItem too.
    25  * ImageItem too.
    26  */
    26  */
    27 public class ImageItem extends Item {
    27 public class ImageItem extends Item
       
    28 {
    28 
    29 
    29     /**
    30     /**
    30      * Left here for source compatibility purposes. Use layout directives from
    31      * Left here for source compatibility purposes. Use layout directives from
    31      * Item class instead.
    32      * Item class instead.
    32      */
    33      */
    74      * @param layout Combination of layout directives.
    75      * @param layout Combination of layout directives.
    75      * @param altText Alternate text which might be displayed if image cannot be
    76      * @param altText Alternate text which might be displayed if image cannot be
    76      *            displayed for some reason.
    77      *            displayed for some reason.
    77      * @throws IllegalArgumentException if Layout is invalid.
    78      * @throws IllegalArgumentException if Layout is invalid.
    78      */
    79      */
    79     public ImageItem(String label, Image image, int layout, String altText) {
    80     public ImageItem(String label, Image image, int layout, String altText)
       
    81     {
    80         this(label, image, layout, altText, Item.PLAIN);
    82         this(label, image, layout, altText, Item.PLAIN);
    81     }
    83     }
    82 
    84 
    83     /**
    85     /**
    84      * Constructor.
    86      * Constructor.
    91      * @param appMode Appearance mode.
    93      * @param appMode Appearance mode.
    92      * @throws IllegalArgumentException if apperance mode is invalid.
    94      * @throws IllegalArgumentException if apperance mode is invalid.
    93      * @throws IllegalArgumentException if Layout is invalid.
    95      * @throws IllegalArgumentException if Layout is invalid.
    94      */
    96      */
    95     public ImageItem(String label, Image image, int layout, String altText,
    97     public ImageItem(String label, Image image, int layout, String altText,
    96             int appMode) {
    98                      int appMode)
       
    99     {
    97 
   100 
    98         if (appMode != Item.PLAIN && appMode != Item.BUTTON
   101         if(appMode != Item.PLAIN && appMode != Item.BUTTON
    99                 && appMode != Item.HYPERLINK) {
   102                 && appMode != Item.HYPERLINK)
       
   103         {
   100             throw new IllegalArgumentException(
   104             throw new IllegalArgumentException(
   101                     MsgRepository.IMAGEITEM_EXCEPTION_INVALID_APPMODE);
   105                 MsgRepository.IMAGEITEM_EXCEPTION_INVALID_APPMODE);
   102         }
   106         }
   103 
   107 
   104         setLabel(label);
   108         setLabel(label);
   105         setImage(image);
   109         setImage(image);
   106         setLayout(layout);
   110         setLayout(layout);
   111     /**
   115     /**
   112      * Gets the image object associated with this ImageItem.
   116      * Gets the image object associated with this ImageItem.
   113      *
   117      *
   114      * @return Image-object.
   118      * @return Image-object.
   115      */
   119      */
   116     public Image getImage() {
   120     public Image getImage()
       
   121     {
   117         return image;
   122         return image;
   118     }
   123     }
   119 
   124 
   120     /**
   125     /**
   121      * Sets the image.
   126      * Sets the image.
   122      *
   127      *
   123      * @param image Image to be set.
   128      * @param image Image to be set.
   124      */
   129      */
   125     public void setImage(Image image) {
   130     public void setImage(Image image)
       
   131     {
   126         this.image = image;
   132         this.image = image;
   127         updateParent(UPDATE_SIZE_CHANGED);
   133         updateParent(UPDATE_SIZE_CHANGED);
   128     }
   134     }
   129 
   135 
   130     /**
   136     /**
   131      * Gets alternate text.
   137      * Gets alternate text.
   132      *
   138      *
   133      * @return Alternate text or null if no alternate text defined.
   139      * @return Alternate text or null if no alternate text defined.
   134      */
   140      */
   135     public String getAltText() {
   141     public String getAltText()
       
   142     {
   136         return alternateText;
   143         return alternateText;
   137     }
   144     }
   138 
   145 
   139     /**
   146     /**
   140      * Sets alternate text.
   147      * Sets alternate text.
   141      *
   148      *
   142      * @param newAltText Alternate text to be set.
   149      * @param newAltText Alternate text to be set.
   143      */
   150      */
   144     public void setAltText(String newAltText) {
   151     public void setAltText(String newAltText)
       
   152     {
   145         alternateText = newAltText;
   153         alternateText = newAltText;
   146         updateParent(UPDATE_SIZE_CHANGED);
   154         updateParent(UPDATE_SIZE_CHANGED);
   147     }
   155     }
   148 
   156 
   149     /**
   157     /**
   150      * Gets appearance mode of this item. Modes are defined in Item-class.
   158      * Gets appearance mode of this item. Modes are defined in Item-class.
   151      *
   159      *
   152      * @return Appearance mode.
   160      * @return Appearance mode.
   153      */
   161      */
   154     public int getAppearanceMode() {
   162     public int getAppearanceMode()
       
   163     {
   155         return appearanceMode;
   164         return appearanceMode;
   156     }
   165     }
   157 
   166 
   158     /* (non-Javadoc)
   167     /* (non-Javadoc)
   159      * @see javax.microedition.lcdui.Item#isFocusable()
   168      * @see javax.microedition.lcdui.Item#isFocusable()
   160      */
   169      */
   161     boolean isFocusable() {
   170     boolean isFocusable()
       
   171     {
   162         return (getNumCommands() > 0);
   172         return (getNumCommands() > 0);
   163     }
   173     }
   164 
   174 
   165     /**
   175     /**
   166      * Calculates minimum size of this item.
   176      * Calculates minimum size of this item.
   167      *
   177      *
   168      * @return Minimum size.
   178      * @return Minimum size.
   169      */
   179      */
   170     Point calculateMinimumSize() {
   180     Point calculateMinimumSize()
       
   181     {
   171         return ImageItemLayouter.calculateMinimumBounds(this);
   182         return ImageItemLayouter.calculateMinimumBounds(this);
   172     }
   183     }
   173 
   184 
   174     /**
   185     /**
   175      * Calculates preferred size of this item.
   186      * Calculates preferred size of this item.
   176      *
   187      *
   177      * @return Preferred size.
   188      * @return Preferred size.
   178      */
   189      */
   179     Point calculatePreferredSize() {
   190     Point calculatePreferredSize()
       
   191     {
   180         return ImageItemLayouter.calculatePreferredBounds(this);
   192         return ImageItemLayouter.calculatePreferredBounds(this);
   181     }
   193     }
   182 
   194 
   183 }
   195 }