| 1 package org.columba.core.gui.util; 17 18 import java.awt.event.MouseEvent ; 19 import java.awt.event.MouseListener ; 20 21 import javax.swing.BoxLayout ; 22 import javax.swing.ImageIcon ; 23 import javax.swing.JLabel ; 24 import javax.swing.JPanel ; 25 import javax.swing.JPopupMenu ; 26 27 import org.columba.core.gui.base.LinkLabel; 28 29 30 31 public class AddressLabel extends JPanel implements MouseListener { 33 private String address; 34 private JLabel [] list = new JLabel [3]; 35 36 37 private JPopupMenu popup; 38 39 public AddressLabel(String str) { 40 super(); 41 42 43 setLayout(new BoxLayout (this, BoxLayout.X_AXIS)); 44 setBorder(null); 45 this.address = str; 46 47 parse(); 48 49 URLController controller = new URLController(); 50 51 if (list[1] != null) { 52 controller.setAddress(list[1].getText()); 53 popup = controller.createContactMenu(list[1].getText()); 54 } else { 55 controller.setAddress(address); 56 popup = controller.createContactMenu(address); 57 } 58 } 59 60 protected void parse() { 61 int index1 = address.indexOf("<"); 62 int index2 = address.indexOf(">"); 63 64 if (index1 != -1) { 65 String str = address.substring(0, index1 + 1); 66 list[0] = new JLabel (str); 67 add(list[0]); 68 69 str = address.substring(index1 + 1, index2); 70 list[1] = new LinkLabel(str); 71 list[1].addMouseListener(this); 72 add(list[1]); 73 74 str = address.substring(index2, address.length()); 75 list[2] = new JLabel (str); 76 add(list[2]); 77 } else { 79 String str = address; 80 81 int index = str.indexOf(","); 82 83 if (index != -1) { 84 list[0] = new JLabel (); 86 add(list[0]); 87 88 list[1] = new LinkLabel(str.substring(0, index)); 89 list[1].addMouseListener(this); 90 add(list[1]); 91 92 list[2] = new JLabel (str.substring(index, str.length())); 93 add(list[2]); 94 } else { 95 list[0] = new JLabel (); 96 add(list[0]); 97 98 list[1] = new LinkLabel(str); 99 list[1].addMouseListener(this); 100 add(list[1]); 101 } 102 } 103 } 104 105 public void setIcon(ImageIcon icon) { 106 if (list[0] != null) { 108 list[0].setIcon(icon); 109 } 110 } 111 112 public void mouseClicked(MouseEvent e) { 113 popup.show(e.getComponent(), e.getX(), e.getY()); 114 } 115 116 public void mouseEntered(MouseEvent e) { 117 } 118 119 public void mouseExited(MouseEvent e) { 120 } 121 122 public void mousePressed(MouseEvent e) { 123 } 124 125 public void mouseReleased(MouseEvent e) { 126 } 127 } 128 | Popular Tags |