4
* Created on January 15, 2007, 6:54 AM
6
* Copyright 2006-2007 Nigel Hughes
8
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9
* in compliance with the License. You may obtain a copy of the License at http://www.apache.org/
10
* licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
13
* governing permissions and limitations under the License.
16
package org.pushingpixels.lafwidget.contrib.blogofbug.swing.borders;
19
import java.awt.image.BufferedImage;
22
import javax.swing.border.AbstractBorder;
25
* ImageBorder takes an image and breaks out the corners and the top, left, right, and bottom
26
* borders stretching them to fill the space around which the border is drawn
29
public class ImageBorder extends AbstractBorder{
30
protected AbstractImageBorder borderRenderer;
31
boolean paintBorder = true;
34
* Creates a new ImageBorder using the supplied image and the insets
36
* @param borderImage The image to be used as the border
37
* @param imageInsets The insets around the edge of the image that allow the cookie-cut-and-stretch of the image
38
* around the edge of the border
40
public ImageBorder(BufferedImage borderImage, Insets imageInsets) {
41
borderRenderer= new AbstractImageBorder(borderImage, imageInsets);
46
* Creates a new ImageBofder loading the image from the supplied URL
47
* @param imageURL The location of the image to use
48
* @param imageInsets The insets around the edge of the image that allow the cookie-cut-and-stretch of the image
49
* around the edge of the border
51
public ImageBorder(URL imageURL, Insets imageInsets){
52
borderRenderer = new AbstractImageBorder(imageURL,imageInsets);
56
* Paints the border around the specified component
58
* @param c The component to paint the border on
59
* @param g The graphics context
60
* @param x The x offset
61
* @param y The y offset
62
* @param width The width
63
* @param height The height
66
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
70
borderRenderer.paintBorder(c.getWidth(),c.getHeight(),g,x,y,width,height);
74
* Controls wether or not the border is actually painted or not.
76
* @param paintBorder If false then will not draw the border. Useful if the border is being used to show a selected item
78
public void setPaintBorder(boolean paintBorder){
79
this.paintBorder = paintBorder;
83
* Gets the insets of the image back (subtracting from the component size would give you the renderable
86
* @param c The component to which the border will be applied
87
* @return The insets of the border
90
public Insets getBorderInsets(Component c) {
91
return borderRenderer.getImageInsets();
95
* Gets the insets of the image and returns in the in the supplied Insets instance
97
* @param c The component to which the border will be applied
98
* @param i A pre-created insets object
99
* @return The insets of the border
102
public Insets getBorderInsets(Component c, Insets i){
103
Insets imageInsets = borderRenderer.getImageInsets();
104
i.top = imageInsets.top;
105
i.bottom = imageInsets.bottom;
106
i.left = imageInsets.left;
107
i.right = imageInsets.right;
111
public void paintCenter(Graphics2D g2, Component c) {
113
borderRenderer.paintCenter(g2,c.getWidth(),c.getHeight());