1 package org.wcb.gui.component; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.awt.image.BufferedImage; 6 7 import org.wcb.gui.util.UIHelper; 8 9 /** 10 * <small> 11 * <p/> 12 * Copyright (c) 2006 wbogaardt. 13 * This library is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU Lesser General Public 15 * License as published by the Free Software Foundation; either 16 * version 2.1 of the License, or (at your option) any later version. 17 * 18 * This library is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 * Lesser General Public License for more details. 22 * 23 * You should have received a copy of the GNU Lesser General Public 24 * License along with this library; if not, write to the Free Software 25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 26 * <p/> 27 * $File: $ <br> 28 * $Change: $ submitted by $Author: wbogaardt $ at $DateTime: Sep 14, 2006 4:03:29 PM $ <br> 29 * </small> 30 * 31 * @author wbogaardt 32 * Allows painting a background image as tiled. 33 */ 34 35 public class CoolTitlePanel extends JPanel { 36 37 BufferedImage mImage; 38 BufferedImage mTop; 39 BufferedImage mBottom; 40 BufferedImage mRight; 41 BufferedImage mTopRight; 42 43 public CoolTitlePanel() { 44 mBottom = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/bottom.jpg"); 45 mTop = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/top.jpg"); 46 mRight = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/rightside.jpg"); 47 mTopRight = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/book/top-right-corner.jpg"); 48 mImage = (BufferedImage) UIHelper.loadImage("org/wcb/resources/gui/tile.gif"); 49 setSize(800, 100); 50 } 51 52 53 public void paintComponent(Graphics g) { 54 int width = getWidth(); 55 int height = getHeight(); 56 int topBottomWidth = mTop.getWidth(this); 57 int topBottomHeight = mBottom.getHeight(this); 58 int sideWidth = mRight.getWidth(this); 59 int sideHeight = mRight.getHeight(this); 60 for (int y = 0; y < height; y += sideHeight) { 61 g.drawImage(mRight, width - sideWidth, y, this); 62 } 63 64 for (int i = 0; i < width; i += topBottomWidth) { 65 g.drawImage(mTop, i, 0, this); 66 g.drawImage(mBottom, i, height - topBottomHeight, this); 67 } 68 69 /*for (int x = 0; x < width; x += imageW) { 70 for (int y = 0; y < height; y += imageH) { 71 g.drawImage(mImage, x, y, this); 72 } 73 } */ 74 } 75 76 /*public void paint(Graphics g) { 77 int width = getWidth(); 78 int height = getHeight(); 79 int imageW = mImage.getWidth(this); 80 int imageH = mImage.getHeight(this); 81 int topBottomWidth = mTop.getWidth(this); 82 int topBottomHeight = mBottom.getHeight(this); 83 for (int i = 0; i < width; i +=topBottomWidth) { 84 g.drawImage(mTop,i,0, null); 85 g.drawImage(mBottom, i, height - topBottomHeight, null); 86 } 87 } */ 88 /* 89 public void paint(Graphics g) { 90 Graphics2D g2 = (Graphics2D)g; 91 // Create a round rectangle. 92 RoundRectangle2D r = 93 new RoundRectangle2D.Float(25, 35, 150, 150, 25, 25); 94 // Create a texture rectangle the same size as the texture image. 95 Rectangle2D tr = new Rectangle2D.Double(0, 0, 96 mImage.getWidth(), mImage.getHeight()); 97 // Create the TexturePaint. 98 TexturePaint tp = new TexturePaint(mImage, tr); 99 // Now fill the round rectangle. 100 g2.setPaint(tp); 101 g2.fill(r); 102 }*/ 103 }