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 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 this.addPropertyChangeListener( 30 new PropertyChangeListener() 31 { 32 public void propertyChange(PropertyChangeEvent e) 33 { 34 { 37 { 41 setup(); 42 } 43 } 45 49 } 50 }); 51 52 } 54 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 78 public void updateUI() 79 { 80 super.updateUI(); 81 setup(); 82 } 83 84 85 86 87 public Component getTreeCellRendererComponent( 88 JTree tree, Object value, 89 boolean selected, boolean expanded, 90 boolean leaf, int row, boolean hasFocus) 91 { 92 setFont(UIManager.getFont("Tree.font")); 93 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 } | Popular Tags |