Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExtractedContentPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.keywordsearch;
20 
21 import java.awt.ComponentOrientation;
22 import java.awt.EventQueue;
23 import java.awt.event.ActionListener;
24 import java.awt.event.ItemEvent;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.concurrent.CancellationException;
28 import java.util.concurrent.ExecutionException;
29 import java.util.logging.Level;
30 import javax.swing.SizeRequirements;
31 import javax.swing.SwingWorker;
32 import javax.swing.text.Element;
33 import javax.swing.text.View;
34 import javax.swing.text.ViewFactory;
35 import javax.swing.text.html.HTMLEditorKit;
36 import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
37 import javax.swing.text.html.InlineView;
38 import javax.swing.text.html.ParagraphView;
39 import org.apache.commons.lang3.StringUtils;
40 import org.netbeans.api.progress.ProgressHandle;
41 import org.openide.util.NbBundle;
45 
50 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
51 class ExtractedContentPanel extends javax.swing.JPanel {
52 
53  private static final Logger logger = Logger.getLogger(ExtractedContentPanel.class.getName());
54  private static final long serialVersionUID = 1L;
55  private String contentName;
56 
57  ExtractedContentPanel() {
58  initComponents();
59  setSources("", new ArrayList<>());
60  hitPreviousButton.setEnabled(false);
61  hitNextButton.setEnabled(false);
62 
63  /*
64  * This appears to be an attempt to modify the wrapping behavior of the
65  * extractedTextPane taken form this website:
66  * http://java-sl.com/tip_html_letter_wrap.html.
67  */
68  HTMLEditorKit editorKit = new HTMLEditorKit() {
69  private static final long serialVersionUID = 1L;
70 
71  @Override
72  public ViewFactory getViewFactory() {
73 
74  return new HTMLFactory() {
75  @Override
76  public View create(Element e) {
77  View v = super.create(e);
78  if (v instanceof InlineView) {
79  return new InlineView(e) {
80  @Override
81  public int getBreakWeight(int axis, float pos, float len) {
82  return GoodBreakWeight;
83  }
84 
85  @Override
86  public View breakView(int axis, int p0, float pos, float len) {
87  if (axis == View.X_AXIS) {
88  checkPainter();
89  int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
90  if (p0 == getStartOffset() && p1 == getEndOffset()) {
91  return this;
92  }
93  return createFragment(p0, p1);
94  }
95  return this;
96  }
97  };
98  } else if (v instanceof ParagraphView) {
99  return new ParagraphView(e) {
100  @Override
101  protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
102  SizeRequirements requirements = r;
103  if (requirements == null) {
104  requirements = new SizeRequirements();
105  }
106  float pref = layoutPool.getPreferredSpan(axis);
107  float min = layoutPool.getMinimumSpan(axis);
108  // Don't include insets, Box.getXXXSpan will include them.
109  requirements.minimum = (int) min;
110  requirements.preferred = Math.max(requirements.minimum, (int) pref);
111  requirements.maximum = Integer.MAX_VALUE;
112  requirements.alignment = 0.5f;
113  return requirements;
114  }
115  };
116  }
117  return v;
118  }
119  };
120  }
121  };
122  /*
123  * set font size manually in an effort to get fonts in this panel to
124  * look similar to what is in the 'String View' content viewer.
125  */
126  editorKit.getStyleSheet().addRule("body {font-size: 8.5px;}"); //NON-NLS
127  extractedTextPane.setEditorKit(editorKit);
128 
129  sourceComboBox.addItemListener(itemEvent -> {
130  if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
131  refreshCurrentMarkup();
132  }
133  });
134  extractedTextPane.setComponentPopupMenu(rightClickMenu);
135  copyMenuItem.addActionListener(actionEvent -> extractedTextPane.copy());
136  selectAllMenuItem.addActionListener(actionEvent -> extractedTextPane.selectAll());
137  }
138 
144  @SuppressWarnings("unchecked")
145  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
146  private void initComponents() {
147 
148  rightClickMenu = new javax.swing.JPopupMenu();
149  copyMenuItem = new javax.swing.JMenuItem();
150  selectAllMenuItem = new javax.swing.JMenuItem();
151  extractedScrollPane = new javax.swing.JScrollPane();
152  extractedTextPane = new javax.swing.JTextPane();
153  controlScrollPane = new javax.swing.JScrollPane();
154  controlPanel = new javax.swing.JPanel();
155  sourceComboBox = new javax.swing.JComboBox<>();
156  jLabel1 = new javax.swing.JLabel();
157  pageOfLabel = new javax.swing.JLabel();
158  pageButtonsLabel = new javax.swing.JLabel();
159  pageTotalLabel = new javax.swing.JLabel();
160  pagesLabel = new javax.swing.JLabel();
161  pageNextButton = new javax.swing.JButton();
162  pagePreviousButton = new javax.swing.JButton();
163  pageCurLabel = new javax.swing.JLabel();
164  jSeparator1 = new javax.swing.JSeparator();
165  hitLabel = new javax.swing.JLabel();
166  hitButtonsLabel = new javax.swing.JLabel();
167  hitNextButton = new javax.swing.JButton();
168  hitOfLabel = new javax.swing.JLabel();
169  hitTotalLabel = new javax.swing.JLabel();
170  hitPreviousButton = new javax.swing.JButton();
171  hitCountLabel = new javax.swing.JLabel();
172  jSeparator2 = new javax.swing.JSeparator();
173 
174  copyMenuItem.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.copyMenuItem.text")); // NOI18N
175  rightClickMenu.add(copyMenuItem);
176 
177  selectAllMenuItem.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.selectAllMenuItem.text")); // NOI18N
178  rightClickMenu.add(selectAllMenuItem);
179 
180  setPreferredSize(new java.awt.Dimension(100, 58));
181 
182  extractedScrollPane.setBackground(new java.awt.Color(255, 255, 255));
183  extractedScrollPane.setPreferredSize(new java.awt.Dimension(640, 29));
184 
185  extractedTextPane.setEditable(false);
186  extractedTextPane.setAutoscrolls(false);
187  extractedTextPane.setInheritsPopupMenu(true);
188  extractedTextPane.setMaximumSize(new java.awt.Dimension(2000, 2000));
189  extractedTextPane.setPreferredSize(new java.awt.Dimension(600, 29));
190  extractedScrollPane.setViewportView(extractedTextPane);
191 
192  controlScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
193  controlScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
194  controlScrollPane.setPreferredSize(new java.awt.Dimension(600, 100));
195 
196  controlPanel.setMinimumSize(new java.awt.Dimension(0, 0));
197  controlPanel.setPreferredSize(new java.awt.Dimension(600, 81));
198 
199  sourceComboBox.setModel(new javax.swing.DefaultComboBoxModel<org.sleuthkit.autopsy.keywordsearch.IndexedText>());
200  sourceComboBox.setMaximumSize(new java.awt.Dimension(150, 32767));
201  sourceComboBox.setMinimumSize(new java.awt.Dimension(150, 20));
202  sourceComboBox.setPreferredSize(new java.awt.Dimension(150, 20));
203 
204  jLabel1.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.jLabel1.text")); // NOI18N
205 
206  pageOfLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pageOfLabel.text")); // NOI18N
207 
208  pageButtonsLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pageButtonsLabel.text")); // NOI18N
209 
210  pageTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
211  pageTotalLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pageTotalLabel.text")); // NOI18N
212 
213  pagesLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pagesLabel.text")); // NOI18N
214 
215  pageNextButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_forward.png"))); // NOI18N
216  pageNextButton.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pageNextButton.text")); // NOI18N
217  pageNextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
218  pageNextButton.setBorderPainted(false);
219  pageNextButton.setContentAreaFilled(false);
220  pageNextButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_disabled.png"))); // NOI18N
221  pageNextButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
222  pageNextButton.setPreferredSize(new java.awt.Dimension(23, 23));
223 
224  pagePreviousButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_back.png"))); // NOI18N
225  pagePreviousButton.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pagePreviousButton.text")); // NOI18N
226  pagePreviousButton.setActionCommand(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pagePreviousButton.actionCommand")); // NOI18N
227  pagePreviousButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
228  pagePreviousButton.setBorderPainted(false);
229  pagePreviousButton.setContentAreaFilled(false);
230  pagePreviousButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_back_disabled.png"))); // NOI18N
231  pagePreviousButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
232 
233  pageCurLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
234  pageCurLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.pageCurLabel.text")); // NOI18N
235 
236  jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
237 
238  hitLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitLabel.text")); // NOI18N
239  hitLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitLabel.toolTipText")); // NOI18N
240 
241  hitButtonsLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitButtonsLabel.text")); // NOI18N
242 
243  hitNextButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_forward.png"))); // NOI18N
244  hitNextButton.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitNextButton.text")); // NOI18N
245  hitNextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
246  hitNextButton.setBorderPainted(false);
247  hitNextButton.setContentAreaFilled(false);
248  hitNextButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_disabled.png"))); // NOI18N
249  hitNextButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
250  hitNextButton.setPreferredSize(new java.awt.Dimension(23, 23));
251  hitNextButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_hover.png"))); // NOI18N
252 
253  hitOfLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitOfLabel.text")); // NOI18N
254 
255  hitTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
256  hitTotalLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitTotalLabel.text")); // NOI18N
257  hitTotalLabel.setMaximumSize(new java.awt.Dimension(18, 14));
258  hitTotalLabel.setMinimumSize(new java.awt.Dimension(18, 14));
259  hitTotalLabel.setPreferredSize(new java.awt.Dimension(18, 14));
260 
261  hitPreviousButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_back.png"))); // NOI18N
262  hitPreviousButton.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitPreviousButton.text")); // NOI18N
263  hitPreviousButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
264  hitPreviousButton.setBorderPainted(false);
265  hitPreviousButton.setContentAreaFilled(false);
266  hitPreviousButton.setDisabledIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_back_disabled.png"))); // NOI18N
267  hitPreviousButton.setMargin(new java.awt.Insets(2, 0, 2, 0));
268  hitPreviousButton.setPreferredSize(new java.awt.Dimension(23, 23));
269  hitPreviousButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/keywordsearch/btn_step_back_hover.png"))); // NOI18N
270 
271  hitCountLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
272  hitCountLabel.setText(org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class, "ExtractedContentPanel.hitCountLabel.text")); // NOI18N
273  hitCountLabel.setMaximumSize(new java.awt.Dimension(18, 14));
274  hitCountLabel.setMinimumSize(new java.awt.Dimension(18, 14));
275  hitCountLabel.setPreferredSize(new java.awt.Dimension(18, 14));
276 
277  jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
278 
279  javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
280  controlPanel.setLayout(controlPanelLayout);
281  controlPanelLayout.setHorizontalGroup(
282  controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283  .addGroup(controlPanelLayout.createSequentialGroup()
284  .addContainerGap()
285  .addComponent(hitLabel)
286  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
287  .addComponent(hitCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
288  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
289  .addComponent(hitOfLabel)
290  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
291  .addComponent(hitTotalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
292  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
293  .addComponent(hitButtonsLabel)
294  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
295  .addComponent(hitPreviousButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
296  .addGap(0, 0, 0)
297  .addComponent(hitNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
298  .addGap(18, 18, 18)
299  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
300  .addGap(18, 18, 18)
301  .addComponent(pagesLabel)
302  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
303  .addComponent(pageCurLabel)
304  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
305  .addComponent(pageOfLabel)
306  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307  .addComponent(pageTotalLabel)
308  .addGap(18, 18, 18)
309  .addComponent(pageButtonsLabel)
310  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311  .addComponent(pagePreviousButton)
312  .addGap(0, 0, 0)
313  .addComponent(pageNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
314  .addGap(18, 18, 18)
315  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
316  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
317  .addComponent(jLabel1)
318  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
319  .addComponent(sourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
320  .addContainerGap())
321  );
322  controlPanelLayout.setVerticalGroup(
323  controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
324  .addGroup(controlPanelLayout.createSequentialGroup()
325  .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
326  .addComponent(hitPreviousButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
327  .addComponent(jLabel1)
328  .addComponent(hitNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
329  .addComponent(pageButtonsLabel)
330  .addComponent(pagePreviousButton)
331  .addComponent(pageNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
332  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
333  .addComponent(sourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
334  .addComponent(pagesLabel)
335  .addComponent(hitLabel)
336  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
337  .addComponent(pageCurLabel)
338  .addComponent(pageOfLabel)
339  .addComponent(hitCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
340  .addComponent(pageTotalLabel)
341  .addComponent(hitOfLabel)
342  .addComponent(hitTotalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
343  .addComponent(hitButtonsLabel))
344  .addGap(0, 0, 0))
345  );
346 
347  controlPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {hitButtonsLabel, hitCountLabel, hitLabel, hitNextButton, hitOfLabel, hitPreviousButton, hitTotalLabel, jLabel1, jSeparator1, jSeparator2, pageButtonsLabel, pageCurLabel, pageNextButton, pageOfLabel, pagePreviousButton, pageTotalLabel, pagesLabel, sourceComboBox});
348 
349  controlScrollPane.setViewportView(controlPanel);
350 
351  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
352  this.setLayout(layout);
353  layout.setHorizontalGroup(
354  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
355  .addComponent(controlScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
356  .addComponent(extractedScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
357  );
358  layout.setVerticalGroup(
359  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
360  .addGroup(layout.createSequentialGroup()
361  .addComponent(controlScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
362  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
363  .addComponent(extractedScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
364  );
365  }// </editor-fold>//GEN-END:initComponents
366  // Variables declaration - do not modify//GEN-BEGIN:variables
367  private javax.swing.JPanel controlPanel;
368  private javax.swing.JScrollPane controlScrollPane;
369  private javax.swing.JMenuItem copyMenuItem;
370  private javax.swing.JScrollPane extractedScrollPane;
371  private javax.swing.JTextPane extractedTextPane;
372  private javax.swing.JLabel hitButtonsLabel;
373  private javax.swing.JLabel hitCountLabel;
374  private javax.swing.JLabel hitLabel;
375  private javax.swing.JButton hitNextButton;
376  private javax.swing.JLabel hitOfLabel;
377  private javax.swing.JButton hitPreviousButton;
378  private javax.swing.JLabel hitTotalLabel;
379  private javax.swing.JLabel jLabel1;
380  private javax.swing.JSeparator jSeparator1;
381  private javax.swing.JSeparator jSeparator2;
382  private javax.swing.JLabel pageButtonsLabel;
383  private javax.swing.JLabel pageCurLabel;
384  private javax.swing.JButton pageNextButton;
385  private javax.swing.JLabel pageOfLabel;
386  private javax.swing.JButton pagePreviousButton;
387  private javax.swing.JLabel pageTotalLabel;
388  private javax.swing.JLabel pagesLabel;
389  private javax.swing.JPopupMenu rightClickMenu;
390  private javax.swing.JMenuItem selectAllMenuItem;
391  private javax.swing.JComboBox<org.sleuthkit.autopsy.keywordsearch.IndexedText> sourceComboBox;
392  // End of variables declaration//GEN-END:variables
393 
394  void refreshCurrentMarkup() {
395  setMarkup(getSelectedSource());
396  }
397 
406  final void setSources(String contentName, List<IndexedText> sources) {
407  this.contentName = contentName;
408  setPanelText(null, false);
409 
410  sourceComboBox.removeAllItems();
411  sources.forEach(sourceComboBox::addItem);
412  if (false == sources.isEmpty()) {
413  sourceComboBox.setEnabled(true);
414  sourceComboBox.setSelectedIndex(0);
415  } else {
416  sourceComboBox.setEnabled(false);
417  }
418  }
419 
425  public IndexedText getSelectedSource() {
426  return (IndexedText) sourceComboBox.getSelectedItem();
427  }
428 
429  private void setPanelText(String text, boolean detectDirection) {
430  String safeText = StringUtils.defaultString(text);
431 
432  if (detectDirection) {
433  //detect text direction using first 1024 chars and set it
434  //get first up to 1024 chars, strip <pre> tag and unescape html to get the string on which to detect
435  final int len = safeText.length();
436  final int prefixLen = "<pre>".length(); //NON-NLS
437  if (len > prefixLen) {
438  final int maxOrientChars = Math.min(len, 1024);
439  final String orientDetectText = EscapeUtil.unEscapeHtml(safeText.substring(prefixLen, maxOrientChars));
440  ComponentOrientation direction = TextUtil.getTextDirection(orientDetectText);
441  extractedTextPane.applyComponentOrientation(direction);
442  } else {
443  extractedTextPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
444  }
445  } else {
446  extractedTextPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
447  }
448 
449  extractedTextPane.setText(safeText);
450  extractedTextPane.setCaretPosition(0);
451  }
452 
453  void scrollToAnchor(String anchor) {
454  extractedTextPane.scrollToReference(anchor);
455  }
456 
462  void updateCurrentMatchDisplay(int current) {
463  if (current == 0) {
464  hitCountLabel.setText("-");
465  } else {
466  hitCountLabel.setText(Integer.toString(current));
467  }
468  }
469 
475  void updateTotaMatcheslDisplay(int total) {
476  if (total == 0) {
477  hitTotalLabel.setText("-");
478  } else {
479  hitTotalLabel.setText(Integer.toString(total));
480  }
481  }
482 
488  void updateCurrentPageDisplay(int current) {
489  pageCurLabel.setText(Integer.toString(current));
490  }
491 
497  void updateTotalPagesDisplay(int total) {
498  pageTotalLabel.setText(Integer.toString(total));
499  }
500 
505  void resetDisplay() {
506  setSources("", new ArrayList<>());
507  hitTotalLabel.setText("-");
508  hitCountLabel.setText("-");
509  pageCurLabel.setText("-");
510  pageTotalLabel.setText("-");
511  }
512 
518  void enablePrevMatchControl(boolean enable) {
519  hitPreviousButton.setEnabled(enable);
520  }
521 
527  void enableNextMatchControl(boolean enable) {
528  hitNextButton.setEnabled(enable);
529  }
530 
531  void addPrevMatchControlListener(ActionListener l) {
532  hitPreviousButton.addActionListener(l);
533  }
534 
535  void addNextMatchControlListener(ActionListener l) {
536  hitNextButton.addActionListener(l);
537  }
538 
544  void enablePrevPageControl(boolean enable) {
545  pagePreviousButton.setEnabled(enable);
546  }
547 
553  void enableNextPageControl(boolean enable) {
554  pageNextButton.setEnabled(enable);
555  }
556 
557  void addPrevPageControlListener(ActionListener l) {
558  pagePreviousButton.addActionListener(l);
559  }
560 
561  void addNextPageControlListener(ActionListener l) {
562  pageNextButton.addActionListener(l);
563  }
564 
565  void addSourceComboControlListener(ActionListener l) {
566  sourceComboBox.addActionListener(l);
567  }
568 
574  void updateControls(IndexedText source) {
575  updatePageControls(source);
576  updateSearchControls(source);
577  }
578 
584  void updatePageControls(IndexedText source) {
585  if (source == null) {
586  enableNextPageControl(false);
587  enablePrevPageControl(false);
588  updateCurrentPageDisplay(0);
589  updateTotalPagesDisplay(0);
590  return;
591  }
592 
593  updateCurrentPageDisplay(source.getCurrentPage());
594  int totalPages = source.getNumberPages();
595  updateTotalPagesDisplay(totalPages);
596 
597  if (totalPages < 2) {
598  enableNextPageControl(false);
599  enablePrevPageControl(false);
600  } else {
601  enableNextPageControl(source.hasNextPage());
602  enablePrevPageControl(source.hasPreviousPage());
603  }
604  }
605 
611  void updateSearchControls(IndexedText source) {
612  //setup search controls
613  if (source != null && source.isSearchable()) {
614  updateCurrentMatchDisplay(source.currentItem());
615  updateTotaMatcheslDisplay(source.getNumberHits());
616  enableNextMatchControl(source.hasNextItem() || source.hasNextPage());
617  enablePrevMatchControl(source.hasPreviousItem() || source.hasPreviousPage());
618  } else {
619  enableNextMatchControl(false);
620  enablePrevMatchControl(false);
621  updateCurrentMatchDisplay(0);
622  updateTotaMatcheslDisplay(0);
623  }
624  }
625 
631  private void scrollToCurrentHit(final IndexedText source) {
632  if (source == null || !source.isSearchable()) {
633  return;
634  }
635 
636  //scrolling required invokeLater to enqueue in EDT
637  EventQueue.invokeLater(() -> scrollToAnchor(source.getAnchorPrefix() + source.currentItem()));
638 
639  }
640 
646  @NbBundle.Messages("ExtractedContentPanel.setMarkup.panelTxt=<span style='font-style:italic'>Loading text... Please wait</span>")
647  private void setMarkup(IndexedText source) {
648  setPanelText(Bundle.ExtractedContentPanel_setMarkup_panelTxt(), false);
649  new SetMarkupWorker(contentName, source).execute();
650  }
651 
657  private final class SetMarkupWorker extends SwingWorker<String, Void> {
658 
659  private final String contentName;
660 
661  private final IndexedText source;
662 
663  private ProgressHandle progress;
664 
665  SetMarkupWorker(String contentName, IndexedText source) {
666  this.contentName = contentName;
667  this.source = source;
668  }
669 
670  @Override
671  @NbBundle.Messages({"# {0} - Content name",
672  "ExtractedContentPanel.SetMarkup.progress.loading=Loading text for {0}"})
673  protected String doInBackground() throws Exception {
674  progress = ProgressHandle.createHandle(Bundle.ExtractedContentPanel_SetMarkup_progress_loading(contentName));
675  progress.start();
676  progress.switchToIndeterminate();
677 
678  return source.getText();
679  }
680 
681  @Override
682  protected void done() {
683  super.done();
684  progress.finish();
685 
686  // see if there are any errors
687  try {
688  String markup = get();
689  if (markup != null) {
690  setPanelText(markup, true);
691  } else {
692  setPanelText("", false);
693  }
694  } catch (InterruptedException | CancellationException | ExecutionException ex) {
695  logger.log(Level.SEVERE, "Error getting marked up text", ex); //NON-NLS
696  setPanelText(Bundle.IndexedText_errorMessage_errorGettingText(), true);
697  }
698 
699  updateControls(source);
700  scrollToCurrentHit(source);
701  }
702  }
703 }

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