mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
formatting, commenting, and refactoring
This commit is contained in:
parent
e6500c41ce
commit
2ab62fce47
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datasourcesummary.ui;
|
package org.sleuthkit.autopsy.datasourcesummary.ui;
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -34,6 +33,7 @@ import java.util.concurrent.CancellationException;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
@ -186,7 +186,9 @@ class ExcelExportAction implements Consumer<DataSource> {
|
|||||||
"# {0} - dataSource",
|
"# {0} - dataSource",
|
||||||
"ExcelExportAction_runXLSXExport_progressTitle=Exporting {0} to XLSX",
|
"ExcelExportAction_runXLSXExport_progressTitle=Exporting {0} to XLSX",
|
||||||
"ExcelExportAction_runXLSXExport_progressCancelTitle=Cancel",
|
"ExcelExportAction_runXLSXExport_progressCancelTitle=Cancel",
|
||||||
"ExcelExportAction_runXLSXExport_progressCancelActionTitle=Cancelling..."
|
"ExcelExportAction_runXLSXExport_progressCancelActionTitle=Cancelling...",
|
||||||
|
"ExcelExportAction_runXLSXExport_errorTitle=Error While Exporting",
|
||||||
|
"ExcelExportAction_runXLSXExport_errorMessage=There was an error while exporting.",
|
||||||
})
|
})
|
||||||
private void runXLSXExport(DataSource dataSource, File path) {
|
private void runXLSXExport(DataSource dataSource, File path) {
|
||||||
|
|
||||||
@ -213,6 +215,10 @@ class ExcelExportAction implements Consumer<DataSource> {
|
|||||||
get();
|
get();
|
||||||
} catch (ExecutionException ex) {
|
} catch (ExecutionException ex) {
|
||||||
logger.log(Level.WARNING, "Error while trying to export data source summary to xlsx.", ex);
|
logger.log(Level.WARNING, "Error while trying to export data source summary to xlsx.", ex);
|
||||||
|
JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
|
||||||
|
Bundle.ExcelExportAction_runXLSXExport_errorMessage(),
|
||||||
|
Bundle.ExcelExportAction_runXLSXExport_errorTitle(),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
} catch (InterruptedException | CancellationException ex) {
|
} catch (InterruptedException | CancellationException ex) {
|
||||||
// no op on cancellation
|
// no op on cancellation
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -291,6 +291,13 @@ public class TimelinePanel extends BaseDataSourceSummaryPanel {
|
|||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a default cell model to be use with excel export in the earliest /
|
||||||
|
* latest date format.
|
||||||
|
*
|
||||||
|
* @param date The date.
|
||||||
|
* @return The cell model.
|
||||||
|
*/
|
||||||
private static DefaultCellModel<?> getEarliestLatestCell(Date date) {
|
private static DefaultCellModel<?> getEarliestLatestCell(Date date) {
|
||||||
return new DefaultCellModel<>(date, (dt) -> dt == null ? "" : EARLIEST_LATEST_FORMAT.format(dt), EARLIEST_LATEST_FORMAT_STR);
|
return new DefaultCellModel<>(date, (dt) -> dt == null ? "" : EARLIEST_LATEST_FORMAT.format(dt), EARLIEST_LATEST_FORMAT_STR);
|
||||||
}
|
}
|
||||||
|
@ -447,6 +447,7 @@ class TypesPanel extends BaseDataSourceSummaryPanel {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve data to create the types pie chart
|
||||||
TypesPieChartData typesData = TypesPanel.getFetchResult(typesFetcher, "Types", dataSource);
|
TypesPieChartData typesData = TypesPanel.getFetchResult(typesFetcher, "Types", dataSource);
|
||||||
PieChartExport typesChart = (typesData == null || !typesData.isUsefulContent()) ? null :
|
PieChartExport typesChart = (typesData == null || !typesData.isUsefulContent()) ? null :
|
||||||
new PieChartExport(
|
new PieChartExport(
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* Autopsy Forensic Browser
|
||||||
* To change this template file, choose Tools | Templates
|
*
|
||||||
* and open the template in the editor.
|
* Copyright 2021 Basis Technology Corp.
|
||||||
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
||||||
|
|
||||||
@ -42,35 +55,26 @@ import org.sleuthkit.autopsy.datasourcesummary.uiutils.ExcelSpecialFormatExport.
|
|||||||
import org.sleuthkit.autopsy.datasourcesummary.uiutils.ExcelSpecialFormatExport.ItemDimensions;
|
import org.sleuthkit.autopsy.datasourcesummary.uiutils.ExcelSpecialFormatExport.ItemDimensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Class that creates an excel stacked bar chart along with data table.
|
||||||
* @author gregd
|
|
||||||
*/
|
*/
|
||||||
public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
||||||
|
|
||||||
private final ExcelTableExport<Pair<Object, List<Double>>, ? extends ExcelCellModel> tableExport;
|
/**
|
||||||
private final int colOffset;
|
* Creates an excel table model to be written to an excel sheet and used as
|
||||||
private final int rowPadding;
|
* a datasource for the chart.
|
||||||
private final int colSize;
|
*
|
||||||
private final int rowSize;
|
* @param categories The categories with their data.
|
||||||
private final String chartTitle;
|
* @param keyColumnHeader The header column name for the table descriptions
|
||||||
private final String sheetName;
|
* (i.e. types: file types / artifact types).
|
||||||
private final List<BarChartSeries> categories;
|
* @param valueFormatString The excel format string to use for values.
|
||||||
private final String keyColumnHeader;
|
* @return An excel table export to be used as the data source for the chart
|
||||||
|
* in the excel document.
|
||||||
public BarChartExport(String keyColumnHeader,
|
*/
|
||||||
String valueFormatString,
|
private static ExcelTableExport<Pair<Object, List<Double>>, ? extends ExcelCellModel> getTableModel(
|
||||||
String chartTitle,
|
List<BarChartSeries> categories, String keyColumnHeader, String chartTitle) {
|
||||||
List<BarChartSeries> categories) {
|
|
||||||
this(keyColumnHeader, valueFormatString, chartTitle, chartTitle, categories, 1, 1, 8, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BarChartExport(String keyColumnHeader, String valueFormatString,
|
|
||||||
String chartTitle, String sheetName,
|
|
||||||
List<BarChartSeries> categories,
|
|
||||||
int colOffset, int rowPadding, int colSize, int rowSize) {
|
|
||||||
|
|
||||||
this.keyColumnHeader = keyColumnHeader;
|
|
||||||
|
|
||||||
|
// get the row keys by finding the series with the largest set of bar items
|
||||||
|
// (they should all be equal, but just in case)
|
||||||
List<? extends Object> rowKeys = categories.stream()
|
List<? extends Object> rowKeys = categories.stream()
|
||||||
.filter(cat -> cat != null && cat.getItems() != null)
|
.filter(cat -> cat != null && cat.getItems() != null)
|
||||||
.map(cat -> cat.getItems())
|
.map(cat -> cat.getItems())
|
||||||
@ -80,7 +84,7 @@ public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
.map((barChartItem) -> barChartItem.getKey())
|
.map((barChartItem) -> barChartItem.getKey())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// map of (category, item) -> value
|
// map of (bar chart category index, bar chart item index) -> value
|
||||||
Map<Pair<Integer, Integer>, Double> valueMap = IntStream.range(0, categories.size())
|
Map<Pair<Integer, Integer>, Double> valueMap = IntStream.range(0, categories.size())
|
||||||
.mapToObj(idx -> Pair.of(idx, categories.get(idx)))
|
.mapToObj(idx -> Pair.of(idx, categories.get(idx)))
|
||||||
.filter(pair -> pair.getValue() != null && pair.getValue().getItems() != null)
|
.filter(pair -> pair.getValue() != null && pair.getValue().getItems() != null)
|
||||||
@ -88,11 +92,13 @@ public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
return IntStream.range(0, categoryPair.getValue().getItems().size())
|
return IntStream.range(0, categoryPair.getValue().getItems().size())
|
||||||
.mapToObj(idx -> Pair.of(idx, categoryPair.getValue().getItems().get(idx)))
|
.mapToObj(idx -> Pair.of(idx, categoryPair.getValue().getItems().get(idx)))
|
||||||
.map(itemPair -> Pair.of(
|
.map(itemPair -> Pair.of(
|
||||||
Pair.of(categoryPair.getKey(), itemPair.getKey()),
|
Pair.of(categoryPair.getKey(), itemPair.getKey()),
|
||||||
itemPair.getValue() == null ? null : itemPair.getValue().getValue()));
|
itemPair.getValue() == null ? null : itemPair.getValue().getValue()));
|
||||||
})
|
})
|
||||||
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v1));
|
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v1));
|
||||||
|
|
||||||
|
// Create rows of data to be displayed where each row is a tuple of the bar chart item
|
||||||
|
// key and the list of values in category order.
|
||||||
List<Pair<Object, List<Double>>> values = IntStream.range(0, rowKeys.size())
|
List<Pair<Object, List<Double>>> values = IntStream.range(0, rowKeys.size())
|
||||||
.mapToObj(idx -> Pair.of(idx, rowKeys.get(idx)))
|
.mapToObj(idx -> Pair.of(idx, rowKeys.get(idx)))
|
||||||
.map((rowPair) -> {
|
.map((rowPair) -> {
|
||||||
@ -104,20 +110,80 @@ public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
ColumnModel<Pair<Object, List<Double>>, DefaultCellModel<?>> categoryColumn = new ColumnModel<>(keyColumnHeader, (row) -> new DefaultCellModel<>(row.getKey()));
|
// Create the model for the category column
|
||||||
|
ColumnModel<Pair<Object, List<Double>>, DefaultCellModel<?>> categoryColumn
|
||||||
|
= new ColumnModel<>(keyColumnHeader, (row) -> new DefaultCellModel<>(row.getKey()));
|
||||||
|
|
||||||
|
// create the models for each category of data to be displayed
|
||||||
Stream<ColumnModel<Pair<Object, List<Double>>, DefaultCellModel<?>>> dataColumns = IntStream.range(0, categories.size())
|
Stream<ColumnModel<Pair<Object, List<Double>>, DefaultCellModel<?>>> dataColumns = IntStream.range(0, categories.size())
|
||||||
.mapToObj(idx -> new ColumnModel<>(
|
.mapToObj(idx -> new ColumnModel<>(
|
||||||
categories.get(idx).getKey().toString(),
|
categories.get(idx).getKey().toString(),
|
||||||
(row) -> new DefaultCellModel<>(row.getValue().get(idx))));
|
(row) -> new DefaultCellModel<>(row.getValue().get(idx))));
|
||||||
|
|
||||||
this.tableExport = new ExcelTableExport<Pair<Object, List<Double>>, DefaultCellModel<?>>(
|
// create table
|
||||||
|
return new ExcelTableExport<Pair<Object, List<Double>>, DefaultCellModel<?>>(
|
||||||
chartTitle,
|
chartTitle,
|
||||||
Stream.concat(Stream.of(categoryColumn), dataColumns)
|
Stream.concat(Stream.of(categoryColumn), dataColumns)
|
||||||
.collect(Collectors.toList()),
|
.collect(Collectors.toList()),
|
||||||
values
|
values
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int DEFAULT_ROW_SIZE = 8;
|
||||||
|
private static final int DEFAULT_COL_SIZE = 15;
|
||||||
|
private static final int DEFAULT_ROW_PADDING = 1;
|
||||||
|
private static final int DEFAULT_COL_OFFSET = 1;
|
||||||
|
|
||||||
|
private final ExcelTableExport<Pair<Object, List<Double>>, ? extends ExcelCellModel> tableExport;
|
||||||
|
private final int colOffset;
|
||||||
|
private final int rowPadding;
|
||||||
|
private final int colSize;
|
||||||
|
private final int rowSize;
|
||||||
|
private final String chartTitle;
|
||||||
|
private final String sheetName;
|
||||||
|
private final List<BarChartSeries> categories;
|
||||||
|
private final String keyColumnHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main constructor that assumes some defaults (i.e. chart size follows
|
||||||
|
* defaults and sheet name is chart title).
|
||||||
|
*
|
||||||
|
* @param keyColumnHeader The header column name for the table descriptions
|
||||||
|
* (i.e. types: file types / artifact types).
|
||||||
|
* @param valueFormatString The excel format string to use for values.
|
||||||
|
* @param chartTitle The title for the chart.
|
||||||
|
* @param categories The categories along with data.
|
||||||
|
*/
|
||||||
|
public BarChartExport(String keyColumnHeader,
|
||||||
|
String valueFormatString,
|
||||||
|
String chartTitle,
|
||||||
|
List<BarChartSeries> categories) {
|
||||||
|
this(keyColumnHeader, valueFormatString, chartTitle, chartTitle, categories,
|
||||||
|
DEFAULT_COL_OFFSET, DEFAULT_ROW_PADDING, DEFAULT_COL_SIZE, DEFAULT_ROW_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main constructor.
|
||||||
|
*
|
||||||
|
* @param keyColumnHeader The header column name for the table descriptions
|
||||||
|
* (i.e. types: file types / artifact types).
|
||||||
|
* @param valueFormatString The excel format string to use for values.
|
||||||
|
* @param chartTitle The title for the chart.
|
||||||
|
* @param sheetName The sheet name if used as a sheet export.
|
||||||
|
* @param categories The categories along with data.
|
||||||
|
* @param colOffset The column spacing between the table and the chart.
|
||||||
|
* @param rowPadding The padding between this and data above or below (if
|
||||||
|
* used as an ExcelItemExportable).
|
||||||
|
* @param colSize The column size of the chart.
|
||||||
|
* @param rowSize The row size of the chart.
|
||||||
|
*/
|
||||||
|
public BarChartExport(String keyColumnHeader, String valueFormatString,
|
||||||
|
String chartTitle, String sheetName,
|
||||||
|
List<BarChartSeries> categories,
|
||||||
|
int colOffset, int rowPadding, int colSize, int rowSize) {
|
||||||
|
|
||||||
|
this.keyColumnHeader = keyColumnHeader;
|
||||||
|
this.tableExport = getTableModel(categories, keyColumnHeader, chartTitle);
|
||||||
this.colOffset = colOffset;
|
this.colOffset = colOffset;
|
||||||
this.rowPadding = rowPadding;
|
this.rowPadding = rowPadding;
|
||||||
this.colSize = colSize;
|
this.colSize = colSize;
|
||||||
@ -152,7 +218,7 @@ public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
|
|
||||||
int chartColStart = colStart + categories.size() + 1 + colOffset;
|
int chartColStart = colStart + categories.size() + 1 + colOffset;
|
||||||
|
|
||||||
//createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
|
//createAnchor has arguments of (int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
|
||||||
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, chartColStart, rowStart + rowPadding, chartColStart + colSize, rowStart + rowSize);
|
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, chartColStart, rowStart + rowPadding, chartColStart + colSize, rowStart + rowSize);
|
||||||
|
|
||||||
XSSFChart chart = drawing.createChart(anchor);
|
XSSFChart chart = drawing.createChart(anchor);
|
||||||
@ -178,6 +244,7 @@ public class BarChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
|
|
||||||
data.setBarDirection(BarDirection.COL);
|
data.setBarDirection(BarDirection.COL);
|
||||||
|
|
||||||
|
// set data for each series and set color if applicable
|
||||||
for (int i = 0; i < categories.size(); i++) {
|
for (int i = 0; i < categories.size(); i++) {
|
||||||
XDDFChartData.Series series = data.addSeries(headerSource,
|
XDDFChartData.Series series = data.addSeries(headerSource,
|
||||||
XDDFDataSourcesFactory.fromNumericCellRange(xssfSheet,
|
XDDFDataSourcesFactory.fromNumericCellRange(xssfSheet,
|
||||||
|
@ -39,7 +39,6 @@ import org.sleuthkit.autopsy.datasourcesummary.uiutils.BarChartSeries.BarChartIt
|
|||||||
*/
|
*/
|
||||||
public class BarChartPanel extends AbstractLoadableComponent<List<BarChartSeries>> {
|
public class BarChartPanel extends AbstractLoadableComponent<List<BarChartSeries>> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JFreeChart bar charts don't preserve the order of bars provided to the
|
* JFreeChart bar charts don't preserve the order of bars provided to the
|
||||||
* chart, but instead uses the comparable nature to order items. This
|
* chart, but instead uses the comparable nature to order items. This
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2020 Basis Technology Corp.
|
* Copyright 2021 Basis Technology Corp.
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -23,8 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a series in a bar chart where all items pertain to one
|
* Represents a series in a bar chart where all items pertain to one category.
|
||||||
* category.
|
|
||||||
*/
|
*/
|
||||||
public class BarChartSeries {
|
public class BarChartSeries {
|
||||||
|
|
||||||
@ -98,5 +97,5 @@ public class BarChartSeries {
|
|||||||
public Comparable<?> getKey() {
|
public Comparable<?> getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,6 @@ public class ExcelTableExport<T, C extends ExcelCellModel> implements ExcelSheet
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create Cell Style for each column (if one is needed)
|
// Create Cell Style for each column (if one is needed)
|
||||||
|
|
||||||
for (int rowNum = 0; rowNum < safeData.size(); rowNum++) {
|
for (int rowNum = 0; rowNum < safeData.size(); rowNum++) {
|
||||||
T rowData = safeData.get(rowNum);
|
T rowData = safeData.get(rowNum);
|
||||||
Row row = sheet.createRow(rowNum + rowStart + 1);
|
Row row = sheet.createRow(rowNum + rowStart + 1);
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* Autopsy Forensic Browser
|
||||||
* To change this template file, choose Tools | Templates
|
*
|
||||||
* and open the template in the editor.
|
* Copyright 2021 Basis Technology Corp.
|
||||||
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
||||||
|
|
||||||
@ -29,10 +42,15 @@ import org.sleuthkit.autopsy.datasourcesummary.uiutils.ExcelSpecialFormatExport.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author gregd
|
* Class that creates an excel pie chart along with data table.
|
||||||
*/
|
*/
|
||||||
public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
||||||
|
|
||||||
|
private static final int DEFAULT_ROW_SIZE = 8;
|
||||||
|
private static final int DEFAULT_COL_SIZE = 15;
|
||||||
|
private static final int DEFAULT_ROW_PADDING = 1;
|
||||||
|
private static final int DEFAULT_COL_OFFSET = 1;
|
||||||
|
|
||||||
private final ExcelTableExport<PieChartItem, ? extends ExcelCellModel> tableExport;
|
private final ExcelTableExport<PieChartItem, ? extends ExcelCellModel> tableExport;
|
||||||
private final int colOffset;
|
private final int colOffset;
|
||||||
private final int rowPadding;
|
private final int rowPadding;
|
||||||
@ -41,13 +59,40 @@ public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
private final String chartTitle;
|
private final String chartTitle;
|
||||||
private final String sheetName;
|
private final String sheetName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main constructor assuming defaults.
|
||||||
|
*
|
||||||
|
* @param keyColumnHeader The header column name for the table descriptions
|
||||||
|
* (i.e. file types).
|
||||||
|
* @param valueColumnHeader The header column name for the values.
|
||||||
|
* @param valueFormatString The excel format string to use for values.
|
||||||
|
* @param chartTitle The title for the chart.
|
||||||
|
* @param slices The values for the pie slices.
|
||||||
|
*/
|
||||||
public PieChartExport(String keyColumnHeader,
|
public PieChartExport(String keyColumnHeader,
|
||||||
String valueColumnHeader, String valueFormatString,
|
String valueColumnHeader, String valueFormatString,
|
||||||
String chartTitle,
|
String chartTitle,
|
||||||
List<PieChartItem> slices) {
|
List<PieChartItem> slices) {
|
||||||
this(keyColumnHeader, valueColumnHeader, valueFormatString, chartTitle, chartTitle, slices, 1, 1, 8, 14);
|
this(keyColumnHeader, valueColumnHeader, valueFormatString, chartTitle, chartTitle, slices,
|
||||||
|
DEFAULT_COL_OFFSET, DEFAULT_ROW_PADDING, DEFAULT_COL_SIZE, DEFAULT_ROW_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main constructor.
|
||||||
|
*
|
||||||
|
* @param keyColumnHeader The header column name for the table descriptions
|
||||||
|
* (i.e. file types).
|
||||||
|
* @param valueColumnHeader The header column name for the values.
|
||||||
|
* @param valueFormatString The excel format string to use for values.
|
||||||
|
* @param chartTitle The title for the chart.
|
||||||
|
* @param sheetName The sheet name if used as a sheet export.
|
||||||
|
* @param slices The values for the pie slices.
|
||||||
|
* @param colOffset The column spacing between the table and the chart.
|
||||||
|
* @param rowPadding The padding between this and data above or below (if
|
||||||
|
* used as an ExcelItemExportable).
|
||||||
|
* @param colSize The column size of the chart.
|
||||||
|
* @param rowSize The row size of the chart.
|
||||||
|
*/
|
||||||
public PieChartExport(String keyColumnHeader,
|
public PieChartExport(String keyColumnHeader,
|
||||||
String valueColumnHeader, String valueFormatString,
|
String valueColumnHeader, String valueFormatString,
|
||||||
String chartTitle, String sheetName,
|
String chartTitle, String sheetName,
|
||||||
@ -93,7 +138,7 @@ public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
|
|
||||||
int chartColStart = colStart + 2 + colOffset;
|
int chartColStart = colStart + 2 + colOffset;
|
||||||
|
|
||||||
//createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
|
//createAnchor has arguments of (int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
|
||||||
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, chartColStart, rowStart + rowPadding, chartColStart + colSize, rowStart + rowSize);
|
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, chartColStart, rowStart + rowPadding, chartColStart + colSize, rowStart + rowSize);
|
||||||
|
|
||||||
XSSFChart chart = drawing.createChart(anchor);
|
XSSFChart chart = drawing.createChart(anchor);
|
||||||
@ -102,7 +147,7 @@ public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
XDDFChartLegend legend = chart.getOrAddLegend();
|
XDDFChartLegend legend = chart.getOrAddLegend();
|
||||||
legend.setPosition(LegendPosition.RIGHT);
|
legend.setPosition(LegendPosition.RIGHT);
|
||||||
|
|
||||||
// (int firstRow, int lastRow, int firstCol, int lastCol)
|
// CellRangeAddress has arguments of (int firstRow, int lastRow, int firstCol, int lastCol)
|
||||||
XDDFDataSource<String> cat = XDDFDataSourcesFactory.fromStringCellRange(xssfSheet,
|
XDDFDataSource<String> cat = XDDFDataSourcesFactory.fromStringCellRange(xssfSheet,
|
||||||
new CellRangeAddress(tableDimensions.getRowStart() + 1, tableDimensions.getRowEnd(),
|
new CellRangeAddress(tableDimensions.getRowStart() + 1, tableDimensions.getRowEnd(),
|
||||||
tableDimensions.getColStart(), tableDimensions.getColStart()));
|
tableDimensions.getColStart(), tableDimensions.getColStart()));
|
||||||
@ -111,13 +156,14 @@ public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
new CellRangeAddress(tableDimensions.getRowStart() + 1, tableDimensions.getRowEnd(),
|
new CellRangeAddress(tableDimensions.getRowStart() + 1, tableDimensions.getRowEnd(),
|
||||||
tableDimensions.getColStart() + 1, tableDimensions.getColStart() + 1));
|
tableDimensions.getColStart() + 1, tableDimensions.getColStart() + 1));
|
||||||
|
|
||||||
|
// NOTE: There appears to be a classpath issue with POI (a version of 4.0.1 and 4.1.1 simultaneously)
|
||||||
// XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
|
// that is causing conflicts for XDDFPieChartData creation (i.e. the compiler thinks its using 4.1.1
|
||||||
// XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
|
// and the runtime thinks its using 4.0.1) Reflection is used below to use the 4.0.1 method while
|
||||||
|
// sidestepping compiler issues.
|
||||||
// NOTE: these can be null parameters to chart.createData in poi >= 4.1.1
|
// XDDFPieChartData creation that can be used in poi >= 4.1.1:
|
||||||
//XDDFPieChartData data = (XDDFPieChartData) chart.createData(ChartTypes.PIE, bottomAxis, leftAxis);
|
// XDDFPieChartData data = (XDDFPieChartData) chart.createData(ChartTypes.PIE, bottomAxis, leftAxis);
|
||||||
|
// XDDFPieChartData creation that can be used in 4.0.1:
|
||||||
|
// XDDFPieChartData data = new XDDFPieChartData(chart.getCTChart().getPlotArea().addNewPieChart());
|
||||||
XDDFPieChartData data;
|
XDDFPieChartData data;
|
||||||
try {
|
try {
|
||||||
Constructor<XDDFPieChartData> constructor = XDDFPieChartData.class.getConstructor(CTPieChart.class);
|
Constructor<XDDFPieChartData> constructor = XDDFPieChartData.class.getConstructor(CTPieChart.class);
|
||||||
@ -126,7 +172,7 @@ public class PieChartExport implements ExcelItemExportable, ExcelSheetExport {
|
|||||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) {
|
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) {
|
||||||
throw new ExcelExportException("Error while instantiating chart data.", ex);
|
throw new ExcelExportException("Error while instantiating chart data.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setVaryColors(true);
|
data.setVaryColors(true);
|
||||||
data.addSeries(cat, val);
|
data.addSeries(cat, val);
|
||||||
|
|
||||||
|
@ -1,7 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* Autopsy Forensic Browser
|
||||||
* To change this template file, choose Tools | Templates
|
*
|
||||||
* and open the template in the editor.
|
* Copyright 2021 Basis Technology Corp.
|
||||||
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
package org.sleuthkit.autopsy.datasourcesummary.uiutils;
|
||||||
|
|
||||||
@ -50,5 +63,5 @@ public class PieChartItem {
|
|||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2019 Basis Technology Corp.
|
* Copyright 2020 Basis Technology Corp.
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -41,7 +41,6 @@ import org.openide.util.NbBundle.Messages;
|
|||||||
})
|
})
|
||||||
public class PieChartPanel extends AbstractLoadableComponent<List<PieChartItem>> {
|
public class PieChartPanel extends AbstractLoadableComponent<List<PieChartItem>> {
|
||||||
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private static final Font DEFAULT_FONT = new JLabel().getFont();
|
private static final Font DEFAULT_FONT = new JLabel().getFont();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user