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;
60 "GeolocationPanel_cityColumn_title=Closest City",
61 "GeolocationPanel_countColumn_title=Count",
62 "GeolocationPanel_onNoCrIngest_message=No results will be shown because the GPX Parser was not run.",
63 "GeolocationPanel_unknownRow_title=Unknown",
64 "GeolocationPanel_mostCommon_tabName=Most Common Cities",
65 "GeolocationPanel_mostRecent_tabName=Most Recent Cities",})
84 GeolocationViewModel(List<Pair<String, Integer>> mostRecentData, List<Pair<String, Integer>> mostCommonData) {
85 this.mostRecentData = mostRecentData;
86 this.mostCommonData = mostCommonData;
94 List<Pair<String, Integer>> getMostRecentData() {
95 return mostRecentData;
103 List<Pair<String, Integer>> getMostCommonData() {
104 return mostCommonData;
108 private static final long serialVersionUID = 1L;
109 private static final int DAYS_COUNT = 30;
110 private static final int MAX_COUNT = 10;
114 Bundle.GeolocationPanel_cityColumn_title(),
121 Bundle.GeolocationPanel_countColumn_title(),
126 private static final List<ColumnModel<Pair<String, Integer>,
DefaultCellModel<?>>> DEFAULT_TEMPLATE = Arrays.asList(
133 .setKeyFunction((pair) -> pair.getLeft());
136 .setKeyFunction((pair) -> pair.getLeft());
139 private final List<JTablePanel<?>> tables = Arrays.asList(mostCommonTable, mostRecentTable);
165 super(whereUsedData);
167 this.whereUsedData = whereUsedData;
169 this.geolocationFetcher = (dataSource) -> convertToViewModel(whereUsedData.
getCityCounts(dataSource, DAYS_COUNT, MAX_COUNT));
172 dataFetchComponents = Arrays.asList(
175 (result) -> handleData(result)));
187 showCityContent(
DataFetchResult.
getSubResult(result, (dr) -> dr.getMostCommonData()), mostCommonTable, commonViewInGeolocationBtn);
188 showCityContent(
DataFetchResult.
getSubResult(result, (dr) -> dr.getMostRecentData()), mostRecentTable, recentViewInGeolocationBtn);
199 if (record == null) {
204 .filter(StringUtils::isNotBlank)
205 .collect(Collectors.toList());
207 if (cityIdentifiers.size() == 1) {
208 return cityIdentifiers.get(0);
209 }
else if (cityIdentifiers.size() == 2) {
210 return String.format(
"%s, %s", cityIdentifiers.get(0), cityIdentifiers.get(1));
211 }
else if (cityIdentifiers.size() >= 3) {
212 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);
247 if (countsList == null) {
248 return Collections.emptyList();
251 Stream<CityRecordCount> countsStream = ((countsList.
getCounts() == null)
252 ?
new ArrayList<CityRecordCount>()
255 Stream<Pair<String, Integer>> pairStream = countsStream.map((r) -> formatRecord(r));
257 Pair<String, Integer> unknownRecord = Pair.of(Bundle.GeolocationPanel_unknownRow_title(), countsList.
getOtherCount());
259 return Stream.concat(pairStream, Stream.of(unknownRecord))
260 .filter((p) -> p != null && p.getRight() != null && p.getRight() > 0)
261 .sorted((a, b) -> -Integer.compare(a.getRight(), b.getRight()))
263 .collect(Collectors.toList());
275 if (cityData == null) {
291 goToGeolocation.setEnabled(
true);
294 table.showDataFetchResult(result);
310 TopComponent topComponent = WindowManager.getDefault().findTopComponent(
GeolocationTopComponent.class.getSimpleName());
312 GeolocationTopComponent geoComponent = (GeolocationTopComponent) topComponent;
316 :
new GeoFilter(
false,
false, DAYS_COUNT, Arrays.asList(dataSource), whereUsedData.
getGeoTypes());
321 logger.log(Level.WARNING,
"There was an error setting filters in the GeoLocationTopComponent.", ex);
327 if (action == null) {
328 logger.log(Level.WARNING,
"Unable to obtain an OpenGeolocationAction instance from CallableSystemAction.");
338 commonViewInGeolocationBtn.setEnabled(
false);
339 recentViewInGeolocationBtn.setEnabled(
false);
345 fetchInformation(dataFetchComponents, dataSource);
351 onNewDataSource(dataFetchComponents, tables, dataSource);
365 @SuppressWarnings(
"unchecked")
367 private
void initComponents() {
369 javax.swing.JScrollPane mainScrollPane =
new javax.swing.JScrollPane();
370 javax.swing.JPanel mainContentPanel =
new javax.swing.JPanel();
371 javax.swing.JPanel ingestRunningPanel = ingestRunningLabel;
372 javax.swing.JLabel mostRecentLabel =
new javax.swing.JLabel();
373 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));
374 javax.swing.JPanel mostRecentPanel = mostRecentTable;
375 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));
376 javax.swing.JLabel withinDistanceLabel =
new javax.swing.JLabel();
377 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));
378 recentViewInGeolocationBtn =
new javax.swing.JButton();
379 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));
380 javax.swing.JLabel mostCommonLabel =
new javax.swing.JLabel();
381 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));
382 javax.swing.JPanel mostCommonPanel = mostCommonTable;
383 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));
384 javax.swing.JLabel withinDistanceLabel1 =
new javax.swing.JLabel();
385 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));
386 commonViewInGeolocationBtn =
new javax.swing.JButton();
387 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));
389 mainContentPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
390 mainContentPanel.setLayout(
new javax.swing.BoxLayout(mainContentPanel, javax.swing.BoxLayout.PAGE_AXIS));
392 ingestRunningPanel.setAlignmentX(0.0F);
393 ingestRunningPanel.setMaximumSize(
new java.awt.Dimension(32767, 25));
394 ingestRunningPanel.setMinimumSize(
new java.awt.Dimension(10, 25));
395 ingestRunningPanel.setPreferredSize(
new java.awt.Dimension(10, 25));
396 mainContentPanel.add(ingestRunningPanel);
398 org.openide.awt.Mnemonics.setLocalizedText(mostRecentLabel,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.mostRecentLabel.text"));
399 mainContentPanel.add(mostRecentLabel);
400 mostRecentLabel.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"PastCasesPanel.notableFileLabel.text"));
402 filler1.setAlignmentX(0.0F);
403 mainContentPanel.add(filler1);
405 mostRecentPanel.setAlignmentX(0.0F);
406 mostRecentPanel.setMaximumSize(
new java.awt.Dimension(32767, 106));
407 mostRecentPanel.setMinimumSize(
new java.awt.Dimension(100, 106));
408 mostRecentPanel.setPreferredSize(
new java.awt.Dimension(100, 106));
409 mainContentPanel.add(mostRecentPanel);
411 filler2.setAlignmentX(0.0F);
412 mainContentPanel.add(filler2);
414 org.openide.awt.Mnemonics.setLocalizedText(withinDistanceLabel,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.withinDistanceLabel.text"));
415 mainContentPanel.add(withinDistanceLabel);
417 filler3.setAlignmentX(0.0F);
418 mainContentPanel.add(filler3);
420 org.openide.awt.Mnemonics.setLocalizedText(recentViewInGeolocationBtn,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.recentViewInGeolocationBtn.text"));
421 recentViewInGeolocationBtn.setEnabled(
false);
422 recentViewInGeolocationBtn.addActionListener(
new java.awt.event.ActionListener() {
423 public void actionPerformed(java.awt.event.ActionEvent evt) {
424 recentViewInGeolocationBtnActionPerformed(evt);
427 mainContentPanel.add(recentViewInGeolocationBtn);
429 filler8.setAlignmentX(0.0F);
430 mainContentPanel.add(filler8);
432 org.openide.awt.Mnemonics.setLocalizedText(mostCommonLabel,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.mostCommonLabel.text"));
433 mainContentPanel.add(mostCommonLabel);
435 filler7.setAlignmentX(0.0F);
436 mainContentPanel.add(filler7);
438 mostCommonPanel.setAlignmentX(0.0F);
439 mostCommonPanel.setMaximumSize(
new java.awt.Dimension(32767, 106));
440 mostCommonPanel.setMinimumSize(
new java.awt.Dimension(100, 106));
441 mostCommonPanel.setPreferredSize(
new java.awt.Dimension(100, 106));
442 mainContentPanel.add(mostCommonPanel);
444 filler6.setAlignmentX(0.0F);
445 mainContentPanel.add(filler6);
447 org.openide.awt.Mnemonics.setLocalizedText(withinDistanceLabel1,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.withinDistanceLabel1.text"));
448 mainContentPanel.add(withinDistanceLabel1);
450 filler4.setAlignmentX(0.0F);
451 mainContentPanel.add(filler4);
453 org.openide.awt.Mnemonics.setLocalizedText(commonViewInGeolocationBtn,
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class,
"GeolocationPanel.commonViewInGeolocationBtn.text"));
454 commonViewInGeolocationBtn.setEnabled(
false);
455 commonViewInGeolocationBtn.addActionListener(
new java.awt.event.ActionListener() {
456 public void actionPerformed(java.awt.event.ActionEvent evt) {
457 commonViewInGeolocationBtnActionPerformed(evt);
460 mainContentPanel.add(commonViewInGeolocationBtn);
462 filler5.setAlignmentX(0.0F);
463 mainContentPanel.add(filler5);
465 mainScrollPane.setViewportView(mainContentPanel);
467 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
468 this.setLayout(layout);
469 layout.setHorizontalGroup(
470 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
471 .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
473 layout.setVerticalGroup(
474 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
475 .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
480 openGeolocationWindow(getDataSource(), DAYS_COUNT);
484 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)
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)
void fetchInformation(DataSource dataSource)
static< T, CextendsGuiCellModel > JTablePanel< T > getJTablePanel(List< ColumnModel< T, C >> columns)
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)
GeolocationPanel(GeolocationSummaryGetter whereUsedData)
CityData getCityCounts(DataSource dataSource, int daysCount, int maxCount)
GeolocationViewModel convertToViewModel(CityData cityData)
Pair< String, Integer > formatRecord(CityRecordCount cityCount)
synchronized static Logger getLogger(String name)
List< ARTIFACT_TYPE > getGeoTypes()
void handleData(DataFetchResult< GeolocationViewModel > result)
final GeolocationSummaryGetter whereUsedData
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()