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 @SuppressWarnings(
"PMD.SingularField")
36 final class CriterionChooser extends javax.swing.JPanel {
38 private DefaultListCellRenderer defaultListCellRenderer =
new DefaultListCellRenderer();
45 CriterionChooser(SortCriterion criterion, List<Node.Property<?>> availableProps, Consumer<CriterionChooser> removeCallback) {
47 propComboBox.setModel(
new DefaultComboBoxModel<>(availableProps.toArray(
new Node.Property<?>[availableProps.size()])));
48 propComboBox.setRenderer(
new ListCellRenderer<Node.Property<?>>() {
50 public Component getListCellRendererComponent(JList<? extends Node.Property<?>> list, Node.Property<?> value, int index, boolean isSelected, boolean cellHasFocus) {
52 return defaultListCellRenderer.getListCellRendererComponent(list, value == null ?
"" : value.getName(), index, isSelected, cellHasFocus);
55 if (criterion != null) {
56 setCriterion(criterion);
58 removeButton.addActionListener(event -> removeCallback.accept(
this));
67 private void setCriterion(SortCriterion criterion) {
68 propComboBox.setSelectedItem(criterion.getProperty());
69 if (criterion.getSortOrder() == SortOrder.DESCENDING) {
70 descendingRadio.setSelected(
true);
72 ascendingRadio.setSelected(
true);
84 SortCriterion getCriterion(
int rank) {
85 return new SortCriterion(
86 (Node.Property<?>) propComboBox.getSelectedItem(),
87 ascendingRadio.isSelected() ? SortOrder.ASCENDING : SortOrder.DESCENDING,
97 @SuppressWarnings(
"unchecked")
99 private
void initComponents() {
101 sortOrderGroup =
new javax.swing.ButtonGroup();
102 propComboBox =
new javax.swing.JComboBox<>();
103 label1 =
new java.awt.Label();
104 removeButton =
new javax.swing.JButton();
105 jSeparator1 =
new javax.swing.JSeparator();
106 jPanel1 =
new javax.swing.JPanel();
107 ascendingRadio =
new javax.swing.JRadioButton();
108 descendingRadio =
new javax.swing.JRadioButton();
110 label1.setText(
"Sort By: ");
112 removeButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/cross-script.png")));
113 org.openide.awt.Mnemonics.setLocalizedText(removeButton,
org.openide.util.NbBundle.getMessage(CriterionChooser.class,
"CriterionChooser.removeButton.text"));
115 sortOrderGroup.add(ascendingRadio);
116 ascendingRadio.setSelected(
true);
117 org.openide.awt.Mnemonics.setLocalizedText(ascendingRadio,
org.openide.util.NbBundle.getMessage(CriterionChooser.class,
"CriterionChooser.ascendingRadio.text"));
119 sortOrderGroup.add(descendingRadio);
120 org.openide.awt.Mnemonics.setLocalizedText(descendingRadio,
org.openide.util.NbBundle.getMessage(CriterionChooser.class,
"CriterionChooser.descendingRadio.text"));
122 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
123 jPanel1.setLayout(jPanel1Layout);
124 jPanel1Layout.setHorizontalGroup(
125 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
126 .addGroup(jPanel1Layout.createSequentialGroup()
128 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129 .addComponent(descendingRadio)
130 .addComponent(ascendingRadio))
133 jPanel1Layout.setVerticalGroup(
134 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135 .addGroup(jPanel1Layout.createSequentialGroup()
137 .addComponent(ascendingRadio)
138 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
139 .addComponent(descendingRadio)
143 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
144 this.setLayout(layout);
145 layout.setHorizontalGroup(
146 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
147 .addGroup(layout.createSequentialGroup()
149 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
150 .addComponent(jSeparator1)
151 .addGroup(layout.createSequentialGroup()
152 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
153 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154 .addComponent(propComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
155 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
156 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
157 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
158 .addComponent(removeButton)))
161 layout.setVerticalGroup(
162 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163 .addGroup(layout.createSequentialGroup()
165 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
166 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
167 .addComponent(propComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
168 .addComponent(removeButton)
169 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
170 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
171 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
177 private javax.swing.JRadioButton ascendingRadio;
178 private javax.swing.JRadioButton descendingRadio;
179 private javax.swing.JPanel jPanel1;
180 private javax.swing.JSeparator jSeparator1;
181 private java.awt.Label label1;
182 private javax.swing.JComboBox<Node.Property<?>> propComboBox;
183 private javax.swing.JButton removeButton;
184 private javax.swing.ButtonGroup sortOrderGroup;