1
package org.herac.tuxguitar.gui.editors.tab;
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;
8
public class CacheImage {
19
public CacheImage(Device device){
23
public CacheImage(Device device,int width,int height){
25
this.resizeCache(width,height);
28
private void resizeCache(int newWidth,int newHeight){
29
//solo si la medida es distinta
30
if(this.width != newWidth || this.height != newHeight){
32
this.cache = new Image(this.device,newWidth,newHeight);
34
//si el area es igual al viejo solo limpio la imagen.
36
if(this.cache == null || this.cache.isDisposed()){
37
this.cache = new Image(this.device,newWidth,newHeight);
39
getGC().fillRectangle(new Rectangle(0,0,newWidth,newHeight));
41
this.width = newWidth;
42
this.height = newHeight;
45
public void setSize(int width,int height){
46
this.resizeCache(width,height);
50
if(this.gc == null || this.gc.isDisposed()){
51
this.gc = new GC(this.cache);
56
public void paintImage(GC gc,int x,int y){
57
gc.drawImage(this.cache,x,y);
60
public Image getImage(){
64
public void dispose(){
65
if(cache != null && !cache.isDisposed()){
68
if(gc != null && !gc.isDisposed()){
73
public boolean isDisposed(){
74
return (cache == null || cache.isDisposed());