srecord noeq G22JavaObjectVisualizer(G22Utils g22utils) is Swingable { settable bool withTypeAndTime = true; settable bool singleLineLayout; // TODO settable int maxElements = 1000; // max elements of collection to show transient settable O object; transient settable long nanos = -1; *(G22Utils *g22utils, O *object) {} cachedVisualize { S type = null; JComponent c = visualizeObject(object); if (withTypeAndTime) type = shortClassName(object); if (withTypeAndTime) { S timeDesc = nanos < 0 ? "" : formatElapsedTimeWithAppropriateUnit(nanosToSeconds(nanos)); c = northAndCenterWithMargins( westAndEastWithMargin( withLabel("Object type:", jlabel(type)), empty(timeDesc) ? jpanel() : withLabel("Execution time:", jlabel(timeDesc)) ), c); } ret c; } JComponent visualizeObject(O object) { ret mainVisualizer().visualize(object); } ObjectVisualizer mainVisualizer() { ret new ObjectVisualizer().recurse(true).bigFont(true); } class ObjectVisualizer { settable bool recurse; settable bool bigFont; ObjectVisualizer subVisualizer() { ret new ObjectVisualizer; } JComponent makeBig(JComponent c) { if (bigFont) ret fontSizePlus(10, c); ret c; } JComponent visualize(O object) { try { ret visualize2(object); } catch e { ret jErrorView(new RuntimeException("Visualization error", e)); } } JComponent visualize2(O object) { // exception if (object cast Throwable) ret jErrorView(object); // null or empty string if (object == null || eq(object, "")) ret jpanel(); // number if (object cast Int) object = toLong(object); if (object cast Long) ret makeBig(jcenteredLabel(n2(object))); if (object cast Number) ret makeBig(jcenteredLabel(str(object))); // image if (object cast MakesBufferedImage) object = toBufferedImage(object); if (object cast BufferedImage) ret jscroll_centered_borderless(g22utils.stdImageSurface(object)); // collection if (recurse) { if (object cast Collection) { var sub = subVisualizer(); ret jscroll_centered_borderless(vstackWithSpacing(cloneTakeFirst(maxElements, object), element -> sub.visualize(element))); } } ret jcenteredlabel(shorten(str(object))); } } }