These changes were made by Embarcadero Technologies for KTable v2.1.3.v20060416-0120. Attached you will find the file KTable.java containing the fixes described below.
Faryaaz Kassam
Embarcadero Technologies
faryaaz.kassam@embarcadero.com
##################################################################################
#
# Bug 1
#
##################################################################################
- Modified the implementation of getCellForCoordinates(..) within de.kupzog.ktable.KTable to fix
a problem. Prior to this modification, the cell's column index was being computed without
accounting for the possibility that columns at the left of the table may be hidden (i.e. not
visible). Contrastingly, the cell's row index was being computed with provisions for invisible
rows at the top of the table. When iterating over the columns from left to right in the modified
version, we now start with the leftmost visible column (at index m_leftColumn) rather than
the leftmost column (at index 0). Also, a blank line (line 2026) was removed.
The following is a diff representing the change made to KTable.java:
2021c2021
< for (int i=0; width<x; i++) {
---
> for (int i=m_LeftColumn; width<x; i++) {
2026d2025
<
##################################################################################
#
# Bug 2
#
##################################################################################
Bug:
When repainting a cell in the last column, until you redraw the whole table,
the right-side border is not drawn in the vertical space that cell takes up.
This doesn't always happen. It will always happen, however, when the last column
takes up exactly the same amount or more then the table has to offer.
(Horizontal scroll bar visible.)
Solution:
- passing a clipping rectangle into drawCell and making sure it doesn't draw over
the border on the right
##################################################################################
#
# Bug 3
#
##################################################################################
Bug:
In some cases the bottom border doesn't get drawn.
Solution:
Adding the following code to the end of KTable.drawBottomSpace(...)
// draw bottom line
Rectangle clientArea = getClientArea();
if ( ( getStyle() & SWT.FLAT ) == 0 )
{
gc.setForeground( m_Display.getSystemColor( SWT.COLOR_WIDGET_DARK_SHADOW ) );
}
else
{
gc.setForeground( m_Display.getSystemColor( SWT.COLOR_LIST_BACKGROUND ) );
}
gc.drawLine( 1, clientArea.height - 1, clientArea.x + clientArea.width - 1, clientArea.height - 1 );
##################################################################################
#
# Bug 4
#
##################################################################################
Bug:
KTable.updateScrollBarVisibility() throws a null pointer exception if the model is null.
Solution:
Adding a simple null check. New code for KTable.updateScrollBarVisibility():
protected void updateScrollbarVisibility() {
KTableModel model = getModel();
if ( model != null )
{
Rectangle actualSize = getClientArea();
// vertical:
boolean showVertBar = false;
int theoreticalHeight = 1;
for (int i=0; i<model.getRowCount(); i++) {
theoreticalHeight+=model.getRowHeight(i);
if (theoreticalHeight>actualSize.height) {
showVertBar=true;
break;
}
}
getVerticalBar().setVisible(showVertBar);
// horizontal:
int theoreticalWidth = 0;
for (int i = 0; i < model.getColumnCount(); i++)
theoreticalWidth += model.getColumnWidth(i);
getHorizontalBar().setVisible(actualSize.width < theoreticalWidth);
}
}
##################################################################################
#
# Bug 5
#
##################################################################################
Bug:
When KTable is in row selection mode, and set to allow multiple row selections,
selection listeners do not get notified when one or more rows are removed from
the group of selected rows. (as long as at least one row remains selected,
no notification happens.)
Solution:
Modifying KTable.toggleSelection(...) to return true if the selection was added or
removed. The new code looks as follows:
/**
* Works in both modes: Cell and Row Selection.
* Has no redraw functionality!<p>
*
* Returns true, if succeeded
*/
protected boolean toggleSelection(int col, int row) {
if (isMultiSelectMode()) {
Object o;
if (isRowSelectMode()) {
o = new Integer(row);
} else {
o = new Point(col, row);
}
if (m_Selection.get(o) != null) {
m_Selection.remove(o);
return true;
} else {
m_Selection.put(o, o);
return true;
}
}
return false;
}
##################################################################################
#
# Bug 6
#
##################################################################################
Bug:
When scrolling the last element might not show up or only show up partially.
Solution:
Calculate the numer of visible and fully visible rows more accurately. Take fixed
into account properly. For modifications see the following methods:
private int getFullyVisibleRowCount(int fixedHeight) {
Rectangle rect = getClientArea();
ScrollBar sb = getHorizontalBar();
if (sb != null)
rect.height-=sb.getSize().y;
int count = getFixedRowCount();
int heightSum = fixedHeight;
for (int i=m_TopRow; heightSum<=rect.height && i<=m_Model.getRowCount(); i++) {
count++;
heightSum+=m_Model.getRowHeight(i);
}
return --count;
}
private int getVisibleRowCount(int fixedHeight)
{
Rectangle rect = getClientArea();
ScrollBar sb = getHorizontalBar();
if (sb != null)
rect.height-=sb.getSize().y;
int count = getFixedRowCount();
int heightSum = fixedHeight;
for (int i=m_TopRow; heightSum<rect.height && i<=m_Model.getRowCount(); i++) {
count++;
heightSum+=m_Model.getRowHeight(i);
}
return count;
}
protected void doCalculations() {
if (m_Model == null) {
ScrollBar sb = getHorizontalBar();
if (sb != null) {
sb.setMinimum(0);
sb.setMaximum(1);
sb.setPageIncrement(1);
sb.setThumb(1);
sb.setSelection(1);
}
sb = getVerticalBar();
if (sb != null) {
sb.setMinimum(0);
sb.setMaximum(1);
sb.setPageIncrement(1);
sb.setThumb(1);
sb.setSelection(1);
}
return;
}
Rectangle rect = getClientArea();
if (m_LeftColumn < getFixedColumnCount()) {
m_LeftColumn = getFixedColumnCount();
}
if (m_LeftColumn > m_Model.getColumnCount())
m_LeftColumn=0;
if (m_TopRow < getFixedRowCount()) {
m_TopRow = getFixedRowCount();
}
if (m_TopRow > m_Model.getRowCount())
m_TopRow = 0;
int fixedHeight = getFixedHeight();
m_ColumnsVisible = 0;
m_ColumnsFullyVisible = 0;
if (m_Model.getColumnCount() > getFixedColumnCount()) {
int runningWidth = getColumnLeft(m_LeftColumn);
for (int col = m_LeftColumn; col < m_Model.getColumnCount(); col++) {
if (runningWidth < rect.width + rect.x)
m_ColumnsVisible++;
runningWidth += getColumnWidth(col);
if (runningWidth < rect.width + rect.x)
m_ColumnsFullyVisible++;
else
break;
}
}
ScrollBar sb = getHorizontalBar();
if (sb != null) {
if (m_Model.getColumnCount() <= getFixedColumnCount()) {
sb.setMinimum(0);
sb.setMaximum(1);
sb.setPageIncrement(1);
sb.setThumb(1);
sb.setSelection(1);
} else {
sb.setMinimum(getFixedColumnCount());
sb.setMaximum(m_Model.getColumnCount());
sb.setIncrement(1);
sb.setPageIncrement(1);
sb.setThumb(m_ColumnsFullyVisible);
sb.setSelection(m_LeftColumn);
}
}
m_RowsFullyVisible = getFullyVisibleRowCount(fixedHeight);
m_RowsVisible = getVisibleRowCount( fixedHeight );
sb = getVerticalBar();
if (sb != null) {
if (m_Model.getRowCount() <= getFixedRowCount()) {
sb.setMinimum(0);
sb.setMaximum(1);
sb.setPageIncrement(1);
sb.setThumb(1);
sb.setSelection(1);
} else {
sb.setMinimum(getFixedRowCount());
sb.setMaximum(m_Model.getRowCount() - getFixedRowCount());
sb.setPageIncrement(m_RowsVisible - getFixedRowCount());
sb.setIncrement(1);
sb.setThumb(m_RowsFullyVisible);
sb.setSelection(m_TopRow);
}
}
}
Logged In: YES
user_id=954986
Originator: NO
I tried your patch but now the last line of my table disappear when I redraw it. I will try to find out why.