From ef741d60d080fd238c9b1c65fce9c14d093ccd88 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 28 May 2021 17:08:18 -0400 Subject: [PATCH] 7660 make tables have uniform look and feel --- .../casemodule/IngestJobInfoPanel.form | 18 ++--- .../casemodule/IngestJobInfoPanel.java | 5 +- .../ui/DataSourceBrowser.java | 1 - .../uiutils/BaseMessageOverlay.java | 1 - .../uiutils/CellModelTableCellRenderer.java | 38 ++--------- .../uiutils/DefaultCellModel.java | 65 +++++++------------ .../uiutils/GuiCellModel.java | 6 -- .../uiutils/JTablePanel.java | 33 ++++++---- 8 files changed, 58 insertions(+), 109 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.form b/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.form index c183e0de36..4e74529073 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.form +++ b/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.form @@ -1,11 +1,6 @@
- - - - - @@ -16,6 +11,7 @@ + @@ -35,9 +31,6 @@ - - - @@ -60,9 +53,6 @@ - - - @@ -85,6 +75,9 @@ + + + @@ -157,6 +150,9 @@ + + + diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.java index 4dcdc5260f..c0afb624e7 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/IngestJobInfoPanel.java @@ -267,19 +267,17 @@ public final class IngestJobInfoPanel extends javax.swing.JPanel { javax.swing.JScrollPane ingestModulesScrollPane = new javax.swing.JScrollPane(); ingestModuleTable = new javax.swing.JTable(); - setMaximumSize(new java.awt.Dimension(32767, 32767)); setLayout(new java.awt.BorderLayout()); - contentPanel.setMaximumSize(new java.awt.Dimension(32767, 32767)); contentPanel.setMinimumSize(new java.awt.Dimension(625, 150)); contentPanel.setPreferredSize(new java.awt.Dimension(625, 150)); contentPanel.setLayout(new java.awt.GridBagLayout()); ingestJobsScrollPane.setBorder(null); ingestJobsScrollPane.setMinimumSize(new java.awt.Dimension(16, 16)); - ingestJobsScrollPane.setPreferredSize(null); ingestJobTable.setModel(ingestJobTableModel); + ingestJobTable.setGridColor(javax.swing.UIManager.getDefaults().getColor("InternalFrame.borderColor")); ingestJobTable.getTableHeader().setReorderingAllowed(false); ingestJobsScrollPane.setViewportView(ingestJobTable); ingestJobTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); @@ -315,6 +313,7 @@ public final class IngestJobInfoPanel extends javax.swing.JPanel { ingestModulesScrollPane.setPreferredSize(new java.awt.Dimension(254, 16)); ingestModuleTable.setModel(ingestModuleTableModel); + ingestModuleTable.setGridColor(javax.swing.UIManager.getDefaults().getColor("InternalFrame.borderColor")); ingestModulesScrollPane.setViewportView(ingestModuleTable); gridBagConstraints = new java.awt.GridBagConstraints(); diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceBrowser.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceBrowser.java index 98522e5071..bb945833aa 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceBrowser.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/ui/DataSourceBrowser.java @@ -80,7 +80,6 @@ final class DataSourceBrowser extends javax.swing.JPanel implements ExplorerMana Bundle.DataSourceSummaryNode_column_results_header(), Bundle.DataSourceSummaryNode_column_results_header(), Bundle.DataSourceSummaryNode_column_tags_header(), Bundle.DataSourceSummaryNode_column_tags_header()); outline = outlineView.getOutline(); - outline.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dataSourceSummaryList = getDataSourceSummaryList(usageMap, fileCountsMap); diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/BaseMessageOverlay.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/BaseMessageOverlay.java index 8e90945eb7..634bb159cc 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/BaseMessageOverlay.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/BaseMessageOverlay.java @@ -26,7 +26,6 @@ import javax.swing.JLabel; * painting a JLabel using a java.awt.Graphics object. */ public class BaseMessageOverlay { - private final JLabel label; private boolean visible = false; diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/CellModelTableCellRenderer.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/CellModelTableCellRenderer.java index 2638ce1f56..1f18e23e30 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/CellModelTableCellRenderer.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/CellModelTableCellRenderer.java @@ -19,7 +19,6 @@ package org.sleuthkit.autopsy.datasourcesummary.uiutils; import java.awt.Component; -import java.awt.Insets; import java.awt.event.MouseEvent; import java.util.List; import javax.swing.BorderFactory; @@ -30,7 +29,6 @@ import javax.swing.JTable; import javax.swing.border.Border; import javax.swing.table.DefaultTableCellRenderer; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.sleuthkit.autopsy.datasourcesummary.uiutils.GuiCellModel.MenuItem; import org.sleuthkit.autopsy.datasourcesummary.uiutils.JTablePanel.CellMouseEvent; import org.sleuthkit.autopsy.datasourcesummary.uiutils.JTablePanel.CellMouseListener; @@ -43,7 +41,7 @@ public class CellModelTableCellRenderer extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; private static final int DEFAULT_ALIGNMENT = JLabel.LEFT; - private static final Border DEFAULT_BORDER = BorderFactory.createEmptyBorder(1, 5, 1, 5); + private static final Border DEFAULT_BORDER = BorderFactory.createEmptyBorder(2, 4, 2, 4); @Override public Component getTableCellRendererComponent(JTable table, Object value, @@ -62,43 +60,21 @@ public class CellModelTableCellRenderer extends DefaultTableCellRenderer { * Customizes the jlabel to match the column model and cell model provided. * * @param defaultCell The cell to customize that will be displayed in the - * jtable. - * @param cellModel The cell model for this cell. + * jtable. + * @param cellModel The cell model for this cell. * * @return The provided defaultCell. */ protected Component getTableCellRendererComponent(JLabel defaultCell, GuiCellModel cellModel) { - // sets the text for the cell or null if not present. - String text = cellModel.getText(); - if (StringUtils.isNotBlank(text)) { - defaultCell.setText(text); - } else { - defaultCell.setText(null); - } - - // sets the tooltip for the cell if present. - String tooltip = cellModel.getTooltip(); - if (StringUtils.isNotBlank(tooltip)) { - defaultCell.setToolTipText(tooltip); - } else { - defaultCell.setToolTipText(null); - } - - // sets the padding for cell text within the cell. - Insets insets = cellModel.getInsets(); - if (insets != null) { - defaultCell.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)); - } else { - defaultCell.setBorder(DEFAULT_BORDER); - } - + defaultCell.setText(cellModel.getText()); + defaultCell.setToolTipText(cellModel.getTooltip()); // sets the JLabel alignment (left, center, right) or default alignment // if no alignment is specified int alignment = (cellModel.getHorizontalAlignment() == null) ? DEFAULT_ALIGNMENT : cellModel.getHorizontalAlignment().getJLabelAlignment(); defaultCell.setHorizontalAlignment(alignment); - + defaultCell.setBorder(DEFAULT_BORDER); return defaultCell; } @@ -134,7 +110,7 @@ public class CellModelTableCellRenderer extends DefaultTableCellRenderer { /** * @return The default cell mouse listener that triggers popups for - * non-primary button events. + * non-primary button events. */ public static CellMouseListener getMouseListener() { return DEFAULT_CELL_MOUSE_LISTENER; diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DefaultCellModel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DefaultCellModel.java index 06165a3023..215f71469e 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DefaultCellModel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/DefaultCellModel.java @@ -18,27 +18,24 @@ */ package org.sleuthkit.autopsy.datasourcesummary.uiutils; -import java.awt.Insets; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Function; import java.util.function.Supplier; -import org.sleuthkit.autopsy.datasourcesummary.uiutils.ExcelCellModel; /** * The default cell model. */ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { - final T data; - final Function stringConverter; - String tooltip; - CellModel.HorizontalAlign horizontalAlignment; - Insets insets; - List popupMenu; - Supplier> menuItemSupplier; - final String excelFormatString; + private final T data; + private final String text; + private String tooltip; + private CellModel.HorizontalAlign horizontalAlignment; + private List popupMenu; + private Supplier> menuItemSupplier; + private final String excelFormatString; /** * Main constructor. @@ -52,9 +49,9 @@ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { /** * Constructor. * - * @param data The data to be displayed in the cell. + * @param data The data to be displayed in the cell. * @param stringConverter The means of converting that data to a string or - * null to use .toString method on object. + * null to use .toString method on object. */ public DefaultCellModel(T data, Function stringConverter) { this(data, stringConverter, null); @@ -63,20 +60,25 @@ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { /** * Constructor. * - * @param data The data to be displayed in the cell. - * @param stringConverter The means of converting that data to a string or - * null to use .toString method on object. + * @param data The data to be displayed in the cell. + * @param stringConverter The means of converting that data to a string or + * null to use .toString method on object. * @param excelFormatString The apache poi excel format string to use with - * the data. + * the data. * * NOTE: Only certain data types can be exported. See * ExcelTableExport.createCell() for types. */ public DefaultCellModel(T data, Function stringConverter, String excelFormatString) { this.data = data; - this.stringConverter = stringConverter; this.excelFormatString = excelFormatString; - this.tooltip = getText(); + + if (stringConverter == null) { + text = this.data == null ? "" : this.data.toString(); + } else { + text = stringConverter.apply(this.data); + } + this.tooltip = text; } @Override @@ -91,11 +93,7 @@ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { @Override public String getText() { - if (this.stringConverter == null) { - return this.data == null ? "" : this.data.toString(); - } else { - return this.stringConverter.apply(this.data); - } + return text; } @Override @@ -132,33 +130,14 @@ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { return this; } - @Override - public Insets getInsets() { - return insets; - } - - /** - * Sets the insets for the text within the cell - * - * @param insets The insets. - * - * @return As a utility, returns this. - */ - public DefaultCellModel setInsets(Insets insets) { - this.insets = insets; - return this; - } - @Override public List getPopupMenu() { if (popupMenu != null) { return Collections.unmodifiableList(popupMenu); } - if (menuItemSupplier != null) { return this.menuItemSupplier.get(); } - return null; } @@ -166,6 +145,7 @@ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { * Sets a function to lazy load the popup menu items. * * @param menuItemSupplier The lazy load function for popup items. + * * @return */ public DefaultCellModel setPopupMenuRetriever(Supplier> menuItemSupplier) { @@ -177,6 +157,7 @@ public class DefaultCellModel implements GuiCellModel, ExcelCellModel { * Sets the list of items for a popup menu * * @param popupMenu + * * @return As a utility, returns this. */ public DefaultCellModel setPopupMenu(List popupMenu) { diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/GuiCellModel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/GuiCellModel.java index e1c7fa0944..bac74d8fd5 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/GuiCellModel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/GuiCellModel.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.datasourcesummary.uiutils; -import java.awt.Insets; import java.util.List; /** @@ -72,11 +71,6 @@ public interface GuiCellModel extends CellModel { } } - /** - * @return The insets for the cell text. - */ - Insets getInsets(); - /** * @return The popup menu associated with this cell or null if no popup menu * should be shown for this cell. diff --git a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java index be814d23a9..b1713d366a 100644 --- a/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java +++ b/Core/src/org/sleuthkit/autopsy/datasourcesummary/uiutils/JTablePanel.java @@ -41,6 +41,8 @@ import javax.swing.table.TableColumnModel; */ public class JTablePanel extends AbstractLoadableComponent> { + private static final int EXTRA_ROW_HEIGHT = 4; + /** * An event that wraps a swing MouseEvent also providing context within the * table cell. @@ -56,10 +58,10 @@ public class JTablePanel extends AbstractLoadableComponent> { /** * Main constructor. * - * @param e The underlying mouse event. - * @param table The table that was the target of the mouse event. - * @param row The row within the table that the event occurs. - * @param col The column within the table that the event occurs. + * @param e The underlying mouse event. + * @param table The table that was the target of the mouse event. + * @param row The row within the table that the event occurs. + * @param col The column within the table that the event occurs. * @param cellValue The value within the cell. */ public CellMouseEvent(MouseEvent e, JTable table, int row, int col, Object cellValue) { @@ -115,15 +117,14 @@ public class JTablePanel extends AbstractLoadableComponent> { * Handles mouse events at a cell level for the table. * * @param e The event containing information about the cell, the mouse - * event, and the table. + * event, and the table. */ void mouseClicked(CellMouseEvent e); } /** - * JTables don't allow displaying messages. So this LayerUI is used to - * display the contents of a child JLabel. Inspired by TableWaitLayerTest - * (Animating a Busy Indicator): + * This LayerUI is used to display the contents of a child JLabel. Inspired + * by TableWaitLayerTest (Animating a Busy Indicator): * https://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html. */ private static class Overlay extends LayerUI { @@ -205,7 +206,7 @@ public class JTablePanel extends AbstractLoadableComponent> { .map((colModel) -> colModel.getCellRenderer()) .collect(Collectors.toList()); - return new DefaultListTableModel(columnRenderers); + return new DefaultListTableModel<>(columnRenderers); } /** @@ -225,7 +226,6 @@ public class JTablePanel extends AbstractLoadableComponent> { return resultTable; } - private JScrollPane tableScrollPane; private Overlay overlayLayer; private ListTableModel tableModel; @@ -241,6 +241,7 @@ public class JTablePanel extends AbstractLoadableComponent> { public JTablePanel(ListTableModel tableModel) { this(); setModel(tableModel); + table.setRowHeight(table.getRowHeight() + EXTRA_ROW_HEIGHT); } /** @@ -268,6 +269,7 @@ public class JTablePanel extends AbstractLoadableComponent> { } } }); + table.setGridColor(javax.swing.UIManager.getDefaults().getColor("InternalFrame.borderColor")); } /** @@ -290,7 +292,7 @@ public class JTablePanel extends AbstractLoadableComponent> { /** * @return The current listener for mouse events. The events provided to - * this listener will have cell and table context. + * this listener will have cell and table context. */ public CellMouseListener getCellListener() { return cellListener; @@ -300,7 +302,8 @@ public class JTablePanel extends AbstractLoadableComponent> { * Sets the current listener for mouse events. * * @param cellListener The event listener that will receive these events - * with cell and table context. + * with cell and table context. + * * @return */ public JTablePanel setCellListener(CellMouseListener cellListener) { @@ -329,7 +332,8 @@ public class JTablePanel extends AbstractLoadableComponent> { /** * @return The function for determining the key for a data row. This key is - * used to maintain current selection in the table despite changing rows. + * used to maintain current selection in the table despite changing + * rows. */ public Function getKeyFunction() { return keyFunction; @@ -351,9 +355,10 @@ public class JTablePanel extends AbstractLoadableComponent> { this.keyFunction = keyFunction; return this; } - + /** * Returns the selected items or null if no item is selected. + * * @return The selected items or null if no item is selected. */ public List getSelectedItems() {