Skip to main content

how to show progress bar in imageicon

No replies
ranjeet0101
Offline
Joined: 2008-10-01

I have on icon in snake shape i want to show progress bar in this shape.my progress bar is in rectingular shape. I need to show in snake shape.

My code

protected void paintComponent(Graphics g) {
Graphics2D g2=(Graphics2D)g.create();

float fx = 0;
float fy = 0;
float fw = getSize().width-1;
float fh = getSize().height-1;

GradientPaint p;
shape= loadImage();
//shape=g2.getClip();
g2.setClip(shape);

int x = 0;
int y = 0;
g2.drawImage(icon,x,y,this);
g2.setBackground(Color.lightGray);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.9f));
Paint oldPaint = g2.getPaint();
//p = new GradientPaint(x,y,new Color(0x1b70c7),(int)xFactorUpdate,(int)xFactorUpdate,new Color(0x69e2f3));
//p = new GradientPaint(x,y,new Color(0x1b70c7),(int)xFactorUpdate,(int)xFactorUpdate,new Color(0x69e2f3));
// g2.setPaint(p);
g2.fillRect(0,0,100,height);
// g2.fillRect(0,0,100,height/2);
g2.setPaint(oldPaint);
}
// INTEGRATION PATCH END HERE

//=====================================================================================
//////////////////////
private Shape shape=null;
private Image img=null;
private BufferedImage bimg=null;
private Shape loadImage()
{

img=ImageLoader.loadImage("images/Buttons/GlupodGUI/ProgressBar.png");
bimg = ImageLoader.convert(img);
shape=getShape(bimg,new Point(0,0),0);

// setPreferredSize(new Dimension(img.getHeight(),img.getWidth()));
return shape;
}

private Shape getShape(BufferedImage img,Point2D pos,int limit)
{
Raster data=img.getData();
System.out.println("data ::: "+data +"data.getHeight():: "+data.getHeight());
Area area=new Area();
int[] lookAt=null;
int alpha;
Point2D start=null;
Point2D end=null;
ArrayList lines=new ArrayList();
for (int y=0;y0)
{
lookAt=data.getPixel(x-1,y,lookAt);
alpha=lookAt[3];
if (start!=null&&alpha<=limit)
{
end=new Point2D.Double(x-1,y);
lines.add(new Line2D.Double(start,end));
// Reset
start=null;
end=null;
}
}
}
}
// The line bounds
Rectangle b;
// Go round all the lines
for (int i=0;i