Autopsy  4.21.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 = dataModelWaypoint.getContent();
223 
224  menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
225  menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
226  if (content instanceof AbstractFile) {
227  menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
228  }
229  menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
230 
231  return menuItems.toArray(new JMenuItem[0]);
232  }
233 
241  private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
242  List<JMenuItem> menuItems = new ArrayList<>();
243  //if this artifact has a time stamp add the action to view it in the timeline
244  try {
246  menuItems.add(new JMenuItem(new ViewArtifactInTimelineAction(artifact)));
247  }
248  } catch (TskCoreException ex) {
249  logger.log(Level.SEVERE, String.format("Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex); //NON-NLS
250  }
251 
252  return menuItems;
253  }
254 
265  @Messages({
266  "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
267  })
268  private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
269  List<JMenuItem> menuItems = new ArrayList<>();
270 
271  List<Action> actions = DataModelActionsFactory.getActions(content, true);
272  for (Action action : actions) {
273  if (action == null) {
274  menuItems.add(null);
275  } else if (action instanceof ExportCSVAction) {
276  // Do nothing we don't need this menu item.
277  } else if (action instanceof AddContentTagAction) {
278  menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
279  } else if (action instanceof AddBlackboardArtifactTagAction) {
280  menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
281  } else if (action instanceof ExternalViewerShortcutAction) {
282  // Replace with an ExternalViewerAction
283  ExternalViewerAction newAction = new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(), new FileNode((AbstractFile) content));
284  menuItems.add(new JMenuItem(newAction));
285  } else if (action instanceof ExtractAction) {
286  menuItems.add(new JMenuItem(new WaypointExtractAction((AbstractFile) content)));
287  } else {
288  menuItems.add(new JMenuItem(action));
289  }
290  }
291  return menuItems;
292  }
293 
301  private String getFormattedDetails(Waypoint point) {
302  StringBuilder result = new StringBuilder(); //NON-NLS
303 
304  result.append("<html>").append(formatAttribute("Name", point.getLabel()));
305 
306  Long timestamp = point.getTimestamp();
307  if (timestamp != null) {
308  result.append(formatAttribute("Timestamp", getTimeStamp(timestamp)));
309  }
310 
311  result.append(formatAttribute("Latitude", point.getLatitude().toString()))
312  .append(formatAttribute("Longitude", point.getLongitude().toString()));
313 
314  if (point.getAltitude() != null) {
315  result.append(formatAttribute("Altitude", point.getAltitude().toString()));
316  }
317 
318  List<Waypoint.Property> list = point.getOtherProperties();
319  for (Waypoint.Property prop : list) {
320  String value = prop.getValue();
321  if (value != null && !value.isEmpty()) {
322  result.append(formatAttribute(prop.getDisplayName(), value));
323  }
324  }
325 
326  result.append("</html>");
327 
328  return result.toString();
329  }
330 
339  private String formatAttribute(String title, String value) {
340  return String.format(HTML_PROP_FORMAT, title, value);
341  }
342 
350  private String getTimeStamp(long timeStamp) {
351  return DATE_FORMAT.format(new java.util.Date(timeStamp * 1000));
352  }
353 
358  static Color getColor(int artifactTypeId) {
359  return artifactTypesToColors.getOrDefault(artifactTypeId, Color.GRAY);
360  }
361 
366  Color getColor() {
367  return getColor(dataModelWaypoint.getArtifact().getArtifactTypeID());
368  }
369 
373  public Long getTimestamp() {
374  return dataModelWaypoint.getTimestamp();
375  }
376 
380  @Messages({
381  "WaypointExtractAction_label=Extract Files(s)"
382  })
383  final class WaypointExtractAction extends AbstractAction {
384 
385  private static final long serialVersionUID = 1L;
386  final private AbstractFile file;
387 
388  WaypointExtractAction(AbstractFile file) {
389  super(Bundle.WaypointExtractAction_label());
390  this.file = file;
391  }
392 
393  @Override
394  public void actionPerformed(ActionEvent e) {
395  ExtractActionHelper helper = new ExtractActionHelper();
396  helper.extract(e, Arrays.asList(file));
397 
398  }
399  }
400 }
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-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.