United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4009555 : RFE: API to location of mouse on desktop

Details
Type:
Enhancement
Submit Date:
1996-10-16
Status:
Resolved
Updated Date:
2003-08-19
Project Name:
JDK
Resolved Date:
2003-08-08
Component:
client-libs
OS:
solaris_2.5,windows_nt,solaris_7,generic
Sub-Component:
java.awt
CPU:
x86,sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1,1.1.4,1.3.1,1.4.0
Fixed Versions:
5.0 (tiger)

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
Applix has requested an API to return the location of the mouse on the desktop.  They would use this to place windows at the mouse location.

=============================================================
Another report:

I would like to obtain the current mouse location without waiting for any events.

I'm looking for something simple, like:

public class java.awt.Mouse
{
  /**
   * @return A Point representing the mouse's current X and Y coordinates.
   */
  public static native Point getCurrentPosition();
}

An example of why this is useful is:
1/ Load up Netscape
2/ Go to a really long page that has lots of URLs
3/ Click anywhere on the page that isn't over an URL
4/ Let go of the mouse; don't ever touch it
5/ Use the cursor keys (Up Arrow, Down Arrow, etc.) to scroll the long 
   page up and down
6/ Watch the mouse cursor change as an URL scrolls behind the mouse cursor
   (again, without so much as breathing on the mouse)

In order for Netscape to change the shape of the mouse cursor, it needs 
to know if the mouse's current location on the screen is over an URL or 
not.  To do this, whenever you scroll the page with the cursor keys 
(which are far from being a Mouse Event), Netscape must query to see 
where the mouse is currently situated on the screen.  If that location is 
on top of an URL, it changes the mouse shape to a Hand Pointer, or some 
such thing.

brian.klock@eng 1997-11-12
=============================================================

                                    

Comments
EVALUATION

mike.somlo@eng 1997-12-08:
This sounds like a very reasonable request to me. Changing state to Evaluated.

commit to tiger since Robot does not have provide this.

xianfa.deng@Eng 2000-01-20

As per 4717900, we probably will also want to add a convenience method for checking if the mouse cursor is over a particular Component.
###@###.### 2003-01-06

Name: rpR10076			Date: 07/21/2003


See suggested fix for new APIs developed for this RFE.
======================================================================
                                     
2003-01-06
SUGGESTED FIX



Name: rpR10076			Date: 07/21/2003


Here're the new APIs being implemented for this RFE.
New class added to java.awt package:

/**
 * A class that describes the pointer position.
 * It provides the <code>GraphicsDevice</code> where the
 * pointer is and the <code>Point</code> that represents
 * the coordinates of the pointer.
 * <p>
 * Instances of this class should be obtained via
 * {@link MouseInfo#getPointerInfo}.
 * The <code>PointerInfo</code> instance is not updated dynamically
 * as the mouse moves. To get the updated location, you must call
 * {@link MouseInfo#getPointerInfo} again.
 *
 * @see MouseInfo#getDefaultMouseInfo
 * @see MouseInfo#getPointerInfo
 */
public class java.awt.PointerInfo {

    /**
     * Returns the <code>GraphicsDevice</code> where the mouse pointer
     * was at the moment this <code>PointerInfo</code> was created.
     *
     * @return   <code>GraphicsDevice</code> corresponding to the pointer
     * @since    1.5
     */
    public GraphicsDevice getDevice();

    /**
     * Returns the <code>Point</code> that represents the coordinates
     * of the pointer on the screen. See {@link MouseInfo#getPointerInfo}
     * for more information about coordinate calculation for multiscreen
     * systems.
     *
     * @see MouseInfo
     * @see MouseInfo#getPointerInfo
     * @return   coordinates of mouse pointer
     * @since    1.5
     */
    public Point getLocation();

}


New class added to java.awt package:

/**
 * <code>MouseInfo</code>  provides methods for getting information about the mouse,
 * such as mouse pointer location and the number of mouse buttons.
 */
public class MouseInfo {

    /**
     * Returns a <code>PointerInfo</code> instance that represents the current
     * location of the mouse pointer.
     * The <code>GraphicsDevice</code> stored in this <code>PointerInfo</code>
     * contains the mouse pointer. The coordinate system used for the mouse position
     * depends on whether the <code>GraphicsDevice</code> is part of a virtual
     * screen device.
     * For virtual screen devices, the coordinates are given in the virtual
     * coordinate system, otherwise they are returned in the coordinate system
     * of the <code>GraphicsDevice</code>. See {@link GraphicsConfiguration} for
     * more information about the virtual screen devices.
     * On the systems without a mouse, returns <code>null</code>.
     * <p>
     * If there is a security manager, its <code>checkPermission</code> method
     * is called with an <code>AWTPermission("watchMousePointer")</code>
     * permission before creating and returning a <code>PointerInfo</code>
     * object. This may result in a <code>SecurityException</code>.
     *
     * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
     * @exception SecurityException if a security manager exists and its
     *            <code>checkPermission</code> method doesn't allow the operation
     * @see       GraphicsConfiguration
     * @see       SecurityManager#checkPermission
     * @see       java.awt.AWTPermission
     * @return    location of the mouse pointer
     * @since     1.5
     */
     public static PointerInfo getPointerInfo() throws HeadlessException;

     /**
      * Returns the number of buttons on the mouse.
      * On systems without a mouse, returns <code>-1</code>.
      *
      * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
      * @return number of buttons on the mouse
      * @since 1.5
      */
     public static int getNumberOfButtons() throws HeadlessException;

}

New method added to java.awt.Component:

/**
 * Returns the position of the mouse pointer in this <code>Component</code>'s
 * coordinate space if the <code>Component</code> is directly under the mouse
 * pointer, otherwise returns <code>null</code>.
 * If the <code>Component</code> is not showing on the screen, this method
 * returns <code>null</code> even if the mouse pointer is above the area
 * where the <code>Component</code> would be displayed.
 * If the <code>Component</code> is partially or fully obscured by other
 * <code>Component</code>s or native windows, this method returns a non-null
 * value only if the mouse pointer is located above the unobscured part of the
 * <code>Component</code>.
 * <p>
 * For <code>Container</code>s it returns a non-null value only if the mouse
 * is above the <code>Container</code> itself or above any of its children.
 * Use {@link Container#getMousePosition(boolean)} if you need to exclude children.
 * <p>
 * Sometimes the exact mouse coordinates are not important, and the only thing
 * that matters is whether a specific <code>Component</code> is under the mouse
 * pointer. If the return value of this method is <code>null</code>, mouse
 * pointer is not directly above the <code>Component</code>.
 *
 * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
 * @see       #isShowing
 * @see       Container#getMousePosition
 * @return    mouse coordinates relative to this <code>Component</code>, or null
 * @since     1.5
 */
public Point getMousePosition() throws HeadlessException;

New method added to java.awt.Container:

/**
 * Returns the position of the mouse pointer in this <code>Container</code>'s
 * coordinate space if the <code>Container</code> is under the mouse pointer,
 * otherwise returns <code>null</code>.
 * This method is similar to {@link Component#getMousePosition()} with the exception
 * that it can take the <code>Container</code>'s children into account.
 * If <code>allowChildren</code> is <code>false</code>, this method will return
 * a non-null value only if the mouse pointer is above the <code>Container</code>
 * directly, not above the part obscured by children.
 * If <code>allowChildren</code> is <code>true</code>, this method returns
 * a non-null value if the mouse pointer is above <code>Container</code> or any
 * of its descendants.
 *
 * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true
 * @param     allowChildren true if children should be taken into account
 * @see       Component#getMousePosition
 * @return    mouse coordinates relative to this <code>Component</code>, or null
 * @since     1.5
 */
public Point getMousePosition(boolean allowChildren) throws HeadlessException;



======================================================================
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b15


                                     
2004-06-14



Hardware and Software, Engineered to Work Together