edu.neu.ccs.gui
Class Annotation

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byedu.neu.ccs.gui.DisplayPanel
                      extended byedu.neu.ccs.gui.Annotation
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants

public class Annotation
extends DisplayPanel

A Displayable component representing an annotation in a GUI, such as the prompt for an input object or the caption for an image.

The functionality of this class is based on the functionality of the JLabel class provided in the javax.swing package, with the following additional functionality:

As of 2.5.0, added constructors that permit the font to be specified.

Version:
2.5.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
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
protected  Icon alertIcon
          Icon to be displayed when this annotation is in alert status.
protected  int align
          Alignment of the icon relative to the text.
static int DEFAULT_ALIGNMENT
          Default alignment of the icon relative to the text for an annotation (icon is ABOVE the text).
protected  JLabel iconLabel
          JLabel used to render the icon.
protected  Color oldBackground
          Background color of this annotation before alert status was entered.
protected  Color oldForeground
          Text foreground color of this annotation before alert status was entered.
static String SET_ALERT_ICON
          Bound property name for the set alert icon property.
static String SET_BACKGROUND
          Bound property name for the set background property.
static String SET_DISABLED_ICON
          Bound property name for the set disabled icon property.
static String SET_FONT
          Bound property name for the set font property.
static String SET_FOREGROUND
          Bound property name for the set foreground property.
static String SET_ICON
          Bound property name for the set icon property.
static String SET_OPAQUE
          Bound property name for the set opaque property.
static String SET_TEXT
          Bound property name for the set text property.
protected  JTextArea textLabel
          JTextArea used to render the text.
 
Fields inherited from class edu.neu.ccs.gui.DisplayPanel
background, codec, CODEC
 
Fields inherited from class javax.swing.JPanel
 
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.gui.Displayable
DEFAULT_VIEW_STATE, VIEW_STATE
 
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
Annotation()
          Constructs an annotation with no icon or text.
Annotation(Icon icon)
          Constructs an annotation displaying the given icon.
Annotation(String text)
          Constructs an annotation displaying the given text.
Annotation(String text, Font font)
          Constructs an annotation displaying the given text using the given font.
Annotation(String text, Icon icon, int alignment)
          Constructor for an annotation displaying the given text and icon.
Annotation(String text, Icon icon, int alignment, Font font)
          Constructor for an annotation displaying the given text and icon using the given font.
 
Method Summary
 void dataMalformed(MalformedDataEvent evt)
          Handles a malformed data event generated by a fragile input component by alerting the user through changes to the background and foreground colors of the annotation.
 void endAlert(AlertEvent evt)
          Turns off alert status for this component.
 Icon getAlertIcon()
          Returns the icon to be displayed when this annotation is put in an alert state, or null if it has not been set.
 int getAlignment()
          Returns the alignment of the icon relative to the text.
static Font getDefaultFont()
          Returns the default font for a JLabel.
 Icon getDisabledIcon()
          Returns the icon to be displayed when this annotation is disabled, if it has been set through use of the setDisabledIcon method, or null if it has not been set.
 Icon getIcon()
          Returns the icon displayed by this annotation, or null if it has not been set.
 String getText()
          Returns the text displayed by this annotation.
static Annotation makeAnnotation(String text, Object object, int alignment)
          Returns an Annotation using the given string, object, and alignment; the object is converted to an Icon using ComponentFactory.makeIcon.
static Annotation makeAnnotation(String text, Object object, int alignment, Font font)
          Returns an Annotation using the given string, object, alignment, and font; the object is converted to an Icon using ComponentFactory.makeIcon.
 void setAlertIcon(Icon icon)
          Sets the icon to be displayed when this annotation is in an alert state.
 void setAlignment(int alignment)
          Sets the alignment of the icon relative to the text using one of the constants ABOVE, BELOW, LEFT, RIGHT, or DEFAULT.
 void setBackground(Color background)
          Sets the background color for the annotation to the given color.
 void setDisabledIcon(Icon icon)
          Sets the icon to be displayed when this annotation is disabled.
 void setFont(Font font)
          Sets the font used to render the text to the given font.
 void setForeground(Color foreground)
          Sets the foreground color for the annotation to the given color.
 void setIcon(Icon icon)
          Sets the icon displayed by this annotation to the given icon.
 void setOpaque(boolean opaque)
          Sets the opaque state for the annotation.
 void setText(String text)
          Sets the text displayed by this annotation to the given text.
 void startAlert(AlertEvent evt)
          Turns on alert status for this component.
 
Methods inherited from class edu.neu.ccs.gui.DisplayPanel
add, add, add, add, add, addBorder, addObject, addObject, addObject, addObject, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, compoundBorder, compoundBorder, emptyBorder, emptyBorder, emptyBorder, etchBorderLowered, etchBorderLowered, etchBorderLowered, etchBorderRaised, etchBorderRaised, etchBorderRaised, frame, frame, frame, frame, frame, frame, generalDialog, generalDialog, generalDialog, generalDialog, getCodec, getDefaultViewState, getDefaultViewStates, getDisplayables, getViewState, getViewStates, lineBorder, lineBorder, lineBorder, lineBorder, makeComponent, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, remove, remove, removeAll, removeBorder, reset, sandwichBorder, setCodec, setDeepBackground, setDeepBackground, setDefaultViewState, setDefaultViewStates, setEnabled, setViewState, setViewStates, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, uniformizeHeight, uniformizeSize, uniformizeWidth, YesNoCancelDialog, YesNoCancelDialog
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, 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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
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, 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, getSize, 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
 

Field Detail

SET_TEXT

public static final String SET_TEXT
Bound property name for the set text property.

See Also:
Constant Field Values

SET_ICON

public static final String SET_ICON
Bound property name for the set icon property.

See Also:
Constant Field Values

SET_DISABLED_ICON

public static final String SET_DISABLED_ICON
Bound property name for the set disabled icon property.

See Also:
Constant Field Values

SET_ALERT_ICON

public static final String SET_ALERT_ICON
Bound property name for the set alert icon property.

See Also:
Constant Field Values

SET_FONT

public static final String SET_FONT
Bound property name for the set font property.

See Also:
Constant Field Values

SET_FOREGROUND

public static final String SET_FOREGROUND
Bound property name for the set foreground property.

See Also:
Constant Field Values

SET_BACKGROUND

public static final String SET_BACKGROUND
Bound property name for the set background property.

See Also:
Constant Field Values

SET_OPAQUE

public static final String SET_OPAQUE
Bound property name for the set opaque property.

See Also:
Constant Field Values

DEFAULT_ALIGNMENT

public static final int DEFAULT_ALIGNMENT
Default alignment of the icon relative to the text for an annotation (icon is ABOVE the text).

See Also:
Constant Field Values

oldForeground

protected Color oldForeground
Text foreground color of this annotation before alert status was entered.


oldBackground

protected Color oldBackground
Background color of this annotation before alert status was entered.


iconLabel

protected JLabel iconLabel
JLabel used to render the icon.


textLabel

protected JTextArea textLabel
JTextArea used to render the text.


align

protected int align
Alignment of the icon relative to the text.


alertIcon

protected Icon alertIcon
Icon to be displayed when this annotation is in alert status. If the alert icon is null, when this annotation is in alert status, the currently displayed icon is not changed.

Constructor Detail

Annotation

public Annotation()
Constructs an annotation with no icon or text.


Annotation

public Annotation(String text)
Constructs an annotation displaying the given text.

Parameters:
text - the text to be displayed

Annotation

public Annotation(String text,
                  Font font)
Constructs an annotation displaying the given text using the given font.

Parameters:
text - the text to be displayed
font - the font to use throughout the annotation

Annotation

public Annotation(Icon icon)
Constructs an annotation displaying the given icon.

Parameters:
icon - the icon to be displayed

Annotation

public Annotation(String text,
                  Icon icon,
                  int alignment)
Constructor for an annotation displaying the given text and icon.

Parameters:
text - the text to be displayed
icon - the icon to be displayed
alignment - the alignment of the icon relative to text

Annotation

public Annotation(String text,
                  Icon icon,
                  int alignment,
                  Font font)
Constructor for an annotation displaying the given text and icon using the given font.

Parameters:
text - the text to be displayed
icon - the icon to be displayed
alignment - the alignment of the icon relative to text
font - the font to use throughout the annotation
Method Detail

makeAnnotation

public static Annotation makeAnnotation(String text,
                                        Object object,
                                        int alignment)

Returns an Annotation using the given string, object, and alignment; the object is converted to an Icon using ComponentFactory.makeIcon.

Parameters:
text - the text to be displayed
object - the object to convert into an icon
alignment - the alignment of the icon relative to text

makeAnnotation

public static Annotation makeAnnotation(String text,
                                        Object object,
                                        int alignment,
                                        Font font)

Returns an Annotation using the given string, object, alignment, and font; the object is converted to an Icon using ComponentFactory.makeIcon.

Parameters:
text - the text to be displayed
object - the object to convert into an icon
alignment - the alignment of the icon relative to text
font - the font to use throughout the annotation

dataMalformed

public void dataMalformed(MalformedDataEvent evt)
Handles a malformed data event generated by a fragile input component by alerting the user through changes to the background and foreground colors of the annotation.

Specified by:
dataMalformed in interface MalformedDataListener
Overrides:
dataMalformed in class DisplayPanel
Parameters:
evt - the malformed data event
See Also:
MalformedDataListener

startAlert

public void startAlert(AlertEvent evt)
Turns on alert status for this component.

Specified by:
startAlert in interface AlertListener
Overrides:
startAlert in class DisplayPanel
Parameters:
evt - the alert event
See Also:
AlertListener

endAlert

public void endAlert(AlertEvent evt)
Turns off alert status for this component.

Specified by:
endAlert in interface AlertListener
Overrides:
endAlert in class DisplayPanel
Parameters:
evt - the alert event
See Also:
AlertListener

setAlignment

public void setAlignment(int alignment)

Sets the alignment of the icon relative to the text using one of the constants ABOVE, BELOW, LEFT, RIGHT, or DEFAULT.

If the alignment value is not valid, the alignment is not changed.

Fires property change: ALIGNMENT.

Parameters:
alignment - the new alignment of the icon relative to the text
See Also:
JPTConstants.ABOVE, JPTConstants.BELOW, SwingConstants.LEFT, SwingConstants.RIGHT, JPTConstants.DEFAULT

getAlignment

public int getAlignment()
Returns the alignment of the icon relative to the text.

See Also:
JPTConstants.ABOVE, JPTConstants.BELOW, SwingConstants.LEFT, SwingConstants.RIGHT

setOpaque

public void setOpaque(boolean opaque)

Sets the opaque state for the annotation.

The default opaque state is false which is the default for a JLabel.

Fires property change: SET_OPAQUE.

Parameters:
opaque - the opaque state (true or false)

setForeground

public void setForeground(Color foreground)

Sets the foreground color for the annotation to the given color.

If the given color is null, the foreground color is not changed.

Fires property change: SET_FOREGROUND.

Parameters:
foreground - the desired foreground color

setBackground

public void setBackground(Color background)

Sets the background color for the annotation to the given color.

If the given color is null, the background color is not changed.

Fires property change: SET_BACKGROUND.

Parameters:
background - the desired background color

setFont

public void setFont(Font font)

Sets the font used to render the text to the given font.

If the given font is null then it is set to getDefaultFont().

Fires property change: SET_FONT.

Parameters:
font - the font for this component

getDefaultFont

public static Font getDefaultFont()
Returns the default font for a JLabel.

Since:
2.3.3

setText

public void setText(String text)

Sets the text displayed by this annotation to the given text.

If the given text is null, no text will be displayed by this annotation.

Fires property change: SET_TEXT.

Parameters:
text - the text to be displayed

getText

public String getText()

Returns the text displayed by this annotation.


setIcon

public void setIcon(Icon icon)

Sets the icon displayed by this annotation to the given icon.

If the given icon is null, no icon will be displayed by this annotation.

Fires property change: SET_ICON.

Parameters:
icon - the icon to be displayed

getIcon

public Icon getIcon()
Returns the icon displayed by this annotation, or null if it has not been set.


setDisabledIcon

public void setDisabledIcon(Icon icon)

Sets the icon to be displayed when this annotation is disabled.

If the disabled icon is null, and the value of the icon property is an ImageIcon, a "grayed out" version of the icon is computed and displayed when the annotation is disabled.

The default value of this property is null.

Fires property change: SET_DISABLED_ICON.

Parameters:
icon - the icon to be displayed when this component is disabled

getDisabledIcon

public Icon getDisabledIcon()

Returns the icon to be displayed when this annotation is disabled, if it has been set through use of the setDisabledIcon method, or null if it has not been set.

If the disabled icon is null, and the value of the icon property is an ImageIcon, a "grayed out" version of the icon is computed and displayed when the annotation is disabled.

Returns:
the icon displayed when this annotation is disabled

setAlertIcon

public void setAlertIcon(Icon icon)

Sets the icon to be displayed when this annotation is in an alert state.

If the given icon is null, the currently displayed icon will not be changed when the annotation is in an alert state.

The default value of this property is null.

Fires property change: SET_ALERT_ICON.

Parameters:
icon - the icon to be displayed when this annotation is in alert status

getAlertIcon

public Icon getAlertIcon()

Returns the icon to be displayed when this annotation is put in an alert state, or null if it has not been set.