org.peace_tools.generic
Class CustomBorder

java.lang.Object
  extended by javax.swing.border.AbstractBorder
      extended by org.peace_tools.generic.CustomBorder
All Implemented Interfaces:
java.io.Serializable, javax.swing.border.Border

public class CustomBorder
extends javax.swing.border.AbstractBorder

A custom border that draws 4 lines along the edges of a given component based on either color codes or four custom colors. Each side of the border can be independently controlled.

See Also:
Serialized Form

Field Summary
(package private)  java.lang.String colorCodes
          Create a custom border using 4 character codes for top, left, bottom, right.
(package private)  java.awt.Color[] colors
          An array of four colors corresponding to top, left, bottom, right borders
private static long serialVersionUID
          A generated serialization values.
 
Constructor Summary
CustomBorder(java.awt.Color top, java.awt.Color left, java.awt.Color bottom, java.awt.Color right)
          Create a custom border with a given set of colors.
CustomBorder(java.lang.String colorCodes)
          Create a custom border using 4 character codes for top, left, bottom, right.
 
Method Summary
 java.awt.Insets getBorderInsets(java.awt.Component c)
          Returns the insets of the border.
 java.awt.Insets getBorderInsets(java.awt.Component c, java.awt.Insets insets)
          Reinitialize the insets parameter with this Border's current Insets.
protected  java.awt.Color getColor(int i, java.awt.Component c)
          Helper method to get the color associated with a given side of the border.
 boolean isBorderOpaque()
          Returns whether or not the border is opaque.
 void paintBorder(java.awt.Component comp, java.awt.Graphics g, int x, int y, int width, int height)
          Paints the border for the specified component with the specified position and size.
 
Methods inherited from class javax.swing.border.AbstractBorder
getBaseline, getBaselineResizeBehavior, getInteriorRectangle, getInteriorRectangle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
A generated serialization values.

See Also:
Constant Field Values

colorCodes

java.lang.String colorCodes
Create a custom border using 4 character codes for top, left, bottom, right. The character codes are "d" for darker and "l" for lighter. Any other characters result in a null color and a border is not drawn.


colors

java.awt.Color[] colors
An array of four colors corresponding to top, left, bottom, right borders

Constructor Detail

CustomBorder

public CustomBorder(java.lang.String colorCodes)
Create a custom border using 4 character codes for top, left, bottom, right. The character codes are "d" for darker, 'D' for much-darker, "l" for lighter, 'L' for much-lighter, and "s" for same. Any other characters result in a null color and a border is not drawn.

Parameters:
colorCodes - A string with 4 characters (example: "ddll" indicating the border colors in the order top, left, bottom, right.

CustomBorder

public CustomBorder(java.awt.Color top,
                    java.awt.Color left,
                    java.awt.Color bottom,
                    java.awt.Color right)
Create a custom border with a given set of colors. If one of the colors is null, then a border is not drawn on that side and the border does not take up space on that side.

Parameters:
top - Color to be used for the top line.
left - Color to be used for the left line.
bottom - Color to be used for the bottom line.
right - Color to be used for the right line.
Method Detail

paintBorder

public void paintBorder(java.awt.Component comp,
                        java.awt.Graphics g,
                        int x,
                        int y,
                        int width,
                        int height)
Paints the border for the specified component with the specified position and size.

Specified by:
paintBorder in interface javax.swing.border.Border
Overrides:
paintBorder in class javax.swing.border.AbstractBorder
Parameters:
comp - the component for which this border is being painted
g - the paint graphics
x - the x position of the painted border
y - the y position of the painted border
width - the width of the painted border
height - the height of the painted border

getBorderInsets

public java.awt.Insets getBorderInsets(java.awt.Component c)
Returns the insets of the border.

Specified by:
getBorderInsets in interface javax.swing.border.Border
Overrides:
getBorderInsets in class javax.swing.border.AbstractBorder
Parameters:
c - the component for which this border insets value applies

getBorderInsets

public java.awt.Insets getBorderInsets(java.awt.Component c,
                                       java.awt.Insets insets)
Reinitialize the insets parameter with this Border's current Insets.

Overrides:
getBorderInsets in class javax.swing.border.AbstractBorder
Parameters:
c - the component for which this border insets value applies
insets - the object to be reinitialized

isBorderOpaque

public boolean isBorderOpaque()
Returns whether or not the border is opaque.

Specified by:
isBorderOpaque in interface javax.swing.border.Border
Overrides:
isBorderOpaque in class javax.swing.border.AbstractBorder
Returns:
This method always returns true to indicate that this border is opaque.

getColor

protected java.awt.Color getColor(int i,
                                  java.awt.Component c)
Helper method to get the color associated with a given side of the border. The numbers 0, 1, 2, and 3 are top, left, bottom, and right.

Parameters:
i - The index/direction of border.
c - The component from which colors are derived.
Returns:
A color code if a border is to be drawn. null otherwise.