Package net.helipilot50.stocktrade.displayproject

Source Code of net.helipilot50.stocktrade.displayproject.PopupListener

/*
Copyright (c) 2003-2009 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 net.helipilot50.stocktrade.displayproject;

import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Hashtable;

import javax.swing.JComponent;
import javax.swing.JPopupMenu;
import javax.swing.JTable;

import net.helipilot50.stocktrade.displayproject.actions.WidgetState;
import net.helipilot50.stocktrade.displayproject.events.ClientEventManager;
import net.helipilot50.stocktrade.displayproject.table.ArrayFieldCellHelper;
import net.helipilot50.stocktrade.framework.ParameterHolder;



/**
* @author Peter
*/
public class PopupListener extends MouseAdapter {
    protected JPopupMenu popup = null;
    protected JComponent comp = null;
    public PopupListener(JPopupMenu p) {
        super();
        this.popup = p;
    }
    public PopupListener(JPopupMenu p, JComponent pComp) {
        super();
        this.popup = p;
        this.comp = pComp;
    }
    public void mousePressed(MouseEvent e) {
        super.mousePressed(e);
        showPopup(e);
    }
    public void mouseReleased(MouseEvent e) {
        super.mouseReleased(e);
        showPopup(e);
    }
    public void showPopup(MouseEvent e) {
        if (popup != null && (e.isPopupTrigger() || e.getSource() instanceof JTable )) {
            if (this.comp != null){
                if (WidgetState.get(this.comp) == Constants.FS_DISABLED ||
                    WidgetState.get(this.comp) == Constants.FS_INACTIVE)
                {
                    return;
                }
                else {
                    boolean showPopup = false;
                    Component[] components = popup.getComponents();
                    for (int i = 0; i < components.length; i++) {
                        Component eachComponent = components[i];
                        if (WidgetState.get(eachComponent) != Constants.MS_INVISIBLE) {
                            showPopup = true;
                            break;
                        }
                    }
                    if (showPopup == false) {
                        return;
                    }
                }

                Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
                qq_Params.put("sourceField", new ParameterHolder(e.getComponent()));

                //The forte will return the X & Y in mils, so covert here
                qq_Params.put("x", new ParameterHolder(UIutils.pixelsToMils(e.getX())));
                qq_Params.put("y", new ParameterHolder(UIutils.pixelsToMils(e.getY())));

                ClientEventManager.postEvent(comp.getTopLevelAncestor(), "PopUpRequest", qq_Params);

                popup.show(comp, e.getX(), e.getY());
            }
            else
                popup.show(getComponent(e), e.getX(), e.getY());
        }
    }
    public JPopupMenu getPopup() {
        return popup;
    }
    public void setPopup(JPopupMenu popup) {
        this.popup = popup;
    }

    private JComponent getComponent(MouseEvent e){
        // SO: we found that there is a problem with DataFiled in jTable.
        // we need to choose component to show popup menu.
        JComponent component = null;

        JTable table = ArrayFieldCellHelper.getArrayField(e.getComponent());

        if (table == null)
            // This is a normal component, just use as is.
            component = (JComponent)e.getComponent();
        else
            component = comp;

        return component;
    }

}
TOP

Related Classes of net.helipilot50.stocktrade.displayproject.PopupListener

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.