01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.mail.gui.composer.contact;
19:
20: import java.awt.Component;
21: import java.util.Iterator;
22:
23: import javax.swing.DefaultListCellRenderer;
24: import javax.swing.JComboBox;
25: import javax.swing.JList;
26:
27: import org.columba.addressbook.facade.IFolderFacade;
28:
29: import org.columba.addressbook.facade.IFolder;
30: import org.columba.api.exception.ServiceNotFoundException;
31: import org.columba.mail.connector.ServiceConnector;
32:
33: public class FolderComboBox extends JComboBox {
34:
35: public FolderComboBox(boolean showRootFolders) {
36: super ();
37:
38: IFolderFacade folderFacade = null;
39: try {
40: folderFacade = ServiceConnector.getFolderFacade();
41: Iterator<IFolder> it = folderFacade.getAllFolders()
42: .listIterator();
43:
44: while (it.hasNext()) {
45: IFolder folder = it.next();
46: if (!showRootFolders) {
47: //if (folder instanceof IContactFolder)
48: addItem(folder);
49: }
50: }
51:
52: } catch (ServiceNotFoundException e) {
53: e.printStackTrace();
54: }
55:
56: setRenderer(new MyListCellRenderer());
57: }
58:
59: class MyListCellRenderer extends DefaultListCellRenderer {
60:
61: MyListCellRenderer() {
62:
63: }
64:
65: /**
66: * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList,
67: * java.lang.Object, int, boolean, boolean)
68: */
69: @Override
70: public Component getListCellRendererComponent(JList list,
71: Object value, int index, boolean isSelected,
72: boolean cellHasFocus) {
73:
74: super .getListCellRendererComponent(list, value, index,
75: isSelected, cellHasFocus);
76:
77: IFolder folder = (IFolder) value;
78:
79: setText(folder.getName());
80: setIcon(folder.getIcon());
81:
82: return this;
83: }
84:
85: }
86: }
|