19 package org.sleuthkit.autopsy.datasourcesummary.ui;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import java.util.stream.Collectors;
28 import java.util.stream.Stream;
29 import javax.swing.JButton;
30 import org.apache.commons.collections.CollectionUtils;
31 import org.apache.commons.lang3.StringUtils;
32 import org.apache.commons.lang3.tuple.Pair;
33 import org.openide.util.NbBundle.Messages;
34 import org.openide.util.actions.CallableSystemAction;
35 import org.openide.windows.TopComponent;
36 import org.openide.windows.WindowManager;
62 "GeolocationPanel_cityColumn_title=Closest City",
63 "GeolocationPanel_countColumn_title=Count",
64 "GeolocationPanel_onNoCrIngest_message=No results will be shown because the GPX Parser was not run.",
65 "GeolocationPanel_unknownRow_title=Unknown",
66 "GeolocationPanel_mostCommon_tabName=Most Common Cities",
67 "GeolocationPanel_mostRecent_tabName=Most Recent Cities",})
86 GeolocationViewModel(List<Pair<String, Integer>> mostRecentData, List<Pair<String, Integer>> mostCommonData) {
87 this.mostRecentData = mostRecentData;
88 this.mostCommonData = mostCommonData;
96 List<Pair<String, Integer>> getMostRecentData() {
97 return mostRecentData;
105 List<Pair<String, Integer>> getMostCommonData() {
106 return mostCommonData;
110 private static final long serialVersionUID = 1L;
111 private static final int DAYS_COUNT = 30;
112 private static final int MAX_COUNT = 10;
116 Bundle.GeolocationPanel_cityColumn_title(),
123 Bundle.GeolocationPanel_countColumn_title(),
128 private static final List<ColumnModel<Pair<String, Integer>,
DefaultCellModel<?>>> DEFAULT_TEMPLATE = Arrays.asList(
135 .setKeyFunction((pair) -> pair.getLeft());
138 .setKeyFunction((pair) -> pair.getLeft());
141 private final List<JTablePanel<?>> tables = Arrays.asList(mostCommonTable, mostRecentTable);
167 super(whereUsedData);
169 this.whereUsedData = whereUsedData;
171 this.geolocationFetcher = (dataSource) -> convertToViewModel(whereUsedData.
getCityCounts(dataSource, DAYS_COUNT, MAX_COUNT));
174 dataFetchComponents = Arrays.asList(
177 (result) -> handleData(result)));
189 showCityContent(
DataFetchResult.
getSubResult(result, (dr) -> dr.getMostCommonData()), mostCommonTable, commonViewInGeolocationBtn);
190 showCityContent(
DataFetchResult.
getSubResult(result, (dr) -> dr.getMostRecentData()), mostRecentTable, recentViewInGeolocationBtn);
200 if (record == null) {
205 .filter(StringUtils::isNotBlank)
206 .collect(Collectors.toList());
208 if (cityIdentifiers.size() == 1) {
209 return cityIdentifiers.get(0);
210 }
else if (cityIdentifiers.size() == 2) {
211 return String.format(
"%s, %s", cityIdentifiers.get(0), cityIdentifiers.get(1));
212 }
else if (cityIdentifiers.size() >= 3) {
213 return String.format(
"%s, %s; %s", cityIdentifiers.get(0), cityIdentifiers.get(1), cityIdentifiers.get(2));
227 if (cityCount == null) {
233 return Pair.of(cityName, count);
246 if (countsList == null) {
247 return Collections.emptyList();
250 Stream<CityRecordCount> countsStream = ((countsList.
getCounts() == null)
251 ?
new ArrayList<CityRecordCount>()
254 Stream<Pair<String, Integer>> pairStream = countsStream.map((r) -> formatRecord(r));
256 Pair<String, Integer> unknownRecord = Pair.of(Bundle.GeolocationPanel_unknownRow_title(), countsList.
getOtherCount());
258 return Stream.concat(pairStream, Stream.of(unknownRecord))
259 .filter((p) -> p != null && p.getRight() != null && p.getRight() > 0)
260 .sorted((a, b) -> -Integer.compare(a.getRight(), b.getRight()))
262 .collect(Collectors.toList());
273 if (cityData == null) {
289 goToGeolocation.setEnabled(
true);
292 table.showDataFetchResult(result);
308 TopComponent topComponent = WindowManager.getDefault().findTopComponent(
GeolocationTopComponent.class.getSimpleName());
310 GeolocationTopComponent geoComponent = (GeolocationTopComponent) topComponent;
314 :
new GeoFilter(
false,
false, DAYS_COUNT, Arrays.asList(dataSource), whereUsedData.
getGeoTypes());
319 logger.log(Level.WARNING,
"There was an error setting filters in the GeoLocationTopComponent.", ex);
325 if (action == null) {
326 logger.log(Level.WARNING,
"Unable to obtain an OpenGeolocationAction instance from CallableSystemAction.");
336 commonViewInGeolocationBtn.setEnabled(
false);
337 recentViewInGeolocationBtn.setEnabled(
false);
343 fetchInformation(dataFetchComponents, dataSource);
349 onNewDataSource(dataFetchComponents, tables, dataSource);
354 GeolocationViewModel model = getFetchResult(geolocationFetcher,
"Geolocation sheets", dataSource);
356 return Collections.emptyList();
359 return Arrays.asList(
360 getTableExport(DEFAULT_TEMPLATE, Bundle.GeolocationPanel_mostRecent_tabName(), model.getMostRecentData()),
361 getTableExport(DEFAULT_TEMPLATE, Bundle.GeolocationPanel_mostCommon_tabName(), model.getMostCommonData())
376 @SuppressWarnings(
"unchecked")
378 private
void initComponents() {
380 javax.swing.JScrollPane mainScrollPane =
new javax.swing.JScrollPane();
381 javax.swing.JPanel mainContentPanel =
new javax.swing.JPanel();
382 javax.swing.JPanel ingestRunningPanel = ingestRunningLabel;
383 javax.swing.JLabel mostRecentLabel =
new javax.swing.JLabel();
384 javax.swing.Box.Filler filler1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2));
385 javax.swing.JPanel mostRecentPanel = mostRecentTable;
386 javax.swing.Box.Filler filler2 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2));
387 javax.swing.JLabel withinDistanceLabel =
new javax.swing.JLabel();
388 javax.swing.Box.Filler filler3 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 5),
new java.awt.Dimension(0, 5),
new java.awt.Dimension(0, 5));
389 recentViewInGeolocationBtn =
new javax.swing.JButton();
390 javax.swing.Box.Filler filler8 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 20),
new java.awt.Dimension(0, 20),
new java.awt.Dimension(0, 20));
391 javax.swing.JLabel mostCommonLabel =
new javax.swing.JLabel();
392 javax.swing.Box.Filler filler7 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2));
393 javax.swing.JPanel mostCommonPanel = mostCommonTable;
394 javax.swing.Box.Filler filler6 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2),
new java.awt.Dimension(0, 2));
395 javax.swing.JLabel withinDistanceLabel1 =
new javax.swing.JLabel();
396 javax.swing.Box.Filler filler4 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 5),
new java.awt.Dimension(0, 5),
new java.awt.Dimension(0, 5));
397 commonViewInGeolocationBtn =
new javax.swing.JButton();
398 javax.swing.Box.Filler filler5 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 32767));
400 mainContentPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
401 mainContentPanel.setLayout(
new javax.swing.BoxLayout(mainContentPanel, javax.swing.BoxLayout.PAGE_AXIS));
403 ingestRunningPanel.setAlignmentX(0.0F);
404 ingestRunningPanel.setMaximumSize(
new java.awt.Dimension(32767, 25));
405 ingestRunningPanel.setMinimumSize(
new java.awt.Dimension(10, 25));
406 ingestRunningPanel.setPreferredSize(
new java.awt.Dimension(10, 25));
407 mainContentPanel.add(ingestRunningPanel);
409 org.openide.awt.Mnemonics.setLocalizedText(mostRecentLabel,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.mostRecentLabel.text"));
410 mainContentPanel.add(mostRecentLabel);
411 mostRecentLabel.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"PastCasesPanel.notableFileLabel.text"));
413 filler1.setAlignmentX(0.0F);
414 mainContentPanel.add(filler1);
416 mostRecentPanel.setAlignmentX(0.0F);
417 mostRecentPanel.setMaximumSize(
new java.awt.Dimension(32767, 106));
418 mostRecentPanel.setMinimumSize(
new java.awt.Dimension(100, 106));
419 mostRecentPanel.setPreferredSize(
new java.awt.Dimension(100, 106));
420 mainContentPanel.add(mostRecentPanel);
422 filler2.setAlignmentX(0.0F);
423 mainContentPanel.add(filler2);
425 org.openide.awt.Mnemonics.setLocalizedText(withinDistanceLabel,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.withinDistanceLabel.text"));
426 mainContentPanel.add(withinDistanceLabel);
428 filler3.setAlignmentX(0.0F);
429 mainContentPanel.add(filler3);
431 org.openide.awt.Mnemonics.setLocalizedText(recentViewInGeolocationBtn,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.recentViewInGeolocationBtn.text"));
432 recentViewInGeolocationBtn.setEnabled(
false);
433 recentViewInGeolocationBtn.addActionListener(
new java.awt.event.ActionListener() {
434 public void actionPerformed(java.awt.event.ActionEvent evt) {
435 recentViewInGeolocationBtnActionPerformed(evt);
438 mainContentPanel.add(recentViewInGeolocationBtn);
440 filler8.setAlignmentX(0.0F);
441 mainContentPanel.add(filler8);
443 org.openide.awt.Mnemonics.setLocalizedText(mostCommonLabel,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.mostCommonLabel.text"));
444 mainContentPanel.add(mostCommonLabel);
446 filler7.setAlignmentX(0.0F);
447 mainContentPanel.add(filler7);
449 mostCommonPanel.setAlignmentX(0.0F);
450 mostCommonPanel.setMaximumSize(
new java.awt.Dimension(32767, 106));
451 mostCommonPanel.setMinimumSize(
new java.awt.Dimension(100, 106));
452 mostCommonPanel.setPreferredSize(
new java.awt.Dimension(100, 106));
453 mainContentPanel.add(mostCommonPanel);
455 filler6.setAlignmentX(0.0F);
456 mainContentPanel.add(filler6);
458 org.openide.awt.Mnemonics.setLocalizedText(withinDistanceLabel1,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.withinDistanceLabel1.text"));
459 mainContentPanel.add(withinDistanceLabel1);
461 filler4.setAlignmentX(0.0F);
462 mainContentPanel.add(filler4);
464 org.openide.awt.Mnemonics.setLocalizedText(commonViewInGeolocationBtn,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.commonViewInGeolocationBtn.text"));
465 commonViewInGeolocationBtn.setEnabled(
false);
466 commonViewInGeolocationBtn.addActionListener(
new java.awt.event.ActionListener() {
467 public void actionPerformed(java.awt.event.ActionEvent evt) {
468 commonViewInGeolocationBtnActionPerformed(evt);
471 mainContentPanel.add(commonViewInGeolocationBtn);
473 filler5.setAlignmentX(0.0F);
474 mainContentPanel.add(filler5);
476 mainScrollPane.setViewportView(mainContentPanel);
478 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
479 this.setLayout(layout);
480 layout.setHorizontalGroup(
481 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
482 .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
484 layout.setVerticalGroup(
485 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
486 .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
491 openGeolocationWindow(getDataSource(), DAYS_COUNT);
495 openGeolocationWindow(getDataSource(), null);
final List< Pair< String, Integer > > mostRecentData
List< Pair< String, Integer > > formatList(CityCountsList countsList)
javax.swing.JButton commonViewInGeolocationBtn
static< I, O > DataFetchResult< O > getSubResult(DataFetchResult< I > inputResult, Function< I, O > getSubResult)
final GeolocationSummary whereUsedData
CityCountsList getMostRecent()
void recentViewInGeolocationBtnActionPerformed(java.awt.event.ActionEvent evt)
void commonViewInGeolocationBtnActionPerformed(java.awt.event.ActionEvent evt)
void onNewDataSource(DataSource dataSource)
void openGeolocationWindow(DataSource dataSource, Integer daysLimit)
CityData getCityCounts(DataSource dataSource, int daysCount, int maxCount)
void fetchInformation(DataSource dataSource)
static< T, CextendsGuiCellModel > JTablePanel< T > getJTablePanel(List< ColumnModel< T, C >> columns)
GeolocationPanel(GeolocationSummary whereUsedData)
final DataFetcher< DataSource, GeolocationViewModel > geolocationFetcher
static String getCityName(CityRecord record)
void showCityContent(DataFetchResult< List< Pair< String, Integer >>> result, JTablePanel< Pair< String, Integer >> table, JButton goToGeolocation)
List< ARTIFACT_TYPE > getGeoTypes()
GeolocationViewModel convertToViewModel(CityData cityData)
Pair< String, Integer > formatRecord(CityRecordCount cityCount)
synchronized static Logger getLogger(String name)
void handleData(DataFetchResult< GeolocationViewModel > result)
final List< DataFetchComponents< DataSource,?> > dataFetchComponents
javax.swing.JButton recentViewInGeolocationBtn
final List< Pair< String, Integer > > mostCommonData
CityRecord getCityRecord()
List< CityRecordCount > getCounts()
void setFilterState(GeoFilter filter)
CityCountsList getMostCommon()