01: package org.uispec4j;
02:
03: import org.uispec4j.utils.UIComponentFactory;
04: import org.uispec4j.utils.UnitTestCase;
05: import org.uispec4j.xml.EventLogger;
06:
07: import javax.swing.*;
08: import javax.swing.table.AbstractTableModel;
09: import javax.swing.table.DefaultTableCellRenderer;
10: import java.awt.*;
11: import java.awt.event.MouseEvent;
12: import java.awt.event.MouseListener;
13:
14: public abstract class TableTestCase extends UnitTestCase {
15: Table table;
16: JTable jTable;
17:
18: protected void setUp() throws Exception {
19: super .setUp();
20: init(new JTable(new TableSelectionTest.MyModel()));
21: }
22:
23: private void init(JTable table) {
24: jTable = table;
25: jTable
26: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
27: jTable.setName("myTable");
28: jTable.setDefaultEditor(Integer.class, new DefaultCellEditor(
29: new JComboBox(new Object[] { new Integer(3),
30: new Integer(4), new Integer(5) })));
31: this .table = (Table) UIComponentFactory
32: .createUIComponent(jTable);
33: }
34:
35: protected class MyModel extends AbstractTableModel {
36: String[] columnNames = new String[] { "0", "1", "2" };
37: Object[][] rowData = new Object[][] {
38: { "a", Boolean.TRUE, new Integer(3) },
39: { "c", Boolean.FALSE, new Integer(4) } };
40: Class[] columnClasses = new Class[] { String.class,
41: Boolean.class, Integer.class };
42:
43: public String getColumnName(int column) {
44: return columnNames[column].toString();
45: }
46:
47: public int getRowCount() {
48: return rowData.length;
49: }
50:
51: public int getColumnCount() {
52: return columnNames.length;
53: }
54:
55: public Object getValueAt(int row, int col) {
56: return rowData[row][col];
57: }
58:
59: public void setValueAt(Object aValue, int rowIndex,
60: int columnIndex) {
61: rowData[rowIndex][columnIndex] = aValue;
62: fireTableCellUpdated(rowIndex, columnIndex);
63: }
64:
65: public Class getColumnClass(int columnIndex) {
66: return columnClasses[columnIndex];
67: }
68:
69: public boolean isCellEditable(int row, int column) {
70: return (row != 1) || (column != 0);
71: }
72: }
73:
74: void installJPanelRenderer() {
75: DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {
76: public Component getTableCellRendererComponent(
77: JTable table, Object value, boolean isSelected,
78: boolean hasFocus, int row, int column) {
79: return new JPanel();
80: }
81: };
82: jTable.setDefaultRenderer(Boolean.class, renderer);
83: }
84: }
|