Class JsonRawPane

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

public class JsonRawPane extends TextPaneScrollPane
The left half of the JsonSplitPane: a read-only, syntax-colored view of raw JSON text with incremental search highlighting.

Design

Extends TextPaneScrollPane so all the Nimbus-safe background wiring, StyledDocument setup, and TextPaneScrollPane.createStyle(Color, String, int, boolean, boolean) factory method are inherited without duplication.

Colorization strategy

Text is inserted in one shot with the STYLE_PLAIN base style, then JsonTokenPainter makes a second pass to apply token-level color runs using StyledDocument.setCharacterAttributes(int, int, javax.swing.text.AttributeSet, boolean). Doing the insert first and the coloring second keeps insertion fast regardless of file size — setCharacterAttributes on an already-inserted document is much cheaper than inserting with per-character attributes.

Search highlighting

highlight(String, BiConsumer) uses the Highlighter API (layered on top of the StyledDocument coloring) so that syntax colors are never disturbed by a search. Two highlight painter instances are maintained: one for all matches (dim yellow) and one for the currently selected match (bright orange). nextHighlight() and prevHighlight() cycle through the match list and scroll the pane to keep the current match visible.

Color scheme

Dark background (PANE_BG) with the following token colors:

  • Keys — cornflower blue, bold
  • String values — pale green
  • Numbers — gold
  • Booleans (true/false) — orange
  • Null — medium gray, italic
  • Structural ({ } [ ] , :) — light gray
  • Plain / unrecognised — near-white
See Also:
  • Constructor Details

    • JsonRawPane

      public JsonRawPane()
      Create a JsonRawPane with a dark background and no content.

      The Nimbus-safe background wiring (opaque scroll pane + viewport, transparent text pane) is handled by TextPaneScrollPane's constructor.

  • Method Details

    • showJson

      public void showJson(String json)
      Display a raw JSON string with syntax highlighting.

      The existing content is cleared, the raw text is inserted in one operation using STYLE_PLAIN, and then JsonTokenPainter.paint(StyledDocument, String) applies token-level color runs. The caret is reset to position 0 so the top of the file is visible immediately.

      Must be called on the EDT.

      Parameters:
      json - the raw JSON text to display; must not be null
    • showError

      public void showError(Exception cause)
      Display an inline error message instead of JSON content.

      Used by JsonSplitPane when the file cannot be read or the JSON is malformed. No dialog is shown; the error appears in the raw pane itself.

      Must be called on the EDT.

      Parameters:
      cause - the exception that caused the failure; must not be null
    • highlight

      public void highlight(String query, BiConsumer<Integer,Integer> countCallback)
      Highlight all occurrences of query in the raw text and select the first match.

      All previous highlights are removed before the new search. If query is null or blank, highlights are cleared and countCallback is called with (0, 0).

      Must be called on the EDT.

      Parameters:
      query - the literal string to search for (case-insensitive); null or blank clears highlights
      countCallback - receives (currentMatch, totalMatches) after the search completes; must not be null
    • nextHighlight

      public void nextHighlight()
      Move the selection to the next match, wrapping around at the end.

      No-op if there are no matches. Must be called on the EDT.

    • prevHighlight

      public void prevHighlight()
      Move the selection to the previous match, wrapping around at the start.

      No-op if there are no matches. Must be called on the EDT.