|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
edu.neu.ccs.gui.JPTComponent
edu.neu.ccs.gui.PaintSwatch
Class PaintSwatch is a light weight component to draw
a rectangular paint swatch with a given paint, size, and optional
border.
This class also implements the Icon interface.
For convenience, the class provides three static border objects so that a swatch border may be changed without changing the space needed in the GUI.
| Nested Class Summary |
| Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
private Rectangle2D |
area
The area to paint on within the border. |
static Border |
BLACK_BORDER
A standard black swatch border of standard thickness. |
static int |
BORDER_SIZE
The thickness of a standard swatch border. |
static int |
DEFAULT_SWATCH_SIZE
Default x and y swatch size. |
private Paint |
paint
The encapsulated paint. |
static String |
SET_BORDER
Bound property name for set border. |
static String |
SET_PAINT
Bound property name for set paint. |
static String |
SET_SIZE
Bound property name for set size. |
static Border |
TRANSPARENT_BORDER
A standard transparent swatch border of standard thickness. |
static Border |
WHITE_BORDER
A standard white swatch border of standard thickness. |
private int |
xSize
The x size. |
private int |
ySize
The y size. |
| Fields inherited from class edu.neu.ccs.gui.JPTComponent |
|
| Fields inherited from class javax.swing.JComponent |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Container |
|
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface edu.neu.ccs.util.JPTConstants |
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE |
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
PaintSwatch()
This constructor sets the swatch paint to Colors.transparent;
sets the dimensions of the swatch to (20, 20);
sets the border to BLACK_BORDER which has thickness 2. |
|
PaintSwatch(Paint paint)
This constructor provides the paint to paint in the swatch; sets the dimensions of the swatch to (20, 20); sets the border to BLACK_BORDER which has thickness 2. |
|
PaintSwatch(Paint paint,
Border border)
This constructor provides the paint to paint in the swatch and the border; sets the dimensions of the swatch to (20, 20). |
|
PaintSwatch(Paint paint,
int xSize,
int ySize)
This constructor provides the paint to paint in the swatch and the x and y dimensions of the swatch; sets the border to BLACK_BORDER which has thickness 2. |
|
PaintSwatch(Paint paint,
int xSize,
int ySize,
Border border)
This constructor provides the paint to paint in the swatch, the x and y dimensions of the swatch, and the border. |
|
| Method Summary | |
int |
getIconHeight()
Returns the icon height as getYSize(). |
int |
getIconWidth()
Returns the icon width as getXSize(). |
Dimension |
getMaximumSize()
Returns the same dimension as getPreferredSize. |
Dimension |
getMinimumSize()
Returns the same dimension as getPreferredSize. |
Paint |
getPaint()
Returns the paint of the swatch. |
Dimension |
getPreferredSize()
Returns the preferred size of the swatch based on the size of the area to be painted and the swatch insets if any. |
Dimension |
getSize()
Returns the same dimension as getPreferredSize. |
int |
getXSize()
Returns the current x-dimension of the swatch excluding the border insets. |
int |
getYSize()
Returns the current y-dimension of the swatch excluding the border insets. |
protected void |
paintComponent(Graphics g)
Overrides the inherited paintComponent method
to paint the swatch area with the encapsulated paint. |
void |
paintIcon(Component c,
Graphics g,
int x,
int y)
Draw the swatch as an icon at the specified location. |
void |
setBorder(Border border)
Calls the inherited setBorder method and
then fires the property change SET_BORDER. |
void |
setPaint(Paint paint)
Sets the paint of the swatch. |
void |
setSize(int xSize,
int ySize)
Sets the size of the swatch by giving its x-size and y-size. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final String SET_PAINT
public static final String SET_SIZE
public static final String SET_BORDER
public static final int DEFAULT_SWATCH_SIZE
public static final int BORDER_SIZE
public static final Border BLACK_BORDER
public static final Border WHITE_BORDER
public static final Border TRANSPARENT_BORDER
private Paint paint
private int xSize
private int ySize
private Rectangle2D area
setSize.
| Constructor Detail |
public PaintSwatch()
This constructor
sets the swatch paint to Colors.transparent;
sets the dimensions of the swatch to (20, 20);
sets the border to BLACK_BORDER which has thickness 2.
The caller should set the swatch paint to a more useful paint after construction.
The preferred size of this component will be (24, 24) to take into account both the swatch size and the border.
Other constructors:
- PaintSwatch(Paint)
- PaintSwatch(Paint, int, int)
- PaintSwatch(Paint, Border)
- PaintSwatch(Paint, int, int, Border)
public PaintSwatch(Paint paint)
This constructor provides the paint to paint in the swatch; sets the dimensions of the swatch to (20, 20); sets the border to BLACK_BORDER which has thickness 2.
If the given paint is null, sets the paint to
Colors.transparent.
The preferred size of this component will be (24, 24) to take into account both the swatch size and the border.
paint - the paint to paint in the swatchPaintSwatch()
public PaintSwatch(Paint paint,
int xSize,
int ySize)
This constructor provides the paint to paint in the swatch and the x and y dimensions of the swatch; sets the border to BLACK_BORDER which has thickness 2.
If the given paint is null, sets the paint to
Colors.transparent.
The preferred size of this component will be (xSize+4, ySize+4) to take into account both the swatch size and the border.
paint - the paint to paint in the swatchxSize - the x-dimension of the swatch (must be at least 1)ySize - the y-dimension of the swatch (must be at least 1)PaintSwatch(Paint)
public PaintSwatch(Paint paint,
Border border)
This constructor provides the paint to paint in the swatch and the border; sets the dimensions of the swatch to (20, 20).
If the given paint is null, sets the paint to
Colors.transparent.
Sets no border if the given border is null.
paint - the paint to paint in the swatchborder - the border for the swatchPaintSwatch(Paint)
public PaintSwatch(Paint paint,
int xSize,
int ySize,
Border border)
This constructor provides the paint to paint in the swatch, the x and y dimensions of the swatch, and the border.
If the given paint is null, sets the paint to
Colors.transparent.
Sets no border if the given border is null.
paint - the paint to paint in the swatchxSize - the x-dimension of the swatch (must be at least 1)ySize - the y-dimension of the swatch (must be at least 1)border - the border for the swatchPaintSwatch(Paint)| Method Detail |
public Dimension getPreferredSize()
Returns the preferred size of the swatch based on the size of the area to be painted and the swatch insets if any.
public Dimension getMinimumSize()
Returns the same dimension as getPreferredSize.
public Dimension getMaximumSize()
Returns the same dimension as getPreferredSize.
public Dimension getSize()
Returns the same dimension as getPreferredSize.
public void setPaint(Paint paint)
Sets the paint of the swatch.
If the given paint is null, sets the paint to
Colors.transparent.
Does nothing if the given paint is identical to the current paint.
Fires property change: SET_PAINT.
paint - the paint to setpublic Paint getPaint()
Returns the paint of the swatch.
public void setSize(int xSize,
int ySize)
Sets the size of the swatch by giving its x-size and y-size. If either number is less than 1, that number is set to 1. The size set by this method does not include the border insets.
Does nothing if both parameters equal the corresponding current settings.
Note that the method getPreferredSize will return
dimension data that includes the border insets.
Fires property change: SET_SIZE.
xSize - the x-dimension of the swatch (must be at least 1)ySize - the y-dimension of the swatch (must be at least 1)public int getXSize()
Returns the current x-dimension of the swatch excluding the border insets.
public int getYSize()
Returns the current y-dimension of the swatch excluding the border insets.
public void setBorder(Border border)
Calls the inherited setBorder method and
then fires the property change SET_BORDER.
Does nothing if the given border is null or
if the existing border is the same as the given border.
border - the border for the swatchpublic int getIconWidth()
Returns the icon width as getXSize().
getIconWidth in interface Iconpublic int getIconHeight()
Returns the icon height as getYSize().
getIconHeight in interface Icon
public void paintIcon(Component c,
Graphics g,
int x,
int y)
Draw the swatch as an icon at the specified location.
If the component parameter c is non-null,
if it is set to opaque, and if its background color is
non-null, then the background color will be
painted before the swatch is painted. This will be
useful only if the swatch paint is partially transparent.
Otherwise, the background color will be painted over.
Does nothing if the graphics context parameter g is
null.
paintIcon in interface Iconc - the component on which the icon will be paintedg - the graphics context on which to paintx - the x-locationy - the y-locationprotected void paintComponent(Graphics g)
Overrides the inherited paintComponent method
to paint the swatch area with the encapsulated paint.
If this component is set to opaque and if its background
color is non-null, then the background color
will be painted before the swatch is painted. This will be
useful only if the swatch paint is partially transparent.
Otherwise, the background will be painted over.
Does nothing if the graphics context parameter g is
null.
g - the graphics context of the swatch
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||