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.logging.Level;
27 import org.openide.util.NbBundle;
29 import javax.swing.JMenuItem;
30 import javax.swing.JOptionPane;
31 import org.apache.commons.lang3.StringUtils;
43 @SuppressWarnings(
"PMD.SingularField")
46 private static long currentOffset = 0;
47 private static final long PAGE_LENGTH = 16384;
48 private static final long serialVersionUID = 1L;
49 private final byte[] data =
new byte[(int) PAGE_LENGTH];
50 private static int currentPage = 1;
61 customizeComponents();
66 outputViewPane.setComponentPopupMenu(rightClickMenu);
67 ActionListener actList = (ActionEvent e) -> {
68 JMenuItem jmi = (JMenuItem) e.getSource();
69 if (jmi.equals(copyMenuItem)) {
70 outputViewPane.copy();
71 }
else if (jmi.equals(selectAllMenuItem)) {
72 outputViewPane.selectAll();
75 copyMenuItem.addActionListener(actList);
76 selectAllMenuItem.addActionListener(actList);
79 supportedScripts.forEach((s) -> {
80 languageCombo.addItem(s);
86 controlPanel.setLayout(layout);
90 final void resetDisplay() {
94 this.dataSource = null;
95 currentPageLabel.setText(
"");
96 totalPageLabel.setText(
"");
97 prevPageButton.setEnabled(
false);
98 nextPageButton.setEnabled(
false);
99 outputViewPane.setText(
"");
100 setComponentsVisibility(
false);
108 @SuppressWarnings(
"unchecked")
110 private
void initComponents() {
112 rightClickMenu =
new javax.swing.JPopupMenu();
113 copyMenuItem =
new javax.swing.JMenuItem();
114 selectAllMenuItem =
new javax.swing.JMenuItem();
115 controlPanel =
new javax.swing.JPanel();
116 javax.swing.JPanel panelPageOfCount =
new javax.swing.JPanel();
117 pageLabel =
new javax.swing.JLabel();
118 javax.swing.JSeparator jSepMed1 =
new javax.swing.JSeparator();
119 currentPageLabel =
new javax.swing.JLabel();
120 javax.swing.JSeparator jSepMed2 =
new javax.swing.JSeparator();
121 ofLabel =
new javax.swing.JLabel();
122 javax.swing.JSeparator jSepMed3 =
new javax.swing.JSeparator();
123 totalPageLabel =
new javax.swing.JLabel();
124 javax.swing.JSeparator jSepMed4 =
new javax.swing.JSeparator();
125 javax.swing.JPanel panelPageNextPrevButton =
new javax.swing.JPanel();
126 pageLabel2 =
new javax.swing.JLabel();
127 javax.swing.JSeparator jSepMed5 =
new javax.swing.JSeparator();
128 prevPageButton =
new javax.swing.JButton();
129 nextPageButton =
new javax.swing.JButton();
130 javax.swing.JSeparator jSepMed6 =
new javax.swing.JSeparator();
131 javax.swing.JPanel panelGoToPage =
new javax.swing.JPanel();
132 goToPageLabel =
new javax.swing.JLabel();
133 javax.swing.JSeparator jSepSm1 =
new javax.swing.JSeparator();
134 goToPageTextField =
new javax.swing.JTextField();
135 javax.swing.JSeparator jSepMed7 =
new javax.swing.JSeparator();
136 panelScriptSelect =
new javax.swing.JPanel();
137 languageLabel =
new javax.swing.JLabel();
138 javax.swing.JSeparator jSepSm2 =
new javax.swing.JSeparator();
139 languageCombo =
new javax.swing.JComboBox<>();
140 outputScrollPane =
new javax.swing.JScrollPane();
141 outputViewPane =
new javax.swing.JTextPane();
143 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.copyMenuItem.text"));
144 rightClickMenu.add(copyMenuItem);
146 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.selectAllMenuItem.text"));
147 rightClickMenu.add(selectAllMenuItem);
149 setMinimumSize(
new java.awt.Dimension(250, 5));
150 setPreferredSize(
new java.awt.Dimension(250, 58));
151 setLayout(
new java.awt.BorderLayout());
153 controlPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));
155 panelPageOfCount.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
157 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel.text_1"));
158 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 25));
159 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 25));
160 pageLabel.setPreferredSize(
new java.awt.Dimension(32, 25));
161 panelPageOfCount.add(pageLabel);
163 jSepMed1.setPreferredSize(
new java.awt.Dimension(5, 0));
164 panelPageOfCount.add(jSepMed1);
166 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.currentPageLabel.text_1"));
167 currentPageLabel.setMaximumSize(
new java.awt.Dimension(18, 25));
168 currentPageLabel.setMinimumSize(
new java.awt.Dimension(7, 25));
169 currentPageLabel.setPreferredSize(
new java.awt.Dimension(18, 25));
170 panelPageOfCount.add(currentPageLabel);
172 jSepMed2.setPreferredSize(
new java.awt.Dimension(5, 0));
173 panelPageOfCount.add(jSepMed2);
175 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.ofLabel.text_1"));
176 ofLabel.setMaximumSize(
new java.awt.Dimension(11, 25));
177 ofLabel.setMinimumSize(
new java.awt.Dimension(11, 25));
178 ofLabel.setPreferredSize(
new java.awt.Dimension(11, 25));
179 panelPageOfCount.add(ofLabel);
181 jSepMed3.setPreferredSize(
new java.awt.Dimension(5, 0));
182 panelPageOfCount.add(jSepMed3);
184 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.totalPageLabel.text_1"));
185 totalPageLabel.setMaximumSize(
new java.awt.Dimension(21, 25));
186 totalPageLabel.setMinimumSize(
new java.awt.Dimension(21, 25));
187 totalPageLabel.setPreferredSize(
new java.awt.Dimension(21, 25));
188 panelPageOfCount.add(totalPageLabel);
190 jSepMed4.setPreferredSize(
new java.awt.Dimension(5, 0));
191 panelPageOfCount.add(jSepMed4);
193 controlPanel.add(panelPageOfCount);
195 panelPageNextPrevButton.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
197 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel2.text"));
198 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 25));
199 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 25));
200 pageLabel2.setPreferredSize(
new java.awt.Dimension(29, 25));
201 panelPageNextPrevButton.add(pageLabel2);
203 jSepMed5.setPreferredSize(
new java.awt.Dimension(5, 0));
204 panelPageNextPrevButton.add(jSepMed5);
206 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
207 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.prevPageButton.text"));
208 prevPageButton.setBorderPainted(
false);
209 prevPageButton.setContentAreaFilled(
false);
210 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
211 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
212 prevPageButton.setMaximumSize(
new java.awt.Dimension(25, 25));
213 prevPageButton.setMinimumSize(
new java.awt.Dimension(20, 25));
214 prevPageButton.setPreferredSize(
new java.awt.Dimension(25, 25));
215 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
216 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
217 public void actionPerformed(java.awt.event.ActionEvent evt) {
218 prevPageButtonActionPerformed(evt);
221 panelPageNextPrevButton.add(prevPageButton);
223 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
224 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.nextPageButton.text"));
225 nextPageButton.setBorderPainted(
false);
226 nextPageButton.setContentAreaFilled(
false);
227 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
228 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
229 nextPageButton.setMaximumSize(
new java.awt.Dimension(25, 25));
230 nextPageButton.setMinimumSize(
new java.awt.Dimension(20, 25));
231 nextPageButton.setPreferredSize(
new java.awt.Dimension(25, 25));
232 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
233 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
234 public void actionPerformed(java.awt.event.ActionEvent evt) {
235 nextPageButtonActionPerformed(evt);
238 panelPageNextPrevButton.add(nextPageButton);
240 jSepMed6.setPreferredSize(
new java.awt.Dimension(5, 0));
241 panelPageNextPrevButton.add(jSepMed6);
243 controlPanel.add(panelPageNextPrevButton);
245 panelGoToPage.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
247 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageLabel.text"));
248 panelGoToPage.add(goToPageLabel);
250 jSepSm1.setPreferredSize(
new java.awt.Dimension(2, 0));
251 panelGoToPage.add(jSepSm1);
253 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageTextField.text"));
254 goToPageTextField.setMaximumSize(
new java.awt.Dimension(2147483647, 25));
255 goToPageTextField.setMinimumSize(
new java.awt.Dimension(50, 25));
256 goToPageTextField.setPreferredSize(
new java.awt.Dimension(70, 25));
257 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
258 public void actionPerformed(java.awt.event.ActionEvent evt) {
259 goToPageTextFieldActionPerformed(evt);
262 panelGoToPage.add(goToPageTextField);
264 jSepMed7.setPreferredSize(
new java.awt.Dimension(5, 0));
265 panelGoToPage.add(jSepMed7);
267 controlPanel.add(panelGoToPage);
269 panelScriptSelect.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
271 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.text"));
272 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.toolTipText"));
273 panelScriptSelect.add(languageLabel);
275 jSepSm2.setPreferredSize(
new java.awt.Dimension(2, 0));
276 panelScriptSelect.add(jSepSm2);
278 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageCombo.toolTipText"));
279 languageCombo.setMinimumSize(
new java.awt.Dimension(150, 25));
280 languageCombo.setPreferredSize(
new java.awt.Dimension(150, 25));
281 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
282 public void actionPerformed(java.awt.event.ActionEvent evt) {
283 languageComboActionPerformed(evt);
286 panelScriptSelect.add(languageCombo);
288 controlPanel.add(panelScriptSelect);
290 add(controlPanel, java.awt.BorderLayout.NORTH);
292 outputViewPane.setEditable(
false);
293 outputScrollPane.setViewportView(outputViewPane);
295 add(outputScrollPane, java.awt.BorderLayout.CENTER);
299 if (dataSource != null) {
300 setDataView(dataSource, currentOffset);
305 String pageNumberStr = goToPageTextField.getText();
307 int maxPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
309 pageNumber = Integer.parseInt(pageNumberStr);
310 }
catch (NumberFormatException ex) {
311 pageNumber = maxPage + 1;
313 if (pageNumber > maxPage || pageNumber < 1) {
314 JOptionPane.showMessageDialog(
this,
315 NbBundle.getMessage(
this.getClass(),
316 "StringsTextViewer.goToPageTextField.msgDlg",
318 NbBundle.getMessage(
this.getClass(),
319 "StringsTextViewer.goToPageTextField.err"),
320 JOptionPane.WARNING_MESSAGE);
323 currentOffset = (pageNumber - 1) * PAGE_LENGTH;
324 currentPage = pageNumber;
325 currentPageLabel.setText(Integer.toString(currentPage));
326 setDataView(dataSource, currentOffset);
331 currentOffset -= PAGE_LENGTH;
333 currentPageLabel.setText(Integer.toString(currentPage));
334 setDataView(dataSource, currentOffset);
339 currentOffset += PAGE_LENGTH;
341 currentPageLabel.setText(Integer.toString(currentPage));
342 setDataView(dataSource, currentOffset);
372 void setDataView(Content dataSource,
long offset) {
373 if (dataSource == null) {
377 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
378 this.dataSource = dataSource;
382 if (dataSource.getSize() > 0) {
384 bytesRead = dataSource.read(data, offset, PAGE_LENGTH);
385 }
catch (TskCoreException ex) {
386 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
392 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
396 if (StringUtils.isBlank(text)) {
397 text = NbBundle.getMessage(this.getClass(),
398 "StringsTextViewer.setDataView.errorNoText", currentOffset,
399 currentOffset + PAGE_LENGTH);
402 text = NbBundle.getMessage(this.getClass(),
"StringsTextViewer.setDataView.errorText", currentOffset,
403 currentOffset + PAGE_LENGTH);
407 if (offset + PAGE_LENGTH < dataSource.getSize()) {
408 nextPageButton.setEnabled(
true);
410 nextPageButton.setEnabled(
false);
414 prevPageButton.setEnabled(
false);
417 prevPageButton.setEnabled(
true);
420 int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
421 totalPageLabel.setText(Integer.toString(totalPage));
422 currentPageLabel.setText(Integer.toString(currentPage));
423 outputViewPane.setText(text);
424 setComponentsVisibility(
true);
425 outputViewPane.moveCaretPosition(0);
427 this.setCursor(null);
431 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
433 this.dataSource = null;
437 nextPageButton.setEnabled(
false);
438 prevPageButton.setEnabled(
false);
442 totalPageLabel.setText(Integer.toString(totalPage));
443 currentPageLabel.setText(Integer.toString(currentPage));
444 outputViewPane.setText(text);
445 setComponentsVisibility(
true);
446 outputViewPane.moveCaretPosition(0);
448 this.setCursor(null);
458 currentPageLabel.setVisible(isVisible);
459 totalPageLabel.setVisible(isVisible);
460 ofLabel.setVisible(isVisible);
461 prevPageButton.setVisible(isVisible);
462 nextPageButton.setVisible(isVisible);
463 pageLabel.setVisible(isVisible);
464 pageLabel2.setVisible(isVisible);
465 goToPageTextField.setVisible(isVisible);
466 goToPageLabel.setVisible(isVisible);
467 languageCombo.setVisible(isVisible);
468 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.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)
javax.swing.JLabel pageLabel
synchronized static Logger getLogger(String name)
javax.swing.JLabel pageLabel2
javax.swing.JLabel totalPageLabel