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

Support events using SwingBuilder

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-4
    • 1.0-beta-5
    • None
    • None

    Description

      Right now there does not seem to be any support for attaching event handlers to components via the SwingBuilder class. Some kind of support should be added to make hooking up logic to components easier.

      Here are two initial ideas:

      1 - Provide attributes for components similar to HTML forms:

      builder.frame( onWindowFocusGain:

      {println "I am focused"}

      onMouseClicked:

      {println "Clicked: " + it.clickCount}

      )

      Pro: A common approach that is easy for people to understand.

      Con: Not the most modular an extensible. Does not match the Java model for GUI event handling.

      2 - seperate constructs for creating event handlers

      builder.frame() {

      windowEvents( closing:

      { System.exit() }

      ,
      focusGained:

      { println "I am focused" }

      )

      mouseEvents( clicked:

      { println "Clicked: " + it.clickCount }

      )

      // Adds a static handler
      keyEvents( static: new MyKeyEventHandler() )

      // No reason not to add two handlers
      keyEvents( typed:

      { println "Typed " + it }

      )
      }

      Pro: Easier to abstract and make extensible for new event types. Closer to Swing model for event handling. Convinient grouping of handlers.

      Con: Not intuitive to web programmers. Requires more coding.

      Attachments

        Activity

          People

            slobberchops Rapheal Kaplan
            slobberchops Rapheal Kaplan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 168h
                168h
                Remaining:
                Remaining Estimate - 168h
                168h
                Logged:
                Time Spent - Not Specified
                Not Specified