Package DisplayProject.events

Source Code of DisplayProject.events.ActivateListener

/*
Copyright (c) 2003-2008 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject.events;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import javax.swing.ButtonGroup;
import javax.swing.DefaultButtonModel;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;

import org.apache.log4j.Logger;

import DisplayProject.FocusHelper;
import DisplayProject.controls.MenuList;
import Framework.EventHandle;
import Framework.ParameterHolder;
/**
* This listener provides the forte event(s) and and parameters when a Menu is activated
* @see InstallableListener
* @see java.awt.ActionListener
*
*/
public class ActivateListener implements InstallableListener, ActionListener{
    private static Logger _log = Logger.getLogger(ActivateListener.class);
    public void install(Object o, String event) {
        if (o instanceof JMenuItem) {
            JMenuItem item = (JMenuItem)o;
            // TF:18/06/2008:removed this as I don't understand why it's there
//            int actionCount = item.getActionListeners().length;
//            if (actionCount > 0) {
//                for (ActionListener listener : item.getActionListeners()){
//                    item.removeActionListener(listener);
//                }
//            }
            item.removeActionListener(this);
            item.addActionListener(this);
        } else if (o instanceof MenuList) {
            MenuList item = (MenuList)o;
            // TF:18/06/2008:removed this as I don't understand why it's there
//            int actionCount = item.getActionListeners().length;
//            if (actionCount > 0) {
//                for (ActionListener listener : item.getActionListeners()){
//                    item.removeActionListener(listener);
//                }
//            }
            item.removeActionListener(this);
            item.addActionListener(this);
        }
    }

    public void actionPerformed(ActionEvent e) {
        List<EventHandle> eventsToPost = new ArrayList<EventHandle>();
        Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
        qq_Params.put("x", new ParameterHolder(0));
        qq_Params.put("y", new ParameterHolder(0));
        int modifiers = 0;
        if ((e.getModifiers() & ActionEvent.CTRL_MASK) > 0)
            modifiers = modifiers | 1;
        if ((e.getModifiers() & ActionEvent.SHIFT_MASK) > 0)
            modifiers = modifiers | 2;
        if ((e.getModifiers() & ActionEvent.ALT_MASK) > 0)
            modifiers = modifiers | 4;
        if ((e.getModifiers() & ActionEvent.META_MASK) > 0)
            modifiers = modifiers | 8;
        qq_Params.put("modifier", new ParameterHolder(modifiers));
        qq_Params.put("node", new ParameterHolder(null));
        qq_Params.put("row", new ParameterHolder(0));
        qq_Params.put("column", new ParameterHolder(0));
        if (e.getSource() instanceof JRadioButtonMenuItem) {
            ButtonGroup bg = ((DefaultButtonModel) ((JRadioButtonMenuItem) e
                    .getSource()).getModel()).getGroup();
            _log.debug("Activate on ["+ bg.toString() + "]");
            eventsToPost.add(new EventHandle(bg, "Activate", qq_Params));
        } else {
            Component me = (Component) e.getSource();
            _log.debug("Activate on ["+ me.toString() + "]");
            eventsToPost.add(new EventHandle(me, "Activate", qq_Params));
            //PM:10/11/07 - added the child parameter
            Hashtable<String, Object> qq_Params_child = new Hashtable<String, Object>();
            qq_Params_child.put("Child", new ParameterHolder(me));
            ChildEventHelper.postEventToAllParents(me, "ChildActivate", qq_Params_child, eventsToPost);
        }
        if ((e.getSource() instanceof JCheckBoxMenuItem)
                || (e.getSource() instanceof JRadioButtonMenuItem)) {
            afterValueChange((Component) e.getSource(), eventsToPost);
        }
        FocusHelper.menuActivate((JComponent) e.getSource(), eventsToPost);

    }
    private void afterValueChange(Component me, List<EventHandle> eventsToPost) {
        eventsToPost.add(new EventHandle(me, "AfterValueChange"));
        ChildEventHelper.postEventToAllParents(me, "ChildAfterValueChange", null, eventsToPost);
    }

}
TOP

Related Classes of DisplayProject.events.ActivateListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.