01: /*
02: * LineNumberTable.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Color;
15: import javax.swing.JTable;
16: import javax.swing.SwingConstants;
17: import javax.swing.event.TableModelListener;
18: import javax.swing.table.DefaultTableCellRenderer;
19: import javax.swing.table.TableModel;
20:
21: public class LineNumberTable extends JTable {
22: protected JTable mainTable;
23:
24: public LineNumberTable(JTable table) {
25: super ();
26: mainTable = table;
27: setModel(new RowNumberTableModel());
28: DefaultTableCellRenderer rend = new DefaultTableCellRenderer();
29: //header.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
30: rend.setBackground(new Color(238, 240, 238));
31: rend.setHorizontalAlignment(SwingConstants.RIGHT);
32: setDefaultRenderer(Integer.class, rend);
33: getColumnModel().getColumn(0).setCellRenderer(rend);
34: setRowSelectionAllowed(false);
35: setColumnSelectionAllowed(false);
36: }
37:
38: public int getRowHeight(int row) {
39: return mainTable.getRowHeight(row);
40: }
41:
42: class RowNumberTableModel implements TableModel {
43: public int getRowCount() {
44: TableModel m = mainTable.getModel();
45: if (m == null)
46: return 0;
47: return m.getRowCount();
48: }
49:
50: public int getColumnCount() {
51: return 1;
52: }
53:
54: public Object getValueAt(int row, int column) {
55: return new Integer(row + 1);
56: }
57:
58: public String getColumnName(int columnIndex) {
59: return "";
60: }
61:
62: public Class getColumnClass(int columnIndex) {
63: return String.class;
64: }
65:
66: public boolean isCellEditable(int rowIndex, int columnIndex) {
67: return false;
68: }
69:
70: public void setValueAt(Object aValue, int rowIndex,
71: int columnIndex) {
72: }
73:
74: public void addTableModelListener(TableModelListener l) {
75: }
76:
77: public void removeTableModelListener(TableModelListener l) {
78: }
79: }
80:
81: }
|