Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TimeLineTopComponent.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.timeline;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Component;
23 import java.awt.KeyboardFocusManager;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.beans.PropertyVetoException;
27 import java.util.List;
28 import java.util.logging.Level;
29 import java.util.stream.Collectors;
30 import javafx.application.Platform;
31 import javafx.beans.InvalidationListener;
32 import javafx.beans.Observable;
33 import javafx.scene.Scene;
34 import javafx.scene.control.SplitPane;
35 import javafx.scene.control.Tab;
36 import javafx.scene.control.TabPane;
37 import javafx.scene.image.ImageView;
38 import javafx.scene.input.KeyCode;
39 import javafx.scene.input.KeyCodeCombination;
40 import javafx.scene.input.KeyEvent;
41 import javafx.scene.layout.Priority;
42 import javafx.scene.layout.VBox;
43 import javax.swing.JComponent;
44 import javax.swing.JPanel;
45 import javax.swing.SwingUtilities;
46 import static javax.swing.SwingUtilities.isDescendingFrom;
47 import org.controlsfx.control.Notifications;
48 import org.joda.time.Interval;
49 import org.joda.time.format.DateTimeFormatter;
50 import org.openide.explorer.ExplorerManager;
51 import static org.openide.explorer.ExplorerUtils.createLookup;
52 import org.openide.nodes.AbstractNode;
53 import org.openide.nodes.Children;
54 import org.openide.nodes.Node;
55 import org.openide.util.NbBundle;
56 import org.openide.windows.Mode;
57 import org.openide.windows.RetainLocation;
58 import org.openide.windows.TopComponent;
59 import org.openide.windows.WindowManager;
80 import org.sleuthkit.datamodel.TskCoreException;
81 
85 @TopComponent.Description(
86  preferredID = "TimeLineTopComponent",
87  //iconBase="SET/PATH/TO/ICON/HERE", //use this to put icon in window title area,
88  persistenceType = TopComponent.PERSISTENCE_NEVER)
89 @TopComponent.Registration(mode = "timeline", openAtStartup = false)
90 @RetainLocation("timeline")
91 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
92 public final class TimeLineTopComponent extends TopComponent implements ExplorerManager.Provider {
93 
94  private static final Logger logger = Logger.getLogger(TimeLineTopComponent.class.getName());
95 
97  private final DataContentExplorerPanel contentViewerPanel;
98 
99  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
100  private final DataResultPanel dataResultPanel;
101 
102  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
103  private final ExplorerManager explorerManager = new ExplorerManager();
104 
105  private final TimeLineController controller;
106 
110  private final ModifiableProxyLookup proxyLookup = new ModifiableProxyLookup();
111 
112  private final PropertyChangeListener focusPropertyListener = new PropertyChangeListener() {
136  @Override
137  public void propertyChange(final PropertyChangeEvent focusEvent) {
138  if (focusEvent.getPropertyName().equalsIgnoreCase("focusOwner")) {
139  final Component newFocusOwner = (Component) focusEvent.getNewValue();
140 
141  if (newFocusOwner == null) {
142  return;
143  }
144  if (isDescendingFrom(newFocusOwner, contentViewerPanel)) {
145  //if the focus owner is within the MessageContentViewer (the attachments table)
146  proxyLookup.setNewLookups(createLookup(contentViewerPanel.getExplorerManager(), getActionMap()));
147  } else if (isDescendingFrom(newFocusOwner, TimeLineTopComponent.this)) {
148  //... or if it is within the Results table.
149  proxyLookup.setNewLookups(createLookup(explorerManager, getActionMap()));
150 
151  }
152  }
153  }
154  };
155 
156  @NbBundle.Messages({"TimelineTopComponent.selectedEventListener.errorMsg=There was a problem getting the content for the selected event."})
157  private final InvalidationListener selectedEventsListener = new InvalidationListener() {
165  @Override
166  public void invalidated(Observable observable) {
167  List<Long> selectedEventIDs = controller.getSelectedEventIDs();
168 
169  //depending on the active view mode, we either update the dataResultPanel, or update the contentViewerPanel directly.
170  switch (controller.getViewMode()) {
171  case LIST:
172  //make an array of EventNodes for the selected events
173  EventNode[] childArray = new EventNode[selectedEventIDs.size()];
174  try {
175  for (int i = 0; i < selectedEventIDs.size(); i++) {
176  childArray[i] = EventNode.createEventNode(selectedEventIDs.get(i), controller.getEventsModel());
177  }
178  Children children = new Children.Array();
179  children.add(childArray);
180 
181  SwingUtilities.invokeLater(() -> {
182  //set generic container node as root context
183  explorerManager.setRootContext(new AbstractNode(children));
184  try {
185  //set selected nodes for actions
186  explorerManager.setSelectedNodes(childArray);
187  } catch (PropertyVetoException ex) {
188  //I don't know why this would ever happen.
189  logger.log(Level.SEVERE, "Selecting the event node was vetoed.", ex); // NON-NLS
190  }
191  //if there is only one event selected push it into content viewer.
192  if (childArray.length == 1) {
193  contentViewerPanel.setNode(childArray[0]);
194  } else {
195  contentViewerPanel.setNode(null);
196  }
197  });
198  } catch (NoCurrentCaseException ex) {
199  //Since the case is closed, the user probably doesn't care about this, just log it as a precaution.
200  logger.log(Level.SEVERE, "There was no case open to lookup the Sleuthkit object backing a SingleEvent.", ex); // NON-NLS
201  } catch (TskCoreException ex) {
202  logger.log(Level.SEVERE, "Failed to lookup Sleuthkit object backing a SingleEvent.", ex); // NON-NLS
203  Platform.runLater(() -> {
204  Notifications.create()
205  .owner(jFXViewPanel.getScene().getWindow())
206  .text(Bundle.TimelineTopComponent_selectedEventListener_errorMsg())
207  .showError();
208  });
209  }
210  break;
211  case COUNTS:
212  case DETAIL:
213  //make a root node with nodes for the selected events as children and push it to the result viewer.
214  EventRootNode rootNode = new EventRootNode(selectedEventIDs, controller.getEventsModel());
215  TableFilterNode tableFilterNode = new TableFilterNode(rootNode, true, "Event");
216  SwingUtilities.invokeLater(() -> {
217  dataResultPanel.setPath(getResultViewerSummaryString());
218  dataResultPanel.setNode(tableFilterNode);
219  });
220  break;
221  default:
222  throw new UnsupportedOperationException("Unknown view mode: " + controller.getViewMode());
223  }
224  }
225  };
226 
227  private void syncViewMode() {
228  switch (controller.getViewMode()) {
229  case COUNTS:
230  case DETAIL:
231  /*
232  * For counts and details mode, restore the result table at the
233  * bottom left.
234  */
235  SwingUtilities.invokeLater(() -> {
236  splitYPane.remove(contentViewerPanel);
237  if (horizontalSplitPane.getParent() != splitYPane) {
238  splitYPane.setBottomComponent(horizontalSplitPane);
239  horizontalSplitPane.setRightComponent(contentViewerPanel);
240  }
241  });
242  break;
243  case LIST:
244  /*
245  * For list mode, remove the result table, and let the content
246  * viewer expand across the bottom.
247  */
248  SwingUtilities.invokeLater(() -> splitYPane.setBottomComponent(contentViewerPanel));
249  break;
250  default:
251  throw new UnsupportedOperationException("Unknown ViewMode: " + controller.getViewMode());
252  }
253  }
254 
261  initComponents();
262  associateLookup(proxyLookup);
263  setName(NbBundle.getMessage(TimeLineTopComponent.class, "CTL_TimeLineTopComponent"));
264 
265  getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(AddBookmarkTagAction.BOOKMARK_SHORTCUT, "addBookmarkTag"); //NON-NLS
266  getActionMap().put("addBookmarkTag", new AddBookmarkTagAction()); //NON-NLS
267  getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ExternalViewerShortcutAction.EXTERNAL_VIEWER_SHORTCUT, "useExternalViewer"); //NON-NLS
268  getActionMap().put("useExternalViewer", ExternalViewerShortcutAction.getInstance()); //NON-NLS
269  this.controller = controller;
270 
271  //create linked result and content views
272  contentViewerPanel = new DataContentExplorerPanel();
273  dataResultPanel = DataResultPanel.createInstanceUninitialized("", "", Node.EMPTY, 0, contentViewerPanel);
274 
275  //add them to bottom splitpane
276  horizontalSplitPane.setLeftComponent(dataResultPanel);
277  horizontalSplitPane.setRightComponent(contentViewerPanel);
278 
279  dataResultPanel.open(); //get the explorermanager
280  contentViewerPanel.initialize();
281 
282  Platform.runLater(this::initFXComponents);
283 
284  //set up listeners
285  TimeLineController.getTimeZone().addListener(timeZone -> dataResultPanel.setPath(getResultViewerSummaryString()));
286  controller.getSelectedEventIDs().addListener(selectedEventsListener);
287 
288  //Listen to ViewMode and adjust GUI componenets as needed.
289  controller.viewModeProperty().addListener(viewMode -> syncViewMode());
290  syncViewMode();
291 
292  //add listener that maintains correct selection in the Global Actions Context
293  KeyboardFocusManager.getCurrentKeyboardFocusManager()
294  .addPropertyChangeListener("focusOwner", focusPropertyListener);
295  }
296 
300  @NbBundle.Messages({
301  "TimeLineTopComponent.eventsTab.name=Events",
302  "TimeLineTopComponent.filterTab.name=Filters"})
303  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
304  void initFXComponents() {
306  final TimeZonePanel timeZonePanel = new TimeZonePanel();
307  VBox.setVgrow(timeZonePanel, Priority.SOMETIMES);
308  HistoryToolBar historyToolBar = new HistoryToolBar(controller);
309  final ZoomSettingsPane zoomSettingsPane = new ZoomSettingsPane(controller);
310 
311  //set up filter tab
312  final Tab filterTab = new Tab(Bundle.TimeLineTopComponent_filterTab_name(), new FilterSetPanel(controller));
313  filterTab.setClosable(false);
314  filterTab.setGraphic(new ImageView("org/sleuthkit/autopsy/timeline/images/funnel.png")); // NON-NLS
315 
316  //set up events tab
317  final EventsTree eventsTree = new EventsTree(controller);
318  final Tab eventsTreeTab = new Tab(Bundle.TimeLineTopComponent_eventsTab_name(), eventsTree);
319  eventsTreeTab.setClosable(false);
320  eventsTreeTab.setGraphic(new ImageView("org/sleuthkit/autopsy/timeline/images/timeline_marker.png")); // NON-NLS
321  eventsTreeTab.disableProperty().bind(controller.viewModeProperty().isNotEqualTo(ViewMode.DETAIL));
322 
323  final TabPane leftTabPane = new TabPane(filterTab, eventsTreeTab);
324  VBox.setVgrow(leftTabPane, Priority.ALWAYS);
325  controller.viewModeProperty().addListener(viewMode -> {
326  if (controller.getViewMode() != ViewMode.DETAIL) {
327  //if view mode is not details, switch back to the filter tab
328  leftTabPane.getSelectionModel().select(filterTab);
329  }
330  });
331 
332  //assemble left column
333  final VBox leftVBox = new VBox(5, timeZonePanel, historyToolBar, zoomSettingsPane, leftTabPane);
334  SplitPane.setResizableWithParent(leftVBox, Boolean.FALSE);
335 
336  final ViewFrame viewFrame = new ViewFrame(controller, eventsTree);
337  final SplitPane mainSplitPane = new SplitPane(leftVBox, viewFrame);
338  mainSplitPane.setDividerPositions(0);
339 
340  final Scene scene = new Scene(mainSplitPane);
341  scene.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> {
342  if (new KeyCodeCombination(KeyCode.LEFT, KeyCodeCombination.ALT_DOWN).match(keyEvent)) {
343  new Back(controller).handle(null);
344  } else if (new KeyCodeCombination(KeyCode.BACK_SPACE).match(keyEvent)) {
345  new Back(controller).handle(null);
346  } else if (new KeyCodeCombination(KeyCode.RIGHT, KeyCodeCombination.ALT_DOWN).match(keyEvent)) {
347  new Forward(controller).handle(null);
348  } else if (new KeyCodeCombination(KeyCode.BACK_SPACE, KeyCodeCombination.SHIFT_DOWN).match(keyEvent)) {
349  new Forward(controller).handle(null);
350  }
351  });
352 
353  //add ui componenets to JFXPanels
354  jFXViewPanel.setScene(scene);
355  jFXstatusPanel.setScene(new Scene(new StatusBar(controller)));
356  }
357 
358  @Override
359  public List<Mode> availableModes(List<Mode> modes) {
360  /*
361  * This looks like the right thing to do, but online discussions seems
362  * to indicate this method is effectively deprecated. A break point
363  * placed here was never hit.
364  */
365  return modes.stream().filter(mode -> mode.getName().equals("timeline") || mode.getName().equals("ImageGallery"))
366  .collect(Collectors.toList());
367  }
368 
374  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
375  private void initComponents() {
376 
377  jFXstatusPanel = new javafx.embed.swing.JFXPanel();
378  splitYPane = new javax.swing.JSplitPane();
379  jFXViewPanel = new javafx.embed.swing.JFXPanel();
380  horizontalSplitPane = new javax.swing.JSplitPane();
381  leftFillerPanel = new javax.swing.JPanel();
382  rightfillerPanel = new javax.swing.JPanel();
383 
384  jFXstatusPanel.setPreferredSize(new java.awt.Dimension(100, 16));
385 
386  splitYPane.setDividerLocation(420);
387  splitYPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
388  splitYPane.setResizeWeight(0.9);
389  splitYPane.setPreferredSize(new java.awt.Dimension(1024, 400));
390  splitYPane.setLeftComponent(jFXViewPanel);
391 
392  horizontalSplitPane.setDividerLocation(600);
393  horizontalSplitPane.setResizeWeight(0.5);
394  horizontalSplitPane.setPreferredSize(new java.awt.Dimension(1200, 300));
395  horizontalSplitPane.setRequestFocusEnabled(false);
396 
397  javax.swing.GroupLayout leftFillerPanelLayout = new javax.swing.GroupLayout(leftFillerPanel);
398  leftFillerPanel.setLayout(leftFillerPanelLayout);
399  leftFillerPanelLayout.setHorizontalGroup(
400  leftFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401  .addGap(0, 599, Short.MAX_VALUE)
402  );
403  leftFillerPanelLayout.setVerticalGroup(
404  leftFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
405  .addGap(0, 54, Short.MAX_VALUE)
406  );
407 
408  horizontalSplitPane.setLeftComponent(leftFillerPanel);
409 
410  javax.swing.GroupLayout rightfillerPanelLayout = new javax.swing.GroupLayout(rightfillerPanel);
411  rightfillerPanel.setLayout(rightfillerPanelLayout);
412  rightfillerPanelLayout.setHorizontalGroup(
413  rightfillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
414  .addGap(0, 364, Short.MAX_VALUE)
415  );
416  rightfillerPanelLayout.setVerticalGroup(
417  rightfillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
418  .addGap(0, 54, Short.MAX_VALUE)
419  );
420 
421  horizontalSplitPane.setRightComponent(rightfillerPanel);
422 
423  splitYPane.setRightComponent(horizontalSplitPane);
424 
425  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
426  this.setLayout(layout);
427  layout.setHorizontalGroup(
428  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
429  .addComponent(splitYPane, javax.swing.GroupLayout.DEFAULT_SIZE, 972, Short.MAX_VALUE)
430  .addComponent(jFXstatusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
431  );
432  layout.setVerticalGroup(
433  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
434  .addGroup(layout.createSequentialGroup()
435  .addComponent(splitYPane, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
436  .addGap(0, 0, 0)
437  .addComponent(jFXstatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
438  );
439  }// </editor-fold>//GEN-END:initComponents
440 
441  // Variables declaration - do not modify//GEN-BEGIN:variables
442  private javax.swing.JSplitPane horizontalSplitPane;
443  private javafx.embed.swing.JFXPanel jFXViewPanel;
444  private javafx.embed.swing.JFXPanel jFXstatusPanel;
445  private javax.swing.JPanel leftFillerPanel;
446  private javax.swing.JPanel rightfillerPanel;
447  private javax.swing.JSplitPane splitYPane;
448  // End of variables declaration//GEN-END:variables
449 
450  @Override
451  public void componentOpened() {
452  super.componentOpened();
453  WindowManager.getDefault().setTopComponentFloating(this, true);
454 
455  //add listener that maintains correct selection in the Global Actions Context
456  KeyboardFocusManager.getCurrentKeyboardFocusManager()
457  .addPropertyChangeListener("focusOwner", focusPropertyListener);
458  }
459 
460  @Override
461  protected void componentClosed() {
462  super.componentClosed();
463  KeyboardFocusManager.getCurrentKeyboardFocusManager()
464  .removePropertyChangeListener("focusOwner", focusPropertyListener);
465  }
466 
467  @Override
468  public ExplorerManager getExplorerManager() {
469  return explorerManager;
470  }
471 
478  @NbBundle.Messages({
479  "# {0} - start of date range",
480  "# {1} - end of date range",
481  "TimeLineResultView.startDateToEndDate.text={0} to {1}"})
482  private String getResultViewerSummaryString() {
483  Interval selectedTimeRange = controller.getSelectedTimeRange();
484  if (selectedTimeRange == null) {
485  return "";
486  } else {
487  final DateTimeFormatter zonedFormatter = TimeLineController.getZonedFormatter();
488  String start = selectedTimeRange.getStart()
490  .toString(zonedFormatter);
491  String end = selectedTimeRange.getEnd()
493  .toString(zonedFormatter);
494  return Bundle.TimeLineResultView_startDateToEndDate_text(start, end);
495 
496  }
497  }
498 
507  final private static class DataContentExplorerPanel extends JPanel implements ExplorerManager.Provider, DataContent {
508 
509  private final ExplorerManager explorerManager = new ExplorerManager();
510  private final DataContentPanel wrapped;
511 
513  super(new BorderLayout());
514  wrapped = DataContentPanel.createInstance();
515  }
516 
517  @Override
518  public ExplorerManager getExplorerManager() {
519  return explorerManager;
520  }
521 
522  @Override
523  public void setNode(Node selectedNode) {
524  wrapped.setNode(selectedNode);
525  }
526 
527  @Override
528  public void propertyChange(PropertyChangeEvent evt) {
529  wrapped.propertyChange(evt);
530  }
531 
539  private void initialize() {
540  add(wrapped, BorderLayout.CENTER);
541  }
542  }
543 }
static EventNode createEventNode(final Long eventID, FilteredEventsModel eventsModel)
Definition: EventNode.java:219
static ReadOnlyObjectProperty< TimeZone > getTimeZone()
static DataResultPanel createInstanceUninitialized(String title, String description, Node currentRootNode, int childNodeCount, DataContent customContentView)
synchronized ObservableList< Long > getSelectedEventIDs()
synchronized ReadOnlyObjectProperty< ViewMode > viewModeProperty()
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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