Autopsy  4.13.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CheckBoxJList.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.geolocation;
20 
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;
28 
32 final class CheckBoxJList<T extends CheckBoxJList.CheckboxListItem> extends JList<T> {
33 
34  private static final long serialVersionUID = 1L;
35 
41  interface CheckboxListItem {
42 
48  boolean isChecked();
49 
55  void setChecked(boolean checked);
56 
62  String getDisplayName();
63  }
64 
68  CheckBoxJList() {
69  initalize();
70  }
71 
75  private void initalize() {
76  setCellRenderer(new CellRenderer());
77  addMouseListener(new MouseAdapter() {
78  @Override
79  public void mousePressed(MouseEvent e) {
80  int index = locationToIndex(e.getPoint());
81  if (index != -1) {
82  CheckBoxJList.CheckboxListItem element = getModel().getElementAt(index);
83  element.setChecked(!element.isChecked());
84  repaint();
85  }
86  }
87  });
88  setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
89  }
90 
94  class CellRenderer extends JCheckBox implements ListCellRenderer<CheckBoxJList.CheckboxListItem> {
95 
96  private static final long serialVersionUID = 1L;
97 
98  @Override
99  public Component getListCellRendererComponent(
100  JList<? extends CheckBoxJList.CheckboxListItem> list, CheckBoxJList.CheckboxListItem value, int index,
101  boolean isSelected, boolean cellHasFocus) {
102 
103  setBackground(list.getBackground());
104  setSelected(value.isChecked());
105  setText(value.getDisplayName());
106  setEnabled(list.isEnabled());
107  return this;
108  }
109  }
110 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.