Autopsy  4.4.1
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-2017 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.beans.PropertyVetoException;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.stream.Collectors;
25 import javafx.application.Platform;
26 import javafx.beans.InvalidationListener;
27 import javafx.beans.Observable;
28 import javafx.scene.Scene;
29 import javafx.scene.control.SplitPane;
30 import javafx.scene.control.Tab;
31 import javafx.scene.control.TabPane;
32 import javafx.scene.image.ImageView;
33 import javafx.scene.input.KeyCode;
34 import javafx.scene.input.KeyCodeCombination;
35 import javafx.scene.input.KeyEvent;
36 import javafx.scene.layout.Priority;
37 import javafx.scene.layout.VBox;
38 import javax.swing.JComponent;
39 import javax.swing.SwingUtilities;
40 import org.controlsfx.control.Notifications;
41 import org.joda.time.Interval;
42 import org.joda.time.format.DateTimeFormatter;
43 import org.openide.explorer.ExplorerManager;
44 import org.openide.explorer.ExplorerUtils;
45 import org.openide.nodes.AbstractNode;
46 import org.openide.nodes.Children;
47 import org.openide.nodes.Node;
48 import org.openide.util.NbBundle;
49 import org.openide.windows.Mode;
50 import org.openide.windows.RetainLocation;
51 import org.openide.windows.TopComponent;
52 import org.openide.windows.WindowManager;
69 import org.sleuthkit.datamodel.TskCoreException;
70 
74 @TopComponent.Description(
75  preferredID = "TimeLineTopComponent",
76  //iconBase="SET/PATH/TO/ICON/HERE", //use this to put icon in window title area,
77  persistenceType = TopComponent.PERSISTENCE_NEVER)
78 @TopComponent.Registration(mode = "timeline", openAtStartup = false)
79 @RetainLocation("timeline")
80 public final class TimeLineTopComponent extends TopComponent implements ExplorerManager.Provider {
81 
82  private static final Logger LOGGER = Logger.getLogger(TimeLineTopComponent.class.getName());
83 
85  private final DataContentPanel contentViewerPanel;
86 
87  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
88  private DataResultPanel dataResultPanel;
89 
90  @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
91  private final ExplorerManager em = new ExplorerManager();
92 
93  private final TimeLineController controller;
94 
99  @NbBundle.Messages({"TimelineTopComponent.selectedEventListener.errorMsg=There was a problem getting the content for the selected event."})
100  private final InvalidationListener selectedEventsListener = new InvalidationListener() {
101  @Override
102  public void invalidated(Observable observable) {
103  List<Long> selectedEventIDs = controller.getSelectedEventIDs();
104 
105  //depending on the active view mode, we either update the dataResultPanel, or update the contentViewerPanel directly.
106  switch (controller.getViewMode()) {
107  case LIST:
108 
109  //make an array of EventNodes for the selected events
110  EventNode[] childArray = new EventNode[selectedEventIDs.size()];
111  try {
112  for (int i = 0; i < selectedEventIDs.size(); i++) {
113  childArray[i] = EventNode.createEventNode(selectedEventIDs.get(i), controller.getEventsModel());
114  }
115  Children children = new Children.Array();
116  children.add(childArray);
117 
118  SwingUtilities.invokeLater(() -> {
119  //set generic container node as root context
120  em.setRootContext(new AbstractNode(children));
121  try {
122  //set selected nodes for actions
123  em.setSelectedNodes(childArray);
124  } catch (PropertyVetoException ex) {
125  //I don't know why this would ever happen.
126  LOGGER.log(Level.SEVERE, "Selecting the event node was vetoed.", ex); // NON-NLS
127  }
128  //if there is only one event selected push it into content viewer.
129  if (childArray.length == 1) {
130  contentViewerPanel.setNode(childArray[0]);
131  } else {
132  contentViewerPanel.setNode(null);
133  }
134  });
135  } catch (IllegalStateException ex) {
136  //Since the case is closed, the user probably doesn't care about this, just log it as a precaution.
137  LOGGER.log(Level.SEVERE, "There was no case open to lookup the Sleuthkit object backing a SingleEvent.", ex); // NON-NLS
138  } catch (TskCoreException ex) {
139  LOGGER.log(Level.SEVERE, "Failed to lookup Sleuthkit object backing a SingleEvent.", ex); // NON-NLS
140  Platform.runLater(() -> {
141  Notifications.create()
142  .owner(jFXViewPanel.getScene().getWindow())
143  .text(Bundle.TimelineTopComponent_selectedEventListener_errorMsg())
144  .showError();
145  });
146  }
147 
148  break;
149  case COUNTS:
150  case DETAIL:
151  //make a root node with nodes for the selected events as children and push it to the result viewer.
152  EventRootNode rootNode = new EventRootNode(selectedEventIDs, controller.getEventsModel());
153  SwingUtilities.invokeLater(() -> {
154  dataResultPanel.setPath(getResultViewerSummaryString());
155  dataResultPanel.setNode(rootNode);
156  });
157  break;
158  default:
159  throw new UnsupportedOperationException("Unknown view mode: " + controller.getViewMode());
160  }
161  }
162  };
163 
164  private void syncViewMode() {
165  switch (controller.getViewMode()) {
166  case COUNTS:
167  case DETAIL:
168  /*
169  * For counts and details mode, restore the result table at the
170  * bottom left.
171  */
172  SwingUtilities.invokeLater(() -> {
173  splitYPane.remove(contentViewerPanel);
174  if ((horizontalSplitPane.getParent() == splitYPane) == false) {
175  splitYPane.setBottomComponent(horizontalSplitPane);
176  horizontalSplitPane.setRightComponent(contentViewerPanel);
177  }
178  });
179  break;
180  case LIST:
181  /*
182  * For list mode, remove the result table, and let the content
183  * viewer expand across the bottom.
184  */
185  SwingUtilities.invokeLater(() -> {
186  splitYPane.setBottomComponent(contentViewerPanel);
187  });
188  break;
189  default:
190  throw new UnsupportedOperationException("Unknown ViewMode: " + controller.getViewMode());
191  }
192  }
193 
200  initComponents();
201  associateLookup(ExplorerUtils.createLookup(em, getActionMap()));
202  setName(NbBundle.getMessage(TimeLineTopComponent.class, "CTL_TimeLineTopComponent"));
203 
204  getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(AddBookmarkTagAction.BOOKMARK_SHORTCUT, "addBookmarkTag"); //NON-NLS
205  getActionMap().put("addBookmarkTag", new AddBookmarkTagAction()); //NON-NLS
206 
207  this.controller = controller;
208 
209  //create linked result and content views
210  contentViewerPanel = DataContentPanel.createInstance();
211  dataResultPanel = DataResultPanel.createInstanceUninitialized("", "", Node.EMPTY, 0, contentViewerPanel);
212 
213  //add them to bottom splitpane
214  horizontalSplitPane.setLeftComponent(dataResultPanel);
215  horizontalSplitPane.setRightComponent(contentViewerPanel);
216 
217  dataResultPanel.open(); //get the explorermanager
218 
219  Platform.runLater(this::initFXComponents);
220 
221  //set up listeners
222  TimeLineController.getTimeZone().addListener(timeZone -> dataResultPanel.setPath(getResultViewerSummaryString()));
223  controller.getSelectedEventIDs().addListener(selectedEventsListener);
224 
225  //Listen to ViewMode and adjust GUI componenets as needed.
226  controller.viewModeProperty().addListener(viewMode -> syncViewMode());
227  syncViewMode();
228  }
229 
233  @NbBundle.Messages({
234  "TimeLineTopComponent.eventsTab.name=Events",
235  "TimeLineTopComponent.filterTab.name=Filters"})
236  @ThreadConfined(type = ThreadConfined.ThreadType.JFX)
237  void initFXComponents() {
239  final TimeZonePanel timeZonePanel = new TimeZonePanel();
240  VBox.setVgrow(timeZonePanel, Priority.SOMETIMES);
241  HistoryToolBar historyToolBar = new HistoryToolBar(controller);
242  final ZoomSettingsPane zoomSettingsPane = new ZoomSettingsPane(controller);
243 
244  //set up filter tab
245  final Tab filterTab = new Tab(Bundle.TimeLineTopComponent_filterTab_name(), new FilterSetPanel(controller));
246  filterTab.setClosable(false);
247  filterTab.setGraphic(new ImageView("org/sleuthkit/autopsy/timeline/images/funnel.png")); // NON-NLS
248 
249  //set up events tab
250  final EventsTree eventsTree = new EventsTree(controller);
251  final Tab eventsTreeTab = new Tab(Bundle.TimeLineTopComponent_eventsTab_name(), eventsTree);
252  eventsTreeTab.setClosable(false);
253  eventsTreeTab.setGraphic(new ImageView("org/sleuthkit/autopsy/timeline/images/timeline_marker.png")); // NON-NLS
254  eventsTreeTab.disableProperty().bind(controller.viewModeProperty().isNotEqualTo(ViewMode.DETAIL));
255 
256  final TabPane leftTabPane = new TabPane(filterTab, eventsTreeTab);
257  VBox.setVgrow(leftTabPane, Priority.ALWAYS);
258  controller.viewModeProperty().addListener(viewMode -> {
259  if (controller.getViewMode().equals(ViewMode.DETAIL) == false) {
260  //if view mode is not details, switch back to the filter tab
261  leftTabPane.getSelectionModel().select(filterTab);
262  }
263  });
264 
265  //assemble left column
266  final VBox leftVBox = new VBox(5, timeZonePanel, historyToolBar, zoomSettingsPane, leftTabPane);
267  SplitPane.setResizableWithParent(leftVBox, Boolean.FALSE);
268 
269  final ViewFrame viewFrame = new ViewFrame(controller, eventsTree);
270  final SplitPane mainSplitPane = new SplitPane(leftVBox, viewFrame);
271  mainSplitPane.setDividerPositions(0);
272 
273  final Scene scene = new Scene(mainSplitPane);
274  scene.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> {
275  if (new KeyCodeCombination(KeyCode.LEFT, KeyCodeCombination.ALT_DOWN).match(keyEvent)) {
276  new Back(controller).handle(null);
277  } else if (new KeyCodeCombination(KeyCode.BACK_SPACE).match(keyEvent)) {
278  new Back(controller).handle(null);
279  } else if (new KeyCodeCombination(KeyCode.RIGHT, KeyCodeCombination.ALT_DOWN).match(keyEvent)) {
280  new Forward(controller).handle(null);
281  } else if (new KeyCodeCombination(KeyCode.BACK_SPACE, KeyCodeCombination.SHIFT_DOWN).match(keyEvent)) {
282  new Forward(controller).handle(null);
283  }
284  });
285 
286  //add ui componenets to JFXPanels
287  jFXViewPanel.setScene(scene);
288  jFXstatusPanel.setScene(new Scene(new StatusBar(controller)));
289  }
290 
291  @Override
292  public List<Mode> availableModes(List<Mode> modes) {
293  /*
294  * This looks like the right thing to do, but online discussions seems
295  * to indicate this method is effectively deprecated. A break point
296  * placed here was never hit.
297  */
298  return modes.stream().filter(mode -> mode.getName().equals("timeline") || mode.getName().equals("ImageGallery"))
299  .collect(Collectors.toList());
300  }
301 
307  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
308  private void initComponents() {
309 
310  jFXstatusPanel = new javafx.embed.swing.JFXPanel();
311  splitYPane = new javax.swing.JSplitPane();
312  jFXViewPanel = new javafx.embed.swing.JFXPanel();
313  horizontalSplitPane = new javax.swing.JSplitPane();
314  leftFillerPanel = new javax.swing.JPanel();
315  rightfillerPanel = new javax.swing.JPanel();
316 
317  jFXstatusPanel.setPreferredSize(new java.awt.Dimension(100, 16));
318 
319  splitYPane.setDividerLocation(420);
320  splitYPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
321  splitYPane.setResizeWeight(0.9);
322  splitYPane.setPreferredSize(new java.awt.Dimension(1024, 400));
323  splitYPane.setLeftComponent(jFXViewPanel);
324 
325  horizontalSplitPane.setDividerLocation(600);
326  horizontalSplitPane.setResizeWeight(0.5);
327  horizontalSplitPane.setPreferredSize(new java.awt.Dimension(1200, 300));
328  horizontalSplitPane.setRequestFocusEnabled(false);
329 
330  javax.swing.GroupLayout leftFillerPanelLayout = new javax.swing.GroupLayout(leftFillerPanel);
331  leftFillerPanel.setLayout(leftFillerPanelLayout);
332  leftFillerPanelLayout.setHorizontalGroup(
333  leftFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334  .addGap(0, 599, Short.MAX_VALUE)
335  );
336  leftFillerPanelLayout.setVerticalGroup(
337  leftFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338  .addGap(0, 54, Short.MAX_VALUE)
339  );
340 
341  horizontalSplitPane.setLeftComponent(leftFillerPanel);
342 
343  javax.swing.GroupLayout rightfillerPanelLayout = new javax.swing.GroupLayout(rightfillerPanel);
344  rightfillerPanel.setLayout(rightfillerPanelLayout);
345  rightfillerPanelLayout.setHorizontalGroup(
346  rightfillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347  .addGap(0, 364, Short.MAX_VALUE)
348  );
349  rightfillerPanelLayout.setVerticalGroup(
350  rightfillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
351  .addGap(0, 54, Short.MAX_VALUE)
352  );
353 
354  horizontalSplitPane.setRightComponent(rightfillerPanel);
355 
356  splitYPane.setRightComponent(horizontalSplitPane);
357 
358  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
359  this.setLayout(layout);
360  layout.setHorizontalGroup(
361  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
362  .addComponent(splitYPane, javax.swing.GroupLayout.DEFAULT_SIZE, 972, Short.MAX_VALUE)
363  .addComponent(jFXstatusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
364  );
365  layout.setVerticalGroup(
366  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
367  .addGroup(layout.createSequentialGroup()
368  .addComponent(splitYPane, javax.swing.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
369  .addGap(0, 0, 0)
370  .addComponent(jFXstatusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
371  );
372  }// </editor-fold>//GEN-END:initComponents
373 
374  // Variables declaration - do not modify//GEN-BEGIN:variables
375  private javax.swing.JSplitPane horizontalSplitPane;
376  private javafx.embed.swing.JFXPanel jFXViewPanel;
377  private javafx.embed.swing.JFXPanel jFXstatusPanel;
378  private javax.swing.JPanel leftFillerPanel;
379  private javax.swing.JPanel rightfillerPanel;
380  private javax.swing.JSplitPane splitYPane;
381  // End of variables declaration//GEN-END:variables
382 
383  @Override
384  public void componentOpened() {
385  super.componentOpened();
386  WindowManager.getDefault().setTopComponentFloating(this, true);
387  }
388 
389  @Override
390  public ExplorerManager getExplorerManager() {
391  return em;
392  }
393 
400  @NbBundle.Messages({
401  "# {0} - start of date range",
402  "# {1} - end of date range",
403  "TimeLineResultView.startDateToEndDate.text={0} to {1}"})
404  private String getResultViewerSummaryString() {
405  Interval selectedTimeRange = controller.getSelectedTimeRange();
406  if (selectedTimeRange == null) {
407  return "";
408  } else {
409  final DateTimeFormatter zonedFormatter = TimeLineController.getZonedFormatter();
410  String start = selectedTimeRange.getStart()
412  .toString(zonedFormatter);
413  String end = selectedTimeRange.getEnd()
415  .toString(zonedFormatter);
416  return Bundle.TimeLineResultView_startDateToEndDate_text(start, end);
417  }
418  }
419 }
static EventNode createEventNode(final Long eventID, FilteredEventsModel eventsModel)
Definition: EventNode.java:218
static ReadOnlyObjectProperty< TimeZone > getTimeZone()
synchronized ObservableList< Long > getSelectedEventIDs()
static DataResultPanel createInstanceUninitialized(String title, String pathText, Node rootNode, int totalMatches, DataContent customContentView)
synchronized ReadOnlyObjectProperty< ViewMode > viewModeProperty()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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