package parser.ServletParser.library;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.table.TableColumn;
import javax.swing.border.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.tree.*;

public class MetricsInfoDlg extends JDialog {
	private JTreeTable table;
	public MetricsInfoDlg(StringList titles,StringList tooltips,boolean colSel[],DefaultMutableTreeNode metricsInfoTreeNode)
	{
		super();
		setModal(true);
		setTitle("Metrics Information");
		setLocation(100,100);
		setSize(new Dimension(800,400));

		MetricsTableValues values = new MetricsTableValues(titles);
		values.setData(colSel,metricsInfoTreeNode);

		Container pane = getContentPane();
		pane.setLayout(new BorderLayout());
		table = new JTreeTable(values);
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		table.getTreeCellRenderer().setLeafIcon(new ImageIcon("./images/class16.gif"));
		table.getTreeCellRenderer().setClosedIcon(new ImageIcon("./images/package16.gif"));
		table.getTreeCellRenderer().setOpenIcon(new ImageIcon("./images/package16.gif"));

		String tip = tooltips.getFirst();
		TableColumnModel tcm = table.getColumnModel();
		for (int i = 0; i < titles.nOfList(); i++) {
			TableColumn tc = tcm.getColumn(i);
			if (i == 0) tc.setPreferredWidth(200);
			MetricsInfoHeaderRenderer hr = new MetricsInfoHeaderRenderer();
			hr.setToolTipText(tip);
			tip = tooltips.getNext();
			tc.setHeaderRenderer(hr);
		}

		table.setDefaultRenderer(String.class,new MetricsItemRenderer());
		table.setDefaultRenderer(Integer.class,new IntRenderer());

		JScrollPane jsp = new JScrollPane(table);
		pane.add(jsp,BorderLayout.CENTER);
	}
}