KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > action > HeadersMenu


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.gui.message.action;
19
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.util.Observable JavaDoc;
23 import java.util.Observer JavaDoc;
24
25 import javax.swing.ButtonGroup JavaDoc;
26 import javax.swing.JRadioButtonMenuItem JavaDoc;
27
28 import org.columa.core.config.IDefaultItem;
29 import org.columba.api.gui.frame.IFrameMediator;
30 import org.columba.core.config.DefaultItem;
31 import org.columba.core.gui.menu.IMenu;
32 import org.columba.core.xml.XmlElement;
33 import org.columba.mail.config.MailConfig;
34
35 /**
36  * Submenu containing three choices: Show default headers, show custom headers
37  * and show all available headers.
38  *
39  * @author fdietz
40  */

41 public class HeadersMenu extends IMenu implements ActionListener JavaDoc, Observer JavaDoc {
42
43     private XmlElement element;
44
45     private JRadioButtonMenuItem JavaDoc defaultMenuItem;
46
47     private JRadioButtonMenuItem JavaDoc customMenuItem;
48
49     private JRadioButtonMenuItem JavaDoc allMenuItem;
50     
51     /**
52      * @param controller
53      * @param caption
54      */

55     public HeadersMenu(IFrameMediator controller) {
56         super(controller, "Show Headers","show_headers_menu");
57
58         ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
59
60         defaultMenuItem = new JRadioButtonMenuItem JavaDoc("Default");
61         defaultMenuItem.setActionCommand("DEFAULT");
62         defaultMenuItem.addActionListener(this);
63         group.add(defaultMenuItem);
64
65         add(defaultMenuItem);
66
67         customMenuItem = new JRadioButtonMenuItem JavaDoc("Custom");
68         customMenuItem.setActionCommand("CUSTOM");
69         customMenuItem.addActionListener(this);
70         group.add(customMenuItem);
71         add(customMenuItem);
72
73         allMenuItem = new JRadioButtonMenuItem JavaDoc("Compact");
74         allMenuItem.setActionCommand("ALL");
75         allMenuItem.addActionListener(this);
76         group.add(allMenuItem);
77         add(allMenuItem);
78
79         element = MailConfig.getInstance().get("options").getElement(
80                 "/options/headerviewer");
81         element.addObserver(this);
82
83         update(element, null);
84     }
85
86     public void actionPerformed(ActionEvent JavaDoc e) {
87         String JavaDoc action = e.getActionCommand();
88
89         if (action.equals("DEFAULT")) {
90             element.addAttribute("style", "0");
91
92             new ViewMessageAction(getFrameMediator()).actionPerformed(null);
93         } else if (action.equals("CUSTOM")) {
94             element.addAttribute("style", "1");
95
96             new ViewMessageAction(getFrameMediator()).actionPerformed(null);
97         } else if (action.equals("ALL")) {
98             element.addAttribute("style", "2");
99
100             new ViewMessageAction(getFrameMediator()).actionPerformed(null);
101         }
102     }
103
104     /**
105      * Method is called when configuration changes.
106      *
107      * @param arg0
108      * @param arg1
109      */

110     public void update(Observable JavaDoc arg0, Object JavaDoc arg1) {
111         IDefaultItem item = new DefaultItem(element);
112         int style = item.getIntegerWithDefault("style", 0);
113         switch (style) {
114         case 0:
115             defaultMenuItem.setSelected(true);
116             break;
117         case 1:
118             customMenuItem.setSelected(true);
119             break;
120         case 2:
121             allMenuItem.setSelected(true);
122             break;
123         }
124     }
125 }
Popular Tags