Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PrimaryDetailsChartLane.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.ui.detailview;
20 
21 import java.util.Map;
22 import java.util.concurrent.ConcurrentHashMap;
23 import java.util.logging.Level;
24 import javafx.collections.ListChangeListener;
25 import javafx.scene.chart.Axis;
26 import javafx.scene.shape.Line;
27 import javafx.scene.shape.StrokeLineCap;
28 import org.controlsfx.control.Notifications;
29 import org.openide.util.NbBundle;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
50 public final class PrimaryDetailsChartLane extends DetailsChartLane<EventStripe> implements ContextMenuProvider {
51 
52  private static final Logger logger = Logger.getLogger(PrimaryDetailsChartLane.class.getName());
53 
54  private static final int PROJECTED_LINE_Y_OFFSET = 5;
55  private static final int PROJECTED_LINE_STROKE_WIDTH = 5;
56 
58  private final Map<EventCluster, Line> projectionMap = new ConcurrentHashMap<>();
59 
60  @NbBundle.Messages({"PrimaryDetailsChartLane.stripeChangeListener.errorMessage=Error adding stripe to chart lane."})
61  PrimaryDetailsChartLane(DetailsChart parentChart, DateAxis dateAxis, final Axis<EventStripe> verticalAxis) {
62  super(parentChart, dateAxis, verticalAxis, true);
63 
64  //add listener for events that should trigger layout
65  getController().getQuickHideFilters().addListener(layoutInvalidationListener);
66 
67  parentChart.getRootEventStripes().addListener((ListChangeListener.Change<? extends EventStripe> change) -> {
68  while (change.next()) {
69  try {
70  for (EventStripe stripe : change.getAddedSubList()) {
71  addEvent(stripe);
72  }
73  } catch (TskCoreException ex) {
74  Notifications.create().owner(getScene().getWindow())
75  .text(Bundle.PrimaryDetailsChartLane_stripeChangeListener_errorMessage()).showError();
76  logger.log(Level.SEVERE, "Error adding stripe to chart lane.", ex);
77  }
78  change.getRemoved().forEach(this::removeEvent);
79  }
80  requestChartLayout();
81  });
82  for (EventStripe stripe : parentChart.getRootEventStripes()) {
83  try {
84  addEvent(stripe);
85  } catch (TskCoreException ex) {
86  Notifications.create().owner(getScene().getWindow())
87  .text(Bundle.PrimaryDetailsChartLane_stripeChangeListener_errorMessage())
88  .showError();
89  logger.log(Level.SEVERE, "Error adding stripe to chart lane.", ex);
90  }
91  }
92  requestChartLayout();
93 
94  getSelectedNodes().addListener((ListChangeListener.Change<? extends EventNodeBase<?>> change) -> {
95  while (change.next()) {
96  change.getRemoved().forEach(removedNode -> {
97  removedNode.getEvent().getClusters().forEach(cluster -> {
98  Line removedLine = projectionMap.remove(cluster);
99  getChartChildren().removeAll(removedLine);
100  });
101 
102  });
103  change.getAddedSubList().forEach(addedNode -> {
104  for (EventCluster range : addedNode.getEvent().getClusters()) {
105  double y = dateAxis.getLayoutY() + PROJECTED_LINE_Y_OFFSET; //NOPMD y is standard coord name
106  Line line
107  = new Line(dateAxis.localToParent(getXForEpochMillis(range.getStartMillis()), 0).getX(), y,
108  dateAxis.localToParent(getXForEpochMillis(range.getEndMillis()), 0).getX(), y);
109  line.setStroke(getColor(addedNode.getEventType()).deriveColor(0, 1, 1, .5));
110  line.setStrokeWidth(PROJECTED_LINE_STROKE_WIDTH);
111  line.setStrokeLineCap(StrokeLineCap.ROUND);
112  projectionMap.put(range, line);
113  getChartChildren().add(line);
114  }
115  });
116  }
117  });
118  }
119 
120  private double getParentXForEpochMillis(Long epochMillis) {
121  return getXAxis().localToParent(getXForEpochMillis(epochMillis), 0).getX();
122  }
123 
124  @Override
125  void doAdditionalLayout() {
126  for (final Map.Entry<EventCluster, Line> entry : projectionMap.entrySet()) {
127  final EventCluster cluster = entry.getKey();
128  final Line line = entry.getValue();
129 
130  line.setStartX(getParentXForEpochMillis(cluster.getStartMillis()));
131  line.setEndX(getParentXForEpochMillis(cluster.getEndMillis()));
132 
133  line.setStartY(getXAxis().getLayoutY() + PROJECTED_LINE_Y_OFFSET);
134  line.setEndY(getXAxis().getLayoutY() + PROJECTED_LINE_Y_OFFSET);
135  }
136  }
137 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
ObservableList< DescriptionFilterState > getQuickHideFilters()
static Color getColor(TimelineEventType type)

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