hex/string viewer handle case when file offset could not be read, which can happen e.g. for deleted content

This commit is contained in:
adam-m 2013-01-31 16:16:12 -05:00
parent 2cadfadfa9
commit 5b21911756
2 changed files with 232 additions and 197 deletions

View File

@ -39,44 +39,47 @@ import org.sleuthkit.datamodel.TskException;
/** /**
* Hex view of file contents. * Hex view of file contents.
*/ */
@ServiceProvider(service = DataContentViewer.class, position=1) @ServiceProvider(service = DataContentViewer.class, position = 1)
public class DataContentViewerHex extends javax.swing.JPanel implements DataContentViewer { public class DataContentViewerHex extends javax.swing.JPanel implements DataContentViewer {
private static long currentOffset = 0; private static long currentOffset = 0;
private static final long pageLength = 16384; private static final long pageLength = 16384;
private final byte[] data = new byte[(int)pageLength]; private final byte[] data = new byte[(int) pageLength];
private static int currentPage = 1; private static int currentPage = 1;
private Content dataSource; private Content dataSource;
// for error handling // for error handling
private String className = this.getClass().toString(); private String className = this.getClass().toString();
/** Creates new form DataContentViewerHex */ /**
* Creates new form DataContentViewerHex
*/
public DataContentViewerHex() { public DataContentViewerHex() {
initComponents(); initComponents();
customizeComponents(); customizeComponents();
this.resetComponent(); this.resetComponent();
} }
private void customizeComponents(){ private void customizeComponents() {
outputViewPane.setComponentPopupMenu(rightClickMenu); outputViewPane.setComponentPopupMenu(rightClickMenu);
ActionListener actList = new ActionListener(){ ActionListener actList = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e){ public void actionPerformed(ActionEvent e) {
JMenuItem jmi = (JMenuItem) e.getSource(); JMenuItem jmi = (JMenuItem) e.getSource();
if(jmi.equals(copyMenuItem)) if (jmi.equals(copyMenuItem)) {
outputViewPane.copy(); outputViewPane.copy();
else if(jmi.equals(selectAllMenuItem)) } else if (jmi.equals(selectAllMenuItem)) {
outputViewPane.selectAll(); outputViewPane.selectAll();
}
} }
}; };
copyMenuItem.addActionListener(actList); copyMenuItem.addActionListener(actList);
selectAllMenuItem.addActionListener(actList); selectAllMenuItem.addActionListener(actList);
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -257,7 +260,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed
String pageNumberStr = goToPageTextField.getText(); String pageNumberStr = goToPageTextField.getText();
int pageNumber = 0; int pageNumber = 0;
int maxPage = Math.round((dataSource.getSize()-1) / pageLength) + 1; int maxPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
try { try {
pageNumber = Integer.parseInt(pageNumberStr); pageNumber = Integer.parseInt(pageNumberStr);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
@ -268,12 +271,11 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
"Invalid page number", JOptionPane.WARNING_MESSAGE); "Invalid page number", JOptionPane.WARNING_MESSAGE);
return; return;
} }
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, false);
}//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;
private javax.swing.JLabel currentPageLabel; private javax.swing.JLabel currentPageLabel;
@ -295,73 +297,91 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
/** /**
* 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 * @param reset whether to reset the dataView or not
*/ */
public void setDataView(Content dataSource, long offset, boolean reset) { public void setDataView(Content dataSource, long offset, boolean reset) {
if (dataSource == null) {
return;
}
// change the cursor to "waiting cursor" for this operation // change the cursor to "waiting cursor" for this operation
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
this.dataSource = dataSource;
String errorText = null;
Boolean setVisible = false;
int bytesRead = 0;
if (!reset && dataSource.getSize() > 0) {
try { try {
this.dataSource = dataSource; bytesRead = dataSource.read(data, offset, pageLength); // read the data
int bytesRead =0;
if (!reset && dataSource.getSize() > 0) {
bytesRead = dataSource.read(data, offset, pageLength); // read the data
}
// set the data on the bottom and show it
Boolean setVisible = false;
if (bytesRead > 0) {
setVisible = true;
}
// disable or enable the next button
if (!reset && offset + pageLength < dataSource.getSize()) {
nextPageButton.setEnabled(true);
} else {
nextPageButton.setEnabled(false);
}
if (offset == 0) {
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
// set the output view
int showLength = bytesRead<pageLength?bytesRead:(int)pageLength;
outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset, outputViewPane.getFont()));
} 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);
} catch (TskException ex) { } catch (TskException ex) {
// TODO: maybe make this error bubble up further setVisible = true;
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)";
Logger.getLogger(this.className).log(Level.WARNING, "Error while trying to show the hex content.", ex); Logger.getLogger(this.className).log(Level.WARNING, "Error while trying to show the hex content.", ex);
} }
} finally {
this.setCursor(null);
} }
// set the data on the bottom and show it
if (bytesRead > 0) {
setVisible = true;
}
else {
errorText = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)";
setVisible = true;
}
// disable or enable the next button
if (!reset && offset + pageLength < dataSource.getSize()) {
nextPageButton.setEnabled(true);
} else {
nextPageButton.setEnabled(false);
}
if (offset == 0) {
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
// set the output view
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.moveCaretPosition(0);
this.setCursor(null);
} }
@Override @Override
public void setNode(Node selectedNode) { public void setNode(Node selectedNode) {
if(!isSupported(selectedNode)) { if (!isSupported(selectedNode)) {
setDataView(null, 0, true); setDataView(null, 0, true);
return; return;
} }
@ -379,7 +399,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
public String getTitle() { public String getTitle() {
return "Hex View"; return "Hex View";
} }
@Override @Override
public String getToolTip() { public String getToolTip() {
return "Displays the binary contents of a file as hexidecimal, with " return "Displays the binary contents of a file as hexidecimal, with "
@ -407,7 +427,7 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
/** /**
* To set the visibility of specific components in this class. * To set the visibility of specific components in this class.
* *
* @param isVisible whether to show or hide the specific components * @param isVisible whether to show or hide the specific components
*/ */
private void setComponentsVisibility(boolean isVisible) { private void setComponentsVisibility(boolean isVisible) {
currentPageLabel.setVisible(isVisible); currentPageLabel.setVisible(isVisible);
@ -423,21 +443,21 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
@Override @Override
public boolean isSupported(Node node) { public boolean isSupported(Node node) {
if(node == null) { if (node == null) {
return false; return false;
} }
FsContent fsContent = node.getLookup().lookup(FsContent.class); Content content = node.getLookup().lookup(Content.class);
LayoutFile lc = node.getLookup().lookup(LayoutFile.class);
if(fsContent != null && fsContent.getSize() != 0) if (content != null && content.getSize() != 0) {
return true;
if(lc != null && lc.getSize() != 0)
return true; return true;
}
return false; return false;
} }
@Override @Override
public int isPreferred(Node node, boolean isSupported) { public int isPreferred(Node node, boolean isSupported) {
if(isSupported) { if (isSupported) {
return 1; return 1;
} else { } else {
return 0; return 0;
@ -448,14 +468,15 @@ public class DataContentViewerHex extends javax.swing.JPanel implements DataCont
public Component getComponent() { public Component getComponent() {
return this; return this;
} }
/* Show the right click menu only if evt is the correct mouse event */ /* Show the right click menu only if evt is the correct mouse event */
private void maybeShowPopup(java.awt.event.MouseEvent evt){ private void maybeShowPopup(java.awt.event.MouseEvent evt) {
if(evt.isPopupTrigger()){ if (evt.isPopupTrigger()) {
rightClickMenu.setLocation(evt.getLocationOnScreen()); rightClickMenu.setLocation(evt.getLocationOnScreen());
rightClickMenu.setVisible(true); rightClickMenu.setVisible(true);
copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null); copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
}else } else {
rightClickMenu.setVisible(false); rightClickMenu.setVisible(false);
}
} }
} }

View File

@ -44,53 +44,55 @@ import org.sleuthkit.datamodel.TskException;
/** /**
* Viewer displays strings extracted from contents. * Viewer displays strings extracted from contents.
*/ */
@ServiceProvider(service = DataContentViewer.class, position=2) @ServiceProvider(service = DataContentViewer.class, position = 2)
public class DataContentViewerString extends javax.swing.JPanel implements DataContentViewer { public class DataContentViewerString extends javax.swing.JPanel implements DataContentViewer {
private static long currentOffset = 0; private static long currentOffset = 0;
private static final long pageLength = 16384; private static final long pageLength = 16384;
private final byte[] data = new byte[(int)pageLength]; private final byte[] data = new byte[(int) pageLength];
private static int currentPage = 1; private static int currentPage = 1;
private Content dataSource; private Content dataSource;
// for error handling // for error handling
private String className = this.getClass().toString(); private String className = this.getClass().toString();
//string extract utility //string extract utility
private final StringExtract stringExtract = new StringExtract(); private final StringExtract stringExtract = new StringExtract();
/** Creates new form DataContentViewerString */ /**
* Creates new form DataContentViewerString
*/
public DataContentViewerString() { public DataContentViewerString() {
initComponents(); initComponents();
customizeComponents(); customizeComponents();
this.resetComponent(); this.resetComponent();
} }
private void customizeComponents(){ private void customizeComponents() {
outputViewPane.setComponentPopupMenu(rightClickMenu); outputViewPane.setComponentPopupMenu(rightClickMenu);
ActionListener actList = new ActionListener(){ ActionListener actList = new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e){ public void actionPerformed(ActionEvent e) {
JMenuItem jmi = (JMenuItem) e.getSource(); JMenuItem jmi = (JMenuItem) e.getSource();
if(jmi.equals(copyMenuItem)) if (jmi.equals(copyMenuItem)) {
outputViewPane.copy(); outputViewPane.copy();
else if(jmi.equals(selectAllMenuItem)) } else if (jmi.equals(selectAllMenuItem)) {
outputViewPane.selectAll(); outputViewPane.selectAll();
}
} }
}; };
copyMenuItem.addActionListener(actList); copyMenuItem.addActionListener(actList);
selectAllMenuItem.addActionListener(actList); selectAllMenuItem.addActionListener(actList);
List<SCRIPT> supportedScripts = StringExtract.getSupportedScripts(); List<SCRIPT> supportedScripts = StringExtract.getSupportedScripts();
for (SCRIPT s : supportedScripts) { for (SCRIPT s : supportedScripts) {
languageCombo.addItem(s); languageCombo.addItem(s);
} }
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@ -273,7 +275,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed
String pageNumberStr = goToPageTextField.getText(); String pageNumberStr = goToPageTextField.getText();
int pageNumber; int pageNumber;
int maxPage = Math.round((dataSource.getSize()-1) / pageLength) + 1; int maxPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
try { try {
pageNumber = Integer.parseInt(pageNumberStr); pageNumber = Integer.parseInt(pageNumberStr);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
@ -284,7 +286,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
"Invalid page number", JOptionPane.WARNING_MESSAGE); "Invalid page number", JOptionPane.WARNING_MESSAGE);
return; return;
} }
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, false);
@ -296,7 +298,6 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
setDataView(dataSource, currentOffset, false); setDataView(dataSource, currentOffset, false);
} }
}//GEN-LAST:event_languageComboActionPerformed }//GEN-LAST:event_languageComboActionPerformed
// 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;
private javax.swing.JLabel currentPageLabel; private javax.swing.JLabel currentPageLabel;
@ -320,82 +321,91 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
/** /**
* 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 * @param reset whether to reset the dataView or not
*/ */
public void setDataView(Content dataSource, long offset, boolean reset) { public void setDataView(Content dataSource, long offset, boolean reset) {
if (dataSource == null) {
return;
}
// change the cursor to "waiting cursor" for this operation // change the cursor to "waiting cursor" for this operation
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
this.dataSource = dataSource;
int bytesRead = 0;
// set the data on the bottom and show it
String text = "";
Boolean setVisible = false;
if (!reset && dataSource.getSize() > 0) {
try { try {
this.dataSource = dataSource; bytesRead = dataSource.read(data, offset, pageLength); // read the data
int bytesRead = 0;
if (!reset && dataSource.getSize() > 0) {
bytesRead = dataSource.read(data, offset, pageLength); // read the data
}
// set the data on the bottom and show it
String text = "";
Boolean setVisible = false;
if (bytesRead > 0) {
//text = DataConversion.getString(data, bytesRead, 4);
final SCRIPT selScript = (SCRIPT) languageCombo.getSelectedItem();
stringExtract.setEnabledScript(selScript);
StringExtractResult res = stringExtract.extract(data, bytesRead, 0);
text = res.getText();
if (text.trim().isEmpty()) {
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " contains no text)";
}
setVisible = true;
}
// disable or enable the next button
if (!reset && offset + pageLength < dataSource.getSize()) {
nextPageButton.setEnabled(true);
} else {
nextPageButton.setEnabled(false);
}
if (offset == 0) {
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));
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
}
outputViewPane.moveCaretPosition(0);
} catch (TskException ex) { } catch (TskException ex) {
text = "(offset " + currentOffset + "-" + (currentOffset + pageLength)
+ " could not be read)";
setVisible = true;
Logger logger = Logger.getLogger(this.className); Logger logger = Logger.getLogger(this.className);
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);
} }
} finally {
this.setCursor(null);
} }
if (bytesRead > 0) {
//text = DataConversion.getString(data, bytesRead, 4);
final SCRIPT selScript = (SCRIPT) languageCombo.getSelectedItem();
stringExtract.setEnabledScript(selScript);
StringExtractResult res = stringExtract.extract(data, bytesRead, 0);
text = res.getText();
if (text.trim().isEmpty()) {
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()) {
nextPageButton.setEnabled(true);
} else {
nextPageButton.setEnabled(false);
}
if (offset == 0) {
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));
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
}
outputViewPane.moveCaretPosition(0);
this.setCursor(null);
} }
/** /**
* To set the visibility of specific components in this class. * To set the visibility of specific components in this class.
* *
* @param isVisible whether to show or hide the specific components * @param isVisible whether to show or hide the specific components
*/ */
private void setComponentsVisibility(boolean isVisible) { private void setComponentsVisibility(boolean isVisible) {
currentPageLabel.setVisible(isVisible); currentPageLabel.setVisible(isVisible);
@ -409,31 +419,30 @@ 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 (!isSupported(selectedNode)) {
setDataView(null, 0, true); setDataView(null, 0, true);
return; return;
} }
if (selectedNode != null) { 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 != null) { if (content
!= null) {
this.setDataView(content, 0, false); this.setDataView(content, 0, false);
return; return;
} } else {
else{
StringContent scontent = selectedNode.getLookup().lookup(StringContent.class); StringContent scontent = selectedNode.getLookup().lookup(StringContent.class);
if(scontent != null){ if (scontent != null) {
this.setDataView(scontent); this.setDataView(scontent);
return; return;
} }
} }
} }
this.setDataView(null, 0, true); this.setDataView(null, 0, true);
} }
@ -441,7 +450,7 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
public String getTitle() { public String getTitle() {
return "String View"; return "String View";
} }
@Override @Override
public String getToolTip() { public String getToolTip() {
return "Displays ASCII strings extracted from the file."; return "Displays ASCII strings extracted from the file.";
@ -467,21 +476,25 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
@Override @Override
public boolean isSupported(Node node) { public boolean isSupported(Node node) {
if(node == null) { if (node == null) {
return false; return false;
} }
FsContent fsContent = node.getLookup().lookup(FsContent.class); Content content = node.getLookup().lookup(Content.class);
LayoutFile lc = node.getLookup().lookup(LayoutFile.class);
if(fsContent != null && fsContent.getSize() != 0) if (content
return true; != null && content.getSize()
if(lc != null && lc.getSize() != 0) != 0) {
return true; return true;
}
return false; return false;
} }
@Override @Override
public int isPreferred(Node node, boolean isSupported) { public int isPreferred(Node node, boolean isSupported) {
if(node != null && isSupported){ if (node != null && isSupported) {
return 1; return 1;
} else { } else {
return 0; return 0;
@ -492,38 +505,39 @@ public class DataContentViewerString extends javax.swing.JPanel implements DataC
public Component getComponent() { public Component getComponent() {
return this; return this;
} }
private void setDataView(StringContent dataSource) { private void setDataView(StringContent dataSource) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try { try {
this.dataSource = null; this.dataSource = null;
// set the data on the bottom and show it // set the data on the bottom and show it
String text = dataSource.getString(); String text = dataSource.getString();
nextPageButton.setEnabled(false); nextPageButton.setEnabled(false);
prevPageButton.setEnabled(false); prevPageButton.setEnabled(false);
currentPage = 1; currentPage = 1;
int totalPage = 1; int totalPage = 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
outputViewPane.moveCaretPosition(0); outputViewPane.moveCaretPosition(0);
} finally { } finally {
this.setCursor(null); this.setCursor(null);
} }
} }
/* Show the right click menu only if evt is the correct mouse event */ /* Show the right click menu only if evt is the correct mouse event */
private void maybeShowPopup(java.awt.event.MouseEvent evt){ private void maybeShowPopup(java.awt.event.MouseEvent evt) {
if(evt.isPopupTrigger()){ if (evt.isPopupTrigger()) {
rightClickMenu.setLocation(evt.getLocationOnScreen()); rightClickMenu.setLocation(evt.getLocationOnScreen());
rightClickMenu.setVisible(true); rightClickMenu.setVisible(true);
copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null); copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
}else } else {
rightClickMenu.setVisible(false); rightClickMenu.setVisible(false);
}
} }
} }