Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class DualIcon

java.lang.Object
  com.wordpress.tipsforjava.swing.DualIcon
All Implemented Interfaces:
Icon, SwingConstants

public class DualIcon
extends Object

A composite Icon class used to compose two Icon objects into a single Icon by painting the icons in turn at the precomputed offsets. For example, this class may be used to add a custom icon to a component like JCheckBox or JRadioButton, in addition to the default icon provided by the Look and Feel.

Authors:
Rob Camick
Darryl Burke
Version:
1.0 03/11/09


Field Summary
private int height

Icon icon1

private int icon1HOffset

private int icon1VOffset

Icon icon2

private int icon2HOffset

private int icon2VOffset

private int iconIconGap

private int width

 
Constructor Summary
DualIcon(Icon icon1, Icon icon2)

Creates a DualIcon with the specified icons, the default horizontal and vertical positioning and default gap.

DualIcon(Icon icon1, Icon icon2, int horizontalPosition, int verticalPosition, int iconIconGap)

Creates a DualIcon with the specified icons, the specified horizontal and vertical positioning and the specified gap.

 
Method Summary
private int checkHorizontalKey(int key, String exception)

private int checkVerticalKey(int key, String exception)

int getIconHeight()

Gets the height of the the bounding rectangle of this DualIcon.

int getIconWidth()

Gets the width of the bounding rectangle of this DualIcon.

void paintIcon(Component c, Graphics g, int x, int y)

Paints the icons of this compound icon at the specified location with the precomputed offsets.

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

Field Detail

height

private int height


icon1

Icon icon1


icon1HOffset

private int icon1HOffset


icon1VOffset

private int icon1VOffset


icon2

Icon icon2


icon2HOffset

private int icon2HOffset


icon2VOffset

private int icon2VOffset


iconIconGap

private int iconIconGap


width

private int width


 
Constructor Detail

DualIcon

public DualIcon(Icon icon1, Icon icon2)
Creates a DualIcon with the specified icons, the default horizontal and vertical positioning and default gap. icon2 is positioned to the right of icon1 with a 4 pixel gap, and the vertical centers of the icons are aligned.
Parameters:
icon1 - the first icon
icon2 - the second icon


DualIcon

public DualIcon(Icon icon1, Icon icon2, int horizontalPosition, int verticalPosition, int iconIconGap)
Creates a DualIcon with the specified icons, the specified horizontal and vertical positioning and the specified gap.
Parameters:
icon1 - the first icon
icon2 - the second icon
horizontalPosition - of the second icon relative to the first.
One of the following values:
  • SwingConstants.LEFT
  • SwingConstants.CENTER
  • SwingConstants.RIGHT

verticalPosition - of the second icon relative to the first.
One of the following values:
  • SwingConstants.TOP
  • SwingConstants.CENTER
  • SwingConstants.BOTTOM

iconIconGap - the gap between the icons in pizels, ignored if the horizontalPosition and verticalPosition are both SwingConstants.CENTER.


 
Method Detail

checkHorizontalKey

private int checkHorizontalKey(int key, String exception)


checkVerticalKey

private int checkVerticalKey(int key, String exception)


getIconHeight

@Override
public int getIconHeight()
Gets the height of the the bounding rectangle of this DualIcon.
Returns:
the height in pixels


getIconWidth

@Override
public int getIconWidth()
Gets the width of the bounding rectangle of this DualIcon.
Returns:
the width in pixels


paintIcon

@Override
public void paintIcon(Component c, Graphics g, int x, int y)
Paints the icons of this compound icon at the specified location with the precomputed offsets.
Parameters:
c - The component to which the icon is painted, which may be used to get properties useful for painting, e.g. the foreground or background color or selection status.
g - the graphics context
x - the X coordinate of the compound icon's top-left corner
y - the Y coordinate of the compound icon's top-left corner


 

Groovy Documentation