19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
21 import java.awt.Component;
22 import java.awt.Insets;
23 import java.awt.event.MouseEvent;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.function.Supplier;
28 import javax.swing.BorderFactory;
29 import javax.swing.JLabel;
30 import javax.swing.JMenuItem;
31 import javax.swing.JPopupMenu;
32 import javax.swing.JTable;
33 import javax.swing.border.Border;
34 import javax.swing.table.DefaultTableCellRenderer;
35 import org.apache.commons.collections.CollectionUtils;
36 import org.apache.commons.lang3.StringUtils;
65 this.jlabelAlignment = jlabelAlignment;
73 return this.jlabelAlignment;
213 this.horizontalAlignment = alignment;
236 if (popupMenu != null) {
237 return Collections.unmodifiableList(popupMenu);
240 if (menuItemSupplier != null) {
241 return this.menuItemSupplier.get();
265 this.popupMenu = popupMenu == null ? null :
new ArrayList<>(
popupMenu);
276 private static final Border
DEFAULT_BORDER = BorderFactory.createEmptyBorder(1, 5, 1, 5);
280 boolean isSelected,
boolean hasFocus,
int row,
int column) {
282 JLabel c = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
302 String text = cellModel.
getText();
303 if (StringUtils.isNotBlank(text)) {
304 defaultCell.setText(text);
306 defaultCell.setText(null);
311 if (StringUtils.isNotBlank(tooltip)) {
312 defaultCell.setToolTipText(tooltip);
314 defaultCell.setToolTipText(null);
319 if (insets != null) {
320 defaultCell.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
322 defaultCell.setBorder(DEFAULT_BORDER);
330 defaultCell.setHorizontalAlignment(alignment);
350 if (CollectionUtils.isNotEmpty(menuItems)) {
351 final JPopupMenu popupMenu =
new JPopupMenu();
353 JMenuItem jMenuItem =
new JMenuItem(mItem.getTitle());
354 if (mItem.getAction() != null) {
355 jMenuItem.addActionListener((evt) -> mItem.getAction().run());
357 popupMenu.add(jMenuItem);
HorizontalAlign getHorizontalAlignment()
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
List< MenuItem > popupMenu
static final CellMouseListener DEFAULT_CELL_MOUSE_LISTENER
HorizontalAlign(int jlabelAlignment)
DefaultCellModel setPopupMenuRetriever(Supplier< List< MenuItem >> menuItemSupplier)
DefaultCellModel setHorizontalAlignment(HorizontalAlign alignment)
List< MenuItem > getPopupMenu()
static final Border DEFAULT_BORDER
HorizontalAlign horizontalAlignment
static final int DEFAULT_ALIGNMENT
List< MenuItem > getPopupMenu()
DefaultCellModel setInsets(Insets insets)
Supplier< List< MenuItem > > menuItemSupplier
final int jlabelAlignment
MouseEvent getMouseEvent()
DefaultCellModel setPopupMenu(List< MenuItem > popupMenu)
static final long serialVersionUID
static CellMouseListener getMouseListener()
HorizontalAlign getHorizontalAlignment()
Component getTableCellRendererComponent(JLabel defaultCell, CellModel cellModel)
DefaultCellModel(String text)
DefaultCellModel setTooltip(String tooltip)