/*
* Created on 2003/05/24
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.jpn.xucker.subplayer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
/**
* @author ak
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class ImageCanvas extends Canvas implements PaintListener{
private Image image;
private String text;
private Font font=new Font(this.getDisplay(),"MS –¾’©",24,SWT.NONE);
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public ImageCanvas(Composite composite){
super(composite,SWT.NO_BACKGROUND);
this.addPaintListener(this);
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
if(this.image!=null){
this.image.dispose();
}
this.image = image;
}
public void paintControl(PaintEvent e) {
GC gc=new GC(this);
Image bgImage = new Image(this.getShell().getDisplay(), this.getClientArea());
GC imageGc = new GC(bgImage);
imageGc.setBackground(new Color(this.getDisplay(),0,0,0));
imageGc.setForeground(new Color(this.getDisplay(),255,0,0));
imageGc.fillRectangle(0,0,getBounds().width,getBounds().height);
//System.out.println(this.getBounds());
if(image!=null){
if(image.getBounds().height>this.getClientArea().height){
imageGc.drawImage(image,0,this.getClientArea().height-image.getBounds().height);
}else{
imageGc.drawImage(image,0,0);
}
}else{
if(text!=null){
imageGc.setFont(font);
imageGc.setForeground(new Color(this.getDisplay(),255,255,255));
imageGc.drawText(text,10,10);
}
}
gc.drawImage(bgImage,0,0);
bgImage.dispose();
imageGc.dispose();
gc.dispose();
}
}
|