KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > dialog > importfilter > PluginListCellRenderer


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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 JavaDoc;
19
20 import javax.swing.DefaultListCellRenderer JavaDoc;
21 import javax.swing.JList JavaDoc;
22 import javax.swing.UIManager JavaDoc;
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
31 public class PluginListCellRenderer extends DefaultListCellRenderer JavaDoc {
32     protected IExtensionHandler pluginHandler;
33
34     public PluginListCellRenderer() {
35         super();
36
37         try {
38             pluginHandler = PluginManager.getInstance().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 JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
49         int index, boolean isSelected, boolean cellHasFocus) {
50         if (isSelected) {
51             setBackground(list.getSelectionBackground());
52             setForeground(list.getSelectionForeground());
53         } else {
54             setBackground(list.getBackground());
55             setForeground(list.getForeground());
56         }
57
58         setBorder((cellHasFocus)
59             ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
60
61         // id = org.columba.example.HelloWorld$HelloWorldPlugin
62
String JavaDoc id = (String JavaDoc) value;
63         IExtension extension = pluginHandler.getExtension(id);
64         String JavaDoc userVisibleName = extension.getMetadata().getId();
65         setText(userVisibleName);
66
67         return this;
68     }
69 }
70
Popular Tags