KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > decorator > HierarchicalColumnHighlighter


1 /*
2  * $Id: HierarchicalColumnHighlighter.java,v 1.2 2004/10/14 01:28:19 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.decorator;
9
10 import java.awt.Color JavaDoc;
11 import java.awt.Component JavaDoc;
12
13 /**
14  * HierarchicalColumnHighlighter
15  *
16  * @author Ramesh Gupta
17  */

18 public class HierarchicalColumnHighlighter extends Highlighter {
19     public HierarchicalColumnHighlighter() {
20     }
21
22     public HierarchicalColumnHighlighter(Color JavaDoc background, Color JavaDoc foreground) {
23         super(background, foreground);
24     }
25
26     protected Color JavaDoc computeBackground(Component JavaDoc component, ComponentAdapter adapter) {
27         if (adapter.isHierarchical()) {
28             Color JavaDoc background = getBackground();
29             Color JavaDoc seed = background == null ? component.getBackground() : background;
30             seed = computeBackgroundSeed(seed);
31             return adapter.isSelected() ? computeSelectedBackground(seed) : seed;
32         }
33         return null; // don't change the background
34
}
35
36     public Color JavaDoc getForeground(Component JavaDoc component, ComponentAdapter adapter) {
37         if (adapter.isHierarchical()) {
38             if (getForeground() != null) {
39                 return super.computeForeground(component, adapter);
40             }
41         }
42         return null; // don't change the foreground
43
}
44
45     protected Color JavaDoc computeBackgroundSeed(Color JavaDoc seed) {
46         return new Color JavaDoc(Math.max((int)(seed.getRed() * 0.95), 0),
47                          Math.max((int)(seed.getGreen()* 0.95), 0),
48                          Math.max((int)(seed.getBlue() * 0.95), 0));
49     }
50 }
51
Popular Tags