KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > SearchTreePanel


1 package SnowMailClient.view;
2
3 import SnowMailClient.*;
4 import SnowMailClient.Language.Language;
5 import SnowMailClient.model.*;
6 import snow.utils.gui.*;
7 import SnowMailClient.view.attachments.MimeTreeRenderer;
8 import snow.lookandfeel.*;
9 import java.awt.*;
10 import java.awt.event.*;
11 import javax.swing.*;
12 import javax.swing.tree.*;
13 import javax.swing.event.*;
14 import java.util.*;
15
16 public class SearchTreePanel extends SnowBackgroundPanel
17 {
18   final JTree tree = new JTree();
19
20   public SearchTreePanel( )
21   {
22     super(new BorderLayout());
23     JScrollPane jsp = new JScrollPane(tree);
24     jsp.setOpaque(false);
25     jsp.getViewport().setOpaque(false);
26     tree.setOpaque(false);
27
28     add(jsp, BorderLayout.CENTER);
29     tree.setFont(ThemesManager.getInstance().getSmallFont());
30     tree.setCellRenderer(new MimeTreeRenderer());
31
32     tree.addTreeSelectionListener(new TreeSelectionListener()
33     {
34        public void valueChanged(TreeSelectionEvent e)
35        {
36           if(tree.getSelectionCount()>0)
37           {
38              TreePath path = e.getPath();
39              DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
40              Object JavaDoc uo = node.getUserObject();
41              if(uo instanceof SearchHit)
42              {
43                 SearchHit hit = (SearchHit) uo;
44                 select(hit);
45              }
46           }
47        }
48     });
49
50     // default empty model
51
setModel(new SearchResults());
52   } // Constructor
53

54   public void setModel(SearchResults sr)
55   {
56     tree.setModel(sr);
57   }
58
59   private void select(final SearchHit hit)
60   {
61     EventQueue.invokeLater(new Runnable JavaDoc()
62     {
63       public void run()
64       {
65         SnowMailClientApp.getInstance().getFoldersView().setSelectedFolder(hit.getNode(), hit.getMessage());
66       }
67     });
68   }
69
70   /** call this at the end of the search
71   */

72   public void updateTree()
73   {
74      DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
75      root.setUserObject(Language.translate("Search Results")
76        +": ("+root.getChildCount()
77        +" "+
78        (root.getChildCount()==1 ? Language.translate("hit") : Language.translate("hits"))
79        +")");
80
81      // ### ugly
82
EventQueue.invokeLater(new Runnable JavaDoc()
83      {
84        public void run()
85        {
86          tree.updateUI();
87        }
88      });
89   }
90
91
92 } // searchTree
Popular Tags