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.Arrays;
28 import java.util.List;
29 import java.util.concurrent.CancellationException;
30 import java.util.concurrent.ExecutionException;
31 import java.util.logging.Level;
32 import javax.swing.JLabel;
33 import javax.swing.SizeRequirements;
34 import javax.swing.SwingUtilities;
35 import javax.swing.SwingWorker;
36 import javax.swing.text.Element;
37 import javax.swing.text.View;
38 import javax.swing.text.ViewFactory;
39 import javax.swing.text.html.HTMLEditorKit;
40 import javax.swing.text.html.HTMLEditorKit.HTMLFactory;
41 import javax.swing.text.html.InlineView;
42 import javax.swing.text.html.ParagraphView;
43 import javax.swing.text.html.StyleSheet;
44 import org.apache.commons.lang3.StringUtils;
45 import org.netbeans.api.progress.ProgressHandle;
46 import org.openide.util.NbBundle;
56 @SuppressWarnings(
"PMD.SingularField")
57 class ExtractedContentPanel extends javax.swing.JPanel implements ResizableTextPanel {
59 private static final Logger logger = Logger.getLogger(ExtractedContentPanel.class.getName());
62 private static final Font DEFAULT_FONT =
new JLabel().getFont();
64 private static final long serialVersionUID = 1L;
65 private String contentName;
68 private final StyleSheet styleSheet;
69 private final HTMLEditorKit editorKit;
70 private String lastKnownAnchor = null;
72 ExtractedContentPanel() {
75 setSources(
"",
new ArrayList<>());
76 hitPreviousButton.setEnabled(
false);
77 hitNextButton.setEnabled(
false);
84 editorKit =
new HTMLEditorKit() {
85 private static final long serialVersionUID = 1L;
88 public ViewFactory getViewFactory() {
90 return new HTMLFactory() {
92 public View create(Element e) {
93 View v = super.create(e);
94 if (v instanceof InlineView) {
95 return new InlineView(e) {
97 public int getBreakWeight(
int axis,
float pos,
float len) {
98 return GoodBreakWeight;
102 public View breakView(
int axis,
int p0,
float pos,
float len) {
103 if (axis == View.X_AXIS) {
105 int p1 = getGlyphPainter().getBoundedPosition(
this, p0, pos, len);
106 if (p0 == getStartOffset() && p1 == getEndOffset()) {
109 return createFragment(p0, p1);
114 }
else if (v instanceof ParagraphView) {
115 return new ParagraphView(e) {
117 protected SizeRequirements calculateMinorAxisRequirements(
int axis, SizeRequirements r) {
118 SizeRequirements requirements = r;
119 if (requirements == null) {
120 requirements =
new SizeRequirements();
122 float pref = layoutPool.getPreferredSpan(axis);
123 float min = layoutPool.getMinimumSpan(axis);
125 requirements.minimum = (int) min;
126 requirements.preferred = Math.max(requirements.minimum, (
int) pref);
127 requirements.maximum = Integer.MAX_VALUE;
128 requirements.alignment = 0.5f;
139 styleSheet = editorKit.getStyleSheet();
141 sourceComboBox.addItemListener(itemEvent -> {
142 if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
143 refreshCurrentMarkup();
146 extractedTextPane.setComponentPopupMenu(rightClickMenu);
147 copyMenuItem.addActionListener(actionEvent -> extractedTextPane.copy());
148 selectAllMenuItem.addActionListener(actionEvent -> extractedTextPane.selectAll());
155 SwingUtilities.invokeLater(() -> {
156 if (zoomPanel instanceof TextZoomPanel)
157 ((TextZoomPanel) this.zoomPanel).resetSize();
162 private void setStyleSheetSize(StyleSheet styleSheet,
int size) {
163 styleSheet.addRule(
"body {font-family:\"" + DEFAULT_FONT.getFamily() +
"\"; font-size:" + size +
"pt; } ");
168 public int getTextSize() {
173 public void setTextSize(
int newSize) {
176 String curText = extractedTextPane.getText();
178 setStyleSheetSize(styleSheet, curSize);
180 editorKit.setStyleSheet(styleSheet);
181 extractedTextPane.setEditorKit(editorKit);
183 extractedTextPane.setText(curText);
184 if (lastKnownAnchor != null)
185 scrollToAnchor(lastKnownAnchor);
189 private void additionalInit() {
191 WrapLayout layout =
new WrapLayout(0,5);
192 layout.setOppositeAligned(Arrays.asList(textSourcePanel));
193 controlPanel.setLayout(layout);
202 @SuppressWarnings(
"unchecked")
204 private
void initComponents() {
206 rightClickMenu =
new javax.swing.JPopupMenu();
207 copyMenuItem =
new javax.swing.JMenuItem();
208 selectAllMenuItem =
new javax.swing.JMenuItem();
209 controlPanel =
new javax.swing.JPanel();
210 javax.swing.JPanel pagePanel =
new javax.swing.JPanel();
211 pagesLabel =
new javax.swing.JLabel();
212 javax.swing.Box.Filler fillerSmall1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
213 pageCurLabel =
new javax.swing.JLabel();
214 javax.swing.Box.Filler fillerSmall2 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
215 pageOfLabel =
new javax.swing.JLabel();
216 javax.swing.Box.Filler fillerSmall3 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
217 pageTotalLabel =
new javax.swing.JLabel();
218 javax.swing.Box.Filler fillerSmall4 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
219 pageButtonsLabel =
new javax.swing.JLabel();
220 javax.swing.Box.Filler fillerMed1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(10, 0),
new java.awt.Dimension(10, 0),
new java.awt.Dimension(10, 32767));
221 pagePreviousButton =
new javax.swing.JButton();
222 pageNextButton =
new javax.swing.JButton();
223 javax.swing.Box.Filler fillerSmall6 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
224 jSeparator2 =
new javax.swing.JSeparator();
225 javax.swing.JPanel matchesPanel =
new javax.swing.JPanel();
226 hitLabel =
new javax.swing.JLabel();
227 hitCountLabel =
new javax.swing.JLabel();
228 hitOfLabel =
new javax.swing.JLabel();
229 hitTotalLabel =
new javax.swing.JLabel();
230 hitButtonsLabel =
new javax.swing.JLabel();
231 javax.swing.Box.Filler fillerMed2 =
new javax.swing.Box.Filler(
new java.awt.Dimension(10, 0),
new java.awt.Dimension(10, 0),
new java.awt.Dimension(10, 32767));
232 hitPreviousButton =
new javax.swing.JButton();
233 hitNextButton =
new javax.swing.JButton();
234 javax.swing.Box.Filler fillerSmall11 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
235 jSeparator3 =
new javax.swing.JSeparator();
236 javax.swing.JPanel zoomPanelWrapper =
new javax.swing.JPanel();
237 zoomPanel =
new TextZoomPanel(
this);
238 javax.swing.Box.Filler fillerSmall14 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
239 jSeparator4 =
new javax.swing.JSeparator();
240 textSourcePanel =
new javax.swing.JPanel();
241 jLabel1 =
new javax.swing.JLabel();
242 javax.swing.Box.Filler fillerSmall12 =
new javax.swing.Box.Filler(
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 0),
new java.awt.Dimension(5, 32767));
243 sourceComboBox =
new javax.swing.JComboBox<>();
244 extractedScrollPane =
new javax.swing.JScrollPane();
245 extractedTextPane =
new javax.swing.JTextPane();
247 copyMenuItem.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.copyMenuItem.text"));
248 rightClickMenu.add(copyMenuItem);
250 selectAllMenuItem.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.selectAllMenuItem.text"));
251 rightClickMenu.add(selectAllMenuItem);
253 setMinimumSize(
new java.awt.Dimension(250, 0));
254 setPreferredSize(
new java.awt.Dimension(250, 58));
255 setLayout(
new java.awt.BorderLayout());
257 controlPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
259 pagePanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
261 pagesLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pagesLabel.text"));
262 pagePanel.add(pagesLabel);
263 pagePanel.add(fillerSmall1);
265 pageCurLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
266 pageCurLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageCurLabel.text"));
267 pagePanel.add(pageCurLabel);
268 pagePanel.add(fillerSmall2);
270 pageOfLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageOfLabel.text"));
271 pagePanel.add(pageOfLabel);
272 pagePanel.add(fillerSmall3);
274 pageTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
275 pageTotalLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageTotalLabel.text"));
276 pagePanel.add(pageTotalLabel);
277 pagePanel.add(fillerSmall4);
279 pageButtonsLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageButtonsLabel.text"));
280 pagePanel.add(pageButtonsLabel);
281 pagePanel.add(fillerMed1);
283 pagePreviousButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back.png")));
284 pagePreviousButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pagePreviousButton.text"));
285 pagePreviousButton.setActionCommand(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pagePreviousButton.actionCommand"));
286 pagePreviousButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
287 pagePreviousButton.setBorderPainted(
false);
288 pagePreviousButton.setContentAreaFilled(
false);
289 pagePreviousButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back_disabled.png")));
290 pagePreviousButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
291 pagePanel.add(pagePreviousButton);
293 pageNextButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward.png")));
294 pageNextButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.pageNextButton.text"));
295 pageNextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
296 pageNextButton.setBorderPainted(
false);
297 pageNextButton.setContentAreaFilled(
false);
298 pageNextButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_disabled.png")));
299 pageNextButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
300 pageNextButton.setPreferredSize(
new java.awt.Dimension(23, 23));
301 pagePanel.add(pageNextButton);
302 pagePanel.add(fillerSmall6);
304 jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);
305 jSeparator2.setMaximumSize(
new java.awt.Dimension(2, 25));
306 jSeparator2.setMinimumSize(
new java.awt.Dimension(2, 25));
307 jSeparator2.setPreferredSize(
new java.awt.Dimension(2, 25));
308 pagePanel.add(jSeparator2);
310 controlPanel.add(pagePanel);
312 matchesPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
314 hitLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitLabel.text"));
315 hitLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitLabel.toolTipText"));
316 matchesPanel.add(hitLabel);
318 hitCountLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
319 hitCountLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitCountLabel.text"));
320 hitCountLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
321 hitCountLabel.setMinimumSize(
new java.awt.Dimension(18, 14));
322 hitCountLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
323 matchesPanel.add(hitCountLabel);
325 hitOfLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitOfLabel.text"));
326 matchesPanel.add(hitOfLabel);
328 hitTotalLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
329 hitTotalLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitTotalLabel.text"));
330 hitTotalLabel.setMaximumSize(
new java.awt.Dimension(18, 14));
331 hitTotalLabel.setMinimumSize(
new java.awt.Dimension(18, 14));
332 hitTotalLabel.setPreferredSize(
new java.awt.Dimension(18, 14));
333 matchesPanel.add(hitTotalLabel);
335 hitButtonsLabel.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitButtonsLabel.text"));
336 matchesPanel.add(hitButtonsLabel);
337 matchesPanel.add(fillerMed2);
339 hitPreviousButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back.png")));
340 hitPreviousButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitPreviousButton.text"));
341 hitPreviousButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
342 hitPreviousButton.setBorderPainted(
false);
343 hitPreviousButton.setContentAreaFilled(
false);
344 hitPreviousButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back_disabled.png")));
345 hitPreviousButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
346 hitPreviousButton.setPreferredSize(
new java.awt.Dimension(23, 23));
347 hitPreviousButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_back_hover.png")));
348 matchesPanel.add(hitPreviousButton);
350 hitNextButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward.png")));
351 hitNextButton.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.hitNextButton.text"));
352 hitNextButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
353 hitNextButton.setBorderPainted(
false);
354 hitNextButton.setContentAreaFilled(
false);
355 hitNextButton.setDisabledIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_disabled.png")));
356 hitNextButton.setMargin(
new java.awt.Insets(2, 0, 2, 0));
357 hitNextButton.setPreferredSize(
new java.awt.Dimension(23, 23));
358 hitNextButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/btn_step_forward_hover.png")));
359 matchesPanel.add(hitNextButton);
360 matchesPanel.add(fillerSmall11);
362 jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
363 jSeparator3.setMaximumSize(
new java.awt.Dimension(2, 25));
364 jSeparator3.setMinimumSize(
new java.awt.Dimension(2, 25));
365 jSeparator3.setName(
"");
366 jSeparator3.setPreferredSize(
new java.awt.Dimension(2, 25));
367 matchesPanel.add(jSeparator3);
369 controlPanel.add(matchesPanel);
371 zoomPanelWrapper.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
373 zoomPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));
374 zoomPanelWrapper.add(zoomPanel);
375 zoomPanel.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.AccessibleContext.accessibleName"));
377 zoomPanelWrapper.add(fillerSmall14);
379 jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);
380 jSeparator4.setMaximumSize(
new java.awt.Dimension(2, 25));
381 jSeparator4.setMinimumSize(
new java.awt.Dimension(2, 25));
382 jSeparator4.setName(
"");
383 jSeparator4.setPreferredSize(
new java.awt.Dimension(2, 25));
384 zoomPanelWrapper.add(jSeparator4);
386 controlPanel.add(zoomPanelWrapper);
388 textSourcePanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
390 jLabel1.setText(
org.openide.util.NbBundle.getMessage(ExtractedContentPanel.class,
"ExtractedContentPanel.jLabel1.text"));
391 textSourcePanel.add(jLabel1);
392 textSourcePanel.add(fillerSmall12);
395 sourceComboBox.setMaximumSize(
new java.awt.Dimension(150, 32767));
396 sourceComboBox.setMinimumSize(
new java.awt.Dimension(150, 25));
397 sourceComboBox.setPreferredSize(
new java.awt.Dimension(150, 25));
398 textSourcePanel.add(sourceComboBox);
400 controlPanel.add(textSourcePanel);
402 add(controlPanel, java.awt.BorderLayout.NORTH);
404 extractedScrollPane.setBackground(
new java.awt.Color(255, 255, 255));
405 extractedScrollPane.setPreferredSize(
new java.awt.Dimension(640, 29));
407 extractedTextPane.setEditable(
false);
408 extractedTextPane.setAutoscrolls(
false);
409 extractedTextPane.setInheritsPopupMenu(
true);
410 extractedTextPane.setMaximumSize(
new java.awt.Dimension(2000, 2000));
411 extractedTextPane.setPreferredSize(
new java.awt.Dimension(600, 29));
412 extractedScrollPane.setViewportView(extractedTextPane);
414 add(extractedScrollPane, java.awt.BorderLayout.CENTER);
417 private javax.swing.JPanel controlPanel;
418 private javax.swing.JMenuItem copyMenuItem;
419 private javax.swing.JScrollPane extractedScrollPane;
420 private javax.swing.JTextPane extractedTextPane;
421 private javax.swing.JLabel hitButtonsLabel;
422 private javax.swing.JLabel hitCountLabel;
423 private javax.swing.JLabel hitLabel;
424 private javax.swing.JButton hitNextButton;
425 private javax.swing.JLabel hitOfLabel;
426 private javax.swing.JButton hitPreviousButton;
427 private javax.swing.JLabel hitTotalLabel;
428 private javax.swing.JLabel jLabel1;
429 private javax.swing.JSeparator jSeparator2;
430 private javax.swing.JSeparator jSeparator3;
431 private javax.swing.JSeparator jSeparator4;
432 private javax.swing.JLabel pageButtonsLabel;
433 private javax.swing.JLabel pageCurLabel;
434 private javax.swing.JButton pageNextButton;
435 private javax.swing.JLabel pageOfLabel;
436 private javax.swing.JButton pagePreviousButton;
437 private javax.swing.JLabel pageTotalLabel;
438 private javax.swing.JLabel pagesLabel;
439 private javax.swing.JPopupMenu rightClickMenu;
440 private javax.swing.JMenuItem selectAllMenuItem;
442 private javax.swing.JPanel textSourcePanel;
443 private javax.swing.JPanel zoomPanel;
446 void refreshCurrentMarkup() {
447 setMarkup(getSelectedSource());
458 final void setSources(String contentName, List<IndexedText> sources) {
459 this.lastKnownAnchor = null;
460 this.contentName = contentName;
461 setPanelText(null,
false);
463 sourceComboBox.removeAllItems();
464 sources.forEach(sourceComboBox::addItem);
465 if (
false == sources.isEmpty()) {
466 sourceComboBox.setEnabled(
true);
467 sourceComboBox.setSelectedIndex(0);
469 sourceComboBox.setEnabled(
false);
478 public IndexedText getSelectedSource() {
479 return (IndexedText) sourceComboBox.getSelectedItem();
482 private void setPanelText(String text,
boolean detectDirection) {
483 String safeText = StringUtils.defaultString(text);
485 if (detectDirection) {
488 final int len = safeText.length();
489 final int prefixLen =
"<pre>".length();
490 if (len > prefixLen) {
491 final int maxOrientChars = Math.min(len, 1024);
492 final String orientDetectText = EscapeUtil.unEscapeHtml(safeText.substring(prefixLen, maxOrientChars));
493 ComponentOrientation direction = TextUtil.getTextDirection(orientDetectText);
494 extractedTextPane.applyComponentOrientation(direction);
496 extractedTextPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
499 extractedTextPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
502 extractedTextPane.setText(safeText);
503 extractedTextPane.setCaretPosition(0);
506 void scrollToAnchor(String anchor) {
507 lastKnownAnchor = anchor;
508 extractedTextPane.scrollToReference(anchor);
516 void updateCurrentMatchDisplay(
int current) {
518 hitCountLabel.setText(
"-");
520 hitCountLabel.setText(Integer.toString(current));
529 void updateTotaMatcheslDisplay(
int total) {
531 hitTotalLabel.setText(
"-");
533 hitTotalLabel.setText(Integer.toString(total));
542 void updateCurrentPageDisplay(
int current) {
543 pageCurLabel.setText(Integer.toString(current));
551 void updateTotalPagesDisplay(
int total) {
552 pageTotalLabel.setText(Integer.toString(total));
559 void resetDisplay() {
560 setSources(
"",
new ArrayList<>());
561 hitTotalLabel.setText(
"-");
562 hitCountLabel.setText(
"-");
563 pageCurLabel.setText(
"-");
564 pageTotalLabel.setText(
"-");
572 void enablePrevMatchControl(
boolean enable) {
573 hitPreviousButton.setEnabled(enable);
581 void enableNextMatchControl(
boolean enable) {
582 hitNextButton.setEnabled(enable);
585 void addPrevMatchControlListener(ActionListener l) {
586 hitPreviousButton.addActionListener(l);
589 void addNextMatchControlListener(ActionListener l) {
590 hitNextButton.addActionListener(l);
598 void enablePrevPageControl(
boolean enable) {
599 pagePreviousButton.setEnabled(enable);
607 void enableNextPageControl(
boolean enable) {
608 pageNextButton.setEnabled(enable);
611 void addPrevPageControlListener(ActionListener l) {
612 pagePreviousButton.addActionListener(l);
615 void addNextPageControlListener(ActionListener l) {
616 pageNextButton.addActionListener(l);
619 void addSourceComboControlListener(ActionListener l) {
620 sourceComboBox.addActionListener(l);
628 void updateControls(IndexedText source) {
629 updatePageControls(source);
630 updateSearchControls(source);
638 void updatePageControls(IndexedText source) {
639 if (source == null) {
640 enableNextPageControl(
false);
641 enablePrevPageControl(
false);
642 updateCurrentPageDisplay(0);
643 updateTotalPagesDisplay(0);
647 updateCurrentPageDisplay(source.getCurrentPage());
648 int totalPages = source.getNumberPages();
649 updateTotalPagesDisplay(totalPages);
651 if (totalPages < 2) {
652 enableNextPageControl(
false);
653 enablePrevPageControl(
false);
655 enableNextPageControl(source.hasNextPage());
656 enablePrevPageControl(source.hasPreviousPage());
665 void updateSearchControls(IndexedText source) {
667 if (source != null && source.isSearchable()) {
668 updateCurrentMatchDisplay(source.currentItem());
669 updateTotaMatcheslDisplay(source.getNumberHits());
670 enableNextMatchControl(source.hasNextItem() || source.hasNextPage());
671 enablePrevMatchControl(source.hasPreviousItem() || source.hasPreviousPage());
673 enableNextMatchControl(
false);
674 enablePrevMatchControl(
false);
675 updateCurrentMatchDisplay(0);
676 updateTotaMatcheslDisplay(0);
685 private void scrollToCurrentHit(
final IndexedText source) {
686 if (source == null || !source.isSearchable()) {
691 EventQueue.invokeLater(() -> scrollToAnchor(source.getAnchorPrefix() + source.currentItem()));
700 @NbBundle.Messages(
"ExtractedContentPanel.setMarkup.panelTxt=<span style='font-style:italic'>Loading text... Please wait</span>")
701 private void setMarkup(IndexedText source) {
702 setPanelText(Bundle.ExtractedContentPanel_setMarkup_panelTxt(),
false);
703 new SetMarkupWorker(contentName, source).execute();
720 this.contentName = contentName;
721 this.source = source;
725 @NbBundle.Messages({
"# {0} - Content name",
726 "ExtractedContentPanel.SetMarkup.progress.loading=Loading text for {0}"})
728 progress = ProgressHandle.createHandle(Bundle.ExtractedContentPanel_SetMarkup_progress_loading(contentName));
730 progress.switchToIndeterminate();
732 return source.getText();
742 String markup =
get();
743 if (markup != null) {
744 setPanelText(markup,
true);
746 setPanelText(
"",
false);
748 }
catch (InterruptedException | CancellationException | ExecutionException ex) {
749 logger.log(Level.SEVERE,
"Error getting marked up text", ex);
750 setPanelText(Bundle.IndexedText_errorMessage_errorGettingText(),
true);
753 updateControls(source);
754 scrollToCurrentHit(source);