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(
"");
99 totalPageLabel.setText(
"");
100 prevPageButton.setEnabled(
false);
101 nextPageButton.setEnabled(
false);
102 outputViewPane.setText(
"");
103 setComponentsVisibility(
false);
111 @SuppressWarnings(
"unchecked")
113 private
void initComponents() {
115 rightClickMenu =
new javax.swing.JPopupMenu();
116 copyMenuItem =
new javax.swing.JMenuItem();
117 selectAllMenuItem =
new javax.swing.JMenuItem();
118 controlPanel =
new javax.swing.JPanel();
119 javax.swing.JPanel panelPageOfCount =
new javax.swing.JPanel();
120 pageLabel =
new javax.swing.JLabel();
121 javax.swing.JSeparator jSepMed1 =
new javax.swing.JSeparator();
122 currentPageLabel =
new javax.swing.JLabel();
123 javax.swing.JSeparator jSepMed2 =
new javax.swing.JSeparator();
124 ofLabel =
new javax.swing.JLabel();
125 javax.swing.JSeparator jSepMed3 =
new javax.swing.JSeparator();
126 totalPageLabel =
new javax.swing.JLabel();
127 javax.swing.JSeparator jSepMed4 =
new javax.swing.JSeparator();
128 javax.swing.JPanel panelPageNextPrevButton =
new javax.swing.JPanel();
129 pageLabel2 =
new javax.swing.JLabel();
130 javax.swing.JSeparator jSepMed5 =
new javax.swing.JSeparator();
131 prevPageButton =
new javax.swing.JButton();
132 nextPageButton =
new javax.swing.JButton();
133 javax.swing.JSeparator jSepMed6 =
new javax.swing.JSeparator();
134 javax.swing.JPanel panelGoToPage =
new javax.swing.JPanel();
135 goToPageLabel =
new javax.swing.JLabel();
136 javax.swing.JSeparator jSepSm1 =
new javax.swing.JSeparator();
137 goToPageTextField =
new javax.swing.JTextField();
138 javax.swing.JSeparator jSepMed7 =
new javax.swing.JSeparator();
139 panelScriptSelect =
new javax.swing.JPanel();
140 languageLabel =
new javax.swing.JLabel();
141 javax.swing.JSeparator jSepSm2 =
new javax.swing.JSeparator();
142 languageCombo =
new javax.swing.JComboBox<>();
143 outputScrollPane =
new javax.swing.JScrollPane();
144 outputViewPane =
new javax.swing.JTextPane();
146 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.copyMenuItem.text"));
147 rightClickMenu.add(copyMenuItem);
149 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.selectAllMenuItem.text"));
150 rightClickMenu.add(selectAllMenuItem);
152 setMinimumSize(
new java.awt.Dimension(250, 5));
153 setPreferredSize(
new java.awt.Dimension(250, 58));
154 setLayout(
new java.awt.BorderLayout());
156 controlPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));
158 panelPageOfCount.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
160 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel.text_1"));
161 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 25));
162 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 25));
163 pageLabel.setPreferredSize(
new java.awt.Dimension(32, 25));
164 panelPageOfCount.add(pageLabel);
166 jSepMed1.setPreferredSize(
new java.awt.Dimension(5, 0));
167 panelPageOfCount.add(jSepMed1);
169 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.currentPageLabel.text_1"));
170 currentPageLabel.setMaximumSize(
new java.awt.Dimension(18, 25));
171 currentPageLabel.setMinimumSize(
new java.awt.Dimension(7, 25));
172 currentPageLabel.setPreferredSize(
new java.awt.Dimension(18, 25));
173 panelPageOfCount.add(currentPageLabel);
175 jSepMed2.setPreferredSize(
new java.awt.Dimension(5, 0));
176 panelPageOfCount.add(jSepMed2);
178 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.ofLabel.text_1"));
179 ofLabel.setMaximumSize(
new java.awt.Dimension(11, 25));
180 ofLabel.setMinimumSize(
new java.awt.Dimension(11, 25));
181 ofLabel.setPreferredSize(
new java.awt.Dimension(11, 25));
182 panelPageOfCount.add(ofLabel);
184 jSepMed3.setPreferredSize(
new java.awt.Dimension(5, 0));
185 panelPageOfCount.add(jSepMed3);
187 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.totalPageLabel.text_1"));
188 totalPageLabel.setMaximumSize(
new java.awt.Dimension(21, 25));
189 totalPageLabel.setMinimumSize(
new java.awt.Dimension(21, 25));
190 totalPageLabel.setPreferredSize(
new java.awt.Dimension(21, 25));
191 panelPageOfCount.add(totalPageLabel);
193 jSepMed4.setPreferredSize(
new java.awt.Dimension(5, 0));
194 panelPageOfCount.add(jSepMed4);
196 controlPanel.add(panelPageOfCount);
198 panelPageNextPrevButton.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
200 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel2.text"));
201 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 25));
202 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 25));
203 pageLabel2.setPreferredSize(
new java.awt.Dimension(29, 25));
204 panelPageNextPrevButton.add(pageLabel2);
206 jSepMed5.setPreferredSize(
new java.awt.Dimension(5, 0));
207 panelPageNextPrevButton.add(jSepMed5);
209 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
210 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.prevPageButton.text"));
211 prevPageButton.setBorderPainted(
false);
212 prevPageButton.setContentAreaFilled(
false);
213 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
214 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
215 prevPageButton.setMaximumSize(
new java.awt.Dimension(25, 25));
216 prevPageButton.setMinimumSize(
new java.awt.Dimension(20, 25));
217 prevPageButton.setPreferredSize(
new java.awt.Dimension(25, 25));
218 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
219 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
220 public void actionPerformed(java.awt.event.ActionEvent evt) {
221 prevPageButtonActionPerformed(evt);
224 panelPageNextPrevButton.add(prevPageButton);
226 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
227 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.nextPageButton.text"));
228 nextPageButton.setBorderPainted(
false);
229 nextPageButton.setContentAreaFilled(
false);
230 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
231 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
232 nextPageButton.setMaximumSize(
new java.awt.Dimension(25, 25));
233 nextPageButton.setMinimumSize(
new java.awt.Dimension(20, 25));
234 nextPageButton.setPreferredSize(
new java.awt.Dimension(25, 25));
235 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
236 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
237 public void actionPerformed(java.awt.event.ActionEvent evt) {
238 nextPageButtonActionPerformed(evt);
241 panelPageNextPrevButton.add(nextPageButton);
243 jSepMed6.setPreferredSize(
new java.awt.Dimension(5, 0));
244 panelPageNextPrevButton.add(jSepMed6);
246 controlPanel.add(panelPageNextPrevButton);
248 panelGoToPage.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
250 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageLabel.text"));
251 panelGoToPage.add(goToPageLabel);
253 jSepSm1.setPreferredSize(
new java.awt.Dimension(2, 0));
254 panelGoToPage.add(jSepSm1);
256 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageTextField.text"));
257 goToPageTextField.setMaximumSize(
new java.awt.Dimension(2147483647, 25));
258 goToPageTextField.setMinimumSize(
new java.awt.Dimension(50, 25));
259 goToPageTextField.setPreferredSize(
new java.awt.Dimension(70, 25));
260 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
261 public void actionPerformed(java.awt.event.ActionEvent evt) {
262 goToPageTextFieldActionPerformed(evt);
265 panelGoToPage.add(goToPageTextField);
267 jSepMed7.setPreferredSize(
new java.awt.Dimension(5, 0));
268 panelGoToPage.add(jSepMed7);
270 controlPanel.add(panelGoToPage);
272 panelScriptSelect.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
274 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.text"));
275 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.toolTipText"));
276 panelScriptSelect.add(languageLabel);
278 jSepSm2.setPreferredSize(
new java.awt.Dimension(2, 0));
279 panelScriptSelect.add(jSepSm2);
281 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageCombo.toolTipText"));
282 languageCombo.setMinimumSize(
new java.awt.Dimension(150, 25));
283 languageCombo.setPreferredSize(
new java.awt.Dimension(150, 25));
284 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
285 public void actionPerformed(java.awt.event.ActionEvent evt) {
286 languageComboActionPerformed(evt);
289 panelScriptSelect.add(languageCombo);
291 controlPanel.add(panelScriptSelect);
293 add(controlPanel, java.awt.BorderLayout.NORTH);
295 outputViewPane.setEditable(
false);
296 outputScrollPane.setViewportView(outputViewPane);
298 add(outputScrollPane, java.awt.BorderLayout.CENTER);
302 if (dataSource != null) {
303 setDataView(dataSource, currentOffset);
308 String pageNumberStr = goToPageTextField.getText();
310 int maxPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
312 pageNumber = Integer.parseInt(pageNumberStr);
313 }
catch (NumberFormatException ex) {
314 pageNumber = maxPage + 1;
316 if (pageNumber > maxPage || pageNumber < 1) {
317 JOptionPane.showMessageDialog(
this,
318 NbBundle.getMessage(
this.getClass(),
319 "StringsTextViewer.goToPageTextField.msgDlg",
321 NbBundle.getMessage(
this.getClass(),
322 "StringsTextViewer.goToPageTextField.err"),
323 JOptionPane.WARNING_MESSAGE);
326 currentOffset = (pageNumber - 1) * PAGE_LENGTH;
327 currentPage = pageNumber;
328 currentPageLabel.setText(Integer.toString(currentPage));
329 setDataView(dataSource, currentOffset);
334 currentOffset -= PAGE_LENGTH;
336 currentPageLabel.setText(Integer.toString(currentPage));
337 setDataView(dataSource, currentOffset);
342 currentOffset += PAGE_LENGTH;
344 currentPageLabel.setText(Integer.toString(currentPage));
345 setDataView(dataSource, currentOffset);
370 "StringContentPanel_Loading_String=Loading text..."
379 void setDataView(Content dataSource,
long offset) {
381 if (worker != null) {
386 if (dataSource == null) {
390 worker =
new ContentWorker(dataSource, offset);
391 outputViewPane.setText(Bundle.StringContentPanel_Loading_String());
392 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
396 void setDataView(StringContent dataSource) {
397 if (worker != null) {
402 if (dataSource == null) {
406 worker =
new StringContentWorker(dataSource);
407 outputViewPane.setText(Bundle.StringContentPanel_Loading_String());
408 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
418 currentPageLabel.setVisible(isVisible);
419 totalPageLabel.setVisible(isVisible);
420 ofLabel.setVisible(isVisible);
421 prevPageButton.setVisible(isVisible);
422 nextPageButton.setVisible(isVisible);
423 pageLabel.setVisible(isVisible);
424 pageLabel2.setVisible(isVisible);
425 goToPageTextField.setVisible(isVisible);
426 goToPageLabel.setVisible(isVisible);
427 languageCombo.setVisible(isVisible);
428 languageLabel.setVisible(isVisible);
446 this.content = content;
447 this.offset = offset;
455 if (content.getSize() > 0) {
457 bytesRead = content.read(data, offset, PAGE_LENGTH);
458 }
catch (TskCoreException ex) {
459 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
465 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
470 if (StringUtils.isBlank(text)) {
471 text = NbBundle.getMessage(this.getClass(),
472 "StringsTextViewer.setDataView.errorNoText", currentOffset,
473 currentOffset + PAGE_LENGTH);
476 text = NbBundle.getMessage(this.getClass(),
"StringsTextViewer.setDataView.errorText", currentOffset,
477 currentOffset + PAGE_LENGTH);
494 dataSource = content;
497 if (offset + PAGE_LENGTH < dataSource.getSize()) {
498 nextPageButton.setEnabled(
true);
500 nextPageButton.setEnabled(
false);
504 prevPageButton.setEnabled(
false);
507 prevPageButton.setEnabled(
true);
510 int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
511 totalPageLabel.setText(Integer.toString(totalPage));
512 currentPageLabel.setText(
"1");
513 outputViewPane.setText(text);
514 setComponentsVisibility(
true);
515 outputViewPane.moveCaretPosition(0);
517 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
519 }
catch (InterruptedException | ExecutionException ex) {
520 logger.log(Level.SEVERE, String.format(
"Failed to get text from content (id=%d)", content.getId()), ex);
538 this.content = content;
556 nextPageButton.setEnabled(
false);
557 prevPageButton.setEnabled(
false);
560 totalPageLabel.setText(
"1");
561 currentPageLabel.setText(
"1");
562 outputViewPane.setText(text);
563 setComponentsVisibility(
true);
564 outputViewPane.moveCaretPosition(0);
565 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
567 }
catch (InterruptedException | ExecutionException ex) {
568 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
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)
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