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.action;
017:
018: import java.awt.Toolkit;
019: import java.awt.event.ActionEvent;
020: import java.awt.event.KeyEvent;
021: import java.nio.charset.Charset;
022:
023: import javax.swing.KeyStroke;
024:
025: import org.columba.core.base.OSInfo;
026: import org.columba.api.gui.frame.IFrameMediator;
027: import org.columba.api.selection.ISelectionListener;
028: import org.columba.api.selection.SelectionChangedEvent;
029: import org.columba.core.charset.CharsetOwnerInterface;
030: import org.columba.core.command.CommandProcessor;
031: import org.columba.core.gui.action.AbstractColumbaAction;
032: import org.columba.core.resourceloader.GlobalResourceLoader;
033: import org.columba.core.resourceloader.ImageLoader;
034: import org.columba.mail.command.IMailFolderCommandReference;
035: import org.columba.mail.folder.command.PrintMessageCommand;
036: import org.columba.mail.gui.frame.AbstractMailFrameController;
037: import org.columba.mail.gui.frame.MailFrameMediator;
038: import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
039:
040: public class PrintAction extends AbstractColumbaAction implements
041: ISelectionListener {
042: public PrintAction(IFrameMediator controller) {
043: super (controller, GlobalResourceLoader.getString("global",
044: "global", "menu_message_print"));
045:
046: // tooltip text
047: putValue(SHORT_DESCRIPTION, GlobalResourceLoader.getString(
048: "global", "global", "menu_message_print_tooltip")
049: .replaceAll("&", ""));
050:
051: // small icon for menu
052: putValue(SMALL_ICON, ImageLoader.getSmallIcon("printer.png"));
053:
054: // large icon for toolbar
055: putValue(LARGE_ICON, ImageLoader.getIcon("printer.png"));
056:
057: //TODO: Test Mac keyboard accelerator changes done here by mlivingstone
058: // shortcut key
059: /*if(OSInfo.isMac())
060: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P,
061: ActionEvent.META_MASK));
062: else*/
063: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P,
064: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
065:
066: // *20030614, karlpeder* In main view only enabled when
067: // message(s) selected
068: if (frameMediator instanceof AbstractMailFrameController) {
069: ((AbstractMailFrameController) frameMediator)
070: .registerTableSelectionListener(this );
071: }
072:
073: setEnabled(false);
074: }
075:
076: /*
077: * (non-Javadoc)
078: *
079: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
080: */
081: public void actionPerformed(ActionEvent evt) {
082: IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
083: .getTableSelection();
084:
085: Charset charset = ((CharsetOwnerInterface) getFrameMediator())
086: .getCharset();
087: PrintMessageCommand c = new PrintMessageCommand(r, charset);
088: CommandProcessor.getInstance().addOp(c);
089: }
090:
091: /**
092: * Ensures that the action is only enabled when at least one message is
093: * selected in the GUI.
094: *
095: * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
096: */
097: public void selectionChanged(SelectionChangedEvent e) {
098: setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
099: }
100: }
|