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.event.ItemEvent;
019: import java.awt.event.ItemListener;
020:
021: import org.columba.mail.config.AccountItem;
022: import org.columba.mail.config.AccountList;
023: import org.columba.mail.config.MailConfig;
024:
025: /**
026: * Account chooser component.
027: *
028: * @author frd
029: */
030: public class AccountController implements ItemListener {
031: private AccountView view;
032:
033: private ComposerController controller;
034:
035: public AccountController(ComposerController controller) {
036: this .controller = controller;
037:
038: view = new AccountView(this );
039:
040: AccountList config = MailConfig.getInstance().getAccountList();
041:
042: for (int i = 0; i < config.count(); i++) {
043: AccountItem accountItem = config.get(i);
044: view.addItem(accountItem);
045:
046: if (accountItem.isDefault()) {
047: view.setSelectedItem(accountItem);
048: controller.getModel().setAccountItem(accountItem);
049: }
050: }
051:
052: view.addItemListener(this );
053: }
054:
055: /*
056: * public void setSecurityMenuItems( JCheckBoxMenuItem signItem,
057: * JCheckBoxMenuItem encryptItem) { signMenuItem = signItem; encryptMenuItem =
058: * encryptItem;
059: *
060: * AccountItem item = (AccountItem) view.getSelectedItem();
061: *
062: * SecurityItem pgpItem = item.getPGPItem(); if(
063: * pgpItem.getBoolean("enabled") ) { signMenuItem.setEnabled(true);
064: * encryptMenuItem.setEnabled(true);
065: *
066: * model.setSignMessage(pgpItem.getBoolean("always_sign"));
067: * model.setEncryptMessage(pgpItem.getBoolean("always_encrypt")); } }
068: */
069: public void itemStateChanged(ItemEvent e) {
070: if (e.getStateChange() == ItemEvent.SELECTED) {
071: updateComponents(false);
072:
073: }
074: }
075:
076: public void updateComponents(boolean b) {
077: if (b) {
078: view
079: .setSelectedItem(((ComposerModel) controller
080: .getModel()).getAccountItem());
081:
082: /*
083: * encryptMenuItem.setSelected(model.isEncryptMessage());
084: * signMenuItem.setSelected(model.isSignMessage());
085: */
086: } else {
087: ((ComposerModel) controller.getModel())
088: .setAccountItem((AccountItem) view
089: .getSelectedItem());
090:
091: /*
092: * model.setSignMessage(signMenuItem.isSelected());
093: * model.setEncryptMessage(encryptMenuItem.isSelected());
094: */
095: }
096: }
097:
098: /**
099: * @return Returns the view.
100: */
101: public AccountView getView() {
102: return view;
103: }
104: }
|