001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.gui.util;
017:
018: import java.awt.event.MouseEvent;
019: import java.awt.event.MouseListener;
020:
021: import javax.swing.BoxLayout;
022: import javax.swing.ImageIcon;
023: import javax.swing.JLabel;
024: import javax.swing.JPanel;
025: import javax.swing.JPopupMenu;
026:
027: import org.columba.core.gui.base.LinkLabel;
028:
029: public class AddressLabel extends JPanel implements MouseListener //, ActionListener
030: {
031: private String address;
032: private JLabel[] list = new JLabel[3];
033:
034: private JPopupMenu popup;
035:
036: public AddressLabel(String str) {
037: super ();
038:
039: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
040: setBorder(null);
041: this .address = str;
042:
043: parse();
044:
045: URLController controller = new URLController();
046:
047: if (list[1] != null) {
048: controller.setAddress(list[1].getText());
049: popup = controller.createContactMenu(list[1].getText());
050: } else {
051: controller.setAddress(address);
052: popup = controller.createContactMenu(address);
053: }
054: }
055:
056: protected void parse() {
057: int index1 = address.indexOf("<");
058: int index2 = address.indexOf(">");
059:
060: if (index1 != -1) {
061: String str = address.substring(0, index1 + 1);
062: list[0] = new JLabel(str);
063: add(list[0]);
064:
065: str = address.substring(index1 + 1, index2);
066: list[1] = new LinkLabel(str);
067: list[1].addMouseListener(this );
068: add(list[1]);
069:
070: str = address.substring(index2, address.length());
071: list[2] = new JLabel(str);
072: add(list[2]);
073: } else //if ( address.indexOf("@") != -1 )
074: {
075: String str = address;
076:
077: int index = str.indexOf(",");
078:
079: if (index != -1) {
080: // we got this from headerfieldtree
081: list[0] = new JLabel();
082: add(list[0]);
083:
084: list[1] = new LinkLabel(str.substring(0, index));
085: list[1].addMouseListener(this );
086: add(list[1]);
087:
088: list[2] = new JLabel(str.substring(index, str.length()));
089: add(list[2]);
090: } else {
091: list[0] = new JLabel();
092: add(list[0]);
093:
094: list[1] = new LinkLabel(str);
095: list[1].addMouseListener(this );
096: add(list[1]);
097: }
098: }
099: }
100:
101: public void setIcon(ImageIcon icon) {
102: //list[2].setHorizontalTextPosition( JLabel.LEADING );
103: if (list[0] != null) {
104: list[0].setIcon(icon);
105: }
106: }
107:
108: public void mouseClicked(MouseEvent e) {
109: popup.show(e.getComponent(), e.getX(), e.getY());
110: }
111:
112: public void mouseEntered(MouseEvent e) {
113: }
114:
115: public void mouseExited(MouseEvent e) {
116: }
117:
118: public void mousePressed(MouseEvent e) {
119: }
120:
121: public void mouseReleased(MouseEvent e) {
122: }
123: }
|