19 package org.sleuthkit.autopsy.datasourcesummary.ui;
 
   21 import java.util.ArrayList;
 
   22 import java.util.Arrays;
 
   23 import java.util.List;
 
   24 import java.util.logging.Level;
 
   25 import java.util.logging.Logger;
 
   26 import java.util.stream.Collectors;
 
   27 import java.util.stream.Stream;
 
   28 import javax.swing.JButton;
 
   29 import org.apache.commons.collections.CollectionUtils;
 
   30 import org.apache.commons.lang3.StringUtils;
 
   31 import org.apache.commons.lang3.tuple.Pair;
 
   32 import org.openide.util.NbBundle.Messages;
 
   33 import org.openide.util.actions.CallableSystemAction;
 
   34 import org.openide.windows.TopComponent;
 
   35 import org.openide.windows.WindowManager;
 
   59     "GeolocationPanel_cityColumn_title=Closest City",
 
   60     "GeolocationPanel_countColumn_title=Count",
 
   61     "GeolocationPanel_onNoCrIngest_message=No results will be shown because the GPX Parser was not run.",
 
   62     "GeolocationPanel_unknownRow_title=Unknown",})
 
   65     private static final long serialVersionUID = 1L;
 
   66     private static final int DAYS_COUNT = 30;
 
   67     private static final int MAX_COUNT = 10;
 
   71             Bundle.GeolocationPanel_cityColumn_title(),
 
   78             Bundle.GeolocationPanel_countColumn_title(),
 
   85             .setKeyFunction((pair) -> pair.getLeft());
 
   88             .setKeyFunction((pair) -> pair.getLeft());
 
   91     private final List<JTablePanel<?>> tables = Arrays.asList(mostCommonTable, mostRecentTable);
 
  115         super(whereUsedData);
 
  117         this.whereUsedData = whereUsedData;
 
  119         dataFetchComponents = Arrays.asList(
 
  121                         (dataSource) -> whereUsedData.
getCityCounts(dataSource, DAYS_COUNT, MAX_COUNT),
 
  122                         (result) -> handleData(result)));
 
  144         if (record == null) {
 
  149                 .filter(StringUtils::isNotBlank)
 
  150                 .collect(Collectors.toList());
 
  152         if (cityIdentifiers.size() == 1) {
 
  153             return cityIdentifiers.get(0);
 
  154         } 
else if (cityIdentifiers.size() == 2) {
 
  155             return String.format(
"%s, %s", cityIdentifiers.get(0), cityIdentifiers.get(1));
 
  156         } 
else if (cityIdentifiers.size() >= 3) {
 
  157             return String.format(
"%s, %s; %s", cityIdentifiers.get(0), cityIdentifiers.get(1), cityIdentifiers.get(2));
 
  171         if (cityCount == null) {
 
  177         return Pair.of(cityName, count);
 
  190         if (countsList == null) {
 
  194         Stream<CityRecordCount> countsStream = ((countsList.
getCounts() == null)
 
  195                 ? 
new ArrayList<CityRecordCount>()
 
  198         Stream<Pair<String, Integer>> pairStream = countsStream.map((r) -> formatRecord(r));
 
  200         Pair<String, Integer> unknownRecord = Pair.of(Bundle.GeolocationPanel_unknownRow_title(), countsList.
getOtherCount());
 
  202         return Stream.concat(pairStream, Stream.of(unknownRecord))
 
  203                 .filter((p) -> p != null && p.getRight() != null && p.getRight() > 0)
 
  204                 .sorted((a, b) -> -Integer.compare(a.getRight(), b.getRight()))
 
  206                 .collect(Collectors.toList());
 
  219             goToGeolocation.setEnabled(
true);
 
  222         table.showDataFetchResult(convertedData);
 
  238         TopComponent topComponent = WindowManager.getDefault().findTopComponent(
GeolocationTopComponent.class.getSimpleName());
 
  240             GeolocationTopComponent geoComponent = (GeolocationTopComponent) topComponent;
 
  244                     : 
new GeoFilter(
false, 
false, DAYS_COUNT, Arrays.asList(dataSource), whereUsedData.
getGeoTypes());
 
  249                 logger.log(Level.WARNING, 
"There was an error setting filters in the GeoLocationTopComponent.", ex);
 
  255         if (action == null) {
 
  256             logger.log(Level.WARNING, 
"Unable to obtain an OpenGeolocationAction instance from CallableSystemAction.");
 
  266         commonViewInGeolocationBtn.setEnabled(
false);
 
  267         recentViewInGeolocationBtn.setEnabled(
false);
 
  273         fetchInformation(dataFetchComponents, dataSource);
 
  279         onNewDataSource(dataFetchComponents, tables, dataSource);
 
  293     @SuppressWarnings(
"unchecked")
 
  295     private 
void initComponents() {
 
  297         javax.swing.JScrollPane mainScrollPane = 
new javax.swing.JScrollPane();
 
  298         javax.swing.JPanel mainContentPanel = 
new javax.swing.JPanel();
 
  299         javax.swing.JPanel ingestRunningPanel = ingestRunningLabel;
 
  300         javax.swing.JLabel mostRecentLabel = 
new javax.swing.JLabel();
 
  301         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));
 
  302         javax.swing.JPanel mostRecentPanel = mostRecentTable;
 
  303         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));
 
  304         javax.swing.JLabel withinDistanceLabel = 
new javax.swing.JLabel();
 
  305         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));
 
  306         recentViewInGeolocationBtn = 
new javax.swing.JButton();
 
  307         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));
 
  308         javax.swing.JLabel mostCommonLabel = 
new javax.swing.JLabel();
 
  309         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));
 
  310         javax.swing.JPanel mostCommonPanel = mostCommonTable;
 
  311         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));
 
  312         javax.swing.JLabel withinDistanceLabel1 = 
new javax.swing.JLabel();
 
  313         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));
 
  314         commonViewInGeolocationBtn = 
new javax.swing.JButton();
 
  315         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));
 
  317         mainContentPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10));
 
  318         mainContentPanel.setLayout(
new javax.swing.BoxLayout(mainContentPanel, javax.swing.BoxLayout.PAGE_AXIS));
 
  320         ingestRunningPanel.setAlignmentX(0.0F);
 
  321         ingestRunningPanel.setMaximumSize(
new java.awt.Dimension(32767, 25));
 
  322         ingestRunningPanel.setMinimumSize(
new java.awt.Dimension(10, 25));
 
  323         ingestRunningPanel.setPreferredSize(
new java.awt.Dimension(10, 25));
 
  324         mainContentPanel.add(ingestRunningPanel);
 
  326         org.openide.awt.Mnemonics.setLocalizedText(mostRecentLabel, 
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"GeolocationPanel.mostRecentLabel.text")); 
 
  327         mainContentPanel.add(mostRecentLabel);
 
  328         mostRecentLabel.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"PastCasesPanel.notableFileLabel.text")); 
 
  330         filler1.setAlignmentX(0.0F);
 
  331         mainContentPanel.add(filler1);
 
  333         mostRecentPanel.setAlignmentX(0.0F);
 
  334         mostRecentPanel.setMaximumSize(
new java.awt.Dimension(32767, 106));
 
  335         mostRecentPanel.setMinimumSize(
new java.awt.Dimension(100, 106));
 
  336         mostRecentPanel.setPreferredSize(
new java.awt.Dimension(100, 106));
 
  337         mainContentPanel.add(mostRecentPanel);
 
  339         filler2.setAlignmentX(0.0F);
 
  340         mainContentPanel.add(filler2);
 
  342         org.openide.awt.Mnemonics.setLocalizedText(withinDistanceLabel, 
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"GeolocationPanel.withinDistanceLabel.text")); 
 
  343         mainContentPanel.add(withinDistanceLabel);
 
  345         filler3.setAlignmentX(0.0F);
 
  346         mainContentPanel.add(filler3);
 
  348         org.openide.awt.Mnemonics.setLocalizedText(recentViewInGeolocationBtn, 
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"GeolocationPanel.recentViewInGeolocationBtn.text")); 
 
  349         recentViewInGeolocationBtn.setEnabled(
false);
 
  350         recentViewInGeolocationBtn.addActionListener(
new java.awt.event.ActionListener() {
 
  351             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  352                 recentViewInGeolocationBtnActionPerformed(evt);
 
  355         mainContentPanel.add(recentViewInGeolocationBtn);
 
  357         filler8.setAlignmentX(0.0F);
 
  358         mainContentPanel.add(filler8);
 
  360         org.openide.awt.Mnemonics.setLocalizedText(mostCommonLabel, 
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"GeolocationPanel.mostCommonLabel.text")); 
 
  361         mainContentPanel.add(mostCommonLabel);
 
  363         filler7.setAlignmentX(0.0F);
 
  364         mainContentPanel.add(filler7);
 
  366         mostCommonPanel.setAlignmentX(0.0F);
 
  367         mostCommonPanel.setMaximumSize(
new java.awt.Dimension(32767, 106));
 
  368         mostCommonPanel.setMinimumSize(
new java.awt.Dimension(100, 106));
 
  369         mostCommonPanel.setPreferredSize(
new java.awt.Dimension(100, 106));
 
  370         mainContentPanel.add(mostCommonPanel);
 
  372         filler6.setAlignmentX(0.0F);
 
  373         mainContentPanel.add(filler6);
 
  375         org.openide.awt.Mnemonics.setLocalizedText(withinDistanceLabel1, 
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"GeolocationPanel.withinDistanceLabel1.text")); 
 
  376         mainContentPanel.add(withinDistanceLabel1);
 
  378         filler4.setAlignmentX(0.0F);
 
  379         mainContentPanel.add(filler4);
 
  381         org.openide.awt.Mnemonics.setLocalizedText(commonViewInGeolocationBtn, 
org.openide.util.NbBundle.getMessage(
GeolocationPanel.class, 
"GeolocationPanel.commonViewInGeolocationBtn.text")); 
 
  382         commonViewInGeolocationBtn.setEnabled(
false);
 
  383         commonViewInGeolocationBtn.addActionListener(
new java.awt.event.ActionListener() {
 
  384             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  385                 commonViewInGeolocationBtnActionPerformed(evt);
 
  388         mainContentPanel.add(commonViewInGeolocationBtn);
 
  390         filler5.setAlignmentX(0.0F);
 
  391         mainContentPanel.add(filler5);
 
  393         mainScrollPane.setViewportView(mainContentPanel);
 
  395         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(
this);
 
  396         this.setLayout(layout);
 
  397         layout.setHorizontalGroup(
 
  398             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  399             .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
 
  401         layout.setVerticalGroup(
 
  402             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  403             .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 746, Short.MAX_VALUE)
 
  408         openGeolocationWindow(getDataSource(), DAYS_COUNT);
 
  412         openGeolocationWindow(getDataSource(), null);
 
List< Pair< String, Integer > > formatList(CityCountsList countsList)
 
javax.swing.JButton commonViewInGeolocationBtn
 
static< I, O > DataFetchResult< O > getSubResult(DataFetchResult< I > inputResult, Function< I, O > getSubResult)
 
ResultType getResultType()
 
final GeolocationSummary whereUsedData
 
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)
 
GeolocationPanel(GeolocationSummary whereUsedData)
 
static< T > JTablePanel< T > getJTablePanel(List< ColumnModel< T >> columns)
 
static String getCityName(CityRecord record)
 
void handleData(DataFetchResult< CityData > result)
 
List< ARTIFACT_TYPE > getGeoTypes()
 
Pair< String, Integer > formatRecord(CityRecordCount cityCount)
 
synchronized static Logger getLogger(String name)
 
void showCityContent(DataFetchResult< CityCountsList > result, JTablePanel< Pair< String, Integer >> table, JButton goToGeolocation)
 
final List< DataFetchComponents< DataSource,?> > dataFetchComponents
 
javax.swing.JButton recentViewInGeolocationBtn
 
CityRecord getCityRecord()
 
List< CityRecordCount > getCounts()
 
void setFilterState(GeoFilter filter)