Package edu.cnu.mdi.json
Class JsonNodeData
java.lang.Object
edu.cnu.mdi.json.JsonNodeData
Immutable value object carried as the user-object of every
DefaultMutableTreeNode in the JSON tree.
Purpose
Rather than encoding type information in the label string and re-parsing it
in the renderer, each node carries an explicit JsonNodeData.Kind tag. This lets
JsonTreeCellRenderer select colors in a single switch
without any string analysis.
Label format
toString() returns the string that JsonTreeCellRenderer
passes to the underlying label. The format is:
- Leaf nodes with a key —
key: value(e.g.name: "Alice",count: 42) - Non-leaf key/index nodes —
key summary(e.g.address {3 keys},[0] [2 items]) - Root node — the file name
- Top-level primitives (no key) — the value string alone
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumClassifies a JSON tree node for color selection inJsonTreeCellRenderer. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal StringThe key or array index label.final JsonNodeData.KindThe token kind, used byJsonTreeCellRendererto pick a color without re-parsing the label.final StringThe value string for leaf nodes, or a size summary (e.g. -
Constructor Summary
ConstructorsConstructorDescriptionJsonNodeData(String key, String value, JsonNodeData.Kind kind) Create aJsonNodeData. -
Method Summary
Modifier and TypeMethodDescriptiontoString()Returns the display string used byJsonTreeCellRenderer.
-
Field Details
-
key
The key or array index label.Empty for top-level primitive nodes that have no enclosing key.
-
value
The value string for leaf nodes, or a size summary (e.g.{3 keys}) for non-leaf key/index nodes.Empty for the root node.
-
kind
The token kind, used byJsonTreeCellRendererto pick a color without re-parsing the label.
-
-
Constructor Details
-
JsonNodeData
Create aJsonNodeData.- Parameters:
key- key or array index; may be empty but notnullvalue- value string or size summary; may be empty but notnullkind- token kind; must not benull
-
-
Method Details
-
toString
Returns the display string used byJsonTreeCellRenderer.- Root: just the key (the file name).
- No key (top-level primitive): just the value.
- Otherwise:
"key: value"for leaves or"key summary"for non-leaf keys.
-