19 package org.sleuthkit.autopsy.geolocation;
21 import java.awt.Component;
22 import java.awt.event.MouseAdapter;
23 import java.awt.event.MouseEvent;
24 import javax.swing.JCheckBox;
25 import javax.swing.JList;
26 import javax.swing.ListCellRenderer;
27 import javax.swing.ListSelectionModel;
32 final class CheckBoxJList<T
extends CheckBoxJList.CheckboxListItem> extends JList<T> {
34 private static final long serialVersionUID = 1L;
41 interface CheckboxListItem {
55 void setChecked(
boolean checked);
62 String getDisplayName();
75 private void initalize() {
76 setCellRenderer(
new CellRenderer());
77 addMouseListener(
new MouseAdapter() {
79 public void mousePressed(MouseEvent e) {
80 int index = locationToIndex(e.getPoint());
82 CheckBoxJList.CheckboxListItem element = getModel().getElementAt(index);
83 element.setChecked(!element.isChecked());
88 setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
94 class CellRenderer
extends JCheckBox implements ListCellRenderer<CheckBoxJList.CheckboxListItem> {
96 private static final long serialVersionUID = 1L;
99 public Component getListCellRendererComponent(
100 JList<? extends CheckBoxJList.CheckboxListItem> list, CheckBoxJList.CheckboxListItem value,
int index,
101 boolean isSelected,
boolean cellHasFocus) {
103 setBackground(list.getBackground());
104 setSelected(value.isChecked());
105 setText(value.getDisplayName());
106 setEnabled(list.isEnabled());