Class FeedbackPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, ScrollPaneConstants

public class FeedbackPane extends TextPaneScrollPane
A scrollable pane specialized for displaying mouse-over feedback in the MDI application.

This class is a "low-tech" alternative to a heads-up display (HUD). It renders feedback lines with simple styling rules driven by prefixes in the feedback text:

  • "$mono$" — renders the remainder of the line using a small monospaced style (e.g. for coordinate dumps or debug info).
  • "$colorName$" — renders the remainder of the line using the specified X11 color (e.g. "$red$hit", "$dark blue$selection"). See append(String) for the full validation rules.
  • No recognized prefix — renders using the default feedback style.

Styles for X11 colors are cached so subsequent lines with the same color reuse the same SimpleAttributeSet.

Author:
heddle
See Also:
  • Constructor Details

    • FeedbackPane

      public FeedbackPane()
      Constructs a FeedbackPane with a dark background suitable for overlay-style feedback. Uses cyan foreground and 11 pt font size.
    • FeedbackPane

      public FeedbackPane(Color fg, Color bg, int fontSize)
      Constructs a FeedbackPane with explicit foreground color, background color, and font size.
      Parameters:
      fg - foreground color for the default and monospaced styles
      bg - background color applied to all text styles and the pane
      fontSize - base font size in points; monospaced style uses a reduced size derived from this value
  • Method Details

    • append

      public void append(String message)
      Appends a feedback line, applying the simple prefix-based styling rules.

      Prefix syntax

      • "$mono$" (case-insensitive: $Mono$, $MONO$, etc. are all accepted) — the prefix is stripped and the remainder is rendered in the small monospaced style.
      • "$<name>$" where <name> is a valid X11 color name (case-insensitive, 2–40 characters) — the prefix is stripped and the remainder is rendered using a style derived from that color. Styles are cached per lower-cased name.
      • No recognized prefix, or an unrecognized / malformed prefix — the entire, unmodified string (including any $…$ fragment) is rendered in the default style. This ensures malformed tags are visible to the developer rather than being silently swallowed.

      Validation rules for the color prefix

      1. The message must start with $.
      2. A closing $ must appear such that the enclosed name is between 2 and 40 characters long.
      3. The enclosed name must resolve to a known X11 color via X11Colors.getX11Color(java.lang.String, int); if it does not, the entire original string is rendered in the default style.

      The $mono$ special case (tested first, case-insensitively) is exempt from the length and color-name validation that applies to the generic $name$ path. Previously, a capitalized variant such as $Mono$ would fall through to the color-name path, fail to match any X11 color, and be rendered raw including the tag — an unintuitive developer experience. The case-insensitive comparison eliminates that class of mistake.

      Overrides:
      append in class TextPaneScrollPane
      Parameters:
      message - the feedback line; ignored if null
    • stripStyle

      public static String stripStyle(String message)
      Strips a recognized "$mono$" or "$colorName$" styling prefix from a feedback line, returning just the text that append(String) would have rendered -- for callers that want the same feedback content somewhere that isn't this pane itself (e.g. a hover popup window), without needing to duplicate this class's own prefix-parsing rules.

      A tag is only stripped if it matches append(String)'s own recognition rules ($mono$ exactly, or $name$ where name is a real X11 color); an unrecognized $...$ tag is left in place, exactly as append(String) would render it (visibly, so a malformed tag stays noticeable to the developer) rather than being silently stripped.

      Parameters:
      message - the feedback line; null returns null
      Returns:
      the line with any recognized styling prefix removed
    • append

      public void append(SimpleAttributeSet style, String message)
      Appends the given message using the specified style.
      Parameters:
      style - the style to apply; must not be null
      message - the message text; may be null (treated as empty)
    • updateFeedback

      public void updateFeedback(List<String> feedbackStrings)
      Replaces the current content with the provided feedback strings, then appends each one using append(String).

      Called by FeedbackControl on every mouse-move update that produces a changed set of feedback strings.

      Parameters:
      feedbackStrings - the list of feedback strings to display; may be null or empty, in which case the pane is simply cleared
    • toString

      public String toString()
      Returns a short descriptive name for this component, useful for debugging.
      Overrides:
      toString in class Component
      Returns:
      the string "FeedbackPane"