Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
GlobalListSettingsPanel.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.keywordsearch;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.beans.PropertyChangeListener;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.swing.JOptionPane;
27 import org.openide.util.NbBundle;
29 
33 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
34 final class GlobalListSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
35 
36  private static final long serialVersionUID = 1L;
37 
38  private final GlobalListsManagementPanel listsManagementPanel = new GlobalListsManagementPanel(this);
39  private final GlobalEditListPanel editListPanel = new GlobalEditListPanel();
40 
41  GlobalListSettingsPanel() {
42  initComponents();
43  customizeComponents();
44  setName(org.openide.util.NbBundle.getMessage(DropdownToolbar.class, "ListBundleConfig"));
45  }
46 
47  private void customizeComponents() {
48  listsManagementPanel.addListSelectionListener(editListPanel);
49  listsManagementPanel.addDeleteButtonActionPerformed(new ActionListener() {
50  @Override
51  public void actionPerformed(ActionEvent e) {
52  if (KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.title"), NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.body"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
53  deleteAction();
54  listsManagementPanel.resync();
55  }
56  }
57  });
58 
59  listsManagementPanel.addRenameButtonActionPerformed(new ActionListener() {
60  @Override
61  public void actionPerformed(ActionEvent e) {
62  if (copyAction()) {
63  deleteAction();
64  listsManagementPanel.resync();
65  }
66  }
67  });
68 
69  listsManagementPanel.addCopyButtonActionPerformed(new ActionListener() {
70  @Override
71  public void actionPerformed(ActionEvent e) {
72  copyAction();
73  listsManagementPanel.resync();
74  }
75  });
76 
77  mainSplitPane.setLeftComponent(listsManagementPanel);
78  mainSplitPane.setRightComponent(editListPanel);
79  mainSplitPane.revalidate();
80  mainSplitPane.repaint();
81  }
82 
88  private void deleteAction() {
89  listsManagementPanel.deleteSelected();
90  editListPanel.setCurrentKeywordList(null);
91  editListPanel.setButtonStates();
92  listsManagementPanel.setButtonStates();
93  }
94 
101  private boolean copyAction() {
102  final String FEATURE_NAME = NbBundle.getMessage(this.getClass(),
103  "KeywordSearchGlobalListSettingsPanel.component.featureName.text");
104  KeywordList currentKeywordList = editListPanel.getCurrentKeywordList();
105 
106  List<Keyword> keywords = new ArrayList<>();
107  keywords.addAll(currentKeywordList.getKeywords());
108 
109  String listName = (String) JOptionPane.showInputDialog(
110  this,
111  NbBundle.getMessage(this.getClass(), "KeywordSearch.newKwListTitle"),
112  FEATURE_NAME,
113  JOptionPane.PLAIN_MESSAGE,
114  null,
115  null,
116  currentKeywordList.getName());
117 
118  if (listName == null) {
119  return false;
120  }
121  //remove trailing and leading spaces so lists can't have visually identical names
122  listName = listName.trim();
123  //if the name is empty or unchanged return without changing anything
124  if (listName.equals("") || listName.equals(currentKeywordList.getName())) {
125  return false;
126  }
127  XmlKeywordSearchList writer = XmlKeywordSearchList.getCurrent();
128  if (writer.listExists(listName) && writer.getList(listName).isEditable()) {
129  KeywordSearchUtil.displayDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.noOwDefaultMsg"), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
130  return false;
131  }
132  if (writer.listExists(listName)) {
133  if (!KeywordSearchUtil.displayConfirmDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.kwListExistMsg", listName),
134  KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
135  return false;
136  }
137  }
138  writer.addList(listName, keywords);
139  KeywordSearchUtil.displayDialog(FEATURE_NAME, NbBundle.getMessage(this.getClass(), "KeywordSearchConfigurationPanel1.customizeComponents.kwListSavedMsg", listName), KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
140  return true;
141  }
142 
143  @Override
144  public void addPropertyChangeListener(PropertyChangeListener l) {
145  super.addPropertyChangeListener(l);
146  /*
147  * There is at least one look and feel library that follows the bad
148  * practice of calling overrideable methods in a constructor, e.g.:
149  *
150  * at
151  * javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:83)
152  * at
153  * javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:63)
154  * at javax.swing.JComponent.setUI(JComponent.java:666) at
155  * javax.swing.JPanel.setUI(JPanel.java:153) at
156  * javax.swing.JPanel.updateUI(JPanel.java:126) at
157  * javax.swing.JPanel.<init>(JPanel.java:86) at
158  * javax.swing.JPanel.<init>(JPanel.java:109) at
159  * javax.swing.JPanel.<init>(JPanel.java:117)
160  *
161  * When this happens, the following child components of this JPanel
162  * subclass have not been constructed yet, since this panel's
163  * constructor has not been called yet.
164  */
165  if (null != listsManagementPanel) {
166  listsManagementPanel.addPropertyChangeListener(l);
167  }
168  if (null != editListPanel) {
169  editListPanel.addPropertyChangeListener(l);
170  }
171  }
172 
173  @Override
174  public void removePropertyChangeListener(PropertyChangeListener l) {
175  super.removePropertyChangeListener(l);
176  listsManagementPanel.removePropertyChangeListener(l);
177  editListPanel.removePropertyChangeListener(l);
178  }
179 
180  @Override
181  public void store() {
182  XmlKeywordSearchList.getCurrent().save(false);
183  //refresh the list viewer/searcher panel
184  DropdownListSearchPanel.getDefault().resync();
185  }
186 
187  @Override
188  public void load() {
189  listsManagementPanel.load();
190  }
191 
195  void setFocusOnKeywordTextBox() {
196  editListPanel.setFocusOnKeywordTextBox();
197  }
198 
204  @SuppressWarnings("unchecked")
205  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
206  private void initComponents() {
207 
208  jScrollPane1 = new javax.swing.JScrollPane();
209  mainSplitPane = new javax.swing.JSplitPane();
210  leftPanel = new javax.swing.JPanel();
211  rightPanel = new javax.swing.JPanel();
212 
213  mainSplitPane.setBorder(null);
214  mainSplitPane.setDividerSize(1);
215 
216  leftPanel.setPreferredSize(new java.awt.Dimension(309, 327));
217  leftPanel.setVerifyInputWhenFocusTarget(false);
218 
219  javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
220  leftPanel.setLayout(leftPanelLayout);
221  leftPanelLayout.setHorizontalGroup(
222  leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
223  .addGap(0, 309, Short.MAX_VALUE)
224  );
225  leftPanelLayout.setVerticalGroup(
226  leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
227  .addGap(0, 327, Short.MAX_VALUE)
228  );
229 
230  mainSplitPane.setLeftComponent(leftPanel);
231 
232  rightPanel.setPreferredSize(new java.awt.Dimension(360, 327));
233 
234  javax.swing.GroupLayout rightPanelLayout = new javax.swing.GroupLayout(rightPanel);
235  rightPanel.setLayout(rightPanelLayout);
236  rightPanelLayout.setHorizontalGroup(
237  rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
238  .addGap(0, 362, Short.MAX_VALUE)
239  );
240  rightPanelLayout.setVerticalGroup(
241  rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242  .addGap(0, 327, Short.MAX_VALUE)
243  );
244 
245  mainSplitPane.setRightComponent(rightPanel);
246 
247  jScrollPane1.setViewportView(mainSplitPane);
248 
249  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
250  this.setLayout(layout);
251  layout.setHorizontalGroup(
252  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253  .addGroup(layout.createSequentialGroup()
254  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE)
255  .addGap(0, 0, 0))
256  );
257  layout.setVerticalGroup(
258  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addGroup(layout.createSequentialGroup()
260  .addComponent(jScrollPane1)
261  .addGap(0, 0, 0))
262  );
263  }// </editor-fold>//GEN-END:initComponents
264  // Variables declaration - do not modify//GEN-BEGIN:variables
265  private javax.swing.JScrollPane jScrollPane1;
266  private javax.swing.JPanel leftPanel;
267  private javax.swing.JSplitPane mainSplitPane;
268  private javax.swing.JPanel rightPanel;
269  // End of variables declaration//GEN-END:variables
270 }

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