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:
Brian Carrier 2013-08-16 12:52:54 -04:00
parent 1a6c40d97d
commit 2fb3dc67c6
7 changed files with 101 additions and 114 deletions

View File

@ -1,4 +1,5 @@
Changes to make to API when we are ready to make backward incompatible changes: 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. - 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

View File

@ -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. // set the tab to the one the user wants, then set that viewer's node.
jTabbedPane1.setSelectedIndex(tabIndex); 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 @Override

View File

@ -231,18 +231,21 @@ public class DataContentViewerArtifact extends javax.swing.JPanel implements Dat
@Override @Override
public void setNode(Node selectedNode) { public void setNode(Node selectedNode) {
if (selectedNode == null) { if (selectedNode == null) {
this.setDataView(new ArrayList<BlackboardArtifact>(), 1); resetComponent();
return; return;
} }
Lookup lookup = selectedNode.getLookup(); Lookup lookup = selectedNode.getLookup();
Content content = lookup.lookup(Content.class); Content content = lookup.lookup(Content.class);
if (content != null) { if (content == null) {
try { resetComponent();
this.setDataView(content.getAllArtifacts(), 1); return;
} catch (TskException ex) { }
logger.log(Level.WARNING, "Couldn't get artifacts: ", ex);
} 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 // 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>(); this.artifacts = new ArrayList<BlackboardArtifact>();
currentPageLabel.setText(""); currentPageLabel.setText("");
totalPageLabel.setText(""); totalPageLabel.setText("");
outputViewPane.setText("");
prevPageButton.setEnabled(false); prevPageButton.setEnabled(false);
nextPageButton.setEnabled(false); nextPageButton.setEnabled(false);
setComponentsVisibility(false); // hides the components that not needed 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)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
if(artifacts.isEmpty()){ if(artifacts.isEmpty()){
setComponentsVisibility(false); resetComponent();
this.setCursor(null);
outputViewPane.setText("");
return; return;
} }
this.artifacts = artifacts; this.artifacts = artifacts;

View File

@ -247,7 +247,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
currentOffset -= pageLength; currentOffset -= pageLength;
currentPage = currentPage - 1; currentPage = currentPage - 1;
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
}//GEN-LAST:event_prevPageButtonActionPerformed }//GEN-LAST:event_prevPageButtonActionPerformed
private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed 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; currentOffset += pageLength;
currentPage = currentPage + 1; currentPage = currentPage + 1;
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
}//GEN-LAST:event_nextPageButtonActionPerformed }//GEN-LAST:event_nextPageButtonActionPerformed
private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed 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; currentOffset = (pageNumber - 1) * pageLength;
currentPage = pageNumber; currentPage = pageNumber;
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
}//GEN-LAST:event_goToPageTextFieldActionPerformed }//GEN-LAST:event_goToPageTextFieldActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem copyMenuItem; private javax.swing.JMenuItem copyMenuItem;
@ -295,14 +295,23 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
private javax.swing.JLabel totalPageLabel; private javax.swing.JLabel totalPageLabel;
// End of variables declaration//GEN-END:variables // 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) * Sets the DataView (The tabbed panel)
* *
* @param dataSource the content that want to be shown * @param dataSource the content that want to be shown
* @param offset the starting offset * @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) { if (dataSource == null) {
return; return;
} }
@ -312,14 +321,12 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
this.dataSource = dataSource; this.dataSource = dataSource;
String errorText = null; String errorText = null;
Boolean setVisible = false;
int bytesRead = 0; int bytesRead = 0;
if (!reset && dataSource.getSize() > 0) { if (dataSource.getSize() > 0) {
try { try {
bytesRead = dataSource.read(data, offset, pageLength); // read the data bytesRead = dataSource.read(data, offset, pageLength); // read the data
} catch (TskException ex) { } catch (TskException ex) {
setVisible = true;
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength) errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)"; + " could not be read)";
logger.log(Level.WARNING, "Error while trying to show the hex content.", ex); 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 // set the data on the bottom and show it
if (bytesRead > 0) { if (bytesRead <= 0) {
setVisible = true;
}
else {
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength) errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)"; + " could not be read)";
setVisible = true;
} }
// disable or enable the next button // disable or enable the next button
if (!reset && offset + pageLength < dataSource.getSize()) { if ((errorText != null) && (offset + pageLength < dataSource.getSize())) {
nextPageButton.setEnabled(true); nextPageButton.setEnabled(true);
} else { } else {
nextPageButton.setEnabled(false); nextPageButton.setEnabled(false);
} }
if (offset == 0) { if ((offset == 0) || (errorText == null)) {
prevPageButton.setEnabled(false); prevPageButton.setEnabled(false);
currentPage = 1; // reset the page number currentPage = 1; // reset the page number
} else { } else {
prevPageButton.setEnabled(true); prevPageButton.setEnabled(true);
} }
if (setVisible) { int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1; totalPageLabel.setText(Integer.toString(totalPage));
totalPageLabel.setText(Integer.toString(totalPage)); currentPageLabel.setText(Integer.toString(currentPage));
currentPageLabel.setText(Integer.toString(currentPage)); setComponentsVisibility(true); // shows the components that not needed
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; int showLength = bytesRead < pageLength ? bytesRead : (int) pageLength;
if (errorText == null) { outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont()));
outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont())); }
} else {
else { outputViewPane.setText(errorText);
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.moveCaretPosition(0); outputViewPane.moveCaretPosition(0);
this.setCursor(null); this.setCursor(null);
} }
@Override @Override
public void setNode(Node selectedNode) { public void setNode(Node selectedNode) {
if ((selectedNode == null) || (!isSupported(selectedNode))) { if ((selectedNode == null) || (!isSupported(selectedNode))) {
setDataView(null, 0, true); resetComponent();
return; return;
} }
Content content = (selectedNode).getLookup().lookup(Content.class); Content content = (selectedNode).getLookup().lookup(Content.class);
if (content == null) { if (content == null) {
this.setDataView(null, 0, true); resetComponent();
return; return;
} }
this.setDataView(content, 0, false); this.setDataView(content, 0);
} }
@Override @Override
@ -420,8 +412,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
this.dataSource = null; this.dataSource = null;
currentPageLabel.setText(""); currentPageLabel.setText("");
totalPageLabel.setText(""); totalPageLabel.setText("");
prevPageButton.setEnabled(false); outputViewPane.setText("");
nextPageButton.setEnabled(false);
setComponentsVisibility(false); // hides the components that not needed setComponentsVisibility(false); // hides the components that not needed
} }
@ -448,8 +439,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
return false; return false;
} }
Content content = node.getLookup().lookup(Content.class); Content content = node.getLookup().lookup(Content.class);
if (content != null && content.getSize() > 0) {
if (content != null && content.getSize() != 0) {
return true; return true;
} }

View File

@ -110,14 +110,14 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
@Override @Override
public void setNode(Node selectedNode) { public void setNode(Node selectedNode) {
if (selectedNode == null) { if (selectedNode == null) {
videoPanel.reset(); resetComponent();
return; return;
} }
AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class); AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
if (file == null) { if (file == null) {
resetComponent();
return; return;
} }
@ -177,15 +177,13 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
@Override @Override
public void resetComponent() { public void resetComponent() {
// we don't want this to do anything videoPanel.reset();
// because we already reset on each selected node
} }
@Override @Override
public boolean isSupported(Node node) { public boolean isSupported(Node node) {
if (node == null) { if (node == null) {
return false; return false;
} }
@ -195,13 +193,11 @@ public class DataContentViewerMedia extends javax.swing.JPanel implements DataCo
return false; return false;
} }
if (file.getSize() == 0) { if (file.getSize() == 0) {
return false; return false;
} }
String name = file.getName().toLowerCase(); String name = file.getName().toLowerCase();
if (imagePanelInited && containsExt(name, IMAGES)) { if (imagePanelInited && containsExt(name, IMAGES)) {
return true; return true;
} //for gstreamer formats, check if initialized first, then } //for gstreamer formats, check if initialized first, then

View File

@ -265,7 +265,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
currentOffset -= pageLength; currentOffset -= pageLength;
currentPage = currentPage - 1; currentPage = currentPage - 1;
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
}//GEN-LAST:event_prevPageButtonActionPerformed }//GEN-LAST:event_prevPageButtonActionPerformed
private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed 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; currentOffset += pageLength;
currentPage = currentPage + 1; currentPage = currentPage + 1;
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
}//GEN-LAST:event_nextPageButtonActionPerformed }//GEN-LAST:event_nextPageButtonActionPerformed
private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed 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; currentOffset = (pageNumber - 1) * pageLength;
currentPage = pageNumber; currentPage = pageNumber;
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
}//GEN-LAST:event_goToPageTextFieldActionPerformed }//GEN-LAST:event_goToPageTextFieldActionPerformed
private void languageComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_languageComboActionPerformed private void languageComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_languageComboActionPerformed
if (dataSource != null) { if (dataSource != null) {
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset);
} }
}//GEN-LAST:event_languageComboActionPerformed }//GEN-LAST:event_languageComboActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // 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; private javax.swing.JLabel totalPageLabel;
// End of variables declaration//GEN-END:variables // 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) * Sets the DataView (The tabbed panel)
* *
* @param dataSource the content that want to be shown * @param dataSource the content that want to be shown
* @param offset the starting offset * @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) { if (dataSource == null) {
return; return;
} }
@ -342,14 +350,12 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
int bytesRead = 0; int bytesRead = 0;
// set the data on the bottom and show it // set the data on the bottom and show it
String text = ""; String text = "";
Boolean setVisible = false; if (dataSource.getSize() > 0) {
if (!reset && dataSource.getSize() > 0) {
try { try {
bytesRead = dataSource.read(data, offset, pageLength); // read the data bytesRead = dataSource.read(data, offset, pageLength); // read the data
} catch (TskException ex) { } catch (TskException ex) {
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength) text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)"; + " could not be read)";
setVisible = true;
logger.log(Level.WARNING, "Error while trying to show the String content.", ex); 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) text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " contains no text)"; + " contains no text)";
} }
setVisible = true;
} else { } else {
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength) text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)"; + " could not be read)";
setVisible = true;
} }
// disable or enable the next button // disable or enable the next button
if (!reset && offset + pageLength < dataSource.getSize()) { if (offset + pageLength < dataSource.getSize()) {
nextPageButton.setEnabled(true); nextPageButton.setEnabled(true);
} else { } else {
nextPageButton.setEnabled(false); nextPageButton.setEnabled(false);
@ -386,23 +389,15 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
prevPageButton.setEnabled(true); prevPageButton.setEnabled(true);
} }
if (setVisible) {
int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1; int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
totalPageLabel.setText(Integer.toString(totalPage)); totalPageLabel.setText(Integer.toString(totalPage));
currentPageLabel.setText(Integer.toString(currentPage)); currentPageLabel.setText(Integer.toString(currentPage));
outputViewPane.setText(text); // set the output view outputViewPane.setText(text); // set the output view
setComponentsVisibility(true); // shows the components that not needed 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
}
outputViewPane.moveCaretPosition(0); outputViewPane.moveCaretPosition(0);
this.setCursor(null); this.setCursor(null);
} }
/** /**
@ -422,31 +417,28 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
goToPageLabel.setVisible(isVisible); goToPageLabel.setVisible(isVisible);
languageCombo.setVisible(isVisible); languageCombo.setVisible(isVisible);
languageLabel.setVisible(isVisible); languageLabel.setVisible(isVisible);
} }
@Override @Override
public void setNode(Node selectedNode) { public void setNode(Node selectedNode) {
if (!isSupported(selectedNode)) { if ((selectedNode == null) || (!isSupported(selectedNode))) {
setDataView(null, 0, true); resetComponent();
return; return;
} }
if (selectedNode != null) {
Lookup lookup = selectedNode.getLookup(); Lookup lookup = selectedNode.getLookup();
Content content = lookup.lookup(Content.class); Content content = lookup.lookup(Content.class);
if (content if (content != null) {
!= null) { this.setDataView(content, 0);
this.setDataView(content, 0, false); return;
} else {
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
if (scontent != null) {
this.setDataView(scontent);
return; return;
} else {
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
if (scontent != null) {
this.setDataView(scontent);
return;
}
} }
} }
this.setDataView(null, 0, true); resetComponent();
} }
@Override @Override
@ -474,6 +466,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
totalPageLabel.setText(""); totalPageLabel.setText("");
prevPageButton.setEnabled(false); prevPageButton.setEnabled(false);
nextPageButton.setEnabled(false); nextPageButton.setEnabled(false);
outputViewPane.setText(""); // reset the output view
setComponentsVisibility(false); // hides the components that not needed 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) { public boolean isSupported(Node node) {
if (node == null) { if (node == null) {
return false; return false;
} }
Content content = node.getLookup().lookup(Content.class); Content content = node.getLookup().lookup(Content.class);
if (content != null && content.getSize() > 0) {
if (content
!= null && content.getSize()
!= 0) {
return true; return true;
} }

View File

@ -416,14 +416,16 @@ public class ExtractedContentViewer implements DataContentViewer {
//because we are storing extracted text in chunks only //because we are storing extracted text in chunks only
//and the non-chunk stores meta-data only //and the non-chunk stores meta-data only
String name = contentObj.getName(); 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) { if (contentObj instanceof AbstractFile) {
//we know it's AbstractFile, but do quick check to make sure if we index other objects in future //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()); boolean isKnown = FileKnown.KNOWN.equals(((AbstractFile)contentObj).getKnown());
if (isKnown && KeywordSearchSettings.getSkipKnown()) { 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>"; String htmlMsg = "<span style='font-style:italic'>" + msg + "</span>";
return htmlMsg; return htmlMsg;