KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > plaf > ColorUtil


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.swing.tabcontrol.plaf;
21
22
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.geom.Area JavaDoc;
26 import java.awt.image.BufferedImage JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29
30 /**
31  * Utilities for manipulating colors, caching gradient paint objects, creating a
32  * bitmap cache of the metal bumps texture and other generally useful stuff.
33  *
34  * @author Dafe Simonek, Tim Boudreau
35  */

36 final class ColorUtil {
37     private static Map JavaDoc<Integer JavaDoc, GradientPaint> gpCache = null;
38     private static Map JavaDoc<RenderingHints.Key, Object JavaDoc> hintsMap = null;
39     private static final boolean noGpCache = Boolean.getBoolean(
40             "netbeans.winsys.nogpcache"); //NOI18N
41
private static final boolean noAntialias =
42         Boolean.getBoolean("nb.no.antialias"); //NOI18N
43

44     //Values for checking if we should flush the cache bitmap
45
private static int focusedHeight = -1;
46     private static int unfocusedHeight = -1;
47     //Some handy ImageIcons for drawing the cache bitmap
48
private static Icon unfocused = null;
49     private static Icon focused = null;
50     //A scratch rectangle for computing clip intersections
51
private static Rectangle scratch = new Rectangle();
52     //The width for the backing cache bitmap for the drag texture.
53
//May want to profile and tune this a bit for optimum between memory
54
//use and painting time
55
private static final int DEFAULT_IMAGE_WIDTH = 200;
56     /**
57      * Constants for allowed texture types, to be passed to drag texture painter
58      * methods
59      */

60     public static final int SEL_TYPE = 1;
61     public static final int UNSEL_TYPE = 2;
62     public static final int FOCUS_TYPE = 4;
63     /**
64      * constants for types of tab headers
65      */

66     public static final int XP_REGULAR_TAB = 0;
67     public static final int XP_HIGHLIGHTED_TAB = 1;
68     /**
69      * constants for gradient borders
70      */

71     public static final int XP_BORDER_RIGHT = 1;
72     public static final int XP_BORDER_BOTTOM = 2;
73     /**
74      * holds icon of XP style tab drag texture
75      */

76     private static Icon XP_DRAG_IMAGE;
77     /**
78      * holds icon of Vista style tab drag texture
79      */

80     private static Icon VISTA_DRAG_IMAGE;
81
82     /**
83      * Utility class, no instances should be created.
84      */

85     private ColorUtil() {
86     }
87
88     /**
89      * Computes "middle" color in terms of rgb color space. Ignores alpha
90      * (transparency) channel
91      */

92     public static Color getMiddle(Color c1, Color c2) {
93         return new Color((c1.getRed() + c2.getRed()) / 2,
94                          (c1.getGreen() + c2.getGreen()) / 2,
95                          (c1.getBlue() + c2.getBlue()) / 2);
96     }
97
98
99     public static GradientPaint getGradientPaint(float x1, float y1,
100                                                  Color upper, float x2,
101                                                  float y2, Color lower) {
102         return getGradientPaint(x1, y1, upper, x2, y2, lower, false);
103     }
104
105     /**
106      * GradientPaint creation is somewhat expensive. This method keeps cached
107      * GradientPaint instances, and normalizes the resulting GradientPaint for
108      * horizontal and vertical cases. Note that this depends entirely on the
109      * hashing algorithm for accuracy - there are hypothetical situations
110      * where the return value could be wrong, though none have as yet been
111      * encountered, and given that the number of gradient heights and widths
112      * actually used in any UI are very small, such a situation is highly
113      * unlikely.
114      */

115     public static GradientPaint getGradientPaint(float x1, float y1,
116                                                  Color upper, float x2,
117                                                  float y2, Color lower,
118                                                  boolean repeats) {
119         if (noGpCache) {
120             return new GradientPaint(x1, y1, upper, x2, y2, lower, repeats);
121         }
122         
123         //Only for test runs with disabled customizations
124
if (upper == null) {
125             upper = Color.BLUE;
126         }
127         
128         if (lower == null) {
129             lower = Color.ORANGE;
130         }
131         
132         if (gpCache == null) {
133             gpCache = new HashMap JavaDoc<Integer JavaDoc, GradientPaint>(20);
134         }
135         //Normalize any non-repeating gradients
136
boolean horizontal = x1 == x2;
137         boolean vertical = y1 == y2;
138         if (horizontal && vertical) {
139             //Hack: gradient paint w/ 2 matching points causes endless loop
140
//in native code on mac os, so pick a random number to make sure
141
//that can't happen
142
y1 = x1 + 28;
143         } else if (horizontal && !repeats) {
144             x1 = 0;
145             x2 = 0;
146         } else if (vertical && !repeats) {
147             y1 = 0;
148             y2 = 0;
149         }
150         //TODO: Normalize non-planar repeating gp's by vector/relative location
151

152         //Generate a hash code for looking up an existing paint
153
long bits = Double.doubleToLongBits(x1)
154                 + Double.doubleToLongBits(y1) * 37 + Double.doubleToLongBits(
155                         x2) * 43 + Double.doubleToLongBits(y2) * 47;
156         int hash = ((((int) bits) ^ ((int) (bits >> 32)))
157                 ^ upper.hashCode() ^ (lower.hashCode() * 17)) * (repeats ? 31 : 1);
158
159         Integer JavaDoc key = new Integer JavaDoc(hash);
160         GradientPaint result = (GradientPaint) gpCache.get(key);
161         if (result == null) {
162             result =
163                     new GradientPaint(x1, y1, upper, x2, y2, lower, repeats);
164             if (gpCache.size() > 40) {
165                 gpCache.clear();
166             }
167             gpCache.put(key, result);
168         }
169         return result;
170     }
171
172     private static Map JavaDoc getHints() {
173         if (hintsMap == null) {
174             //Thanks to Phil Race for making this possible
175
hintsMap = (Map JavaDoc<RenderingHints.Key, Object JavaDoc>)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
176
if (hintsMap == null) {
177                 hintsMap = new HashMap JavaDoc<RenderingHints.Key, Object JavaDoc>();
178                 if (shouldAntialias()) {
179                     hintsMap.put(RenderingHints.KEY_TEXT_ANTIALIASING,
180                             RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
181                 }
182             }
183             if (shouldAntialias()) {
184                 hintsMap.put(RenderingHints.KEY_ANTIALIASING,
185                          RenderingHints.VALUE_ANTIALIAS_ON);
186             }
187         }
188         return hintsMap;
189         
190     }
191
192     public static final void setupAntialiasing(Graphics g) {
193         if (noAntialias) return;
194         
195         ((Graphics2D) g).addRenderingHints(getHints());
196     }
197     
198     private static final boolean antialias = Boolean.getBoolean(
199         "nb.cellrenderer.antialiasing") || //NOI18N
200
("GTK".equals(UIManager.getLookAndFeel().getID()) && //NOI18N
201
gtkShouldAntialias()) ||
202         Boolean.getBoolean ("swing.aatext") || //NOI18N
203
"Aqua".equals(UIManager.getLookAndFeel().getID());
204     
205     public static final boolean shouldAntialias() {
206         return antialias;
207     }
208     
209     private static final boolean gtkShouldAntialias() {
210         Object JavaDoc o = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/Antialias"); //NOI18N
211
return new Integer JavaDoc(1).equals(o);
212     }
213
214     //**************Some static utility methods for color manipulation**********
215
public static boolean isBrighter(Color a, Color b) {
216         int[] ac = new int[]{a.getRed(), a.getGreen(), a.getBlue()};
217         int[] bc = new int[]{b.getRed(), b.getGreen(), b.getBlue()};
218         int dif = 0;
219
220         for (int i = 0; i < 3; i++) {
221             int currDif = ac[i] - bc[i];
222             if (Math.abs(currDif) > Math.abs(dif)) {
223                 dif = currDif;
224             }
225         }
226         return dif > 0;
227     }
228
229     private static int minMax(int i) {
230         if (i < 0) {
231             return 0;
232         } else if (i > 255) {
233             return 255;
234         } else {
235             return i;
236         }
237     }
238
239     public static int averageDifference(Color a, Color b) {
240         int[] ac = new int[]{a.getRed(), a.getGreen(), a.getBlue()};
241         int[] bc = new int[]{b.getRed(), b.getGreen(), b.getBlue()};
242         int dif = 0;
243         for (int i = 0; i < 3; i++) {
244             dif += bc[i] - ac[i];
245         }
246         return dif / 3;
247     }
248
249     public static Color adjustComponentsTowards(Color toAdjust, Color towards) {
250         int r = toAdjust.getRed();
251         int g = toAdjust.getGreen();
252         int b = toAdjust.getBlue();
253
254         int ra = towards.getRed();
255         int ga = towards.getGreen();
256         int ba = towards.getBlue();
257
258         r += minMax((ra - r) / 3);
259         g += minMax((ga - g) / 3);
260         b += minMax((ba - b) / 3);
261
262         return new Color(r, g, b);
263     }
264
265     public static Color adjustTowards(Color toAdjust, int amount,
266                                       Color towards) {
267         int r = toAdjust.getRed();
268         int g = toAdjust.getGreen();
269         int b = toAdjust.getBlue();
270         int factor = isBrighter(towards, toAdjust) ? 1 : -1;
271         r = minMax(r + (factor * amount));
272         g = minMax(g + (factor * amount));
273         b = minMax(b + (factor * amount));
274         return new Color(r, g, b);
275     }
276
277     public static Color adjustBy(Color toAdjust, int amount) {
278         int r = minMax(toAdjust.getRed() + amount);
279         int g = minMax(toAdjust.getGreen() + amount);
280         int b = minMax(toAdjust.getBlue() + amount);
281         return new Color(r, g, b);
282     }
283
284     public static Color adjustBy(Color toAdjust, int[] amounts) {
285         int r = minMax(toAdjust.getRed() + amounts[0]);
286         int g = minMax(toAdjust.getGreen() + amounts[1]);
287         int b = minMax(toAdjust.getBlue() + amounts[2]);
288         return new Color(r, g, b);
289     }
290
291     /**
292      * Rotates a float value around 0-1
293      */

294     private static float minMax(float f) {
295         return Math.max(0, Math.min(1, f));
296     }
297
298     /**
299      * Draws drag texture of given dimensions. Texture is appropriate for Metal
300      * like view tabs
301      */

302     public static void paintViewTabBump(Graphics g, int x, int y, int width,
303                                         int height, int type) {
304         drawTexture(g, x, y, width, height, type, 0);
305     }
306
307     /**
308      * Draws drag texture of given dimensions. Texture is appropriate for Metal
309      * like document tabs
310      */

311     public static void paintDocTabBump(Graphics g, int x, int y, int width,
312                                        int height, int type) {
313         // decline set to 2, so that bump matches the spec
314
drawTexture(g, x, y, width, height, type, 2);
315     }
316
317     /**
318      * Actually draws the texture. yDecline parameter is initial y-coordination
319      * decline in pixels, effective values are <0,3>, will change the "shape" of
320      * texture a bit.
321      */

322     private static void _drawTexture(Graphics g, int x, int y, int width,
323                                      int height, int type, int yDecline) {
324         Color brightC = UIManager.getColor("TabbedPane.highlight");
325         Color darkC;
326         if (type == FOCUS_TYPE) {
327             darkC = UIManager.getColor("TabbedPane.focus");
328         } else {
329             darkC = UIManager.getColor("controlDkShadow");
330         }
331         // assure that last column and row will be dark - make width even
332
// and height odd
333
if (width % 2 != 0) {
334             width--;
335         }
336         if (height % 2 != 0) {
337             height--;
338         }
339         for (int curX = x; curX < x + width; curX++) {
340             g.setColor((curX - x) % 2 == 0 ? brightC : darkC);
341             for (int curY = y + ((curX - x + yDecline) % 4); curY < y + height; curY +=
342                     4) {
343                 g.drawLine(curX, curY, curX, curY);
344             }
345         }
346     }
347
348     /**
349      * Draws the texture from a backing bitmap, creating it on the first call.
350      * Profiling shows that 95% of the main window drawing time is spent
351      * painting this texture on the output window border. So instead, we
352      * generate a bitmap on the first call and subsequent calls just blit it to
353      * the screen.
354      */

355     private static void drawTexture(Graphics g, int x, int y, int width,
356                                     int height, int type, int yDecline) {
357
358
359         if (!g.hitClip(x, y, width, height)) {
360             return;
361         }
362         if (type == FOCUS_TYPE) {
363             if (focused == null || height > focusedHeight * 2) {
364                 //Create the focused backing bitmap
365
Image JavaDoc img = createBitmap(height, type, yDecline);
366                 //Store the height in case somebody asks to paint a region
367
//larger than our stored bitmap. Probably will never happen,
368
//but it would be difficult to diagnose if it did
369
focusedHeight = height;
370
371                 focused = new ImageIcon(img);
372             }
373             blitBitmap(g, focused, x, y, width, height);
374
375         } else {
376             if (unfocused == null || unfocusedHeight > height * 2) {
377                 //create the unfocused backing bitmap
378
Image JavaDoc img = createBitmap(height, type, yDecline);
379                 //Store the height in case somebody asks to paint a region
380
//larger than our stored bitmap. Probably will never happen,
381
//but it would be difficult to diagnose if it did
382
unfocusedHeight = height;
383                 unfocused = new ImageIcon(img);
384             }
385             blitBitmap(g, unfocused, x, y, width, height);
386         }
387     }
388
389     /**
390      * Create a backing bitmap, painting the texture into it with the specified
391      * parameters. The bitmap will be created at 2*height, so that even if
392      * there is some minor variation in height, it will not force recreating the
393      * bitmap
394      */

395     private static BufferedImage JavaDoc createBitmap(int height, int type,
396                                               int yDecline) {
397
398         //Create an optimal image for blitting to the screen with no format conversion
399
BufferedImage JavaDoc result = GraphicsEnvironment.getLocalGraphicsEnvironment()
400                 .getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(
401                         200, height * 2);
402
403         Graphics g = result.getGraphics();
404
405         if (result.getAlphaRaster() == null) {
406             Color c = type == FOCUS_TYPE ?
407                     MetalViewTabDisplayerUI.getActBgColor() :
408                     MetalViewTabDisplayerUI.getInactBgColor();
409             g.setColor(c);
410             g.fillRect(0, 0, DEFAULT_IMAGE_WIDTH, height * 2);
411         }
412
413         //draw the texture into the offscreen image
414
_drawTexture(g, 0, 0, DEFAULT_IMAGE_WIDTH, height * 2, type, yDecline);
415         return result;
416     }
417
418     /**
419      * Paint a backing bitmap into the specified rectangle of the passed
420      * Graphics object. Sets the clipping rectangle to match the coordinates
421      * and loops until the rectangle has been filled with the texture.
422      */

423     private static void blitBitmap(Graphics g, Icon icon, int x, int y, int w,
424                                    int h) {
425         //Store the current clip to reset it after
426
Shape clip = g.getClip();
427
428         if (clip == null) {
429             //Limit it to the space we're requested to paint
430
g.setClip(x, y, w, h);
431         } else {
432             //If there is an existing clip, get the intersection with the
433
//rectangle we want to paint and set that
434

435             scratch.setBounds(x, y, w, h);
436             Area JavaDoc area = new Area JavaDoc(clip);
437             area.intersect(new Area JavaDoc(scratch));
438             g.setClip(area);
439         }
440         int iwidth = icon.getIconWidth();
441         int widthPainted = 0;
442         while (widthPainted < w) {
443             //Loop until we've covered the entire area
444
icon.paintIcon(null, g, x + widthPainted, y);
445             widthPainted += iwidth;
446         }
447
448         //restore the clip
449
g.setClip(clip);
450     }
451
452     /**
453      * Paints XP style tab highlight on given coordinates and with given width.
454      */

455     public static void paintXpTabHeader(int type, Graphics g, int x, int y,
456                                         int width) {
457         Color capBorderC = getXpHeaderColor(type, false);
458         Color capFillC = getXpHeaderColor(type, true);
459         // paint header "cap" shape
460
g.setColor(capBorderC);
461         g.drawLine(x + 2, y, x + width - 3, y);
462         g.drawLine(x + 2, y, x, y + 2);
463         g.drawLine(x + width - 3, y, x + width - 1, y + 2);
464         g.setColor(capFillC);
465         g.drawLine(x + 2, y + 1, x + width - 3, y + 1);
466         g.drawLine(x + 1, y + 2, x + width - 2, y + 2);
467         // antialised effect around corners
468
// TBD
469
}
470
471     /**
472      * Gradient fill with left top light direction.
473      */

474     public static void xpFillRectGradient(Graphics2D g, Rectangle rect,
475                                           Color brightC, Color darkC) {
476         xpFillRectGradient(g, rect.x, rect.y, rect.width, rect.height, brightC,
477                            darkC, XP_BORDER_BOTTOM | XP_BORDER_RIGHT);
478     }
479
480     /**
481      * Fills given rectangle in gradient style from bright to dark colors, with
482      * virtual light shining from left top direction.
483      */

484     public static void xpFillRectGradient(Graphics2D g, int x, int y,
485                                           int width, int height, Color brightC,
486                                           Color darkC) {
487         xpFillRectGradient(g, x, y, width, height, brightC, darkC,
488                            XP_BORDER_BOTTOM | XP_BORDER_RIGHT);
489     }
490
491     /**
492      * Fills given rectangle in gradient style from bright to dark colors, with
493      * optional emphasized borders.
494      */

495     public static void xpFillRectGradient(Graphics2D g, int x, int y,
496                                           int width, int height, Color brightC,
497                                           Color darkC, int borderType) {
498         paintXpGradientBorder(g, x, y, width, height, darkC, borderType);
499         int gradWidth = ((borderType & XP_BORDER_RIGHT) != 0) ?
500                 width - 2 : width;
501         int gradHeight = ((borderType & XP_BORDER_BOTTOM) != 0) ?
502                 height - 2 : height;
503         paintXpGradientFill(g, x, y, gradWidth, gradHeight, brightC, darkC);
504     }
505
506     /**
507      * Draws drag texture of the tab in specified bounds.
508      */

509     public static void paintXpTabDragTexture(Component control, Graphics g,
510                                              int x, int y, int height) {
511         if (XP_DRAG_IMAGE == null) {
512             XP_DRAG_IMAGE = initXpDragTextureImage();
513         }
514         int count = height / 4;
515         int ypos = y;
516         for (int i = 0; i < count; i++) {
517             XP_DRAG_IMAGE.paintIcon(control, g, x, ypos);
518             ypos += 4;
519         }
520     }
521
522     /**
523      * Fills given the upper and lower halves of the given rectangle
524      * in gradient style from bright to dark colors.
525      */

526     public static void vistaFillRectGradient(Graphics2D g, Rectangle rect,
527                                           Color brightUpperC, Color darkUpperC,
528                                           Color brightLowerC, Color darkLowerC) {
529         vistaFillRectGradient(g, rect.x, rect.y, rect.width, rect.height,
530                 brightUpperC, darkUpperC, brightLowerC, darkLowerC);
531     }
532
533     /**
534      * Fills given the upper and lower halves of the given rectangle
535      * in gradient style from bright to dark colors.
536      */

537     public static void vistaFillRectGradient(Graphics2D g, int x, int y,
538                                           int width, int height,
539                                           Color brightUpperC, Color darkUpperC,
540                                           Color brightLowerC, Color darkLowerC) {
541         paintVistaGradientFill( g, x, y, width, height/2,
542                 brightUpperC, darkUpperC );
543         paintVistaGradientFill( g, x, y+height/2, width, height-height/2,
544                 brightLowerC, darkLowerC );
545     }
546
547     /**
548      * Fills given rectangle in gradient style from bright to dark colors,
549      * the upper half of the rectangle has a single color fill.
550      */

551     public static void vistaFillRectGradient(Graphics2D g, Rectangle rect,
552                                           Color upperC,
553                                           Color brightLowerC, Color darkLowerC) {
554         vistaFillRectGradient( g, rect.x, rect.y, rect.width, rect.height,
555                 upperC, brightLowerC, darkLowerC );
556     }
557     /**
558      * Fills given rectangle in gradient style from bright to dark colors,
559      * the upper half of the rectangle has a single color fill.
560      */

561     public static void vistaFillRectGradient(Graphics2D g, int x, int y,
562                                           int width, int height,
563                                           Color upperC,
564                                           Color brightLowerC, Color darkLowerC) {
565         g.setColor( upperC );
566         g.fillRect( x, y, width, height/2 );
567         paintVistaGradientFill( g, x, y+height/2, width, height-height/2,
568                 brightLowerC, darkLowerC );
569     }
570     
571     /**
572      * Draws drag texture of the tab in specified bounds.
573      */

574     public static void paintVistaTabDragTexture(Component control, Graphics g,
575                                              int x, int y, int height) {
576         if (VISTA_DRAG_IMAGE == null) {
577             VISTA_DRAG_IMAGE = initVistaDragTextureImage();
578         }
579         int count = height / 4;
580         int ypos = y;
581         g.setColor( Color.WHITE );
582         for (int i = 0; i < count; i++) {
583             VISTA_DRAG_IMAGE.paintIcon(control, g, x, ypos);
584             g.drawLine( x+1, ypos+2, x+2, ypos+2 );
585             g.drawLine( x+2, ypos+1, x+2, ypos+1 );
586             ypos += 4;
587         }
588     }
589     /**
590      * Adjusts color by given values, positive values means brightening,
591      * negative values darkening of original color.
592      *
593      * @return adjusted color
594      */

595     public static Color adjustColor(Color c, int rDiff, int gDiff, int bDiff) {
596         if (c == null) {
597             c = Color.GRAY;
598         }
599         int red = Math.max(0, Math.min(255, c.getRed() + rDiff));
600         int green = Math.max(0, Math.min(255, c.getGreen() + gDiff));
601         int blue = Math.max(0, Math.min(255, c.getBlue() + bDiff));
602         return new Color(red, green, blue);
603     }
604
605     /**
606      * Paints border of given rectangle, which enhances "light shining" effect
607      */

608     private static void paintXpGradientBorder(Graphics g, int x, int y,
609                                               int width, int height,
610                                               Color darkC, int borderType) {
611         // right and bottom border, darker
612
if ((borderType & XP_BORDER_RIGHT) != 0) {
613             Color color = adjustColor(darkC, -6, -5, -3);
614             g.setColor(color);
615             g.drawLine(x + width - 2, y, x + width - 2, y + height - 2);
616             color = adjustColor(darkC, -27, -26, -20);
617             g.setColor(color);
618             g.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
619         }
620         if ((borderType & XP_BORDER_BOTTOM) != 0) {
621             Color color = adjustColor(darkC, -6, -5, -3);
622             g.setColor(color);
623             g.drawLine(x, y + height - 2, x + width - 2, y + height - 2);
624             color = adjustColor(darkC, -27, -26, -20);
625             g.setColor(color);
626             g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
627         }
628     }
629
630     /**
631      * Fills given rectangle using top-down gradient fill of specified colors
632      */

633     private static void paintXpGradientFill(Graphics2D g, int x, int y,
634                                             int width, int height,
635                                             Color brightC, Color darkC) {
636         GradientPaint gradient = getGradientPaint(x, y, brightC, x, y + height,
637                                                   darkC);
638         g.setPaint(gradient);
639         g.fillRect(x, y, width, height);
640     }
641
642     /**
643      * @return Header color of tab depending on tab type
644      */

645     private static Color getXpHeaderColor(int type, boolean fill) {
646         String JavaDoc colorKey = null;
647         switch (type) {
648             case XP_REGULAR_TAB:
649                 colorKey = fill ? "tab_unsel_fill_bright" : "tab_border";
650                 break;
651             case XP_HIGHLIGHTED_TAB:
652                 colorKey = fill ?
653                         "tab_highlight_header_fill" : "tab_highlight_header";
654                 break;
655             default:
656                 throw new IllegalArgumentException JavaDoc(
657                         "Unknown type of tab header: " + type);
658         }
659         return UIManager.getColor(colorKey);
660     }
661
662     /**
663      * Dynamically creates and returns drag texture icon
664      */

665     private static final Icon initXpDragTextureImage() {
666         BufferedImage JavaDoc i = new BufferedImage JavaDoc(3, 3, BufferedImage.TYPE_INT_RGB);
667         Color hl = UIManager.getColor("controlLtHighlight"); //NOI18N
668
i.setRGB(2, 2, hl.getRGB());
669         i.setRGB(2, 1, hl.getRGB());
670         i.setRGB(1, 2, hl.getRGB());
671         Color dk = UIManager.getColor("TabbedPane.darkShadow"); //NOI18N
672
i.setRGB(1, 1, dk.getRGB());
673         Color corners = UIManager.getColor("TabbedPane.light"); //NOI18N
674
i.setRGB(0, 2, corners.getRGB());
675         i.setRGB(2, 0, corners.getRGB());
676         Color dk2 = UIManager.getColor("TabbedPane.shadow"); //NOI18N
677
i.setRGB(0, 1, dk2.getRGB());
678         i.setRGB(1, 0, dk2.getRGB());
679         Color up = UIManager.getColor("inactiveCaptionBorder"); //NOI18N
680
i.setRGB(0, 0, up.getRGB());
681         return new ImageIcon(i);
682     }
683     
684     /**
685      * Fills given rectangle using top-down gradient fill of specified colors
686      */

687     private static void paintVistaGradientFill(Graphics2D g, int x, int y,
688                                             int width, int height,
689                                             Color brightC, Color darkC) {
690         GradientPaint gradient = getGradientPaint(x, y, brightC, x, y + height,
691                                                   darkC);
692         g.setPaint(gradient);
693         g.fillRect(x, y, width, height);
694     }
695
696     /**
697      * Dynamically creates and returns drag texture icon
698      */

699     private static final Icon initVistaDragTextureImage() {
700         BufferedImage JavaDoc i = new BufferedImage JavaDoc(2, 2, BufferedImage.TYPE_INT_RGB);
701         int grey = new Color(124,124,124).getRGB();
702         i.setRGB(1, 0, grey);
703         i.setRGB(0, 1, grey);
704         i.setRGB(0, 0, new Color(162,163,164).getRGB());
705         i.setRGB(1, 1, new Color(107,107,107).getRGB());
706         return new ImageIcon(i);
707     }
708     
709     public boolean isBlueprintTheme() {
710             return ("blueprint".equals(//NOI18N
711
Toolkit.getDefaultToolkit().getDesktopProperty(
712                 "gnome.Net/ThemeName"))); //NOI18N
713
}
714 }
715
Popular Tags