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

« back to all changes in this revision

Viewing changes to TuxGuitar/src/org/herac/tuxguitar/gui/editors/tab/TGMeasureBuffer.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
package org.herac.tuxguitar.gui.editors.tab;
 
2
 
 
3
import org.eclipse.swt.graphics.Color;
 
4
import org.eclipse.swt.graphics.Device;
 
5
import org.eclipse.swt.graphics.Image;
 
6
import org.herac.tuxguitar.gui.editors.TGPainter;
 
7
 
 
8
public class TGMeasureBuffer {
 
9
        
 
10
        private Device device;
 
11
        
 
12
        private Image buffer;
 
13
        
 
14
        private TGPainter painter;
 
15
        
 
16
        private int width;
 
17
        
 
18
        private int height;
 
19
        
 
20
        public TGMeasureBuffer(Device device){
 
21
                this.device = device;
 
22
        }
 
23
        
 
24
        public void makeBuffer(int width,int height,Color background){
 
25
                this.dispose();
 
26
                this.buffer = new Image(this.device,width,height);
 
27
                this.width = width;
 
28
                this.height = height;
 
29
                this.fillBuffer(background);
 
30
        }
 
31
        
 
32
        private void fillBuffer(Color background){
 
33
                getPainter().setBackground(background);
 
34
                getPainter().initPath(TGPainter.PATH_FILL);
 
35
                getPainter().addRectangle(0,0,this.width,this.height);
 
36
                getPainter().closePath();
 
37
        }
 
38
        
 
39
        public TGPainter getPainter(){
 
40
                if(this.painter == null || this.painter.getGC().isDisposed()){
 
41
                        this.painter = new TGPainter(this.buffer);
 
42
                }
 
43
                return this.painter;
 
44
        }
 
45
        
 
46
        public void paintImage(TGPainter painter,int x,int y,int srcY){
 
47
                painter.drawImage(this.buffer,0,srcY, this.width, (this.height - srcY), x, (y + srcY), this.width, (this.height - srcY));
 
48
        }
 
49
        
 
50
        public Image getImage(){
 
51
                return this.buffer;
 
52
        }
 
53
        
 
54
        public void dispose(){
 
55
                if(this.painter != null && !this.painter.getGC().isDisposed()){
 
56
                        this.painter.dispose();
 
57
                }
 
58
                if(this.buffer != null && !this.buffer.isDisposed()){
 
59
                        this.buffer.dispose();
 
60
                }
 
61
        }
 
62
        
 
63
        public boolean isDisposed(){
 
64
                return (this.buffer == null || this.buffer.isDisposed());
 
65
        }
 
66
}