Class FeedbackPane
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,ScrollPaneConstants
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"). Seeappend(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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JScrollPane
JScrollPane.AccessibleJScrollPane, JScrollPane.ScrollBarNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields inherited from class edu.cnu.mdi.component.TextPaneScrollPane
BLACK_SS_10_P, BLACK_SS_12_P, BLUE_M_10_B, BLUE_SS_10_B, BLUE_SS_12_B, BLUE_SS_12_P, BLUE_TERMINAL, CYAN_TERMINAL, defaultStyle, document, GREEN_SS_10_P, GREEN_SS_12_B, GREEN_SS_12_P, GREEN_TERMINAL, RED_SS_10_P, RED_SS_12_P, RED_TERMINAL, textPane, YELLOW_TERMINALFields inherited from class javax.swing.JScrollPane
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewportFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.ScrollPaneConstants
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aFeedbackPanewith a dark background suitable for overlay-style feedback.FeedbackPane(Color fg, Color bg, int fontSize) Constructs aFeedbackPanewith explicit foreground color, background color, and font size. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends a feedback line, applying the simple prefix-based styling rules.voidappend(SimpleAttributeSet style, String message) Appends the given message using the specified style.static StringstripStyle(String message) Strips a recognized"$mono$"or"$colorName$"styling prefix from a feedback line, returning just the text thatappend(String)would have rendered -- for callers that want the same feedback content somewhere that isn't this pane itself (e.g.toString()Returns a short descriptive name for this component, useful for debugging.voidupdateFeedback(List<String> feedbackStrings) Replaces the current content with the provided feedback strings, then appends each one usingappend(String).Methods inherited from class edu.cnu.mdi.component.TextPaneScrollPane
append, append, clear, createStyle, createStyle, createStyle, getDefaultStyle, refresh, setDefaultStyleMethods inherited from class javax.swing.JScrollPane
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, updateUIMethods 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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, 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, updateMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
FeedbackPane
public FeedbackPane()Constructs aFeedbackPanewith a dark background suitable for overlay-style feedback. Uses cyan foreground and 11 pt font size. -
FeedbackPane
Constructs aFeedbackPanewith explicit foreground color, background color, and font size.- Parameters:
fg- foreground color for the default and monospaced stylesbg- background color applied to all text styles and the panefontSize- base font size in points; monospaced style uses a reduced size derived from this value
-
-
Method Details
-
append
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
- The message must start with
$. - A closing
$must appear such that the enclosed name is between 2 and 40 characters long. - 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:
appendin classTextPaneScrollPane- Parameters:
message- the feedback line; ignored ifnull
-
stripStyle
Strips a recognized"$mono$"or"$colorName$"styling prefix from a feedback line, returning just the text thatappend(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$wherenameis a real X11 color); an unrecognized$...$tag is left in place, exactly asappend(String)would render it (visibly, so a malformed tag stays noticeable to the developer) rather than being silently stripped.- Parameters:
message- the feedback line;nullreturnsnull- Returns:
- the line with any recognized styling prefix removed
-
append
Appends the given message using the specified style.- Parameters:
style- the style to apply; must not benullmessage- the message text; may benull(treated as empty)
-
updateFeedback
Replaces the current content with the provided feedback strings, then appends each one usingappend(String).Called by
FeedbackControlon every mouse-move update that produces a changed set of feedback strings.- Parameters:
feedbackStrings- the list of feedback strings to display; may benullor empty, in which case the pane is simply cleared
-
toString
Returns a short descriptive name for this component, useful for debugging.
-