~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/table/SongTable.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Created on 28-ene-2006
3
 
 *
4
 
 * TODO To change the template for this generated file go to
5
 
 * Window - Preferences - Java - Code Style - Code Templates
6
 
 */
7
 
package org.herac.tuxguitar.gui.table;
8
 
 
9
 
import org.eclipse.swt.SWT;
10
 
import org.eclipse.swt.custom.SashForm;
11
 
import org.eclipse.swt.layout.GridData;
12
 
import org.eclipse.swt.layout.GridLayout;
13
 
import org.eclipse.swt.widgets.Button;
14
 
import org.eclipse.swt.widgets.Composite;
15
 
import org.eclipse.swt.widgets.Control;
16
 
import org.herac.tuxguitar.gui.editors.TablatureEditor;
17
 
 
18
 
/**
19
 
 * @author julian
20
 
 *
21
 
 * TODO To change the template for this generated type comment go to
22
 
 * Window - Preferences - Java - Code Style - Code Templates
23
 
 */
24
 
public class SongTable extends Composite{
25
 
    private TablatureEditor editor;
26
 
    private SashForm form;   
27
 
    private SongTableColumn[] columns;
28
 
    
29
 
    public SongTable(Composite parent,int columns,TablatureEditor editor) {
30
 
        super(parent,SWT.NONE);        
31
 
        this.editor = editor;                   
32
 
            this.setLayout(makeLayout());
33
 
            this.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false,0,0));          
34
 
 
35
 
            this.form = new SashForm(this,SWT.HORIZONTAL);                  
36
 
            this.form.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false,0,0));      
37
 
            this.form.SASH_WIDTH = 1;       
38
 
            
39
 
            this.makeColumns(columns);
40
 
    }
41
 
    
42
 
    private GridLayout makeLayout(){
43
 
                GridLayout layout = new GridLayout();
44
 
                layout.marginTop = 0;
45
 
                layout.marginBottom = 0;
46
 
                layout.marginLeft = 0;
47
 
                layout.marginRight = 0;
48
 
                layout.marginHeight = 0;
49
 
                layout.marginWidth = 0;
50
 
                layout.horizontalSpacing = 0;
51
 
                layout.verticalSpacing = 0;
52
 
                return layout;
53
 
    }
54
 
    
55
 
    public void makeColumns(int columns){
56
 
        this.columns = new SongTableColumn[columns];
57
 
        for(int i = 0; i< columns;i++){
58
 
            this.columns[i] = new SongTableColumn(this.form);
59
 
        }
60
 
    }
61
 
    
62
 
    public SongTableColumn getColumn(int index){
63
 
        return this.columns[index];
64
 
    }
65
 
    
66
 
    public void  clearColumnsAfter(int index){
67
 
        for(int i = 0; i< this.columns.length;i++){            
68
 
            this.columns[i].clearAfter(index);
69
 
        }
70
 
    }
71
 
       
72
 
    public int getItemCount(){
73
 
        return getColumn(0).getItemCount();
74
 
    }
75
 
    
76
 
    public int getHeaderHeight(){
77
 
        return getColumn(0).getHeaderHeight();
78
 
    }
79
 
    
80
 
    public void layout(){
81
 
        super.layout();
82
 
        for(int i = 0; i< this.columns.length;i++){            
83
 
            this.columns[i].layout();
84
 
        }
85
 
        this.form.layout();
86
 
    }
87
 
 
88
 
    public void setWeights(int[] weights){
89
 
        this.form.setWeights(weights);        
90
 
    }
91
 
 
92
 
    
93
 
    public class SongTableColumn extends Composite{
94
 
        private Button header;
95
 
        
96
 
        public SongTableColumn(Composite parent){
97
 
            super(parent,SWT.NONE);                             
98
 
            this.setLayout(makeLayout());                           
99
 
            this.header = new Button(this,SWT.LEFT);                
100
 
            this.header.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false,0,0));
101
 
        } 
102
 
        
103
 
        private GridLayout makeLayout(){
104
 
                GridLayout layout = new GridLayout();
105
 
                layout.marginTop = 0;
106
 
                layout.marginBottom = 0;
107
 
                layout.marginLeft = 0;
108
 
                layout.marginRight = 0;
109
 
                layout.marginHeight = 0;
110
 
                layout.marginWidth = 0;
111
 
                layout.horizontalSpacing = 0;
112
 
                layout.verticalSpacing = 0;
113
 
                return layout;
114
 
        }
115
 
        
116
 
        public void setName(String name){
117
 
            this.header.setText(name);
118
 
        }
119
 
        
120
 
        public int getItemCount(){
121
 
            return getChildren().length - 1;
122
 
        }
123
 
 
124
 
        public int getItemHeight(){
125
 
            Control[] controls = getChildren();
126
 
            return controls[1].getBounds().height;
127
 
        }
128
 
        
129
 
        public Control getItem(int index){
130
 
            Control[] controls = getChildren();
131
 
            return controls[index + 1];
132
 
        }        
133
 
        
134
 
        public int getHeaderHeight(){
135
 
            return this.header.getBounds().height;
136
 
        }
137
 
        
138
 
        public boolean isEmpty(){
139
 
                return getChildren().length <= 1;
140
 
        }
141
 
 
142
 
        public void clearAfter(int index){
143
 
            Control[] controls = getChildren();
144
 
            for(int i = (index + 1);i < controls.length;i++){
145
 
                controls[i].dispose();
146
 
            }
147
 
        }
148
 
    }
149
 
    
150
 
 
151
 
}