01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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.addressbook.gui.dialog.importfilter;
17:
18: import java.awt.Component;
19:
20: import javax.swing.DefaultListCellRenderer;
21: import javax.swing.JList;
22: import javax.swing.UIManager;
23:
24: import org.columba.api.plugin.IExtension;
25: import org.columba.api.plugin.IExtensionHandler;
26: import org.columba.api.plugin.PluginHandlerNotFoundException;
27: import org.columba.core.gui.dialog.ErrorDialog;
28: import org.columba.core.plugin.PluginManager;
29:
30: public class PluginListCellRenderer extends DefaultListCellRenderer {
31: protected IExtensionHandler pluginHandler;
32:
33: public PluginListCellRenderer() {
34: super ();
35:
36: try {
37: pluginHandler = PluginManager.getInstance()
38: .getExtensionHandler(
39: "org.columba.addressbook.import");
40: } catch (PluginHandlerNotFoundException ex) {
41: ErrorDialog.createDialog(ex.getMessage(), ex);
42: }
43: }
44:
45: /* (non-Javadoc)
46: * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
47: */
48: public Component getListCellRendererComponent(JList list,
49: Object value, int index, boolean isSelected,
50: boolean cellHasFocus) {
51: if (isSelected) {
52: setBackground(list.getSelectionBackground());
53: setForeground(list.getSelectionForeground());
54: } else {
55: setBackground(list.getBackground());
56: setForeground(list.getForeground());
57: }
58:
59: setBorder((cellHasFocus) ? UIManager
60: .getBorder("List.focusCellHighlightBorder")
61: : noFocusBorder);
62:
63: // id = org.columba.example.HelloWorld$HelloWorldPlugin
64: String id = (String) value;
65: IExtension extension = pluginHandler.getExtension(id);
66: String userVisibleName = extension.getMetadata().getId();
67: setText(userVisibleName);
68:
69: return this;
70: }
71: }
|