Package net.helipilot50.stocktrade.displayproject.events

Source Code of net.helipilot50.stocktrade.displayproject.events.AfterFieldScrolledListener

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

import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RepaintManager;

import net.helipilot50.stocktrade.displayproject.ForteRepaintManager;
import net.helipilot50.stocktrade.displayproject.GlassPaneWithEvents;
import net.helipilot50.stocktrade.framework.EventManager;



/**
* Listen for a scroll in an ArrayField, OutlineField, or Viewport.
*
* @author Craig Mitchell
* @since 29/01/2008.
*/
public class AfterFieldScrolledListener implements InstallableListener, AdjustmentListener {

    public void install(Object o, String event) {

        // Check we are a widget that's parents, parent is a JScrollPane.
        // This will be the case for most widgets that are scrollable, as the
        // widget is contained in a viewport, which is contained in the scroll
        // pane.
        if (o instanceof Component &&
                ((Component)o).getParent() != null &&
                ((Component)o).getParent().getParent() instanceof JScrollPane) {
            JScrollPane sp = (JScrollPane)((JTable)o).getParent().getParent();
            sp.getHorizontalScrollBar().addAdjustmentListener(this);
            sp.getVerticalScrollBar().addAdjustmentListener(this);
        }
    }

    public void adjustmentValueChanged(AdjustmentEvent e) {
      if (e.getSource() instanceof JScrollBar &&
          ((JScrollBar)e.getSource()).getParent() instanceof JScrollPane) {

        // TF:04/09/2009:We only want to post the event if we're currently processing either a keyboard or mouse event. Otherwise
        // we can fire listener events when the window is resized (unlike Forte). We can only do this if we are not adjusting.
        AWTEvent currentEvent = GlassPaneWithEvents.getCurrentEvent();
        if ((currentEvent instanceof MouseEvent || currentEvent instanceof KeyEvent) && !e.getValueIsAdjusting()) {
        // TF:31 Oct 2008:Don't post the event if we're in the process of laying out.
        Component source = ((JScrollPane)((JScrollBar)e.getSource()).getParent()).getViewport().getView();
        RepaintManager manager = RepaintManager.currentManager(source);
        if (!(manager instanceof ForteRepaintManager && ((ForteRepaintManager)manager).isValidating())) {
          EventManager.startEventChain();

          // Post the event on the actual component contained in the scroll pane
          ClientEventManager.postEvent(source, "AfterFieldScrolled");
          EventManager.endEventChain();
        }
        }
        }
    }
}
TOP

Related Classes of net.helipilot50.stocktrade.displayproject.events.AfterFieldScrolledListener

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.