UNB/ CS/ David Bremner/ teaching/ java/ HistoryPane.java
import javax.swing.JPanel;
import java.awt.event.MouseListener;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

public class HistoryPane extends JPanel implements MouseListener {
    private DefaultListModel listModel;
    private JList listView;

    private HistoryPaneClient client=null;

    // Implementation of java.awt.event.MouseListener

    /**
     * Describe <code>mouseClicked</code> method here.
     *
     * @param e a <code>MouseEvent</code> value
     */
    public void mouseClicked(MouseEvent e) {
        if (client!=null){
            int index = listView.locationToIndex(e.getPoint()); 
            client.mouseClickCallback((String)listModel.elementAt(index));
        }
    }

    /**
     * Describe <code>mousePressed</code> method here.
     *
     * @param mouseEvent a <code>MouseEvent</code> value
     */
    public void mousePressed(MouseEvent mouseEvent) {
        
    }

    /**
     * Describe <code>mouseReleased</code> method here.
     *
     * @param mouseEvent a <code>MouseEvent</code> value
     */
    public void mouseReleased(MouseEvent mouseEvent) {
        
    }

    /**
     * Describe <code>mouseEntered</code> method here.
     *
     * @param mouseEvent a <code>MouseEvent</code> value
     */
    public void mouseEntered(MouseEvent mouseEvent) {
        
    }

    /**
     * Describe <code>mouseExited</code> method here.
     *
     * @param mouseEvent a <code>MouseEvent</code> value
     */
    public void mouseExited(MouseEvent mouseEvent) {
        
    }


    public void addClient(HistoryPaneClient theClient){
        client=theClient;
    }

    HistoryPane(){

        listModel=new DefaultListModel();

        listView= new JList(listModel);
        listView.addMouseListener(this);
        JScrollPane scroller=new JScrollPane(listView);

        this.add(scroller);
                
    }

    HistoryPane(String exampleItem){
        this();
        listView.setPrototypeCellValue(exampleItem);
    }


    public void addElement(Object obj){
        listModel.addElement(obj);
    }
    public void addMouseListener(MouseListener mel){
        listView.addMouseListener(mel);
    }



    public static void main(String args[]){
        DBFrame f=new DBFrame();
        HistoryPane h=new HistoryPane();
        f.getContentPane().add(h);
        f.setVisible(true);
        
        for (int i=1; i<1000; i++){
            h.addElement("item"+i);
        }
    }
}
//