Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestMessageDetailsPanel.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.ingest;
20 
21 import java.awt.Cursor;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import javax.swing.JMenuItem;
25 import javax.swing.text.html.HTMLEditorKit;
26 import javax.swing.text.html.StyleSheet;
31 import org.sleuthkit.datamodel.AbstractFile;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
34 import org.sleuthkit.datamodel.TskException;
35 
39 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
40 class IngestMessageDetailsPanel extends javax.swing.JPanel {
41 
42  private final IngestMessageMainPanel mainPanel;
43  private final DirectoryTreeTopComponent dtc = DirectoryTreeTopComponent.findInstance();
44 
48  IngestMessageDetailsPanel(IngestMessageMainPanel mainPanel) {
49  this.mainPanel = mainPanel;
50  initComponents();
51  customizeComponents();
52  }
53 
54  private void customizeComponents() {
55  messageDetailsPane.setContentType("text/html"); //NON-NLS
56  viewArtifactButton.setEnabled(false);
57  viewContentButton.setEnabled(false);
58  HTMLEditorKit kit = new HTMLEditorKit();
59  messageDetailsPane.setEditorKit(kit);
60  StyleSheet styleSheet = kit.getStyleSheet();
61  /*
62  * I tried to define the font-size only on body to have it inherit, it
63  * didn't work in all cases.
64  */
65  styleSheet.addRule("body {font-family:Arial;font-size:10pt;}"); //NON-NLS
66  styleSheet.addRule("p {font-family:Arial;font-size:10pt;}"); //NON-NLS
67  styleSheet.addRule("li {font-family:Arial;font-size:10pt;}"); //NON-NLS
68  styleSheet.addRule("table {table-layout:fixed;}"); //NON-NLS
69  styleSheet.addRule("td {white-space:pre-wrap;overflow:hidden;}"); //NON-NLS
70  styleSheet.addRule("th {font-weight:bold;}"); //NON-NLS
71 
72  //right click
73  messageDetailsPane.setComponentPopupMenu(rightClickMenu);
74  ActionListener actList = new ActionListener() {
75  @Override
76  public void actionPerformed(ActionEvent e) {
77  JMenuItem jmi = (JMenuItem) e.getSource();
78  if (jmi.equals(copyMenuItem)) {
79  messageDetailsPane.copy();
80  } else if (jmi.equals(selectAllMenuItem)) {
81  messageDetailsPane.selectAll();
82  }
83  }
84  };
85  copyMenuItem.addActionListener(actList);
86  selectAllMenuItem.addActionListener(actList);
87  }
88 
94  @SuppressWarnings("unchecked")
95  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
96  private void initComponents() {
97 
98  rightClickMenu = new javax.swing.JPopupMenu();
99  copyMenuItem = new javax.swing.JMenuItem();
100  selectAllMenuItem = new javax.swing.JMenuItem();
101  jScrollPane1 = new javax.swing.JScrollPane();
102  messageDetailsPane = new javax.swing.JTextPane();
103  jToolBar1 = new javax.swing.JToolBar();
104  backButton = new javax.swing.JButton();
105  filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
106  viewArtifactButton = new javax.swing.JButton();
107  viewContentButton = new javax.swing.JButton();
108 
109  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.copyMenuItem.text")); // NOI18N
110  rightClickMenu.add(copyMenuItem);
111 
112  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.selectAllMenuItem.text")); // NOI18N
113  rightClickMenu.add(selectAllMenuItem);
114 
115  messageDetailsPane.setEditable(false);
116  messageDetailsPane.setBackground(new java.awt.Color(221, 221, 235));
117  messageDetailsPane.setBorder(null);
118  messageDetailsPane.setContentType(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.messageDetailsPane.contentType")); // NOI18N
119  messageDetailsPane.setFont(messageDetailsPane.getFont().deriveFont(messageDetailsPane.getFont().getSize()-1f));
120  messageDetailsPane.setToolTipText(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.messageDetailsPane.toolTipText")); // NOI18N
121  jScrollPane1.setViewportView(messageDetailsPane);
122 
123  jToolBar1.setFloatable(false);
124  jToolBar1.setRollover(true);
125 
126  backButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/btn_step_back.png"))); // NOI18N
127  backButton.setText(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.backButton.text")); // NOI18N
128  backButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
129  backButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
130  backButton.setMaximumSize(new java.awt.Dimension(23, 23));
131  backButton.setMinimumSize(new java.awt.Dimension(23, 23));
132  backButton.setPreferredSize(new java.awt.Dimension(23, 23));
133  backButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/btn_step_back_hover.png"))); // NOI18N
134  backButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/btn_step_back_hover.png"))); // NOI18N
135  backButton.addActionListener(new java.awt.event.ActionListener() {
136  public void actionPerformed(java.awt.event.ActionEvent evt) {
137  backButtonActionPerformed(evt);
138  }
139  });
140  jToolBar1.add(backButton);
141  jToolBar1.add(filler1);
142 
143  viewArtifactButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/goto_res.png"))); // NOI18N
144  viewArtifactButton.setText(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.viewArtifactButton.text")); // NOI18N
145  viewArtifactButton.setIconTextGap(2);
146  viewArtifactButton.addActionListener(new java.awt.event.ActionListener() {
147  public void actionPerformed(java.awt.event.ActionEvent evt) {
148  viewArtifactButtonActionPerformed(evt);
149  }
150  });
151  jToolBar1.add(viewArtifactButton);
152 
153  viewContentButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/goto_dir.png"))); // NOI18N
154  viewContentButton.setText(org.openide.util.NbBundle.getMessage(IngestMessageDetailsPanel.class, "IngestMessageDetailsPanel.viewContentButton.text")); // NOI18N
155  viewContentButton.setIconTextGap(2);
156  viewContentButton.addActionListener(new java.awt.event.ActionListener() {
157  public void actionPerformed(java.awt.event.ActionEvent evt) {
158  viewContentButtonActionPerformed(evt);
159  }
160  });
161  jToolBar1.add(viewContentButton);
162 
163  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
164  this.setLayout(layout);
165  layout.setHorizontalGroup(
166  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167  .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
168  .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
169  );
170  layout.setVerticalGroup(
171  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
172  .addGroup(layout.createSequentialGroup()
173  .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
174  .addGap(0, 0, 0)
175  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE))
176  );
177  }// </editor-fold>//GEN-END:initComponents
178 
179  private void viewContentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewContentButtonActionPerformed
180  messageDetailsPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
181  final IngestMessageGroup messageGroup = mainPanel.getMessagePanel().getSelectedMessage();
182  if (messageGroup != null) {
183  BlackboardArtifact art = messageGroup.getData();
184  if (art != null) {
185  dtc.viewArtifactContent(art);
186  }
187  }
188  messageDetailsPane.setCursor(null);
189  }//GEN-LAST:event_viewContentButtonActionPerformed
190 
191  private void viewArtifactButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewArtifactButtonActionPerformed
192  messageDetailsPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
193  final IngestMessageGroup messageGroup = mainPanel.getMessagePanel().getSelectedMessage();
194  if (messageGroup != null) {
195  BlackboardArtifact art = messageGroup.getData();
196  if (art != null) {
197  dtc.viewArtifact(art);
198  }
199  }
200  messageDetailsPane.setCursor(null);
201  }//GEN-LAST:event_viewArtifactButtonActionPerformed
202 
203  private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
204  mainPanel.showMessages();
205  }//GEN-LAST:event_backButtonActionPerformed
206  // Variables declaration - do not modify//GEN-BEGIN:variables
207  private javax.swing.JButton backButton;
208  private javax.swing.JMenuItem copyMenuItem;
209  private javax.swing.Box.Filler filler1;
210  private javax.swing.JScrollPane jScrollPane1;
211  private javax.swing.JToolBar jToolBar1;
212  private javax.swing.JTextPane messageDetailsPane;
213  private javax.swing.JPopupMenu rightClickMenu;
214  private javax.swing.JMenuItem selectAllMenuItem;
215  private javax.swing.JButton viewArtifactButton;
216  private javax.swing.JButton viewContentButton;
217  // End of variables declaration//GEN-END:variables
218 
224  void showDetails(int rowNumber) {
225  final IngestMessageGroup messageGroup = mainPanel.getMessagePanel().getMessageGroup(rowNumber);
226  if (messageGroup != null) {
227  String details = messageGroup.getDetails();
228  if (details != null) {
229  StringBuilder b = new StringBuilder();
230  if (details.startsWith("<html><body>") == false) { //NON-NLS
231  b.append("<html><body>"); //NON-NLS
232  b.append(details);
233  b.append("</body></html>"); //NON-NLS
234  } else {
235  b.append(details);
236  }
237  this.messageDetailsPane.setText(b.toString());
238  } else {
239  this.messageDetailsPane.setText("");
240  }
241  //show artifact/content only for a message group with a single message
242  BlackboardArtifact artifact = messageGroup.getData();
243  if (artifact != null && messageGroup.getCount() == 1) {
244  viewArtifactButton.setEnabled(true);
245 
246  //check file type
247  long objId = artifact.getObjectID();
248  AbstractFile file = null;
249  try {
250  file = Case.getCurrentCaseThrows().getSleuthkitCase().getAbstractFileById(objId);
251  } catch (TskException | NoCurrentCaseException ex) {
252 
253  }
254  if (file == null) {
255  viewContentButton.setEnabled(false);
256  } else if (!file.getType().equals(TSK_DB_FILES_TYPE_ENUM.FS)) {
257  viewContentButton.setEnabled(false);
258  } else {
259  viewContentButton.setEnabled(true);
260  }
261  } else {
262  viewArtifactButton.setEnabled(false);
263  viewContentButton.setEnabled(false);
264  }
265  } else {
266  viewArtifactButton.setEnabled(false);
267  viewContentButton.setEnabled(false);
268  messageDetailsPane.setText("");
269  }
270 
271  }
272 }

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