1 /*
2  * @(#)PrintAction.java	1.3 06/10/30
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This code is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License version 2 only, as
9  * published by the Free Software Foundation.  Sun designates this
10  * particular file as subject to the "Classpath" exception as provided
11  * by Sun in the LICENSE file that accompanied this code.
12  *
13  * This code is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16  * version 2 for more details (a copy is included in the LICENSE file that
17  * accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License version
20  * 2 along with this work; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24  * CA 95054 USA or visit www.sun.com if you need additional information or
25  * have any questions.
26  */
27 
28 package javax.help;
29 
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32 import java.beans.PropertyChangeEvent;
33 import java.beans.PropertyChangeListener;
34 import java.net.URL;
35 import java.util.Locale;
36 import javax.swing.UIManager;
37 import com.sun.java.help.impl.JHelpPrintHandler;
38 
39 /**
40  *
41  * @author Stepan Marek
42  * @version	1.3	10/30/06
43  */
44 public class PrintAction extends AbstractHelpAction implements PropertyChangeListener, ActionListener {
45 
46     private static final String NAME = "PrintAction";
47 
48     private JHelpPrintHandler handler = null;
49 
50     /** Creates new BackAction */
PrintAction(Object control)51     public PrintAction(Object control) {
52 
53         super(control, NAME);
54 
55         if (control instanceof JHelp) {
56 
57             JHelp help = (JHelp)control;
58 
59             handler = JHelpPrintHandler.getJHelpPrintHandler(help);
60             handler.addPropertyChangeListener(this);
61 
62 	    Locale locale = null;
63 	    try {
64 		locale = help.getModel().getHelpSet().getLocale();
65 	    } catch (NullPointerException npe) {
66 		locale = Locale.getDefault();
67 	    }
68             putValue("tooltip", HelpUtilities.getString(locale, "tooltip." + NAME));
69             putValue("access", HelpUtilities.getString(locale, "access." + NAME));
70 
71         }
72 
73         putValue("icon", UIManager.getIcon(NAME + ".icon"));
74 
75     }
76 
actionPerformed(ActionEvent event)77     public void actionPerformed(ActionEvent event) {
78         if (handler != null) {
79             JHelp help = (JHelp)getControl();
80             URL[] urls = null;
81             TreeItem[] items = help.getSelectedItems();
82             if (items != null) {
83                 urls = new URL[items.length];
84                 for (int i = 0; i < items.length; i++) {
85                     urls[i] = items[i].getURL();
86                 }
87             }
88             if ((urls != null) && (urls.length > 0)) {
89                 handler.print(urls);
90             } else {
91                 handler.print(help.getModel().getCurrentURL());
92             }
93         }
94     }
95 
96 
97     /**
98      * This method gets called when a bound property is changed.
99      * @param evt A PropertyChangeEvent object describing the event source
100      *  	and the property that has changed.
101      */
propertyChange(PropertyChangeEvent evt)102     public void propertyChange(PropertyChangeEvent evt) {
103         if (evt.getPropertyName().equals("enabled")) {
104             setEnabled(((Boolean)evt.getNewValue()).booleanValue());
105         }
106     }
107 }
108