01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.metrics;
10:
11: import java.awt.Dimension;
12: import java.awt.Font;
13: import javax.swing.*;
14: import javax.swing.table.AbstractTableModel;
15:
16: /**
17: * Base class for metrics frame
18: *
19: *@author Chris Seguin
20: *@created July 26, 1999
21: */
22: public abstract class MetricsFrame extends AbstractTableModel {
23: /*<Instance Variables>*/
24: /**
25: * Description of the Field
26: */
27: protected String[] descriptions = null;
28: /**
29: * Description of the Field
30: */
31: protected String[] values = null;
32:
33: /**
34: * Get the number of rows in the table
35: *
36: *@return The number of rows
37: */
38: public int getRowCount() {
39: return descriptions.length;
40: }
41:
42: /**
43: * Get the number of columns in the table
44: *
45: *@return the number of columns
46: */
47: public int getColumnCount() {
48: return 2;
49: }
50:
51: /**
52: * Get the value at a particular spot in the table
53: *
54: *@param row The row index
55: *@param column The column index
56: *@return The value at that location
57: */
58: public Object getValueAt(int row, int column) {
59: if (column == 0) {
60: return descriptions[row];
61: } else {
62: return values[row];
63: }
64: }
65:
66: /**
67: * Returns the title of this frame
68: *
69: *@return The Title value
70: */
71: protected abstract String getTitle();
72:
73: /*</Instance Variables>*/
74:
75: /**
76: * Create the frame
77: */
78: protected void createFrame() {
79: JTable table = new JTable(this );
80: table.setDefaultRenderer(table.getColumnClass(0),
81: new MetricsTableCellRenderer());
82:
83: JFrame frame = new JFrame(getTitle());
84: frame.getContentPane().add(table);
85: Dimension minimum = table.getPreferredSize();
86: frame
87: .setSize(Math.max(minimum.width, 300),
88: minimum.height + 30);
89: frame.setVisible(true);
90: }
91: }
|