KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > mailboximport > 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.mail.gui.config.mailboximport;
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 import org.columba.mail.plugin.IExtensionHandlerKeys;
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()
39                     .getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_MAIL_IMPORT);
40         } catch (PluginHandlerNotFoundException ex) {
41             ErrorDialog.createDialog(ex.getMessage(), ex);
42         }
43     }
44
45     /*
46      * (non-Javadoc)
47      *
48      * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList,
49      * java.lang.Object, int, boolean, boolean)
50      */

51     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
52             int index, boolean isSelected, boolean cellHasFocus) {
53         if (isSelected) {
54             setBackground(list.getSelectionBackground());
55             setForeground(list.getSelectionForeground());
56         } else {
57             setBackground(list.getBackground());
58             setForeground(list.getForeground());
59         }
60
61         setBorder((cellHasFocus) ? UIManager
62                 .getBorder("List.focusCellHighlightBorder") : noFocusBorder);
63
64         // id = org.columba.example.HelloWorld$HelloWorldPlugin
65
String JavaDoc id = (String JavaDoc) value;
66         IExtension extension = pluginHandler.getExtension(id);
67         String JavaDoc userVisibleName = extension.getMetadata().getId();
68         setText(userVisibleName);
69
70         return this;
71     }
72 }
73
Popular Tags