|
||||||||||
| 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.PaintableComponent
Class PaintableComponent encapsulates a
Paintable and uses that paintable to define the
PaintComponent method and to determine the size
of the component.
This class also implements the Icon interface.
As of 2.5.0, the built-in listener that listens for changes to the paintable or component will normally repaint() but will do a full refresh() if it detects that the bounds of the internal paintable have changed.
| Nested Class Summary | |
private class |
PaintableComponent.RefreshListener
The internal refresh listener class. |
| 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 |
bounds
The current default bounds of the component. |
private PaintableComponent.RefreshListener |
listener
The internal refresh listener. |
private Paintable |
paintable
The encapsulated paintable that defines this component. |
static String |
SET_PAINTABLE
Bound property name for set paintable. |
| 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 | |
PaintableComponent(Paintable paintable)
This constructor provides the paintable needed to define the component. |
|
PaintableComponent(Paintable paintable,
Color color)
This constructor provides the paintable needed to define the component, and the optional background color. |
|
PaintableComponent(Paintable paintable,
Color color,
boolean opaque)
This constructor provides the paintable needed to define the component, the optional background color, and the opacity setting. |
|
PaintableComponent(Paintable paintable,
Color color,
boolean opaque,
Border border)
This constructor provides the paintable needed to define the component, the optional background color, the opacity setting, and the component border. |
|
| Method Summary | |
Rectangle2D |
getDefaultBounds2D()
Returns the default bounds for the component using the information in the encapsulated paintable and the insets if any. |
Point2D |
getDefaultLocation()
Returns the default location for the component using the information in the encapsulated paintable and the insets if any. |
Rectangle2D |
getIconBounds2D()
Returns the bounds for the component viewed as an icon using the information in the encapsulated paintable. |
int |
getIconHeight()
Returns the icon height which is the height of the bounds region of the encapsulated paintable. |
int |
getIconWidth()
Returns the icon width which is the width of the bounds region of the encapsulated paintable. |
Dimension |
getMaximumSize()
Returns the same dimension as getPreferredSize. |
Dimension |
getMinimumSize()
Returns the same dimension as getPreferredSize. |
Paintable |
getPaintable()
Returns the encapsulated paintable. |
Dimension |
getPreferredSize()
Returns the preferred size of the component based on the bounds of the encapsulated paintable and the component insets if any. |
Dimension |
getSize()
Returns the same dimension as getPreferredSize. |
protected void |
paintComponent(Graphics g)
Overrides the inherited paintComponent method to
paint the background if the component is set to be opaque and
then to use the paintable to paint the component details. |
void |
paintIcon(Component c,
Graphics g,
int x,
int y)
Draw this object as an icon at the specified location using the paintable to paint the icon details. |
void |
refresh()
If the default bounds rectangle of this component has not changed then calls repaint();
otherwise sets the component location and size using the
default bounds rectangle and refreshes the component by
repacking the parent window. |
void |
setPaintable(Paintable paintable)
Sets the encapsulated paintable to the given paintable. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final String SET_PAINTABLE
private Paintable paintable
private Rectangle2D bounds
private PaintableComponent.RefreshListener listener
| Constructor Detail |
public PaintableComponent(Paintable paintable)
This constructor provides the paintable needed to define the component.
Throws NullPointerException if the given paintable
is null.
paintable - the paintable to encapsulatePaintableComponent(Paintable, Color),
PaintableComponent(Paintable, Color, boolean),
PaintableComponent(Paintable, Color, boolean, Border)
public PaintableComponent(Paintable paintable,
Color color)
This constructor provides the paintable needed to define the component, and the optional background color.
Throws NullPointerException if the given paintable
is null.
Ignores the given color if it is null.
The background will not be painted unless the opaque property is also set to true.
paintable - the paintable to encapsulatecolor - the optional background colorPaintableComponent(Paintable),
PaintableComponent(Paintable, Color, boolean),
PaintableComponent(Paintable, Color, boolean, Border)
public PaintableComponent(Paintable paintable,
Color color,
boolean opaque)
This constructor provides the paintable needed to define the component, the optional background color, and the opacity setting.
Throws NullPointerException if the given paintable
is null.
Ignores the given color if it is null.
If the given value of opaque is true, then the background color is painted on the component area before painting the paintable.
paintable - the paintable to encapsulatecolor - the optional background coloropaque - whether or not to paint the component backgroundPaintableComponent(Paintable),
PaintableComponent(Paintable, Color),
PaintableComponent(Paintable, Color, boolean, Border)
public PaintableComponent(Paintable paintable,
Color color,
boolean opaque,
Border border)
This constructor provides the paintable needed to define the component, the optional background color, the opacity setting, and the component border.
Throws NullPointerException if the given paintable
is null.
Ignores the given color if it is null.
If the given value of opaque is true, then the background color is painted on the component area before painting the paintable.
Ignores the given border if it is null.
paintable - the paintable to encapsulatecolor - the optional background coloropaque - whether or not to paint the component backgroundborder - the border for the componentPaintableComponent(Paintable),
PaintableComponent(Paintable, Color),
PaintableComponent(Paintable, Color, boolean)| Method Detail |
public void setPaintable(Paintable paintable)
Sets the encapsulated paintable to the given paintable.
Does nothing if the given paintable is null
or if it is the same object as the encapsulated paintable.
Fires property change: SET_PAINTABLE.
paintable - the paintable to encapsulatepublic Paintable getPaintable()
Returns the encapsulated paintable.
public Rectangle2D getDefaultBounds2D()
Returns the default bounds for the component using the information in the encapsulated paintable and the insets if any.
A LayoutManager may change the actual bounds of the component in a GUI to satisfy layout decisions.
public Point2D getDefaultLocation()
Returns the default location for the component using the information in the encapsulated paintable and the insets if any.
A LayoutManager may change the actual location of the component in a GUI to satisfy layout decisions.
public Dimension getPreferredSize()
Returns the preferred size of the component based on the bounds of the encapsulated paintable and the component 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 Rectangle2D getIconBounds2D()
Returns the bounds for the component viewed as an icon using the information in the encapsulated paintable.
These bounds ignore the insets of the object viewed as a component since the border is not painted in the icon.
public int getIconWidth()
Returns the icon width which is the width of the bounds region of the encapsulated paintable.
This width ignores the insets of the object viewed as a component since the border is not painted in the icon.
getIconWidth in interface Iconpublic int getIconHeight()
Returns the icon height which is the height of the bounds region of the encapsulated paintable.
This height ignores the insets of the object viewed as a component since the border is not painted in the icon.
getIconHeight in interface Icon
public void paintIcon(Component c,
Graphics g,
int x,
int y)
Draw this object as an icon at the specified location using the paintable to paint the icon details.
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 icon is painted.
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 background if the component is set to be opaque and
then to use the paintable to paint the component details.
Note: The javadocs for JComponent claim that the
the component background is painted if the opaque setting is true.
This is not always the case in practice. In this class, we take
care to see that the opaque setting is always respected.
g - the graphics context of the component that will be copied
prior to any paint operationspublic void refresh()
If the default bounds rectangle of this component has
not changed then calls repaint();
otherwise sets the component location and size using the
default bounds rectangle and refreshes the component by
repacking the parent window.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||