19 package org.sleuthkit.autopsy.corecomponents;
21 import java.awt.Component;
22 import java.util.List;
23 import java.util.function.Consumer;
24 import javax.swing.DefaultComboBoxModel;
25 import javax.swing.DefaultListCellRenderer;
26 import javax.swing.JList;
27 import javax.swing.ListCellRenderer;
28 import javax.swing.SortOrder;
29 import org.openide.nodes.Node;
35 final class CriterionChooser
extends javax.swing.JPanel {
37 private DefaultListCellRenderer defaultListCellRenderer =
new DefaultListCellRenderer();
44 CriterionChooser(SortCriterion criterion, List<Node.Property<?>> availableProps, Consumer<CriterionChooser> removeCallback) {
46 propComboBox.setModel(
new DefaultComboBoxModel<>(availableProps.toArray(
new Node.Property<?>[availableProps.size()])));
47 propComboBox.setRenderer(
new ListCellRenderer<Node.Property<?>>() {
49 public Component getListCellRendererComponent(JList<? extends Node.Property<?>> list, Node.Property<?> value, int index, boolean isSelected, boolean cellHasFocus) {
51 return defaultListCellRenderer.getListCellRendererComponent(list, value == null ?
"" : value.getName(), index, isSelected, cellHasFocus);
54 if (criterion != null) {
55 setCriterion(criterion);
57 removeButton.addActionListener(event -> removeCallback.accept(
this));
66 private void setCriterion(SortCriterion criterion) {
67 propComboBox.setSelectedItem(criterion.getProperty());
68 if (criterion.getSortOrder() == SortOrder.DESCENDING) {
69 descendingRadio.setSelected(
true);
71 ascendingRadio.setSelected(
true);
83 SortCriterion getCriterion(
int rank) {
84 return new SortCriterion(
85 (Node.Property<?>) propComboBox.getSelectedItem(),
86 ascendingRadio.isSelected() ? SortOrder.ASCENDING : SortOrder.DESCENDING,
96 @SuppressWarnings(
"unchecked")
98 private
void initComponents() {
100 sortOrderGroup =
new javax.swing.ButtonGroup();
101 propComboBox =
new javax.swing.JComboBox<>();
102 label1 =
new java.awt.Label();
103 removeButton =
new javax.swing.JButton();
104 jSeparator1 =
new javax.swing.JSeparator();
105 jPanel1 =
new javax.swing.JPanel();
106 ascendingRadio =
new javax.swing.JRadioButton();
107 descendingRadio =
new javax.swing.JRadioButton();
109 label1.setText(
"Sort By: ");
111 removeButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/cross-script.png")));
112 org.openide.awt.Mnemonics.setLocalizedText(removeButton,
org.openide.util.NbBundle.getMessage(CriterionChooser.class,
"CriterionChooser.removeButton.text"));
114 sortOrderGroup.add(ascendingRadio);
115 ascendingRadio.setSelected(
true);
116 org.openide.awt.Mnemonics.setLocalizedText(ascendingRadio,
org.openide.util.NbBundle.getMessage(CriterionChooser.class,
"CriterionChooser.ascendingRadio.text"));
118 sortOrderGroup.add(descendingRadio);
119 org.openide.awt.Mnemonics.setLocalizedText(descendingRadio,
org.openide.util.NbBundle.getMessage(CriterionChooser.class,
"CriterionChooser.descendingRadio.text"));
121 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
122 jPanel1.setLayout(jPanel1Layout);
123 jPanel1Layout.setHorizontalGroup(
124 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
125 .addGroup(jPanel1Layout.createSequentialGroup()
127 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128 .addComponent(descendingRadio)
129 .addComponent(ascendingRadio))
132 jPanel1Layout.setVerticalGroup(
133 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134 .addGroup(jPanel1Layout.createSequentialGroup()
136 .addComponent(ascendingRadio)
137 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
138 .addComponent(descendingRadio)
142 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
143 this.setLayout(layout);
144 layout.setHorizontalGroup(
145 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146 .addGroup(layout.createSequentialGroup()
148 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
149 .addComponent(jSeparator1)
150 .addGroup(layout.createSequentialGroup()
151 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
153 .addComponent(propComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
154 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
155 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
156 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
157 .addComponent(removeButton)))
160 layout.setVerticalGroup(
161 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162 .addGroup(layout.createSequentialGroup()
164 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
165 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
166 .addComponent(propComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
167 .addComponent(removeButton)
168 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
169 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
170 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
176 private javax.swing.JRadioButton ascendingRadio;
177 private javax.swing.JRadioButton descendingRadio;
178 private javax.swing.JPanel jPanel1;
179 private javax.swing.JSeparator jSeparator1;
180 private java.awt.Label label1;
181 private javax.swing.JComboBox<Node.Property<?>> propComboBox;
182 private javax.swing.JButton removeButton;
183 private javax.swing.ButtonGroup sortOrderGroup;