SlideShare uma empresa Scribd logo
1 de 39
Advanced Effects
in Java Desktop
Applications

Kirill Grouchnikov, Senior Software
Engineer, Amdocs
kirillcool@yahoo.com
http://www.pushing-pixels.org
OSCON 2007
Agenda
                                 •Swing pipeline
                                 •Hooking into the pipeline
                                   •RepaintManager
                                   •Playing with opacity
                                   •Glass pane
                                   •Layering in UI delegates
                                 •Rainbow demo
                                 •Q&A



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing basics
 - UI toolkit for Java applications
 - What is a lightweight component?
     - Very flexible
     - Provides a lot of hooks for custom behavior
     - Not trivial to implement
 - Heavyweight counterparts – AWT and SWT




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline
 - Three major “participants”
     - JComponent
     - RepaintManager
     - ComponentUI
 - Provide various hooks to customize behavior
 - Vary in flexibility, robustness and ease of use




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline – part I
      JComponent                         RepaintManager
   repaint()                             addDirtyRegion()
                                           •Coalesce repaints
                                           •Create an event
                                           •Queue event on EDT



                                         paintDirtyRegions() EDT gets to the
  paintImmediately()
                                                                    queued event
    •Opacity checks
    •Double-buffering
    paint()


Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline – part II
          JComponent                                     ComponentUI
   paint()
       paintComponent()
                                                    update()
                                                       paint()


        paintBorder()
        paintChildren()




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing pipeline hooks
 - JComponent
     - Override paint or paintComponent
     - Or even repaint or paintImmediately
 - RepaintManager
     - Install a custom implementation (singleton)
 - ComponentUI
     - Provide custom painting for a specific component class


Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
What we can achieve?
 - Translucency
 - Non-rectangular components
 - Layering
 - Image filtering
 - Animation




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Agenda
                                 •Swing pipeline
                                 •Hooking into the pipeline
                                   •RepaintManager
                                   •Playing with opacity
                                   •Glass pane
                                   •Layering in UI delegates
                                 •Rainbow demo
                                 •Q&A



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline hooks
      JComponent                         RepaintManager
   repaint()                             addDirtyRegion()
                                           •Coalesce repaints
                                           •Create an event
                                           •Queue event on EDT



                                         paintDirtyRegions() EDT gets to the
  paintImmediately()
                                                                    queued event
    •Opacity checks
    •Double-buffering
    paint()


Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
RepaintManager example
 - SwingX project
 - JXPanel that provides translucency
     - setAlpha(float)
     - using RepaintManagerX – see code




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
There can be only one (singleton)
    class JXPanel {
       public void setAlpha(float alpha) {
          if (alpha > 0f && alpha < 1f) {
            ...
            RepaintManager.setCurrentManager(
                new RepaintManagerX());
          }
        }




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Agenda
                                 •Swing pipeline
                                 •Hooking into the pipeline
                                   •RepaintManager
                                   •Playing with opacity
                                   •Glass pane
                                   •Layering in UI delegates
                                 •Rainbow demo
                                 •Q&A



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline hooks
      JComponent                         RepaintManager
   repaint()                             addDirtyRegion()
                                           •Coalesce repaints
                                           •Create an event
                                           •Queue event on EDT



                                         paintDirtyRegions() EDT gets to the
  paintImmediately()
                                                                    queued event
    •Opacity checks
    •Double-buffering
    paint()


Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Opacity basics - setOpaque
   - setOpaque(false) == “draw stuff behind me”
      - Useful for translucent or non-rectangular
        components
   - setOpaque(true) == “I’ll handle it”
      - During repainting of an opaque component
        Swing does not repaint any components behind




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Transition effects using opacity
   - UIs changes are immediate
      - Showing / hiding a control
      - Moving a control to new location
      - Tab switch
   - Solution – use transitions (cross fades, fly-in / out)
   - Making controls non-opaque to enable the transition effects




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
DEMO
 Transition layout demo




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Transition layout manager
    TransitionLayoutManager.getInstance().
          track(myTabbedPane, true);
    TransitionLayoutManager.getInstance().
          track(myPanel, true);

    - Play with opacity (set to false during animation cycle)
    - Set translucency (for fades)
    - Custom layout manager (for sliding effects)



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Transition scenarios
    - Remains visible and has the same bounds
    - Remains visible and has different bounds
    - Becomes invisible
    - Added or becomes visible
    - Remains invisible




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Agenda
                                 •Swing pipeline
                                 •Hooking into the pipeline
                                   •RepaintManager
                                   •Playing with opacity
                                   •Glass pane
                                   •Layering in UI delegates
                                 •Rainbow demo
                                 •Q&A



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline hooks
          JComponent                                     ComponentUI
   paint()
       paintComponent()
                                                    update()
                                                       paint()


        paintBorder()
        paintChildren()




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Glass pane basics
    - Painting over all the components

     frame.setGlassPane(new CustomGlassPanel());
     frame.getGlassPane().setVisible(true);




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Glass pane
    - Pros
       - Does not affect component's state
    - Cons
       - Global resource (for a frame)
       - Everything is repainted (performance)




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
JXLayer overview
  - It is a component wrapper like JScrollPane
     - You have access to the wrapped component's state
  - It does not use glassPane from the frame
     - It has its own a transparent panel on the top
  - JXLayer.paint() delegates all painting to the painter
     - A flexible way to modify component's appearance



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
JXLayer overview
    - Painters API
    - Image filtering
    - Translucency
       - PainterModel.setAlpha(float)
    - Non-rectangular components
       - MouseEvents filtering



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Agenda
                                 •Swing pipeline
                                 •Hooking into the pipeline
                                   •RepaintManager
                                   •Playing with opacity
                                   •Glass pane
                                   •Layering in UI delegates
                                 •Rainbow demo
                                 •Q&A



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Swing painting pipeline hooks
          JComponent                                     ComponentUI
   paint()
       paintComponent()
                                                    update()
                                                       paint()


        paintBorder()          [*]
        paintChildren() [*]




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
UI delegates basics
   - UI delegates – classes responsible for painting Swing
     components.
      - JPanel – PanelUI delegate [*]
      - JButton – ButtonUI delegate [*]
      - ... (41 different UI delegates)
   - Provide flexible control over painting different visual layers
     of Swing components


Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
UI delegate flow
          JComponent                                        ButtonUI
   paint()
       paintComponent()
                                                    update()
                                                       paint()

                                                          paintIcon()
                                                          paintText()
                                                          paintFocus()
        paintBorder()
        paintChildren()


Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Alternatives
 - Repaint manager and glass pane - much higher level
 - UI delegate can put painting code
    - After icon painting
    - But before text painting
 - Opens the field to a wide array of effects
    - Ghost images / springs
    - Ripples
    - ...
Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
DEMO
 Ghost effects




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Ghost effects sequence




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Ghost effects implementation

                                                         update()
                                                             paint()

  - Custom painting code in:                                    paintIcon()
                                                                paintText()
     - ButtonUI.paintIcon() or                                  paintFocus()
     - ButtonUI.update()




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Ghost effects eye candy
                  Icon ghosting over multiple components




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Ghost effects
    - Pros
        - Minimal changes in the application code.
        - No need for custom painting code
        - Available under multiple look and feels (use
          bytecode injection)
    - Cons
        - Custom paintComponent implementations



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Agenda
                                 •Swing pipeline
                                 •Hooking into the pipeline
                                   •RepaintManager
                                   •Playing with opacity
                                   •Glass pane
                                   •Layering in UI delegates
                                 •Rainbow demo
                                 •Q&A



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
DEMO
    Rainbow demo


         https://rainbow.dev.java.net

        Sources + WebStart link




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Links
  - JXLayer project https://swinghelper.dev.java.net/
  - Laf-Widget project http://laf-widget.dev.java.net
  - SwingX project http://swingx.dev.java.net/


  - Old blog http://weblogs.java.net/blog/kirillcool/
  - New blog http://www.pushing-pixels.org



Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
Q&A
    Kirill Grouchnikov
    kirillcool@yahoo.com




Kirill Grouchnikov, Advanced Effects in Java Desktop Applications

Mais conteúdo relacionado

Destaque

Destaque (20)

Os Lavigne
Os LavigneOs Lavigne
Os Lavigne
 
Os Gottfrid
Os GottfridOs Gottfrid
Os Gottfrid
 
Os Kelly
Os KellyOs Kelly
Os Kelly
 
Os Lewisship
Os LewisshipOs Lewisship
Os Lewisship
 
Os Grossupdated
Os GrossupdatedOs Grossupdated
Os Grossupdated
 
Os Nolen Gebhart
Os Nolen GebhartOs Nolen Gebhart
Os Nolen Gebhart
 
Os Nightingale
Os NightingaleOs Nightingale
Os Nightingale
 
Os Bernier
Os BernierOs Bernier
Os Bernier
 
Os Oram
Os OramOs Oram
Os Oram
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarsky
 
Os Ramirez
Os RamirezOs Ramirez
Os Ramirez
 
Pmg1
Pmg1Pmg1
Pmg1
 
Os Harrison
Os HarrisonOs Harrison
Os Harrison
 
Os Harris
Os HarrisOs Harris
Os Harris
 
Os Wardenupdated
Os WardenupdatedOs Wardenupdated
Os Wardenupdated
 
Os Vilain
Os VilainOs Vilain
Os Vilain
 
Os Rash
Os RashOs Rash
Os Rash
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
Os Pittaro
Os PittaroOs Pittaro
Os Pittaro
 
Os Fletcher Bereza
Os Fletcher Bereza Os Fletcher Bereza
Os Fletcher Bereza
 

Semelhante a Os Grouchnikov

CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6fungfung Chen
 
Javascript Dependency Management
Javascript Dependency ManagementJavascript Dependency Management
Javascript Dependency ManagementSean Duncan
 
State Of Ajax Zend Con 08
State Of Ajax   Zend Con 08State Of Ajax   Zend Con 08
State Of Ajax Zend Con 08bgalbs
 
Oscon2007 Windmill
Oscon2007 WindmillOscon2007 Windmill
Oscon2007 Windmilloscon2007
 
Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2360|Conferences
 
Effects Conduit
Effects ConduitEffects Conduit
Effects Conduittektor
 
Úvod do programování 7
Úvod do programování 7Úvod do programování 7
Úvod do programování 7Karel Minarik
 
Mobile VR, Programming, Rendering
Mobile VR, Programming, RenderingMobile VR, Programming, Rendering
Mobile VR, Programming, RenderingUnity Technologies
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 
Lessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to AndroidLessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to AndroidManish Mathai
 
Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019RackN
 
Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008Alcides Fonseca
 
ميهين
ميهينميهين
ميهينAhmed
 
Don't turn on/off your Photoshop yet
Don't turn on/off your Photoshop yetDon't turn on/off your Photoshop yet
Don't turn on/off your Photoshop yetFrontownia
 
Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQueryDrupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQueryMatt Butcher
 
Reverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptReverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptYusuf Motiwala
 

Semelhante a Os Grouchnikov (20)

Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 
Os Ramani
Os RamaniOs Ramani
Os Ramani
 
CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6CG OpneGL 2D viewing & simple animation-course 6
CG OpneGL 2D viewing & simple animation-course 6
 
Javascript Dependency Management
Javascript Dependency ManagementJavascript Dependency Management
Javascript Dependency Management
 
State Of Ajax Zend Con 08
State Of Ajax   Zend Con 08State Of Ajax   Zend Con 08
State Of Ajax Zend Con 08
 
Pc54
Pc54Pc54
Pc54
 
Oscon2007 Windmill
Oscon2007 WindmillOscon2007 Windmill
Oscon2007 Windmill
 
Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2
 
Effects Conduit
Effects ConduitEffects Conduit
Effects Conduit
 
Úvod do programování 7
Úvod do programování 7Úvod do programování 7
Úvod do programování 7
 
Mobile VR, Programming, Rendering
Mobile VR, Programming, RenderingMobile VR, Programming, Rendering
Mobile VR, Programming, Rendering
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 
Lessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to AndroidLessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to Android
 
Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019
 
Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008Linguagens Dinamicas - Tech Days 2008
Linguagens Dinamicas - Tech Days 2008
 
GlassFish v3 Prelude Aquarium Paris
GlassFish v3 Prelude Aquarium ParisGlassFish v3 Prelude Aquarium Paris
GlassFish v3 Prelude Aquarium Paris
 
ميهين
ميهينميهين
ميهين
 
Don't turn on/off your Photoshop yet
Don't turn on/off your Photoshop yetDon't turn on/off your Photoshop yet
Don't turn on/off your Photoshop yet
 
Drupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQueryDrupal 6 JavaScript and jQuery
Drupal 6 JavaScript and jQuery
 
Reverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptReverse Engineering Malicious Javascript
Reverse Engineering Malicious Javascript
 

Mais de oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifmoscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Moleoscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashearsoscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swposcon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Mythsoscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillipsoscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdatedoscon2007
 

Mais de oscon2007 (20)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
 
Os Borger
Os BorgerOs Borger
Os Borger
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
 
Os Fogel
Os FogelOs Fogel
Os Fogel
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
 

Último

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Último (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Os Grouchnikov

  • 1. Advanced Effects in Java Desktop Applications Kirill Grouchnikov, Senior Software Engineer, Amdocs kirillcool@yahoo.com http://www.pushing-pixels.org OSCON 2007
  • 2. Agenda •Swing pipeline •Hooking into the pipeline •RepaintManager •Playing with opacity •Glass pane •Layering in UI delegates •Rainbow demo •Q&A Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 3. Swing basics - UI toolkit for Java applications - What is a lightweight component? - Very flexible - Provides a lot of hooks for custom behavior - Not trivial to implement - Heavyweight counterparts – AWT and SWT Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 4. Swing painting pipeline - Three major “participants” - JComponent - RepaintManager - ComponentUI - Provide various hooks to customize behavior - Vary in flexibility, robustness and ease of use Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 5. Swing painting pipeline – part I JComponent RepaintManager repaint() addDirtyRegion() •Coalesce repaints •Create an event •Queue event on EDT paintDirtyRegions() EDT gets to the paintImmediately() queued event •Opacity checks •Double-buffering paint() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 6. Swing painting pipeline – part II JComponent ComponentUI paint() paintComponent() update() paint() paintBorder() paintChildren() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 7. Swing pipeline hooks - JComponent - Override paint or paintComponent - Or even repaint or paintImmediately - RepaintManager - Install a custom implementation (singleton) - ComponentUI - Provide custom painting for a specific component class Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 8. What we can achieve? - Translucency - Non-rectangular components - Layering - Image filtering - Animation Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 9. Agenda •Swing pipeline •Hooking into the pipeline •RepaintManager •Playing with opacity •Glass pane •Layering in UI delegates •Rainbow demo •Q&A Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 10. Swing painting pipeline hooks JComponent RepaintManager repaint() addDirtyRegion() •Coalesce repaints •Create an event •Queue event on EDT paintDirtyRegions() EDT gets to the paintImmediately() queued event •Opacity checks •Double-buffering paint() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 11. RepaintManager example - SwingX project - JXPanel that provides translucency - setAlpha(float) - using RepaintManagerX – see code Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 12. There can be only one (singleton) class JXPanel { public void setAlpha(float alpha) { if (alpha > 0f && alpha < 1f) { ... RepaintManager.setCurrentManager( new RepaintManagerX()); } } Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 13. Agenda •Swing pipeline •Hooking into the pipeline •RepaintManager •Playing with opacity •Glass pane •Layering in UI delegates •Rainbow demo •Q&A Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 14. Swing painting pipeline hooks JComponent RepaintManager repaint() addDirtyRegion() •Coalesce repaints •Create an event •Queue event on EDT paintDirtyRegions() EDT gets to the paintImmediately() queued event •Opacity checks •Double-buffering paint() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 15. Opacity basics - setOpaque - setOpaque(false) == “draw stuff behind me” - Useful for translucent or non-rectangular components - setOpaque(true) == “I’ll handle it” - During repainting of an opaque component Swing does not repaint any components behind Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 16. Transition effects using opacity - UIs changes are immediate - Showing / hiding a control - Moving a control to new location - Tab switch - Solution – use transitions (cross fades, fly-in / out) - Making controls non-opaque to enable the transition effects Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 17. DEMO Transition layout demo Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 18. Transition layout manager TransitionLayoutManager.getInstance(). track(myTabbedPane, true); TransitionLayoutManager.getInstance(). track(myPanel, true); - Play with opacity (set to false during animation cycle) - Set translucency (for fades) - Custom layout manager (for sliding effects) Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 19. Transition scenarios - Remains visible and has the same bounds - Remains visible and has different bounds - Becomes invisible - Added or becomes visible - Remains invisible Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 20. Agenda •Swing pipeline •Hooking into the pipeline •RepaintManager •Playing with opacity •Glass pane •Layering in UI delegates •Rainbow demo •Q&A Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 21. Swing painting pipeline hooks JComponent ComponentUI paint() paintComponent() update() paint() paintBorder() paintChildren() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 22. Glass pane basics - Painting over all the components frame.setGlassPane(new CustomGlassPanel()); frame.getGlassPane().setVisible(true); Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 23. Glass pane - Pros - Does not affect component's state - Cons - Global resource (for a frame) - Everything is repainted (performance) Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 24. JXLayer overview - It is a component wrapper like JScrollPane - You have access to the wrapped component's state - It does not use glassPane from the frame - It has its own a transparent panel on the top - JXLayer.paint() delegates all painting to the painter - A flexible way to modify component's appearance Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 25. JXLayer overview - Painters API - Image filtering - Translucency - PainterModel.setAlpha(float) - Non-rectangular components - MouseEvents filtering Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 26. Agenda •Swing pipeline •Hooking into the pipeline •RepaintManager •Playing with opacity •Glass pane •Layering in UI delegates •Rainbow demo •Q&A Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 27. Swing painting pipeline hooks JComponent ComponentUI paint() paintComponent() update() paint() paintBorder() [*] paintChildren() [*] Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 28. UI delegates basics - UI delegates – classes responsible for painting Swing components. - JPanel – PanelUI delegate [*] - JButton – ButtonUI delegate [*] - ... (41 different UI delegates) - Provide flexible control over painting different visual layers of Swing components Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 29. UI delegate flow JComponent ButtonUI paint() paintComponent() update() paint() paintIcon() paintText() paintFocus() paintBorder() paintChildren() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 30. Alternatives - Repaint manager and glass pane - much higher level - UI delegate can put painting code - After icon painting - But before text painting - Opens the field to a wide array of effects - Ghost images / springs - Ripples - ... Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 31. DEMO Ghost effects Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 32. Ghost effects sequence Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 33. Ghost effects implementation update() paint() - Custom painting code in: paintIcon() paintText() - ButtonUI.paintIcon() or paintFocus() - ButtonUI.update() Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 34. Ghost effects eye candy Icon ghosting over multiple components Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 35. Ghost effects - Pros - Minimal changes in the application code. - No need for custom painting code - Available under multiple look and feels (use bytecode injection) - Cons - Custom paintComponent implementations Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 36. Agenda •Swing pipeline •Hooking into the pipeline •RepaintManager •Playing with opacity •Glass pane •Layering in UI delegates •Rainbow demo •Q&A Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 37. DEMO Rainbow demo https://rainbow.dev.java.net Sources + WebStart link Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 38. Links - JXLayer project https://swinghelper.dev.java.net/ - Laf-Widget project http://laf-widget.dev.java.net - SwingX project http://swingx.dev.java.net/ - Old blog http://weblogs.java.net/blog/kirillcool/ - New blog http://www.pushing-pixels.org Kirill Grouchnikov, Advanced Effects in Java Desktop Applications
  • 39. Q&A Kirill Grouchnikov kirillcool@yahoo.com Kirill Grouchnikov, Advanced Effects in Java Desktop Applications