Package DisplayProject

Source Code of DisplayProject.ForteMouseAdapter

/*
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 DisplayProject;

import java.awt.Component;
import java.awt.Container;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Hashtable;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTree;

import DisplayProject.controls.OutlineField;
import DisplayProject.events.ChildEventHelper;
import DisplayProject.events.ClientEventManager;
import DisplayProject.table.ArrayFieldCellHelper;
import Framework.ParameterHolder;

/**
* @author Peter
*
*/
@SuppressWarnings("deprecation")
public class ForteMouseAdapter extends MouseAdapter implements ActionListener {
    public static final String PSUED0_DOUBLE_CLICK = "psuedoDoubleClick";
    protected JTree tree = null;
    protected JTable table = null;
    protected OutlineField olf = null;
    protected JPanel panel = null;
  protected JListView lv = null;
    public ForteMouseAdapter(){
        super();
    }

    public ForteMouseAdapter(JListView lv){
        this();
        this.lv = lv;
    }
    public ForteMouseAdapter(OutlineField of){
        this();
        olf = of;
    }
    public ForteMouseAdapter(JTable table){
        this();
        this.table = table;
    }
    public ForteMouseAdapter(JPanel panel){
        this();
        this.panel = panel;
    }
    public ForteMouseAdapter(JTree tree){
        this();
        this.tree = tree;
    }

    public void actionPerformed(ActionEvent e) {
        //  String evName = "";
        if (((JComponent)e.getSource()).isEnabled() &&
                (e.getModifiers() & ActionEvent.MOUSE_EVENT_MASK) == 0) {

            Hashtable<String, Object> qq_Params = makeParamList(0, 0, e.getModifiers());
            ClientEventManager.postEvent( e.getSource(), "Click", qq_Params );

            // TF:27/9/07:Revamped to use the event structure
            ChildEventHelper.postEventToAllParents((Component)e.getSource(), "ChildClick");
        }
    }
    public void mouseClicked(MouseEvent e) {
        if (!(e.getComponent().isEnabled())) return;
        e.getComponent().requestFocus();
        processClick((JComponent)e.getComponent(), e.getButton(),e.getClickCount(),e.getModifiers(),e.getX(),e.getY());

    }
    public void processClick(JComponent comp, int Button, int ClickCount, int Mod, int X, int Y){
        String evName = "Click";
        switch(Button) {
        case MouseEvent.BUTTON1:
            // Do nothing
            break;
        case MouseEvent.BUTTON2:
            evName = evName + "Middle";
        break;
        case MouseEvent.BUTTON3:
            evName = evName + "Outer";
        break;
        }
        if (ClickCount == 2)
            evName = "Double" + evName;
        Hashtable<String, Object> qq_Params = makeParamList(X, Y, Mod);
        // Special case: JTables without an editor but that are used as arrays must post a ChildClick event
        // on the table, even though comp will point to the JTable (so normally it would get just a Click event)
        // Note that this normally isn't an issue with jcTOOL generated code -- this is just special code in
        // case people have decided to remove the cell editor that is generated. If this is the case, then
        // the child parameter to the event will not be set.
        if (comp instanceof JTable && ((JTable)comp).getColumnModel() != null && ((JTable)comp).getColumnModel() instanceof ArrayColumnModel) {
            ClientEventManager.postEvent( comp, "Child" + evName, qq_Params );         
        }
        else {
            ClientEventManager.postEvent( comp, evName, qq_Params );
        }
        if (comp.getParent() != null){
            qq_Params.put("child", new ParameterHolder(comp));
            Container mum = comp.getParent();
            while (mum != null) {
                ClientEventManager.postEvent(mum, "Child" + evName, qq_Params);
                mum = mum.getParent();
            }
        }
        // Process the clicks on a JTable also. In this case, if there is an editor installed then
        // we won't actually have a parent, but we get the table out of the attribute.
        else if (ArrayFieldCellHelper.getArrayField(comp) != null) {
            qq_Params.put("child", new ParameterHolder(comp));
            Container mum = ArrayFieldCellHelper.getArrayField(comp);
            while (mum != null){
                ClientEventManager.postEvent( mum, "Child" + evName, qq_Params );
                mum = mum.getParent();
            }
        }
    }

    public void mouseEntered(MouseEvent e) {
        ClientEventManager.postEvent( e.getSource(), "MouseEnter" );
        if (((JComponent)e.getSource()).getParent() != null){
            Hashtable<String, ParameterHolder> qq_Params = new Hashtable<String, ParameterHolder>();
            qq_Params.put("child", new ParameterHolder(e.getSource()));
            Container mum = ((JComponent)e.getSource()).getParent();
            while (mum != null) {
                ClientEventManager.postEvent(mum, "ChildMouseEnter", qq_Params);
                mum = mum.getParent();
            }
        }
    }
    public void mouseExited(MouseEvent e) {
        ClientEventManager.postEvent( e.getSource(), "MouseLeave" );
        if (((JComponent)e.getSource()).getParent() != null){
            Hashtable<String, ParameterHolder> qq_Params = new Hashtable<String, ParameterHolder>();
            qq_Params.put("child", new ParameterHolder(e.getSource()));
            Container mum = ((JComponent)e.getSource()).getParent();
            while (mum != null) {
                ClientEventManager.postEvent(mum, "ChildMouseLeave", qq_Params);
                mum = mum.getParent();
            }
        }
    }
   
    protected Hashtable<String, Object> makeParamList(int X, int Y, int mod){
        Hashtable<String, Object> qq_Params = new Hashtable<String, Object>();
        // The forte will return the X & Y in mils, so covert here
        qq_Params.put( "x", new ParameterHolder(UIutils.pixelsToMils(X)));
        qq_Params.put( "y", new ParameterHolder(UIutils.pixelsToMils(Y)));
        int modifiers = 0;
        if ((mod & ActionEvent.CTRL_MASK) > 0)
            modifiers = modifiers | 1;
        if ((mod & ActionEvent.SHIFT_MASK) > 0)
            modifiers = modifiers | 2;
        if ((mod & ActionEvent.ALT_MASK) > 0)
            modifiers = modifiers | 4;
        if ((mod & ActionEvent.META_MASK) > 0)
            modifiers = modifiers | 8;
        qq_Params.put( "modifier", new ParameterHolder(modifiers) );
        if ((table != null) && (table.getModel() instanceof TableSorter)) {
            DisplayNode dn =
                ((DisplayNode)((ArrayFieldModel)((TableSorter)table.getModel()).getTableModel()).getData().get(table.getSelectedRow()));
            qq_Params.put( "node", new ParameterHolder(dn) );
        } else if (tree != null) {
            qq_Params.put( "node", new ParameterHolder(tree.getLastSelectedPathComponent()) );
        } else if (olf != null) {
            qq_Params.put( "node", new ParameterHolder(olf.getTree().getLastSelectedPathComponent()) );
        } else if (lv != null) {
            qq_Params.put( "node", new ParameterHolder(lv.getCurrentNode()) );
        } else
            qq_Params.put( "node", new ParameterHolder(null) );
        if (table != null)
        {
            // TF:27/9/07:Made the row and column 1-based indexes instead of 0-based
            qq_Params.put( "row", new ParameterHolder(table.rowAtPoint(new Point(X,Y))+1) );
            qq_Params.put( "column", new ParameterHolder(table.columnAtPoint(new Point(X,Y))+1) );
        }
        else
        {
            qq_Params.put( "row", new ParameterHolder(0) );
            qq_Params.put( "column", new ParameterHolder(0) );
        }
        return qq_Params;
    }

}
TOP

Related Classes of DisplayProject.ForteMouseAdapter

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.