Autopsy  4.6.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-17 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 final class CriterionChooser extends javax.swing.JPanel {
36 
37  private DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer();
38 
44  CriterionChooser(SortCriterion criterion, List<Node.Property<?>> availableProps, Consumer<CriterionChooser> removeCallback) {
45  initComponents();
46  propComboBox.setModel(new DefaultComboBoxModel<>(availableProps.toArray(new Node.Property<?>[availableProps.size()])));
47  propComboBox.setRenderer(new ListCellRenderer<Node.Property<?>>() {
48  @Override
49  public Component getListCellRendererComponent(JList<? extends Node.Property<?>> list, Node.Property<?> value, int index, boolean isSelected, boolean cellHasFocus) {
50  //override default renderer to use Property.getName()
51  return defaultListCellRenderer.getListCellRendererComponent(list, value == null ? "" : value.getName(), index, isSelected, cellHasFocus);
52  }
53  });
54  if (criterion != null) {
55  setCriterion(criterion);
56  }
57  removeButton.addActionListener(event -> removeCallback.accept(this));
58  }
59 
66  private void setCriterion(SortCriterion criterion) {
67  propComboBox.setSelectedItem(criterion.getProperty());
68  if (criterion.getSortOrder() == SortOrder.DESCENDING) {
69  descendingRadio.setSelected(true);
70  } else {
71  ascendingRadio.setSelected(true);
72  }
73  }
74 
83  SortCriterion getCriterion(int rank) {
84  return new SortCriterion(
85  (Node.Property<?>) propComboBox.getSelectedItem(),
86  ascendingRadio.isSelected() ? SortOrder.ASCENDING : SortOrder.DESCENDING,
87  rank
88  );
89  }
90 
96  @SuppressWarnings("unchecked")
97  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
98  private void initComponents() {
99 
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();
108 
109  label1.setText("Sort By: ");
110 
111  removeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/cross-script.png"))); // NOI18N
112  org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(CriterionChooser.class, "CriterionChooser.removeButton.text")); // NOI18N
113 
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")); // NOI18N
117 
118  sortOrderGroup.add(descendingRadio);
119  org.openide.awt.Mnemonics.setLocalizedText(descendingRadio, org.openide.util.NbBundle.getMessage(CriterionChooser.class, "CriterionChooser.descendingRadio.text")); // NOI18N
120 
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()
126  .addGap(0, 0, 0)
127  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128  .addComponent(descendingRadio)
129  .addComponent(ascendingRadio))
130  .addGap(0, 0, 0))
131  );
132  jPanel1Layout.setVerticalGroup(
133  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134  .addGroup(jPanel1Layout.createSequentialGroup()
135  .addGap(0, 0, 0)
136  .addComponent(ascendingRadio)
137  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
138  .addComponent(descendingRadio)
139  .addGap(0, 0, 0))
140  );
141 
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()
147  .addContainerGap()
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)))
158  .addContainerGap())
159  );
160  layout.setVerticalGroup(
161  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addGroup(layout.createSequentialGroup()
163  .addContainerGap()
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))
171  );
172  }// </editor-fold>//GEN-END:initComponents
173 
174 
175  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
184  // End of variables declaration//GEN-END:variables
185 
186 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.