net.sourceforge.webcompmath.awt
Class DisplayLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by net.sourceforge.webcompmath.awt.DisplayLabel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants, Computable
Direct Known Subclasses:
WCMDisplayLabelBean

public class DisplayLabel
extends javax.swing.JLabel
implements Computable

A DisplayLabel is a label that can display numbers embedded in strings. The text for the label can include '#' characters, which are substituted by values of specified Value objects. (A doubled ## is interpreted as a single literal # to be displayed rather than substituted.) You should provide as many Values as there are #'s in the text. However, no errors are generated if this is not the case. Extra expressions are ignored; extra #'s are shown as "undefined" in the display. In fact, DisplayLabels do not ever generat JCMErrors. Note that Value objects include objects of type Constant, Variable, and Expression, for example. Value is just an interface defined in package edu.hws.jcm.data.

The values displayed in a DisplayLabel are recomputed when the Label's compute() method is called. Usually, this is done by a Controller that the DisplayLabel is registered with. See the Controller class for more information.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int numSize
          Desired maximum number of characters in displayed numbers.
protected  java.lang.String text
          Unsubstituted text for display.
protected  Value[] values
          Value objects whose values will be substituted for #'s in text.
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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
DisplayLabel()
          Create a label with no expressions set up to display a single number.
DisplayLabel(java.lang.String text, Value val)
          Convenience method for making a DisplayLabel with just one value to display.
DisplayLabel(java.lang.String text, Value[] vals)
          Create a DisplayLabel to display one or more values.
 
Method Summary
 void compute()
          The compute method recalculates the displayed Values and changes the text of the label to show the new values.
 java.lang.String getBaseText()
          Return the basic text, including the #'s where Values are inserted in the displayed text.
 int getNumSize()
          Return the desired maximum number of characters in displayed numbers.
 java.awt.Dimension getPreferredSize()
          Return the preferred size of this DisplayLabel.
 Value[] getValues()
          Get the array of Value objects whose values are displayed in this DisplayLabel.
 void setNumSize(int size)
          Set the desired maximum number of characters in displayed numbers.
 void setText(java.lang.String text)
          Set text for display -- text should include as many (single) #'s as there are values to display.
 void setValue(Value val)
          A convenience method that can be used when the display string contains just a single #.
 void setValues(Value[] vals)
          Set the array of Value objects whose values are displayed in this DisplayLabel, and change the display to show the new values.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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

text

protected java.lang.String text
Unsubstituted text for display.


numSize

protected int numSize
Desired maximum number of characters in displayed numbers.


values

protected Value[] values
Value objects whose values will be substituted for #'s in text.

Constructor Detail

DisplayLabel

public DisplayLabel()
Create a label with no expressions set up to display a single number. Initial value is "undefined"; Use the setValue() method to set the value to be displayed.


DisplayLabel

public DisplayLabel(java.lang.String text,
                    Value val)
Convenience method for making a DisplayLabel with just one value to display.

Parameters:
text - Text to display. It shoud contain a single '#', which will be substituted by the value.
val - a Value object whose value is substituted for the # in the text.

DisplayLabel

public DisplayLabel(java.lang.String text,
                    Value[] vals)
Create a DisplayLabel to display one or more values. Text and vals can be null. If not, text should have as many (single) #'s as there are expressions. The values of the Value objects are substituted for the #'s in the display.

Parameters:
text - The text to display. If this is null, it is set to "#".
vals - The Value object(s) whose values are substituted for #'s in the text. If this is null, the values shoud be set later by calling the setValues() method.
Method Detail

compute

public void compute()
The compute method recalculates the displayed Values and changes the text of the label to show the new values. This is usually called by a Controller.

Specified by:
compute in interface Computable

getValues

public Value[] getValues()
Get the array of Value objects whose values are displayed in this DisplayLabel.

Returns:
array of values

setValue

public void setValue(Value val)
A convenience method that can be used when the display string contains just a single #. This sets the Value object whose value is substituted for that #.

Parameters:
val - value to use

setValues

public void setValues(Value[] vals)
Set the array of Value objects whose values are displayed in this DisplayLabel, and change the display to show the new values. (The contents of the array, vals, are copied into a newly created array.)

Parameters:
vals - array of values

setNumSize

public void setNumSize(int size)
Set the desired maximum number of characters in displayed numbers. Actual size might be larger. Value is clamped to the range 6 to 25.

Parameters:
size - max number of chars

getNumSize

public int getNumSize()
Return the desired maximum number of characters in displayed numbers.

Returns:
max number of chars

getBaseText

public java.lang.String getBaseText()
Return the basic text, including the #'s where Values are inserted in the displayed text. Note that the getText() method from the JLabel class will return the actual displayed text, including the substitited values.

Returns:
basic text

setText

public void setText(java.lang.String text)
Set text for display -- text should include as many (single) #'s as there are values to display.

Overrides:
setText in class javax.swing.JLabel
Parameters:
text - text to use

getPreferredSize

public java.awt.Dimension getPreferredSize()
Return the preferred size of this DisplayLabel. Allow space for up to numSize (or 8, whichever is larger) characters for each (single) # in the text. This is not meant to be called directly.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
preferred size