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.addressbook.gui.base;
19:
20: import java.awt.Component;
21: import java.util.Iterator;
22: import java.util.Vector;
23:
24: import javax.swing.DefaultListCellRenderer;
25: import javax.swing.JComboBox;
26: import javax.swing.JList;
27:
28: import org.columba.addressbook.folder.IContactFolder;
29: import org.columba.addressbook.folder.IFolder;
30: import org.columba.addressbook.gui.tree.AddressbookTreeModel;
31:
32: public class FolderComboBox extends JComboBox {
33:
34: public FolderComboBox(boolean showRootFolders) {
35: super ();
36:
37: AddressbookTreeModel model = AddressbookTreeModel.getInstance();
38: Vector<IFolder> v = new Vector<IFolder>();
39:
40: Object parent = model.getRoot();
41:
42: getChildren(model, parent, v);
43:
44: Iterator<IFolder> it = v.listIterator();
45:
46: while (it.hasNext()) {
47: IFolder folder = it.next();
48: if (!showRootFolders) {
49: if (folder instanceof IContactFolder)
50: addItem(folder);
51: }
52: }
53:
54: setRenderer(new MyListCellRenderer());
55: }
56:
57: private void getChildren(AddressbookTreeModel model, Object parent,
58: Vector<IFolder> v) {
59: int childCount = model.getChildCount(parent);
60: for (int i = 0; i < childCount; i++) {
61: Object child = model.getChild(parent, i);
62: v.add((IFolder) child);
63:
64: getChildren(model, child, v);
65: }
66: }
67:
68: class MyListCellRenderer extends DefaultListCellRenderer {
69:
70: MyListCellRenderer() {
71:
72: }
73:
74: /**
75: * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList,
76: * java.lang.Object, int, boolean, boolean)
77: */
78: @Override
79: public Component getListCellRendererComponent(JList list,
80: Object value, int index, boolean isSelected,
81: boolean cellHasFocus) {
82:
83: super .getListCellRendererComponent(list, value, index,
84: isSelected, cellHasFocus);
85:
86: IFolder folder = (IFolder) value;
87:
88: setText(folder.getName());
89: setIcon(folder.getIcon());
90:
91: return this;
92: }
93:
94: }
95: }
|