From 88fa4dc88d8cd5c2ac3ec8600c16c29bd152b3d3 Mon Sep 17 00:00:00 2001 From: Bukowa Date: Fri, 14 Feb 2025 04:22:40 +0100 Subject: [PATCH] allow table sorting --- .../bindiffhelper/BinDiffHelperProvider.java | 14 +++++++++++-- .../bindiffhelper/ComparisonTableModel.java | 21 ++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/bindiffhelper/BinDiffHelperProvider.java b/src/main/java/bindiffhelper/BinDiffHelperProvider.java index e610f75..f05cfe4 100644 --- a/src/main/java/bindiffhelper/BinDiffHelperProvider.java +++ b/src/main/java/bindiffhelper/BinDiffHelperProvider.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,12 +32,14 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; +import java.util.Comparator; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingConstants; +import javax.swing.table.TableRowSorter; import docking.ActionContext; import docking.DockingWindowManager; @@ -384,6 +386,14 @@ protected void doDiffWork() { if (createTable) { table = new GTable(); + + TableRowSorter sorter = new TableRowSorter<>(ctm); + table.setRowSorter(sorter); + + // Ensure proper sorting for similarity and confidence + sorter.setComparator(6, Comparator.comparingDouble(o -> (Double) o)); // Similarity + sorter.setComparator(7, Comparator.comparingDouble(o -> (Double) o)); // Confidence + scrollPane = new JScrollPane(table); gui.removeAll(); gui.add(scrollPane, BorderLayout.CENTER); diff --git a/src/main/java/bindiffhelper/ComparisonTableModel.java b/src/main/java/bindiffhelper/ComparisonTableModel.java index e9b347e..cde1513 100644 --- a/src/main/java/bindiffhelper/ComparisonTableModel.java +++ b/src/main/java/bindiffhelper/ComparisonTableModel.java @@ -85,13 +85,20 @@ public boolean isCellEditable(int row, int col) { return false; } - public Class getColumnClass(int c) { - if (c == 0) - return Boolean.class; - // else if (c == 5) - // return Double.class; - - return String.class; + @Override + public Class getColumnClass(int columnIndex) { + return switch (columnIndex) { + case 0 -> Boolean.class; // Checkbox column + case 1 -> String.class; // Address this file (hex string) + case 2 -> String.class; // Name this file + case 3 -> String.class; // Name Database + case 4 -> String.class; // Address other file (hex string) + case 5 -> String.class; // Name other file + case 6 -> Double.class; // Similarity (numeric) + case 7 -> Double.class; // Confidence (numeric) + case 8 -> String.class; // Algorithm + default -> Object.class; + }; } public void setValueAt(Object value, int row, int col) {