- protected void paintBackgroundImage(Graphics g, JComponent c, Image image, ImageDisplayMode mode, int titleHeight)
- {
- int width = c.getWidth();
- int height = c.getHeight() - titleHeight;
- int imageWidth = image.getWidth(null);
- int imageHeight = image.getHeight(null);
- g.translate(0, titleHeight);
- if(mode == ImageDisplayMode.SCALED)
- {
- g.drawImage(image, 0, 0, width, height, c);
- }
- else if(mode == ImageDisplayMode.TILED)
- {
- for(int x = 0; x < width; x += imageWidth)
- {
- for(int y = 0; y < height; y += imageHeight)
- {
- g.drawImage(image, x, y, c);
- }
- }
- }
- else
- {
- if(edgeBlurImage == null)
- {
- edgeBlurImage = UIUtil.createEdgeBlurryImage(image, BLUR_SIZE, BLUR_FILTER, c);
- }
- imageWidth = edgeBlurImage.getWidth();
- imageHeight = edgeBlurImage.getHeight();
- if(width > imageWidth || height > imageHeight)
- {
- rightEdge = UIUtil.cutImage(edgeBlurImage, new Rectangle(imageWidth - 1, 0, 1, imageHeight), c);
- bottomEdge = UIUtil.cutImage(edgeBlurImage, new Rectangle(0, imageHeight - 1, imageWidth, 1), c);
- width = Math.max(width, imageWidth);
- height = Math.max(height, imageHeight);
- BufferedImage tempBlurImage = UIUtil.getGraphicsConfiguration(c).createCompatibleImage(width, height, Transparency.TRANSLUCENT);
- Graphics2D tempG2d = tempBlurImage.createGraphics();
- tempG2d.drawImage(edgeBlurImage, 0, 0, c);
- //draw right edge
- if(width > imageWidth)
- {
- int x1 = imageWidth;
- int y2 = Math.min(height, imageHeight);
- for(int i = 0; i < width - imageWidth; i++)
- {
- tempG2d.drawImage(rightEdge, x1, 0, x1 + 1, y2, 0, 0, 1, Math.min(height, imageHeight), c);
- x1++;
- if(y2 < height)
- {
- y2++;
- }
- }
- }
- //draw bottom edge
- if(height > imageHeight)
- {
- int x2 = Math.min(width, imageWidth + 1);
- int y1 = imageHeight;
- for(int i = 0; i < height - imageHeight; i++)
- {
- tempG2d.drawImage(bottomEdge, 0, y1, x2, y1 + 1, 0, 0, Math.min(width, imageWidth), 1, c);
- y1++;
- if(x2 < width)
- {
- x2++;
- }
- }
- }
- tempG2d.dispose();
- edgeBlurImage = tempBlurImage;
- tempBlurImage = null;
- }
- g.drawImage(edgeBlurImage, 0, 0, c);
- }
- g.translate(0, -titleHeight);
- }
- //该片段来自于http://www.codesnippet.cn/detail/0810201410514.html
来源: http://www.codesnippet.cn/detail/0810201410514.html