Autopsy  4.1
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-2016 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.JTextPane;
31 import javax.swing.text.BadLocationException;
32 import javax.swing.text.Utilities;
33 import org.openide.nodes.Node;
34 import org.openide.util.lookup.ServiceProvider;
37 import org.sleuthkit.datamodel.Content;
38 import org.sleuthkit.datamodel.TskException;
39 
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  outputViewPane.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  outputViewPane.copy();
72  } else if (jmi.equals(selectAllMenuItem)) {
73  outputViewPane.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  hexViewerPanel = new javax.swing.JPanel();
94  jScrollPane1 = new javax.swing.JScrollPane();
95  outputViewPane = new JTextPane(){
96  public boolean getScrollableTracksViewportWidth() {
97  return (getSize().width < 400);
98  }};
99  this.outputViewPane.setBackground(new java.awt.Color(255, 255, 255)); // to make sure the background color is white
100  this.outputViewPane.requestFocusInWindow();
101  this.outputViewPane.setCursor(Cursor.getDefaultCursor());
102  totalPageLabel = new javax.swing.JLabel();
103  ofLabel = new javax.swing.JLabel();
104  currentPageLabel = new javax.swing.JLabel();
105  pageLabel = new javax.swing.JLabel();
106  prevPageButton = new javax.swing.JButton();
107  nextPageButton = new javax.swing.JButton();
108  pageLabel2 = new javax.swing.JLabel();
109  goToPageTextField = new javax.swing.JTextField();
110  goToPageLabel = new javax.swing.JLabel();
111  goToOffsetLabel = new javax.swing.JLabel();
112  goToOffsetTextField = new javax.swing.JTextField();
113 
114  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.copyMenuItem.text")); // NOI18N
115  rightClickMenu.add(copyMenuItem);
116 
117  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.selectAllMenuItem.text")); // NOI18N
118  rightClickMenu.add(selectAllMenuItem);
119 
120  jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
121 
122  outputViewPane.setEditable(false);
123  outputViewPane.setFont(new java.awt.Font("Courier New", 0, 11)); // NOI18N
124  outputViewPane.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
125  outputViewPane.setMinimumSize(new java.awt.Dimension(700, 20));
126  outputViewPane.setPreferredSize(new java.awt.Dimension(700, 400));
127  jScrollPane1.setViewportView(outputViewPane);
128 
129  totalPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.totalPageLabel.text_1")); // NOI18N
130 
131  ofLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.ofLabel.text_1")); // NOI18N
132 
133  currentPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.currentPageLabel.text_1")); // NOI18N
134  currentPageLabel.setMaximumSize(new java.awt.Dimension(18, 14));
135  currentPageLabel.setMinimumSize(new java.awt.Dimension(18, 14));
136  currentPageLabel.setPreferredSize(new java.awt.Dimension(18, 14));
137 
138  pageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.pageLabel.text_1")); // NOI18N
139  pageLabel.setMaximumSize(new java.awt.Dimension(33, 14));
140  pageLabel.setMinimumSize(new java.awt.Dimension(33, 14));
141  pageLabel.setPreferredSize(new java.awt.Dimension(33, 14));
142 
143  prevPageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back.png"))); // NOI18N
144  prevPageButton.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.prevPageButton.text")); // NOI18N
145  prevPageButton.setBorderPainted(false);
146  prevPageButton.setContentAreaFilled(false);
147  prevPageButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back_disabled.png"))); // NOI18N
148  prevPageButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
149  prevPageButton.setPreferredSize(new java.awt.Dimension(23, 23));
150  prevPageButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_back_hover.png"))); // NOI18N
151  prevPageButton.addActionListener(new java.awt.event.ActionListener() {
152  public void actionPerformed(java.awt.event.ActionEvent evt) {
153  prevPageButtonActionPerformed(evt);
154  }
155  });
156 
157  nextPageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward.png"))); // NOI18N
158  nextPageButton.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.nextPageButton.text")); // NOI18N
159  nextPageButton.setBorderPainted(false);
160  nextPageButton.setContentAreaFilled(false);
161  nextPageButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward_disabled.png"))); // NOI18N
162  nextPageButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
163  nextPageButton.setPreferredSize(new java.awt.Dimension(23, 23));
164  nextPageButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/btn_step_forward_hover.png"))); // NOI18N
165  nextPageButton.addActionListener(new java.awt.event.ActionListener() {
166  public void actionPerformed(java.awt.event.ActionEvent evt) {
167  nextPageButtonActionPerformed(evt);
168  }
169  });
170 
171  pageLabel2.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.pageLabel2.text")); // NOI18N
172  pageLabel2.setMaximumSize(new java.awt.Dimension(29, 14));
173  pageLabel2.setMinimumSize(new java.awt.Dimension(29, 14));
174  pageLabel2.setPreferredSize(new java.awt.Dimension(29, 14));
175 
176  goToPageTextField.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToPageTextField.text")); // NOI18N
177  goToPageTextField.addActionListener(new java.awt.event.ActionListener() {
178  public void actionPerformed(java.awt.event.ActionEvent evt) {
179  goToPageTextFieldActionPerformed(evt);
180  }
181  });
182 
183  goToPageLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToPageLabel.text")); // NOI18N
184 
185  goToOffsetLabel.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToOffsetLabel.text")); // NOI18N
186 
187  goToOffsetTextField.setText(org.openide.util.NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.goToOffsetTextField.text")); // NOI18N
188  goToOffsetTextField.addActionListener(new java.awt.event.ActionListener() {
189  public void actionPerformed(java.awt.event.ActionEvent evt) {
190  goToOffsetTextFieldActionPerformed(evt);
191  }
192  });
193 
194  javax.swing.GroupLayout hexViewerPanelLayout = new javax.swing.GroupLayout(hexViewerPanel);
195  hexViewerPanel.setLayout(hexViewerPanelLayout);
196  hexViewerPanelLayout.setHorizontalGroup(
197  hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198  .addGroup(hexViewerPanelLayout.createSequentialGroup()
199  .addContainerGap()
200  .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
201  .addGap(18, 18, 18)
202  .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
203  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204  .addComponent(ofLabel)
205  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
206  .addComponent(totalPageLabel)
207  .addGap(50, 50, 50)
208  .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
209  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
210  .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
211  .addGap(0, 0, 0)
212  .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
213  .addGap(18, 18, 18)
214  .addComponent(goToPageLabel)
215  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
216  .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
217  .addGap(18, 18, 18)
218  .addComponent(goToOffsetLabel)
219  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
220  .addComponent(goToOffsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
221  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
222  .addComponent(jScrollPane1)
223  );
224  hexViewerPanelLayout.setVerticalGroup(
225  hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addGroup(hexViewerPanelLayout.createSequentialGroup()
227  .addGroup(hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228  .addComponent(pageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
229  .addGroup(hexViewerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
230  .addComponent(currentPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
231  .addComponent(ofLabel)
232  .addComponent(totalPageLabel))
233  .addComponent(pageLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
234  .addComponent(nextPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
235  .addComponent(prevPageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
236  .addComponent(goToPageLabel)
237  .addComponent(goToPageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238  .addComponent(goToOffsetLabel)
239  .addComponent(goToOffsetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
240  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
241  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE))
242  );
243 
244  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
245  this.setLayout(layout);
246  layout.setHorizontalGroup(
247  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248  .addGap(0, 622, Short.MAX_VALUE)
249  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250  .addGroup(layout.createSequentialGroup()
251  .addGap(0, 0, 0)
252  .addComponent(hexViewerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
253  .addGap(0, 0, 0)))
254  );
255  layout.setVerticalGroup(
256  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257  .addGap(0, 411, Short.MAX_VALUE)
258  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259  .addGroup(layout.createSequentialGroup()
260  .addGap(0, 0, 0)
261  .addComponent(hexViewerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
262  .addGap(0, 0, 0)))
263  );
264  }// </editor-fold>//GEN-END:initComponents
265 
266  private void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevPageButtonActionPerformed
267  setDataViewByPageNumber(currentPage - 1);
268  goToPageTextField.setText(Integer.toString(currentPage));
269  }//GEN-LAST:event_prevPageButtonActionPerformed
270 
271  private void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPageButtonActionPerformed
272  setDataViewByPageNumber(currentPage + 1);
273  goToPageTextField.setText(Integer.toString(currentPage));
274  }//GEN-LAST:event_nextPageButtonActionPerformed
275 
276  private void goToPageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToPageTextFieldActionPerformed
277  String pageNumberStr = goToPageTextField.getText();
278  int pageNumber = 0;
279 
280  try {
281  pageNumber = Integer.parseInt(pageNumberStr);
282  } catch (NumberFormatException ex) {
283  pageNumber = totalPages + 1;
284  }
285  if (pageNumber > totalPages || pageNumber < 1) {
286  JOptionPane.showMessageDialog(this,
287  NbBundle.getMessage(this.getClass(),
288  "DataContentViewerHex.goToPageTextField.msgDlg",
289  totalPages),
290  NbBundle.getMessage(this.getClass(),
291  "DataContentViewerHex.goToPageTextField.err"),
292  JOptionPane.WARNING_MESSAGE);
293  return;
294  }
295  setDataViewByPageNumber(pageNumber);
296  }//GEN-LAST:event_goToPageTextFieldActionPerformed
297 
308  private long getOffsetRelativeToCaretPosition(Long userInput) {
309  String userSelectedLine;
310  try {
311  // get the selected line. Extract the current hex offset location.
312  userSelectedLine = outputViewPane.getText().subSequence(
313  Utilities.getRowStart(outputViewPane, outputViewPane.getCaretPosition()),
314  Utilities.getRowEnd(outputViewPane, outputViewPane.getCaretPosition()))
315  .toString();
316  // NOTE: This needs to change if the outputFormat of outputViewPane changes.
317  String hexForUserSelectedLine = userSelectedLine.substring(0, userSelectedLine.indexOf(":"));
318 
319  return Long.decode(hexForUserSelectedLine) + userInput;
320  } catch (BadLocationException | StringIndexOutOfBoundsException | NumberFormatException ex) {
321  // thrown in case the caret location is out of the range of the outputViewPane.
322  return -1L;
323  }
324  }
325 
326  private void goToOffsetTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goToOffsetTextFieldActionPerformed
327  long offset;
328  try {
329  if (goToOffsetTextField.getText().startsWith("+") || goToOffsetTextField.getText().startsWith("-")) {
330  offset = getOffsetRelativeToCaretPosition(Long.decode(goToOffsetTextField.getText()));
331  } else {
332  offset = Long.decode(goToOffsetTextField.getText());
333  }
334  } catch (NumberFormatException ex) {
335  // notify the user and return
336  JOptionPane.showMessageDialog(this, NbBundle.getMessage(this.getClass(), "DataContentViewerHex.goToOffsetTextField.msgDlg", goToOffsetTextField.getText()));
337  return;
338  }
339 
340  if (offset >= 0) {
341  setDataViewByOffset(offset);
342  } else {
343  outputViewPane.setText(NbBundle.getMessage(DataContentViewerHex.class, "DataContentViewerHex.setDataView.invalidOffset.negativeOffsetValue"));
344  }
345  }//GEN-LAST:event_goToOffsetTextFieldActionPerformed
346 
347  // Variables declaration - do not modify//GEN-BEGIN:variables
348  private javax.swing.JMenuItem copyMenuItem;
349  private javax.swing.JLabel currentPageLabel;
350  private javax.swing.JLabel goToOffsetLabel;
351  private javax.swing.JTextField goToOffsetTextField;
352  private javax.swing.JLabel goToPageLabel;
353  private javax.swing.JTextField goToPageTextField;
354  private javax.swing.JPanel hexViewerPanel;
355  private javax.swing.JScrollPane jScrollPane1;
356  private javax.swing.JButton nextPageButton;
357  private javax.swing.JLabel ofLabel;
358  private javax.swing.JTextPane outputViewPane;
359  private javax.swing.JLabel pageLabel;
360  private javax.swing.JLabel pageLabel2;
361  private javax.swing.JButton prevPageButton;
362  private javax.swing.JPopupMenu rightClickMenu;
363  private javax.swing.JMenuItem selectAllMenuItem;
364  private javax.swing.JLabel totalPageLabel;
365  // End of variables declaration//GEN-END:variables
366 
372  private void setDataViewByPageNumber(int page) {
373  if (this.dataSource == null) {
374  return;
375  }
376  if (page == 0) {
377  return;
378  }
379  currentPage = page;
380  long offset = (currentPage - 1) * pageLength;
381  setDataView(offset);
382  goToOffsetTextField.setText(Long.toString(offset));
383  }
384 
390  private void setDataViewByOffset(long offset) {
391  if (this.dataSource == null) {
392  return;
393  }
394  currentPage = (int) (offset / pageLength) + 1;
395  setDataView(offset);
396  goToPageTextField.setText(Integer.toString(currentPage));
397  }
398 
399  private void setDataView(long offset) {
400  // change the cursor to "waiting cursor" for this operation
401  this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
402 
403  String errorText = null;
404 
405  int bytesRead = 0;
406  if (dataSource.getSize() > 0) {
407  try {
408  bytesRead = dataSource.read(data, offset, pageLength); // read the data
409  } catch (TskException ex) {
410  errorText = NbBundle.getMessage(this.getClass(), "DataContentViewerHex.setDataView.errorText", offset,
411  offset + pageLength);
412  logger.log(Level.WARNING, "Error while trying to show the hex content.", ex); //NON-NLS
413  }
414  }
415 
416  // set the data on the bottom and show it
417  if (bytesRead <= 0) {
418  errorText = NbBundle.getMessage(this.getClass(), "DataContentViewerHex.setDataView.errorText", offset,
419  offset + pageLength);
420  }
421 
422  // disable or enable the next button
423  if ((errorText == null) && (currentPage < totalPages)) {
424  nextPageButton.setEnabled(true);
425  } else {
426  nextPageButton.setEnabled(false);
427  }
428 
429  if ((errorText == null) && (currentPage > 1)) {
430  prevPageButton.setEnabled(true);
431  } else {
432  prevPageButton.setEnabled(false);
433  }
434 
435  currentPageLabel.setText(Integer.toString(currentPage));
436  setComponentsVisibility(true); // shows the components that not needed
437 
438  // set the output view
439  if (errorText == null) {
440  int showLength = bytesRead < pageLength ? bytesRead : (int) pageLength;
441  outputViewPane.setText(DataConversion.byteArrayToHex(data, showLength, offset));
442  } else {
443  outputViewPane.setText(errorText);
444  }
445 
446  outputViewPane.setCaretPosition(0);
447  this.setCursor(null);
448  }
449 
450  @Override
451  public void setNode(Node selectedNode) {
452  if ((selectedNode == null) || (!isSupported(selectedNode))) {
453  resetComponent();
454  return;
455  }
456 
457  Content content = (selectedNode).getLookup().lookup(Content.class);
458  if (content == null) {
459  resetComponent();
460  return;
461  }
462 
463  dataSource = content;
464  totalPages = 0;
465  if (dataSource.getSize() > 0) {
466  totalPages = Math.round((dataSource.getSize() - 1) / pageLength) + 1;
467  }
468  totalPageLabel.setText(Integer.toString(totalPages));
469 
470  this.setDataViewByPageNumber(1);
471  }
472 
473  @Override
474  public String getTitle() {
475  return NbBundle.getMessage(this.getClass(), "DataContentViewerHex.title");
476  }
477 
478  @Override
479  public String getToolTip() {
480  return NbBundle.getMessage(this.getClass(), "DataContentViewerHex.toolTip");
481  }
482 
483  @Override
484  public DataContentViewer createInstance() {
485  return new DataContentViewerHex();
486  }
487 
488  @Override
489  public void resetComponent() {
490  // clear / reset the fields
491  currentPage = 1;
492  this.dataSource = null;
493  currentPageLabel.setText("");
494  totalPageLabel.setText("");
495  outputViewPane.setText("");
496  setComponentsVisibility(false); // hides the components that not needed
497  }
498 
504  private void setComponentsVisibility(boolean isVisible) {
505  currentPageLabel.setVisible(isVisible);
506  totalPageLabel.setVisible(isVisible);
507  ofLabel.setVisible(isVisible);
508  prevPageButton.setVisible(isVisible);
509  nextPageButton.setVisible(isVisible);
510  pageLabel.setVisible(isVisible);
511  pageLabel2.setVisible(isVisible);
512  goToPageTextField.setVisible(isVisible);
513  goToPageLabel.setVisible(isVisible);
514  goToOffsetTextField.setVisible(isVisible);
515  goToOffsetLabel.setVisible(isVisible);
516  }
517 
518  @Override
519  public boolean isSupported(Node node) {
520  if (node == null) {
521  return false;
522  }
523  Content content = node.getLookup().lookup(Content.class);
524  if (content != null && content.getSize() > 0) {
525  return true;
526  }
527 
528  return false;
529  }
530 
531  @Override
532  public int isPreferred(Node node) {
533  return 1;
534  }
535 
536  @Override
537  public Component getComponent() {
538  return this;
539  }
540 
541  /*
542  * Show the right click menu only if evt is the correct mouse event
543  */
544  private void maybeShowPopup(java.awt.event.MouseEvent evt) {
545  if (evt.isPopupTrigger()) {
546  rightClickMenu.setLocation(evt.getLocationOnScreen());
547  rightClickMenu.setVisible(true);
548  copyMenuItem.setEnabled(outputViewPane.getSelectedText() != null);
549  } else {
550  rightClickMenu.setVisible(false);
551  }
552  }
553 }
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:161
void prevPageButtonActionPerformed(java.awt.event.ActionEvent evt)
void nextPageButtonActionPerformed(java.awt.event.ActionEvent evt)

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.