edu.neu.ccs.gui
Class PaintableButton

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.AbstractButton
                          |
                          +--javax.swing.JButton
                                |
                                +--edu.neu.ccs.gui.PaintableButton
All Implemented Interfaces:
Accessible, ImageObserver, ItemSelectable, MenuContainer, Serializable, SwingConstants

public class PaintableButton
extends JButton

Class PaintableButton encapsulates a Paintable and uses that paintable to define the icon for the button and to determine the size of the button.

Since:
2.3.2
See Also:
Serialized Form

Field Summary
static String SET_PAINTABLE
          Bound property name for set paintable.
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
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.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
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
PaintableButton(Paintable paintable)
          This constructor provides the paintable needed to define the button.
PaintableButton(Paintable paintable, Action action)
          This constructor provides the paintable needed to define the button, and the action for the button behavior.
PaintableButton(Paintable paintable, Action action, Color color)
          This constructor provides the paintable needed to define the button, the action for the button behavior and the optional background color.
PaintableButton(Paintable paintable, Action action, Color color, Insets insets)
          This constructor provides the paintable needed to define the button, the action for the button behavior the optional background color, and the button insets (margin).
 
Method Summary
 Rectangle2D getDefaultBounds2D()
          Returns the default bounds for the button using the information in the encapsulated paintable and the insets.
 Point getDefaultLocation()
          Returns the default location for the button using the information in the encapsulated paintable and the insets.
 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 button based on the bounds of the encapsulated paintable and the button insets.
 Dimension getSize()
          Returns the same dimension as getPreferredSize.
 void refresh()
          Sets the component location and size using the information in the given paintable and then refreshes the component by repacking the parent window.
 void refreshComponent()
          Refreshes the component by repacking the parent window.
 void setAction(Action a)
          Overrides the inherited method to make sure that the icon for the button is the one associated with the paintable and the text for the button is null.
 void setPaintable(Paintable paintable)
          Sets the encapsulated paintable to the given paintable and refreshes the screen provided the button is installed in a GUI.
 
Methods inherited from class javax.swing.JButton
configurePropertiesFromAction, getAccessibleContext, getUIClassID, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapable, updateUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
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, firePropertyChange, fireVetoableChange, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
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, 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
 

Field Detail

SET_PAINTABLE

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

See Also:
Constant Field Values
Constructor Detail

PaintableButton

public PaintableButton(Paintable paintable)

This constructor provides the paintable needed to define the button.

Throws NullPointerException if the given paintable is null.

The button behavior must be supplied later.

This button uses the default JButton background color.

This button uses default insets of 2, 2, 2, 2 which are not the Java default but which work better with most paintable objects.

Parameters:
paintable - the paintable to encapsulate
See Also:
PaintableButton(Paintable, Action), PaintableButton(Paintable, Action, Color), PaintableButton(Paintable, Action, Color, Insets)

PaintableButton

public PaintableButton(Paintable paintable,
                       Action action)

This constructor provides the paintable needed to define the button, and the action for the button behavior.

Throws NullPointerException if the given paintable is null.

Determines the button icon from the paintable and ignores any NAME or SMALL_ICON properties that may be set for the action.

Ignores the given action if it is null.

This button uses the default JButton background color.

This button uses default insets of 2, 2, 2, 2 which are not the Java default but which work better with most paintable objects.

Parameters:
paintable - the paintable to encapsulate
action - the action for the button behavior
See Also:
PaintableButton(Paintable), PaintableButton(Paintable, Action, Color), PaintableButton(Paintable, Action, Color, Insets)

PaintableButton

public PaintableButton(Paintable paintable,
                       Action action,
                       Color color)

This constructor provides the paintable needed to define the button, the action for the button behavior and the optional background color.

Throws NullPointerException if the given paintable is null.

Determines the button icon from the paintable and ignores any NAME or SMALL_ICON properties that may be set for the action.

Ignores the given action if it is null.

Ignores the given color if it is null.

This button uses default insets of 2, 2, 2, 2 which are not the Java default but which work better with most paintable objects.

Parameters:
paintable - the paintable to encapsulate
action - the action for the button behavior
color - the optional background color
See Also:
PaintableButton(Paintable), PaintableButton(Paintable, Action), PaintableButton(Paintable, Action, Color, Insets)

PaintableButton

public PaintableButton(Paintable paintable,
                       Action action,
                       Color color,
                       Insets insets)

This constructor provides the paintable needed to define the button, the action for the button behavior the optional background color, and the button insets (margin).

Throws NullPointerException if the given paintable is null.

Determines the button icon from the paintable and ignores any NAME or SMALL_ICON properties that may be set for the action.

Ignores the given action if it is null.

Ignores the given color if it is null.

If the given insets is null, it is set to 2, 2, 2, 2.

Parameters:
paintable - the paintable to encapsulate
action - the action for the button behavior
color - the optional background color
insets - the button insets or margin
See Also:
PaintableButton(Paintable), PaintableButton(Paintable, Action), PaintableButton(Paintable, Action, Color)
Method Detail

setPaintable

public void setPaintable(Paintable paintable)

Sets the encapsulated paintable to the given paintable and refreshes the screen provided the button is installed in a GUI.

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

setAction

public void setAction(Action a)

Overrides the inherited method to make sure that the icon for the button is the one associated with the paintable and the text for the button is null.

Overrides:
setAction in class AbstractButton

getDefaultBounds2D

public Rectangle2D getDefaultBounds2D()

Returns the default bounds for the button using the information in the encapsulated paintable and the insets.

A LayoutManager may change the actual bounds of the button in a GUI to satisfy layout decisions.

Returns:
the default bounds for the button

getDefaultLocation

public Point getDefaultLocation()

Returns the default location for the button using the information in the encapsulated paintable and the insets.

A LayoutManager may change the actual location of the button in a GUI to satisfy layout decisions.

Returns:
the default location for the button

getPreferredSize

public Dimension getPreferredSize()

Returns the preferred size of the button based on the bounds of the encapsulated paintable and the button insets.

Overrides:
getPreferredSize in class JComponent
Returns:
the preferred size

getMinimumSize

public Dimension getMinimumSize()

Returns the same dimension as getPreferredSize.

Overrides:
getMinimumSize in class JComponent
Returns:
the minimum size

getMaximumSize

public Dimension getMaximumSize()

Returns the same dimension as getPreferredSize.

Overrides:
getMaximumSize in class JComponent
Returns:
the maximum size

getSize

public Dimension getSize()

Returns the same dimension as getPreferredSize.

Overrides:
getSize in class Component
Returns:
the size

refresh

public void refresh()

Sets the component location and size using the information in the given paintable and then refreshes the component by repacking the parent window.


refreshComponent

public void refreshComponent()
Refreshes the component by repacking the parent window.