//TitlePanel.java
/*
 * Main Title Panel of the applet - two lines of text (titulo, titulo2)
 * authors: Singh T. Junior and Umberto Ravaioli
 * version 1.0 - Copyright: Amanogawa.com - All Rights Reserved
 */

import java.awt.*;
import java.applet.*;
import java.lang.*;


public class TitlePanel extends Panel{
	private static final Color bgcolor = new Color(236,236,236);
	String titulo, titulo2;
        Font titleFont;
    public boolean useSmallerFont;
	
        public TitlePanel(){
		super();
                titleFont = new Font("SanSerif",Font.BOLD,14);
                titulo="Unknown Title";
                titulo2="Unknown Title";
        }
        public TitlePanel(Font titleFont, String titulo, String titulo2,
                      boolean useSmallerFont){
                super();
                this.titulo=titulo;
                this.titulo2=titulo2;
                this.titleFont = titleFont;
                this.useSmallerFont = useSmallerFont;
        }
	public void paint(Graphics g){
                FontMetrics fmetrics=g.getFontMetrics();

		g.setColor(Color.gray);	
		g.fillRect(0,0,getSize().width-1,getSize().height-1);
		g.setColor(Color.black);
        	g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
        	g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
        	g.setColor(Color.white);
        	g.drawLine(0,0,getSize().width-1,0);
        	g.drawLine(0,0,0,getSize().height-1);

		g.setColor(Color.black);
        	g.drawLine(5,5,getSize().width-6,5);
        	g.drawLine(5,5,5,getSize().height-6);
		g.setColor(Color.white);
        	g.drawLine(5,getSize().height-5,getSize().width-5,getSize().height-5);
        	g.drawLine(getSize().width-5,5,getSize().width-5,getSize().height-5);

		g.setColor(bgcolor);
		g.fillRect(6,6,getSize().width-11,getSize().height-11);

		//Graphics 2D et up for SMOOTHING
                Graphics2D g2d = (Graphics2D)g;
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    
                //g.setFont(new Font("SanSerif",Font.PLAIN,11));
                if (useSmallerFont) {
                    float fontSize = titleFont.getSize2D();
                    fontSize -= 2;
                    g.setFont(titleFont.deriveFont(fontSize));
                } else {
                    g.setFont(titleFont);
                }

                fmetrics = g.getFontMetrics();
	        g.setColor(Color.black);
                //g.drawString(titulo,14,18);
                g.drawString(titulo,14,31);
                
                // Center the 2nd title between the remaining horizontal space

                int nextCol = 14 + fmetrics.stringWidth(titulo);
                int availWidth = getSize().width - nextCol;
                int border = (availWidth - fmetrics.stringWidth(titulo2))/2;
                nextCol += border;
                
                g.setColor(Color.lightGray);
                //g.drawString(titulo2,getSize().width-fmetrics.stringWidth(titulo2)-31,31);
                g.drawString(titulo2,nextCol,31);
                g.setColor(Color.red.darker());
                //g.drawString(titulo2,getSize().width-fmetrics.stringWidth(titulo2)-30,31);
                g.drawString(titulo2,nextCol-1,31);
                
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);

        }
}
