Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4388

Support pre-configured 'addAction' and 'addActions' methods for java.awt.Component through Groovy DSL

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.7.4
    • None
    • Swing
    • None

    Description

      Currently I have to use add(Action|Mouse)Listener if I want to register a action/mouse listener to a component. It would be great if Groovy support 'addAction' and 'addActions' methods that will cleverly register any kind of EventListener to a component without a need to call methods related to it (pre configured via Groovy DSL).

      So this is what I basically do in my swing projects:

      // Add addAction syntax to java.awt.Component
      Component.metaClass."addAction" = { action ->
         if (action instanceof MouseListener)
      	addMouseListener(action);
         else
      	addActionListener(action);
      }
      		
      // Add addActions syntax to java.awt.Component
      Component.metaClass."addActions" = { actions ->
         for (def action: actions)
      	addAction(action);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            fenrir Donny A. Wijaya
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: