home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
TextAndImageCell.java
< prev
next >
Wrap
Text File
|
1998-08-21
|
5KB
|
187 lines
package symantec.itools.awt.multiList;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.FontMetrics;
import symantec.itools.awt.MultiList;
// 07/14/97 LAB Separeated from Multilist.java. Made public to accommodate future
// extendibility of the MultiList class.
// 07/30/97 CAR marked fields transient as needed
/**
* This is a helper class to the MultiList class.
* It contains and draws the image and text of a cell.
* @version 1.1, July 14, 1997
* @author Symantec
*/
public class TextAndImageCell
extends Cell
implements java.awt.image.ImageObserver, java.io.Serializable
{
/**
* The MultiList this cell belongs to.
*/
protected MultiList list = null;
/**
* This cell's text value.
*/
protected String text = "";
/**
* This cell's image value.
*/
protected transient Image im = null;
/**
* Constructs a default TextAndImageCell.
* @param l the MultiList this cell is in
*/
public TextAndImageCell(MultiList l)
{
list = l;
}
/**
* Constructs a TextAndImageCell with the given text value.
* @param l the MultiList this cell is in
* @param s the cell's text value
*/
public TextAndImageCell(MultiList l, String s)
{
list = l;
text = s;
}
/**
* Constructs a TextAndImageCell with the given image value.
* @param l the MultiList this cell is in
* @param i the cell's image value
*/
public TextAndImageCell(MultiList l, Image i)
{
list = l;
im = i;
}
/**
* Constructs a TextAndImageCell with the given text and image values.
* @param l the MultiList this cell is in
* @param s the cell's text value
* @param i the cell's image value
*/
public TextAndImageCell(MultiList l, String s, Image i)
{
list = l;
text = s;
im = i;
}
/**
* Draws the cell using the given graphics context.
* @param g the graphics context used for drawing
* @param align the column alignment, one of LEFT, CENTER, or RIGHT
* @param x the horizontal cell position, in pixels
* @param y the vertical cell position, in pixels
* @param w the width of the cell, in pixels
* @param h the height of the cell, in pixels
* @param asc the ascent metric of the cell's font
* @see symantec.itools.awt.MultiList#LEFT
* @see symantec.itools.awt.MultiList#CENTER
* @see symantec.itools.awt.MultiList#RIGHT
*/
public void drawCell(Graphics g, int align, int x, int y, int w, int h, int asc)
{
FontMetrics fm = g.getFontMetrics();
int sw = fm.stringWidth(text);
int offset = 0;
switch(align)
{
case MultiList.LEFT:
{
if (im != null)
{
g.drawImage(im, x, y, this);
offset = im.getWidth(this) + 2;
}
g.drawString(text, x + offset, y+asc);
break;
}
case MultiList.CENTER:
{
if (sw > w)
g.drawString(text, x, y+asc);
else
g.drawString(text, x + (w-sw)/2, y+asc);
break;
}
case MultiList.RIGHT:
{
if (sw > w)
g.drawString(text, x, y+asc);
else
g.drawString(text, x+w-sw-6, y+asc);
break;
}
}//switch
}
/**
* Returns this cell's text.
*/
public String getText()
{
return text;
}
/**
* Returns this cell's image.
*/
public Image getImage()
{
return im;
}
/**
* Incrementally updates an image as image data becomes available.
* This is a standard Java AWT method which gets called by the AWT to
* incrementally draw an image as more image data becomes available.
* @param img the image being drawn
* @param flags image update flags (see class ImageObserver)
* @param x horizontal position, in pixels
* @param y vertical position, in pixels
* @param w width, in pixels
* @param h height, in pixels
*
* @return true if image has been completely loaded
*
* @see java.awt.image.ImageObserver
* @see java.awt.image.ImageObserver#imageUpdate
*/
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
{
if ((flags & (ALLBITS|ABORT)) != 0)
{
list.redraw();
list.repaint();
return false;
}
return true;
}
/**
* Returns a string representation of this component.
* This is a standard Java AWT method which gets called to generate
* a string that represents this component.
*
* @return a meaningful string about this object
*/
public String toString()
{
return text;
}
}