SlideShare a Scribd company logo
1 of 39
Download to read offline
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



  paintImmediately()                     paintDirtyRegions() EDT gets to the
                                                                    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



  paintImmediately()                     paintDirtyRegions() EDT gets to the
                                                                    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



  paintImmediately()                     paintDirtyRegions() EDT gets to the
                                                                    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
    - Add drop shadow to the button text
    - And get all the rest from the core implementation
 - 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

More Related Content

What's hot

Boldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone beforeBoldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone beforeelliando dias
 
Scrumbox ece2011.pptx
Scrumbox ece2011.pptxScrumbox ece2011.pptx
Scrumbox ece2011.pptxda152
 
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...manssandstrom
 
Capstone Project Final Presentation
Capstone Project Final PresentationCapstone Project Final Presentation
Capstone Project Final PresentationMatthew Chang
 
Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics Viewaccount inactive
 
Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...
Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...
Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...Igor Sfiligoi
 
Inside the Android application framework - Google I/O 2009
Inside the Android application framework - Google I/O 2009Inside the Android application framework - Google I/O 2009
Inside the Android application framework - Google I/O 2009Viswanath J
 

What's hot (8)

Boldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone beforeBoldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone before
 
Scrumbox ece2011.pptx
Scrumbox ece2011.pptxScrumbox ece2011.pptx
Scrumbox ece2011.pptx
 
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
Att lyckas med integration av arbetet från flera scrum team - Christophe Acho...
 
Capstone Project Final Presentation
Capstone Project Final PresentationCapstone Project Final Presentation
Capstone Project Final Presentation
 
Special Effects with Qt Graphics View
Special Effects with Qt Graphics ViewSpecial Effects with Qt Graphics View
Special Effects with Qt Graphics View
 
Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...
Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...
Glidein startup Internals and Glidein configuration - glideinWMS Training Jan...
 
Inside the Android application framework - Google I/O 2009
Inside the Android application framework - Google I/O 2009Inside the Android application framework - Google I/O 2009
Inside the Android application framework - Google I/O 2009
 
Agile Software Development & Tools
Agile Software Development & ToolsAgile Software Development & Tools
Agile Software Development & Tools
 

Similar to Advanced Effects Oscon 2007

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
 
ميهين
ميهينميهين
ميهينAhmed
 
Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019RackN
 
CG simple openGL point & line-course 2
CG simple openGL point & line-course 2CG simple openGL point & line-course 2
CG simple openGL point & line-course 2fungfung Chen
 
About OpenGL and Vulkan interoperability (XDC 2020)
About OpenGL and Vulkan interoperability (XDC 2020)About OpenGL and Vulkan interoperability (XDC 2020)
About OpenGL and Vulkan interoperability (XDC 2020)Igalia
 
Oscon2007 Windmill
Oscon2007 WindmillOscon2007 Windmill
Oscon2007 Windmilloscon2007
 
Mobile VR, Programming, Rendering
Mobile VR, Programming, RenderingMobile VR, Programming, Rendering
Mobile VR, Programming, RenderingUnity Technologies
 
Image manipulationworkshop amit
Image manipulationworkshop amitImage manipulationworkshop amit
Image manipulationworkshop amitAmit Singhai
 
Mono for Game Developers - AltDevConf 2012
Mono for Game Developers - AltDevConf 2012Mono for Game Developers - AltDevConf 2012
Mono for Game Developers - AltDevConf 2012Xamarin
 
YolactEdge Review [cdm]
YolactEdge Review [cdm]YolactEdge Review [cdm]
YolactEdge Review [cdm]Dongmin Choi
 
Browser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdooBrowser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdooSebastian Werner
 
Writing Tools using WebKit
Writing Tools using WebKitWriting Tools using WebKit
Writing Tools using WebKitAriya Hidayat
 
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
 
Continuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and JenkinsContinuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and JenkinsCamilo Ribeiro
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Docker, Inc.
 

Similar to Advanced Effects Oscon 2007 (20)

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
 
ميهين
ميهينميهين
ميهين
 
Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019Immutable Infrastructure & Rethinking Configuration - Interop 2019
Immutable Infrastructure & Rethinking Configuration - Interop 2019
 
CG simple openGL point & line-course 2
CG simple openGL point & line-course 2CG simple openGL point & line-course 2
CG simple openGL point & line-course 2
 
About OpenGL and Vulkan interoperability (XDC 2020)
About OpenGL and Vulkan interoperability (XDC 2020)About OpenGL and Vulkan interoperability (XDC 2020)
About OpenGL and Vulkan interoperability (XDC 2020)
 
Oscon2007 Windmill
Oscon2007 WindmillOscon2007 Windmill
Oscon2007 Windmill
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 
Mobile VR, Programming, Rendering
Mobile VR, Programming, RenderingMobile VR, Programming, Rendering
Mobile VR, Programming, Rendering
 
Image manipulationworkshop amit
Image manipulationworkshop amitImage manipulationworkshop amit
Image manipulationworkshop amit
 
Mono for Game Developers - AltDevConf 2012
Mono for Game Developers - AltDevConf 2012Mono for Game Developers - AltDevConf 2012
Mono for Game Developers - AltDevConf 2012
 
YolactEdge Review [cdm]
YolactEdge Review [cdm]YolactEdge Review [cdm]
YolactEdge Review [cdm]
 
Browser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdooBrowser Object Model and Animations in qooxdoo
Browser Object Model and Animations in qooxdoo
 
Writing Tools using WebKit
Writing Tools using WebKitWriting Tools using WebKit
Writing Tools using WebKit
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
Javascript Dependency Management
Javascript Dependency ManagementJavascript Dependency Management
Javascript Dependency Management
 
Os Ramani
Os RamaniOs Ramani
Os Ramani
 
State Of Ajax Zend Con 08
State Of Ajax   Zend Con 08State Of Ajax   Zend Con 08
State Of Ajax Zend Con 08
 
XS Oracle 2009 Just Run It
XS Oracle 2009 Just Run ItXS Oracle 2009 Just Run It
XS Oracle 2009 Just Run It
 
Continuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and JenkinsContinuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and Jenkins
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
 

More from Kirill Grouchnikov

More from Kirill Grouchnikov (8)

Responsive mobile design in practice
Responsive mobile design in practiceResponsive mobile design in practice
Responsive mobile design in practice
 
Responsive mobile design
Responsive mobile designResponsive mobile design
Responsive mobile design
 
Designing for the mobile form factor
Designing for the mobile form factorDesigning for the mobile form factor
Designing for the mobile form factor
 
Substance Java One 2007 Community Corner
Substance Java One 2007  Community  CornerSubstance Java One 2007  Community  Corner
Substance Java One 2007 Community Corner
 
Flamingo Ribbon component
Flamingo Ribbon componentFlamingo Ribbon component
Flamingo Ribbon component
 
Party of One
Party of OneParty of One
Party of One
 
High DPI for desktop applications
High DPI for desktop applicationsHigh DPI for desktop applications
High DPI for desktop applications
 
On The Shoulders Of Giants
On The Shoulders Of GiantsOn The Shoulders Of Giants
On The Shoulders Of Giants
 

Recently uploaded

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Advanced Effects Oscon 2007

  • 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 paintImmediately() paintDirtyRegions() EDT gets to the 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 paintImmediately() paintDirtyRegions() EDT gets to the 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 paintImmediately() paintDirtyRegions() EDT gets to the 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 - Add drop shadow to the button text - And get all the rest from the core implementation - 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