// (c) MIT 2003.  All rights reserved.

// -*-Mode: Java -*- 
// TinyBrowserPane.java -- 
// Author: mark a. foltz <mfoltz@ai.mit.edu>
// Maintainer: mark a. foltz <mfoltz@ai.mit.edu>
// Copyright: Copyright (C) 2000 by mark a. foltz
// Created: <Thu Jan  6 07:39:55 2000> 
// Keywords: 

/**
 * 
 * @author mark a. foltz <mfoltz@ai.mit.edu>
 * @version $Id: TinyBrowserPane.java,v 1.2 2003/03/06 00:40:41 moltmans Exp $
 * */

package rec.tinybrowser;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class TinyBrowserPane extends ScrollPane  {

  public static final Color DEFAULT_FOREGROUND = Color.black;
  public static final Color DEFAULT_BACKGROUND = Color.white;
  public static final Color DEFAULT_HYPERLINK = Color.red;
  public static final Font DEFAULT_FONT = new Font("SERIF", Font.PLAIN, 11);
  public static final int DEFAULT_INSETS = 3;
  public static final int INDENT_INCREMENT = 9;
  public static final int BULLET_INDENT = 5;

  public static final int DEFAULT_ALIGN = Content.ALIGN_LEFT;

  private TinyBrowserPanel panel;

  public TinyBrowserPane(int w, int h) {
    this(w, h, DEFAULT_FOREGROUND, DEFAULT_BACKGROUND, DEFAULT_HYPERLINK,
	 DEFAULT_FONT, DEFAULT_ALIGN);
  }

  public TinyBrowserPane(int w, int h, Color fg, Color bg, Color hyper,
			 Font font, int align) {
    super(ScrollPane.SCROLLBARS_AS_NEEDED);
    panel = new TinyBrowserPanel(fg, bg, hyper, font, align, this);
    addImpl(panel, null, 0);
    setSize(w, h);
  }

  public void display(Content content) {
    panel.display(content);
  }

  public void setBackground(Color bg) {
    panel.setBackground(bg);
  }

  public void addActionListener(ActionListener l) {
    panel.addActionListener(l);
  }

  public void removeActionListener(ActionListener l) {
    panel.removeActionListener(l);
  }

  public void scrollToBottom() 
  {
    setScrollPosition( getScrollPosition().x, panel.getHeight() );
  }
  
  public Dimension getPreferredSize() { return getSize(); }

  public void setSize(Dimension d) {
    setSize(d.width, d.height);
    internalSetSize(d.width, d.height);
  }
    
  public void setSize(int w, int h) {
    super.setSize(w, h);
    internalSetSize(w,h);
  }

  public void setBounds(int x, int y, int width, int height) {
    super.setBounds(x,y,width,height);
    internalSetSize(width, height);
  }
    
  public void setBounds(Rectangle r) {
    super.setBounds(r);
    internalSetSize(r.width, r.height);
  }  

  private void internalSetSize(int w, int h) {
//      System.err.println("TinyBrowserPane.internalSetSize: "+w+","+h);
    panel.setSize(w-getVScrollbarWidth()-4,panel.getSize().height);
    panel.repaint();
  }
  
}
