19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.ComponentOrientation;
22 import java.awt.EventQueue;
24 import java.awt.event.ActionListener;
25 import java.awt.event.ItemEvent;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.concurrent.CancellationException;
29 import java.util.concurrent.ExecutionException;
30 import java.util.logging.Level;
31 import javax.swing.JLabel;
32 import javax.swing.SizeRequirements;
33 import javax.swing.SwingUtilities;
34 import javax.swing.SwingWorker;
35 import javax.swing.text.Element;
36 import javax.swing.text.View;
37 import javax.swing.text.ViewFactory;
38 import javax.swing.text.html.HTMLEditorKit;
39 import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
40 import javax.swing.text.html.InlineView;
41 import javax.swing.text.html.ParagraphView;
42 import javax.swing.text.html.StyleSheet;
43 import org.apache.commons.lang3.StringUtils;
44 import org.netbeans.api.progress.ProgressHandle;
45 import org.openide.util.NbBundle;
54 @SuppressWarnings(
"PMD.SingularField")
55 class ExtractedContentPanel extends javax.swing.JPanel implements ResizableTextPanel {
57 private static final Logger logger = Logger.getLogger(ExtractedContentPanel.class.getName());
60 private static final Font DEFAULT_FONT =
new JLabel().getFont();
62 private static final long serialVersionUID = 1L;
63 private String contentName;
66 private final StyleSheet styleSheet;
67 private final HTMLEditorKit editorKit;
68 private String lastKnownAnchor = null;
70 ExtractedContentPanel() {
72 setSources(
"",
new ArrayList<>());
73 hitPreviousButton.setEnabled(
false);
74 hitNextButton.setEnabled(
false);
81 editorKit =
new HTMLEditorKit() {
82 private static final long serialVersionUID = 1L;
85 public ViewFactory getViewFactory() {
87 return new HTMLFactory() {
89 public View create(Element e) {
90 View v = super.create(e);
91 if (v instanceof InlineView) {
92 return new InlineView(e) {
94 public int getBreakWeight(
int axis,
float pos,
float len) {
95 return GoodBreakWeight;
99 public View breakView(
int axis,
int p0,
float pos,
float len) {
100 if (axis == View.X_AXIS) {
102 int p1 = getGlyphPainter().getBoundedPosition(
this, p0, pos, len);
103 if (p0 == getStartOffset() && p1 == getEndOffset()) {
106 return createFragment(p0, p1);
111 }
else if (v instanceof ParagraphView) {
112 return new ParagraphView(e) {
114 protected SizeRequirements calculateMinorAxisRequirements(
int axis, SizeRequirements r) {
115 SizeRequirements requirements = r;
116 if (requirements == null) {
117 requirements =
new SizeRequirements();
119 float pref = layoutPool.getPreferredSpan(axis);
120 float min = layoutPool.getMinimumSpan(axis);
122 requirements.minimum = (int) min;
123 requirements.preferred = Math.max(requirements.minimum, (
int) pref);
124 requirements.maximum = Integer.MAX_VALUE;
125 requirements.alignment = 0.5f;
136 styleSheet = editorKit.getStyleSheet();
138 sourceComboBox.addItemListener(itemEvent -> {
139 if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
140 refreshCurrentMarkup();
143 extractedTextPane.setComponentPopupMenu(rightClickMenu);
144 copyMenuItem.addActionListener(actionEvent -> extractedTextPane.copy());
145 selectAllMenuItem.addActionListener(actionEvent -> extractedTextPane.selectAll());
152 SwingUtilities.invokeLater(() -> {
153 if (zoomPanel instanceof TextZoomPanel)
154 ((TextZoomPanel) this.zoomPanel).resetSize();
159 private void setStyleSheetSize(StyleSheet styleSheet,
int size) {
160 styleSheet.addRule(
"body {font-family:\"" + DEFAULT_FONT.getFamily() +
"\"; font-size:" + size +
"pt; } ");
165 public int getTextSize() {
170 public void setTextSize(
int newSize) {
173 String curText = extractedTextPane.getText();
175 setStyleSheetSize(styleSheet, curSize);
177 editorKit.setStyleSheet(styleSheet);
178 extractedTextPane.setEditorKit(editorKit);
180 extractedTextPane.setText(curText);
181 if (lastKnownAnchor != null)
182 scrollToAnchor(lastKnownAnchor);
194 @SuppressWarnings(
"unchecked")
196 private
void initComponents() {
198 rightClickMenu =
new javax.swing.JPopupMenu();
199 copyMenuItem =
new javax.swing.JMenuItem();
200 selectAllMenuItem =
new javax.swing.JMenuItem();
201 extractedScrollPane =
new javax.swing.JScrollPane();
202 extractedTextPane =
new javax.swing.JTextPane();
203 controlScrollPane =
new javax.swing.JScrollPane();
204 controlPanel =
new javax.swing.JPanel();
205 sourceComboBox =
new javax.swing.JComboBox<>();
206 jLabel1 =
new javax.swing.JLabel();
207 pageOfLabel =
new javax.swing.JLabel();
208 pageButtonsLabel =
new javax.swing.JLabel();
209 pageTotalLabel =
new javax.swing.JLabel();
210 pagesLabel =
new javax.swing.JLabel();
211 pageNextButton =
new javax.swing.JButton();
212 pagePreviousButton =
new javax.swing.JButton();
213 pageCurLabel =
new javax.swing.JLabel();
214 hitLabel =
new javax.swing.JLabel();
215 hitButtonsLabel =
new javax.swing.JLabel();
216 hitNextButton =
new javax.swing.JButton();
217 hitOfLabel =
new javax.swing.JLabel();
218 hitTotalLabel =
new javax.swing.JLabel();
219 hitPreviousButton =
new javax.swing.JButton();
220 hitCountLabel =
new javax.swing.JLabel();
221 jSeparator2 =
new javax.swing.JSeparator();
222 jSeparator3 =
new javax.swing.JSeparator();
223 zoomPanel =
new TextZoomPanel(
this);
225 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.copyMenuItem.text"));
226 rightClickMenu.add(copyMenuItem);
228 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.selectAllMenuItem.text"));
229 rightClickMenu.add(selectAllMenuItem);
231 setMinimumSize(
new java.awt.Dimension(100, 0));
232 setPreferredSize(
new java.awt.Dimension(100, 58));
234 extractedScrollPane.setBackground(
new java.awt.Color(255, 255, 255));
235 extractedScrollPane.setPreferredSize(
new java.awt.Dimension(640, 29));
237 extractedTextPane.setEditable(
false);
238 extractedTextPane.setAutoscrolls(
false);
239 extractedTextPane.setInheritsPopupMenu(
true);
240 extractedTextPane.setMaximumSize(
new java.awt.Dimension(2000, 2000));
241 extractedTextPane.setPreferredSize(
new java.awt.Dimension(600, 29));
242 extractedScrollPane.setViewportView(extractedTextPane);
244 controlScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
245 controlScrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
246 controlScrollPane.setPreferredSize(
new java.awt.Dimension(600, 100));
248 controlPanel.setMinimumSize(
new java.awt.Dimension(0, 20));
249 controlPanel.setPreferredSize(
new java.awt.Dimension(600, 81));
252 sourceComboBox.setMaximumSize(
new java.awt.Dimension(150, 32767));
253 sourceComboBox.setMinimumSize(
new java.awt.Dimension(150, 20));
254 sourceComboBox.setPreferredSize(
new java.awt.Dimension(150, 20));
256 jLabel1.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.jLabel1.text"));
258 pageOfLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageOfLabel.text"));
260 pageButtonsLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageButtonsLabel.text"));
262 pageTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
263 pageTotalLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageTotalLabel.text"));
265 pagesLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pagesLabel.text"));
267 pageNextButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward.png")));
268 pageNextButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageNextButton.text"));
269 pageNextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
270 pageNextButton.setBorderPainted(
false);
271 pageNextButton.setContentAreaFilled(
false);
272 pageNextButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_disabled.png")));
273 pageNextButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
274 pageNextButton.setPreferredSize(
new java.awt.Dimension(23, 23));
276 pagePreviousButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back.png")));
277 pagePreviousButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pagePreviousButton.text"));
278 pagePreviousButton.setActionCommand(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pagePreviousButton.actionCommand"));
279 pagePreviousButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
280 pagePreviousButton.setBorderPainted(
false);
281 pagePreviousButton.setContentAreaFilled(
false);
282 pagePreviousButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back_disabled.png")));
283 pagePreviousButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
285 pageCurLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
286 pageCurLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageCurLabel.text"));
288 hitLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitLabel.text"));
289 hitLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitLabel.toolTipText"));
291 hitButtonsLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitButtonsLabel.text"));
293 hitNextButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward.png")));
294 hitNextButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitNextButton.text"));
295 hitNextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
296 hitNextButton.setBorderPainted(
false);
297 hitNextButton.setContentAreaFilled(
false);
298 hitNextButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_disabled.png")));
299 hitNextButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
300 hitNextButton.setPreferredSize(
new java.awt.Dimension(23, 23));
301 hitNextButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_hover.png")));
303 hitOfLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitOfLabel.text"));
305 hitTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
306 hitTotalLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitTotalLabel.text"));
307 hitTotalLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
308 hitTotalLabel.setMinimumSize(
new java.awt.Dimension(18, 14));
309 hitTotalLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
311 hitPreviousButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back.png")));
312 hitPreviousButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitPreviousButton.text"));
313 hitPreviousButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
314 hitPreviousButton.setBorderPainted(
false);
315 hitPreviousButton.setContentAreaFilled(
false);
316 hitPreviousButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back_disabled.png")));
317 hitPreviousButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
318 hitPreviousButton.setPreferredSize(
new java.awt.Dimension(23, 23));
319 hitPreviousButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back_hover.png")));
321 hitCountLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
322 hitCountLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitCountLabel.text"));
323 hitCountLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
324 hitCountLabel.setMinimumSize(
new java.awt.Dimension(18, 14));
325 hitCountLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
327 jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
329 jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
331 zoomPanel.setMinimumSize(
new java.awt.Dimension(150, 20));
332 zoomPanel.setName(
"");
333 zoomPanel.setPreferredSize(
new java.awt.Dimension(200, 20));
335 javax.swing.GroupLayout controlPanelLayout =
new javax.swing.GroupLayout(controlPanel);
336 controlPanel.setLayout(controlPanelLayout);
337 controlPanelLayout.setHorizontalGroup(
338 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
339 .addGroup(controlPanelLayout.createSequentialGroup()
341 .addComponent(hitLabel)
342 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
343 .addComponent(hitCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
344 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
345 .addComponent(hitOfLabel)
346 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
347 .addComponent(hitTotalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
348 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
349 .addComponent(hitButtonsLabel)
350 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
351 .addComponent(hitPreviousButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
353 .addComponent(hitNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
355 .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
357 .addComponent(pagesLabel)
358 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
359 .addComponent(pageCurLabel)
360 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
361 .addComponent(pageOfLabel)
362 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
363 .addComponent(pageTotalLabel)
365 .addComponent(pageButtonsLabel)
366 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
367 .addComponent(pagePreviousButton)
369 .addComponent(pageNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
371 .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
373 .addComponent(zoomPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
374 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
375 .addComponent(jLabel1)
376 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
377 .addComponent(sourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
380 controlPanelLayout.setVerticalGroup(
381 controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
382 .addGroup(controlPanelLayout.createSequentialGroup()
383 .addGroup(controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
384 .addComponent(hitPreviousButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
385 .addComponent(jLabel1)
386 .addComponent(hitNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
387 .addComponent(pageButtonsLabel)
388 .addComponent(pagePreviousButton)
389 .addComponent(pageNextButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
390 .addComponent(sourceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
391 .addComponent(pagesLabel)
392 .addComponent(hitLabel)
393 .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
394 .addComponent(pageCurLabel)
395 .addComponent(pageOfLabel)
396 .addComponent(hitCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
397 .addComponent(pageTotalLabel)
398 .addComponent(hitOfLabel)
399 .addComponent(hitTotalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
400 .addComponent(hitButtonsLabel)
401 .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
402 .addComponent(zoomPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
406 controlPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL,
new java.awt.Component[] {hitButtonsLabel, hitCountLabel, hitLabel, hitNextButton, hitOfLabel, hitPreviousButton, hitTotalLabel, jLabel1, jSeparator2, jSeparator3, pageButtonsLabel, pageCurLabel, pageNextButton, pageOfLabel, pagePreviousButton, pageTotalLabel, pagesLabel, sourceComboBox, zoomPanel});
408 zoomPanel.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.AccessibleContext.accessibleName"));
410 controlScrollPane.setViewportView(controlPanel);
412 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
413 this.setLayout(layout);
414 layout.setHorizontalGroup(
415 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
416 .addComponent(controlScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 980, Short.MAX_VALUE)
417 .addComponent(extractedScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 980, Short.MAX_VALUE)
419 layout.setVerticalGroup(
420 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
421 .addGroup(layout.createSequentialGroup()
422 .addComponent(controlScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
423 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
424 .addComponent(extractedScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
428 private javax.swing.JPanel controlPanel;
429 private javax.swing.JScrollPane controlScrollPane;
430 private javax.swing.JMenuItem copyMenuItem;
431 private javax.swing.JScrollPane extractedScrollPane;
432 private javax.swing.JTextPane extractedTextPane;
433 private javax.swing.JLabel hitButtonsLabel;
434 private javax.swing.JLabel hitCountLabel;
435 private javax.swing.JLabel hitLabel;
436 private javax.swing.JButton hitNextButton;
437 private javax.swing.JLabel hitOfLabel;
438 private javax.swing.JButton hitPreviousButton;
439 private javax.swing.JLabel hitTotalLabel;
440 private javax.swing.JLabel jLabel1;
441 private javax.swing.JSeparator jSeparator2;
442 private javax.swing.JSeparator jSeparator3;
443 private javax.swing.JLabel pageButtonsLabel;
444 private javax.swing.JLabel pageCurLabel;
445 private javax.swing.JButton pageNextButton;
446 private javax.swing.JLabel pageOfLabel;
447 private javax.swing.JButton pagePreviousButton;
448 private javax.swing.JLabel pageTotalLabel;
449 private javax.swing.JLabel pagesLabel;
450 private javax.swing.JPopupMenu rightClickMenu;
451 private javax.swing.JMenuItem selectAllMenuItem;
453 private javax.swing.JPanel zoomPanel;
456 void refreshCurrentMarkup() {
457 setMarkup(getSelectedSource());
468 final void setSources(String contentName, List<IndexedText> sources) {
469 this.lastKnownAnchor = null;
470 this.contentName = contentName;
471 setPanelText(null,
false);
473 sourceComboBox.removeAllItems();
474 sources.forEach(sourceComboBox::addItem);
475 if (
false == sources.isEmpty()) {
476 sourceComboBox.setEnabled(
true);
477 sourceComboBox.setSelectedIndex(0);
479 sourceComboBox.setEnabled(
false);
488 public IndexedText getSelectedSource() {
489 return (IndexedText) sourceComboBox.getSelectedItem();
492 private void setPanelText(String text,
boolean detectDirection) {
493 String safeText = StringUtils.defaultString(text);
495 if (detectDirection) {
498 final int len = safeText.length();
499 final int prefixLen =
"<pre>".length();
500 if (len > prefixLen) {
501 final int maxOrientChars = Math.min(len, 1024);
502 final String orientDetectText = EscapeUtil.unEscapeHtml(safeText.substring(prefixLen, maxOrientChars));
503 ComponentOrientation direction = TextUtil.getTextDirection(orientDetectText);
504 extractedTextPane.applyComponentOrientation(direction);
506 extractedTextPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
509 extractedTextPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
512 extractedTextPane.setText(safeText);
513 extractedTextPane.setCaretPosition(0);
516 void scrollToAnchor(String anchor) {
517 lastKnownAnchor = anchor;
518 extractedTextPane.scrollToReference(anchor);
526 void updateCurrentMatchDisplay(
int current) {
528 hitCountLabel.setText(
"-");
530 hitCountLabel.setText(Integer.toString(current));
539 void updateTotaMatcheslDisplay(
int total) {
541 hitTotalLabel.setText(
"-");
543 hitTotalLabel.setText(Integer.toString(total));
552 void updateCurrentPageDisplay(
int current) {
553 pageCurLabel.setText(Integer.toString(current));
561 void updateTotalPagesDisplay(
int total) {
562 pageTotalLabel.setText(Integer.toString(total));
569 void resetDisplay() {
570 setSources(
"",
new ArrayList<>());
571 hitTotalLabel.setText(
"-");
572 hitCountLabel.setText(
"-");
573 pageCurLabel.setText(
"-");
574 pageTotalLabel.setText(
"-");
582 void enablePrevMatchControl(
boolean enable) {
583 hitPreviousButton.setEnabled(enable);
591 void enableNextMatchControl(
boolean enable) {
592 hitNextButton.setEnabled(enable);
595 void addPrevMatchControlListener(ActionListener l) {
596 hitPreviousButton.addActionListener(l);
599 void addNextMatchControlListener(ActionListener l) {
600 hitNextButton.addActionListener(l);
608 void enablePrevPageControl(
boolean enable) {
609 pagePreviousButton.setEnabled(enable);
617 void enableNextPageControl(
boolean enable) {
618 pageNextButton.setEnabled(enable);
621 void addPrevPageControlListener(ActionListener l) {
622 pagePreviousButton.addActionListener(l);
625 void addNextPageControlListener(ActionListener l) {
626 pageNextButton.addActionListener(l);
629 void addSourceComboControlListener(ActionListener l) {
630 sourceComboBox.addActionListener(l);
638 void updateControls(IndexedText source) {
639 updatePageControls(source);
640 updateSearchControls(source);
648 void updatePageControls(IndexedText source) {
649 if (source == null) {
650 enableNextPageControl(
false);
651 enablePrevPageControl(
false);
652 updateCurrentPageDisplay(0);
653 updateTotalPagesDisplay(0);
657 updateCurrentPageDisplay(source.getCurrentPage());
658 int totalPages = source.getNumberPages();
659 updateTotalPagesDisplay(totalPages);
661 if (totalPages < 2) {
662 enableNextPageControl(
false);
663 enablePrevPageControl(
false);
665 enableNextPageControl(source.hasNextPage());
666 enablePrevPageControl(source.hasPreviousPage());
675 void updateSearchControls(IndexedText source) {
677 if (source != null && source.isSearchable()) {
678 updateCurrentMatchDisplay(source.currentItem());
679 updateTotaMatcheslDisplay(source.getNumberHits());
680 enableNextMatchControl(source.hasNextItem() || source.hasNextPage());
681 enablePrevMatchControl(source.hasPreviousItem() || source.hasPreviousPage());
683 enableNextMatchControl(
false);
684 enablePrevMatchControl(
false);
685 updateCurrentMatchDisplay(0);
686 updateTotaMatcheslDisplay(0);
695 private void scrollToCurrentHit(
final IndexedText source) {
696 if (source == null || !source.isSearchable()) {
701 EventQueue.invokeLater(() -> scrollToAnchor(source.getAnchorPrefix() + source.currentItem()));
710 @NbBundle.Messages(
"ExtractedContentPanel.setMarkup.panelTxt=<span style='font-style:italic'>Loading text... Please wait</span>")
711 private void setMarkup(IndexedText source) {
712 setPanelText(Bundle.ExtractedContentPanel_setMarkup_panelTxt(),
false);
713 new SetMarkupWorker(contentName, source).execute();
730 this.contentName = contentName;
731 this.source = source;
735 @NbBundle.Messages({
"# {0} - Content name",
736 "ExtractedContentPanel.SetMarkup.progress.loading=Loading text for {0}"})
738 progress = ProgressHandle.createHandle(Bundle.ExtractedContentPanel_SetMarkup_progress_loading(contentName));
740 progress.switchToIndeterminate();
742 return source.getText();
752 String markup =
get();
753 if (markup != null) {
754 setPanelText(markup,
true);
756 setPanelText(
"",
false);
758 }
catch (InterruptedException | CancellationException | ExecutionException ex) {
759 logger.log(Level.SEVERE,
"Error getting marked up text", ex);
760 setPanelText(Bundle.IndexedText_errorMessage_errorGettingText(),
true);
763 updateControls(source);
764 scrollToCurrentHit(source);