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.setPreferredSize(
new java.awt.Dimension(100, 40));
137 outputScrollPane.setViewportView(outputViewPane);
139 controlScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
140 controlScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
142 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.totalPageLabel.text_1"));
144 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.ofLabel.text_1"));
146 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.currentPageLabel.text_1"));
147 currentPageLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
148 currentPageLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
150 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel.text_1"));
151 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 14));
152 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 14));
154 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
155 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.nextPageButton.text"));
156 nextPageButton.setBorderPainted(
false);
157 nextPageButton.setContentAreaFilled(
false);
158 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
159 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
160 nextPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
161 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
162 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
163 public void actionPerformed(java.awt.event.ActionEvent evt) {
164 nextPageButtonActionPerformed(evt);
168 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.pageLabel2.text"));
169 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 14));
170 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 14));
172 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
173 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.prevPageButton.text"));
174 prevPageButton.setBorderPainted(
false);
175 prevPageButton.setContentAreaFilled(
false);
176 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
177 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
178 prevPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
179 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
180 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
181 public void actionPerformed(java.awt.event.ActionEvent evt) {
182 prevPageButtonActionPerformed(evt);
186 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageLabel.text"));
188 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.goToPageTextField.text"));
189 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
190 public void actionPerformed(java.awt.event.ActionEvent evt) {
191 goToPageTextFieldActionPerformed(evt);
195 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageCombo.toolTipText"));
196 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
197 public void actionPerformed(java.awt.event.ActionEvent evt) {
198 languageComboActionPerformed(evt);
202 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.text"));
203 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
StringsContentPanel.class,
"StringsContentPanel.languageLabel.toolTipText"));
205 javax.swing.GroupLayout controlPanelLayout =
new javax.swing.GroupLayout(controlPanel);
206 controlPanel.setLayout(controlPanelLayout);
207 controlPanelLayout.setHorizontalGroup(
208 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209 .addGroup(controlPanelLayout.createSequentialGroup()
211 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
213 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
214 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215 .addComponent(ofLabel)
216 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
217 .addComponent(totalPageLabel)
219 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
220 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
221 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
223 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
225 .addComponent(goToPageLabel)
226 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
227 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
228 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
229 .addComponent(languageLabel)
230 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
231 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
234 controlPanelLayout.setVerticalGroup(
235 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
236 .addGroup(controlPanelLayout.createSequentialGroup()
237 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
238 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
239 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
240 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
241 .addComponent(ofLabel)
242 .addComponent(totalPageLabel))
243 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
244 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
245 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
246 .addComponent(goToPageLabel)
247 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
248 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
249 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
250 .addComponent(languageLabel)))
254 controlScrollPane.setViewportView(controlPanel);
256 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
257 this.setLayout(layout);
258 layout.setHorizontalGroup(
259 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260 .addComponent(outputScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
261 .addComponent(controlScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
263 layout.setVerticalGroup(
264 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265 .addGroup(layout.createSequentialGroup()
266 .addComponent(controlScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
268 .addComponent(outputScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
273 if (dataSource != null) {
274 setDataView(dataSource, currentOffset);
279 String pageNumberStr = goToPageTextField.getText();
281 int maxPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
283 pageNumber = Integer.parseInt(pageNumberStr);
284 }
catch (NumberFormatException ex) {
285 pageNumber = maxPage + 1;
287 if (pageNumber > maxPage || pageNumber < 1) {
288 JOptionPane.showMessageDialog(
this,
289 NbBundle.getMessage(
this.getClass(),
290 "StringsTextViewer.goToPageTextField.msgDlg",
292 NbBundle.getMessage(
this.getClass(),
293 "StringsTextViewer.goToPageTextField.err"),
294 JOptionPane.WARNING_MESSAGE);
297 currentOffset = (pageNumber - 1) * PAGE_LENGTH;
298 currentPage = pageNumber;
299 currentPageLabel.setText(Integer.toString(currentPage));
300 setDataView(dataSource, currentOffset);
305 currentOffset -= PAGE_LENGTH;
307 currentPageLabel.setText(Integer.toString(currentPage));
308 setDataView(dataSource, currentOffset);
313 currentOffset += PAGE_LENGTH;
315 currentPageLabel.setText(Integer.toString(currentPage));
316 setDataView(dataSource, currentOffset);
346 void setDataView(Content dataSource,
long offset) {
347 if (dataSource == null) {
351 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
352 this.dataSource = dataSource;
356 if (dataSource.getSize() > 0) {
358 bytesRead = dataSource.read(data, offset, PAGE_LENGTH);
359 }
catch (TskCoreException ex) {
360 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
366 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
370 if (StringUtils.isBlank(text)) {
371 text = NbBundle.getMessage(this.getClass(),
372 "StringsTextViewer.setDataView.errorNoText", currentOffset,
373 currentOffset + PAGE_LENGTH);
376 text = NbBundle.getMessage(this.getClass(),
"StringsTextViewer.setDataView.errorText", currentOffset,
377 currentOffset + PAGE_LENGTH);
381 if (offset + PAGE_LENGTH < dataSource.getSize()) {
382 nextPageButton.setEnabled(
true);
384 nextPageButton.setEnabled(
false);
388 prevPageButton.setEnabled(
false);
391 prevPageButton.setEnabled(
true);
394 int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
395 totalPageLabel.setText(Integer.toString(totalPage));
396 currentPageLabel.setText(Integer.toString(currentPage));
397 outputViewPane.setText(text);
398 setComponentsVisibility(
true);
399 outputViewPane.moveCaretPosition(0);
401 this.setCursor(null);
405 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
407 this.dataSource = null;
411 nextPageButton.setEnabled(
false);
412 prevPageButton.setEnabled(
false);
416 totalPageLabel.setText(Integer.toString(totalPage));
417 currentPageLabel.setText(Integer.toString(currentPage));
418 outputViewPane.setText(text);
419 setComponentsVisibility(
true);
420 outputViewPane.moveCaretPosition(0);
422 this.setCursor(null);
432 currentPageLabel.setVisible(isVisible);
433 totalPageLabel.setVisible(isVisible);
434 ofLabel.setVisible(isVisible);
435 prevPageButton.setVisible(isVisible);
436 nextPageButton.setVisible(isVisible);
437 pageLabel.setVisible(isVisible);
438 pageLabel2.setVisible(isVisible);
439 goToPageTextField.setVisible(isVisible);
440 goToPageLabel.setVisible(isVisible);
441 languageCombo.setVisible(isVisible);
442 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