Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentViewerHex.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.corecomponents;
20 
21 import java.awt.*;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.logging.Level;
25 
26 import org.openide.util.NbBundle;
28 import javax.swing.JMenuItem;
29 import javax.swing.JOptionPane;
30 import javax.swing.text.BadLocationException;
31 import javax.swing.text.Utilities;
32 import org.openide.nodes.Node;
33 import org.openide.util.lookup.ServiceProvider;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.TskException;
38 
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 @ServiceProvider(service = DataContentViewer.class, position = 1)
44 public class DataContentViewerHex extends javax.swing.JPanel implements DataContentViewer {
45 
46  private static final long pageLength = 16384;
47  private final byte[] data = new byte[(int) pageLength];
48  private static int currentPage = 1;
49  private int totalPages;
50  private Content dataSource;
51 
52  private static final Logger logger = Logger.getLogger(DataContentViewerHex.class.getName());
53 
58  initComponents();
59  customizeComponents();
60  this.resetComponent();
61  logger.log(Level.INFO, "Created HexView instance: " + this); //NON-NLS
62  }
63 
64  private void customizeComponents() {
65  outputTextArea.setComponentPopupMenu(rightClickMenu);
66  ActionListener actList = new ActionListener() {
67  @Override
68  public void actionPerformed(ActionEvent e) {
69  JMenuItem jmi = (JMenuItem) e.getSource();
70  if (jmi.equals(copyMenuItem)) {
71  outputTextArea.copy();
72  } else if (jmi.equals(selectAllMenuItem)) {
73  outputTextArea.selectAll();
74  }
75  }
76  };
77  copyMenuItem.addActionListener(actList);
78  selectAllMenuItem.addActionListener(actList);
79  }
80 
86  @SuppressWarnings("unchecked")
87  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
88  private void initComponents() {
89 
90  rightClickMenu = new javax.swing.JPopupMenu();
91  copyMenuItem = new javax.swing.JMenuItem();
92  selectAllMenuItem = new javax.swing.JMenuItem();
93  jScrollPane3 = new javax.swing.JScrollPane();
94  outputTextArea = new javax.swing.JTextArea();
95  jScrollPane2 = new javax.swing.JScrollPane();
96  hexViewerPanel = new javax.swing.JPanel();
97  totalPageLabel = new javax.swing.JLabel();
98  ofLabel = new javax.swing.JLabel();
99  currentPageLabel = new javax.swing.JLabel();
100  pageLabel = new javax.swing.JLabel();
101  prevPageButton = new javax.swing.JButton();
102  nextPageButton = new javax.swing.JButton();
103  pageLabel2 = new javax.swing.JLabel();
104  goToPageTextField = new javax.swing.JTextField();
105  goToPageLabel = new javax.swing.JLabel();
106  goToOffsetLabel = new javax.swing.JLabel();
107  goToOffsetTextField = new javax.swing.JTextField();
108 
109  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.copyMenuItem.text")); // NOI18N
110  rightClickMenu.add(copyMenuItem);
111 
112  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.selectAllMenuItem.text")); // NOI18N
113  rightClickMenu.add(selectAllMenuItem);
114 
115  setPreferredSize(new java.awt.Dimension(100, 58));
116 
117  jScrollPane3.setPreferredSize(new java.awt.Dimension(300, 33));
118 
119  outputTextArea.setEditable(false);
120  outputTextArea.setFont(new java.awt.Font("Courier New", 0, 11)); // NOI18N
121  outputTextArea.setTabSize(0);
122  outputTextArea.setInheritsPopupMenu(true);
123  jScrollPane3.setViewportView(outputTextArea);
124 
125  jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
126  jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
127 
128  totalPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.totalPageLabel.text_1")); // NOI18N
129 
130  ofLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.ofLabel.text_1")); // NOI18N
131 
132  currentPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.currentPageLabel.text_1")); // NOI18N
133  currentPageLabel.setMaximumSize(new java.awt.Dimension(18, 14));
134  currentPageLabel.setMinimumSize(new java.awt.Dimension(18, 14));
135 
136  pageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.pageLabel.text_1")); // NOI18N
137  pageLabel.setMaximumSize(new java.awt.Dimension(33, 14));
138  pageLabel.setMinimumSize(new java.awt.Dimension(33, 14));
139 
140  prevPageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back.png"))); // NOI18N
141  prevPageButton.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.prevPageButton.text")); // NOI18N
142  prevPageButton.setBorderPainted(false);
143  prevPageButton.setContentAreaFilled(false);
144  prevPageButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png"))); // NOI18N
145  prevPageButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
146  prevPageButton.setPreferredSize(new java.awt.Dimension(23, 23));
147  prevPageButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png"))); // NOI18N
148  prevPageButton.addActionListener(new java.awt.event.ActionListener() {
149  public void actionPerformed(java.awt.event.ActionEvent evt) {
150  prevPageButtonActionPerformed(evt);
151  }
152  });
153 
154  nextPageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png"))); // NOI18N
155  nextPageButton.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.nextPageButton.text")); // NOI18N
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"))); // NOI18N
159  nextPageButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
160  nextPageButton.setPreferredSize(new java.awt.Dimension(23, 23));
161  nextPageButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png"))); // NOI18N
162  nextPageButton.addActionListener(new java.awt.event.ActionListener() {
163  public void actionPerformed(java.awt.event.ActionEvent evt) {
164  nextPageButtonActionPerformed(evt);
165  }
166  });
167 
168  pageLabel2.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.pageLabel2.text")); // NOI18N
169  pageLabel2.setMaximumSize(new java.awt.Dimension(29, 14));
170  pageLabel2.setMinimumSize(new java.awt.Dimension(29, 14));
171 
172  goToPageTextField.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToPageTextField.text")); // NOI18N
173  goToPageTextField.addActionListener(new java.awt.event.ActionListener() {
174  public void actionPerformed(java.awt.event.ActionEvent evt) {
175  goToPageTextFieldActionPerformed(evt);
176  }
177  });
178 
179  goToPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToPageLabel.text")); // NOI18N
180 
181  goToOffsetLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToOffsetLabel.text")); // NOI18N
182 
183  goToOffsetTextField.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToOffsetTextField.text")); // NOI18N
184  goToOffsetTextField.addActionListener(new java.awt.event.ActionListener() {
185  public void actionPerformed(java.awt.event.ActionEvent evt) {
186  goToOffsetTextFieldActionPerformed(evt);
187  }
188  });
189 
190  javax.swing.GroupLayout hexViewerPanelLayout = new javax.swing.GroupLayout(hexViewerPanel);
191  hexViewerPanel.setLayout(hexViewerPanelLayout);
192  hexViewerPanelLayout.setHorizontalGroup(
193  hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194  .addGroup(hexViewerPanelLayout.createSequentialGroup()
195  .addContainerGap()
196  .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
197  .addGap(18, 18, 18)
198  .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
199  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
200  .addComponent(ofLabel)
201  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
202  .addComponent(totalPageLabel)
203  .addGap(50, 50, 50)
204  .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
205  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
206  .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
207  .addGap(0, 0, 0)
208  .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
209  .addGap(18, 18, 18)
210  .addComponent(goToPageLabel)
211  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
212  .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
213  .addGap(18, 18, 18)
214  .addComponent(goToOffsetLabel)
215  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
216  .addComponent(goToOffsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
217  .addContainerGap(32, Short.MAX_VALUE))
218  );
219  hexViewerPanelLayout.setVerticalGroup(
220  hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221  .addGroup(hexViewerPanelLayout.createSequentialGroup()
222  .addGroup(hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
223  .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224  .addGroup(hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
225  .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
226  .addComponent(ofLabel)
227  .addComponent(totalPageLabel))
228  .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
229  .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
230  .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
231  .addComponent(goToPageLabel)
232  .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
233  .addComponent(goToOffsetLabel)
234  .addComponent(goToOffsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
235  .addGap(0, 0, 0))
236  );
237 
238  jScrollPane2.setViewportView(hexViewerPanel);
239 
240  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
241  this.setLayout(layout);
242  layout.setHorizontalGroup(
243  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
245  .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
246  );
247  layout.setVerticalGroup(
248  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
250  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
251  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
252  .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE))
253  );
254  }// </editor-fold>//GEN-END:initComponents
255 
256  private void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevPageButtonActionPerformed
257  setDataViewByPageNumber(currentPage - 1);
258  goToPageTextField.setText(Integer.toString(currentPage));
259  }//GEN-LAST:event_prevPageButtonActionPerformed
260 
261  private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed
262  setDataViewByPageNumber(currentPage + 1);
263  goToPageTextField.setText(Integer.toString(currentPage));
264  }//GEN-LAST:event_nextPageButtonActionPerformed
265 
266  private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed
267  String pageNumberStr = goToPageTextField.getText();
268  int pageNumber = 0;
269 
270  try {
271  pageNumber = Integer.parseInt(pageNumberStr);
272  } catch (NumberFormatException ex) {
273  pageNumber = totalPages + 1;
274  }
275  if (pageNumber > totalPages || pageNumber < 1) {
276  JOptionPane.showMessageDialog(this,
277  NbBundle.getMessage(this.getClass(),
278  "DataContentViewerHex.goToPageTextField.msgDlg",
279  totalPages),
280  NbBundle.getMessage(this.getClass(),
281  "DataContentViewerHex.goToPageTextField.err"),
282  JOptionPane.WARNING_MESSAGE);
283  return;
284  }
285  setDataViewByPageNumber(pageNumber);
286  }//GEN-LAST:event_goToPageTextFieldActionPerformed
287 
298  private long getOffsetRelativeToCaretPosition(Long userInput) {
299  String userSelectedLine;
300  try {
301  // get the selected line. Extract the current hex offset location.
302  userSelectedLine = outputTextArea.getText().subSequence(
303  Utilities.getRowStart(outputTextArea, outputTextArea.getCaretPosition()),
304  Utilities.getRowEnd(outputTextArea, outputTextArea.getCaretPosition()))
305  .toString();
306  // NOTE: This needs to change if the outputFormat of outputTextArea changes.
307  String hexForUserSelectedLine = userSelectedLine.substring(0, userSelectedLine.indexOf(":"));
308 
309  return Long.decode(hexForUserSelectedLine) + userInput;
310  } catch (BadLocationException | StringIndexOutOfBoundsException | NumberFormatException ex) {
311  // thrown in case the caret location is out of the range of the outputTextArea.
312  return -1L;
313  }
314  }
315 
316  private void goToOffsetTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToOffsetTextFieldActionPerformed
317  long offset;
318  try {
319  if (goToOffsetTextField.getText().startsWith("+") || goToOffsetTextField.getText().startsWith("-")) {
320  offset = getOffsetRelativeToCaretPosition(Long.decode(goToOffsetTextField.getText()));
321  } else {
322  offset = Long.decode(goToOffsetTextField.getText());
323  }
324  } catch (NumberFormatException ex) {
325  // notify the user and return
326  JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), "DataContentViewerHex.goToOffsetTextField.msgDlg", goToOffsetTextField.getText()));
327  return;
328  }
329 
330  if (offset >= 0) {
331  setDataViewByOffset(offset);
332  } else {
333  outputTextArea.setText(NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.setDataView.invalidOffset.negativeOffsetValue"));
334  }
335  }//GEN-LAST:event_goToOffsetTextFieldActionPerformed
336 
337  // Variables declaration - do not modify//GEN-BEGIN:variables
338  private javax.swing.JMenuItem copyMenuItem;
339  private javax.swing.JLabel currentPageLabel;
340  private javax.swing.JLabel goToOffsetLabel;
341  private javax.swing.JTextField goToOffsetTextField;
342  private javax.swing.JLabel goToPageLabel;
343  private javax.swing.JTextField goToPageTextField;
344  private javax.swing.JPanel hexViewerPanel;
345  private javax.swing.JScrollPane jScrollPane2;
346  private javax.swing.JScrollPane jScrollPane3;
347  private javax.swing.JButton nextPageButton;
348  private javax.swing.JLabel ofLabel;
349  private javax.swing.JTextArea outputTextArea;
350  private javax.swing.JLabel pageLabel;
351  private javax.swing.JLabel pageLabel2;
352  private javax.swing.JButton prevPageButton;
353  private javax.swing.JPopupMenu rightClickMenu;
354  private javax.swing.JMenuItem selectAllMenuItem;
355  private javax.swing.JLabel totalPageLabel;
356  // End of variables declaration//GEN-END:variables
357 
363  private void setDataViewByPageNumber(int page) {
364  if (this.dataSource == null) {
365  return;
366  }
367  if (page == 0) {
368  return;
369  }
370  currentPage = page;
371  long offset = (currentPage - 1) * pageLength;
372  setDataView(offset);
373  goToOffsetTextField.setText(Long.toString(offset));
374  }
375 
381  private void setDataViewByOffset(long offset) {
382  if (this.dataSource == null) {
383  return;
384  }
385  currentPage = (int) (offset / pageLength) + 1;
386  setDataView(offset);
387  goToPageTextField.setText(Integer.toString(currentPage));
388  }
389 
390  private void setDataView(long offset) {
391  // change the cursor to "waiting cursor" for this operation
392  this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
393 
394  String errorText = null;
395 
396  int bytesRead = 0;
397  if (dataSource.getSize() > 0) {
398  try {
399  bytesRead = dataSource.read(data, offset, pageLength); // read the data
400  } catch (TskException ex) {
401  errorText = NbBundle.getMessage(this.getClass(), "DataContentViewerHex.setDataView.errorText", offset,
402  offset + pageLength);
403  logger.log(Level.WARNING, "Error while trying to show the hex content.", ex); //NON-NLS
404  }
405  }
406 
407  // set the data on the bottom and show it
408  if (bytesRead <= 0) {
409  errorText = NbBundle.getMessage(this.getClass(), "DataContentViewerHex.setDataView.errorText", offset,
410  offset + pageLength);
411  }
412 
413  // disable or enable the next button
414  if ((errorText == null) && (currentPage < totalPages)) {
415  nextPageButton.setEnabled(true);
416  } else {
417  nextPageButton.setEnabled(false);
418  }
419 
420  if ((errorText == null) && (currentPage > 1)) {
421  prevPageButton.setEnabled(true);
422  } else {
423  prevPageButton.setEnabled(false);
424  }
425 
426  currentPageLabel.setText(Integer.toString(currentPage));
427  setComponentsVisibility(true); // shows the components that not needed
428 
429  // set the output view
430  if (errorText == null) {
431  int showLength = bytesRead < pageLength ? bytesRead : (int) pageLength;
432  outputTextArea.setText(DataConversion.byteArrayToHex(data, showLength, offset));
433  } else {
434  outputTextArea.setText(errorText);
435  }
436 
437  outputTextArea.setCaretPosition(0);
438  this.setCursor(null);
439  }
440 
441  @Override
442  public void setNode(Node selectedNode) {
443  if ((selectedNode == null) || (!isSupported(selectedNode))) {
444  resetComponent();
445  return;
446  }
447 
448  Content content = DataContentViewerUtility.getDefaultContent(selectedNode);
449  if (content == null) {
450  resetComponent();
451  return;
452  }
453 
454  dataSource = content;
455  totalPages = 0;
456  if (dataSource.getSize() > 0) {
457  totalPages = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
458  }
459  totalPageLabel.setText(Integer.toString(totalPages));
460 
461  this.setDataViewByPageNumber(1);
462  }
463 
464  @Override
465  public String getTitle() {
466  return NbBundle.getMessage(this.getClass(), "DataContentViewerHex.title");
467  }
468 
469  @Override
470  public String getToolTip() {
471  return NbBundle.getMessage(this.getClass(), "DataContentViewerHex.toolTip");
472  }
473 
474  @Override
475  public DataContentViewer createInstance() {
476  return new DataContentViewerHex();
477  }
478 
479  @Override
480  public void resetComponent() {
481  // clear / reset the fields
482  currentPage = 1;
483  this.dataSource = null;
484  currentPageLabel.setText("");
485  totalPageLabel.setText("");
486  outputTextArea.setText("");
487  setComponentsVisibility(false); // hides the components that not needed
488  }
489 
495  private void setComponentsVisibility(boolean isVisible) {
496  currentPageLabel.setVisible(isVisible);
497  totalPageLabel.setVisible(isVisible);
498  ofLabel.setVisible(isVisible);
499  prevPageButton.setVisible(isVisible);
500  nextPageButton.setVisible(isVisible);
501  pageLabel.setVisible(isVisible);
502  pageLabel2.setVisible(isVisible);
503  goToPageTextField.setVisible(isVisible);
504  goToPageLabel.setVisible(isVisible);
505  goToOffsetTextField.setVisible(isVisible);
506  goToOffsetLabel.setVisible(isVisible);
507  }
508 
509  @Override
510  public boolean isSupported(Node node) {
511  if (node == null) {
512  return false;
513  }
514  Content content = node.getLookup().lookup(Content.class);
515  if (content != null && content.getSize() > 0) {
516  return true;
517  }
518 
519  return false;
520  }
521 
522  @Override
523  public int isPreferred(Node node) {
524  return 1;
525  }
526 
527  @Override
528  public Component getComponent() {
529  return this;
530  }
531 
532  /*
533  * Show the right click menu only if evt is the correct mouse event
534  */
535  private void maybeShowPopup(java.awt.event.MouseEvent evt) {
536  if (evt.isPopupTrigger()) {
537  rightClickMenu.setLocation(evt.getLocationOnScreen());
538  rightClickMenu.setVisible(true);
539  copyMenuItem.setEnabled(outputTextArea.getSelectedText() != null);
540  } else {
541  rightClickMenu.setVisible(false);
542  }
543  }
544 }
void goToOffsetTextFieldActionPerformed(java.awt.event.ActionEvent evt)
void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt)
static String byteArrayToHex(byte[] array, int length, long arrayOffset, Font font)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt)
void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt)

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.