summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2026-01-28 21:32:27 -0500
committerBenjamin Culkin <scorpress@gmail.com>2026-01-28 21:32:27 -0500
commitdde33dd8a8abb5418a04120e70da7998bc2e069c (patch)
tree5794ce0c21c1cdc3afec60fdc3ed19dec7146b37
parentdb210a8fd59f5281c120f1e8749b917246254e75 (diff)
Add proper formatting for JSON
Adds proper formatting/highlighting for the 'raw' message view
-rw-r--r--firmal/src/main/java/bjc/firmal/gptbrowser/GPTJSONBrowserFrame.java26
1 files changed, 19 insertions, 7 deletions
diff --git a/firmal/src/main/java/bjc/firmal/gptbrowser/GPTJSONBrowserFrame.java b/firmal/src/main/java/bjc/firmal/gptbrowser/GPTJSONBrowserFrame.java
index 2b96910..879d636 100644
--- a/firmal/src/main/java/bjc/firmal/gptbrowser/GPTJSONBrowserFrame.java
+++ b/firmal/src/main/java/bjc/firmal/gptbrowser/GPTJSONBrowserFrame.java
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -42,8 +43,10 @@ import org.json.JSONTokener;
import bjc.firmal.Firmal;
import bjc.functypes.ClosableThrowFunction;
import bjc.utils.gui.DelegateListCellRenderer;
+import bjc.utils.gui.JsonEditorKit;
import bjc.utils.gui.panels.BatchTaskProgressPanel.BatchHandle;
import bjc.utils.misc.NamedPreparedStatement;
+import bjc.utils.misc.SmartJSONFormatter;
import org.json.JSONArray;
@@ -62,8 +65,8 @@ public class GPTJSONBrowserFrame {
*/
private final class SaveConversationTask extends SwingWorker<Void, Integer> {
private GPTConversationDB conversation;
- private ClosableThrowFunction<List<NamedPreparedStatement.Args>, Future<List<Integer>>, SQLException> insertConvFunc;
- private ClosableThrowFunction<List<NamedPreparedStatement.Args>, Future<List<Integer>>, SQLException> insertMessageFunc;
+ private ClosableThrowFunction<List<NamedPreparedStatement.Args>, CompletableFuture<List<Integer>>, SQLException> insertConvFunc;
+ private ClosableThrowFunction<List<NamedPreparedStatement.Args>, CompletableFuture<List<Integer>>, SQLException> insertMessageFunc;
private String note;
private CountDownLatch msgCounter;
@@ -76,8 +79,8 @@ public class GPTJSONBrowserFrame {
* @param msgCounter The message counter
*/
public SaveConversationTask(GPTConversationDB conv,
- ClosableThrowFunction<List<NamedPreparedStatement.Args>, Future<List<Integer>>, SQLException> convUpdate,
- ClosableThrowFunction<List<NamedPreparedStatement.Args>, Future<List<Integer>>, SQLException> msgUpdate,
+ ClosableThrowFunction<List<NamedPreparedStatement.Args>, CompletableFuture<List<Integer>>, SQLException> convUpdate,
+ ClosableThrowFunction<List<NamedPreparedStatement.Args>, CompletableFuture<List<Integer>>, SQLException> msgUpdate,
CountDownLatch msgCounter) {
this.conversation = conv;
this.insertConvFunc = convUpdate;
@@ -470,7 +473,7 @@ public class GPTJSONBrowserFrame {
JMenuItem loadConversations = new JMenuItem("Load Conversations...");
loadConversations.addActionListener((aev) -> {
- // TODO load conversations from DB
+
});
fileMenu.add(loadConversations);
@@ -498,6 +501,9 @@ public class GPTJSONBrowserFrame {
conversationMessageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JTextPane messagePane = new JTextPane();
+ messagePane.setEditorKit(new JsonEditorKit());
+ JsonEditorKit.JsonHighlightSupport.install(messagePane);
+
JScrollPane messageScrollPane = new JScrollPane(messagePane);
JSplitPane detailPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, conversationMessageScroll, messageScrollPane);
@@ -521,9 +527,15 @@ public class GPTJSONBrowserFrame {
if (lse.getValueIsAdjusting()) return;
int idx = lse.getFirstIndex();
- RawMessageDB rawMessage = conversationMessageModel.get(idx);
+ if (conversationMessageModel.size() >= idx) {
+ RawMessageDB rawMessage = conversationMessageModel.get(idx);
- messagePane.setText(rawMessage.getMessageBody());
+ String rawMessageBody = rawMessage.getMessageBody();
+ String formattedMessageBody = SmartJSONFormatter.format(rawMessageBody);
+
+
+ ((JsonEditorKit.JsonDocument)messagePane.getDocument()).setJson(formattedMessageBody);
+ }
});
}
}