/*
 * @(#) TextPanel.java 1.0 96/11/20
 * Copyright (c) 1996 Larry Rodrigues 
 *
 */
   //package vis.util;
   import java.awt.*;
   import java.util.*;
 /** TextPanel class
   * @version 1.0  20 Nov 1996
   * @author Larry Rodrigues
   *
   */
   public class  TextPanel extends Canvas{
 
         Font fnt = new Font("Helevetica", Font.PLAIN, 10);
         int fontSize  =12;
         int rowHt = 10; 
         FontMetrics fm;
         String message;
         int rows= 0;
         String rowString[];
         int stx = 10;
         int sty =10;
         int width,height;
         public TextPanel(int wid, int ht, String msg){
                message = msg;
                width = wid;
                height = ht;

                parse(message);
                setSize(wid,ht);
         }

         public void setFont(Font ft){
                fnt = ft;
                fontSize = fnt.getSize();
         }
         public void setMessage(String txt){
            parse(txt);
            repaint();
         }

         public void parse(String msg){

                StringTokenizer st = new StringTokenizer(msg, "\n");
                rows = st.countTokens();
                rowString = new String[rows];
                for(int i =0; i<rows; i++){
                    rowString[i] = st.nextToken();
                }
                FontMetrics fm = getFontMetrics(fnt);
                rowHt = fm.getHeight();
                if(rows ==1){
                   if(width >0)
                   stx = (width-fm.stringWidth(msg))/2;
                }
                else stx =10;
                int maxRows = height/rowHt;
                //System.out.println("maxrows"+ maxRows + " rowHt "+ rowHt);
                if(maxRows >0){
                   sty = (int)(((maxRows - rows)/2+1)*rowHt);
                   //System.out.println("sty "+sty);
                }
          }

         public void paint(Graphics g){
                g.setColor(Color.black);
                g.setFont(fnt); 
                for(int i =0;i<rows;i++){
                    g.drawString(rowString[i], stx,(i*rowHt)+sty);
	        }
         }
    /*
         public void  update(Graphics g){
                g.setColor(Color.white);
                g.setFont(fnt); 
                for(int i=0;i<rows;i++){
                    g.drawString(rowString[i], stx,(i*rowHt)+sty);
	        }
         }
      */
   }

