Autopsy 4.22.1
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 */
19package org.sleuthkit.autopsy.geolocation;
20
21import java.awt.Color;
22import java.awt.event.ActionEvent;
23import java.awt.image.BufferedImage;
24import java.text.SimpleDateFormat;
25import java.util.ArrayList;
26import java.util.Arrays;
27import java.util.HashMap;
28import java.util.LinkedHashSet;
29import java.util.List;
30import java.util.Locale;
31import java.util.Map;
32import java.util.Set;
33import java.util.logging.Level;
34import javax.swing.AbstractAction;
35import javax.swing.Action;
36import javax.swing.ImageIcon;
37import javax.swing.JMenuItem;
38import org.jxmapviewer.viewer.GeoPosition;
39import org.openide.util.NbBundle.Messages;
40import org.sleuthkit.autopsy.actions.AddBlackboardArtifactTagAction;
41import org.sleuthkit.autopsy.actions.AddContentTagAction;
42import org.sleuthkit.autopsy.actions.DeleteFileBlackboardArtifactTagAction;
43import org.sleuthkit.autopsy.actions.DeleteFileContentTagAction;
44import org.sleuthkit.autopsy.coreutils.ImageUtils;
45import org.sleuthkit.autopsy.coreutils.Logger;
46import org.sleuthkit.autopsy.datamodel.DataModelActionsFactory;
47import org.sleuthkit.autopsy.datamodel.FileNode;
48import org.sleuthkit.autopsy.directorytree.ExportCSVAction;
49import org.sleuthkit.autopsy.directorytree.ExternalViewerAction;
50import org.sleuthkit.autopsy.directorytree.ExternalViewerShortcutAction;
51import org.sleuthkit.autopsy.directorytree.ExtractAction;
52import org.sleuthkit.autopsy.directorytree.actionhelpers.ExtractActionHelper;
53import org.sleuthkit.autopsy.geolocation.datamodel.Waypoint;
54import org.sleuthkit.autopsy.timeline.actions.ViewArtifactInTimelineAction;
55import org.sleuthkit.datamodel.AbstractFile;
56import org.sleuthkit.datamodel.BlackboardArtifact;
57import org.sleuthkit.datamodel.Content;
58import org.sleuthkit.datamodel.TskCoreException;
59
65@SuppressWarnings("deprecation")
66public 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
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
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 boolean isImageThumbnailSupported(AbstractFile file)
static BufferedImage getThumbnail(Content content, int iconSize)
synchronized static Logger getLogger(String name)
Definition Logger.java:124
static List< Action > getActions(File file, boolean isArtifactSource)
List< JMenuItem > getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content)
static final SimpleDateFormat DATE_FORMAT
static final Map< Integer, Color > artifactTypesToColors
List< JMenuItem > getTimelineMenuItems(BlackboardArtifact artifact)
String formatAttribute(String title, String value)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.