KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > util > AddressLabel


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.gui.util;
17
18 import java.awt.event.MouseEvent JavaDoc;
19 import java.awt.event.MouseListener JavaDoc;
20
21 import javax.swing.BoxLayout JavaDoc;
22 import javax.swing.ImageIcon JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.JPopupMenu JavaDoc;
26
27 import org.columba.core.gui.base.LinkLabel;
28
29
30
31 public class AddressLabel extends JPanel JavaDoc implements MouseListener JavaDoc //, ActionListener
32
{
33     private String JavaDoc address;
34     private JLabel JavaDoc[] list = new JLabel JavaDoc[3];
35
36   
37     private JPopupMenu JavaDoc popup;
38
39     public AddressLabel(String JavaDoc str) {
40         super();
41
42         
43         setLayout(new BoxLayout JavaDoc(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 JavaDoc str = address.substring(0, index1 + 1);
66             list[0] = new JLabel JavaDoc(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 JavaDoc(str);
76             add(list[2]);
77         } else //if ( address.indexOf("@") != -1 )
78
{
79             String JavaDoc str = address;
80
81             int index = str.indexOf(",");
82
83             if (index != -1) {
84                 // we got this from headerfieldtree
85
list[0] = new JLabel JavaDoc();
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 JavaDoc(str.substring(index, str.length()));
93                 add(list[2]);
94             } else {
95                 list[0] = new JLabel JavaDoc();
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 JavaDoc icon) {
106         //list[2].setHorizontalTextPosition( JLabel.LEADING );
107
if (list[0] != null) {
108             list[0].setIcon(icon);
109         }
110     }
111
112     public void mouseClicked(MouseEvent JavaDoc e) {
113         popup.show(e.getComponent(), e.getX(), e.getY());
114     }
115
116     public void mouseEntered(MouseEvent JavaDoc e) {
117     }
118
119     public void mouseExited(MouseEvent JavaDoc e) {
120     }
121
122     public void mousePressed(MouseEvent JavaDoc e) {
123     }
124
125     public void mouseReleased(MouseEvent JavaDoc e) {
126     }
127 }
128
Popular Tags