Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CriterionChooser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.corecomponents;
20 
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;
31 
35 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
36 final class CriterionChooser extends javax.swing.JPanel {
37 
38  private DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer();
39 
45  CriterionChooser(SortCriterion criterion, List<Node.Property<?>> availableProps, Consumer<CriterionChooser> removeCallback) {
46  initComponents();
47  propComboBox.setModel(new DefaultComboBoxModel<>(availableProps.toArray(new Node.Property<?>[availableProps.size()])));
48  propComboBox.setRenderer(new ListCellRenderer<Node.Property<?>>() {
49  @Override
50  public Component getListCellRendererComponent(JList<? extends Node.Property<?>> list, Node.Property<?> value, int index, boolean isSelected, boolean cellHasFocus) {
51  //override default renderer to use Property.getName()
52  return defaultListCellRenderer.getListCellRendererComponent(list, value == null ? "" : value.getName(), index, isSelected, cellHasFocus);
53  }
54  });
55  if (criterion != null) {
56  setCriterion(criterion);
57  }
58  removeButton.addActionListener(event -> removeCallback.accept(this));
59  }
60 
67  private void setCriterion(SortCriterion criterion) {
68  propComboBox.setSelectedItem(criterion.getProperty());
69  if (criterion.getSortOrder() == SortOrder.DESCENDING) {
70  descendingRadio.setSelected(true);
71  } else {
72  ascendingRadio.setSelected(true);
73  }
74  }
75 
84  SortCriterion getCriterion(int rank) {
85  return new SortCriterion(
86  (Node.Property<?>) propComboBox.getSelectedItem(),
87  ascendingRadio.isSelected() ? SortOrder.ASCENDING : SortOrder.DESCENDING,
88  rank
89  );
90  }
91 
97  @SuppressWarnings("unchecked")
98  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
99  private void initComponents() {
100 
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();
109 
110  label1.setText("Sort By: ");
111 
112  removeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/cross-script.png"))); // NOI18N
113  org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(CriterionChooser.class, "CriterionChooser.removeButton.text")); // NOI18N
114 
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")); // NOI18N
118 
119  sortOrderGroup.add(descendingRadio);
120  org.openide.awt.Mnemonics.setLocalizedText(descendingRadio, org.openide.util.NbBundle.getMessage(CriterionChooser.class, "CriterionChooser.descendingRadio.text")); // NOI18N
121 
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()
127  .addGap(0, 0, 0)
128  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129  .addComponent(descendingRadio)
130  .addComponent(ascendingRadio))
131  .addGap(0, 0, 0))
132  );
133  jPanel1Layout.setVerticalGroup(
134  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135  .addGroup(jPanel1Layout.createSequentialGroup()
136  .addGap(0, 0, 0)
137  .addComponent(ascendingRadio)
138  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
139  .addComponent(descendingRadio)
140  .addGap(0, 0, 0))
141  );
142 
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()
148  .addContainerGap()
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)))
159  .addContainerGap())
160  );
161  layout.setVerticalGroup(
162  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163  .addGroup(layout.createSequentialGroup()
164  .addContainerGap()
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))
172  );
173  }// </editor-fold>//GEN-END:initComponents
174 
175 
176  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
185  // End of variables declaration//GEN-END:variables
186 
187 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.