/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Liquid Look and Feel *
* *
* Author, Miroslav Lazarevic *
* *
* For licensing information and credits, please refer to the *
* comment in file com.birosoft.liquid.LiquidLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package com.birosoft.liquid.borders;
import com.birosoft.liquid.skin.Skin;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.border.AbstractBorder;
import javax.swing.plaf.UIResource;
/**
* The border for a Textfield.
*/
public class LiquidTextFieldBorder extends AbstractBorder implements UIResource {
/**
*
*/
private static final long serialVersionUID = -1128841407808527L;
private static final Insets defaultInsets = new Insets(3, 5, 3, 5);
static Skin skin;
private Insets insets;
public LiquidTextFieldBorder() {
insets = defaultInsets;
}
public LiquidTextFieldBorder(Insets insets) {
this.insets = insets;
}
/**
* Gets the border insets for a given component.
*
* @param c The component to get its border insets.
* @return Always returns the same insets as defined in <code>insets</code>.
*/
public Insets getBorderInsets(Component c) {
return insets;
}
public void setInsets(Insets i) {
insets = i;
}
/**
* lazy initialization of the skin
*/
public Skin getSkin() {
if (skin == null) {
skin = new Skin("textbox.png", 2, 3);
}
return skin;
}
/**
* Use the skin to paint the border
* @see javax.swing.border.Border#paintBorder(Component, Graphics, int, int, int, int)
*/
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
int index = c.isEnabled() ? 0 : 1;
getSkin().draw(g, index, w, h);
}
}