Class SwingMessageField<M extends Message>

Type Parameters:
M - the type of the messages
All Implemented Interfaces:
MessageReceiver<M>, ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class SwingMessageField<M extends Message> extends JLabel implements MessageReceiver<M>
A one-line display for one message at a time, to be included in a Swing based GUI. The background color is set according to the Message.Kind.
See Also:
  • Field Details

  • Constructor Details

    • SwingMessageField

      public SwingMessageField()
      Only constructor. After construction, setup() must be called for the completion of this instance configuration.
  • Method Details

    • setup

      public SwingMessageField<M> setup()
      Completion of the configuration after construction. This method sets Swing attributes by method invocations. These are separate from the constructor to avoid "this-escapes" with future subclasses.
    • setColorWarn

      public Color setColorWarn(Color nc)
      Set the color used to signal warning messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorError

      public Color setColorError(Color nc)
      Set the color used to signal error messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorHint

      public Color setColorHint(Color nc)
      Set the color used to signal hint messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorNeutral

      public Color setColorNeutral(Color nc)
      Set the color used to signal non-error, warning or hint messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setMessageToString

      public void setMessageToString(Function<? super M,String> toStr)
      Sets the function which is applied to the received message for getting a printable string.
      Parameters:
      toStr - the function to get a printable string
    • setLocallyUsed

      public void setLocallyUsed(boolean locallyUsed)
      Allows a local use of the text input field and prevents overwriting by
      Parameters:
      locallyUsed - whether the text input field is used for another purpose
    • receive

      public void receive(M msg)
      Receive a message, render it to string and print it on the message field. That can be suppressed by locallyUsed. The background color is swichted according to Message.Kind.
      Specified by:
      receive in interface MessageReceiver<M extends Message>
      Parameters:
      msg - the message to display
    • clear

      public void clear()
      Set background color to neutral and text content to empty.