All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.help.PrintAction Maven / Gradle / Ivy

/*
 * @(#) PrintAction.java 1.2 - last change made 06/27/03
 *
 * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */

package javax.help;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.URL;
import java.util.Locale;
import javax.swing.UIManager;
import com.sun.java.help.impl.JHelpPrintHandler;

/**
 *
 * @author Stepan Marek
 * @version	1.2	06/27/03
 */
public class PrintAction extends AbstractHelpAction implements PropertyChangeListener, ActionListener {

    private static final String NAME = "PrintAction";
    
    private JHelpPrintHandler handler = null;

    /** Creates new BackAction */
    public PrintAction(Object control) {
        
        super(control, NAME);
        
        if (control instanceof JHelp) {
            
            JHelp help = (JHelp)control;
            
            handler = JHelpPrintHandler.getJHelpPrintHandler(help);
            handler.addPropertyChangeListener(this);
            
	    Locale locale = null;
	    try {
		locale = help.getModel().getHelpSet().getLocale();
	    } catch (NullPointerException npe) {
		locale = Locale.getDefault();
	    }
            putValue("tooltip", HelpUtilities.getString(locale, "tooltip." + NAME));
            putValue("access", HelpUtilities.getString(locale, "access." + NAME));

        }
        
        putValue("icon", UIManager.getIcon(NAME + ".icon"));
        
    }

    public void actionPerformed(ActionEvent event) {
        if (handler != null) {
            JHelp help = (JHelp)getControl();
            URL[] urls = null;
            TreeItem[] items = help.getSelectedItems();
            if (items != null) {
                urls = new URL[items.length];
                for (int i = 0; i < items.length; i++) {
                    urls[i] = items[i].getURL();
                }
            }
            if ((urls != null) && (urls.length > 0)) {
                handler.print(urls);
            } else {
                handler.print(help.getModel().getCurrentURL());
            }
        }
    }
    
        
    /**
     * This method gets called when a bound property is changed.
     * @param evt A PropertyChangeEvent object describing the event source
     *  	and the property that has changed.
     */
    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals("enabled")) {
            setEnabled(((Boolean)evt.getNewValue()).booleanValue());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy