1
package org.herac.tuxguitar.gui.table;
3
import java.util.ArrayList;
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.custom.SashForm;
8
import org.eclipse.swt.custom.ScrolledComposite;
9
import org.eclipse.swt.layout.GridData;
10
import org.eclipse.swt.layout.GridLayout;
11
import org.eclipse.swt.widgets.Composite;
12
import org.eclipse.swt.widgets.Control;
14
public class TGTable {
15
private ScrolledComposite sComposite;
16
private Composite table;
17
private SashForm columnControl;
18
private Composite rowControl;
19
private TGTableColumn columnNumber;
20
private TGTableColumn columnName;
21
private TGTableColumn columnInstrument;
22
private TGTableColumn columnCanvas;
24
private int rowHeight;
25
private int scrollIncrement;
27
public TGTable(Composite parent){
28
this.rows = new ArrayList();
29
this.newTable(parent);
32
public void newTable(Composite parent){
33
this.sComposite = new ScrolledComposite(parent,SWT.BORDER | SWT.V_SCROLL);
34
this.sComposite.setLayout(new GridLayout());
35
this.sComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
36
this.sComposite.setAlwaysShowScrollBars(true);
37
this.sComposite.setExpandHorizontal(true);
38
this.sComposite.setExpandVertical(true);
39
this.table = new Composite(this.sComposite,SWT.NONE);
40
this.table.setLayout(newGridLayout(1,0,0,0,0));
41
this.table.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
43
this.columnControl = new SashForm(this.table,SWT.HORIZONTAL);
44
this.columnControl.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
46
this.columnNumber = new TGTableColumn(this,SWT.LEFT);
47
this.columnName = new TGTableColumn(this,SWT.LEFT);
48
this.columnInstrument = new TGTableColumn(this,SWT.LEFT);
49
this.columnCanvas = new TGTableColumn(this,SWT.CENTER);
50
this.columnControl.setWeights(new int[]{1,7,7,20});
52
this.rowControl = new Composite(this.table,SWT.NONE);
53
this.rowControl.setLayout(newGridLayout(1,0,1,0,1));
54
this.rowControl.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
56
this.sComposite.setContent(this.table);
59
public Composite getControl(){
64
this.rows.add(new TGTableRow(this));
67
private GridLayout newGridLayout(int cols,int marginWidth,int marginHeight,int horizontalSpacing,int verticalSpacing){
68
GridLayout layout = new GridLayout(cols,false);
69
layout.marginWidth = marginWidth;
70
layout.marginHeight = marginHeight;
71
layout.horizontalSpacing = horizontalSpacing;
72
layout.verticalSpacing = verticalSpacing;
76
public void addRowItem(TGTableColumn column,Control control,boolean computeSize){
78
this.rowHeight = Math.max(this.rowHeight,control.computeSize(SWT.DEFAULT,SWT.DEFAULT).y);
79
this.scrollIncrement = this.rowHeight;
81
column.addControl(control);
84
public int getMinHeight(){
85
return (this.sComposite.getMinHeight() + ( this.sComposite.getBorderWidth() * 2 ) );
88
public Composite getColumnControl(){
89
return this.columnControl;
92
public Composite getRowControl(){
93
return this.rowControl;
96
public int getRowHeight(){
97
return this.rowHeight;
100
public int getScrollIncrement(){
101
return this.scrollIncrement;
104
public TGTableColumn getColumnInstrument() {
105
return this.columnInstrument;
108
public TGTableColumn getColumnName() {
109
return this.columnName;
112
public TGTableColumn getColumnNumber() {
113
return this.columnNumber;
116
public TGTableColumn getColumnCanvas() {
117
return this.columnCanvas;
120
public TGTableRow getRow(int index){
121
if(index >= 0 && index < this.rows.size()){
122
return (TGTableRow)this.rows.get(index);
127
public void removeRowsAfter(int index){
128
while(index < this.rows.size()){
129
TGTableRow row = (TGTableRow)this.rows.get(index);
131
this.rows.remove(index);
133
this.notifyRemoved();
136
public int getRowCount(){
137
return this.rows.size();
140
public void update(){
141
this.layoutColumns();
142
this.table.layout(true,true);
143
this.sComposite.setMinHeight(this.table.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
144
this.sComposite.getVerticalBar().setIncrement( (getScrollIncrement() + this.sComposite.getBorderWidth() ) );
147
private void notifyRemoved(){
148
this.columnNumber.notifyRemoved();
149
this.columnName.notifyRemoved();
150
this.columnInstrument.notifyRemoved();
151
this.columnCanvas.notifyRemoved();
154
private void layoutColumns(){
155
this.columnNumber.layout();
156
this.columnName.layout();
157
this.columnInstrument.layout();
158
this.columnCanvas.layout();