Package DisplayProject.events

Source Code of DisplayProject.events.ChildClickListener

/*
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.events;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JTable;

import DisplayProject.controls.Graphic;

class ChildClickListener extends MouseAdapter implements InstallableListener, ChildInstallableListener, ActionListener {
    MouseEvent mousePressedEvent;

    public void install(Object o, String pEvent) {
        if (o instanceof JComponent) {
            // Recursively install this notification on our children
            ChildEventHelper.installOnAllChildren((JComponent)o, pEvent, this);
        }
    }

    public void installChildForParent(JComponent pChild, Container pParent, String pEvent) {
        pChild.removeMouseListener(this);
        pChild.addMouseListener(this);
        // We also need to register for an action listener on a JButton as well for when the
        // end user hits Enter, which does the same thing as a Click event in Forte.
        if (pChild instanceof JButton) {
            ((JButton)pChild).addActionListener(this);
        }
        // TF:26/9/07: If we're doing this on an Array, we also need to listen to the header of
        // the array, because this can also post child click events.
        // seb: Make sure there is a table header
        if (pChild instanceof JTable) {
            if (((JTable)pChild).getTableHeader() != null) {
                ((JTable)pChild).getTableHeader().addMouseListener(this);
            }
        }
    }

    /**
     * CraigM:09/09/2008.
     * @see ClickListener#mousePressed(java.awt.event.MouseEvent)
     */
    @Override
    public void mousePressed(MouseEvent pEvent) {
      this.mousePressedEvent = pEvent;
    }

    /**
     * CraigM:09/09/2008.
     * @see ClickListener#mousePressed(java.awt.event.MouseEvent)
     */
    @Override
    public void mouseReleased(MouseEvent pEvent) {
      if (this.mousePressedEvent != null) {
          // Check if the mouse release occurred in the same component.  CraigM: 05/02/2008
            if (this.mousePressedEvent.getComponent() != null) {

                // If they released the mouse off the component, don't fire the click event
                if (this.mousePressedEvent.getComponent().contains(pEvent.getX(), pEvent.getY()) == false) {
                    return;
                }
            }
           
            // The following code was moved from mouseClicked event.  CraigM:09/09/2008.
            // TF:25/05/2010:In the case of array fields, the mouse pressed event points to the array field,
            // but the mouse released event points to the edited field, eg the underlying data field.
            // Hence, we really should use the released event.
//            MouseEvent e = ChildEventHelper.fixMouseEvent(this.mousePressedEvent);
            MouseEvent e = ChildEventHelper.fixMouseEvent(pEvent);

            // TF:25/05/2010:If the component is an array field and we've clicked on an editable column, then the
            // click should be handled by the editor and we shouldn't repost it here.
            boolean postEvent = true;
            if (e.getComponent() instanceof JTable) {
              JTable table = (JTable)e.getComponent();
              int column = table.columnAtPoint(e.getPoint());
              int row = table.rowAtPoint(e.getPoint());
              if (table.isCellEditable(row, column)) {
                postEvent = false;
              }
            }
            if (postEvent && (e.getComponent() instanceof Graphic || e.getComponent().isEnabled())) {
                if (e.getComponent().isFocusable()) {
                    e.getComponent().requestFocus();
                }
                // We post a click event if the button 1 is pressed, and either this control cannot
                // fire double clicks, or it can fire double clicks but the click count is odd.
                boolean canDoubleClick = ClickListener.canFireDoubleClickEvents(e.getComponent());
                if (e.getButton() == MouseEvent.BUTTON1 && (!canDoubleClick || ((e.getClickCount() & 1) == 1))) {
                    ChildEventHelper.postEventToAllParents((JComponent)e.getSource(), "ChildClick", ClickListener.makeParamList(e, true));
                }
            }
      }
    }

    /**
     * Process the click action on the button control, but only for non-mouse events. This
     * ensures that the order of events is correct for mouse events.
     */
    public void actionPerformed(ActionEvent e) {
        if (((JComponent)e.getSource()).isEnabled() &&
                (e.getModifiers() & ActionEvent.MOUSE_EVENT_MASK) == 0) {
            ChildEventHelper.postEventToAllParents((JComponent)e.getSource(), "ChildClick", ClickListener.makeParamList(e, true));
        }
    }
}
TOP

Related Classes of DisplayProject.events.ChildClickListener

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.