001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.message.action;
019:
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022: import java.util.Observable;
023: import java.util.Observer;
024:
025: import javax.swing.ButtonGroup;
026: import javax.swing.JRadioButtonMenuItem;
027:
028: import org.columa.core.config.IDefaultItem;
029: import org.columba.api.gui.frame.IFrameMediator;
030: import org.columba.core.config.DefaultItem;
031: import org.columba.core.gui.menu.IMenu;
032: import org.columba.core.xml.XmlElement;
033: import org.columba.mail.config.MailConfig;
034:
035: /**
036: * Submenu containing three choices: Show default headers, show custom headers
037: * and show all available headers.
038: *
039: * @author fdietz
040: */
041: public class HeadersMenu extends IMenu implements ActionListener,
042: Observer {
043:
044: private XmlElement element;
045:
046: private JRadioButtonMenuItem defaultMenuItem;
047:
048: private JRadioButtonMenuItem customMenuItem;
049:
050: private JRadioButtonMenuItem allMenuItem;
051:
052: /**
053: * @param controller
054: * @param caption
055: */
056: public HeadersMenu(IFrameMediator controller) {
057: super (controller, "Show Headers", "show_headers_menu");
058:
059: ButtonGroup group = new ButtonGroup();
060:
061: defaultMenuItem = new JRadioButtonMenuItem("Default");
062: defaultMenuItem.setActionCommand("DEFAULT");
063: defaultMenuItem.addActionListener(this );
064: group.add(defaultMenuItem);
065:
066: add(defaultMenuItem);
067:
068: customMenuItem = new JRadioButtonMenuItem("Custom");
069: customMenuItem.setActionCommand("CUSTOM");
070: customMenuItem.addActionListener(this );
071: group.add(customMenuItem);
072: add(customMenuItem);
073:
074: allMenuItem = new JRadioButtonMenuItem("Compact");
075: allMenuItem.setActionCommand("ALL");
076: allMenuItem.addActionListener(this );
077: group.add(allMenuItem);
078: add(allMenuItem);
079:
080: element = MailConfig.getInstance().get("options").getElement(
081: "/options/headerviewer");
082: element.addObserver(this );
083:
084: update(element, null);
085: }
086:
087: public void actionPerformed(ActionEvent e) {
088: String action = e.getActionCommand();
089:
090: if (action.equals("DEFAULT")) {
091: element.addAttribute("style", "0");
092:
093: new ViewMessageAction(getFrameMediator())
094: .actionPerformed(null);
095: } else if (action.equals("CUSTOM")) {
096: element.addAttribute("style", "1");
097:
098: new ViewMessageAction(getFrameMediator())
099: .actionPerformed(null);
100: } else if (action.equals("ALL")) {
101: element.addAttribute("style", "2");
102:
103: new ViewMessageAction(getFrameMediator())
104: .actionPerformed(null);
105: }
106: }
107:
108: /**
109: * Method is called when configuration changes.
110: *
111: * @param arg0
112: * @param arg1
113: */
114: public void update(Observable arg0, Object arg1) {
115: IDefaultItem item = new DefaultItem(element);
116: int style = item.getIntegerWithDefault("style", 0);
117: switch (style) {
118: case 0:
119: defaultMenuItem.setSelected(true);
120: break;
121: case 1:
122: customMenuItem.setSelected(true);
123: break;
124: case 2:
125: allMenuItem.setSelected(true);
126: break;
127: }
128: }
129: }
|