104 |
{ |
{ |
105 |
Point begin, curr; |
Point begin, curr; |
106 |
|
|
|
private int getRowForPoint(Point p) |
|
|
{ |
|
|
int y0 = table.getLocation().y; |
|
|
int nrows = table.getRowCount(); |
|
|
Dimension gap = table.getIntercellSpacing(); |
|
|
int height = table.getRowHeight() + (gap == null ? 0 : gap.height); |
|
|
int y = p.y; |
|
|
for (int i = 0; i < nrows; ++i) |
|
|
{ |
|
|
if (0 <= y && y < height) |
|
|
return i; |
|
|
y -= height; |
|
|
} |
|
|
return -1; |
|
|
} |
|
|
|
|
|
private int getColForPoint(Point p) |
|
|
{ |
|
|
int x0 = table.getLocation().x; |
|
|
int ncols = table.getColumnCount(); |
|
|
Dimension gap = table.getIntercellSpacing(); |
|
|
TableColumnModel cols = table.getColumnModel(); |
|
|
int x = p.x; |
|
|
for (int i = 0; i < ncols; ++i) |
|
|
{ |
|
|
int width = cols.getColumn(i).getWidth() + (gap == null ? 0 : gap.width); |
|
|
if (0 <= x && x < width) |
|
|
return i; |
|
|
x -= width; |
|
|
} |
|
|
return -1; |
|
|
} |
|
|
|
|
107 |
private void updateSelection() |
private void updateSelection() |
108 |
{ |
{ |
109 |
if (table.getRowSelectionAllowed()) |
if (table.getRowSelectionAllowed()) |
110 |
{ |
{ |
111 |
int lo_row = getRowForPoint(begin); |
int lo_row = table.rowAtPoint(begin); |
112 |
int hi_row = getRowForPoint(curr); |
int hi_row = table.rowAtPoint(curr); |
113 |
ListSelectionModel rowModel = table.getSelectionModel(); |
ListSelectionModel rowModel = table.getSelectionModel(); |
114 |
if (lo_row != -1 && hi_row != -1) |
if (lo_row != -1 && hi_row != -1) |
115 |
rowModel.setSelectionInterval(lo_row, hi_row); |
rowModel.setSelectionInterval(lo_row, hi_row); |
117 |
|
|
118 |
if (table.getColumnSelectionAllowed()) |
if (table.getColumnSelectionAllowed()) |
119 |
{ |
{ |
120 |
int lo_col = getColForPoint(begin); |
int lo_col = table.columnAtPoint(begin); |
121 |
int hi_col = getColForPoint(curr); |
int hi_col = table.columnAtPoint(curr); |
122 |
ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); |
ListSelectionModel colModel = table.getColumnModel().getSelectionModel(); |
123 |
if (lo_col != -1 && hi_col != -1) |
if (lo_col != -1 && hi_col != -1) |
124 |
colModel.setSelectionInterval(lo_col, hi_col); |
colModel.setSelectionInterval(lo_col, hi_col); |