001: package org.columba.addressbook.gui.context;
002:
003: import java.awt.Color;
004: import java.awt.Font;
005: import java.awt.Point;
006: import java.awt.event.ActionEvent;
007: import java.awt.event.ActionListener;
008: import java.awt.event.MouseAdapter;
009: import java.awt.event.MouseEvent;
010: import java.util.Iterator;
011:
012: import javax.swing.BorderFactory;
013: import javax.swing.JLabel;
014: import javax.swing.JMenuItem;
015: import javax.swing.JPanel;
016: import javax.swing.JPopupMenu;
017: import javax.swing.UIManager;
018: import javax.swing.border.Border;
019:
020: import org.columba.addressbook.facade.DialogFacade;
021: import org.columba.addressbook.model.IContactModel;
022: import org.columba.addressbook.model.PhoneModel;
023: import org.columba.api.exception.ServiceNotFoundException;
024: import org.columba.contact.search.ContactSearchResult;
025: import org.columba.core.facade.ServiceFacadeRegistry;
026: import org.columba.core.gui.base.RoundedBorder;
027: import org.columba.core.resourceloader.ImageLoader;
028: import org.columba.mail.facade.IDialogFacade;
029: import org.jdesktop.swingx.JXHyperlink;
030:
031: import com.jgoodies.forms.factories.FormFactory;
032: import com.jgoodies.forms.layout.CellConstraints;
033: import com.jgoodies.forms.layout.ColumnSpec;
034: import com.jgoodies.forms.layout.FormLayout;
035: import com.jgoodies.forms.layout.RowSpec;
036:
037: public class ContactDetailPanel extends JPanel {
038:
039: private static final String NOT_AVAIL = "n/a";
040:
041: private JLabel pictureLabel;
042:
043: private JLabel label1;
044:
045: private JXHyperlink label2;
046:
047: private JXHyperlink label5;
048:
049: private JLabel label9;
050:
051: private JLabel label10;
052:
053: private JLabel label12;
054:
055: private JLabel label13;
056:
057: private JLabel label4;
058:
059: private JLabel label11;
060:
061: private JLabel label7;
062:
063: private JLabel label8;
064:
065: private JPopupMenu contextMenu;
066:
067: private final IContactModel model;
068:
069: private final ContactSearchResult searchResult;
070:
071: public ContactDetailPanel(final IContactModel model,
072: final ContactSearchResult searchResult) {
073: this .model = model;
074: this .searchResult = searchResult;
075:
076: setBackground(UIManager.getColor("TextField.background"));
077:
078: Border b = BorderFactory.createCompoundBorder(
079: new RoundedBorder(new Color(220, 220, 220)),
080: BorderFactory.createEmptyBorder(4, 4, 4, 4));
081: Border b2 = BorderFactory.createCompoundBorder(BorderFactory
082: .createEmptyBorder(4, 4, 4, 4), b);
083: setBorder(b2);
084:
085: initComponents();
086:
087: pictureLabel.setIcon(ImageLoader.getMiscIcon("malehead.png"));
088: pictureLabel.setHorizontalAlignment(JLabel.CENTER);
089: pictureLabel.setBorder(BorderFactory.createCompoundBorder(
090: new RoundedBorder(new Color(220, 220, 220)),
091: BorderFactory.createEmptyBorder(4, 4, 4, 4)));
092:
093: if (model.getFormattedName() != null)
094: label1.setText(model.getFormattedName());
095: else
096: label1.setText(NOT_AVAIL);
097:
098: label1.setFont(label1.getFont().deriveFont(Font.BOLD));
099: if (model.getPreferredEmail() != null) {
100: label2.setText(model.getPreferredEmail());
101: label2.addActionListener(new ActionListener() {
102: public void actionPerformed(ActionEvent event) {
103: try {
104: IDialogFacade facade = (IDialogFacade) ServiceFacadeRegistry
105: .getInstance()
106: .getService(
107: org.columba.mail.facade.IDialogFacade.class);
108: facade.openComposer(model.getPreferredEmail());
109: } catch (ServiceNotFoundException e) {
110: e.printStackTrace();
111: }
112: }
113: });
114: } else
115: label2.setText(NOT_AVAIL);
116: if (model.getHomePage() != null)
117: label5.setText(model.getHomePage());
118: else
119: label5.setText(NOT_AVAIL);
120:
121: label9.setText("Birthday:");
122: if (model.getBirthday() != null)
123: label10.setText(model.getBirthday().toLocaleString());
124: else
125: label10.setText(NOT_AVAIL);
126:
127: label12.setText("Phone Home:");
128: label4.setText("Phone Work:");
129: label11.setText(NOT_AVAIL);
130: label13.setText(NOT_AVAIL);
131: Iterator it = model.getPhoneIterator();
132: while (it.hasNext()) {
133: PhoneModel phoneModel = (PhoneModel) it.next();
134: if (phoneModel.getType() == PhoneModel.TYPE_HOME_PHONE)
135: label13.setText(phoneModel.getNumber());
136: if (phoneModel.getType() == PhoneModel.TYPE_BUSINESS_PHONE)
137: label11.setText(phoneModel.getNumber());
138: }
139: if (model.getPreferredInstantMessaging() != null)
140: label7.setText(model.getPreferredInstantMessaging() + ":");
141: else
142: label7.setText("No IM available");
143:
144: // TODO: real IM status here
145: label8.setText(NOT_AVAIL);
146:
147: addMouseListener(new MyMouseListener());
148: }
149:
150: private void initComponents() {
151: pictureLabel = new JLabel();
152: label1 = new JLabel();
153: label2 = new JXHyperlink();
154: label5 = new JXHyperlink();
155: label9 = new JLabel();
156: label10 = new JLabel();
157: label12 = new JLabel();
158: label13 = new JLabel();
159: label4 = new JLabel();
160: label11 = new JLabel();
161: label7 = new JLabel();
162: label8 = new JLabel();
163:
164: CellConstraints cc = new CellConstraints();
165:
166: // ======== this ========
167: setLayout(new FormLayout(new ColumnSpec[] {
168: FormFactory.DEFAULT_COLSPEC,
169: FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
170: FormFactory.DEFAULT_COLSPEC }, new RowSpec[] {
171: FormFactory.DEFAULT_ROWSPEC,
172: FormFactory.LINE_GAP_ROWSPEC,
173: FormFactory.DEFAULT_ROWSPEC,
174: FormFactory.LINE_GAP_ROWSPEC,
175: FormFactory.DEFAULT_ROWSPEC,
176: FormFactory.LINE_GAP_ROWSPEC,
177: FormFactory.DEFAULT_ROWSPEC,
178: FormFactory.LINE_GAP_ROWSPEC,
179: FormFactory.DEFAULT_ROWSPEC,
180: FormFactory.LINE_GAP_ROWSPEC,
181: FormFactory.DEFAULT_ROWSPEC,
182: FormFactory.LINE_GAP_ROWSPEC,
183: FormFactory.DEFAULT_ROWSPEC,
184: FormFactory.LINE_GAP_ROWSPEC,
185: FormFactory.DEFAULT_ROWSPEC }));
186: add(pictureLabel, cc.xywh(1, 1, 1, 7, CellConstraints.FILL,
187: CellConstraints.FILL));
188:
189: add(label1, cc.xy(3, 1));
190:
191: add(label2, cc.xy(3, 3));
192:
193: add(label5, cc.xy(3, 5));
194:
195: add(label9, cc.xywh(1, 9, 1, 1, CellConstraints.RIGHT,
196: CellConstraints.DEFAULT));
197:
198: add(label10, cc.xywh(3, 9, 1, 1, CellConstraints.FILL,
199: CellConstraints.DEFAULT));
200:
201: add(label12, cc.xywh(1, 11, 1, 1, CellConstraints.RIGHT,
202: CellConstraints.DEFAULT));
203:
204: add(label13, cc.xywh(3, 11, 1, 1, CellConstraints.FILL,
205: CellConstraints.DEFAULT));
206:
207: add(label4, cc.xywh(1, 13, 1, 1, CellConstraints.RIGHT,
208: CellConstraints.DEFAULT));
209:
210: add(label11, cc.xywh(3, 13, 1, 1, CellConstraints.FILL,
211: CellConstraints.DEFAULT));
212:
213: add(label7, cc.xywh(1, 15, 1, 1, CellConstraints.RIGHT,
214: CellConstraints.DEFAULT));
215:
216: add(label8, cc.xywh(3, 15, 1, 1, CellConstraints.FILL,
217: CellConstraints.DEFAULT));
218: }
219:
220: private JPopupMenu getPopupMenu() {
221: if (contextMenu != null)
222: return contextMenu;
223:
224: contextMenu = new JPopupMenu();
225:
226: JMenuItem item = new JMenuItem("Open..");
227: item.addActionListener(new ActionListener() {
228: public void actionPerformed(ActionEvent event) {
229: new DialogFacade().openContactDialog(searchResult
230: .getLocation());
231: }
232: });
233: contextMenu.add(item);
234:
235: item = new JMenuItem("Compose Message..");
236: item.addActionListener(new ActionListener() {
237: public void actionPerformed(ActionEvent event) {
238:
239: String address = model.getPreferredEmail();
240:
241: try {
242: IDialogFacade facade = (IDialogFacade) ServiceFacadeRegistry
243: .getInstance()
244: .getService(
245: org.columba.mail.facade.IDialogFacade.class);
246: facade.openComposer(address);
247: } catch (ServiceNotFoundException e) {
248: e.printStackTrace();
249: }
250: }
251: });
252:
253: contextMenu.add(item);
254: return contextMenu;
255: }
256:
257: class MyMouseListener extends MouseAdapter {
258:
259: @Override
260: public void mouseClicked(MouseEvent e) {
261: handleEvent(e);
262: }
263:
264: @Override
265: public void mousePressed(MouseEvent e) {
266: handlePopupEvent(e);
267: }
268:
269: @Override
270: public void mouseReleased(MouseEvent e) {
271: handlePopupEvent(e);
272: }
273:
274: /**
275: * @param e
276: */
277: private void handlePopupEvent(MouseEvent e) {
278: Point p = e.getPoint();
279: if (e.isPopupTrigger()) {
280: // show context menu
281: getPopupMenu().show(e.getComponent(), p.x, p.y);
282: }
283: }
284:
285: /**
286: * @param e
287: */
288: private void handleEvent(MouseEvent e) {
289: }
290: }
291:
292: }
|