edu.neu.ccs.gui
Class PaintableComponent

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byedu.neu.ccs.gui.JPTComponent
                  extended byedu.neu.ccs.gui.PaintableComponent
All Implemented Interfaces:
Icon, ImageObserver, JPTConstants, MenuContainer, Serializable, SupportsPropertyChange, SwingConstants

public class PaintableComponent
extends JPTComponent
implements Icon

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.

Since:
2.3.2
Version:
2.5.0
See Also:
Serialized Form

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 edu.neu.ccs.gui.JPTComponent
addBorder, addForwardingListener, addPropertyChangeListeners, addPropertyChangeListeners, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, emptyBorder, emptyBorder, emptyBorder, etchBorderLowered, etchBorderLowered, etchBorderLowered, etchBorderRaised, etchBorderRaised, etchBorderRaised, firePropertyChange, firePropertyChange, frame, frame, frame, frame, frame, frame, generalDialog, generalDialog, generalDialog, generalDialog, getForwardingListener, getKeyActionAdapter, getMouseActionAdapter, hasListeners, lineBorder, lineBorder, lineBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, removeAndAddForwardingListener, removeBorder, removeForwardingListener, setDeepBackground, setDeepBackground, titleBorder, YesNoCancelDialog, YesNoCancelDialog
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.neu.ccs.gui.SupportsPropertyChange
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 

Field Detail

SET_PAINTABLE

public static final String SET_PAINTABLE
Bound property name for set paintable.

See Also:
Constant Field Values

paintable

private Paintable paintable
The encapsulated paintable that defines this component.


bounds

private Rectangle2D bounds
The current default bounds of the component.


listener

private PaintableComponent.RefreshListener listener
The internal refresh listener.

Constructor Detail

PaintableComponent

public PaintableComponent(Paintable paintable)

This constructor provides the paintable needed to define the component.

Throws NullPointerException if the given paintable is null.

Parameters:
paintable - the paintable to encapsulate
See Also:
PaintableComponent(Paintable, Color), PaintableComponent(Paintable, Color, boolean), PaintableComponent(Paintable, Color, boolean, Border)

PaintableComponent

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.

Parameters:
paintable - the paintable to encapsulate
color - the optional background color
See Also:
PaintableComponent(Paintable), PaintableComponent(Paintable, Color, boolean), PaintableComponent(Paintable, Color, boolean, Border)

PaintableComponent

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.

Parameters:
paintable - the paintable to encapsulate
color - the optional background color
opaque - whether or not to paint the component background
See Also:
PaintableComponent(Paintable), PaintableComponent(Paintable, Color), PaintableComponent(Paintable, Color, boolean, Border)

PaintableComponent

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.

Parameters:
paintable - the paintable to encapsulate
color - the optional background color
opaque - whether or not to paint the component background
border - the border for the component
See Also:
PaintableComponent(Paintable), PaintableComponent(Paintable, Color), PaintableComponent(Paintable, Color, boolean)
Method Detail

setPaintable

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.

Parameters:
paintable - the paintable to encapsulate

getPaintable

public Paintable getPaintable()

Returns the encapsulated paintable.

Returns:
the encapsulated paintable

getDefaultBounds2D

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.

Returns:
the default bounds for the component

getDefaultLocation

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.

Returns:
the default location for the component

getPreferredSize

public Dimension getPreferredSize()

Returns the preferred size of the component based on the bounds of the encapsulated paintable and the component insets if any.

Returns:
the preferred size

getMinimumSize

public Dimension getMinimumSize()

Returns the same dimension as getPreferredSize.

Returns:
the minimum size

getMaximumSize

public Dimension getMaximumSize()

Returns the same dimension as getPreferredSize.

Returns:
the maximum size

getSize

public Dimension getSize()

Returns the same dimension as getPreferredSize.

Returns:
the size

getIconBounds2D

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.

Returns:
the icon bounds for the component

getIconWidth

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.

Specified by:
getIconWidth in interface Icon
Returns:
the icon width

getIconHeight

public 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.

Specified by:
getIconHeight in interface Icon
Returns:
the icon height

paintIcon

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.

Specified by:
paintIcon in interface Icon
Parameters:
c - the component on which the icon will be painted
g - the graphics context on which to paint
x - the x-location
y - the y-location

paintComponent

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.

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.

Parameters:
g - the graphics context of the component that will be copied prior to any paint operations

refresh

public 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.