-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombineTable.java
More file actions
131 lines (75 loc) · 2.98 KB
/
CombineTable.java
File metadata and controls
131 lines (75 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
public class CombineTable extends JTable {
public CombineData combineData;
public CombineTable(TableModel tableModel) {
super(tableModel);
super.setUI(new CombineTableUI());
}
public CombineTable(CombineData combineData, TableModel tableModel) {
super(tableModel);
this.combineData = combineData;
for (Integer column : combineData.combineColumns) {
TableColumn tableColumn = super.columnModel.getColumn(column);
tableColumn.setCellRenderer(new CombineColumnRender());
}
super.setUI(new CombineTableUI());
}
public void setCombineData(CombineData combineData) {
this.combineData = combineData;
for (Integer column : combineData.combineColumns) {
TableColumn tableColumn = super.columnModel.getColumn(column);
tableColumn.setCellRenderer(new CombineColumnRender());
}
}
@Override
public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
// required because getCellRect is used in JTable constructor
if (combineData == null) {
return super.getCellRect(row, column, includeSpacing);
}
// add widths of all spanned logical cells
int sk = combineData.visibleCell(row, column);
//Rectangle r1 = super.getCellRect(row, sk, includeSpacing);
Rectangle rect1 = super.getCellRect(sk, column, includeSpacing);
if (combineData.span(sk, column) != 1) {
for (int i = 1; i < combineData.span(sk, column); i++) {
//r1.width += getColumnModel().getColumn(sk + i).getWidth();
rect1.height += this.getRowHeight(sk + i);
}
}
return rect1;
}
@Override
public int rowAtPoint(Point p) {
int column = super.columnAtPoint(p);
// -1 is returned by columnAtPoint if the point is not in the table
if (column < 0) {
return column;
}
int row = super.rowAtPoint(p);
return combineData.visibleCell(row, column);
}
@Override
public boolean isCellEditable(int row, int column) {
if (combineData.combineColumns.contains(column)) {
return false;
}
return super.isCellEditable(row, column);
}
@Override
public boolean isCellSelected(int row, int column) {
if (combineData.combineColumns.contains(column)) {
return false;
}
return super.isCellSelected(row, column);
}
}