Download - Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

Transcript
Page 1: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

Nimbus:Making Swing Look Sexy!

Jasper PottsPeter ZhelezniakovSun Microsystems

Page 2: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

2

Abstract

Get acquainted with the new Nimbus Look andFeel, and learn some ways to customize it

Page 3: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

3

Agenda

> Overview> Architecture> Customizations> Tool Support

Page 4: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

4

Nimbus Overview

> A Synth descendant> Cross platform> Vector based> Painters based> Highly customizable> Now in JDK7!

Page 5: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

5

Its Default Look

Page 6: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

6

Agenda

> Overview> Architecture> Customizations

Page 7: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

7

Vector Based

> All Nimbus components are purely vector based● Scalable: larger or smaller

> No images used● Allows us to participate in solution for hi-DPI● Allows color theming for branding

Page 8: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

8

Vector Based

> Heuristic based image caching● Cache is invalidated if the sizes change

dramatically● Or colors, fonts, etc change

> 9-Square technique resizes vector shapes● Move control points based on location in grid

Page 9: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

9

Bitmap Scaling

Page 10: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

10

Vector Scaling

Page 11: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

11

9 SquareHow vectors are resized dynamically

Page 12: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

12

Painters

> Component rendering is delegated to Painters● javax.swing.Painter● Stateless● Extend AbstractRegionPainter

to get scaling and caching

Page 13: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

13

Painters

public interface Painter { public void paint( Graphics2D g, JComponent c, int width, int height);}

Page 14: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

14

Now in JDKTM7

> javax.swing.plaf.nimbus> javax.swing.Painter> Some old com.sun.java.swing stuff

preserved for backward compatibility:● Painter● plaf.nimbus.NimbusLookAndFeel

Page 15: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

15

Agenda

> Overview> Architecture> Customizations

Page 16: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

16

Scalable Components

> Support for small and large components● For use in palettes or toolbars

> Supply a client property to the component● “JComponent.sizeVariant”● Either “large”, “small”, or “mini”

Page 17: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

17

Scalable Componentshttps://laffy.dev.java.net

Page 18: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

18

Color Themes

> Most colors are derived from a set ofbase colors

> Derived colors are updated automatically whentheir parent colors change

> Derived colors refer to parent colors indirectly viaUI property name

Page 19: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

19

Color Tree

nimbusBase

nimbusBlueGrey nimbusSelection

nimbusBorder

Page 20: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

20

Creating Derived Colors

> NimbusLookAndFeel.getDerivedColor(String uiDefaultParentName,float hOffset, float sOffset,float bOffset, int aOffset,boolean uiResource)

Page 21: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

21

Customizing Colors

UIManager.put("nimbusBase", new Color(...));UIManager.put("nimbusBlueGrey", new Color(...));UIManager.put("control", new Color(...));

Page 22: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

22

DEMO: Custom Color Theme

Page 23: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

23

Everything is in UIDefaults

> All customizations are exposed via UIDefaults● Button.foreground

> Properties can be state dependent● Button[Disabled].foreground

> States can be combined● Button[Default+Focused].foreground

Page 24: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

24

Selectors

> Region names● ComboBox

> Component names● “ComboBox.renderer”

● Applies to all components with that name> Hierarchical

● MenuBar:Menu● Applies to all Menus whose parent is a MenuBar

Page 25: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

25

Cascading Defaults

> Most specific default wins> Example:

● foreground = Color.BLACK● Label.foreground = Color.BLUE● Label[Disabled].foreground = Color.GRAY● “SomeLabel”[Disabled].foreground = Color.WHITE

Page 26: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

26

Customizations

> States> Fonts and colors> Standard components

● Replace painting code and change defaults● For all components of a single type (ie: JButton)● For a single component instance● For all components with a specific name

> Add support for 3rd Party components

Page 27: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

27

Per-instance Customization

> Create a UIDefaults Map> Load the map with all overrides of global values> Set map on target component

● Nimbus.Overrides> Ignore UIManager defaults if necessary

● Nimbus.Overrides.InheritDefaults

Page 28: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

28

Custom Painters

> Button[Enabled].backgroundPainter● Used by buttons when enabled

> Button[MouseOver].borderPainter● Used by buttons when mouse over

> Button.foregroundPainter● Used by default

Page 29: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

29

DEMO: Missile Control Login

> TODO add some demo slides

Page 30: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

30

Further Development

> Publish Synth delegates: 6827653> Fix startup performance: 6802944

● Fixed in 6u14> Open Designer source code

Page 31: Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes > Most colors are derived from a set of base colors > Derived colors are updated automatically

31

More Information

> http://openjdk.java.net> https://laffy.dev.java.net> http://www.jasperpotts.com/blog