Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5094690

Please add isPopupEvent(MouseEvent anEvent)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 5.0
    • client-libs
    • x86
    • windows_2000

      Name: js151677 Date: 08/31/2004


      A DESCRIPTION OF THE REQUEST :
      Please add isPopupEvent(MouseEvent anEvent)

      This method should return true for Mouse Pressed, Released or Clicked Events when any of the 3 of them is the PopupTrigger (on most platforms this method will return true when SwingUtilities.isRightMouseButton(anEvent) returns true).

      Please add this method to SwingUtilities or something similar such as isPopupEvent() to MouseEvent and isDoingPopupEvent() to SwingUtilities.

      The isPopupEvent(MouseEvent anEvent) implementation might be as simple as calling SwingUtilities.isRightMouseButton(anEvent). Or might delagate to PopupMenuUI or something like that in order to determine it's result.

      If isPopupEvent() is added to the MouseEvent instead then we also need a method such as isDoingPopupEvent() to find out if a Popup Event is happening from such methods as valueChanged(TreeSelectionEvent anEvent) (which doesn't get passed in the MouseEvent that caused it).

      JUSTIFICATION :
      Basically we and many other developers (search through the Bug Database finds many similar requests) have cases where we need to know if the mousePressed Event is a PopupEvent or not. By the time it gets to mouseReleased the check for isPopupTrigger is already too late.

      The code we would like to be able to write is something like this:

      new MouseAdapter() {
        public void mousePressed(MouseEvent anEvent) {
          if (SwingUtilities.isPopupEvent(anEvent)) {
            if (anEvent.isPopupTrigger()) {
              // do popup
            }
            return;
          }
          // do mouse pressed
        }

        public void mouseReleased(MouseEvent anEvent) {
          if (SwingUtilities.isPopupEvent(anEvent)) {
            if (anEvent.isPopupTrigger()) {
              // do popup
            }
            return;
          }
          // do mouse released
        }
            
        public void mouseClicked(MouseEvent anEvent) {
          if (!SwingUtilities.isPopupEvent(anEvent)) {
            // do mouse clicked
          }
        }
      };

      new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent anEvent) {
          if (!SwingUtilities.isDoingPopupEvent()) {
            // do value changed
          }
        }
      };

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Methods to exist
      ACTUAL -
      Methods don't exist

      CUSTOMER SUBMITTED WORKAROUND :
      Use SwingUtilities.isRightMouseButton(anEvent) instead (although this might not work for all L&Fs and all Platforms)
      (Incident Review ID: 301452)
      ======================================================================

            vbaranovsunw Vyacheslav Baranov (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: