Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MapWaypoint.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 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.geolocation;
20 
21 import java.awt.Color;
22 import java.awt.event.ActionEvent;
23 import java.awt.image.BufferedImage;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.LinkedHashSet;
29 import java.util.List;
30 import java.util.Locale;
31 import java.util.Map;
32 import java.util.Set;
33 import java.util.logging.Level;
34 import javax.swing.AbstractAction;
35 import javax.swing.Action;
36 import javax.swing.ImageIcon;
37 import javax.swing.JMenuItem;
38 import org.jxmapviewer.viewer.GeoPosition;
39 import org.openide.util.NbBundle.Messages;
55 import org.sleuthkit.datamodel.AbstractFile;
56 import org.sleuthkit.datamodel.BlackboardArtifact;
57 import org.sleuthkit.datamodel.Content;
58 import org.sleuthkit.datamodel.TskCoreException;
59 
65 @SuppressWarnings("deprecation")
66 final class MapWaypoint extends KdTree.XYZPoint implements org.jxmapviewer.viewer.Waypoint {
67 
68  private static final Logger logger = Logger.getLogger(MapWaypoint.class.getName());
69  private final static String HTML_PROP_FORMAT = "<b>%s: </b>%s<br>";
70  static private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX", Locale.US);
71 
72  private static final Map<Integer, Color> artifactTypesToColors = new HashMap<>();
73 
74  static {
75  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_BOOKMARK.getTypeID(), Color.BLUE);
76  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_LAST_KNOWN_LOCATION.getTypeID(), Color.RED);
77  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE.getTypeID(), Color.CYAN);
78  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_SEARCH.getTypeID(), Color.GREEN);
79  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACK.getTypeID(), Color.ORANGE);
80  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT.getTypeID(), Color.ORANGE);
81  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF.getTypeID(), Color.MAGENTA);
82  }
83 
84  private final Waypoint dataModelWaypoint;
85  private final GeoPosition position;
86 
96  static Set<MapWaypoint> getWaypoints(List<Waypoint> dmWaypoints) {
97  Set<MapWaypoint> mapPoints = new LinkedHashSet<>();
98 
99  if (dmWaypoints != null) {
100 
101  for (Waypoint point : dmWaypoints) {
102  mapPoints.add(new MapWaypoint(point));
103  }
104  }
105 
106  return mapPoints;
107  }
108 
118  static List<Waypoint> getDataModelWaypoints(List<MapWaypoint> mapWaypoints) {
119  List<Waypoint> waypoints = new ArrayList<>();
120 
121  if (mapWaypoints != null) {
122  for (MapWaypoint point : mapWaypoints) {
123  waypoints.add(point.dataModelWaypoint);
124  }
125  }
126 
127  return waypoints;
128  }
129 
137  static MapWaypoint getDummyWaypoint(GeoPosition position) {
138  return new MapWaypoint(position);
139  }
140 
146  private MapWaypoint(Waypoint dataModelWaypoint) {
147  super(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
148  this.dataModelWaypoint = dataModelWaypoint;
149  position = new GeoPosition(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
150  }
151 
157  private MapWaypoint(GeoPosition position) {
158  super(position.getLatitude(), position.getLongitude());
159  dataModelWaypoint = null;
160  this.position = position;
161  }
162 
168  ImageIcon getImage() {
169  if (dataModelWaypoint.getImage() != null && ImageUtils.isImageThumbnailSupported(dataModelWaypoint.getImage())) {
170  BufferedImage buffImage = ImageUtils.getThumbnail(dataModelWaypoint.getImage(), 150);
171  return new ImageIcon(buffImage);
172  }
173 
174  return null;
175  }
176 
180  @Override
181  public GeoPosition getPosition() {
182  return position;
183  }
184 
190  String getLabel() {
191  return dataModelWaypoint.getLabel();
192  }
193 
199  String getHTMLFormattedWaypointDetails() {
200  return getFormattedDetails(dataModelWaypoint);
201  }
202 
206  int getArtifactTypeID() {
207  return dataModelWaypoint.getArtifact().getArtifactTypeID();
208  }
209 
218  JMenuItem[] getMenuItems() throws TskCoreException {
219  List<JMenuItem> menuItems = new ArrayList<>();
220  BlackboardArtifact artifact = dataModelWaypoint.getArtifact();
221  Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
222 
223  menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
224  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
225  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
226  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
227 
228  return menuItems.toArray(new JMenuItem[0]);
229  }
230 
238  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
239  List<JMenuItem> menuItems = new ArrayList<>();
240  //if this artifact has a time stamp add the action to view it in the timeline
241  try {
242  if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
243  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
244  }
245  } catch (TskCoreException ex) {
246  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
247  }
248 
249  return menuItems;
250  }
251 
262  @Messages({
263  "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
264  })
265  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
266  List<JMenuItem> menuItems = new ArrayList<>();
267 
268  List<Action> actions = DataModelActionsFactory.getActions(content, true);
269  for (Action action : actions) {
270  if (action == null) {
271  menuItems.add(null);
272  } else if (action instanceof ExportCSVAction) {
273  // Do nothing we don't need this menu item.
274  } else if (action instanceof AddContentTagAction) {
275  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
276  } else if (action instanceof AddBlackboardArtifactTagAction) {
277  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
278  } else if (action instanceof ExternalViewerShortcutAction) {
279  // Replace with an ExternalViewerAction
280  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(), new FileNode((AbstractFile) content));
281  menuItems.add(new JMenuItem(newAction));
282  } else if (action instanceof ExtractAction) {
283  menuItems.add(new JMenuItem(new WaypointExtractAction((AbstractFile) content)));
284  } else {
285  menuItems.add(new JMenuItem(action));
286  }
287  }
288  return menuItems;
289  }
290 
299  private String getFormattedDetails(Waypoint point) {
300  StringBuilder result = new StringBuilder(); //NON-NLS
301 
302  result.append("<html>").append(formatAttribute("Name", point.getLabel()));
303 
304  Long timestamp = point.getTimestamp();
305  if (timestamp != null) {
306  result.append(formatAttribute("Timestamp", getTimeStamp(timestamp)));
307  }
308 
309  result.append(formatAttribute("Latitude", point.getLatitude().toString()))
310  .append(formatAttribute("Longitude", point.getLongitude().toString()));
311 
312  if (point.getAltitude() != null) {
313  result.append(formatAttribute("Altitude", point.getAltitude().toString()));
314  }
315 
316  List<Waypoint.Property> list = point.getOtherProperties();
317  for (Waypoint.Property prop : list) {
318  String value = prop.getValue();
319  if (value != null && !value.isEmpty()) {
320  result.append(formatAttribute(prop.getDisplayName(), value));
321  }
322  }
323 
324  result.append("</html>");
325 
326  return result.toString();
327  }
328 
337  private String formatAttribute(String title, String value) {
338  return String.format(HTML_PROP_FORMAT, title, value);
339  }
340 
348  private String getTimeStamp(long timeStamp) {
349  return DATE_FORMAT.format(new java.util.Date(timeStamp * 1000));
350  }
351 
356  static Color getColor(int artifactTypeId) {
357  return artifactTypesToColors.getOrDefault(artifactTypeId, Color.GRAY);
358  }
359 
364  Color getColor() {
365  return getColor(dataModelWaypoint.getArtifact().getArtifactTypeID());
366  }
367 
371  @Messages({
372  "WaypointExtractAction_label=Extract Files(s)"
373  })
374  final class WaypointExtractAction extends AbstractAction {
375 
376  private static final long serialVersionUID = 1L;
377  final private AbstractFile file;
378 
379  WaypointExtractAction(AbstractFile file) {
380  super(Bundle.WaypointExtractAction_label());
381  this.file = file;
382  }
383 
384  @Override
385  public void actionPerformed(ActionEvent e) {
386  ExtractActionHelper helper = new ExtractActionHelper();
387  helper.extract(e, Arrays.asList(file));
388 
389  }
390  }
391 }

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.