RolloverProducer.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:4k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: RolloverProducer.java,v 1.8 2005/10/12 11:26:58 kleopatra Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.swingx;
  22. import java.awt.Point;
  23. import java.awt.Rectangle;
  24. import java.awt.event.MouseEvent;
  25. import java.awt.event.MouseListener;
  26. import java.awt.event.MouseMotionListener;
  27. import javax.swing.JComponent;
  28. import javax.swing.JList;
  29. import javax.swing.JTable;
  30. import javax.swing.JTree;
  31. /**
  32.  * Mouse/Motion/Listener which stores mouse location as 
  33.  * client property in the target JComponent.
  34.  * 
  35.  * Note: assumes that the component it is listening to is 
  36.  * of type JComponent!
  37.  * 
  38.  * @author Jeanette Winzenburg
  39.  */
  40. public class RolloverProducer implements MouseListener, MouseMotionListener {
  41.     //----------------- mouseListener
  42.         
  43.         public static final String CLICKED_KEY = "swingx.clicked";
  44.         public static final String ROLLOVER_KEY = "swingx.rollover";
  45. //        public static final String PRESSED_KEY = "swingx.pressed";
  46.         
  47.         
  48.         public void mouseClicked(MouseEvent e) {
  49.             updateRollover(e, CLICKED_KEY);
  50.         }
  51.         public void mousePressed(MouseEvent e) {
  52.             
  53.         }
  54.         public void mouseReleased(MouseEvent e) {
  55.             
  56.         }
  57.         public void mouseEntered(MouseEvent e) {
  58.             updateRollover(e, ROLLOVER_KEY);
  59.         }
  60.         public void mouseExited(MouseEvent e) {
  61.             if (e.getSource() instanceof JComponent) {
  62.                 ((JComponent) e.getSource()).putClientProperty(ROLLOVER_KEY, null);
  63.                 ((JComponent) e.getSource()).putClientProperty(CLICKED_KEY, null);
  64. //                ((JComponent) e.getSource()).putClientProperty(PRESSED_KEY, null);
  65.             }
  66.             
  67.         }
  68. //---------------- MouseMotionListener
  69.         public void mouseDragged(MouseEvent e) {
  70.             // TODO Auto-generated method stub
  71.             
  72.         }
  73.         public void mouseMoved(MouseEvent e) {
  74.             updateRollover(e, ROLLOVER_KEY);
  75.         }
  76.         protected void updateRollover(MouseEvent e, String property) {
  77.             updateRolloverPoint((JComponent) e.getComponent(), e.getPoint());
  78.             updateClientProperty((JComponent) e.getSource(), property);
  79.         }
  80.         protected Point rollover = new Point(-1, -1);
  81.         
  82.         protected void updateClientProperty(JComponent component, String property) {
  83.             Point p = (Point) component.getClientProperty(property);
  84.             if (p == null || (rollover.x != p.x) || (rollover.y != p.y)) {
  85.                 component.putClientProperty(property, new Point(rollover));
  86.             }
  87.         }
  88.         /**
  89.          * Subclasses must override to map the given mouse coordinates into
  90.          * appropriate client coordinates. The result must be stored in the 
  91.          * rollover field. 
  92.          * 
  93.          * Here: does nothing.
  94.          * 
  95.          * @param component
  96.          * @param mousePoint
  97.          */
  98.         protected void updateRolloverPoint(JComponent component, Point mousePoint) {
  99.             
  100.         }
  101.         
  102.         
  103.     }