Class DisplayLabel

  • All Implemented Interfaces:
    Computable, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class DisplayLabel
    extends java.awt.Label
    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 java.awt.Label

        java.awt.Label.AccessibleAWTLabel
      • 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

      Fields 
      Modifier and Type Field Description
      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 java.awt.Label

        CENTER, LEFT, RIGHT
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 java.awt.Label

        addNotify, getAccessibleContext, getAlignment, getText, paramString, setAlignment
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
      • 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.
      • 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 #.
      • 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.)
      • 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.
      • getNumSize

        public int getNumSize()
        Return the desired maximum number of characters in displayed numbers.
      • 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 Label class will return the actual displayed text, including the substitited values.
      • 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 java.awt.Label
      • 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 java.awt.Component