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