你的分享就是我们的动力 ---﹥

SwingC开源

时间:2013-06-07 16:00来源:www.chengxuyuans.com 点击:

 

    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.chengxuyuans.com/code/android/64191.html