KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > action > PrintAction


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.action;
17
18 import java.awt.Toolkit JavaDoc;
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.KeyEvent JavaDoc;
21 import java.nio.charset.Charset JavaDoc;
22
23 import javax.swing.KeyStroke JavaDoc;
24
25 import org.columba.core.base.OSInfo;
26 import org.columba.api.gui.frame.IFrameMediator;
27 import org.columba.api.selection.ISelectionListener;
28 import org.columba.api.selection.SelectionChangedEvent;
29 import org.columba.core.charset.CharsetOwnerInterface;
30 import org.columba.core.command.CommandProcessor;
31 import org.columba.core.gui.action.AbstractColumbaAction;
32 import org.columba.core.resourceloader.GlobalResourceLoader;
33 import org.columba.core.resourceloader.ImageLoader;
34 import org.columba.mail.command.IMailFolderCommandReference;
35 import org.columba.mail.folder.command.PrintMessageCommand;
36 import org.columba.mail.gui.frame.AbstractMailFrameController;
37 import org.columba.mail.gui.frame.MailFrameMediator;
38 import org.columba.mail.gui.table.selection.TableSelectionChangedEvent;
39
40 public class PrintAction extends AbstractColumbaAction implements
41         ISelectionListener {
42     public PrintAction(IFrameMediator controller) {
43         super(controller, GlobalResourceLoader.getString("global", "global",
44                 "menu_message_print"));
45
46         // tooltip text
47
putValue(SHORT_DESCRIPTION, GlobalResourceLoader.getString("global",
48                 "global", "menu_message_print_tooltip").replaceAll("&", ""));
49
50         // small icon for menu
51
putValue(SMALL_ICON, ImageLoader
52                 .getSmallIcon("printer.png"));
53
54         // large icon for toolbar
55
putValue(LARGE_ICON, ImageLoader.getIcon("printer.png"));
56
57         //TODO: Test Mac keyboard accelerator changes done here by mlivingstone
58
// shortcut key
59
/*if(OSInfo.isMac())
60         putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P,
61                 ActionEvent.META_MASK));
62         else*/

63             putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P,
64                     Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
65
66         // *20030614, karlpeder* In main view only enabled when
67
// message(s) selected
68
if (frameMediator instanceof AbstractMailFrameController) {
69             ((AbstractMailFrameController) frameMediator)
70                     .registerTableSelectionListener(this);
71         }
72
73         setEnabled(false);
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
80      */

81     public void actionPerformed(ActionEvent JavaDoc evt) {
82         IMailFolderCommandReference r = ((MailFrameMediator) getFrameMediator())
83                 .getTableSelection();
84
85         Charset JavaDoc charset = ((CharsetOwnerInterface) getFrameMediator())
86                 .getCharset();
87         PrintMessageCommand c = new PrintMessageCommand(r, charset);
88         CommandProcessor.getInstance().addOp(c);
89     }
90
91     /**
92      * Ensures that the action is only enabled when at least one message is
93      * selected in the GUI.
94      *
95      * @see org.columba.core.gui.util.ISelectionListener#selectionChanged(org.columba.core.gui.util.SelectionChangedEvent)
96      */

97     public void selectionChanged(SelectionChangedEvent e) {
98         setEnabled(((TableSelectionChangedEvent) e).getUids().length > 0);
99     }
100 }
101
Popular Tags