01: package com.xoetrope.carousel.survey;
02:
03: import java.awt.event.MouseListener;
04: import javax.swing.JComboBox;
05: import javax.swing.JTable;
06: import javax.swing.table.DefaultTableColumnModel;
07: import javax.swing.table.DefaultTableCellRenderer;
08: import javax.swing.table.TableModel;
09: import javax.swing.table.TableColumn;
10:
11: /**
12: * A table extension class for managing questions
13: *
14: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
15: * the GNU Public License (GPL), please see license.txt for more details. If
16: * you make commercial use of this software you must purchase a commercial
17: * license from Xoetrope.</p>
18: * <p> $Revision: 1.5 $</p>
19: */
20: public class XTable extends JTable {
21: public XTable() {
22: super ();
23: setAutoCreateColumnsFromModel(false);
24: }
25:
26: public void setModel(TableModel model, XTableColumn[] columns,
27: MouseListener listener) {
28: setColumnModel(new DefaultTableColumnModel());
29: setModel(model);
30:
31: int modelIdx = 0;
32: for (int i = 0; i < columns.length; i++) {
33: if (!columns[i].isActive())
34: continue;
35: DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
36:
37: renderer.setHorizontalAlignment(columns[i].getAlignment());
38: TableColumn column;
39: if (columns[i].getCellEditor() == null
40: || columns[i].getCellEditor().getComponent() instanceof JComboBox)
41: column = new TableColumn(modelIdx++, columns[i]
42: .getWidth(), renderer, columns[i]
43: .getCellEditor());
44: else
45: column = new TableColumn(modelIdx++, columns[i]
46: .getWidth());
47: addColumn(column);
48: }
49:
50: addMouseListener(listener);
51: }
52:
53: }
|