Class JsonRawPane
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,ScrollPaneConstants
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:
-
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidhighlight(String query, BiConsumer<Integer, Integer> countCallback) Highlight all occurrences ofqueryin the raw text and select the first match.voidMove the selection to the next match, wrapping around at the end.voidMove the selection to the previous match, wrapping around at the start.voidDisplay an inline error message instead of JSON content.voidDisplay a raw JSON string with syntax highlighting.Methods inherited from class edu.cnu.mdi.component.TextPaneScrollPane
append, 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, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JsonRawPane
public JsonRawPane()Create aJsonRawPanewith 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
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 thenJsonTokenPainter.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 benull
-
showError
Display an inline error message instead of JSON content.Used by
JsonSplitPanewhen 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 benull
-
highlight
Highlight all occurrences ofqueryin the raw text and select the first match.All previous highlights are removed before the new search. If
queryisnullor blank, highlights are cleared andcountCallbackis called with(0, 0).Must be called on the EDT.
- Parameters:
query- the literal string to search for (case-insensitive);nullor blank clears highlightscountCallback- receives(currentMatch, totalMatches)after the search completes; must not benull
-
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.
-