PersonalJava & Information Appliances, Part II
by Jaison Dolvane and Kumanan Yogaratnam


Listing One
EBooleanGroup bg = new EBooleanGroup ();
// setting up Sticky Button
m_email = new EToolStickyButton ();
m_email.setBooleanGroup (bg);
m_email.setState (true);
m_email.setImagePosition (EToolStickyButton.TOP);
m_email.setImageBundle (ImageUtils.getImageBundledResource (getClass(), "email.gif"));
// ending setup of m_email
container_1.add (m_email);
// setting up Sticky Button
m_directory = new EToolStickyButton ();
m_directory.setBooleanGroup (bg);
m_directory.setState (false);
m_directory.setImagePosition (EToolStickyButton.TOP);
m_directory.setImageBundle (ImageUtils.getImageBundledResource 
                                            (getClass(), "directory.gif"));
// ending setup of m_directory
container_1.add (m_directory);
// setting up Sticky Button
m_scratch = new EToolStickyButton ();
m_scratch.setBooleanGroup (bg);
m_scratch.setState (false);
m_scratch.setImagePosition (EToolStickyButton.TOP);
m_scratch.setImageBundle (ImageUtils.getImageBundledResource 
                                            (getClass(), "scratchpad.gif"));
// ending setup of m_scratch
container_1.add (m_scratch);

Listing Two
// setting up List
m_phoneDirData = new PhoneDirListDataSource ();
m_dirList = new EListBox (m_phoneDirData);
// setting up wrapper for EList
EPanel tmp_0 = new EPanel ();
BaseBorder tmp_1;
tmp_0.setLayout (new BorderLayout ());
EScrollPanel sp_0 = new EScrollPanel (m_dirList);
tmp_0.add (sp_0, BorderLayout.CENTER);
tmp_0.setBorder (tmp_1 = new BevelBorder (new Color (89,165,118), false));
EScrollbar tmp_2 = new EScrollbar (EScrollbar.VERTICAL);
tmp_0.add (tmp_2, BorderLayout.EAST);
sp_0.setVerticalScrollbar (tmp_2);


Listing Three
package espial.demo.phoneapp;

import espial.awt.item.*;
import espial.util.*;
import espial.image.*;

import espial.datasource.list.*;

import java.awt.*;

/** A specialized data source which stored PhoneDirRecord entries. This 
 * implementation stores the list in memory and as a result the data is 
 * non-persistent. The idea here is that by re-implementing this class it is 
 * possible to modify the backend data source for the phone directory without 
 * the directory being any wiser.
 * We rely on the DefaultListDataSource object to manage the data in memory.
 */
public class PhoneDirListDataSource extends DefaultListDataSource {
    ImageBundle m_icon;
    public PhoneDirListDataSource (ImageBundle icon) {
        m_icon = icon;
    }
    /** Get an instance of espial.awt.item.Item that can render the data
     * at a specific index.
     * Developers note: By subclassing this method and setting the 
     *    m_renderer member before calling the superclass method allows the 
     *    subclass to override the Item that is used. Be careful though that 
     *    the Item the assigns is compatible with the one used by the 
     *    superclass unless you're completely overriding this method.
     *    @return an instance of Item. This method does not validate index, 
     *    so it always returns an instance, even though it may draw nothing.
     */
    public Item getDataRenderer (int ix) {
        if (m_renderer == null) {
            ImageItem it;
            m_renderer = (it = new ImageItem (m_icon.getImage ()));
            it.setImagePosition (ImageItem.LEFT);
        }
        Object data = getData (ix);
        if (data instanceof PhoneDirRecord) {
            m_renderer.setName (((PhoneDirRecord) data).name);
        }
        else {
           m_renderer.setName ("** Bad Record **");
        }
        return m_renderer;
    }
}




3


