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.LinkedHashSet;
27 import java.util.List;
28 import java.util.Locale;
30 import java.util.logging.Level;
31 import javax.swing.AbstractAction;
32 import javax.swing.Action;
33 import javax.swing.ImageIcon;
34 import javax.swing.JMenuItem;
35 import org.jxmapviewer.viewer.GeoPosition;
36 import org.openide.util.NbBundle.Messages;
62 final class MapWaypoint
extends KdTree.XYZPoint implements
org.jxmapviewer.viewer.Waypoint {
64 private static final Logger logger = Logger.getLogger(MapWaypoint.class.getName());
65 private final static String HTML_PROP_FORMAT =
"<b>%s: </b>%s<br>";
66 static private final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ssX", Locale.US);
68 private final Waypoint dataModelWaypoint;
69 private final GeoPosition position;
80 static Set<MapWaypoint> getWaypoints(List<Waypoint> dmWaypoints) {
81 Set<MapWaypoint> mapPoints =
new LinkedHashSet<>();
83 if (dmWaypoints != null) {
85 for (Waypoint point : dmWaypoints) {
86 mapPoints.add(
new MapWaypoint(point));
102 static List<Waypoint> getDataModelWaypoints(List<MapWaypoint> mapWaypoints) {
103 List<Waypoint> waypoints =
new ArrayList<>();
105 if (mapWaypoints != null) {
106 for (MapWaypoint point : mapWaypoints) {
107 waypoints.add(point.dataModelWaypoint);
121 static MapWaypoint getDummyWaypoint(GeoPosition position) {
122 return new MapWaypoint(position);
130 private MapWaypoint(Waypoint dataModelWaypoint) {
131 super(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
132 this.dataModelWaypoint = dataModelWaypoint;
133 position =
new GeoPosition(dataModelWaypoint.getLatitude(), dataModelWaypoint.getLongitude());
141 private MapWaypoint(GeoPosition position) {
142 super(position.getLatitude(), position.getLongitude());
143 dataModelWaypoint = null;
144 this.position = position;
152 ImageIcon getImage() {
153 if (dataModelWaypoint.getImage() != null && ImageUtils.isImageThumbnailSupported(dataModelWaypoint.getImage())) {
154 BufferedImage buffImage = ImageUtils.getThumbnail(dataModelWaypoint.getImage(), 150);
155 return new ImageIcon(buffImage);
165 public GeoPosition getPosition() {
175 return dataModelWaypoint.getLabel();
183 String getHTMLFormattedWaypointDetails() {
184 return getFormattedDetails(dataModelWaypoint);
195 JMenuItem[] getMenuItems() throws TskCoreException {
196 List<JMenuItem> menuItems =
new ArrayList<>();
197 BlackboardArtifact artifact = dataModelWaypoint.getArtifact();
198 Content content = artifact.getSleuthkitCase().getContentById(artifact.getObjectID());
200 menuItems.addAll(getTimelineMenuItems(dataModelWaypoint.getArtifact()));
201 menuItems.addAll(getDataModelActionFactoryMenuItems(artifact, content));
202 menuItems.add(DeleteFileContentTagAction.getInstance().getMenuForFiles(Arrays.asList((AbstractFile) content)));
203 menuItems.add(DeleteFileBlackboardArtifactTagAction.getInstance().getMenuForArtifacts(Arrays.asList(artifact)));
205 return menuItems.toArray(
new JMenuItem[0]);
215 private List<JMenuItem> getTimelineMenuItems(BlackboardArtifact artifact) {
216 List<JMenuItem> menuItems =
new ArrayList<>();
219 if (ViewArtifactInTimelineAction.hasSupportedTimeStamp(artifact)) {
220 menuItems.add(
new JMenuItem(
new ViewArtifactInTimelineAction(artifact)));
222 }
catch (TskCoreException ex) {
223 logger.log(Level.SEVERE, String.format(
"Error getting arttribute(s) from blackboard artifact %d.", artifact.getArtifactID()), ex);
240 "MayWaypoint_ExternalViewer_label=Open in ExternalViewer"
242 private List<JMenuItem> getDataModelActionFactoryMenuItems(BlackboardArtifact artifact, Content content) {
243 List<JMenuItem> menuItems =
new ArrayList<>();
245 List<Action> actions = DataModelActionsFactory.getActions(content,
true);
246 for (Action action : actions) {
247 if (action == null) {
249 }
else if (action instanceof ExportCSVAction) {
251 }
else if (action instanceof AddContentTagAction) {
252 menuItems.add(((AddContentTagAction) action).getMenuForContent(Arrays.asList((AbstractFile) content)));
253 }
else if (action instanceof AddBlackboardArtifactTagAction) {
254 menuItems.add(((AddBlackboardArtifactTagAction) action).getMenuForContent(Arrays.asList(artifact)));
255 }
else if (action instanceof ExternalViewerShortcutAction) {
257 ExternalViewerAction newAction =
new ExternalViewerAction(Bundle.MayWaypoint_ExternalViewer_label(),
new FileNode((AbstractFile) content));
258 menuItems.add(
new JMenuItem(newAction));
259 }
else if (action instanceof ExtractAction) {
260 menuItems.add(
new JMenuItem(
new WaypointExtractAction((AbstractFile) content)));
262 menuItems.add(
new JMenuItem(action));
276 private String getFormattedDetails(Waypoint point) {
277 StringBuilder result =
new StringBuilder();
279 result.append(
"<html>").append(formatAttribute(
"Name", point.getLabel()));
281 Long timestamp = point.getTimestamp();
282 if (timestamp != null) {
283 result.append(formatAttribute(
"Timestamp", getTimeStamp(timestamp)));
286 result.append(formatAttribute(
"Latitude", point.getLatitude().toString()))
287 .append(formatAttribute(
"Longitude", point.getLongitude().toString()));
289 if (point.getAltitude() != null) {
290 result.append(formatAttribute(
"Altitude", point.getAltitude().toString()));
293 List<Waypoint.Property> list = point.getOtherProperties();
294 for (Waypoint.Property prop : list) {
295 String value = prop.getValue();
296 if (value != null && !value.isEmpty()) {
297 result.append(formatAttribute(prop.getDisplayName(), value));
301 result.append(
"</html>");
303 return result.toString();
314 private String formatAttribute(String title, String value) {
315 return String.format(HTML_PROP_FORMAT, title, value);
325 private String getTimeStamp(
long timeStamp) {
326 return DATE_FORMAT.format(
new java.util.Date(timeStamp * 1000));
333 "WaypointExtractAction_label=Extract Files(s)"
335 final class WaypointExtractAction extends AbstractAction {
337 private static final long serialVersionUID = 1L;
338 final private AbstractFile file;
340 WaypointExtractAction(AbstractFile file) {
341 super(Bundle.WaypointExtractAction_label());
346 public void actionPerformed(ActionEvent e) {
347 ExtractActionHelper helper =
new ExtractActionHelper();
348 helper.extract(e, Arrays.asList(file));