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

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.