Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileExtMismatchSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.modules.fileextmismatch;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import javax.swing.JOptionPane;
28 import javax.swing.ListSelectionModel;
29 import javax.swing.event.ListSelectionEvent;
30 import javax.swing.event.ListSelectionListener;
31 import javax.swing.table.AbstractTableModel;
32 import org.netbeans.spi.options.OptionsPanelController;
33 import org.openide.util.NbBundle;
38 
43 final class FileExtMismatchSettingsPanel extends IngestModuleGlobalSettingsPanel implements OptionsPanel {
44 
45  private static final Logger logger = Logger.getLogger(FileExtMismatchSettingsPanel.class.getName());
46  private HashMap<String, Set<String>> editableMap = new HashMap<>();
47  private ArrayList<String> mimeList = null;
48  private ArrayList<String> currentExtensions = null;
49  private MimeTableModel mimeTableModel;
50  private ExtTableModel extTableModel;
51  private final String EXT_HEADER_LABEL = NbBundle.getMessage(FileExtMismatchSettingsPanel.class,
52  "AddFileExtensionAction.extHeaderLbl.text");
53  private String selectedMime = "";
54  private String selectedExt = "";
55  ListSelectionModel lsm = null;
56  private FileTypeDetector fileTypeDetector;
57 
58  public FileExtMismatchSettingsPanel() {
59  mimeTableModel = new MimeTableModel();
60  extTableModel = new ExtTableModel();
61 
62  try {
63  fileTypeDetector = new FileTypeDetector();
64  } catch (FileTypeDetector.FileTypeDetectorInitException ex) {
65  logger.log(Level.SEVERE, "Failed to create file type detector", ex); //NON-NLS
66  fileTypeDetector = null;
67  }
68 
69  initComponents();
70  customizeComponents();
71  }
72 
73  @NbBundle.Messages({"FileExtMismatchSettingsPanel.Title=Global File Extension Mismatch Identification Settings"})
74  private void customizeComponents() {
75  setName(Bundle.FileExtMismatchSettingsPanel_Title());
76 
77  // Handle selections on the left table
78  lsm = mimeTable.getSelectionModel();
79  lsm.addListSelectionListener(new ListSelectionListener() {
80  @Override
81  public void valueChanged(ListSelectionEvent e) {
82  ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
83  if (!listSelectionModel.isSelectionEmpty()) {
84  int index = listSelectionModel.getMinSelectionIndex();
85  listSelectionModel.setSelectionInterval(index, index);
86 
87  selectedMime = mimeList.get(index);
88  String labelStr = EXT_HEADER_LABEL + selectedMime + ":";
89  if (labelStr.length() > 80) {
90  labelStr = labelStr.substring(0, 80);
91  }
92  extHeaderLabel.setText(labelStr);
93  updateExtList();
94 
95  extTableModel.resync();
96  removeTypeButton.setEnabled(true);
97  newExtButton.setEnabled(true);
98  //initButtons();
99  } else {
100  selectedMime = "";
101  currentExtensions = null;
102  removeTypeButton.setEnabled(false);
103  newExtButton.setEnabled(false);
104  extTableModel.resync();
105  }
106  }
107  });
108 
109  // Handle selections on the right table
110  ListSelectionModel extLsm = extTable.getSelectionModel();
111  extLsm.addListSelectionListener(new ListSelectionListener() {
112  @Override
113  public void valueChanged(ListSelectionEvent e) {
114  ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
115  if (!listSelectionModel.isSelectionEmpty()) {
116  int index = listSelectionModel.getMinSelectionIndex();
117  listSelectionModel.setSelectionInterval(index, index);
118 
119  selectedExt = currentExtensions.get(index);
120  removeExtButton.setEnabled(true);
121  } else {
122  selectedExt = "";
123  removeExtButton.setEnabled(false);
124  }
125 
126  }
127  });
128  removeExtButton.setEnabled(false);
129  removeTypeButton.setEnabled(false);
130  newExtButton.setEnabled(false);
131  }
132 
138  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
139  private void initComponents() {
140 
141  jPanel1 = new javax.swing.JPanel();
142  jScrollPane1 = new javax.swing.JScrollPane();
143  jSplitPane1 = new javax.swing.JSplitPane();
144  mimePanel = new javax.swing.JPanel();
145  jLabel1 = new javax.swing.JLabel();
146  jScrollPane2 = new javax.swing.JScrollPane();
147  mimeTable = new javax.swing.JTable();
148  newTypeButton = new javax.swing.JButton();
149  removeTypeButton = new javax.swing.JButton();
150  extensionPanel = new javax.swing.JPanel();
151  newExtButton = new javax.swing.JButton();
152  jScrollPane3 = new javax.swing.JScrollPane();
153  extTable = new javax.swing.JTable();
154  removeExtButton = new javax.swing.JButton();
155  extHeaderLabel = new javax.swing.JLabel();
156 
157  jPanel1.setPreferredSize(new java.awt.Dimension(687, 450));
158 
159  jSplitPane1.setDividerLocation(430);
160  jSplitPane1.setDividerSize(1);
161 
162  jLabel1.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.jLabel1.text")); // NOI18N
163 
164  mimeTable.setModel(mimeTableModel);
165  jScrollPane2.setViewportView(mimeTable);
166 
167  newTypeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/add16.png"))); // NOI18N
168  newTypeButton.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newTypeButton.text")); // NOI18N
169  newTypeButton.addActionListener(new java.awt.event.ActionListener() {
170  public void actionPerformed(java.awt.event.ActionEvent evt) {
171  newTypeButtonActionPerformed(evt);
172  }
173  });
174 
175  removeTypeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/delete16.png"))); // NOI18N
176  removeTypeButton.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeTypeButton.text")); // NOI18N
177  removeTypeButton.setToolTipText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeTypeButton.toolTipText")); // NOI18N
178  removeTypeButton.addActionListener(new java.awt.event.ActionListener() {
179  public void actionPerformed(java.awt.event.ActionEvent evt) {
180  removeTypeButtonActionPerformed(evt);
181  }
182  });
183 
184  javax.swing.GroupLayout mimePanelLayout = new javax.swing.GroupLayout(mimePanel);
185  mimePanel.setLayout(mimePanelLayout);
186  mimePanelLayout.setHorizontalGroup(
187  mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188  .addGroup(mimePanelLayout.createSequentialGroup()
189  .addContainerGap()
190  .addGroup(mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
192  .addGroup(mimePanelLayout.createSequentialGroup()
193  .addGroup(mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194  .addComponent(jLabel1)
195  .addGroup(mimePanelLayout.createSequentialGroup()
196  .addComponent(newTypeButton)
197  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198  .addComponent(removeTypeButton)))
199  .addGap(0, 191, Short.MAX_VALUE)))
200  .addContainerGap())
201  );
202  mimePanelLayout.setVerticalGroup(
203  mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addGroup(mimePanelLayout.createSequentialGroup()
205  .addContainerGap()
206  .addComponent(jLabel1)
207  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
208  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
209  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
210  .addGroup(mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
211  .addComponent(newTypeButton)
212  .addComponent(removeTypeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
213  .addContainerGap())
214  );
215 
216  jSplitPane1.setLeftComponent(mimePanel);
217 
218  newExtButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/add16.png"))); // NOI18N
219  newExtButton.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtButton.text")); // NOI18N
220  newExtButton.addActionListener(new java.awt.event.ActionListener() {
221  public void actionPerformed(java.awt.event.ActionEvent evt) {
222  newExtButtonActionPerformed(evt);
223  }
224  });
225 
226  extTable.setModel(extTableModel);
227  jScrollPane3.setViewportView(extTable);
228 
229  removeExtButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/delete16.png"))); // NOI18N
230  removeExtButton.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeExtButton.text")); // NOI18N
231  removeExtButton.addActionListener(new java.awt.event.ActionListener() {
232  public void actionPerformed(java.awt.event.ActionEvent evt) {
233  removeExtButtonActionPerformed(evt);
234  }
235  });
236 
237  extHeaderLabel.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.extHeaderLabel.text")); // NOI18N
238 
239  javax.swing.GroupLayout extensionPanelLayout = new javax.swing.GroupLayout(extensionPanel);
240  extensionPanel.setLayout(extensionPanelLayout);
241  extensionPanelLayout.setHorizontalGroup(
242  extensionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243  .addGroup(extensionPanelLayout.createSequentialGroup()
244  .addContainerGap()
245  .addGroup(extensionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246  .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
247  .addGroup(extensionPanelLayout.createSequentialGroup()
248  .addGroup(extensionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249  .addComponent(extHeaderLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
250  .addGroup(extensionPanelLayout.createSequentialGroup()
251  .addComponent(newExtButton)
252  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
253  .addComponent(removeExtButton)))
254  .addGap(0, 0, Short.MAX_VALUE)))
255  .addContainerGap())
256  );
257  extensionPanelLayout.setVerticalGroup(
258  extensionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, extensionPanelLayout.createSequentialGroup()
260  .addContainerGap()
261  .addComponent(extHeaderLabel)
262  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
263  .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
264  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
265  .addGroup(extensionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
266  .addComponent(newExtButton)
267  .addComponent(removeExtButton))
268  .addContainerGap())
269  );
270 
271  jSplitPane1.setRightComponent(extensionPanel);
272 
273  jScrollPane1.setViewportView(jSplitPane1);
274 
275  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
276  jPanel1.setLayout(jPanel1Layout);
277  jPanel1Layout.setHorizontalGroup(
278  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279  .addGroup(jPanel1Layout.createSequentialGroup()
280  .addContainerGap()
281  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE)
282  .addContainerGap())
283  );
284  jPanel1Layout.setVerticalGroup(
285  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
286  .addGroup(jPanel1Layout.createSequentialGroup()
287  .addContainerGap()
288  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
289  .addContainerGap())
290  );
291 
292  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
293  this.setLayout(layout);
294  layout.setHorizontalGroup(
295  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
296  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE)
297  );
298  layout.setVerticalGroup(
299  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
300  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
301  );
302  }// </editor-fold>//GEN-END:initComponents
303 
304  // Add a user-provided filename extension string to the selecte mimetype
305  private void newExtButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newExtButtonActionPerformed
306  String newExt = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.message"),
307  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.title"), JOptionPane.PLAIN_MESSAGE, null, null, "");
308 
309  if (newExt == null) {
310  return;
311  }
312  if (newExt.isEmpty()) {
313  JOptionPane.showMessageDialog(null,
314  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.empty.message"),
315  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.empty.title"),
316  JOptionPane.ERROR_MESSAGE);
317  return;
318  }
319  if (selectedMime.isEmpty()) {
320  JOptionPane.showMessageDialog(null,
321  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.noMimeType.message"),
322  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.noMimeType.title"),
323  JOptionPane.ERROR_MESSAGE);
324  return;
325  }
326  if (currentExtensions.contains(newExt)) {
327  JOptionPane.showMessageDialog(null,
328  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.extExists.message"),
329  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newExtPrompt.extExists.title"),
330  JOptionPane.ERROR_MESSAGE);
331  return;
332  }
333 
334  Set<String> editedExtensions = editableMap.get(selectedMime);
335  editedExtensions.add(newExt);
336 
337  // Old array will be replaced by new array for this key
338  editableMap.put(selectedMime, editedExtensions);
339 
340  // Refresh table
341  updateExtList();
342  extTableModel.resync();
343  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
344  }//GEN-LAST:event_newExtButtonActionPerformed
345 
346  private void removeExtButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeExtButtonActionPerformed
347  if (selectedExt.isEmpty()) {
348  JOptionPane.showMessageDialog(null,
349  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeExtButton.noneSelected.message"),
350  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeExtButton.noneSelected.title"),
351  JOptionPane.ERROR_MESSAGE);
352  return;
353  }
354 
355  if (selectedMime.isEmpty()) {
356  JOptionPane.showMessageDialog(null,
357  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeExtButton.noMimeTypeSelected.message"),
358  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeExtButton.noMimeTypeSelected.title"),
359  JOptionPane.ERROR_MESSAGE);
360  return;
361  }
362 
363  Set<String> editedExtensions = editableMap.get(selectedMime);
364  editedExtensions.remove(selectedExt);
365  String deadExt = selectedExt;
366 
367  // Old array will be replaced by new array for this key
368  editableMap.put(selectedMime, editedExtensions);
369 
370  // Refresh tables
371  updateExtList();
372  extTableModel.resync();
373  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
374  }//GEN-LAST:event_removeExtButtonActionPerformed
375 
376  private void removeTypeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTypeButtonActionPerformed
377  if (selectedMime.isEmpty()) {
378  JOptionPane.showMessageDialog(null,
379  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeTypeButton.noneSelected.message"),
380  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.removeTypeButton.noneSelected.title"),
381  JOptionPane.ERROR_MESSAGE);
382  return;
383  }
384 
385  editableMap.remove(selectedMime);
386 
387  // Refresh table
388  updateMimeList();
389  mimeTableModel.resync();
390  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
391  }//GEN-LAST:event_removeTypeButtonActionPerformed
392 
393  private void newTypeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newTypeButtonActionPerformed
394  String newMime = (String) JOptionPane.showInputDialog(null, NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.message"),
395  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.title"), JOptionPane.PLAIN_MESSAGE, null, null, "");
396 
397  if (newMime == null) {
398  return;
399  }
400  if (newMime.isEmpty()) {
401  JOptionPane.showMessageDialog(null,
402  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.emptyMime.message"),
403  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.emptyMime.title"),
404  JOptionPane.ERROR_MESSAGE);
405  return;
406  }
407  if (newMime.equals("application/octet-stream")) { //NON-NLS
408  JOptionPane.showMessageDialog(null,
409  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.mimeTypeNotSupported.message"),
410  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.mimeTypeNotSupported.title"),
411  JOptionPane.ERROR_MESSAGE);
412  return;
413  }
414  if (mimeList.contains(newMime)) {
415  JOptionPane.showMessageDialog(null,
416  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.mimeTypeExists.message"),
417  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.mimeTypeExists.title"),
418  JOptionPane.ERROR_MESSAGE);
419  return;
420  }
421 
422  FileTypeDetector detector;
423  try {
424  detector = new FileTypeDetector();
425  } catch (FileTypeDetector.FileTypeDetectorInitException ex) {
426  logger.log(Level.WARNING, "Couldn't create file type detector for file ext mismatch settings.", ex);
427  return;
428  }
429  boolean mimeTypeDetectable = (null != detector) ? detector.isDetectable(newMime) : false;
430  if (!mimeTypeDetectable) {
431  JOptionPane.showMessageDialog(null,
432  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.mimeTypeNotDetectable.message"),
433  NbBundle.getMessage(FileExtMismatchSettingsPanel.class, "FileExtMismatchSettingsPanel.newMimePrompt.mimeTypeNotDetectable.title"),
434  JOptionPane.ERROR_MESSAGE);
435  return;
436  }
437 
438  editableMap.put(newMime, new HashSet<String>());
439 
440  // Refresh table
441  updateMimeList();
442  mimeTableModel.resync();
443  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
444  }//GEN-LAST:event_newTypeButtonActionPerformed
445 
446  private void updateMimeList() {
447  mimeList = new ArrayList<>(editableMap.keySet());
448  if (mimeList.size() > 0) {
449  Collections.sort(mimeList);
450  }
451  }
452 
453  private void updateExtList() {
454  Set<String> temp = editableMap.get(selectedMime);
455  if (temp != null) {
456  currentExtensions = new ArrayList<>(temp);
457  if (temp.size() > 0) {
458  Collections.sort(currentExtensions);
459  }
460  } else {
461  currentExtensions = null;
462  }
463  }
464 
465  @Override
466  public void saveSettings() {
467  try {
468  FileExtMismatchSettings.writeSettings(new FileExtMismatchSettings(editableMap));
469  } catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
470  //error
471  JOptionPane.showMessageDialog(this,
472  NbBundle.getMessage(this.getClass(),
473  "FileExtMismatchConfigPanel.store.msgDlg.msg"),
474  NbBundle.getMessage(this.getClass(),
475  "FileExtMismatchConfigPanel.save.msgDlg.title"),
476  JOptionPane.ERROR_MESSAGE);
477  }
478  }
479 
480  @Override
481  public void load() {
482  try {
483  // Load the configuration into a buffer that the user can modify. They can choose
484  // to save it back to the file after making changes.
485  editableMap = FileExtMismatchSettings.readSettings().getMimeTypeToExtsMap();
486 
487  } catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
488  //error
489  JOptionPane.showMessageDialog(this,
490  NbBundle.getMessage(this.getClass(),
491  "AddFileExtensionAction.msgDlg.msg2"),
492  NbBundle.getMessage(this.getClass(),
493  "FileExtMismatchConfigPanel.save.msgDlg.title"),
494  JOptionPane.ERROR_MESSAGE);
495  }
496  updateMimeList();
497  updateExtList();
498  }
499 
500  @Override
501  public void store() {
502  saveSettings();
503  }
504 
505  public void cancel() {
506  load(); // The next time this panel is opened, we want it to be fresh
507  }
508 
509  public void ok() {
510  store();
511  load(); // The next time this panel is opened, we want it to be fresh
512  }
513 
514  boolean valid() {
515  return true;
516  }
517  // Variables declaration - do not modify//GEN-BEGIN:variables
518  private javax.swing.JLabel extHeaderLabel;
519  private javax.swing.JTable extTable;
520  private javax.swing.JPanel extensionPanel;
521  private javax.swing.JLabel jLabel1;
522  private javax.swing.JPanel jPanel1;
523  private javax.swing.JScrollPane jScrollPane1;
524  private javax.swing.JScrollPane jScrollPane2;
525  private javax.swing.JScrollPane jScrollPane3;
526  private javax.swing.JSplitPane jSplitPane1;
527  private javax.swing.JPanel mimePanel;
528  private javax.swing.JTable mimeTable;
529  private javax.swing.JButton newExtButton;
530  private javax.swing.JButton newTypeButton;
531  private javax.swing.JButton removeExtButton;
532  private javax.swing.JButton removeTypeButton;
533  // End of variables declaration//GEN-END:variables
534 
535  private class MimeTableModel extends AbstractTableModel {
536 
537  @Override
538  public int getColumnCount() {
539  return 1;
540  }
541 
542  @Override
543  public int getRowCount() {
544  return editableMap == null ? 0 : editableMap.size();
545  }
546 
547  @Override
548  public String getColumnName(int column) {
549  String colName = null;
550  return colName;
551  }
552 
553  @Override
554  public Object getValueAt(int rowIndex, int columnIndex) {
555  Object ret = null;
556  if ((mimeList == null) || (rowIndex > mimeList.size())) {
557  return "";
558  }
559  String word = mimeList.get(rowIndex);
560  switch (columnIndex) {
561  case 0:
562  ret = (Object) word;
563  break;
564  default:
565  logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
566  break;
567  }
568  return ret;
569  }
570 
571  @Override
572  public boolean isCellEditable(int rowIndex, int columnIndex) {
573  return false;
574  }
575 
576  @Override
577  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
578  }
579 
580  @Override
581  public Class<?> getColumnClass(int c) {
582  return getValueAt(0, c).getClass();
583  }
584 
585  void resync() {
586  fireTableDataChanged();
587  }
588  }
589 
590  private class ExtTableModel extends AbstractTableModel {
591 
592  @Override
593  public int getColumnCount() {
594  return 1;
595  }
596 
597  @Override
598  public int getRowCount() {
599  return currentExtensions == null ? 0 : currentExtensions.size();
600  }
601 
602  @Override
603  public String getColumnName(int column) {
604  String colName = null;
605  return colName;
606  }
607 
608  @Override
609  public Object getValueAt(int rowIndex, int columnIndex) {
610  Object ret = null;
611 
612  if ((currentExtensions == null) || (currentExtensions.isEmpty()) || (rowIndex > currentExtensions.size())) {
613  return "";
614  }
615  String word = currentExtensions.get(rowIndex);
616  switch (columnIndex) {
617  case 0:
618  ret = (Object) word;
619  break;
620  default:
621  logger.log(Level.SEVERE, "Invalid table column index: {0}", columnIndex); //NON-NLS
622  break;
623  }
624  return ret;
625  }
626 
627  @Override
628  public boolean isCellEditable(int rowIndex, int columnIndex) {
629  return false;
630  }
631 
632  @Override
633  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
634  }
635 
636  @Override
637  public Class<?> getColumnClass(int c) {
638  return getValueAt(0, c).getClass();
639  }
640 
641  void resync() {
642  fireTableDataChanged();
643  }
644  }
645 }

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