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

« back to all changes in this revision

Viewing changes to src/org/herac/tuxguitar/gui/editors/tab/CacheImage.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.Device;
4
 
import org.eclipse.swt.graphics.GC;
5
 
import org.eclipse.swt.graphics.Image;
6
 
import org.eclipse.swt.graphics.Rectangle;
7
 
 
8
 
public class CacheImage {
9
 
        private Device device;
10
 
        
11
 
        private Image cache;
12
 
        
13
 
        private GC gc;
14
 
        
15
 
        private int width;
16
 
        
17
 
        private int height;
18
 
        
19
 
        public CacheImage(Device device){
20
 
                this(device,1,1);
21
 
        }
22
 
 
23
 
        public CacheImage(Device device,int width,int height){
24
 
                this.device = device;
25
 
                this.resizeCache(width,height);
26
 
        }
27
 
 
28
 
        private void resizeCache(int newWidth,int newHeight){
29
 
                //solo si la medida es distinta
30
 
                if(this.width != newWidth || this.height != newHeight){
31
 
                        this.dispose();
32
 
                        this.cache = new Image(this.device,newWidth,newHeight);                 
33
 
                }
34
 
                //si el area es igual al viejo solo limpio la imagen.
35
 
                else{
36
 
                        if(this.cache == null || this.cache.isDisposed()){
37
 
                                this.cache = new Image(this.device,newWidth,newHeight); 
38
 
                        }
39
 
                        getGC().fillRectangle(new Rectangle(0,0,newWidth,newHeight));
40
 
                }
41
 
                this.width = newWidth;
42
 
                this.height = newHeight;
43
 
        }
44
 
        
45
 
        public void setSize(int width,int height){
46
 
                this.resizeCache(width,height);
47
 
        }
48
 
                        
49
 
        public GC getGC(){
50
 
                if(this.gc == null || this.gc.isDisposed()){
51
 
                        this.gc = new GC(this.cache);
52
 
                }
53
 
                return gc;
54
 
        }       
55
 
        
56
 
        public void paintImage(GC gc,int x,int y){
57
 
                gc.drawImage(this.cache,x,y);
58
 
        }
59
 
        
60
 
        public Image getImage(){
61
 
                return this.cache;
62
 
        }
63
 
        
64
 
        public void dispose(){
65
 
                if(cache != null && !cache.isDisposed()){
66
 
                        cache.dispose();
67
 
                }               
68
 
                if(gc != null && !gc.isDisposed()){
69
 
                        gc.dispose();
70
 
                }
71
 
        }
72
 
        
73
 
        public boolean isDisposed(){
74
 
                return (cache == null || cache.isDisposed());
75
 
        }
76
 
}