FileDocCategorySizeDatePackage
ToolTip.javaAPI DocJMF 2.1.1e4813Mon May 12 12:20:52 BST 2003com.sun.media.ui

ToolTip

public class ToolTip extends Window
This class...

Fields Summary
private static final int
MARGIN_HORZ
private static final int
MARGIN_VERT
private String[]
arrStrings
Constructors Summary
public ToolTip(String strText)
Constructs the ToolTip object.

param
strText text to display


         	            
          
        super ( new Frame() );

        Font    font;

    	arrStrings = new String [1];
        arrStrings[0] = new String ( strText );
        font = new Font ( "Helvetica", Font.PLAIN, 10 );
        this.setFont ( font );
    	resizePopup ();
    
public ToolTip(String[] arrStrings)
Constructs the ToolTip object.

param
arrStrings array of strings

        super ( new Frame() );

    	int     i;
        Font    font;

    	arrStrings = new String [arrStrings.length];
    	for ( i = 0;   i < arrStrings.length;   i++ )
            arrStrings[i] = new String ( arrStrings[i] );
        font = new Font ( "Helvetica", Font.PLAIN, 10 );
        this.setFont ( font );
    	resizePopup ();
    
Methods Summary
public voidpaint(java.awt.Graphics graphics)
This method is called, when the window needs redrawing.

param
graphics the specified Graphics window

    	int		i;
    	Rectangle	rect;
    	int		nX, nY;
    	int		nHeight;
        Font            font;
    	FontMetrics	fontMetrics;


    	rect = getBounds ();
        font = getFont ();
    	fontMetrics = getFontMetrics ( font );

    	graphics.setColor ( new Color(255,255,192) );
    	graphics.fillRect ( 0, 0, rect.width, rect.height );

    	graphics.setColor ( Color.black );
    	graphics.drawRect ( 0, 0, rect.width-1, rect.height-1 );

    	nX = MARGIN_HORZ;
    	nY = MARGIN_VERT + fontMetrics.getAscent ();
    	nHeight = fontMetrics.getHeight ();
    	for ( i = 0;   i < arrStrings.length;   i++ ) {
            graphics.drawString ( arrStrings[i], nX, nY );
            nY += nHeight;
    	}
    
private voidresizePopup()
This method resizes window to fit all strings.

    	int		i;
    	int		nWidth = 0;
    	int		nHeight = 0;
    	int		nWidthText;
    	Rectangle	rect;
        Font            font;
    	FontMetrics	fontMetrics;
        Dimension       dim;


    	rect = getBounds ();
        font = getFont ();
    	fontMetrics = getFontMetrics ( font );

    	for ( i = 0;   i < arrStrings.length;   i++ ) {
            nWidthText = fontMetrics.stringWidth ( arrStrings[i] );
            nWidth = Math.max ( nWidth, nWidthText );
    	}
    	nHeight = fontMetrics.getHeight() * arrStrings.length;

    	rect.width = nWidth + 2 * MARGIN_HORZ;
    	rect.height = nHeight + 2 * MARGIN_VERT;
        dim = this.getSize ();
        if ( dim.height != rect.height  ||  rect.width > dim.width  ||  rect.width < dim.width / 2 )
    	    setBounds ( rect );
    
public voidsetText(java.lang.String strText)

    	arrStrings = new String [1];
        arrStrings[0] = new String ( strText );
    	resizePopup ();
        repaint ();