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.Arrays;
25 import java.util.List;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
28 import org.openide.util.NbBundle;
30 import javax.swing.JMenuItem;
31 import javax.swing.JOptionPane;
32 import javax.swing.SwingWorker;
33 import org.apache.commons.lang3.StringUtils;
34 import org.openide.util.NbBundle.Messages;
46 @SuppressWarnings(
"PMD.SingularField")
49 private static long currentOffset = 0;
50 private static final long PAGE_LENGTH = 16384;
51 private static final long serialVersionUID = 1L;
52 private final byte[] data =
new byte[(int) PAGE_LENGTH];
53 private static int currentPage = 1;
57 private SwingWorker<String, Void>
worker;
64 customizeComponents();
69 outputViewPane.setComponentPopupMenu(rightClickMenu);
70 ActionListener actList = (ActionEvent e) -> {
71 JMenuItem jmi = (JMenuItem) e.getSource();
72 if (jmi.equals(copyMenuItem)) {
73 outputViewPane.copy();
74 }
else if (jmi.equals(selectAllMenuItem)) {
75 outputViewPane.selectAll();
78 copyMenuItem.addActionListener(actList);
79 selectAllMenuItem.addActionListener(actList);
82 supportedScripts.forEach((s) -> {
83 languageCombo.addItem(s);
89 controlPanel.setLayout(layout);
93 final void resetDisplay() {
97 this.dataSource = null;
98 currentPageLabel.setText(
"1");
99 totalPageLabel.setText(
"");
100 prevPageButton.setEnabled(
false);
101 nextPageButton.setEnabled(
false);
102 outputViewPane.setText(
"");
110 @SuppressWarnings(
"unchecked")
112 private
void initComponents() {
114 rightClickMenu =
new javax.swing.JPopupMenu();
115 copyMenuItem =
new javax.swing.JMenuItem();
116 selectAllMenuItem =
new javax.swing.JMenuItem();
117 controlPanel =
new javax.swing.JPanel();
118 javax.swing.JPanel panelPageOfCount =
new javax.swing.JPanel();
119 pageLabel =
new javax.swing.JLabel();
120 javax.swing.JSeparator jSepMed1 =
new javax.swing.JSeparator();
121 currentPageLabel =
new javax.swing.JLabel();
122 javax.swing.JSeparator jSepMed2 =
new javax.swing.JSeparator();
123 ofLabel =
new javax.swing.JLabel();
124 javax.swing.JSeparator jSepMed3 =
new javax.swing.JSeparator();
125 totalPageLabel =
new javax.swing.JLabel();
126 javax.swing.JSeparator jSepMed4 =
new javax.swing.JSeparator();
127 javax.swing.JPanel panelPageNextPrevButton =
new javax.swing.JPanel();
128 pageLabel2 =
new javax.swing.JLabel();
129 javax.swing.JSeparator jSepMed5 =
new javax.swing.JSeparator();
130 prevPageButton =
new javax.swing.JButton();
131 nextPageButton =
new javax.swing.JButton();
132 javax.swing.JSeparator jSepMed6 =
new javax.swing.JSeparator();
133 javax.swing.JPanel panelGoToPage =
new javax.swing.JPanel();
134 goToPageLabel =
new javax.swing.JLabel();
135 javax.swing.JSeparator jSepSm1 =
new javax.swing.JSeparator();
136 goToPageTextField =
new javax.swing.JTextField();
137 javax.swing.JSeparator jSepMed7 =
new javax.swing.JSeparator();
138 panelScriptSelect =
new javax.swing.JPanel();
139 languageLabel =
new javax.swing.JLabel();
140 javax.swing.JSeparator jSepSm2 =
new javax.swing.JSeparator();
141 languageCombo =
new javax.swing.JComboBox<>();
142 outputScrollPane =
new javax.swing.JScrollPane();
143 outputViewPane =
new javax.swing.JTextPane();
145 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.copyMenuItem.text"));
146 rightClickMenu.add(copyMenuItem);
148 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.selectAllMenuItem.text"));
149 rightClickMenu.add(selectAllMenuItem);
151 setMinimumSize(
new java.awt.Dimension(250, 5));
152 setPreferredSize(
new java.awt.Dimension(250, 58));
153 setLayout(
new java.awt.BorderLayout());
155 controlPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));
157 panelPageOfCount.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
159 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel.text_1"));
160 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 25));
161 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 25));
162 pageLabel.setPreferredSize(
new java.awt.Dimension(32, 25));
163 panelPageOfCount.add(pageLabel);
165 jSepMed1.setPreferredSize(
new java.awt.Dimension(5, 0));
166 panelPageOfCount.add(jSepMed1);
168 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.currentPageLabel.text_1"));
169 panelPageOfCount.add(currentPageLabel);
171 jSepMed2.setPreferredSize(
new java.awt.Dimension(5, 0));
172 panelPageOfCount.add(jSepMed2);
174 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.ofLabel.text_1"));
175 ofLabel.setMaximumSize(
new java.awt.Dimension(11, 25));
176 ofLabel.setMinimumSize(
new java.awt.Dimension(11, 25));
177 ofLabel.setPreferredSize(
new java.awt.Dimension(11, 25));
178 panelPageOfCount.add(ofLabel);
180 jSepMed3.setPreferredSize(
new java.awt.Dimension(5, 0));
181 panelPageOfCount.add(jSepMed3);
183 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.totalPageLabel.text_1"));
184 totalPageLabel.setMaximumSize(
new java.awt.Dimension(25, 25));
185 totalPageLabel.setMinimumSize(
new java.awt.Dimension(25, 25));
186 totalPageLabel.setPreferredSize(
new java.awt.Dimension(25, 25));
187 panelPageOfCount.add(totalPageLabel);
189 jSepMed4.setPreferredSize(
new java.awt.Dimension(5, 0));
190 panelPageOfCount.add(jSepMed4);
192 controlPanel.add(panelPageOfCount);
194 panelPageNextPrevButton.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
196 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel2.text"));
197 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 25));
198 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 25));
199 pageLabel2.setPreferredSize(
new java.awt.Dimension(29, 25));
200 panelPageNextPrevButton.add(pageLabel2);
202 jSepMed5.setPreferredSize(
new java.awt.Dimension(5, 0));
203 panelPageNextPrevButton.add(jSepMed5);
205 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
206 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.prevPageButton.text"));
207 prevPageButton.setBorderPainted(
false);
208 prevPageButton.setContentAreaFilled(
false);
209 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
210 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
211 prevPageButton.setMaximumSize(
new java.awt.Dimension(25, 25));
212 prevPageButton.setMinimumSize(
new java.awt.Dimension(20, 25));
213 prevPageButton.setPreferredSize(
new java.awt.Dimension(25, 25));
214 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
215 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
216 public void actionPerformed(java.awt.event.ActionEvent evt) {
217 prevPageButtonActionPerformed(evt);
220 panelPageNextPrevButton.add(prevPageButton);
222 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
223 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.nextPageButton.text"));
224 nextPageButton.setBorderPainted(
false);
225 nextPageButton.setContentAreaFilled(
false);
226 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
227 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
228 nextPageButton.setMaximumSize(
new java.awt.Dimension(25, 25));
229 nextPageButton.setMinimumSize(
new java.awt.Dimension(20, 25));
230 nextPageButton.setPreferredSize(
new java.awt.Dimension(25, 25));
231 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
232 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
233 public void actionPerformed(java.awt.event.ActionEvent evt) {
234 nextPageButtonActionPerformed(evt);
237 panelPageNextPrevButton.add(nextPageButton);
239 jSepMed6.setPreferredSize(
new java.awt.Dimension(5, 0));
240 panelPageNextPrevButton.add(jSepMed6);
242 controlPanel.add(panelPageNextPrevButton);
244 panelGoToPage.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
246 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageLabel.text"));
247 panelGoToPage.add(goToPageLabel);
249 jSepSm1.setPreferredSize(
new java.awt.Dimension(2, 0));
250 panelGoToPage.add(jSepSm1);
252 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageTextField.text"));
253 goToPageTextField.setMaximumSize(
new java.awt.Dimension(2147483647, 25));
254 goToPageTextField.setMinimumSize(
new java.awt.Dimension(50, 25));
255 goToPageTextField.setPreferredSize(
new java.awt.Dimension(70, 25));
256 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
257 public void actionPerformed(java.awt.event.ActionEvent evt) {
258 goToPageTextFieldActionPerformed(evt);
261 panelGoToPage.add(goToPageTextField);
263 jSepMed7.setPreferredSize(
new java.awt.Dimension(5, 0));
264 panelGoToPage.add(jSepMed7);
266 controlPanel.add(panelGoToPage);
268 panelScriptSelect.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
270 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.text"));
271 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.toolTipText"));
272 panelScriptSelect.add(languageLabel);
274 jSepSm2.setPreferredSize(
new java.awt.Dimension(2, 0));
275 panelScriptSelect.add(jSepSm2);
277 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageCombo.toolTipText"));
278 languageCombo.setMinimumSize(
new java.awt.Dimension(150, 25));
279 languageCombo.setPreferredSize(
new java.awt.Dimension(150, 25));
280 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
281 public void actionPerformed(java.awt.event.ActionEvent evt) {
282 languageComboActionPerformed(evt);
285 panelScriptSelect.add(languageCombo);
287 controlPanel.add(panelScriptSelect);
289 add(controlPanel, java.awt.BorderLayout.NORTH);
291 outputViewPane.setEditable(
false);
292 outputScrollPane.setViewportView(outputViewPane);
294 add(outputScrollPane, java.awt.BorderLayout.CENTER);
298 if (dataSource != null) {
299 setDataView(dataSource, currentOffset);
304 String pageNumberStr = goToPageTextField.getText();
306 int maxPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
308 pageNumber = Integer.parseInt(pageNumberStr);
309 }
catch (NumberFormatException ex) {
310 pageNumber = maxPage + 1;
312 if (pageNumber > maxPage || pageNumber < 1) {
313 JOptionPane.showMessageDialog(
this,
314 NbBundle.getMessage(
this.getClass(),
315 "StringsTextViewer.goToPageTextField.msgDlg",
317 NbBundle.getMessage(
this.getClass(),
318 "StringsTextViewer.goToPageTextField.err"),
319 JOptionPane.WARNING_MESSAGE);
322 currentOffset = (pageNumber - 1) * PAGE_LENGTH;
323 currentPage = pageNumber;
324 currentPageLabel.setText(Integer.toString(currentPage));
325 setDataView(dataSource, currentOffset);
330 currentOffset -= PAGE_LENGTH;
332 currentPageLabel.setText(Integer.toString(currentPage));
333 setDataView(dataSource, currentOffset);
338 currentOffset += PAGE_LENGTH;
340 currentPageLabel.setText(Integer.toString(currentPage));
341 setDataView(dataSource, currentOffset);
366 "StringContentPanel_Loading_String=Loading text..."
375 void setDataView(Content dataSource,
long offset) {
377 if (worker != null) {
382 if (dataSource == null) {
386 worker =
new ContentWorker(dataSource, offset);
387 outputViewPane.setText(Bundle.StringContentPanel_Loading_String());
388 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
392 void setDataView(StringContent dataSource) {
393 if (worker != null) {
398 if (dataSource == null) {
402 worker =
new StringContentWorker(dataSource);
403 outputViewPane.setText(Bundle.StringContentPanel_Loading_String());
404 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
424 this.content = content;
425 this.offset = offset;
433 if (content.getSize() > 0) {
435 bytesRead = content.read(data, offset, PAGE_LENGTH);
436 }
catch (TskCoreException ex) {
437 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
443 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
448 if (StringUtils.isBlank(text)) {
449 text = NbBundle.getMessage(this.getClass(),
450 "StringsTextViewer.setDataView.errorNoText", currentOffset,
451 currentOffset + PAGE_LENGTH);
454 text = NbBundle.getMessage(this.getClass(),
"StringsTextViewer.setDataView.errorText", currentOffset,
455 currentOffset + PAGE_LENGTH);
472 dataSource = content;
475 if (offset + PAGE_LENGTH < dataSource.getSize()) {
476 nextPageButton.setEnabled(
true);
478 nextPageButton.setEnabled(
false);
482 prevPageButton.setEnabled(
false);
485 prevPageButton.setEnabled(
true);
488 int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
489 totalPageLabel.setText(Integer.toString(totalPage));
490 outputViewPane.setText(text);
491 outputViewPane.moveCaretPosition(0);
493 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
495 }
catch (InterruptedException | ExecutionException ex) {
496 logger.log(Level.SEVERE, String.format(
"Failed to get text from content (id=%d)", content.getId()), ex);
514 this.content = content;
532 nextPageButton.setEnabled(
false);
533 prevPageButton.setEnabled(
false);
536 outputViewPane.setText(text);
537 outputViewPane.moveCaretPosition(0);
538 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
540 }
catch (InterruptedException | ExecutionException ex) {
541 logger.log(Level.SEVERE, String.format(
"Failed to get text from StringContent"), ex);
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
final StringContent content
javax.swing.JPanel panelScriptSelect
javax.swing.JButton nextPageButton
javax.swing.JComboBox< SCRIPT > languageCombo
javax.swing.JMenuItem selectAllMenuItem
void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JButton prevPageButton
javax.swing.JScrollPane outputScrollPane
void customizeComponents()
javax.swing.JLabel languageLabel
javax.swing.JLabel currentPageLabel
void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt)
void setOppositeAligned(Collection< Component > oppAlignedComponents)
SwingWorker< String, Void > worker
javax.swing.JLabel pageLabel
synchronized static Logger getLogger(String name)
javax.swing.JLabel pageLabel2
javax.swing.JLabel totalPageLabel