19 package org.sleuthkit.autopsy.corecomponents;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.List;
25 import java.util.logging.Level;
27 import org.openide.util.NbBundle;
29 import javax.swing.JMenuItem;
30 import javax.swing.JOptionPane;
31 import org.openide.nodes.Node;
32 import org.openide.util.lookup.ServiceProvider;
44 @ServiceProvider(service = DataContentViewer.class, position = 2)
45 @SuppressWarnings(
"PMD.SingularField")
48 private static long currentOffset = 0;
49 private static final long PAGE_LENGTH = 16384;
50 private final byte[] data =
new byte[(int) PAGE_LENGTH];
51 private static int currentPage = 1;
62 customizeComponents();
63 this.resetComponent();
64 logger.log(Level.INFO,
"Created StringView instance: {0}",
this);
68 outputViewPane.setComponentPopupMenu(rightClickMenu);
69 ActionListener actList =
new ActionListener() {
71 public void actionPerformed(ActionEvent e) {
72 JMenuItem jmi = (JMenuItem) e.getSource();
73 if (jmi.equals(copyMenuItem)) {
74 outputViewPane.copy();
75 }
else if (jmi.equals(selectAllMenuItem)) {
76 outputViewPane.selectAll();
80 copyMenuItem.addActionListener(actList);
81 selectAllMenuItem.addActionListener(actList);
84 for (
SCRIPT s : supportedScripts) {
85 languageCombo.addItem(s);
95 @SuppressWarnings(
"unchecked")
97 private
void initComponents() {
99 rightClickMenu =
new javax.swing.JPopupMenu();
100 copyMenuItem =
new javax.swing.JMenuItem();
101 selectAllMenuItem =
new javax.swing.JMenuItem();
102 jScrollPane1 =
new javax.swing.JScrollPane();
103 outputViewPane =
new javax.swing.JTextPane();
104 jScrollPane2 =
new javax.swing.JScrollPane();
105 jPanel2 =
new javax.swing.JPanel();
106 totalPageLabel =
new javax.swing.JLabel();
107 ofLabel =
new javax.swing.JLabel();
108 currentPageLabel =
new javax.swing.JLabel();
109 pageLabel =
new javax.swing.JLabel();
110 nextPageButton =
new javax.swing.JButton();
111 pageLabel2 =
new javax.swing.JLabel();
112 prevPageButton =
new javax.swing.JButton();
113 goToPageLabel =
new javax.swing.JLabel();
114 goToPageTextField =
new javax.swing.JTextField();
115 languageCombo =
new javax.swing.JComboBox<>();
116 languageLabel =
new javax.swing.JLabel();
118 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.copyMenuItem.text"));
119 rightClickMenu.add(copyMenuItem);
121 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.selectAllMenuItem.text"));
122 rightClickMenu.add(selectAllMenuItem);
124 setMinimumSize(
new java.awt.Dimension(5, 5));
125 setPreferredSize(
new java.awt.Dimension(100, 144));
127 jScrollPane1.setPreferredSize(
new java.awt.Dimension(640, 402));
129 outputViewPane.setEditable(
false);
130 outputViewPane.setFont(
new java.awt.Font(
"Courier New", 0, 11));
131 outputViewPane.setPreferredSize(
new java.awt.Dimension(638, 400));
132 jScrollPane1.setViewportView(outputViewPane);
134 jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
135 jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
137 totalPageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.totalPageLabel.text_1"));
139 ofLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.ofLabel.text_1"));
141 currentPageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.currentPageLabel.text_1"));
142 currentPageLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
143 currentPageLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
145 pageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.pageLabel.text_1"));
146 pageLabel.setMaximumSize(
new java.awt.Dimension(33, 14));
147 pageLabel.setMinimumSize(
new java.awt.Dimension(33, 14));
149 nextPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png")));
150 nextPageButton.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.nextPageButton.text"));
151 nextPageButton.setBorderPainted(
false);
152 nextPageButton.setContentAreaFilled(
false);
153 nextPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png")));
154 nextPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
155 nextPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
156 nextPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png")));
157 nextPageButton.addActionListener(
new java.awt.event.ActionListener() {
158 public void actionPerformed(java.awt.event.ActionEvent evt) {
159 nextPageButtonActionPerformed(evt);
163 pageLabel2.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.pageLabel2.text"));
164 pageLabel2.setMaximumSize(
new java.awt.Dimension(29, 14));
165 pageLabel2.setMinimumSize(
new java.awt.Dimension(29, 14));
167 prevPageButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back.png")));
168 prevPageButton.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.prevPageButton.text"));
169 prevPageButton.setBorderPainted(
false);
170 prevPageButton.setContentAreaFilled(
false);
171 prevPageButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png")));
172 prevPageButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
173 prevPageButton.setPreferredSize(
new java.awt.Dimension(55, 23));
174 prevPageButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png")));
175 prevPageButton.addActionListener(
new java.awt.event.ActionListener() {
176 public void actionPerformed(java.awt.event.ActionEvent evt) {
177 prevPageButtonActionPerformed(evt);
181 goToPageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.goToPageLabel.text"));
183 goToPageTextField.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.goToPageTextField.text"));
184 goToPageTextField.addActionListener(
new java.awt.event.ActionListener() {
185 public void actionPerformed(java.awt.event.ActionEvent evt) {
186 goToPageTextFieldActionPerformed(evt);
190 languageCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.languageCombo.toolTipText"));
191 languageCombo.addActionListener(
new java.awt.event.ActionListener() {
192 public void actionPerformed(java.awt.event.ActionEvent evt) {
193 languageComboActionPerformed(evt);
197 languageLabel.setText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.languageLabel.text"));
198 languageLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(
DataContentViewerString.class,
"DataContentViewerString.languageLabel.toolTipText"));
200 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
201 jPanel2.setLayout(jPanel2Layout);
202 jPanel2Layout.setHorizontalGroup(
203 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addGroup(jPanel2Layout.createSequentialGroup()
206 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
208 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
209 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
210 .addComponent(ofLabel)
211 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
212 .addComponent(totalPageLabel)
214 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
215 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
216 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
218 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
220 .addComponent(goToPageLabel)
221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
222 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
224 .addComponent(languageLabel)
225 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
227 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
229 jPanel2Layout.setVerticalGroup(
230 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
232 .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
233 .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
234 .addComponent(ofLabel)
235 .addComponent(totalPageLabel))
236 .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
237 .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
238 .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
239 .addComponent(goToPageLabel)
240 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
241 .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addComponent(languageCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
243 .addComponent(languageLabel))
246 jScrollPane2.setViewportView(jPanel2);
248 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
249 this.setLayout(layout);
250 layout.setHorizontalGroup(
251 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
253 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
255 layout.setVerticalGroup(
256 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257 .addGroup(layout.createSequentialGroup()
258 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
259 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
260 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE))
266 currentOffset -= PAGE_LENGTH;
267 currentPage = currentPage - 1;
268 currentPageLabel.setText(Integer.toString(currentPage));
269 setDataView(dataSource, currentOffset);
274 currentOffset += PAGE_LENGTH;
275 currentPage = currentPage + 1;
276 currentPageLabel.setText(Integer.toString(currentPage));
277 setDataView(dataSource, currentOffset);
281 String pageNumberStr = goToPageTextField.getText();
283 int maxPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
285 pageNumber = Integer.parseInt(pageNumberStr);
286 }
catch (NumberFormatException ex) {
287 pageNumber = maxPage + 1;
289 if (pageNumber > maxPage || pageNumber < 1) {
290 JOptionPane.showMessageDialog(
this,
291 NbBundle.getMessage(
this.getClass(),
292 "DataContentViewerString.goToPageTextField.msgDlg",
294 NbBundle.getMessage(
this.getClass(),
295 "DataContentViewerString.goToPageTextField.err"),
296 JOptionPane.WARNING_MESSAGE);
299 currentOffset = (pageNumber - 1) * PAGE_LENGTH;
300 currentPage = pageNumber;
301 currentPageLabel.setText(Integer.toString(currentPage));
302 setDataView(dataSource, currentOffset);
307 if (dataSource != null) {
308 setDataView(dataSource, currentOffset);
340 if (dataSource == null) {
345 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
347 this.dataSource = dataSource;
352 if (dataSource.getSize() > 0) {
354 bytesRead = dataSource.read(data, offset, PAGE_LENGTH);
355 }
catch (TskException ex) {
356 text = NbBundle.getMessage(this.getClass(),
357 "DataContentViewerString.setDataView.errorText", currentOffset,
358 currentOffset + PAGE_LENGTH);
359 logger.log(Level.WARNING,
"Error while trying to show the String content.", ex);
365 final SCRIPT selScript = (
SCRIPT) languageCombo.getSelectedItem();
369 if (text.trim().isEmpty()) {
370 text = NbBundle.getMessage(this.getClass(),
371 "DataContentViewerString.setDataView.errorNoText", currentOffset,
372 currentOffset + PAGE_LENGTH);
375 text = NbBundle.getMessage(this.getClass(),
"DataContentViewerString.setDataView.errorText", currentOffset,
376 currentOffset + PAGE_LENGTH);
380 if (offset + PAGE_LENGTH < dataSource.getSize()) {
381 nextPageButton.setEnabled(
true);
383 nextPageButton.setEnabled(
false);
387 prevPageButton.setEnabled(
false);
390 prevPageButton.setEnabled(
true);
393 int totalPage = Math.round((dataSource.getSize() - 1) / PAGE_LENGTH) + 1;
394 totalPageLabel.setText(Integer.toString(totalPage));
395 currentPageLabel.setText(Integer.toString(currentPage));
396 outputViewPane.setText(text);
397 setComponentsVisibility(
true);
398 outputViewPane.moveCaretPosition(0);
400 this.setCursor(null);
404 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
406 this.dataSource = null;
411 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);
448 if ((selectedNode == null) || (!isSupported(selectedNode))) {
454 if (content != null) {
455 this.setDataView(content, 0);
459 if (scontent != null) {
460 this.setDataView(scontent);
469 return NbBundle.getMessage(this.getClass(),
"DataContentViewerString.title");
474 return NbBundle.getMessage(this.getClass(),
"DataContentViewerString.toolTip");
487 this.dataSource = null;
488 currentPageLabel.setText(
"");
489 totalPageLabel.setText(
"");
490 prevPageButton.setEnabled(
false);
491 nextPageButton.setEnabled(
false);
492 outputViewPane.setText(
"");
493 setComponentsVisibility(
false);
501 Content content = node.getLookup().lookup(Content.class);
502 return (content != null && content.getSize() > 0);
520 if (evt.isPopupTrigger()) {
521 rightClickMenu.setLocation(evt.getLocationOnScreen());
522 rightClickMenu.setVisible(
true);
523 copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
525 rightClickMenu.setVisible(
false);
static Content getDefaultContent(Node node)
void maybeShowPopup(java.awt.event.MouseEvent evt)
javax.swing.JLabel pageLabel2
javax.swing.JComboBox< SCRIPT > languageCombo
javax.swing.JLabel totalPageLabel
void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JMenuItem copyMenuItem
javax.swing.JLabel pageLabel
void setNode(Node selectedNode)
DataContentViewerString()
DataContentViewer createInstance()
javax.swing.JLabel languageLabel
void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt)
void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel ofLabel
void setDataView(Content dataSource, long offset)
javax.swing.JButton prevPageButton
javax.swing.JButton nextPageButton
javax.swing.JMenuItem selectAllMenuItem
javax.swing.JScrollPane jScrollPane1
void setDataView(StringContent dataSource)
javax.swing.JScrollPane jScrollPane2
javax.swing.JTextField goToPageTextField
synchronized static Logger getLogger(String name)
int isPreferred(Node node)
void setComponentsVisibility(boolean isVisible)
javax.swing.JLabel goToPageLabel
void languageComboActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JTextPane outputViewPane
javax.swing.JLabel currentPageLabel
boolean isSupported(Node node)
javax.swing.JPanel jPanel2
javax.swing.JPopupMenu rightClickMenu
void customizeComponents()