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
| public class TestTable {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Composite composite = new Composite(shell,SWT.NONE);
composite.setEnabled(true);
composite.setLayout(new Layout() {
// vite fait pour le POC : à améliorer, en particulier sur la gestion du cache
@Override
protected void layout(Composite composite, boolean flushCache) {
Point size = computeSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache);
composite.getChildren()[0].setBounds(0, 0, size.x, size.y);
composite.getChildren()[1].setBounds(0, 0, size.x, size.y);
}
@Override
protected Point computeSize(Composite composite, int wHint, int hHint,
boolean flushCache) {
Rectangle area = composite.getClientArea();
int width = area.width;
int height = area.height;
if ( wHint!=SWT.DEFAULT ) {
width = wHint;
}
if ( hHint!=SWT.DEFAULT ) {
height = hHint;
}
return new Point(width, height);
}
});
final Canvas canvas = new Canvas(composite, SWT.TRANSPARENT);
final Table table = new Table(composite, SWT.V_SCROLL);
for (int i = 0; i < 5; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText("Column "+i);
column.setWidth(200);
}
// Create rows
for (int i = 0; i < 50; i++) {
TableItem item = new TableItem(table, SWT.NONE);
for (int j = 0; j < 5; j++) {
item.setText(j, "Item "+i+" value "+j);
}
}
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Point barSize = table.getVerticalBar().getSize();
Rectangle tableBounds = table.getBounds();
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_RED));
e.gc.setAlpha(128);
e.gc.fillRectangle(tableBounds.width-barSize.x, 0, barSize.x, barSize.y);
// le thumb
Rectangle thumbBounds = table.getVerticalBar().getThumbBounds();
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_GREEN));
e.gc.fillRectangle(thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height);
// les boutons, en supposont qu'on puisse determiner leur taille en faisant la différence entre le bar et le track
Rectangle trackBounds = table.getVerticalBar().getThumbBounds();
Point buttonSize = new Point(trackBounds.y, barSize.x);
e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_CYAN));
e.gc.fillRectangle(tableBounds.width-barSize.x, 0, buttonSize.x, buttonSize.y);
e.gc.fillRectangle(tableBounds.width-barSize.x, barSize.y - buttonSize.y, buttonSize.x, buttonSize.y);
}
});
canvas.setEnabled(false);
shell.setVisible(true);
shell.setSize(600, 400);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose();
}
} |
Partager