mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
addressing codacy remarks
This commit is contained in:
parent
78d69f173b
commit
664deb65bc
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datasourcesummary.datamodel;
|
package org.sleuthkit.autopsy.datasourcesummary.datamodel;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -41,6 +40,9 @@ public class DataSourceTopDomainsSummary {
|
|||||||
// this.provider = provider;
|
// this.provider = provider;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* a function to calculate a result from 2 paramaters
|
||||||
|
*/
|
||||||
interface Function2<A1,A2,O> {
|
interface Function2<A1,A2,O> {
|
||||||
O apply(A1 a1, A2 a2);
|
O apply(A1 a1, A2 a2);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import org.sleuthkit.datamodel.SleuthkitCase;
|
|||||||
* uses Case.getCurrentCaseThrows().getSleuthkkitCase().
|
* uses Case.getCurrentCaseThrows().getSleuthkkitCase().
|
||||||
*/
|
*/
|
||||||
public interface SleuthkitCaseProvider {
|
public interface SleuthkitCaseProvider {
|
||||||
public static final SleuthkitCaseProvider DEFAULT = () -> Case.getCurrentCaseThrows().getSleuthkitCase();
|
SleuthkitCaseProvider DEFAULT = () -> Case.getCurrentCaseThrows().getSleuthkitCase();
|
||||||
|
|
||||||
SleuthkitCase get() throws NoCurrentCaseException;
|
SleuthkitCase get() throws NoCurrentCaseException;
|
||||||
}
|
}
|
||||||
|
@ -106,17 +106,7 @@ public class DataFetchWorker<A, R> extends SwingWorker<R, Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected R doInBackground() throws Exception {
|
protected R doInBackground() throws Exception {
|
||||||
if (Thread.interrupted() || isCancelled()) {
|
return processor.process(args);
|
||||||
throw new InterruptedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
R result = processor.process(args);
|
|
||||||
|
|
||||||
if (Thread.interrupted() || isCancelled()) {
|
|
||||||
throw new InterruptedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -135,14 +125,14 @@ public class DataFetchWorker<A, R> extends SwingWorker<R, Void> {
|
|||||||
} catch (ExecutionException ex) {
|
} catch (ExecutionException ex) {
|
||||||
Throwable inner = ex.getCause();
|
Throwable inner = ex.getCause();
|
||||||
// if cancelled during operation, simply return
|
// if cancelled during operation, simply return
|
||||||
if (inner != null && inner instanceof InterruptedException) {
|
if (inner instanceof InterruptedException) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, there is an error to log
|
// otherwise, there is an error to log
|
||||||
logger.log(Level.WARNING, "There was an error while fetching results.", ex);
|
logger.log(Level.WARNING, "There was an error while fetching results.", ex);
|
||||||
|
|
||||||
if (inner != null && inner instanceof DataProcessorException) {
|
if (inner instanceof DataProcessorException) {
|
||||||
resultHandler.accept(DataLoadingResult.getLoadError((DataProcessorException) inner));
|
resultHandler.accept(DataLoadingResult.getLoadError((DataProcessorException) inner));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -21,7 +21,7 @@ package org.sleuthkit.autopsy.guiutils.internal;
|
|||||||
/**
|
/**
|
||||||
* The intermediate or end result of a loading process.
|
* The intermediate or end result of a loading process.
|
||||||
*/
|
*/
|
||||||
public class DataLoadingResult<R> {
|
public final class DataLoadingResult<R> {
|
||||||
|
|
||||||
// The state of loading in the result.
|
// The state of loading in the result.
|
||||||
public enum ProcessorState {
|
public enum ProcessorState {
|
||||||
|
@ -26,35 +26,6 @@ package org.sleuthkit.autopsy.guiutils.internal;
|
|||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface DataProcessor<I, O> {
|
public interface DataProcessor<I, O> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Wraps a DataProcessor in statements looking to see if the thread has been
|
|
||||||
* interrupted and throws an InterruptedException in that event.
|
|
||||||
*
|
|
||||||
* @param toBeWrapped The data processor to be wrapped.
|
|
||||||
*
|
|
||||||
* @return The wrapped data processor that will throw an interrupted
|
|
||||||
* exception before or after the toBeWrapped data processor has been
|
|
||||||
* run.
|
|
||||||
*/
|
|
||||||
public static <I1, O1> DataProcessor<I1, O1> wrap(DataProcessor<I1, O1> toBeWrapped) {
|
|
||||||
return new DataProcessor<I1, O1>() {
|
|
||||||
@Override
|
|
||||||
public O1 process(I1 input) throws InterruptedException, DataProcessorException {
|
|
||||||
if (Thread.interrupted()) {
|
|
||||||
throw new InterruptedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
O1 output = toBeWrapped.process(input);
|
|
||||||
if (Thread.interrupted()) {
|
|
||||||
throw new InterruptedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that accepts an input argument and outputs a result. Since it
|
* A function that accepts an input argument and outputs a result. Since it
|
||||||
* is meant to be used with the DataFetchWorker, it throws an interrupted
|
* is meant to be used with the DataFetchWorker, it throws an interrupted
|
||||||
|
@ -23,7 +23,8 @@ package org.sleuthkit.autopsy.guiutils.internal;
|
|||||||
* DataProcessor.
|
* DataProcessor.
|
||||||
*/
|
*/
|
||||||
public class DataProcessorException extends Exception {
|
public class DataProcessorException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main constructor.
|
* Main constructor.
|
||||||
* @param string The error message.
|
* @param string The error message.
|
||||||
|
@ -42,6 +42,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
|||||||
"DataResultJTable_errorMessage_defaultText=There was an error loading results."
|
"DataResultJTable_errorMessage_defaultText=There was an error loading results."
|
||||||
})
|
})
|
||||||
public class DataResultJTable<T> extends JPanel {
|
public class DataResultJTable<T> extends JPanel {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JTables don't allow display messages. So this LayerUI is used to display
|
* JTables don't allow display messages. So this LayerUI is used to display
|
||||||
@ -50,7 +51,8 @@ public class DataResultJTable<T> extends JPanel {
|
|||||||
* https://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html.
|
* https://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html.
|
||||||
*/
|
*/
|
||||||
private static class Overlay extends LayerUI<JComponent> {
|
private static class Overlay extends LayerUI<JComponent> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final JLabel child;
|
private final JLabel child;
|
||||||
private boolean visible;
|
private boolean visible;
|
||||||
|
|
||||||
@ -96,9 +98,6 @@ public class DataResultJTable<T> extends JPanel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g, JComponent c) {
|
public void paint(Graphics g, JComponent c) {
|
||||||
int w = c.getWidth();
|
|
||||||
int h = c.getHeight();
|
|
||||||
|
|
||||||
// Paint the underlying view.
|
// Paint the underlying view.
|
||||||
super.paint(g, c);
|
super.paint(g, c);
|
||||||
|
|
||||||
@ -106,6 +105,9 @@ public class DataResultJTable<T> extends JPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w = c.getWidth();
|
||||||
|
int h = c.getHeight();
|
||||||
|
|
||||||
// paint the jlabel if visible.
|
// paint the jlabel if visible.
|
||||||
child.setBounds(0, 0, w, h);
|
child.setBounds(0, 0, w, h);
|
||||||
child.paint(g);
|
child.paint(g);
|
||||||
@ -119,17 +121,16 @@ public class DataResultJTable<T> extends JPanel {
|
|||||||
private static final String DEFAULT_NO_RESULTS_MESSAGE = "";
|
private static final String DEFAULT_NO_RESULTS_MESSAGE = "";
|
||||||
private static final String DEFAULT_NOT_LOADED_MESSAGE = "";
|
private static final String DEFAULT_NOT_LOADED_MESSAGE = "";
|
||||||
|
|
||||||
private final JTable table;
|
|
||||||
private final JScrollPane tableScrollPane;
|
private final JScrollPane tableScrollPane;
|
||||||
private final JLayer<JComponent> dualLayer;
|
|
||||||
private final Overlay overlayLayer;
|
private final Overlay overlayLayer;
|
||||||
|
private final PojoListTableDataModel<T> tableModel;
|
||||||
|
|
||||||
private String loadingMessage = DEFAULT_LOADING_MESSAGE;
|
private String loadingMessage = DEFAULT_LOADING_MESSAGE;
|
||||||
private String errorMessage = DEFAULT_ERROR_MESSAGE;
|
private String errorMessage = DEFAULT_ERROR_MESSAGE;
|
||||||
private String noResultsMessage = DEFAULT_NO_RESULTS_MESSAGE;
|
private String noResultsMessage = DEFAULT_NO_RESULTS_MESSAGE;
|
||||||
private String notLoadedMessage = DEFAULT_NOT_LOADED_MESSAGE;
|
private String notLoadedMessage = DEFAULT_NOT_LOADED_MESSAGE;
|
||||||
|
|
||||||
private PojoListTableDataModel<T> tableModel = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main constructor.
|
* Main constructor.
|
||||||
@ -137,12 +138,12 @@ public class DataResultJTable<T> extends JPanel {
|
|||||||
*/
|
*/
|
||||||
public DataResultJTable(PojoListTableDataModel<T> tableModel) {
|
public DataResultJTable(PojoListTableDataModel<T> tableModel) {
|
||||||
this.tableModel = tableModel;
|
this.tableModel = tableModel;
|
||||||
this.table = new JTable(tableModel, tableModel.getTableColumnModel());
|
JTable table = new JTable(tableModel, tableModel.getTableColumnModel());
|
||||||
this.table.getTableHeader().setReorderingAllowed(false);
|
table.getTableHeader().setReorderingAllowed(false);
|
||||||
|
|
||||||
this.overlayLayer = new Overlay();
|
this.overlayLayer = new Overlay();
|
||||||
this.tableScrollPane = new JScrollPane(table);
|
this.tableScrollPane = new JScrollPane(table);
|
||||||
this.dualLayer = new JLayer<JComponent>(tableScrollPane, overlayLayer);
|
JLayer<JComponent> dualLayer = new JLayer<JComponent>(tableScrollPane, overlayLayer);
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
add(dualLayer, BorderLayout.CENTER);
|
add(dualLayer, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
@ -157,21 +158,21 @@ public class DataResultJTable<T> extends JPanel {
|
|||||||
/**
|
/**
|
||||||
* @return The message shown when there is an exception.
|
* @return The message shown when there is an exception.
|
||||||
*/
|
*/
|
||||||
String getErrorMessage() {
|
public String getErrorMessage() {
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message shown when there are no results.
|
* @return The message shown when there are no results.
|
||||||
*/
|
*/
|
||||||
String getNoResultsMessage() {
|
public String getNoResultsMessage() {
|
||||||
return noResultsMessage;
|
return noResultsMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message shown when the table has not been loaded.
|
* @return The message shown when the table has not been loaded.
|
||||||
*/
|
*/
|
||||||
String getNotLoadedMessage() {
|
public String getNotLoadedMessage() {
|
||||||
return notLoadedMessage;
|
return notLoadedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
* class provides a TableModel and TableColumnModel to be used with that class.
|
* class provides a TableModel and TableColumnModel to be used with that class.
|
||||||
*/
|
*/
|
||||||
public class DefaultPojoListTableDataModel<T> extends AbstractTableModel implements PojoListTableDataModel<T> {
|
public class DefaultPojoListTableDataModel<T> extends AbstractTableModel implements PojoListTableDataModel<T> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the horizontal alignment.
|
* Describes the horizontal alignment.
|
||||||
*/
|
*/
|
||||||
@ -63,8 +64,7 @@ public class DefaultPojoListTableDataModel<T> extends AbstractTableModel impleme
|
|||||||
/**
|
/**
|
||||||
* The default cell model.
|
* The default cell model.
|
||||||
*/
|
*/
|
||||||
public static class DefaultCellModel implements CellModel {
|
public static class DefaultCellModel implements CellModel {
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
private String tooltip;
|
private String tooltip;
|
||||||
|
|
||||||
@ -300,6 +300,9 @@ public class DefaultPojoListTableDataModel<T> extends AbstractTableModel impleme
|
|||||||
case RIGHT:
|
case RIGHT:
|
||||||
defaultCell.setHorizontalAlignment(JLabel.RIGHT);
|
defaultCell.setHorizontalAlignment(JLabel.RIGHT);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown horizontal alignment choice: " +
|
||||||
|
columnModel.getCellHorizontalAlignment());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defaultCell.setHorizontalAlignment(JLabel.LEFT);
|
defaultCell.setHorizontalAlignment(JLabel.LEFT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user