19 package org.sleuthkit.autopsy.contentviewers.textcontentviewer;
21 import java.awt.Cursor;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.List;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
28 import javax.swing.JMenuItem;
29 import javax.swing.JOptionPane;
30 import org.apache.commons.lang3.StringUtils;
41 @SuppressWarnings(
"PMD.SingularField")
44 private static long currentOffset = 0;
45 private static final long PAGE_LENGTH = 16384;
46 private static final long serialVersionUID = 1L;
47 private final byte[] data =
new byte[(int) PAGE_LENGTH];
48 private static int currentPage = 1;
59 customizeComponents();
64 outputViewPane.setComponentPopupMenu(rightClickMenu);
65 ActionListener actList = (ActionEvent e) -> {
66 JMenuItem jmi = (JMenuItem) e.getSource();
67 if (jmi.equals(copyMenuItem)) {
68 outputViewPane.copy();
69 }
else if (jmi.equals(selectAllMenuItem)) {
70 outputViewPane.selectAll();
73 copyMenuItem.addActionListener(actList);
74 selectAllMenuItem.addActionListener(actList);
77 supportedScripts.forEach((s) -> {
78 languageCombo.addItem(s);
83 final void resetDisplay() {
87 this.dataSource = null;
88 currentPageLabel.setText(
"");
89 totalPageLabel.setText(
"");
90 prevPageButton.setEnabled(
false);
91 nextPageButton.setEnabled(
false);
92 outputViewPane.setText(
"");
93 setComponentsVisibility(
false);
101 @SuppressWarnings(
"unchecked")
103 private
void initComponents() {
105 rightClickMenu =
new javax.swing.JPopupMenu();
106 copyMenuItem =
new javax.swing.JMenuItem();
107 selectAllMenuItem =
new javax.swing.JMenuItem();
108 outputScrollPane =
new javax.swing.JScrollPane();
109 outputViewPane =
new javax.swing.JTextPane();
110 controlScrollPane =
new javax.swing.JScrollPane();
111 controlPanel =
new javax.swing.JPanel();
112 totalPageLabel =
new javax.swing.JLabel();
113 ofLabel =
new javax.swing.JLabel();
114 currentPageLabel =
new javax.swing.JLabel();
115 pageLabel =
new javax.swing.JLabel();
116 nextPageButton =
new javax.swing.JButton();
117 pageLabel2 =
new javax.swing.JLabel();
118 prevPageButton =
new javax.swing.JButton();
119 goToPageLabel =
new javax.swing.JLabel();
120 goToPageTextField =
new javax.swing.JTextField();
121 languageCombo =
new javax.swing.JComboBox<>();
122 languageLabel =
new javax.swing.JLabel();
124 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.copyMenuItem.text"));
125 rightClickMenu.add(copyMenuItem);
127 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.selectAllMenuItem.text"));
128 rightClickMenu.add(selectAllMenuItem);
130 setMinimumSize(
new java.awt.Dimension(5, 5));
131 setPreferredSize(
new java.awt.Dimension(100, 58));
133 outputScrollPane.setPreferredSize(
new java.awt.Dimension(640, 402));
135 outputViewPane.setEditable(
false);
136 outputViewPane.setFont(
new java.awt.Font(
"Courier New", 0, 11));
137 outputViewPane.setPreferredSize(
new java.awt.Dimension(100, 40));
138 outputScrollPane.setViewportView(outputViewPane);
140 controlScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
141 controlScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
143 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.totalPageLabel.text_1"));
145 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.ofLabel.text_1"));
147 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.currentPageLabel.text_1"));
148 currentPageLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
149 currentPageLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
151 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel.text_1"));
152 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 14));
153 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 14));
155 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
156 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.nextPageButton.text"));
157 nextPageButton.setBorderPainted(
false);
158 nextPageButton.setContentAreaFilled(
false);
159 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
160 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
161 nextPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
162 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
163 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
164 public void actionPerformed(java.awt.event.ActionEvent evt) {
165 nextPageButtonActionPerformed(evt);
169 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel2.text"));
170 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 14));
171 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 14));
173 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
174 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.prevPageButton.text"));
175 prevPageButton.setBorderPainted(
false);
176 prevPageButton.setContentAreaFilled(
false);
177 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
178 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
179 prevPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
180 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
181 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
182 public void actionPerformed(java.awt.event.ActionEvent evt) {
183 prevPageButtonActionPerformed(evt);
187 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageLabel.text"));
189 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageTextField.text"));
190 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
191 public void actionPerformed(java.awt.event.ActionEvent evt) {
192 goToPageTextFieldActionPerformed(evt);
196 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageCombo.toolTipText"));
197 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
198 public void actionPerformed(java.awt.event.ActionEvent evt) {
199 languageComboActionPerformed(evt);
203 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.text"));
204 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.toolTipText"));
206 javax.swing.GroupLayout controlPanelLayout =
new javax.swing.GroupLayout(controlPanel);
207 controlPanel.setLayout(controlPanelLayout);
208 controlPanelLayout.setHorizontalGroup(
209 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210 .addGroup(controlPanelLayout.createSequentialGroup()
212 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
214 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
215 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
216 .addComponent(ofLabel)
217 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
218 .addComponent(totalPageLabel)
220 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
224 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
226 .addComponent(goToPageLabel)
227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
228 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
229 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
230 .addComponent(languageLabel)
231 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
232 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
235 controlPanelLayout.setVerticalGroup(
236 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237 .addGroup(controlPanelLayout.createSequentialGroup()
238 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
240 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
241 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addComponent(ofLabel)
243 .addComponent(totalPageLabel))
244 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
245 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
246 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
247 .addComponent(goToPageLabel)
248 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
249 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
250 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
251 .addComponent(languageLabel)))
255 controlScrollPane.setViewportView(controlPanel);
257 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
258 this.setLayout(layout);
259 layout.setHorizontalGroup(
260 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261 .addComponent(outputScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
262 .addComponent(controlScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
264 layout.setVerticalGroup(
265 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266 .addGroup(layout.createSequentialGroup()
267 .addComponent(controlScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
269 .addComponent(outputScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
274 if (dataSource != null) {
275 setDataView(dataSource, currentOffset);
280 String pageNumberStr = goToPageTextField.getText();
282 int maxPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
284 pageNumber = Integer.parseInt(pageNumberStr);
285 }
catch (NumberFormatException ex) {
286 pageNumber = maxPage + 1;
288 if (pageNumber > maxPage || pageNumber < 1) {
289 JOptionPane.showMessageDialog(
this,
290 NbBundle.getMessage(
this.getClass(),
291 "StringsTextViewer.goToPageTextField.msgDlg",
293 NbBundle.getMessage(
this.getClass(),
294 "StringsTextViewer.goToPageTextField.err"),
295 JOptionPane.WARNING_MESSAGE);
298 currentOffset = (pageNumber - 1) * PAGE_LENGTH;
299 currentPage = pageNumber;
300 currentPageLabel.setText(Integer.toString(currentPage));
301 setDataView(dataSource, currentOffset);
306 currentOffset -= PAGE_LENGTH;
308 currentPageLabel.setText(Integer.toString(currentPage));
309 setDataView(dataSource, currentOffset);
314 currentOffset += PAGE_LENGTH;
316 currentPageLabel.setText(Integer.toString(currentPage));
317 setDataView(dataSource, currentOffset);
347 void setDataView(Content dataSource,
long offset) {
348 if (dataSource == null) {
352 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
353 this.dataSource = dataSource;
357 if (dataSource.getSize() > 0) {
359 bytesRead = dataSource.read(data, offset, PAGE_LENGTH);
360 }
catch (TskCoreException ex) {
361 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
367 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
371 if (StringUtils.isBlank(text)) {
372 text = NbBundle.getMessage(this.getClass(),
373 "StringsTextViewer.setDataView.errorNoText", currentOffset,
374 currentOffset + PAGE_LENGTH);
377 text = NbBundle.getMessage(this.getClass(),
"StringsTextViewer.setDataView.errorText", currentOffset,
378 currentOffset + PAGE_LENGTH);
382 if (offset + PAGE_LENGTH < dataSource.getSize()) {
383 nextPageButton.setEnabled(
true);
385 nextPageButton.setEnabled(
false);
389 prevPageButton.setEnabled(
false);
392 prevPageButton.setEnabled(
true);
395 int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
396 totalPageLabel.setText(Integer.toString(totalPage));
397 currentPageLabel.setText(Integer.toString(currentPage));
398 outputViewPane.setText(text);
399 setComponentsVisibility(
true);
400 outputViewPane.moveCaretPosition(0);
402 this.setCursor(null);
406 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
408 this.dataSource = null;
412 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);
void languageComboActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel goToPageLabel
javax.swing.JTextPane outputViewPane
javax.swing.JMenuItem copyMenuItem
javax.swing.JLabel ofLabel
void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JPanel controlPanel
javax.swing.JPopupMenu rightClickMenu
javax.swing.JTextField goToPageTextField
javax.swing.JScrollPane controlScrollPane
javax.swing.JButton nextPageButton
javax.swing.JComboBox< SCRIPT > languageCombo
javax.swing.JMenuItem selectAllMenuItem
void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JButton prevPageButton
void setComponentsVisibility(boolean isVisible)
javax.swing.JScrollPane outputScrollPane
void customizeComponents()
javax.swing.JLabel languageLabel
javax.swing.JLabel currentPageLabel
void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel pageLabel
synchronized static Logger getLogger(String name)
javax.swing.JLabel pageLabel2
javax.swing.JLabel totalPageLabel