KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > gtk > BluecurveStyle


1 /*
2  * @(#)BluecurveStyle.java 1.5 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.java.swing.plaf.gtk;
8
9 import javax.swing.plaf.synth.*;
10 import java.awt.*;
11 import java.util.*;
12 import javax.swing.*;
13 import javax.swing.plaf.*;
14 import sun.swing.plaf.synth.*;
15
16 /**
17  * @version 1.5, 12/19/03
18  * @author Scott Violet
19  */

20 class BluecurveStyle extends GTKStyle implements GTKConstants {
21     /**
22      * There should only ever be one pixmap engine.
23      */

24     private static final GTKEngine BLUECURVE_ENGINE = new BluecurveEngine();
25
26     private static final Color DEFAULT_COLOR = new ColorUIResource(0, 0, 0);
27
28     /**
29      * Colors specific to blue curve. These don't appear to be specific
30      * to a state, hence they are stored here.
31      */

32     private Color[] blueColors;
33
34     /**
35      * Creates a duplicate of the passed in style.
36      */

37     public BluecurveStyle(DefaultSynthStyle style) {
38         super(style);
39     }
40
41     /**
42      * Creates a PixmapStyle from the passed in arguments.
43      */

44     public BluecurveStyle(StateInfo[] states,
45                           CircularIdentityList classSpecificValues,
46                           Font font,
47                           int xThickness, int yThickness,
48                           GTKStockIconInfo[] icons) {
49         super(states, classSpecificValues, font, xThickness, yThickness,icons);
50     }
51
52     /**
53      * Adds the state of this PixmapStyle to that of <code>s</code>
54      * returning a combined SynthStyle.
55      */

56     public DefaultSynthStyle addTo(DefaultSynthStyle s) {
57         if (!(s instanceof BluecurveStyle)) {
58             s = new BluecurveStyle(s);
59         }
60         BluecurveStyle style = (BluecurveStyle)super.addTo(s);
61         return style;
62     }
63
64     /**
65      * Creates a copy of the reciever and returns it.
66      */

67     public Object JavaDoc clone() {
68         return super.clone();
69     }
70
71     /**
72      * Returns a GTKEngine to use for rendering.
73      */

74     public GTKEngine getEngine(SynthContext context) {
75         return BLUECURVE_ENGINE;
76     }
77
78     Color getDefaultColor(JComponent c, Region id, int state,
79                           ColorType type) {
80         int colorID = type.getID();
81         if (colorID >= BluecurveColorType.MIN_ID &&
82                       colorID <= BluecurveColorType.MAX_ID) {
83             if (blueColors == null) {
84                 int min = BluecurveColorType.MIN_ID;
85                 Color base = getGTKColor(c, id, SynthConstants.SELECTED,
86                                          GTKColorType.TEXT_BACKGROUND);
87                 Color bg = getGTKColor(c, id, SynthConstants.ENABLED,
88                                        GTKColorType.BACKGROUND);
89
90                 blueColors = new Color[BluecurveColorType.MAX_ID - min + 1];
91                 blueColors[BluecurveColorType.OUTER.getID() - min] =
92                     GTKColorType.adjustColor(base, 1.0f, .72f, .7f);
93                 blueColors[BluecurveColorType.INNER_LEFT.getID() - min] =
94                     GTKColorType.adjustColor(base, 1.0f, 1.63f, 1.53f);
95                 blueColors[BluecurveColorType.TOP_GRADIENT.getID() - min] =
96                     GTKColorType.adjustColor(base, 1.0f, .93f, .88f);
97                 blueColors[BluecurveColorType.BOTTOM_GRADIENT.getID() - min] =
98                     GTKColorType.adjustColor(base, 1f, 1.16f,1.13f);
99                 blueColors[BluecurveColorType.INNER_RIGHT.getID() - min] =
100                     GTKColorType.adjustColor(base, 1.0f, 1.06f, 1.08f);
101
102                 blueColors[BluecurveColorType.OUTER2.getID() - min] =
103                     GTKColorType.adjustColor(bg, 1.0f, .67f, .67f);
104                 blueColors[BluecurveColorType.INNER_RIGHT2.getID() - min] =
105                     GTKColorType.adjustColor(bg, 1.0f, .92f, .92f);
106
107                 blueColors[BluecurveColorType.OUTER3.getID() - min] =
108                     GTKColorType.adjustColor(bg, 1.0f, .4f, .4f);
109
110                 blueColors[BluecurveColorType.OUTER4.getID() - min] =
111                     GTKColorType.adjustColor(bg, 1.0f, .84f, .84f);
112
113                 blueColors[BluecurveColorType.OUTER5.getID() - min] =
114                     GTKColorType.adjustColor(bg, 1.0f, .245f, .192f);
115             }
116             return blueColors[colorID - BluecurveColorType.MIN_ID];
117         }
118         return super.getDefaultColor(c, id, state, type);
119     }
120
121     public String JavaDoc toString() {
122         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(super.toString());
123
124         if (blueColors != null) {
125             buf.append("\t" + BluecurveColorType.OUTER + "=" +
126                        blueColors[BluecurveColorType.OUTER.getID() -
127                                   BluecurveColorType.MIN_ID] + "\n");
128             buf.append("\t" + BluecurveColorType.INNER_LEFT + "=" +
129                        blueColors[BluecurveColorType.INNER_LEFT.getID() -
130                                   BluecurveColorType.MIN_ID] + "\n");
131             buf.append("\t" + BluecurveColorType.INNER_RIGHT + "=" +
132                        blueColors[BluecurveColorType.INNER_RIGHT.getID() -
133                                   BluecurveColorType.MIN_ID] + "\n");
134             buf.append("\t" + BluecurveColorType.TOP_GRADIENT + "=" +
135                        blueColors[BluecurveColorType.TOP_GRADIENT.getID() -
136                                   BluecurveColorType.MIN_ID] + "\n");
137             buf.append("\t" + BluecurveColorType.BOTTOM_GRADIENT + "=" +
138                        blueColors[BluecurveColorType.BOTTOM_GRADIENT.getID() -
139                                   BluecurveColorType.MIN_ID] + "\n");
140             buf.append("\t" + BluecurveColorType.OUTER2 + "=" +
141                        blueColors[BluecurveColorType.OUTER2.getID() -
142                                   BluecurveColorType.MIN_ID] + "\n");
143             buf.append("\t" + BluecurveColorType.INNER_RIGHT2 + "=" +
144                        blueColors[BluecurveColorType.INNER_RIGHT2.getID() -
145                                   BluecurveColorType.MIN_ID] + "\n");
146             buf.append("\t" + BluecurveColorType.OUTER3 + "=" +
147                        blueColors[BluecurveColorType.OUTER3.getID() -
148                                   BluecurveColorType.MIN_ID] + "\n");
149             buf.append("\t" + BluecurveColorType.OUTER4 + "=" +
150                        blueColors[BluecurveColorType.OUTER4.getID() -
151                                   BluecurveColorType.MIN_ID] + "\n");
152             buf.append("\t" + BluecurveColorType.OUTER5 + "=" +
153                        blueColors[BluecurveColorType.OUTER5.getID() -
154                                   BluecurveColorType.MIN_ID] + "\n");
155         }
156         return buf.toString();
157     }
158 }
159
Popular Tags