|
|
||
Scott Violet's BlogSeptember 2005 ArchivesCustomizing Ocean GradientsPosted by zixle on September 26, 2005 at 08:37 AM | Permalink | Comments (9)In my last blog I went over how we were able to make Ocean perform as well, and in some cases better than Steel. In this blog I'm going to cover how you can change the gradients that Ocean draws. For a quick refresher the gradients in Ocean consist of 4 distinct regions as shown here:
As with other visual properties Ocean determines how to draw this gradient from the defaults table. JButton uses the defaults key "Button.gradient" to get the value that dictates what to draw. The value is a java.util.List consisting of five values. The first value is the percentage (as a Number) of the width (or height) for the first gradient. The second number gives the percentage (again as a Number) of the the width (or height) for the solid region. The remaining three values are the colors: start color for gradient 1, end color for gradient 1 and end color for gradient 2. The algorithm for drawing a vertical gradient is roughly like: List values = ...; int gradient1Height = ((Number)values.get(0)).floatValue() * h; int solidHeight = ((Number)values.get(1)).floatValue() * h; Color c1 = (Color)values.get(2); Color c2 = (Color)values.get(3); Color c2 = (Color)values.get(4); // First gradient // Fictional method that draws a gradient of the specified size. drawGradient(0, 0, width, gradient1Height, c1, c2); // Solid rectangle g.setColor(c2); fillRect(0, gradient1Height, width, solidHeight); // First gradient inverted drawGradient(0, gradient1Height + solidHeight, width, gradient1Height, c2, c1); // Last gradient drawGradient(0, gradient1Height * 2 + solidHeight, width, h - (gradient1Height * 2 + solidHeight), c1, c3); And the code to initialize the value is roughly like:
java.util.List buttonGradient = Arrays.asList(
new Object[] {new Float(.3f), new Float(0f),
new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() });
Because the colors are not hard coded, you can change the way Ocean looks by changing the value in the defaults table. For example, you can go for the garish:
To the minimalist:
Or a slightly brighter Ocean look:
You can even get a look similar to that used by Incor's Alloy Look and Feel:
Or an XP like gradient:
Ocean Gradient CustomizerIf you have 1.5 you can try your hand at a good combination using the Ocean Gradient Customizer. Post your favorite combinations and I'll do a future blog on the various combinations people have come up with. Ocean, Gradients and Image Caching - oh myPosted by zixle on September 06, 2005 at 06:00 AM | Permalink | Comments (3)One of the biggest features we did in 1.5 was revamping the java look and feel by providing a new theme (OceanTheme). Love it or hate it, Ocean requires a bit more graphics support than the line primitives of yore. In order to make Ocean the default we needed to make sure performance was in line with the old theme (Steel). All of our internal tests show that we succeeded, Ocean performs as well and better in some cases, than Steel. How did we do this? Before I get into the solution let's first look at how the gradients that Ocean makes such extensive use of are painted. The gradient is not a single gradient, but is made up of four distinct areas: 1. Gradient from color1 - color2 Here's a monsterously large button showing the distinct regions:
We placed all this functionality into the package private abstract class javax.swing.plaf.metal.CachedPainter (in 1.6 this has been moved to sun.swing), take a look if you're curious. This class hides all the image management, and SoftReference trickyness from subclasses, a subclass only need override a single method to do the actual painting. CachedPainter makes use of varags to allow for seamless passing of arguments to the method responsible for the actual painting. It results in lossing some type safety, but it works. One last thing, for compatability Ocean still uses bold fonts, but this can easily be turned off with the system property swing.boldMetal=false. Oh ya! Special thank to Romain for helping with the image. | ||
|
|