001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.composer;
017:
018: import java.awt.Component;
019:
020: import javax.swing.BorderFactory;
021: import javax.swing.ImageIcon;
022: import javax.swing.JComboBox;
023: import javax.swing.JLabel;
024: import javax.swing.JList;
025: import javax.swing.ListCellRenderer;
026:
027: import org.columba.mail.resourceloader.MailImageLoader;
028: import org.columba.mail.util.MailResourceLoader;
029:
030: /**
031: * @author frd
032: *
033: * To change this generated comment edit the template variable "typecomment":
034: * Window>Preferences>Java>Templates.
035: * To enable and disable the creation of type comments go to
036: * Window>Preferences>Java>Code Generation.
037: */
038: public class PriorityView extends JComboBox {
039: private static final String[] priorities = {
040: MailResourceLoader.getString("dialog", "composer",
041: "highest"),
042: MailResourceLoader.getString("dialog", "composer", "high"),
043: MailResourceLoader
044: .getString("dialog", "composer", "normal"),
045: MailResourceLoader.getString("dialog", "composer", "low"),
046: MailResourceLoader
047: .getString("dialog", "composer", "lowest") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
048: PriorityController controller;
049:
050: public PriorityView(PriorityController controller) {
051: super (priorities);
052: this .controller = controller;
053:
054: setRenderer(new ComboBoxRenderer());
055:
056: setSelectedIndex(2);
057: }
058:
059: public void installListener(PriorityController controller) {
060: addItemListener(controller);
061: }
062:
063: class ComboBoxRenderer extends JLabel implements ListCellRenderer {
064: private ImageIcon image1 = MailImageLoader
065: .getSmallIcon("priority-high.png");
066:
067: //private ImageIcon image2 = null;
068: //private ImageIcon image3 = null;
069: private ImageIcon image4 = MailImageLoader
070: .getSmallIcon("priority-low.png");
071:
072: public ComboBoxRenderer() {
073: setOpaque(true);
074: }
075:
076: public Component getListCellRendererComponent(JList list,
077: Object value, int index, boolean isSelected,
078: boolean cellHasFocus) {
079: if (isSelected) {
080: setBackground(list.getSelectionBackground());
081: setForeground(list.getSelectionForeground());
082: } else {
083: setBackground(list.getBackground());
084: setForeground(list.getForeground());
085: }
086:
087: String p = (String) value;
088:
089: if (p == null) {
090: return this ;
091: }
092:
093: if (p.equals("Highest")) {
094: setIcon(image1);
095: }
096: /*
097: else if ( p.equals("High") )
098: setIcon( image2 );
099: */
100: /*
101: else if ( p.equals("Low") )
102: setIcon( image3 );
103: */
104: else if (p.equals("Lowest")) {
105: setIcon(image4);
106: } else {
107: setIcon(null);
108: }
109:
110: if (getIcon() == null) {
111: setBorder(BorderFactory.createEmptyBorder(0, image1
112: .getIconWidth()
113: + getIconTextGap(), 0, 0));
114: } else {
115: setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
116: }
117:
118: setText((String) value);
119:
120: return this;
121: }
122: }
123: }
|