19 package org.sleuthkit.autopsy.corecomponents;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.List;
25 import java.util.logging.Level;
27 import org.openide.util.NbBundle;
29 import javax.swing.JMenuItem;
30 import javax.swing.JOptionPane;
31 import javax.swing.JTextPane;
32 import org.openide.nodes.Node;
33 import org.openide.util.Lookup;
34 import org.openide.util.lookup.ServiceProvider;
46 @ServiceProvider(service = DataContentViewer.class, position = 2)
49 private static long currentOffset = 0;
50 private static final long pageLength = 16384;
51 private final byte[] data =
new byte[(int) pageLength];
52 private static int currentPage = 1;
63 customizeComponents();
64 this.resetComponent();
65 logger.log(Level.INFO,
"Created StringView instance: " +
this);
69 outputViewPane.setComponentPopupMenu(rightClickMenu);
70 ActionListener actList =
new ActionListener() {
72 public void actionPerformed(ActionEvent e) {
73 JMenuItem jmi = (JMenuItem) e.getSource();
74 if (jmi.equals(copyMenuItem)) {
75 outputViewPane.copy();
76 }
else if (jmi.equals(selectAllMenuItem)) {
77 outputViewPane.selectAll();
81 copyMenuItem.addActionListener(actList);
82 selectAllMenuItem.addActionListener(actList);
85 for (
SCRIPT s : supportedScripts) {
86 languageCombo.addItem(s);
96 @SuppressWarnings(
"unchecked")
98 private
void initComponents() {
100 rightClickMenu =
new javax.swing.JPopupMenu();
101 copyMenuItem =
new javax.swing.JMenuItem();
102 selectAllMenuItem =
new javax.swing.JMenuItem();
103 jPanel1 =
new javax.swing.JPanel();
104 jScrollPane1 =
new javax.swing.JScrollPane();
105 outputViewPane =
new JTextPane(){
106 public boolean getScrollableTracksViewportWidth() {
107 return (getSize().width < 400);
109 totalPageLabel =
new javax.swing.JLabel();
110 ofLabel =
new javax.swing.JLabel();
111 currentPageLabel =
new javax.swing.JLabel();
112 pageLabel =
new javax.swing.JLabel();
113 nextPageButton =
new javax.swing.JButton();
114 pageLabel2 =
new javax.swing.JLabel();
115 prevPageButton =
new javax.swing.JButton();
116 goToPageLabel =
new javax.swing.JLabel();
117 goToPageTextField =
new javax.swing.JTextField();
118 languageCombo =
new javax.swing.JComboBox<>();
119 languageLabel =
new javax.swing.JLabel();
121 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.copyMenuItem.text"));
122 rightClickMenu.add(copyMenuItem);
124 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.selectAllMenuItem.text"));
125 rightClickMenu.add(selectAllMenuItem);
127 setMinimumSize(
new java.awt.Dimension(5, 5));
129 jPanel1.setPreferredSize(
new java.awt.Dimension(502, 424));
131 outputViewPane.setEditable(
false);
132 outputViewPane.setFont(
new Font(
"monospaced", Font.PLAIN, 11));
133 outputViewPane.setPreferredSize(
new java.awt.Dimension(700, 400));
134 jScrollPane1.setViewportView(outputViewPane);
136 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.totalPageLabel.text_1"));
138 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.ofLabel.text_1"));
140 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.currentPageLabel.text_1"));
141 currentPageLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
142 currentPageLabel.setMinimumSize(
new java.awt.Dimension(18, 14));
143 currentPageLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
145 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.pageLabel.text_1"));
146 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 14));
147 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 14));
148 pageLabel.setPreferredSize(
new java.awt.Dimension(33, 14));
150 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
151 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.nextPageButton.text"));
152 nextPageButton.setBorderPainted(
false);
153 nextPageButton.setContentAreaFilled(
false);
154 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
155 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
156 nextPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
157 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
158 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
159 public void actionPerformed(java.awt.event.ActionEvent evt) {
160 nextPageButtonActionPerformed(evt);
164 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.pageLabel2.text"));
165 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 14));
166 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 14));
167 pageLabel2.setPreferredSize(
new java.awt.Dimension(29, 14));
169 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
170 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.prevPageButton.text"));
171 prevPageButton.setBorderPainted(
false);
172 prevPageButton.setContentAreaFilled(
false);
173 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
174 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
175 prevPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
176 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
177 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
178 public void actionPerformed(java.awt.event.ActionEvent evt) {
179 prevPageButtonActionPerformed(evt);
183 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.goToPageLabel.text"));
185 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.goToPageTextField.text"));
186 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
187 public void actionPerformed(java.awt.event.ActionEvent evt) {
188 goToPageTextFieldActionPerformed(evt);
192 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.languageCombo.toolTipText"));
193 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
194 public void actionPerformed(java.awt.event.ActionEvent evt) {
195 languageComboActionPerformed(evt);
199 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.languageLabel.text"));
200 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.languageLabel.toolTipText"));
202 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
203 jPanel1.setLayout(jPanel1Layout);
204 jPanel1Layout.setHorizontalGroup(
205 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206 .addGroup(jPanel1Layout.createSequentialGroup()
208 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
210 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
211 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
212 .addComponent(ofLabel)
213 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
214 .addComponent(totalPageLabel)
216 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
217 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
218 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
220 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
222 .addComponent(goToPageLabel)
223 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
224 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
226 .addComponent(languageLabel)
227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
228 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
229 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
231 jPanel1Layout.setVerticalGroup(
232 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233 .addGroup(jPanel1Layout.createSequentialGroup()
234 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
236 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
237 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238 .addComponent(ofLabel)
239 .addComponent(totalPageLabel))
240 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
241 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
243 .addComponent(goToPageLabel)
244 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
245 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
246 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
247 .addComponent(languageLabel)))
249 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE))
252 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
253 this.setLayout(layout);
254 layout.setHorizontalGroup(
255 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256 .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
258 layout.setVerticalGroup(
259 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260 .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
266 currentOffset -= pageLength;
267 currentPage = currentPage - 1;
268 currentPageLabel.setText(Integer.toString(currentPage));
269 setDataView(dataSource, currentOffset);
274 currentOffset += pageLength;
275 currentPage = currentPage + 1;
276 currentPageLabel.setText(Integer.toString(currentPage));
277 setDataView(dataSource, currentOffset);
281 String pageNumberStr = goToPageTextField.getText();
283 int maxPage = Math.round((dataSource.
getSize() - 1) / pageLength) + 1;
285 pageNumber = Integer.parseInt(pageNumberStr);
286 }
catch (NumberFormatException ex) {
287 pageNumber = maxPage + 1;
289 if (pageNumber > maxPage || pageNumber < 1) {
290 JOptionPane.showMessageDialog(
this,
291 NbBundle.getMessage(
this.getClass(),
292 "DataContentViewerString.goToPageTextField.msgDlg",
294 NbBundle.getMessage(
this.getClass(),
295 "DataContentViewerString.goToPageTextField.err"),
296 JOptionPane.WARNING_MESSAGE);
299 currentOffset = (pageNumber - 1) * pageLength;
300 currentPage = pageNumber;
301 currentPageLabel.setText(Integer.toString(currentPage));
302 setDataView(dataSource, currentOffset);
307 if (dataSource != null) {
308 setDataView(dataSource, currentOffset);
339 if (dataSource == null) {
344 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
346 this.dataSource = dataSource;
351 if (dataSource.getSize() > 0) {
353 bytesRead = dataSource.
read(data, offset, pageLength);
355 text = NbBundle.getMessage(this.getClass(),
356 "DataContentViewerString.setDataView.errorText", currentOffset,
357 currentOffset + pageLength);
358 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
364 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
368 if (text.trim().isEmpty()) {
369 text = NbBundle.getMessage(this.getClass(),
370 "DataContentViewerString.setDataView.errorNoText", currentOffset,
371 currentOffset + pageLength);
374 text = NbBundle.getMessage(this.getClass(),
"DataContentViewerString.setDataView.errorText", currentOffset,
375 currentOffset + pageLength);
379 if (offset + pageLength < dataSource.getSize()) {
380 nextPageButton.setEnabled(
true);
382 nextPageButton.setEnabled(
false);
386 prevPageButton.setEnabled(
false);
389 prevPageButton.setEnabled(
true);
393 int totalPage = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
394 totalPageLabel.setText(Integer.toString(totalPage));
395 currentPageLabel.setText(Integer.toString(currentPage));
396 outputViewPane.setText(text);
397 setComponentsVisibility(
true);
398 outputViewPane.moveCaretPosition(0);
400 this.setCursor(null);
404 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
406 this.dataSource = null;
411 nextPageButton.setEnabled(
false);
413 prevPageButton.setEnabled(
false);
417 totalPageLabel.setText(Integer.toString(totalPage));
418 currentPageLabel.setText(Integer.toString(currentPage));
419 outputViewPane.setText(text);
420 setComponentsVisibility(
true);
421 outputViewPane.moveCaretPosition(0);
423 this.setCursor(null);
433 currentPageLabel.setVisible(isVisible);
434 totalPageLabel.setVisible(isVisible);
435 ofLabel.setVisible(isVisible);
436 prevPageButton.setVisible(isVisible);
437 nextPageButton.setVisible(isVisible);
438 pageLabel.setVisible(isVisible);
439 pageLabel2.setVisible(isVisible);
440 goToPageTextField.setVisible(isVisible);
441 goToPageLabel.setVisible(isVisible);
442 languageCombo.setVisible(isVisible);
443 languageLabel.setVisible(isVisible);
448 if ((selectedNode == null) || (!isSupported(selectedNode))) {
453 Lookup lookup = selectedNode.getLookup();
455 if (content != null) {
456 this.setDataView(content, 0);
460 if (scontent != null) {
461 this.setDataView(scontent);
470 return NbBundle.getMessage(this.getClass(),
"DataContentViewerString.title");
475 return NbBundle.getMessage(this.getClass(),
"DataContentViewerString.toolTip");
488 this.dataSource = null;
489 currentPageLabel.setText(
"");
490 totalPageLabel.setText(
"");
491 prevPageButton.setEnabled(
false);
492 nextPageButton.setEnabled(
false);
493 outputViewPane.setText(
"");
494 setComponentsVisibility(
false);
503 if (content != null && content.
getSize() > 0) {
523 if (evt.isPopupTrigger()) {
524 rightClickMenu.setLocation(evt.getLocationOnScreen());
525 rightClickMenu.setVisible(
true);
526 copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
528 rightClickMenu.setVisible(
false);
void maybeShowPopup(java.awt.event.MouseEvent evt)
javax.swing.JLabel pageLabel2
javax.swing.JComboBox< SCRIPT > languageCombo
javax.swing.JLabel totalPageLabel
void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JMenuItem copyMenuItem
javax.swing.JPanel jPanel1
javax.swing.JLabel pageLabel
void setNode(Node selectedNode)
DataContentViewerString()
DataContentViewer createInstance()
javax.swing.JLabel languageLabel
int read(byte[] buf, long offset, long len)
void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt)
void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel ofLabel
void setDataView(Content dataSource, long offset)
javax.swing.JButton prevPageButton
javax.swing.JButton nextPageButton
javax.swing.JMenuItem selectAllMenuItem
javax.swing.JScrollPane jScrollPane1
void setDataView(StringContent dataSource)
javax.swing.JTextField goToPageTextField
int isPreferred(Node node)
void setComponentsVisibility(boolean isVisible)
javax.swing.JLabel goToPageLabel
void languageComboActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JTextPane outputViewPane
javax.swing.JLabel currentPageLabel
boolean isSupported(Node node)
static Logger getLogger(String name)
javax.swing.JPopupMenu rightClickMenu
void customizeComponents()