19 package org.sleuthkit.autopsy.geolocation;
21 import java.awt.event.ActionEvent;
22 import java.awt.image.BufferedImage;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Locale;
28 import java.util.logging.Level;
29 import javax.swing.AbstractAction;
30 import javax.swing.Action;
31 import javax.swing.ImageIcon;
32 import javax.swing.JMenuItem;
33 import org.jxmapviewer.viewer.GeoPosition;
34 import org.openide.util.NbBundle.Messages;
64 final class MapWaypoint
extends KdTree.XYZPoint implements
org.jxmapviewer.viewer.Waypoint {
66 private static final Logger logger = Logger.getLogger(MapWaypoint.class.getName());
67 private final static String HTML_PROP_FORMAT =
"<b>%s: </b>%s<br>";
68 static private final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ssX", Locale.US);
70 private final Waypoint dataModelWaypoint;
71 private final GeoPosition position;
82 static List<MapWaypoint> getWaypoints(SleuthkitCase skCase)
throws GeoLocationDataException {
83 List<Waypoint> points = WaypointBuilder.getAllWaypoints(skCase);
85 List<Route> routes = Route.getRoutes(skCase);
86 for (Route route : routes) {
87 points.addAll(route.getRoute());
90 List<MapWaypoint> mapPoints =
new ArrayList<>();
92 for (Waypoint point : points) {
93 mapPoints.add(
new MapWaypoint(point));
108 static List<MapWaypoint> getWaypoints(List<Waypoint> dmWaypoints) {
109 List<MapWaypoint> mapPoints =
new ArrayList<>();
111 if (dmWaypoints != null) {
113 for (Waypoint point : dmWaypoints) {
114 mapPoints.add(
new MapWaypoint(point));
130 static List<Waypoint> getDataModelWaypoints(List<MapWaypoint> mapWaypoints) {
131 List<Waypoint> waypoints =
new ArrayList<>();
133 if (mapWaypoints != null) {
134 for (MapWaypoint point : mapWaypoints) {
135 waypoints.add(point.dataModelWaypoint);
149 static MapWaypoint getDummyWaypoint(GeoPosition position) {
150 return new MapWaypoint(position);
158 private MapWaypoint(Waypoint dataModelWaypoint) {
159 super(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
160 this.dataModelWaypoint = dataModelWaypoint;
161 position =
new GeoPosition(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
169 private MapWaypoint(GeoPosition position) {
170 super(position.getLatitude(), position.getLongitude());
171 dataModelWaypoint = null;
172 this.position = position;
180 ImageIcon getImage() {
181 if (dataModelWaypoint.getImage() != null && ImageUtils.isImageThumbnailSupported(dataModelWaypoint.getImage())) {
182 BufferedImage buffImage = ImageUtils.getThumbnail(dataModelWaypoint.getImage(), 150);
183 return new ImageIcon(buffImage);
193 public GeoPosition getPosition() {
203 return dataModelWaypoint.getLabel();
211 String getHTMLFormattedWaypointDetails() {
212 return getFormattedDetails(dataModelWaypoint);
223 JMenuItem[] getMenuItems() throws TskCoreException {
224 List<JMenuItem> menuItems =
new ArrayList<>();
225 BlackboardArtifact artifact = dataModelWaypoint.getArtifact();
226 Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
228 menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
229 menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
230 menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
231 menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
233 return menuItems.toArray(
new JMenuItem[0]);
243 private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
244 List<JMenuItem> menuItems =
new ArrayList<>();
247 if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
248 menuItems.add(
new JMenuItem(
new ViewArtifactInTimelineAction(artifact)));
250 }
catch (TskCoreException ex) {
251 logger.log(Level.SEVERE, String.format(
"Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex);
268 "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
270 private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
271 List<JMenuItem> menuItems =
new ArrayList<>();
273 List<Action> actions = DataModelActionsFactory.getActions(content,
true);
274 for (Action action : actions) {
275 if (action == null) {
277 }
else if (action instanceof ExportCSVAction) {
279 }
else if (action instanceof AddContentTagAction) {
280 menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
281 }
else if (action instanceof AddBlackboardArtifactTagAction) {
282 menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
283 }
else if (action instanceof ExternalViewerShortcutAction) {
285 ExternalViewerAction newAction =
new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(),
new FileNode((AbstractFile) content));
286 menuItems.add(
new JMenuItem(newAction));
287 }
else if (action instanceof ExtractAction) {
288 menuItems.add(
new JMenuItem(
new WaypointExtractAction((AbstractFile) content)));
290 menuItems.add(
new JMenuItem(action));
304 private String getFormattedDetails(Waypoint point) {
305 StringBuilder result =
new StringBuilder();
307 result.append(
"<html>").append(formatAttribute(
"Name", point.getLabel()));
309 Long timestamp = point.getTimestamp();
310 if (timestamp != null) {
311 result.append(formatAttribute(
"Timestamp", getTimeStamp(timestamp)));
314 result.append(formatAttribute(
"Latitude", point.getLatitude().toString()))
315 .append(formatAttribute(
"Longitude", point.getLongitude().toString()));
317 if (point.getAltitude() != null) {
318 result.append(formatAttribute(
"Altitude", point.getAltitude().toString()));
321 List<Waypoint.Property> list = point.getOtherProperties();
322 for (Waypoint.Property prop : list) {
323 String value = prop.getValue();
324 if (value != null && !value.isEmpty()) {
325 result.append(formatAttribute(prop.getDisplayName(), value));
329 result.append(
"</html>");
331 return result.toString();
342 private String formatAttribute(String title, String value) {
343 return String.format(HTML_PROP_FORMAT, title, value);
353 private String getTimeStamp(
long timeStamp) {
354 return DATE_FORMAT.format(
new java.util.Date(timeStamp * 1000));
361 "WaypointExtractAction_label=Extract Files(s)"
363 final class WaypointExtractAction extends AbstractAction {
365 private static final long serialVersionUID = 1L;
366 final private AbstractFile file;
368 WaypointExtractAction(AbstractFile file) {
369 super(Bundle.WaypointExtractAction_label());
374 public void actionPerformed(ActionEvent e) {
375 ExtractActionHelper helper =
new ExtractActionHelper();
376 helper.extract(e, Arrays.asList(file));