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

Control#contextMenuHandler could be made static

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 8
    • 8
    • javafx
    • None

    Description

      To save one handler instance / control instance one could make the event-handler static and calculate the control from the event information.

      diff --git a/modules/controls/src/main/java/javafx/scene/control/Control.java b/modules/controls/src/main/java/javafx/scene/control/Control.java
      --- a/modules/controls/src/main/java/javafx/scene/control/Control.java
      +++ b/modules/controls/src/main/java/javafx/scene/control/Control.java
      @@ -167,13 +167,18 @@
            * classes which we'd otherwise have to create. When lambda expressions
            * are supported, we could do it that way instead (or use MethodHandles).
            */
      - private final EventHandler<ContextMenuEvent> contextMenuHandler = new EventHandler<ContextMenuEvent>() {
      + private final static EventHandler<ContextMenuEvent> contextMenuHandler = new EventHandler<ContextMenuEvent>() {
               @Override public void handle(ContextMenuEvent event) {
                   // If a context menu was shown, consume the event to prevent multiple context menus
      - if (getContextMenu() != null) {
      - getContextMenu().show(Control.this, event.getScreenX(), event.getScreenY());
      - event.consume();
      - }
      + Object source = event.getSource();
      + if( source instanceof Control ) {
      + Control c = (Control) source;
      + if (c.getContextMenu() != null) {
      + c.getContextMenu().show(c, event.getScreenX(), event.getScreenY());
      + event.consume();
      + }
      + }
      +
               }
           };
       

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            tschindl Tom Schindl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: