Pages

about my opensource eclipse java applications recently i'm studying GWT and Android

Saturday, August 06, 2005

like transparent figure on Draw2D


In this here,I'd like to explain how to create like transparent figure.
but this way is only create 1x1 sized image which has alpha and draw fill bounds of figure.
So If you add figures insert this figure,it would never be transparent.

Although,If you add one more this way figure as shadow,It would be neat.

I use this tips in my Eclipse RCP Application;akJ Subplayer

-Example
In this example,add two AlphaLayerFigures.
---add first AlphaLayerFigure
On Constracter It send color and alpha(0-255) arugments.

AlphaLayerFigure figure1=new AlphaLayerFigure(ColorConstants.red,128);
figure1.setBounds(new Rectangle(0,0,100,100));
figure1.add(new Label("layer1"));
panel.add(figure1);
---add second AlphaLayerFigure
This code use FlowLayout to layout label to align left.

AlphaLayerFigure figure2=new AlphaLayerFigure(ColorConstants.orange,128);
figure2.setBounds(new Rectangle(5,5,100,100));
FlowLayout layout=new FlowLayout();
layout.setMajorAlignment(FlowLayout.ALIGN_RIGHTBOTTOM);
figure2.setLayoutManager(layout);
figure2.add(new Label("layer2"));
panel.add(figure2);
---AlphaLayerFigure
----Constracter
In Constracter,Palette was Created by a color argument.
And a image sized 1x1 was created by that Palette with alpha value.

public AlphaLayerFigure(Color color,int alpha){
super();
this.color=color;

PaletteData palette=new PaletteData(new RGB[]{color.getRGB()});
imageData = new ImageData(1,1,8,palette);
imageData.alpha=alpha;
imageData.setPixel(0,0,0);
layerImage = new Image(null,imageData);


}
---On Color Changed;setColor()
When color was changed,Image would be create again and paint.

this.color=color;
imageData.palette.colors[0]=color.getRGB();
if(layerImage!=null && !layerImage.isDisposed()){
layerImage.dispose();
}
layerImage=new Image(null,imageData);
repaint();
---On Alpah Changed;setAlpha()
Do same as color changed.

public void setAlpha(int alpha){

imageData.alpha=alpha;
if(layerImage!=null && !layerImage.isDisposed()){
layerImage.dispose();
}
layerImage=new Image(null,imageData);
repaint();
}

FullCode
http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/akjrcp/draw2dexample/src/example/draw2d/AlphaTest.java?rev=1.1&content-type=text/vnd.viewcvs-markup

1 comment:

Anonymous said...

Great site

http://arthritis-relief.lysog.info arthritis relief
http://leather-chair.lysog.info leather chair
http://lucchese-boot.malig.info lucchese boot
http://toshiba-part.malig.info toshiba part
http://home-treadmill.malig.info home treadmill
http://turbo-tax.malig.info turbo tax
http://born-shoe.asapdeals.com born shoe
http://stretch-film.bucksathome.com stretch film
http://tv-stand.asapdeals.com tv stand
http://jet-pump.casinogamefactory.com jet pump
http://nfl-jerseys.1timesex.com nfl jerseys
http://party-poker-online.boulevardprivates.com party poker online
http://charlotte-job.asapdeals.com charlotte job
http://porch-swing.eurocarexpert.com porch swing
http://kohler-plumbing.1timesex.com kohler plumbing

Thanks.