This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Using the Image Library

Documents for the development of and with JVx.

--Using the Image Library

Postby Development@SIB » Thu Sep 16, 2010 12:00 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




The Image Library is used to conveniently access pictures in an application. Pictures are usually stored in the classpath of an application and loaded using the complete resource path. For example:

Code: Select all
Toolkit.class.getResourceAsStream("/javax/rad/genui/images/32x32/about.png");


The Image Library allows access via the complete resource path as well as via predefined and/or user-defined picture names. The following example loads the picture about.png from our previous example via the resource path and the predefined picture name:

Code: Select all
//possible
UIImage.getImage("/javax/rad/genui/images/32x32/about.png");

//recommended
UIImage.getImage(UIImage.ABOUT_LARGE);


The Image Library already contains important application-pictures/icons that are commonly used, such as:
SAVE_SMALL, SAVE_LARGE,
COPY_SMALL, COPY_LARGE,
PASTE_SMALL, PASTE_LARGE,
SEARCH_SMALL, SEARCH_LARGE,
etc.

A small (16x16 px) and a large (24x24 px) version exists for each predefined picture. The small version is used for menus and buttons, whereas the large version is used for notifications, details or toolbars.

Please use the class UIImage for a complete list of predefined pictures.

Using the Image Library and picture names, it is very easy to replace single pictures at a central location for the entire application. It is not necessary to search for a picture in each work-screen and to change the resource path. Changing the picture definition is sufficient.


Example

Our Application only uses the Image Library for the display of pictures/icons. We use predefined pictures and additionally define our own pictures that are not contained in the Image Library. We also change some of the predefined pictures, since they do not suit our taste.

We define the changes in our application´s constructor:

Code: Select all
//We don't like the predefined add/remove images
UIImage.setImageMapping(UIImage.ADD_SMALL,
                        "/com/sibvisions/apps/packung/images/16x16/new.png");
UIImage.setImageMapping(UIImage.REMOVE_SMALL,
                        "/com/sibvisions/apps/packung/images/16x16/delete.png");

//We don't need the large images
UIImage.setImageMapping(UIImage.ADD_LARGE, null);
UIImage.setImageMapping(UIImage.REMOVE_LARGE, null);

//We have special images which are not predefined
UIImage.setImageMapping(PackungApplication.IMAGE_NOBODY,
                        "/com/sibvisions/apps/packung/images/nobody.png");


On one of our work-screens we now use the Image Library for our button's pictures:

Code: Select all
UIButton butOK = new UIButton();
butOK.setImage(UIImage.getImage(UIImage.OK_SMALL));


It is also possible to use the picture names instead of the resource path information. This is the case when no IImage instance is required, e.g.:

Code: Select all
/** Yes/ No Choice editor. */
new UIChoiceCellEditor(new Object [] {"Y", "N"},
                       new String [] {UIImage.CHECK_YES_SMALL,
                                      UIImage.CHECK_SMALL},
                                      UIImage.CHECK_SMALL);

Compare this to the access without the Image Library:

Code: Select all
/** Yes/ No Choice editor. */
new UIChoiceCellEditor(new Object [] {"Y", "N"},
                       new String [] {"/javax/rad/genui/images/16x16/check_yes.png",
                                      "/javax/rad/genui/images/16x16/check.png"},
                                      "/javax/rad/genui/images/16x16/check.png");


If we now decide to change the application´s pictures, we do not need to search the entire application. It is sufficient to change the definitions:

Code: Select all
UIImage.setImageMapping(UIImage.CHECK_YES_SMALL,
                        "/com/sibvisions/apps/packung/images/16x16/packung_check_yes_small.png");
UIImage.setImageMapping(UIImage.CHECK_SMALL,
                        "/com/sibvisions/apps/packung/images/16x16/packung_check_small.png");


Note

The Image Library saves pictures that have already been used, which prevents loading the same picture multiple times. This not only saves memory, it also positively affects performance.
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation