GraphicsBuilder: handling events in groups - No Fluff Just Stuff

GraphicsBuilder: handling events in groups

Posted by: Andres Almiray on March 12, 2008

I recently posted on the latest updates available to groups like mouse events, but one thing that bugged me is that the group would trap all events without giving the chance to its nested operations to handle any other event, so if you happen to have an event handler on nested shape it won't receive the event as expected.

Well not anymore, thanks to a new property passThrough, when set to true it will let the event flow to the next available target, taking into consideration that targets may be groups, shapes, outlines and images. All targets now have that property too in case you are wondering. A quick example is in order, the next pic will show 4 rectangles and a star nested in a single group, the group has two mouse handlers (enter & exit), the star has four mouse handlers ( enter, exit, press & release ), whenever the mouse enters the group the star will change color to white, when it exits it will change color to black. When the mouse enters the star it will change color to cyan, and violet when the mouse is pressed, returning to its previous color when the reverse mouse action is triggered. By the way, the group has a set of filters applied



What does the code look like?

Perhaps you have seen in a previous example that the input events had a sourceShape property, but with the recent updates that name no longer makes sense, so it has been updated to target. Notice also that the group references the star by its nested index (I'm thinking in adding a local set of variables if an id is defined), as a matter of fact this trick works for all operations that accept nesting of others.
Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »