public void mouseDragged(MouseEvent arg0) {
int x = arg0.getX();
int y = arg0.getY();
MapBean mb = ((MapBean) arg0.getSource());
if (!isPanning) {
int w = mb.getWidth();
int h = mb.getHeight();
/*
* Making the image
*/
if (bufferedMapImage == null || bufferedRenderingImage == null) {
createBuffers(w, h);
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Graphics2D g = (Graphics2D) ge.createGraphics(bufferedMapImage);
g.setClip(0, 0, w, h);
Border border = mb.getBorder();
mb.setBorder(null);
mb.paintAll(g);
mb.setBorder(border);
oX = x;
oY = y;
isPanning = true;
} else {
if (bufferedMapImage != null && bufferedRenderingImage != null) {
Graphics2D gr2d = (Graphics2D) bufferedRenderingImage.getGraphics();
/*
* Drawing original image whithout transparence and in the
* initial position
*/
if (leaveShadow) {
gr2d.drawImage(bufferedMapImage, 0, 0, null);
} else {
gr2d.setPaint(mb.getBckgrnd());
gr2d.fillRect(0, 0, mb.getWidth(), mb.getHeight());
}
/*
* Drawing image whith transparence and in the mouse position
* minus origianl mouse click position
*/
gr2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opaqueness));
gr2d.drawImage(bufferedMapImage, x - oX, y - oY, null);
((Graphics2D) mb.getGraphics()).drawImage(bufferedRenderingImage, 0, 0, null);
}
}
super.mouseDragged(arg0);
}