KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > composer > PriorityView


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.composer;
17
18 import java.awt.Component JavaDoc;
19
20 import javax.swing.BorderFactory JavaDoc;
21 import javax.swing.ImageIcon JavaDoc;
22 import javax.swing.JComboBox JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JList JavaDoc;
25 import javax.swing.ListCellRenderer JavaDoc;
26
27 import org.columba.mail.resourceloader.MailImageLoader;
28 import org.columba.mail.util.MailResourceLoader;
29
30
31 /**
32  * @author frd
33  *
34  * To change this generated comment edit the template variable "typecomment":
35  * Window>Preferences>Java>Templates.
36  * To enable and disable the creation of type comments go to
37  * Window>Preferences>Java>Code Generation.
38  */

39 public class PriorityView extends JComboBox JavaDoc {
40     private static final String JavaDoc[] priorities = {
41         MailResourceLoader.getString("dialog", "composer", "highest"),
42         MailResourceLoader.getString("dialog", "composer", "high"),
43         MailResourceLoader.getString("dialog", "composer", "normal"),
44         MailResourceLoader.getString("dialog", "composer", "low"),
45         MailResourceLoader.getString("dialog", "composer", "lowest")
46     }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
47
PriorityController controller;
48
49     public PriorityView(PriorityController controller) {
50         super(priorities);
51         this.controller = controller;
52
53         setRenderer(new ComboBoxRenderer());
54
55         setSelectedIndex(2);
56     }
57
58     public void installListener(PriorityController controller) {
59         addItemListener(controller);
60     }
61
62      class ComboBoxRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
63         private ImageIcon JavaDoc image1 = MailImageLoader.getSmallIcon(
64                 "priority-high.png");
65
66         //private ImageIcon image2 = null;
67
//private ImageIcon image3 = null;
68
private ImageIcon JavaDoc image4 = MailImageLoader.getSmallIcon(
69                 "priority-low.png");
70
71         public ComboBoxRenderer() {
72             setOpaque(true);
73         }
74
75         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
76             int index, boolean isSelected, boolean cellHasFocus) {
77             if (isSelected) {
78                 setBackground(list.getSelectionBackground());
79                 setForeground(list.getSelectionForeground());
80             } else {
81                 setBackground(list.getBackground());
82                 setForeground(list.getForeground());
83             }
84
85             String JavaDoc p = (String JavaDoc) value;
86
87             if (p == null) {
88                 return this;
89             }
90
91             if (p.equals("Highest")) {
92                 setIcon(image1);
93             }
94             /*
95 else if ( p.equals("High") )
96   setIcon( image2 );
97 */

98             /*
99 else if ( p.equals("Low") )
100     setIcon( image3 );
101  */

102             else if (p.equals("Lowest")) {
103                 setIcon(image4);
104             } else {
105                 setIcon(null);
106             }
107
108             if (getIcon() == null) {
109                 setBorder(BorderFactory.createEmptyBorder(0,
110                         image1.getIconWidth() + getIconTextGap(), 0, 0));
111             } else {
112                 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
113             }
114
115             setText((String JavaDoc) value);
116
117             return this;
118         }
119     }
120 }
121
Popular Tags