View Javadoc

1   /*
2    * JarInspector - Copyright (C) 2004 Che Inc., Rosario Argentina
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Library General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Library General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public
15   * License along with this library; if not, write to the Free
16   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17   */
18  
19  package inc.che.jarinspector;
20  
21  // Imports
22  
23  import inc.che.common.config.Config;
24  import inc.che.common.gui.ConfigDialog;
25  import inc.che.common.gui.EStatusBar;
26  import inc.che.common.gui.GuiUtil;
27  import inc.che.common.gui.StartWindow;
28  import inc.che.common.resource.ResourceManager;
29  import inc.che.common.type.IntHashMap;
30  
31  import java.awt.BorderLayout;
32  import java.awt.Color;
33  import java.awt.Container;
34  import java.awt.Dimension;
35  import java.awt.FlowLayout;
36  import java.awt.Font;
37  import java.awt.Point;
38  import java.awt.event.ActionEvent;
39  import java.awt.event.ActionListener;
40  import java.awt.event.WindowAdapter;
41  import java.awt.event.WindowEvent;
42  import java.io.File;
43  import java.io.FileFilter;
44  import java.io.IOException;
45  import java.net.URL;
46  import java.text.ParseException;
47  import java.util.ArrayList;
48  import java.util.Collection;
49  import java.util.Collections;
50  import java.util.Iterator;
51  
52  import javax.swing.BorderFactory;
53  import javax.swing.ButtonGroup;
54  import javax.swing.ImageIcon;
55  import javax.swing.JButton;
56  import javax.swing.JCheckBox;
57  import javax.swing.JFileChooser;
58  import javax.swing.JFrame;
59  import javax.swing.JMenu;
60  import javax.swing.JMenuBar;
61  import javax.swing.JMenuItem;
62  import javax.swing.JPanel;
63  import javax.swing.JRadioButtonMenuItem;
64  import javax.swing.JScrollPane;
65  import javax.swing.JTextArea;
66  import javax.swing.JTextField;
67  import javax.swing.text.BadLocationException;
68  import javax.swing.text.DefaultHighlighter;
69  import javax.swing.text.Highlighter;
70  
71  import javax.help.HelpBroker;
72  import javax.help.HelpSet;
73  import javax.help.CSH;
74  
75  import org.apache.log4j.Logger;
76  
77  /***
78   *  <b>@todo</b>
79   * @version $Id: JarInspectorFrame.java,v 1.1 2005/03/06 12:56:57 stevemcmee Exp $
80   * @author <address> Steve McMee &lt;stevemcmee@sourceforge.net&gt; </address>
81   */
82  
83  public class JarInspectorFrame extends JFrame {
84  
85      class ScanThread extends Thread {
86  
87          private File selFile = null;
88          private boolean scan = true;
89  
90          ScanThread(final File selFile) {
91              this.selFile = selFile;
92          }
93          public void run() {
94              setMode(SCAN_MODE);
95              loadDirectory(selFile);
96              setMode(SHOW_MODE);
97          }
98  
99          public void interrupt() {
100             scan = false;
101         }
102 
103         private void loadDirectory(File dir) {
104             GuiUtil.setWaitCursor(textArea, true);
105             if (log.isDebugEnabled()) {
106                 log.debug("loadDirectory(" + dir + ")");
107             }
108             config.setParameter("dir.last", dir.getAbsolutePath());
109             if (log.isDebugEnabled()) {
110                 log.debug(config.getParameter("dir.last"));
111             }
112             infos.clear();
113 
114             int count = getAllJarFiles(dir);
115 
116             statusBar.setText(
117                 0,
118                 resourceManager.getText(
119                     "scan.result",
120                     new String[] {
121                         String.valueOf(count),
122                         String.valueOf(infos.size())}));
123             loadTextArea();
124             GuiUtil.setWaitCursor(textArea, false);
125 
126         }
127         private int scanDirectory(File dir, FileFilter filter) {
128             int count = 0;
129 
130             statusBar.setText(
131                 0,
132                 resourceManager.getText(
133                     "scan.dir",
134                     new String[] {String.valueOf(dir), }));
135 
136             File[] files = dir.listFiles(filter);
137             for (int i = 0; scan && i < files.length; i++) {
138                 if (files[i].isDirectory()) {
139                     if (config.getBooleanParameter("search.recursive", true)) {
140                         count = count + scanDirectory(files[i], filter);
141                     }
142                 } else { // Jar File
143                     count++;
144                     scanJarFile(files[i]);
145                 }
146             }
147             return count;
148         }
149 
150         private void scanJarFile(File file) {
151 
152             statusBar.setText(
153                 0,
154                 resourceManager.getText(
155                     "scan.jar",
156                     new String[] {String.valueOf(file), }));
157 
158             try {
159                 JarFileInfo info = new JarFileInfo(file);
160                 infos.addAll(info.getAllItems());
161 
162             } catch (Exception ex) {
163                 ex.printStackTrace();
164                 log.error(ex);
165             }
166 
167         }
168 
169         private int getAllJarFiles(File root) {
170 
171             return scanDirectory(root, new FileFilter() {
172                 public boolean accept(File file) {
173                     return file.isDirectory() || file.getName().endsWith("jar");
174                 }
175             });
176 
177         }
178 
179     }
180 
181     /*** CVS ID of this file */
182     public static final String CVS_ID =
183         "$Id: JarInspectorFrame.java,v 1.1 2005/03/06 12:56:57 stevemcmee Exp $";
184 
185     /*** logger instance for this class */
186 
187     private static Logger log = Logger.getLogger(JarInspectorFrame.class);
188 
189     /***
190      * configuration instance for this class
191      */
192     private static Config config = Config.getInstance();
193 
194     /***
195      * The ResourceManager
196      */
197     private static ResourceManager resourceManager =
198         ResourceManager.getResourceManager(StringResources.TEXT_RESOURCES);
199 
200     /***
201      * The instance
202      */
203 
204     private static JarInspectorFrame instance = null;
205 
206     private DefaultHighlighter.DefaultHighlightPainter highLightHit =
207         new DefaultHighlighter.DefaultHighlightPainter(
208             config.getColorParameter("color.highlight.hit", Color.cyan));
209     private DefaultHighlighter.DefaultHighlightPainter highLightSearch =
210         new DefaultHighlighter.DefaultHighlightPainter(
211             config.getColorParameter("color.highlight.search", Color.red));
212 
213     private static final int SHOW_MODE = 1;
214     private static final int SCAN_MODE = 2;
215 
216     private static final int NAV_FIRST = 1;
217     private static final int NAV_LAST = 2;
218     private static final int NAV_NEXT = 3;
219     private static final int NAV_PREV = 4;
220 
221     private JTextArea textArea = null;
222     private JScrollPane scrollPane = null;
223     private boolean sortJars = false;
224     private Collection infos = new ArrayList();
225     private EStatusBar statusBar = null;
226     private String searchTerm = null;
227     private JCheckBox caseCb = null;
228     private HelpBroker helpBroker = null;
229 
230     private JButton searchButton = null;
231     private JButton stopButton = null;
232     private JButton[] navButtons = null;
233 
234     private JMenu fileMenu = null;
235     private JMenu sortMenu = null;
236     private JMenu helpMenu = null;
237     private JMenu propMenu = null;
238 
239     private JMenuItem openItem = null;
240     private JMenuItem closeItem = null;
241     private JMenuItem infoItem = null;
242     private JMenuItem helpItem = null;
243     private JMenuItem configItem = null;
244     private JRadioButtonMenuItem classSortItem = null;
245     private JRadioButtonMenuItem jarSortItem = null;
246 
247     private java.util.List hitLines = new ArrayList();
248     private int hitIndex = -1;
249 
250     private ScanThread scanThread = null;
251 
252     private IntHashMap highlightMap = new IntHashMap();
253 
254     public JarInspectorFrame() {
255         config.setIntParameter("startwindow.height", 240);
256         config.setIntParameter("startwindow.width", 165);
257         config.setIntParameter("startwindow.font.size", 10);
258         config.setIntParameter("startwindow.progressbar.height", 10);
259         try {
260             config.setColorParameter("startwindow.text.color", Color.GRAY);
261             config.setColorParameter(
262                 "startwindow.progress.color",
263                 Color.DARK_GRAY);
264             config.setColorParameter(
265                 "startwindow.background.color",
266                 Color.BLACK);
267         } catch (ParseException ex) {
268             log.error(ex);
269         }
270 
271         StartWindow startWindow =
272             new StartWindow(
273                 "JarInspector V" + VersionInfo.VERSION,
274                 (ImageIcon) resourceManager.getIconByGifName(
275                     "startwindow.logo"),
276                 config);
277         startWindow.show();
278         startWindow.setProgress(
279             resourceManager.getText("startwindow.prepareHelp"),
280             50,
281             1);
282 
283         helpBroker = prepareJavaHelp();
284         startWindow.setProgress(
285             resourceManager.getText("startwindow.initComponents"),
286             75,
287             1);
288 
289         initComponents();
290         enableNavButtons(false);
291         if (config.isSet("frame.posx") && config.isSet("frame.posy")) {
292             this.setLocation(
293                 config.getIntParameter("frame.posx"),
294                 config.getIntParameter("frame.posy"));
295         } else {
296             GuiUtil.center(this);
297         }
298         this.setTitle("JarInspector " + VersionInfo.VERSION);
299         this.setIconImage(
300             resourceManager
301                 .getIconByGifPath(StringResources.APP_ICON)
302                 .getImage());
303         instance = this;
304         startWindow.setVisible(false);
305         startWindow.dispose();
306     }
307 
308     public static JarInspectorFrame getJarInspectorFrame() {
309         return instance;
310     }
311 
312     private void initComponents() {
313         Container contentPane = this.getContentPane();
314         contentPane.setLayout(new BorderLayout());
315         contentPane.setSize(
316             new Dimension(
317                 config.getIntParameter("frame.width", 300),
318                 config.getIntParameter("frame.height", 600)));
319         contentPane.add(BorderLayout.NORTH, this.createMenuBar());
320         contentPane.add(BorderLayout.CENTER, createMainPanel());
321         contentPane.add(BorderLayout.SOUTH, createStatusBar());
322         this.textArea.setEditable(false);
323         this.textArea.setFont(new Font("Arial", Font.PLAIN, 10));
324 
325         addWindowListener(new WindowAdapter() {
326             public void windowClosing(WindowEvent evt) {
327                 exitForm(evt);
328             }
329         });
330         this.pack();
331     }
332 
333     private JPanel createStatusBar() {
334         statusBar = new EStatusBar(2);
335         statusBar.setBorder(BorderFactory.createLoweredBevelBorder());
336         statusBar.setFont(new Font("Arial", Font.PLAIN, 10));
337         //    statusBar.setPreferredSize(0, new Dimension (config.getIntParameter("frame.width",300)-100,20));
338         return statusBar;
339     }
340     private JMenuBar createMenuBar() {
341         JMenuBar menuBar = new JMenuBar();
342 
343         fileMenu = new JMenu(resourceManager.getText("button.file"));
344         sortMenu = new JMenu(resourceManager.getText("button.sort"));
345         helpMenu = new JMenu(resourceManager.getText("button.help"));
346         propMenu = new JMenu(resourceManager.getText("button.prop"));
347 
348         openItem = new JMenuItem(resourceManager.getText("button.open"));
349         closeItem = new JMenuItem(resourceManager.getText("button.exit"));
350         infoItem = new JMenuItem(resourceManager.getText("button.info"));
351         helpItem = new JMenuItem(resourceManager.getText("button.javahelp"));
352         configItem = new JMenuItem(resourceManager.getText("button.config"));
353 
354         classSortItem =
355             new JRadioButtonMenuItem(
356                 resourceManager.getText("button.order.classes"),
357                 !config.getBooleanParameter("sort.jar", true));
358         jarSortItem =
359             new JRadioButtonMenuItem(
360                 resourceManager.getText("button.order.jar"),
361                 config.getBooleanParameter("sort.jar", true));
362         ButtonGroup buttonGroup = new ButtonGroup();
363         buttonGroup.add(classSortItem);
364         buttonGroup.add(jarSortItem);
365 
366         // ActonListener
367 
368         configItem.addActionListener(new ActionListener() {
369             public void actionPerformed(ActionEvent evt) {
370                 openConfigDialog();
371             }
372         });
373 
374         helpItem.addActionListener(new CSH.DisplayHelpFromSource(helpBroker));
375         closeItem.addActionListener(new ActionListener() {
376             public void actionPerformed(ActionEvent evt) {
377                 exitMenuItemActionPerformed(evt);
378             }
379         });
380 
381         openItem.addActionListener(new ActionListener() {
382             public void actionPerformed(ActionEvent evt) {
383                 openDir();
384             }
385         });
386 
387         jarSortItem.addActionListener(new ActionListener() {
388             public void actionPerformed(ActionEvent evt) {
389 
390                 sortJars = true;
391                 config.setBooleanParameter("sort.jar", sortJars);
392                 loadTextArea();
393             }
394         });
395 
396         classSortItem.addActionListener(new ActionListener() {
397             public void actionPerformed(ActionEvent evt) {
398 
399                 sortJars = false;
400                 config.setBooleanParameter("sort.jar", sortJars);
401                 loadTextArea();
402             }
403         });
404 
405         infoItem.addActionListener(new ActionListener() {
406             public void actionPerformed(ActionEvent evt) {
407                 openInfoDialog();
408 
409             }
410         });
411 
412         menuBar.add(fileMenu);
413         menuBar.add(sortMenu);
414         menuBar.add(propMenu);
415         menuBar.add(helpMenu);
416 
417         propMenu.add(configItem);
418         helpMenu.add(helpItem);
419         helpMenu.addSeparator();
420         helpMenu.add(infoItem);
421         sortMenu.add(classSortItem);
422         sortMenu.add(jarSortItem);
423         fileMenu.add(openItem);
424         fileMenu.add(closeItem);
425 
426         return menuBar;
427     }
428 
429     private JPanel createMainPanel() {
430         JPanel panel = new JPanel(new BorderLayout());
431         //panel.setPreferredSize(new Dimension(400,300));
432         textArea = new JTextArea();
433         scrollPane = new JScrollPane();
434         scrollPane.setViewportView(textArea);
435         scrollPane.setPreferredSize(
436             new Dimension(
437                 config.getIntParameter("panel.width", 300),
438                 config.getIntParameter("panel.height", 500)));
439 
440         panel.add(BorderLayout.NORTH, createSearchPanel());
441         panel.add(BorderLayout.CENTER, scrollPane);
442         panel.add(BorderLayout.SOUTH, createNavigatePanel());
443         return panel;
444     }
445 
446     private JPanel createSearchPanel() {
447         JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
448         searchButton = new JButton(resourceManager.getText("button.search"));
449 
450         caseCb =
451             new JCheckBox(
452                 resourceManager.getText("button.case"),
453                 config.getBooleanParameter("search.case", true));
454 
455         final JTextField searchField = new JTextField();
456         searchField.setPreferredSize(new Dimension(300, 25));
457         panel.add(searchField);
458         panel.add(searchButton);
459         panel.add(caseCb);
460 
461         searchButton.addActionListener(new ActionListener() {
462             public void actionPerformed(ActionEvent evt) {
463                 searchTerm = searchField.getText();
464                 highlightSearch();
465             }
466         });
467         return panel;
468     }
469 
470     private JPanel createNavigatePanel() {
471         JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
472         JButton firstButton =
473             new JButton(resourceManager.getText("button.first"));
474         JButton lastButton =
475             new JButton(resourceManager.getText("button.last"));
476         JButton prevButton =
477             new JButton(resourceManager.getText("button.prev"));
478         JButton nextButton =
479             new JButton(resourceManager.getText("button.next"));
480 
481         navButtons =
482             new JButton[] {firstButton, lastButton, prevButton, nextButton };
483         panel.add(firstButton);
484         panel.add(prevButton);
485         panel.add(nextButton);
486         panel.add(lastButton);
487 
488         firstButton.addActionListener(new ActionListener() {
489             public void actionPerformed(ActionEvent evt) {
490                 navigate(NAV_FIRST);
491             }
492         });
493         lastButton.addActionListener(new ActionListener() {
494             public void actionPerformed(ActionEvent evt) {
495                 navigate(NAV_LAST);
496             }
497         });
498         prevButton.addActionListener(new ActionListener() {
499             public void actionPerformed(ActionEvent evt) {
500                 navigate(NAV_PREV);
501             }
502         });
503         nextButton.addActionListener(new ActionListener() {
504             public void actionPerformed(ActionEvent evt) {
505                 navigate(NAV_NEXT);
506             }
507         });
508 
509         // Stop Button
510 
511         stopButton = new JButton(resourceManager.getText("button.stop"));
512         stopButton.setVisible(false);
513         panel.add(stopButton);
514 
515         stopButton.addActionListener(new ActionListener() {
516             public void actionPerformed(ActionEvent evt) {
517                 if (scanThread != null) {
518                     scanThread.interrupt();
519                 }
520                 scanThread = null;
521             }
522         });
523         return panel;
524     }
525 
526     private void closeFrame() {
527         this.setVisible(false);
528         this.dispose();
529         config.setIntParameter("frame.posx", this.getX());
530         config.setIntParameter("frame.posy", this.getY());
531         config.setIntParameter("frame.height", this.getHeight());
532         config.setIntParameter("frame.width", this.getWidth());
533         config.setIntParameter("panel.height", scrollPane.getHeight());
534         config.setIntParameter("panel.width", scrollPane.getWidth());
535         config.setBooleanParameter("search.case", caseCb.isSelected());
536         try {
537             config.store();
538         } catch (IOException ex) {
539             ex.printStackTrace();
540             log.error(ex);
541         }
542 
543         System.exit(1);
544     }
545     /***
546      * Callbackmethode zum Schließen des Fensters
547      * @param evt Menüevent zum Schließen des Fensters
548      */
549     private void exitMenuItemActionPerformed(ActionEvent evt) {
550         closeFrame();
551     }
552 
553     /***
554      * Callbackmethode zum Schließen des Fensters
555      * @param evt Event zum Schließen des Fensters
556      */
557     private void exitForm(WindowEvent evt) {
558         closeFrame();
559     }
560 
561     private void openDir() {
562         GuiUtil.setWaitCursor(this, true);
563 
564         JFileChooser chooser = new JFileChooser();
565 
566         if (log.isDebugEnabled()) {
567             log.debug(config.getFileParameter("dir.last"));
568         }
569         if (config.isSet("dir.last")) {
570             chooser = new JFileChooser(config.getFileParameter("dir.last"));
571         }
572         GuiUtil.setWaitCursor(this, false);
573         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
574         chooser.setDialogTitle(resourceManager.getText("chooser.title"));
575         int returnVal = chooser.showOpenDialog(this);
576         if (returnVal == JFileChooser.APPROVE_OPTION) {
577             scanThread = new ScanThread(chooser.getSelectedFile());
578             scanThread.start();
579         }
580 
581     }
582 
583     private void loadTextArea() {
584         GuiUtil.setWaitCursor(textArea, true);
585         if (this.sortJars == true) {
586             Collections.sort(
587                 (java.util.List) infos,
588                 new JarFileInfo.JarFileInfoItemJarComparator());
589         } else {
590             Collections.sort(
591                 (java.util.List) infos,
592                 new JarFileInfo.JarFileInfoItemClassComparator());
593         }
594         textArea.setText("");
595         for (Iterator iit = infos.iterator(); iit.hasNext();) {
596             textArea.append(iit.next().toString());
597             textArea.append("\n");
598         }
599         highlightSearch();
600         GuiUtil.setWaitCursor(textArea, false);
601     }
602 
603     private void highlightSearch() {
604         if (searchTerm == null || searchTerm.trim().length() == 0) {
605             return;
606         }
607 
608         int line = 0;
609         int hits = 0;
610         hitLines.clear();
611         textArea.getHighlighter().removeAllHighlights();
612         JarFileInfo.JarFileInfoItem item = null;
613         for (Iterator it = infos.iterator(); it.hasNext();) {
614             item = (JarFileInfo.JarFileInfoItem) it.next();
615             if ((caseCb.isSelected()
616                 && item.getClassName().indexOf(searchTerm) != -1)
617                 || (!caseCb.isSelected()
618                     && item.getClassName().toLowerCase().indexOf(
619                         searchTerm.toLowerCase())
620                         != -1)) {
621                 hits++;
622                 try {
623                     int start = textArea.getLineStartOffset(line);
624                     int end = textArea.getLineEndOffset(line);
625                     highlightMap.put(
626                         line,
627                         textArea.getHighlighter().addHighlight(
628                             start,
629                             end,
630                             highLightHit));
631                     hitLines.add(new Integer(line));
632                 } catch (BadLocationException ex) {
633                     ex.printStackTrace();
634                     log.error(ex);
635                 }
636             }
637 
638             line++;
639         }
640         enableNavButtons(hits > 0 ? true : false);
641         statusBar.setText(
642             1,
643             resourceManager.getText(
644                 "search.result",
645                 new String[] {String.valueOf(0), String.valueOf(hits), }));
646 
647     }
648 
649     private void openInfoDialog() {
650 
651         InfoDialog infoDialog = new InfoDialog(this);
652         infoDialog.show();
653     }
654 
655     private void openConfigDialog() {
656 
657         ConfigDialog configDialog = new JarInspectorConfigDialog(this, config);
658         configDialog.showOnlyEditable(true);
659         configDialog.show();
660     }
661     private HelpBroker prepareJavaHelp() {
662         // Find the HelpSet file and create the HelpSet object:
663         HelpSet hs = null;
664         String helpHS = "helpset.hs";
665         ClassLoader cl = JarInspector.class.getClassLoader();
666 
667         try {
668             URL hsURL = HelpSet.findHelpSet(cl, helpHS);
669             hs = new HelpSet(null, hsURL);
670 
671         } catch (Exception ex) {
672             log.error(ex);
673             // Say what the exception really is
674             System.out.println("HelpSet " + ex.getMessage());
675             System.out.println("HelpSet " + helpHS + " not found");
676             return null;
677         }
678         // Create a HelpBroker object:
679 
680         return hs.createHelpBroker();
681 
682     }
683 
684     private int getHitLine(int index) {
685         if (index < 0) {
686             return -1;
687         }
688         return ((Integer) hitLines.get(index)).intValue();
689     }
690 
691     private void navigate(int direction) {
692         Highlighter.Highlight[] highlights =
693             textArea.getHighlighter().getHighlights();
694 
695         if (hitIndex != -1) {
696             try {
697                 int line = getHitLine(hitIndex);
698                 int start = textArea.getLineStartOffset(line);
699                 int end = textArea.getLineEndOffset(line);
700 
701                 textArea.getHighlighter().removeHighlight(
702                     highlightMap.get(line));
703 
704                 highlightMap.put(
705                     line,
706                     textArea.getHighlighter().addHighlight(
707                         start,
708                         end,
709                         highLightHit));
710             } catch (BadLocationException ex) {
711                 ex.printStackTrace();
712                 log.error(ex);
713             }
714         }
715 
716         switch (direction) {
717             case NAV_FIRST :
718                 this.hitIndex = 0;
719                 break;
720             case NAV_LAST :
721                 this.hitIndex = this.hitLines.size() - 1;
722                 break;
723             case NAV_NEXT :
724                 if (this.hitIndex < this.hitLines.size() - 1) {
725                     this.hitIndex++;
726                 }
727                 break;
728             case NAV_PREV :
729                 if (this.hitIndex > 0) {
730                     this.hitIndex--;
731                 }
732                 break;
733             default:
734                 break;
735         }
736 
737         statusBar.setText(
738             1,
739             resourceManager.getText(
740                 "search.result",
741                 new String[] {
742                     String.valueOf(hitIndex + 1),
743                     String.valueOf(this.hitLines.size()),
744                     }));
745 
746         int line = getHitLine(hitIndex);
747 
748         try {
749             int start = textArea.getLineStartOffset(line);
750             int end = textArea.getLineEndOffset(line);
751 
752             textArea.getHighlighter().removeHighlight(highlightMap.get(line));
753 
754             highlightMap.put(
755                 line,
756                 textArea.getHighlighter().addHighlight(
757                     start,
758                     end,
759                     highLightSearch));
760         } catch (BadLocationException ex) {
761             ex.printStackTrace();
762             log.error(ex);
763         }
764 
765         scrollPane.getViewport().setViewPosition(
766             new Point(0, Math.max(13 * line - 50, 0)));
767     }
768 
769     private void enableNavButtons(boolean enable) {
770         if (this.navButtons != null) {
771             for (int i = 0; i < navButtons.length; i++) {
772                 navButtons[i].setEnabled(enable);
773             }
774         }
775     }
776     private void enableMenus(boolean enable) {
777         this.openItem.setEnabled(enable);
778         this.classSortItem.setEnabled(enable);
779         this.jarSortItem.setEnabled(enable);
780     }
781 
782     private void setMode(int mode) {
783         switch (mode) {
784             case SCAN_MODE :
785                 enableMenus(false);
786                 searchButton.setEnabled(false);
787                 stopButton.setVisible(true);
788                 break;
789             case SHOW_MODE :
790                 enableMenus(true);
791                 searchButton.setEnabled(true);
792                 stopButton.setVisible(false);
793                 break;
794             default:
795                 break;
796         }
797     }
798 
799     public void setHighlighter() {
800         highLightHit =
801             new DefaultHighlighter.DefaultHighlightPainter(
802                 config.getColorParameter("color.highlight.hit", Color.cyan));
803         highLightSearch =
804             new DefaultHighlighter.DefaultHighlightPainter(
805                 config.getColorParameter("color.highlight.search", Color.red));
806         DefaultHighlighter.DefaultHighlightPainter o;
807 
808         try {
809             int[] keys = highlightMap.keySet();
810             int hitLine = getHitLine(hitIndex);
811             for (int i = 0; i < keys.length; i++) {
812                 int line = keys[i];
813                 boolean isHitLine = (hitLine == line);
814                 textArea.getHighlighter().removeHighlight(
815                     highlightMap.get(line));
816                 int start = textArea.getLineStartOffset(line);
817                 int end = textArea.getLineEndOffset(line);
818                 highlightMap.put(
819                     line,
820                     textArea.getHighlighter().addHighlight(
821                         start,
822                         end,
823                         isHitLine ? highLightSearch : highLightHit));
824             }
825         } catch (Exception ex) {
826             ex.printStackTrace();
827             log.error(ex);
828         }
829     }
830 }