Groovy Documentation

com.wordpress.tipsforjava.swing.border
[Java] Class ComponentBorder

java.lang.Object
  com.wordpress.tipsforjava.swing.border.ComponentBorder
All Implemented Interfaces:
Border

public class ComponentBorder
extends Object

The ComponentBorder class allows you to place a real component in the space reserved for painting the Border of a component. This class takes advantage of the knowledge that all Swing components are also Containers. By default the layout manager is null, so we should be able to place a child component anywhere in the parent component. In order to prevent the child component from painting over top of the parent component a Border is added to the parent componet such that the insets of the Border will reserve space for the child component to be painted without affecting the parent component.

Authors:
Rob Camick
Darryl Burke


Nested Class Summary
enum ComponentBorder.Edge

 
Field Summary
static float CENTER

static float LEADING

The ComponentBorder class allows you to place a real component in the space reserved for painting the Border of a component.

static float TRAILING

private boolean adjustInsets

private float alignment

private Insets borderInsets

private JComponent component

private ComponentBorder.Edge edge

private int gap

private JComponent parent

 
Constructor Summary
ComponentBorder(JComponent component)

Convenience constructor that uses the default edge (Edge.RIGHT) and alignment (CENTER).

ComponentBorder(JComponent component, ComponentBorder.Edge edge)

Convenience constructor that uses the default alignment (CENTER).

ComponentBorder(JComponent component, ComponentBorder.Edge edge, float alignment)

Main constructor to create a ComponentBorder.

 
Method Summary
private void adjustBorderInsets()

private void determineInsetsAndAlignment()

The insets need to be determined so they are included in the preferred size of the component the Border is attached to.

float getAlignment()

Get the component alignment along the Border Edge

Insets getBorderInsets(Component c)

ComponentBorder.Edge getEdge()

Get the Edge the component is positioned along

int getGap()

Get the gap between the border component and the parent component

void install(JComponent parent)

boolean isAdjustInsets()

boolean isBorderOpaque()

void paintBorder(Component c, Graphics g, int x, int y, int width, int height)

In this case a real component is to be painted.

void setAdjustInsets(boolean adjustInsets)

void setAlignment(float alignment)

Set the component alignment along the Border Edge

void setEdge(ComponentBorder.Edge edge)

Set the Edge the component is positioned along

void setGap(int gap)

Set the gap between the border component and the parent component

ComponentBorder valueOf(String name)

Returns the enum constant of this type with the specified name.

ComponentBorder[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

CENTER

public static final float CENTER


LEADING

public static final float LEADING
The ComponentBorder class allows you to place a real component in the space reserved for painting the Border of a component. This class takes advantage of the knowledge that all Swing components are also Containers. By default the layout manager is null, so we should be able to place a child component anywhere in the parent component. In order to prevent the child component from painting over top of the parent component a Border is added to the parent componet such that the insets of the Border will reserve space for the child component to be painted without affecting the parent component.
Authors:
Rob Camick
Darryl Burke


TRAILING

public static final float TRAILING


adjustInsets

private boolean adjustInsets


alignment

private float alignment


borderInsets

private Insets borderInsets


component

private JComponent component


edge

private ComponentBorder.Edge edge


gap

private int gap


parent

private JComponent parent


 
Constructor Detail

ComponentBorder

public ComponentBorder(JComponent component)
Convenience constructor that uses the default edge (Edge.RIGHT) and alignment (CENTER).
Parameters:
component - the component to be added in the Border area


ComponentBorder

public ComponentBorder(JComponent component, ComponentBorder.Edge edge)
Convenience constructor that uses the default alignment (CENTER).
Parameters:
component - the component to be added in the Border area
edge - a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT


ComponentBorder

public ComponentBorder(JComponent component, ComponentBorder.Edge edge, float alignment)
Main constructor to create a ComponentBorder.
Parameters:
component - the component to be added in the Border area
edge - a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT
alignment - the alignment of the component along the specified Edge. Must be in the range 0 - 1.0.


 
Method Detail

adjustBorderInsets

private void adjustBorderInsets()


determineInsetsAndAlignment

private void determineInsetsAndAlignment()
The insets need to be determined so they are included in the preferred size of the component the Border is attached to. The alignment of the component is determined here so it doesn't need to be recalculated every time the Border is painted.


getAlignment

public float getAlignment()
Get the component alignment along the Border Edge
Returns:
the alignment


getBorderInsets

public Insets getBorderInsets(Component c)


getEdge

public ComponentBorder.Edge getEdge()
Get the Edge the component is positioned along
Returns:
the Edge


getGap

public int getGap()
Get the gap between the border component and the parent component
Returns:
the gap in pixels.


install

public void install(JComponent parent)


isAdjustInsets

public boolean isAdjustInsets()


isBorderOpaque

public boolean isBorderOpaque()


paintBorder

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
In this case a real component is to be painted. Setting the location of the component will cause it to be painted at that location.


setAdjustInsets

public void setAdjustInsets(boolean adjustInsets)


setAlignment

public void setAlignment(float alignment)
Set the component alignment along the Border Edge
Parameters:
alignment - a value in the range 0 - 1.0. Standard values would be CENTER (default), LEFT and RIGHT.


setEdge

public void setEdge(ComponentBorder.Edge edge)
Set the Edge the component is positioned along
Parameters:
edge - the Edge the component is position on.


setGap

public void setGap(int gap)
Set the gap between the border component and the parent component
Parameters:
gap - the gap in pixels (default is 5)


valueOf

ComponentBorder valueOf(String name)
Returns the enum constant of this type with the specified name.


values

ComponentBorder[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


 

Groovy Documentation