KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > view > attachments > MimeTreeRenderer


1 package SnowMailClient.view.attachments;
2
3 import SnowMailClient.model.multipart.*;
4 import SnowMailClient.view.*;
5
6 import javax.swing.*;
7 import javax.swing.border.*;
8 import javax.swing.tree.*;
9 import java.awt.*;
10 import java.beans.*;
11
12 /**
13    ### can be optimized for performance... see DefaultTreeCellRenderer
14 */

15 public class MimeTreeRenderer extends JLabel implements TreeCellRenderer
16 {
17   Border validDropTargetBorder = null;
18   Border invalidDropTargetBorder = null;
19   Border emptyBorder = null;
20   int dropTargetRow = -1;
21
22
23   public MimeTreeRenderer()
24   {
25     super();
26     setup();
27
28     // recall after all themes change
29
this.addPropertyChangeListener(
30      new PropertyChangeListener()
31      {
32         public void propertyChange(PropertyChangeEvent e)
33         {
34             //String name = e.getPropertyName();
35
//if (name.equals("lookAndFeel"))
36
{
37               // SwingUtilities.invokeLater( new Runnable()
38
// {
39
// public void run()
40
{
41                      setup();
42                    }
43 // });
44
}
45         /* else
46             {
47               System.out.println(">"+name);
48             }*/

49         }
50      });
51
52   } // Constructor
53

54   /** must be called after each ui change
55   */

56   private void setup()
57   {
58     int fontSize = UIManager.getFont("Tree.font").getSize();
59     emptyBorder = new EmptyBorder(fontSize/4, fontSize/2, fontSize/4, fontSize/2);
60     Border emptyBorderM1 = new EmptyBorder(fontSize/4-1, fontSize/2-1, fontSize/4-1, fontSize/2-1);
61
62     validDropTargetBorder = BorderFactory.createCompoundBorder(
63            BorderFactory.createLineBorder(Color.green, 1), emptyBorderM1);
64
65     invalidDropTargetBorder = BorderFactory.createCompoundBorder(
66            BorderFactory.createLineBorder(Color.red, 1), emptyBorderM1);
67   }
68
69
70     /**
71      * Notification from the <code>UIManager</code> that the look and feel
72      * [L&F] has changed.
73      * Replaces the current UI object with the latest version from the
74      * <code>UIManager</code>.
75      *
76      * @see JComponent#updateUI
77      */

78     public void updateUI()
79     {
80         super.updateUI();
81         setup();
82     }
83
84
85
86
87   public Component getTreeCellRendererComponent(
88      JTree tree, Object JavaDoc value,
89      boolean selected, boolean expanded,
90      boolean leaf, int row, boolean hasFocus)
91   {
92     setFont(UIManager.getFont("Tree.font"));
93     // background
94
if(selected)
95     {
96        setBackground(UIManager.getColor("Tree.selectionBackground"));
97        this.setOpaque(true);
98     }
99     else
100     {
101        setBackground(UIManager.getColor("Tree.textBackground"));
102        this.setOpaque(false);
103     }
104
105     if( value instanceof MimePart )
106     {
107       MimePart part = (MimePart) value;
108       this.setText(part.getTextForTreeRepresentation());
109
110
111     }
112     else
113     {
114       this.setText(value.toString());
115     }
116
117
118
119     return this;
120   }
121
122
123
124 } // MimeTreeRenderer
Popular Tags