
import java.awt.*;
import java.awt.image.*;
import java.net.URL;
import java.io.*;

public class Lbl extends Panel
{
  private int W = 0, H = 0;
  private int Wtxt = 0, Htxt = 0;
  private int gap = 5;
  private String txt;

  private Font plainFont, boldFont;
  private FontMetrics fmp, fmb;
  private Toolkit tk;
  private int leading;
  private int ascent;
  private int descent;
  private int lineHeight;
  private int charWidth;
  private Color textColor = Color.black;

  private int cursor_x = 0;

  public void setTextColor( Color c )
  {
    textColor = c;
  }

  public Color getTextColor()
  {
    return textColor;
  }

  public void paint( Graphics g ) {
    if( txt != null )
    {
      int w, h;
      w = size().width;
      h = size().height;
      g.setFont( boldFont );
      g.setColor( textColor );
      g.drawString( txt, W + gap, h/2 + ascent/2 );
      // g.drawLine( W + gap, h/2, w, h/2  );
      // g.drawLine( W + gap, h/2 + ascent/2, w, h/2 + ascent/2  );
    }
  }

  public Lbl()
  {
  }

  public Lbl( String s )
  {
    setText( s, 12 );
  }

  public String getText()
  {
    return txt;
  }

  public void setText( String s, int fontSize )
  {
    txt = s;

    tk = Toolkit.getDefaultToolkit();
    // plainFont = new Font( "Courier", Font.PLAIN, fontSize);
    boldFont = new Font( "Courier", Font.BOLD, fontSize);
    // fmp = tk.getFontMetrics( plainFont );
    fmb = tk.getFontMetrics( boldFont );
    leading = fmb.getLeading();
    ascent = fmb.getAscent();
    descent = fmb.getDescent();
    // System.out.println( "Leading: " + leading );
    // System.out.println( "Ascent: " + ascent );
    // System.out.println( "Descent: " + descent );
    if( txt != null )
    {
      Htxt = fmb.getHeight();
      // System.out.println( "Height: " + Htxt );
      Wtxt = fmb.stringWidth( txt );
    }
  }

  public Dimension minimumSize() {
    return new Dimension( 2 + W + gap + Wtxt, 2 + Math.max( H, Htxt ) );
  }

  public Dimension preferredSize() {
    return minimumSize();
  }

  public Dimension maximumSize() {
    return new Dimension( W, H );
  }
}
