Posted Saturday, August 20, 2005 @ 21:52:40
DBTableCellListener.cellValueChanged.col does not return the original columns
(as per documentation), but the current columns, if columns are shuffled.
Please verify the correct functionality.
See the example below. The results were obtained by selecting
the columns from left to right, and changing its values
This shuffling can be simualted by
dBTable1.moveColumn(2,0);
dBTable1.moveColumn(1,2);
QuickTable 2.0.5.20 (Free Version)
oldValue = col=1 origCol=2
oldValue = R0C2 col=2 origCol=1
oldValue = R0C1 col=3 origCol=0
with the moveColumn() lines removed
QuickTable 2.0.5.20 (Free Version).
oldValue = R0C1 col=1 origCol=0
oldValue = R0C2 col=2 origCol=1
oldValue = col=3 origCol=2
---- program follows ----
import java.awt.BorderLayout;
import java.io.*;
import java.util.Properties;
import javax.swing.JFrame;
import quick.dbtable.*;
/*
* dBTableTest.java
*
* Created on August 21, 2005, 3:43 AM
*/
public class dBTableTest extends JFrame {
DBTable dBTable1;
/** Creates a new instance of dBTableTest */
public dBTableTest(PipedOutputStream pOut) {
Properties prop = new Properties();
prop.put("delimiter","\t");
prop.put("firstRowHasColumnNames","true");
setSize(500,200);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
// InputStream in = new InputStream();
dBTable1 = new DBTable();
try {
PipedInputStream pIn = new PipedInputStream(pOut);
getContentPane().add(dBTable1, BorderLayout.CENTER);
dBTable1.refresh(pIn,prop);
dBTable1.addTableCellListener(new MyCellListerner());
int num = dBTable1.getColumnCount()+1;
Column c = new Column(num);
c.setHeaderValue("Column " + num);
dBTable1.addColumn(c);
// uncomment these 2 statments and it comes out right
//dBTable1.moveColumn(2,1);
dBTable1.moveColumn(1,2);
} catch (Exception e) {
e.printStackTrace();
}
}
class MyCellListerner implements quick.dbtable.DBTableCellListener {
public java.lang.Object cellValueChanged(int row,
int col,
java.lang.Object oldValue,
java.lang.Object newValue) {
// note the row starts with 0, col start with 1 :-(
// 2.0.5.20 : col can change after shuffling, not guaranteed, contrary to doc
int editingCol = dBTable1.getEditingColumn();
int origCol = dBTable1.getOriginalColumnIndex(editingCol) ;
System.out.println("oldValue = " + oldValue + " col=" + col + " origCol=" + origCol);
col = origCol;
return null;
}
}
public static void writer(PipedOutputStream pOut) {
StringBuffer buf = new StringBuffer();
buf.append("Column 1\tColumn 2\n");
buf.append("R0C1\tR0C2\n");
String s = new String(buf);
byte[] byteArray = s.getBytes();
try {
pOut.write(byteArray);
pOut.flush();
pOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
final PipedOutputStream pOut = new PipedOutputStream();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dBTableTest comp = new dBTableTest(pOut);
comp.setVisible(true);
comp.toFront();
}
});
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
writer(pOut);
}
});
}
}