KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > TMSchema


1 /*
2  * @(#)TMSchema.java 1.3 07/01/18
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /*
9  * <p>These classes are designed to be used while the
10  * corresponding <code>LookAndFeel</code> class has been installed
11  * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>).
12  * Using them while a different <code>LookAndFeel</code> is installed
13  * may produce unexpected results, including exceptions.
14  * Additionally, changing the <code>LookAndFeel</code>
15  * maintained by the <code>UIManager</code> without updating the
16  * corresponding <code>ComponentUI</code> of any
17  * <code>JComponent</code>s may also produce unexpected results,
18  * such as the wrong colors showing up, and is generally not
19  * encouraged.
20  *
21  */

22
23 package com.sun.java.swing.plaf.windows;
24
25 import java.awt.*;
26 import java.util.*;
27
28 import javax.swing.*;
29
30 import sun.awt.windows.ThemeReader;
31
32 /**
33  * Implements Windows Parts and their States and Properties for the Windows Look and Feel.
34  *
35  * See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp
36  *
37  * @version 1.3 01/18/07
38  * @author Leif Samuelsson
39  */

40 class TMSchema {
41
42     /**
43      * An enumeration of the various Windows controls (also known as
44      * components, or top-level parts)
45      */

46     public static enum Control {
47     BUTTON,
48     COMBOBOX,
49     EDIT,
50     HEADER,
51     LISTBOX,
52     LISTVIEW,
53     MENU,
54     PROGRESS,
55     REBAR,
56     SCROLLBAR,
57     SPIN,
58     TAB,
59     TOOLBAR,
60     TRACKBAR,
61     TREEVIEW,
62     WINDOW
63     }
64
65
66     /**
67      * An enumeration of the Windows compoent parts
68      */

69     public static enum Part {
70     MENU (Control.MENU, 0), // Special case, not in native
71
MP_BARBACKGROUND (Control.MENU, 7),
72         MP_BARITEM (Control.MENU, 8),
73         MP_POPUPBACKGROUND (Control.MENU, 9),
74         MP_POPUPBORDERS (Control.MENU, 10),
75         MP_POPUPCHECK (Control.MENU, 11),
76         MP_POPUPCHECKBACKGROUND (Control.MENU, 12),
77         MP_POPUPGUTTER (Control.MENU, 13),
78         MP_POPUPITEM (Control.MENU, 14),
79         MP_POPUPSEPARATOR (Control.MENU, 15),
80         MP_POPUPSUBMENU (Control.MENU, 16),
81
82         BP_PUSHBUTTON (Control.BUTTON, 1),
83         BP_RADIOBUTTON(Control.BUTTON, 2),
84         BP_CHECKBOX (Control.BUTTON, 3),
85         BP_GROUPBOX (Control.BUTTON, 4),
86
87         CP_COMBOBOX (Control.COMBOBOX, 0),
88         CP_DROPDOWNBUTTON(Control.COMBOBOX, 1),
89         CP_BACKGROUND (Control.COMBOBOX, 2),
90         CP_TRANSPARENTBACKGROUND (Control.COMBOBOX, 3),
91         CP_BORDER (Control.COMBOBOX, 4),
92         CP_READONLY (Control.COMBOBOX, 5),
93         CP_DROPDOWNBUTTONRIGHT (Control.COMBOBOX, 6),
94         CP_DROPDOWNBUTTONLEFT (Control.COMBOBOX, 7),
95         CP_CUEBANNER (Control.COMBOBOX, 8),
96
97         EP_EDIT (Control.EDIT, 0),
98         EP_EDITTEXT(Control.EDIT, 1),
99
100         HP_HEADERITEM(Control.HEADER, 1),
101         HP_HEADERSORTARROW(Control.HEADER, 4),
102
103         LBP_LISTBOX(Control.LISTBOX, 0),
104
105         LVP_LISTVIEW(Control.LISTVIEW, 0),
106
107         PP_PROGRESS (Control.PROGRESS, 0),
108         PP_BAR (Control.PROGRESS, 1),
109         PP_BARVERT (Control.PROGRESS, 2),
110         PP_CHUNK (Control.PROGRESS, 3),
111         PP_CHUNKVERT(Control.PROGRESS, 4),
112
113         RP_GRIPPER (Control.REBAR, 1),
114         RP_GRIPPERVERT(Control.REBAR, 2),
115
116         SBP_SCROLLBAR (Control.SCROLLBAR, 0),
117         SBP_ARROWBTN (Control.SCROLLBAR, 1),
118         SBP_THUMBBTNHORZ (Control.SCROLLBAR, 2),
119         SBP_THUMBBTNVERT (Control.SCROLLBAR, 3),
120         SBP_LOWERTRACKHORZ(Control.SCROLLBAR, 4),
121         SBP_UPPERTRACKHORZ(Control.SCROLLBAR, 5),
122         SBP_LOWERTRACKVERT(Control.SCROLLBAR, 6),
123         SBP_UPPERTRACKVERT(Control.SCROLLBAR, 7),
124         SBP_GRIPPERHORZ (Control.SCROLLBAR, 8),
125         SBP_GRIPPERVERT (Control.SCROLLBAR, 9),
126         SBP_SIZEBOX (Control.SCROLLBAR, 10),
127
128         SPNP_SPINUP (Control.SPIN, 1),
129         SPNP_SPINDOWN(Control.SPIN, 2),
130
131         TABP_TABITEM (Control.TAB, 1),
132         TABP_TABITEMLEFTEDGE (Control.TAB, 2),
133         TABP_TABITEMRIGHTEDGE(Control.TAB, 3),
134         TABP_PANE (Control.TAB, 9),
135
136         TP_TOOLBAR (Control.TOOLBAR, 0),
137         TP_BUTTON (Control.TOOLBAR, 1),
138         TP_SEPARATOR (Control.TOOLBAR, 5),
139         TP_SEPARATORVERT (Control.TOOLBAR, 6),
140
141         TKP_TRACK (Control.TRACKBAR, 1),
142         TKP_TRACKVERT (Control.TRACKBAR, 2),
143         TKP_THUMB (Control.TRACKBAR, 3),
144         TKP_THUMBBOTTOM(Control.TRACKBAR, 4),
145         TKP_THUMBTOP (Control.TRACKBAR, 5),
146         TKP_THUMBVERT (Control.TRACKBAR, 6),
147         TKP_THUMBLEFT (Control.TRACKBAR, 7),
148         TKP_THUMBRIGHT (Control.TRACKBAR, 8),
149         TKP_TICS (Control.TRACKBAR, 9),
150         TKP_TICSVERT (Control.TRACKBAR, 10),
151
152         TVP_TREEVIEW(Control.TREEVIEW, 0),
153         TVP_GLYPH (Control.TREEVIEW, 2),
154
155         WP_WINDOW (Control.WINDOW, 0),
156         WP_CAPTION (Control.WINDOW, 1),
157         WP_MINCAPTION (Control.WINDOW, 3),
158         WP_MAXCAPTION (Control.WINDOW, 5),
159         WP_FRAMELEFT (Control.WINDOW, 7),
160         WP_FRAMERIGHT (Control.WINDOW, 8),
161         WP_FRAMEBOTTOM (Control.WINDOW, 9),
162         WP_SYSBUTTON (Control.WINDOW, 13),
163         WP_MDISYSBUTTON (Control.WINDOW, 14),
164         WP_MINBUTTON (Control.WINDOW, 15),
165         WP_MDIMINBUTTON (Control.WINDOW, 16),
166         WP_MAXBUTTON (Control.WINDOW, 17),
167         WP_CLOSEBUTTON (Control.WINDOW, 18),
168         WP_MDICLOSEBUTTON (Control.WINDOW, 20),
169         WP_RESTOREBUTTON (Control.WINDOW, 21),
170         WP_MDIRESTOREBUTTON(Control.WINDOW, 22);
171
172         private final Control control;
173         private final int value;
174
175         private Part(Control control, int value) {
176             this.control = control;
177             this.value = value;
178         }
179
180     public int getValue() {
181         return value;
182     }
183
184         public String JavaDoc getControlName(Component component) {
185         String JavaDoc str = "";
186         if (component instanceof JComponent) {
187         JComponent c = (JComponent)component;
188         String JavaDoc subAppName = (String JavaDoc)c.getClientProperty("XPStyle.subAppName");
189         if (subAppName != null) {
190             str = subAppName + "::";
191         }
192         }
193             return str + control.toString();
194         }
195
196         public String JavaDoc toString() {
197             return control.toString()+"."+name();
198         }
199     }
200
201
202     /**
203      * An enumeration of the possible component states
204      */

205     public static enum State {
206         ACTIVE,
207         ASSIST,
208         BITMAP,
209         CHECKED,
210         CHECKEDDISABLED,
211         CHECKEDHOT,
212         CHECKEDNORMAL,
213         CHECKEDPRESSED,
214         CHECKMARKNORMAL,
215         CHECKMARKDISABLED,
216         BULLETNORMAL,
217         BULLETDISABLED,
218         CLOSED,
219         DEFAULTED,
220         DISABLED,
221         DISABLEDHOT,
222         DISABLEDPUSHED,
223         DOWNDISABLED,
224         DOWNHOT,
225         DOWNNORMAL,
226         DOWNPRESSED,
227         FOCUSED,
228         HOT,
229         HOTCHECKED,
230         INACTIVE,
231     INACTIVENORMAL, // See note 1
232
INACTIVEHOT, // See note 1
233
INACTIVEPUSHED, // See note 1
234
INACTIVEDISABLED, // See note 1
235
LEFTDISABLED,
236         LEFTHOT,
237         LEFTNORMAL,
238         LEFTPRESSED,
239         MIXEDDISABLED,
240         MIXEDHOT,
241         MIXEDNORMAL,
242         MIXEDPRESSED,
243         NORMAL,
244         PRESSED,
245         OPENED,
246         PUSHED,
247         READONLY,
248         RIGHTDISABLED,
249         RIGHTHOT,
250         RIGHTNORMAL,
251         RIGHTPRESSED,
252         SELECTED,
253         UNCHECKEDDISABLED,
254         UNCHECKEDHOT,
255         UNCHECKEDNORMAL,
256         UNCHECKEDPRESSED,
257         UPDISABLED,
258         UPHOT,
259         UPNORMAL,
260         UPPRESSED;
261
262
263     /**
264      * A map of allowed states for each Part
265      */

266     private static EnumMap<Part, State[]> stateMap;
267
268     private static synchronized void initStates() {
269         stateMap = new EnumMap<Part, State[]>(Part.class);
270
271         stateMap.put(Part.EP_EDITTEXT,
272                new State[] {
273             NORMAL, HOT, SELECTED, DISABLED, FOCUSED, READONLY, ASSIST
274         });
275
276         stateMap.put(Part.BP_PUSHBUTTON,
277                new State[] { NORMAL, HOT, PRESSED, DISABLED, DEFAULTED });
278
279         stateMap.put(Part.BP_RADIOBUTTON,
280                new State[] {
281             UNCHECKEDNORMAL, UNCHECKEDHOT, UNCHECKEDPRESSED, UNCHECKEDDISABLED,
282             CHECKEDNORMAL, CHECKEDHOT, CHECKEDPRESSED, CHECKEDDISABLED
283         });
284
285         stateMap.put(Part.BP_CHECKBOX,
286                new State[] {
287             UNCHECKEDNORMAL, UNCHECKEDHOT, UNCHECKEDPRESSED, UNCHECKEDDISABLED,
288             CHECKEDNORMAL, CHECKEDHOT, CHECKEDPRESSED, CHECKEDDISABLED,
289             MIXEDNORMAL, MIXEDHOT, MIXEDPRESSED, MIXEDDISABLED
290         });
291
292             State[] comboBoxStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
293             stateMap.put(Part.CP_COMBOBOX, comboBoxStates);
294             stateMap.put(Part.CP_DROPDOWNBUTTON, comboBoxStates);
295             stateMap.put(Part.CP_BACKGROUND, comboBoxStates);
296             stateMap.put(Part.CP_TRANSPARENTBACKGROUND, comboBoxStates);
297             stateMap.put(Part.CP_BORDER, comboBoxStates);
298             stateMap.put(Part.CP_READONLY, comboBoxStates);
299             stateMap.put(Part.CP_DROPDOWNBUTTONRIGHT, comboBoxStates);
300             stateMap.put(Part.CP_DROPDOWNBUTTONLEFT, comboBoxStates);
301             stateMap.put(Part.CP_CUEBANNER, comboBoxStates);
302
303         stateMap.put(Part.HP_HEADERITEM, new State[] { NORMAL, HOT, PRESSED });
304
305         State[] scrollBarStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
306         stateMap.put(Part.SBP_SCROLLBAR, scrollBarStates);
307         stateMap.put(Part.SBP_THUMBBTNVERT, scrollBarStates);
308         stateMap.put(Part.SBP_THUMBBTNHORZ, scrollBarStates);
309         stateMap.put(Part.SBP_GRIPPERVERT, scrollBarStates);
310         stateMap.put(Part.SBP_GRIPPERHORZ, scrollBarStates);
311
312         stateMap.put(Part.SBP_ARROWBTN,
313                new State[] {
314             UPNORMAL, UPHOT, UPPRESSED, UPDISABLED,
315             DOWNNORMAL, DOWNHOT, DOWNPRESSED, DOWNDISABLED,
316             LEFTNORMAL, LEFTHOT, LEFTPRESSED, LEFTDISABLED,
317             RIGHTNORMAL, RIGHTHOT, RIGHTPRESSED, RIGHTDISABLED
318         });
319
320
321         State[] spinnerStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
322         stateMap.put(Part.SPNP_SPINUP, spinnerStates);
323         stateMap.put(Part.SPNP_SPINDOWN, spinnerStates);
324
325         stateMap.put(Part.TVP_GLYPH, new State[] { CLOSED, OPENED });
326
327         State[] frameButtonStates = new State[] {
328             NORMAL, HOT, PUSHED, DISABLED, // See note 1
329
INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED,
330         };
331         // Note 1: The INACTIVE frame button states apply when the frame
332
// is inactive. They are not defined in tmschema.h
333

334         // Fix for 6316538: Vista has five frame button states
335
if (ThemeReader.getInt(Control.WINDOW.toString(),
336                    Part.WP_CLOSEBUTTON.getValue(), 1,
337                    Prop.IMAGECOUNT.getValue()) == 10) {
338         frameButtonStates = new State[] {
339             NORMAL, HOT, PUSHED, DISABLED, null,
340             INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED, null
341         };
342         }
343
344         stateMap.put(Part.WP_MINBUTTON, frameButtonStates);
345         stateMap.put(Part.WP_MAXBUTTON, frameButtonStates);
346         stateMap.put(Part.WP_RESTOREBUTTON, frameButtonStates);
347         stateMap.put(Part.WP_CLOSEBUTTON, frameButtonStates);
348
349         // States for Slider (trackbar)
350
stateMap.put(Part.TKP_TRACK, new State[] { NORMAL });
351         stateMap.put(Part.TKP_TRACKVERT, new State[] { NORMAL });
352
353         State[] sliderThumbStates =
354         new State[] { NORMAL, HOT, PRESSED, FOCUSED, DISABLED };
355         stateMap.put(Part.TKP_THUMB, sliderThumbStates);
356         stateMap.put(Part.TKP_THUMBBOTTOM, sliderThumbStates);
357         stateMap.put(Part.TKP_THUMBTOP, sliderThumbStates);
358         stateMap.put(Part.TKP_THUMBVERT, sliderThumbStates);
359         stateMap.put(Part.TKP_THUMBRIGHT, sliderThumbStates);
360
361         // States for Tabs
362
State[] tabStates = new State[] { NORMAL, HOT, SELECTED, DISABLED, FOCUSED };
363         stateMap.put(Part.TABP_TABITEM, tabStates);
364         stateMap.put(Part.TABP_TABITEMLEFTEDGE, tabStates);
365         stateMap.put(Part.TABP_TABITEMRIGHTEDGE, tabStates);
366
367
368         stateMap.put(Part.TP_BUTTON,
369                new State[] {
370             NORMAL, HOT, PRESSED, DISABLED, CHECKED, HOTCHECKED
371         });
372
373         State[] frameStates = new State[] { ACTIVE, INACTIVE };
374         stateMap.put(Part.WP_WINDOW, frameStates);
375         stateMap.put(Part.WP_FRAMELEFT, frameStates);
376         stateMap.put(Part.WP_FRAMERIGHT, frameStates);
377         stateMap.put(Part.WP_FRAMEBOTTOM, frameStates);
378
379         State[] captionStates = new State[] { ACTIVE, INACTIVE, DISABLED };
380         stateMap.put(Part.WP_CAPTION, captionStates);
381         stateMap.put(Part.WP_MINCAPTION, captionStates);
382         stateMap.put(Part.WP_MAXCAPTION, captionStates);
383
384             stateMap.put(Part.MP_BARBACKGROUND,
385                          new State[] { ACTIVE, INACTIVE });
386             stateMap.put(Part.MP_BARITEM,
387                          new State[] { NORMAL, HOT, PUSHED,
388                                        DISABLED, DISABLEDHOT, DISABLEDPUSHED });
389             stateMap.put(Part.MP_POPUPCHECK,
390                          new State[] { CHECKMARKNORMAL, CHECKMARKDISABLED,
391                                        BULLETNORMAL, BULLETDISABLED });
392             stateMap.put(Part.MP_POPUPCHECKBACKGROUND,
393                          new State[] { DISABLEDPUSHED, NORMAL, BITMAP });
394             stateMap.put(Part.MP_POPUPITEM,
395                          new State[] { NORMAL, HOT, DISABLED, DISABLEDHOT });
396             stateMap.put(Part.MP_POPUPSUBMENU,
397                          new State[] { NORMAL, DISABLED });
398             
399         }
400
401
402     public static synchronized int getValue(Part part, State state) {
403         if (stateMap == null) {
404         initStates();
405         }
406
407         Enum JavaDoc[] states = stateMap.get(part);
408         if (states != null) {
409         for (int i = 0; i < states.length; i++) {
410             if (state == states[i]) {
411             return i + 1;
412             }
413         }
414         }
415
416         if (state == null || state == State.NORMAL) {
417         return 1;
418         }
419
420         return 0;
421     }
422
423     }
424
425
426     /**
427      * An enumeration of the possible component attributes and the
428      * corresponding value type
429      */

430     public static enum Prop {
431         COLOR(Color.class, 204),
432         SIZE(Dimension.class, 207),
433
434         FLATMENUS(Boolean JavaDoc.class, 1001),
435
436         BORDERONLY(Boolean JavaDoc.class, 2203), // only draw the border area of the image
437

438         IMAGECOUNT(Integer JavaDoc.class, 2401), // the number of state images in an imagefile
439
BORDERSIZE(Integer JavaDoc.class, 2403), // the size of the border line for bgtype=BorderFill
440

441         PROGRESSCHUNKSIZE(Integer JavaDoc.class, 2411), // size of progress control chunks
442
PROGRESSSPACESIZE(Integer JavaDoc.class, 2412), // size of progress control spaces
443

444         TEXTSHADOWOFFSET(Point.class, 3402), // where char shadows are drawn, relative to orig. chars
445

446         NORMALSIZE(Dimension.class, 3409), // size of dest rect that exactly source
447

448
449         SIZINGMARGINS ( Insets.class, 3601), // margins used for 9-grid sizing
450
CONTENTMARGINS(Insets.class, 3602), // margins that define where content can be placed
451
CAPTIONMARGINS(Insets.class, 3603), // margins that define where caption text can be placed
452

453         BORDERCOLOR(Color.class, 3801), // color of borders for BorderFill
454
FILLCOLOR ( Color.class, 3802), // color of bg fill
455
TEXTCOLOR ( Color.class, 3803), // color text is drawn in
456

457         TEXTSHADOWCOLOR(Color.class, 3818), // color of text shadow
458

459         BGTYPE(Integer JavaDoc.class, 4001), // basic drawing type for each part
460

461         TEXTSHADOWTYPE(Integer JavaDoc.class, 4010); // type of shadow to draw with text
462

463
464
465         private final Class JavaDoc type;
466         private final int value;
467
468         private Prop(Class JavaDoc type, int value) {
469             this.type = type;
470             this.value = value;
471         }
472
473     public int getValue() {
474         return value;
475     }
476
477         public String JavaDoc toString() {
478             return name()+"["+type.getName()+"] = "+value;
479         }
480     }
481
482
483     /**
484      * An enumeration of attribute values for some Props
485      */

486     public static enum TypeEnum {
487         BT_IMAGEFILE (Prop.BGTYPE, "imagefile", 0),
488         BT_BORDERFILL(Prop.BGTYPE, "borderfill", 1),
489
490         TST_SINGLE(Prop.TEXTSHADOWTYPE, "single", 1),
491         TST_CONTINUOUS(Prop.TEXTSHADOWTYPE, "continuous", 2);
492
493
494         private TypeEnum(Prop prop, String JavaDoc enumName, int value) {
495             this.prop = prop;
496             this.enumName = enumName;
497             this.value = value;
498         }
499
500         private final Prop prop;
501         private final String JavaDoc enumName;
502         private final int value;
503
504         public String JavaDoc toString() {
505             return prop+"="+enumName+"="+value;
506         }
507
508     String JavaDoc getName() {
509         return enumName;
510     }
511
512
513         static TypeEnum getTypeEnum(Prop prop, int enumval) {
514             for (TypeEnum e : TypeEnum.values()) {
515                 if (e.prop == prop && e.value == enumval) {
516                     return e;
517                 }
518             }
519             return null;
520         }
521     }
522 }
523
Popular Tags