mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
normalized use of resetComponent for content viewers and better handle case where no tabs are enabled so that viewers reset and old data is not visible.
This commit is contained in:
parent
1a6c40d97d
commit
2fb3dc67c6
@ -1,4 +1,5 @@
|
||||
Changes to make to API when we are ready to make backward incompatible changes:
|
||||
|
||||
- HTMLReport has special API for more context on columns and special handling in REportGenerator. Change all reports to the new API.
|
||||
- DataaContentViewer.isPreferred does not need isSupported to be passed in
|
||||
- DataContentViewer.isPreferred does not need isSupported to be passed in
|
||||
- DataContentViewerHex and STrings can have the public setDataView methods removed in favor of the new private ones
|
@ -191,7 +191,14 @@ public class DataContentPanel extends javax.swing.JPanel implements DataContent,
|
||||
|
||||
// set the tab to the one the user wants, then set that viewer's node.
|
||||
jTabbedPane1.setSelectedIndex(tabIndex);
|
||||
viewers.get(tabIndex).setNode(selectedNode);
|
||||
UpdateWrapper dcv = viewers.get(tabIndex);
|
||||
// this is really only needed if no tabs were enabled
|
||||
if (jTabbedPane1.isEnabledAt(tabIndex) == false) {
|
||||
dcv.resetComponent();
|
||||
}
|
||||
else {
|
||||
dcv.setNode(selectedNode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,18 +231,21 @@ public class DataContentViewerArtifact extends javax.swing.JPanel implements Dat
|
||||
@Override
|
||||
public void setNode(Node selectedNode) {
|
||||
if (selectedNode == null) {
|
||||
this.setDataView(new ArrayList<BlackboardArtifact>(), 1);
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
Lookup lookup = selectedNode.getLookup();
|
||||
Content content = lookup.lookup(Content.class);
|
||||
if (content != null) {
|
||||
try {
|
||||
this.setDataView(content.getAllArtifacts(), 1);
|
||||
} catch (TskException ex) {
|
||||
logger.log(Level.WARNING, "Couldn't get artifacts: ", ex);
|
||||
}
|
||||
if (content == null) {
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.setDataView(content.getAllArtifacts(), 1);
|
||||
} catch (TskException ex) {
|
||||
logger.log(Level.WARNING, "Couldn't get artifacts: ", ex);
|
||||
}
|
||||
|
||||
// focus on a specific artifact if it is in the node
|
||||
@ -279,9 +282,11 @@ public class DataContentViewerArtifact extends javax.swing.JPanel implements Dat
|
||||
this.artifacts = new ArrayList<BlackboardArtifact>();
|
||||
currentPageLabel.setText("");
|
||||
totalPageLabel.setText("");
|
||||
outputViewPane.setText("");
|
||||
prevPageButton.setEnabled(false);
|
||||
nextPageButton.setEnabled(false);
|
||||
setComponentsVisibility(false); // hides the components that not needed
|
||||
this.setCursor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,9 +385,7 @@ public class DataContentViewerArtifact extends javax.swing.JPanel implements Dat
|
||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
|
||||
if(artifacts.isEmpty()){
|
||||
setComponentsVisibility(false);
|
||||
this.setCursor(null);
|
||||
outputViewPane.setText("");
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
this.artifacts = artifacts;
|
||||
|
@ -247,7 +247,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
currentOffset -= pageLength;
|
||||
currentPage = currentPage - 1;
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}//GEN-LAST:event_prevPageButtonActionPerformed
|
||||
|
||||
private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed
|
||||
@ -255,7 +255,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
currentOffset += pageLength;
|
||||
currentPage = currentPage + 1;
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}//GEN-LAST:event_nextPageButtonActionPerformed
|
||||
|
||||
private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed
|
||||
@ -275,7 +275,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
currentOffset = (pageNumber - 1) * pageLength;
|
||||
currentPage = pageNumber;
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}//GEN-LAST:event_goToPageTextFieldActionPerformed
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JMenuItem copyMenuItem;
|
||||
@ -295,14 +295,23 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
private javax.swing.JLabel totalPageLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
|
||||
@Deprecated
|
||||
public void setDataView(Content dataSource, long offset, boolean reset) {
|
||||
if (reset) {
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
setDataView(dataSource, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the DataView (The tabbed panel)
|
||||
*
|
||||
* @param dataSource the content that want to be shown
|
||||
* @param offset the starting offset
|
||||
* @param reset whether to reset the dataView or not
|
||||
*/
|
||||
public void setDataView(Content dataSource, long offset, boolean reset) {
|
||||
private void setDataView(Content dataSource, long offset) {
|
||||
if (dataSource == null) {
|
||||
return;
|
||||
}
|
||||
@ -312,14 +321,12 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
|
||||
this.dataSource = dataSource;
|
||||
String errorText = null;
|
||||
Boolean setVisible = false;
|
||||
|
||||
int bytesRead = 0;
|
||||
if (!reset && dataSource.getSize() > 0) {
|
||||
if (dataSource.getSize() > 0) {
|
||||
try {
|
||||
bytesRead = dataSource.read(data, offset, pageLength); // read the data
|
||||
} catch (TskException ex) {
|
||||
setVisible = true;
|
||||
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||
+ " could not be read)";
|
||||
logger.log(Level.WARNING, "Error while trying to show the hex content.", ex);
|
||||
@ -327,73 +334,58 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
}
|
||||
|
||||
// set the data on the bottom and show it
|
||||
if (bytesRead > 0) {
|
||||
setVisible = true;
|
||||
}
|
||||
else {
|
||||
if (bytesRead <= 0) {
|
||||
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||
+ " could not be read)";
|
||||
setVisible = true;
|
||||
}
|
||||
|
||||
|
||||
// disable or enable the next button
|
||||
if (!reset && offset + pageLength < dataSource.getSize()) {
|
||||
if ((errorText != null) && (offset + pageLength < dataSource.getSize())) {
|
||||
nextPageButton.setEnabled(true);
|
||||
} else {
|
||||
nextPageButton.setEnabled(false);
|
||||
}
|
||||
|
||||
if (offset == 0) {
|
||||
if ((offset == 0) || (errorText == null)) {
|
||||
prevPageButton.setEnabled(false);
|
||||
currentPage = 1; // reset the page number
|
||||
} else {
|
||||
prevPageButton.setEnabled(true);
|
||||
}
|
||||
|
||||
if (setVisible) {
|
||||
int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
|
||||
totalPageLabel.setText(Integer.toString(totalPage));
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setComponentsVisibility(true); // shows the components that not needed
|
||||
int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
|
||||
totalPageLabel.setText(Integer.toString(totalPage));
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setComponentsVisibility(true); // shows the components that not needed
|
||||
|
||||
// set the output view
|
||||
// set the output view
|
||||
if (errorText == null) {
|
||||
int showLength = bytesRead < pageLength ? bytesRead : (int) pageLength;
|
||||
if (errorText == null) {
|
||||
outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont()));
|
||||
}
|
||||
else {
|
||||
outputViewPane.setText(errorText);
|
||||
}
|
||||
|
||||
} else {
|
||||
// reset or hide the labels
|
||||
totalPageLabel.setText("");
|
||||
currentPageLabel.setText("");
|
||||
outputViewPane.setText(""); // reset the output view
|
||||
setComponentsVisibility(false); // hides the components that not needed
|
||||
outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont()));
|
||||
}
|
||||
else {
|
||||
outputViewPane.setText(errorText);
|
||||
}
|
||||
|
||||
outputViewPane.moveCaretPosition(0);
|
||||
|
||||
this.setCursor(null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNode(Node selectedNode) {
|
||||
if ((selectedNode == null) || (!isSupported(selectedNode))) {
|
||||
setDataView(null, 0, true);
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
Content content = (selectedNode).getLookup().lookup(Content.class);
|
||||
if (content == null) {
|
||||
this.setDataView(null, 0, true);
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
this.setDataView(content, 0, false);
|
||||
this.setDataView(content, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -420,8 +412,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
this.dataSource = null;
|
||||
currentPageLabel.setText("");
|
||||
totalPageLabel.setText("");
|
||||
prevPageButton.setEnabled(false);
|
||||
nextPageButton.setEnabled(false);
|
||||
outputViewPane.setText("");
|
||||
setComponentsVisibility(false); // hides the components that not needed
|
||||
}
|
||||
|
||||
@ -448,8 +439,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
|
||||
return false;
|
||||
}
|
||||
Content content = node.getLookup().lookup(Content.class);
|
||||
|
||||
if (content != null && content.getSize() != 0) {
|
||||
if (content != null && content.getSize() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -110,14 +110,14 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
|
||||
|
||||
@Override
|
||||
public void setNode(Node selectedNode) {
|
||||
|
||||
if (selectedNode == null) {
|
||||
videoPanel.reset();
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
|
||||
if (file == null) {
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -177,15 +177,13 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
|
||||
|
||||
@Override
|
||||
public void resetComponent() {
|
||||
// we don't want this to do anything
|
||||
// because we already reset on each selected node
|
||||
videoPanel.reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSupported(Node node) {
|
||||
|
||||
if (node == null) {
|
||||
return false;
|
||||
}
|
||||
@ -195,13 +193,11 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (file.getSize() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String name = file.getName().toLowerCase();
|
||||
|
||||
if (imagePanelInited && containsExt(name, IMAGES)) {
|
||||
return true;
|
||||
} //for gstreamer formats, check if initialized first, then
|
||||
|
@ -265,7 +265,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
currentOffset -= pageLength;
|
||||
currentPage = currentPage - 1;
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}//GEN-LAST:event_prevPageButtonActionPerformed
|
||||
|
||||
private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed
|
||||
@ -273,7 +273,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
currentOffset += pageLength;
|
||||
currentPage = currentPage + 1;
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}//GEN-LAST:event_nextPageButtonActionPerformed
|
||||
|
||||
private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed
|
||||
@ -293,13 +293,13 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
currentOffset = (pageNumber - 1) * pageLength;
|
||||
currentPage = pageNumber;
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}//GEN-LAST:event_goToPageTextFieldActionPerformed
|
||||
|
||||
private void languageComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_languageComboActionPerformed
|
||||
|
||||
if (dataSource != null) {
|
||||
setDataView(dataSource, currentOffset, false);
|
||||
setDataView(dataSource, currentOffset);
|
||||
}
|
||||
}//GEN-LAST:event_languageComboActionPerformed
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
@ -322,14 +322,22 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
private javax.swing.JLabel totalPageLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
@Deprecated
|
||||
public void setDataView(Content dataSource, long offset, boolean reset) {
|
||||
if (reset) {
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
setDataView(dataSource, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the DataView (The tabbed panel)
|
||||
*
|
||||
* @param dataSource the content that want to be shown
|
||||
* @param offset the starting offset
|
||||
* @param reset whether to reset the dataView or not
|
||||
*/
|
||||
public void setDataView(Content dataSource, long offset, boolean reset) {
|
||||
private void setDataView(Content dataSource, long offset) {
|
||||
if (dataSource == null) {
|
||||
return;
|
||||
}
|
||||
@ -342,14 +350,12 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
int bytesRead = 0;
|
||||
// set the data on the bottom and show it
|
||||
String text = "";
|
||||
Boolean setVisible = false;
|
||||
if (!reset && dataSource.getSize() > 0) {
|
||||
if (dataSource.getSize() > 0) {
|
||||
try {
|
||||
bytesRead = dataSource.read(data, offset, pageLength); // read the data
|
||||
} catch (TskException ex) {
|
||||
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||
+ " could not be read)";
|
||||
setVisible = true;
|
||||
logger.log(Level.WARNING, "Error while trying to show the String content.", ex);
|
||||
}
|
||||
}
|
||||
@ -364,16 +370,13 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||
+ " contains no text)";
|
||||
}
|
||||
|
||||
setVisible = true;
|
||||
} else {
|
||||
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
|
||||
+ " could not be read)";
|
||||
setVisible = true;
|
||||
}
|
||||
|
||||
// disable or enable the next button
|
||||
if (!reset && offset + pageLength < dataSource.getSize()) {
|
||||
if (offset + pageLength < dataSource.getSize()) {
|
||||
nextPageButton.setEnabled(true);
|
||||
} else {
|
||||
nextPageButton.setEnabled(false);
|
||||
@ -386,23 +389,15 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
prevPageButton.setEnabled(true);
|
||||
}
|
||||
|
||||
if (setVisible) {
|
||||
int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
|
||||
totalPageLabel.setText(Integer.toString(totalPage));
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
outputViewPane.setText(text); // set the output view
|
||||
setComponentsVisibility(true); // shows the components that not needed
|
||||
} else {
|
||||
// reset or hide the labels
|
||||
totalPageLabel.setText("");
|
||||
currentPageLabel.setText("");
|
||||
outputViewPane.setText(""); // reset the output view
|
||||
setComponentsVisibility(false); // hides the components that not needed
|
||||
}
|
||||
|
||||
int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
|
||||
totalPageLabel.setText(Integer.toString(totalPage));
|
||||
currentPageLabel.setText(Integer.toString(currentPage));
|
||||
outputViewPane.setText(text); // set the output view
|
||||
setComponentsVisibility(true); // shows the components that not needed
|
||||
outputViewPane.moveCaretPosition(0);
|
||||
|
||||
this.setCursor(null);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -422,31 +417,28 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
goToPageLabel.setVisible(isVisible);
|
||||
languageCombo.setVisible(isVisible);
|
||||
languageLabel.setVisible(isVisible);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNode(Node selectedNode) {
|
||||
if (!isSupported(selectedNode)) {
|
||||
setDataView(null, 0, true);
|
||||
if ((selectedNode == null) || (!isSupported(selectedNode))) {
|
||||
resetComponent();
|
||||
return;
|
||||
}
|
||||
if (selectedNode != null) {
|
||||
Lookup lookup = selectedNode.getLookup();
|
||||
Content content = lookup.lookup(Content.class);
|
||||
if (content
|
||||
!= null) {
|
||||
this.setDataView(content, 0, false);
|
||||
|
||||
Lookup lookup = selectedNode.getLookup();
|
||||
Content content = lookup.lookup(Content.class);
|
||||
if (content != null) {
|
||||
this.setDataView(content, 0);
|
||||
return;
|
||||
} else {
|
||||
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
|
||||
if (scontent != null) {
|
||||
this.setDataView(scontent);
|
||||
return;
|
||||
} else {
|
||||
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
|
||||
if (scontent != null) {
|
||||
this.setDataView(scontent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setDataView(null, 0, true);
|
||||
resetComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -474,6 +466,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
totalPageLabel.setText("");
|
||||
prevPageButton.setEnabled(false);
|
||||
nextPageButton.setEnabled(false);
|
||||
outputViewPane.setText(""); // reset the output view
|
||||
setComponentsVisibility(false); // hides the components that not needed
|
||||
}
|
||||
|
||||
@ -481,14 +474,9 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
|
||||
public boolean isSupported(Node node) {
|
||||
if (node == null) {
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
Content content = node.getLookup().lookup(Content.class);
|
||||
|
||||
if (content
|
||||
!= null && content.getSize()
|
||||
!= 0) {
|
||||
if (content != null && content.getSize() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -416,14 +416,16 @@ public class ExtractedContentViewer implements DataContentViewer {
|
||||
//because we are storing extracted text in chunks only
|
||||
//and the non-chunk stores meta-data only
|
||||
String name = contentObj.getName();
|
||||
String msg = "<p style='font-style:italic'>No extracted text present in the index for file: " + name + " </p>";
|
||||
String msg = null;
|
||||
if (contentObj instanceof AbstractFile) {
|
||||
//we know it's AbstractFile, but do quick check to make sure if we index other objects in future
|
||||
boolean isKnown = FileKnown.KNOWN.equals(((AbstractFile)contentObj).getKnown());
|
||||
if (isKnown && KeywordSearchSettings.getSkipKnown()) {
|
||||
msg += "<p style='font-style:italic'>It is a 'known' file and the current settings opt to skip indexing 'known' files during ingest. </p>";
|
||||
msg = "<p style='font-style:italic'>" + name + " is a known file (based on MD5 hash) and does not have text in the index.</p>";
|
||||
}
|
||||
|
||||
}
|
||||
if (msg == null) {
|
||||
msg = "<p style='font-style:italic'>" + name + "does not have text in the index.<br/>It may have no text, not been analyzed yet, or keyword search was not enabled during ingest.</p>";
|
||||
}
|
||||
String htmlMsg = "<span style='font-style:italic'>" + msg + "</span>";
|
||||
return htmlMsg;
|
||||
|
Loading…
x
Reference in New Issue
Block a user