Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
SortChooser.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.corecomponents;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.openide.nodes.Node;
24 import org.openide.util.NbBundle;
27 
32 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
33 final class SortChooser extends javax.swing.JPanel {
34 
38  private final List<Node.Property<?>> availableProps;
39 
44  private final ArrayList<CriterionChooser> choosers = new ArrayList<>();
45 
52  SortChooser(List<Node.Property<?>> availableProps, List<SortCriterion> criteria) {
53  super();
54  initComponents();
55 
56  this.availableProps = availableProps;
57  criteria.forEach(this::addCriterionChooser);
58  }
59 
65  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
66  List<SortCriterion> getCriteria() {
67  List<SortCriterion> list = new ArrayList<>();
68  for (int i = 0; i < choosers.size(); i++) {
69  list.add(choosers.get(i).getCriterion(i));
70  }
71  return list;
72  }
73 
74  @NbBundle.Messages({"SortChooser.dialogTitle=Choose Sort Criteria"})
75  String getDialogTitle() {
76  return Bundle.SortChooser_dialogTitle();
77  }
78 
84  @SuppressWarnings("unchecked")
85  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
86  private void initComponents() {
87 
88  jScrollPane1 = new javax.swing.JScrollPane();
89  scrollContent = new javax.swing.JPanel();
90  addCriteriaButton = new javax.swing.JButton();
91 
92  scrollContent.setLayout(new javax.swing.BoxLayout(scrollContent, javax.swing.BoxLayout.Y_AXIS));
93  jScrollPane1.setViewportView(scrollContent);
94 
95  org.openide.awt.Mnemonics.setLocalizedText(addCriteriaButton, org.openide.util.NbBundle.getMessage(SortChooser.class, "SortChooser.addCriteriaButton.text")); // NOI18N
96  addCriteriaButton.addActionListener(new java.awt.event.ActionListener() {
97  public void actionPerformed(java.awt.event.ActionEvent evt) {
98  addCriteriaButtonActionPerformed(evt);
99  }
100  });
101 
102  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
103  this.setLayout(layout);
104  layout.setHorizontalGroup(
105  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
106  .addGroup(layout.createSequentialGroup()
107  .addContainerGap()
108  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
109  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
110  .addGroup(layout.createSequentialGroup()
111  .addComponent(addCriteriaButton)
112  .addGap(0, 0, Short.MAX_VALUE)))
113  .addContainerGap())
114  );
115  layout.setVerticalGroup(
116  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117  .addGroup(layout.createSequentialGroup()
118  .addContainerGap()
119  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
120  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
121  .addComponent(addCriteriaButton)
122  .addContainerGap())
123  );
124  }// </editor-fold>//GEN-END:initComponents
125 
126 
127  private void addCriteriaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addCriteriaButtonActionPerformed
128  addCriterionChooser(null);
129 
130  }//GEN-LAST:event_addCriteriaButtonActionPerformed
131 
138  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
139  private void addCriterionChooser(SortCriterion criterion) {
140  final CriterionChooser chooser = new CriterionChooser(criterion, availableProps, this::removeCriterionChooser);
141  choosers.add(chooser); // keep a reference
142  scrollContent.add(chooser); // add to GUI
143  revalidate(); //needed to force repaint.
144  }
145 
151  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
152  private void removeCriterionChooser(CriterionChooser chooser) {
153  choosers.remove(chooser); //remove from internal list
154  scrollContent.remove(chooser);// remove from GUI
155  revalidate(); //repaint
156  repaint();
157  }
158 
159 
160  // Variables declaration - do not modify//GEN-BEGIN:variables
161  private javax.swing.JButton addCriteriaButton;
162  private javax.swing.JScrollPane jScrollPane1;
163  private javax.swing.JPanel scrollContent;
164  // End of variables declaration//GEN-END:variables
165 
166 }

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.