Autopsy  4.17.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 public 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  artifactTypesToColors.put(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_AREA.getTypeID(), new Color(0x8a2be2)); // Blue violet
83  }
84 
85  private final Waypoint dataModelWaypoint;
86  private final GeoPosition position;
87 
97  static Set<MapWaypoint> getWaypoints(List<Waypoint> dmWaypoints) {
98  Set<MapWaypoint> mapPoints = new LinkedHashSet<>();
99 
100  if (dmWaypoints != null) {
101 
102  for (Waypoint point : dmWaypoints) {
103  mapPoints.add(new MapWaypoint(point));
104  }
105  }
106 
107  return mapPoints;
108  }
109 
119  static List<Waypoint> getDataModelWaypoints(List<MapWaypoint> mapWaypoints) {
120  List<Waypoint> waypoints = new ArrayList<>();
121 
122  if (mapWaypoints != null) {
123  for (MapWaypoint point : mapWaypoints) {
124  waypoints.add(point.dataModelWaypoint);
125  }
126  }
127 
128  return waypoints;
129  }
130 
138  static MapWaypoint getDummyWaypoint(GeoPosition position) {
139  return new MapWaypoint(position);
140  }
141 
147  private MapWaypoint(Waypoint dataModelWaypoint) {
148  super(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
149  this.dataModelWaypoint = dataModelWaypoint;
150  position = new GeoPosition(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
151  }
152 
158  private MapWaypoint(GeoPosition position) {
159  super(position.getLatitude(), position.getLongitude());
160  dataModelWaypoint = null;
161  this.position = position;
162  }
163 
169  ImageIcon getImage() {
170  if (dataModelWaypoint.getImage() != null && ImageUtils.isImageThumbnailSupported(dataModelWaypoint.getImage())) {
171  BufferedImage buffImage = ImageUtils.getThumbnail(dataModelWaypoint.getImage(), 150);
172  return new ImageIcon(buffImage);
173  }
174 
175  return null;
176  }
177 
181  @Override
182  public GeoPosition getPosition() {
183  return position;
184  }
185 
191  String getLabel() {
192  return dataModelWaypoint.getLabel();
193  }
194 
200  String getHTMLFormattedWaypointDetails() {
201  return getFormattedDetails(dataModelWaypoint);
202  }
203 
207  int getArtifactTypeID() {
208  return dataModelWaypoint.getArtifact().getArtifactTypeID();
209  }
210 
219  JMenuItem[] getMenuItems() throws TskCoreException {
220  List<JMenuItem> menuItems = new ArrayList<>();
221  BlackboardArtifact artifact = dataModelWaypoint.getArtifact();
222  Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
223 
224  menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
225  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
226  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
227  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
228 
229  return menuItems.toArray(new JMenuItem[0]);
230  }
231 
239  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
240  List<JMenuItem> menuItems = new ArrayList<>();
241  //if this artifact has a time stamp add the action to view it in the timeline
242  try {
244  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
245  }
246  } catch (TskCoreException ex) {
247  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
248  }
249 
250  return menuItems;
251  }
252 
263  @Messages({
264  "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
265  })
266  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
267  List<JMenuItem> menuItems = new ArrayList<>();
268 
269  List<Action> actions = DataModelActionsFactory.getActions(content, true);
270  for (Action action : actions) {
271  if (action == null) {
272  menuItems.add(null);
273  } else if (action instanceof ExportCSVAction) {
274  // Do nothing we don't need this menu item.
275  } else if (action instanceof AddContentTagAction) {
276  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
277  } else if (action instanceof AddBlackboardArtifactTagAction) {
278  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
279  } else if (action instanceof ExternalViewerShortcutAction) {
280  // Replace with an ExternalViewerAction
281  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(), new FileNode((AbstractFile) content));
282  menuItems.add(new JMenuItem(newAction));
283  } else if (action instanceof ExtractAction) {
284  menuItems.add(new JMenuItem(new WaypointExtractAction((AbstractFile) content)));
285  } else {
286  menuItems.add(new JMenuItem(action));
287  }
288  }
289  return menuItems;
290  }
291 
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  public Long getTimestamp() {
372  return dataModelWaypoint.getTimestamp();
373  }
374 
378  @Messages({
379  "WaypointExtractAction_label=Extract Files(s)"
380  })
381  final class WaypointExtractAction extends AbstractAction {
382 
383  private static final long serialVersionUID = 1L;
384  final private AbstractFile file;
385 
386  WaypointExtractAction(AbstractFile file) {
387  super(Bundle.WaypointExtractAction_label());
388  this.file = file;
389  }
390 
391  @Override
392  public void actionPerformed(ActionEvent e) {
393  ExtractActionHelper helper = new ExtractActionHelper();
394  helper.extract(e, Arrays.asList(file));
395 
396  }
397  }
398 }
static List< Action > getActions(File file, boolean isArtifactSource)
String formatAttribute(String title, String value)
List< JMenuItem > getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content)
List< JMenuItem > getTimelineMenuItems(BlackboardArtifact artifact)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static boolean isImageThumbnailSupported(AbstractFile file)
static BufferedImage getThumbnail(Content content, int iconSize)

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