Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes >...

Post on 07-Aug-2020

3 views 0 download

Transcript of Nimbus: Making Swing Look Sexy! · Allows color theming for branding. 8 ... . 18 Color Themes >...

Nimbus:Making Swing Look Sexy!

Jasper PottsPeter ZhelezniakovSun Microsystems

2

Abstract

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

3

Agenda

> Overview> Architecture> Customizations> Tool Support

4

Nimbus Overview

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

5

Its Default Look

6

Agenda

> Overview> Architecture> Customizations

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

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

9

Bitmap Scaling

10

Vector Scaling

11

9 SquareHow vectors are resized dynamically

12

Painters

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

to get scaling and caching

13

Painters

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

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

15

Agenda

> Overview> Architecture> Customizations

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”

17

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

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

19

Color Tree

nimbusBase

nimbusBlueGrey nimbusSelection

nimbusBorder

20

Creating Derived Colors

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

21

Customizing Colors

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

22

DEMO: Custom Color Theme

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

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

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

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

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

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

29

DEMO: Missile Control Login

> TODO add some demo slides

30

Further Development

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

● Fixed in 6u14> Open Designer source code

31

More Information

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

Jasper.Potts@Sun.comPeter.Zhelezniakov@Sun.com