src/java.desktop/share/classes/com/sun/java/swing/plaf/windows/TMSchema.java
branchhttp-client-branch
changeset 55982 b6ff245c0db6
parent 55981 907bddce488c
parent 48332 651a95f30dfb
child 55983 e4a1f0c9d4c6
equal deleted inserted replaced
55981:907bddce488c 55982:b6ff245c0db6
     1 /*
       
     2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 /*
       
    27  * <p>These classes are designed to be used while the
       
    28  * corresponding <code>LookAndFeel</code> class has been installed
       
    29  * (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>).
       
    30  * Using them while a different <code>LookAndFeel</code> is installed
       
    31  * may produce unexpected results, including exceptions.
       
    32  * Additionally, changing the <code>LookAndFeel</code>
       
    33  * maintained by the <code>UIManager</code> without updating the
       
    34  * corresponding <code>ComponentUI</code> of any
       
    35  * <code>JComponent</code>s may also produce unexpected results,
       
    36  * such as the wrong colors showing up, and is generally not
       
    37  * encouraged.
       
    38  *
       
    39  */
       
    40 
       
    41 package com.sun.java.swing.plaf.windows;
       
    42 
       
    43 import java.awt.*;
       
    44 import java.util.*;
       
    45 
       
    46 import javax.swing.*;
       
    47 
       
    48 import sun.awt.windows.ThemeReader;
       
    49 
       
    50 /**
       
    51  * Implements Windows Parts and their States and Properties for the Windows Look and Feel.
       
    52  *
       
    53  * See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp
       
    54  * See tmschema.h (or vssym32.h & vsstyle.h for MS Vista)
       
    55  *
       
    56  * @author Leif Samuelsson
       
    57  */
       
    58 class TMSchema {
       
    59 
       
    60     /**
       
    61      * An enumeration of the various Windows controls (also known as
       
    62      * components, or top-level parts)
       
    63      */
       
    64     public static enum Control {
       
    65         BUTTON,
       
    66         COMBOBOX,
       
    67         EDIT,
       
    68         HEADER,
       
    69         LISTBOX,
       
    70         LISTVIEW,
       
    71         MENU,
       
    72         PROGRESS,
       
    73         REBAR,
       
    74         SCROLLBAR,
       
    75         SPIN,
       
    76         TAB,
       
    77         TOOLBAR,
       
    78         TRACKBAR,
       
    79         TREEVIEW,
       
    80         WINDOW
       
    81     }
       
    82 
       
    83 
       
    84     /**
       
    85      * An enumeration of the Windows compoent parts
       
    86      */
       
    87     public static enum Part {
       
    88         MENU (Control.MENU, 0), // Special case, not in native
       
    89         MP_BARBACKGROUND   (Control.MENU, 7),
       
    90         MP_BARITEM         (Control.MENU, 8),
       
    91         MP_POPUPBACKGROUND (Control.MENU, 9),
       
    92         MP_POPUPBORDERS    (Control.MENU, 10),
       
    93         MP_POPUPCHECK      (Control.MENU, 11),
       
    94         MP_POPUPCHECKBACKGROUND (Control.MENU, 12),
       
    95         MP_POPUPGUTTER     (Control.MENU, 13),
       
    96         MP_POPUPITEM       (Control.MENU, 14),
       
    97         MP_POPUPSEPARATOR  (Control.MENU, 15),
       
    98         MP_POPUPSUBMENU    (Control.MENU, 16),
       
    99 
       
   100         BP_PUSHBUTTON (Control.BUTTON, 1),
       
   101         BP_RADIOBUTTON(Control.BUTTON, 2),
       
   102         BP_CHECKBOX   (Control.BUTTON, 3),
       
   103         BP_GROUPBOX   (Control.BUTTON, 4),
       
   104 
       
   105         CP_COMBOBOX      (Control.COMBOBOX, 0),
       
   106         CP_DROPDOWNBUTTON(Control.COMBOBOX, 1),
       
   107         CP_BACKGROUND    (Control.COMBOBOX, 2),
       
   108         CP_TRANSPARENTBACKGROUND (Control.COMBOBOX, 3),
       
   109         CP_BORDER                (Control.COMBOBOX, 4),
       
   110         CP_READONLY              (Control.COMBOBOX, 5),
       
   111         CP_DROPDOWNBUTTONRIGHT   (Control.COMBOBOX, 6),
       
   112         CP_DROPDOWNBUTTONLEFT    (Control.COMBOBOX, 7),
       
   113         CP_CUEBANNER             (Control.COMBOBOX, 8),
       
   114 
       
   115 
       
   116         EP_EDIT    (Control.EDIT, 0),
       
   117         EP_EDITTEXT(Control.EDIT, 1),
       
   118 
       
   119         HP_HEADERITEM(Control.HEADER,      1),
       
   120         HP_HEADERSORTARROW(Control.HEADER, 4),
       
   121 
       
   122         LBP_LISTBOX(Control.LISTBOX, 0),
       
   123 
       
   124         LBCP_BORDER_HSCROLL  (Control.LISTBOX, 1),
       
   125         LBCP_BORDER_HVSCROLL (Control.LISTBOX, 2),
       
   126         LBCP_BORDER_NOSCROLL (Control.LISTBOX, 3),
       
   127         LBCP_BORDER_VSCROLL  (Control.LISTBOX, 4),
       
   128         LBCP_ITEM            (Control.LISTBOX, 5),
       
   129 
       
   130         LVP_LISTVIEW(Control.LISTVIEW, 0),
       
   131 
       
   132         PP_PROGRESS (Control.PROGRESS, 0),
       
   133         PP_BAR      (Control.PROGRESS, 1),
       
   134         PP_BARVERT  (Control.PROGRESS, 2),
       
   135         PP_CHUNK    (Control.PROGRESS, 3),
       
   136         PP_CHUNKVERT(Control.PROGRESS, 4),
       
   137 
       
   138         RP_GRIPPER    (Control.REBAR, 1),
       
   139         RP_GRIPPERVERT(Control.REBAR, 2),
       
   140 
       
   141         SBP_SCROLLBAR     (Control.SCROLLBAR,  0),
       
   142         SBP_ARROWBTN      (Control.SCROLLBAR,  1),
       
   143         SBP_THUMBBTNHORZ  (Control.SCROLLBAR,  2),
       
   144         SBP_THUMBBTNVERT  (Control.SCROLLBAR,  3),
       
   145         SBP_LOWERTRACKHORZ(Control.SCROLLBAR,  4),
       
   146         SBP_UPPERTRACKHORZ(Control.SCROLLBAR,  5),
       
   147         SBP_LOWERTRACKVERT(Control.SCROLLBAR,  6),
       
   148         SBP_UPPERTRACKVERT(Control.SCROLLBAR,  7),
       
   149         SBP_GRIPPERHORZ   (Control.SCROLLBAR,  8),
       
   150         SBP_GRIPPERVERT   (Control.SCROLLBAR,  9),
       
   151         SBP_SIZEBOX       (Control.SCROLLBAR, 10),
       
   152 
       
   153         SPNP_UP  (Control.SPIN, 1),
       
   154         SPNP_DOWN(Control.SPIN, 2),
       
   155 
       
   156         TABP_TABITEM         (Control.TAB, 1),
       
   157         TABP_TABITEMLEFTEDGE (Control.TAB, 2),
       
   158         TABP_TABITEMRIGHTEDGE(Control.TAB, 3),
       
   159         TABP_PANE            (Control.TAB, 9),
       
   160 
       
   161         TP_TOOLBAR        (Control.TOOLBAR, 0),
       
   162         TP_BUTTON         (Control.TOOLBAR, 1),
       
   163         TP_SEPARATOR      (Control.TOOLBAR, 5),
       
   164         TP_SEPARATORVERT  (Control.TOOLBAR, 6),
       
   165 
       
   166         TKP_TRACK      (Control.TRACKBAR,  1),
       
   167         TKP_TRACKVERT  (Control.TRACKBAR,  2),
       
   168         TKP_THUMB      (Control.TRACKBAR,  3),
       
   169         TKP_THUMBBOTTOM(Control.TRACKBAR,  4),
       
   170         TKP_THUMBTOP   (Control.TRACKBAR,  5),
       
   171         TKP_THUMBVERT  (Control.TRACKBAR,  6),
       
   172         TKP_THUMBLEFT  (Control.TRACKBAR,  7),
       
   173         TKP_THUMBRIGHT (Control.TRACKBAR,  8),
       
   174         TKP_TICS       (Control.TRACKBAR,  9),
       
   175         TKP_TICSVERT   (Control.TRACKBAR, 10),
       
   176 
       
   177         TVP_TREEVIEW(Control.TREEVIEW, 0),
       
   178         TVP_GLYPH   (Control.TREEVIEW, 2),
       
   179 
       
   180         WP_WINDOW          (Control.WINDOW,  0),
       
   181         WP_CAPTION         (Control.WINDOW,  1),
       
   182         WP_MINCAPTION      (Control.WINDOW,  3),
       
   183         WP_MAXCAPTION      (Control.WINDOW,  5),
       
   184         WP_FRAMELEFT       (Control.WINDOW,  7),
       
   185         WP_FRAMERIGHT      (Control.WINDOW,  8),
       
   186         WP_FRAMEBOTTOM     (Control.WINDOW,  9),
       
   187         WP_SYSBUTTON       (Control.WINDOW, 13),
       
   188         WP_MDISYSBUTTON    (Control.WINDOW, 14),
       
   189         WP_MINBUTTON       (Control.WINDOW, 15),
       
   190         WP_MDIMINBUTTON    (Control.WINDOW, 16),
       
   191         WP_MAXBUTTON       (Control.WINDOW, 17),
       
   192         WP_CLOSEBUTTON     (Control.WINDOW, 18),
       
   193         WP_MDICLOSEBUTTON  (Control.WINDOW, 20),
       
   194         WP_RESTOREBUTTON   (Control.WINDOW, 21),
       
   195         WP_MDIRESTOREBUTTON(Control.WINDOW, 22);
       
   196 
       
   197         private final Control control;
       
   198         private final int value;
       
   199 
       
   200         private Part(Control control, int value) {
       
   201             this.control = control;
       
   202             this.value = value;
       
   203         }
       
   204 
       
   205         public int getValue() {
       
   206             return value;
       
   207         }
       
   208 
       
   209         public String getControlName(Component component) {
       
   210             String str = "";
       
   211             if (component instanceof JComponent) {
       
   212                 JComponent c = (JComponent)component;
       
   213                 String subAppName = (String)c.getClientProperty("XPStyle.subAppName");
       
   214                 if (subAppName != null) {
       
   215                     str = subAppName + "::";
       
   216                 }
       
   217             }
       
   218             return str + control.toString();
       
   219         }
       
   220 
       
   221         public String toString() {
       
   222             return control.toString()+"."+name();
       
   223         }
       
   224     }
       
   225 
       
   226 
       
   227     /**
       
   228      * An enumeration of the possible component states
       
   229      */
       
   230     public static enum State {
       
   231         ACTIVE,
       
   232         ASSIST,
       
   233         BITMAP,
       
   234         CHECKED,
       
   235         CHECKEDDISABLED,
       
   236         CHECKEDHOT,
       
   237         CHECKEDNORMAL,
       
   238         CHECKEDPRESSED,
       
   239         CHECKMARKNORMAL,
       
   240         CHECKMARKDISABLED,
       
   241         BULLETNORMAL,
       
   242         BULLETDISABLED,
       
   243         CLOSED,
       
   244         DEFAULTED,
       
   245         DISABLED,
       
   246         DISABLEDHOT,
       
   247         DISABLEDPUSHED,
       
   248         DOWNDISABLED,
       
   249         DOWNHOT,
       
   250         DOWNNORMAL,
       
   251         DOWNPRESSED,
       
   252         FOCUSED,
       
   253         HOT,
       
   254         HOTCHECKED,
       
   255         ICONHOT,
       
   256         ICONNORMAL,
       
   257         ICONPRESSED,
       
   258         ICONSORTEDHOT,
       
   259         ICONSORTEDNORMAL,
       
   260         ICONSORTEDPRESSED,
       
   261         INACTIVE,
       
   262         INACTIVENORMAL,         // See note 1
       
   263         INACTIVEHOT,            // See note 1
       
   264         INACTIVEPUSHED,         // See note 1
       
   265         INACTIVEDISABLED,       // See note 1
       
   266         LEFTDISABLED,
       
   267         LEFTHOT,
       
   268         LEFTNORMAL,
       
   269         LEFTPRESSED,
       
   270         MIXEDDISABLED,
       
   271         MIXEDHOT,
       
   272         MIXEDNORMAL,
       
   273         MIXEDPRESSED,
       
   274         NORMAL,
       
   275         PRESSED,
       
   276         OPENED,
       
   277         PUSHED,
       
   278         READONLY,
       
   279         RIGHTDISABLED,
       
   280         RIGHTHOT,
       
   281         RIGHTNORMAL,
       
   282         RIGHTPRESSED,
       
   283         SELECTED,
       
   284         UNCHECKEDDISABLED,
       
   285         UNCHECKEDHOT,
       
   286         UNCHECKEDNORMAL,
       
   287         UNCHECKEDPRESSED,
       
   288         UPDISABLED,
       
   289         UPHOT,
       
   290         UPNORMAL,
       
   291         UPPRESSED,
       
   292         HOVER,
       
   293         UPHOVER,
       
   294         DOWNHOVER,
       
   295         LEFTHOVER,
       
   296         RIGHTHOVER,
       
   297         SORTEDDOWN,
       
   298         SORTEDHOT,
       
   299         SORTEDNORMAL,
       
   300         SORTEDPRESSED,
       
   301         SORTEDUP;
       
   302 
       
   303 
       
   304         /**
       
   305          * A map of allowed states for each Part
       
   306          */
       
   307         private static EnumMap<Part, State[]> stateMap;
       
   308 
       
   309         private static synchronized void initStates() {
       
   310             stateMap = new EnumMap<Part, State[]>(Part.class);
       
   311 
       
   312             stateMap.put(Part.EP_EDITTEXT,
       
   313                        new State[] {
       
   314                         NORMAL, HOT, SELECTED, DISABLED, FOCUSED, READONLY, ASSIST
       
   315             });
       
   316 
       
   317             stateMap.put(Part.BP_PUSHBUTTON,
       
   318                        new State[] { NORMAL, HOT, PRESSED, DISABLED, DEFAULTED });
       
   319 
       
   320             stateMap.put(Part.BP_RADIOBUTTON,
       
   321                        new State[] {
       
   322                         UNCHECKEDNORMAL, UNCHECKEDHOT, UNCHECKEDPRESSED, UNCHECKEDDISABLED,
       
   323                         CHECKEDNORMAL,   CHECKEDHOT,   CHECKEDPRESSED,   CHECKEDDISABLED
       
   324             });
       
   325 
       
   326             stateMap.put(Part.BP_CHECKBOX,
       
   327                        new State[] {
       
   328                         UNCHECKEDNORMAL, UNCHECKEDHOT, UNCHECKEDPRESSED, UNCHECKEDDISABLED,
       
   329                         CHECKEDNORMAL,   CHECKEDHOT,   CHECKEDPRESSED,   CHECKEDDISABLED,
       
   330                         MIXEDNORMAL,     MIXEDHOT,     MIXEDPRESSED,     MIXEDDISABLED
       
   331             });
       
   332 
       
   333             State[] comboBoxStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
       
   334             stateMap.put(Part.CP_COMBOBOX, comboBoxStates);
       
   335             stateMap.put(Part.CP_DROPDOWNBUTTON, comboBoxStates);
       
   336             stateMap.put(Part.CP_BACKGROUND, comboBoxStates);
       
   337             stateMap.put(Part.CP_TRANSPARENTBACKGROUND, comboBoxStates);
       
   338             stateMap.put(Part.CP_BORDER, comboBoxStates);
       
   339             stateMap.put(Part.CP_READONLY, comboBoxStates);
       
   340             stateMap.put(Part.CP_DROPDOWNBUTTONRIGHT, comboBoxStates);
       
   341             stateMap.put(Part.CP_DROPDOWNBUTTONLEFT, comboBoxStates);
       
   342             stateMap.put(Part.CP_CUEBANNER, comboBoxStates);
       
   343 
       
   344             stateMap.put(Part.HP_HEADERITEM, new State[] { NORMAL, HOT, PRESSED,
       
   345                           SORTEDNORMAL, SORTEDHOT, SORTEDPRESSED,
       
   346                           ICONNORMAL, ICONHOT, ICONPRESSED,
       
   347                           ICONSORTEDNORMAL, ICONSORTEDHOT, ICONSORTEDPRESSED });
       
   348 
       
   349             stateMap.put(Part.HP_HEADERSORTARROW,
       
   350                          new State[] {SORTEDDOWN, SORTEDUP});
       
   351 
       
   352             State[] listBoxStates = new State[] { NORMAL, PRESSED, HOT, DISABLED};
       
   353             stateMap.put(Part.LBCP_BORDER_HSCROLL, listBoxStates);
       
   354             stateMap.put(Part.LBCP_BORDER_HVSCROLL, listBoxStates);
       
   355             stateMap.put(Part.LBCP_BORDER_NOSCROLL, listBoxStates);
       
   356             stateMap.put(Part.LBCP_BORDER_VSCROLL, listBoxStates);
       
   357 
       
   358             State[] scrollBarStates = new State[] { NORMAL, HOT, PRESSED, DISABLED, HOVER };
       
   359             stateMap.put(Part.SBP_SCROLLBAR,    scrollBarStates);
       
   360             stateMap.put(Part.SBP_THUMBBTNVERT, scrollBarStates);
       
   361             stateMap.put(Part.SBP_THUMBBTNHORZ, scrollBarStates);
       
   362             stateMap.put(Part.SBP_GRIPPERVERT,  scrollBarStates);
       
   363             stateMap.put(Part.SBP_GRIPPERHORZ,  scrollBarStates);
       
   364 
       
   365             stateMap.put(Part.SBP_ARROWBTN,
       
   366                        new State[] {
       
   367                 UPNORMAL,    UPHOT,     UPPRESSED,    UPDISABLED,
       
   368                 DOWNNORMAL,  DOWNHOT,   DOWNPRESSED,  DOWNDISABLED,
       
   369                 LEFTNORMAL,  LEFTHOT,   LEFTPRESSED,  LEFTDISABLED,
       
   370                 RIGHTNORMAL, RIGHTHOT,  RIGHTPRESSED, RIGHTDISABLED,
       
   371                 UPHOVER,     DOWNHOVER, LEFTHOVER,    RIGHTHOVER
       
   372             });
       
   373 
       
   374 
       
   375             State[] spinnerStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
       
   376             stateMap.put(Part.SPNP_UP,   spinnerStates);
       
   377             stateMap.put(Part.SPNP_DOWN, spinnerStates);
       
   378 
       
   379             stateMap.put(Part.TVP_GLYPH, new State[] { CLOSED, OPENED });
       
   380 
       
   381             State[] frameButtonStates = new State[] {
       
   382                         NORMAL,         HOT,         PUSHED,         DISABLED,  // See note 1
       
   383                         INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED,
       
   384             };
       
   385             // Note 1: The INACTIVE frame button states apply when the frame
       
   386             //         is inactive. They are not defined in tmschema.h
       
   387 
       
   388             // Fix for 6316538: Vista has five frame button states
       
   389             if (ThemeReader.getInt(Control.WINDOW.toString(),
       
   390                                    Part.WP_CLOSEBUTTON.getValue(), 1,
       
   391                                    Prop.IMAGECOUNT.getValue()) == 10) {
       
   392                 frameButtonStates = new State[] {
       
   393                         NORMAL,         HOT,         PUSHED,         DISABLED,         null,
       
   394                         INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED, null
       
   395                 };
       
   396             }
       
   397 
       
   398             stateMap.put(Part.WP_MINBUTTON,     frameButtonStates);
       
   399             stateMap.put(Part.WP_MAXBUTTON,     frameButtonStates);
       
   400             stateMap.put(Part.WP_RESTOREBUTTON, frameButtonStates);
       
   401             stateMap.put(Part.WP_CLOSEBUTTON,   frameButtonStates);
       
   402 
       
   403             // States for Slider (trackbar)
       
   404             stateMap.put(Part.TKP_TRACK,     new State[] { NORMAL });
       
   405             stateMap.put(Part.TKP_TRACKVERT, new State[] { NORMAL });
       
   406 
       
   407             State[] sliderThumbStates =
       
   408                 new State[] { NORMAL, HOT, PRESSED, FOCUSED, DISABLED };
       
   409             stateMap.put(Part.TKP_THUMB,       sliderThumbStates);
       
   410             stateMap.put(Part.TKP_THUMBBOTTOM, sliderThumbStates);
       
   411             stateMap.put(Part.TKP_THUMBTOP,    sliderThumbStates);
       
   412             stateMap.put(Part.TKP_THUMBVERT,   sliderThumbStates);
       
   413             stateMap.put(Part.TKP_THUMBRIGHT,  sliderThumbStates);
       
   414 
       
   415             // States for Tabs
       
   416             State[] tabStates = new State[] { NORMAL, HOT, SELECTED, DISABLED, FOCUSED };
       
   417             stateMap.put(Part.TABP_TABITEM,          tabStates);
       
   418             stateMap.put(Part.TABP_TABITEMLEFTEDGE,  tabStates);
       
   419             stateMap.put(Part.TABP_TABITEMRIGHTEDGE, tabStates);
       
   420 
       
   421 
       
   422             stateMap.put(Part.TP_BUTTON,
       
   423                        new State[] {
       
   424                         NORMAL, HOT, PRESSED, DISABLED, CHECKED, HOTCHECKED
       
   425             });
       
   426 
       
   427             State[] frameStates = new State[] { ACTIVE, INACTIVE };
       
   428             stateMap.put(Part.WP_WINDOW,      frameStates);
       
   429             stateMap.put(Part.WP_FRAMELEFT,   frameStates);
       
   430             stateMap.put(Part.WP_FRAMERIGHT,  frameStates);
       
   431             stateMap.put(Part.WP_FRAMEBOTTOM, frameStates);
       
   432 
       
   433             State[] captionStates = new State[] { ACTIVE, INACTIVE, DISABLED };
       
   434             stateMap.put(Part.WP_CAPTION,    captionStates);
       
   435             stateMap.put(Part.WP_MINCAPTION, captionStates);
       
   436             stateMap.put(Part.WP_MAXCAPTION, captionStates);
       
   437 
       
   438             stateMap.put(Part.MP_BARBACKGROUND,
       
   439                          new State[] { ACTIVE, INACTIVE });
       
   440             stateMap.put(Part.MP_BARITEM,
       
   441                          new State[] { NORMAL, HOT, PUSHED,
       
   442                                        DISABLED, DISABLEDHOT, DISABLEDPUSHED });
       
   443             stateMap.put(Part.MP_POPUPCHECK,
       
   444                          new State[] { CHECKMARKNORMAL, CHECKMARKDISABLED,
       
   445                                        BULLETNORMAL, BULLETDISABLED });
       
   446             stateMap.put(Part.MP_POPUPCHECKBACKGROUND,
       
   447                          new State[] { DISABLEDPUSHED, NORMAL, BITMAP });
       
   448             stateMap.put(Part.MP_POPUPITEM,
       
   449                          new State[] { NORMAL, HOT, DISABLED, DISABLEDHOT });
       
   450             stateMap.put(Part.MP_POPUPSUBMENU,
       
   451                          new State[] { NORMAL, DISABLED });
       
   452 
       
   453         }
       
   454 
       
   455 
       
   456         public static synchronized int getValue(Part part, State state) {
       
   457             if (stateMap == null) {
       
   458                 initStates();
       
   459             }
       
   460 
       
   461             Enum<?>[] states = stateMap.get(part);
       
   462             if (states != null) {
       
   463                 for (int i = 0; i < states.length; i++) {
       
   464                     if (state == states[i]) {
       
   465                         return i + 1;
       
   466                     }
       
   467                 }
       
   468             }
       
   469 
       
   470             if (state == null || state == State.NORMAL) {
       
   471                 return 1;
       
   472             }
       
   473 
       
   474             return 0;
       
   475         }
       
   476 
       
   477     }
       
   478 
       
   479 
       
   480     /**
       
   481      * An enumeration of the possible component attributes and the
       
   482      * corresponding value type
       
   483      */
       
   484     public static enum Prop {
       
   485         COLOR(Color.class,                204),
       
   486         SIZE(Dimension.class,             207),
       
   487 
       
   488         FLATMENUS(Boolean.class,         1001),
       
   489 
       
   490         BORDERONLY(Boolean.class,        2203), // only draw the border area of the image
       
   491 
       
   492         IMAGECOUNT(Integer.class,        2401), // the number of state images in an imagefile
       
   493         BORDERSIZE(Integer.class,        2403), // the size of the border line for bgtype=BorderFill
       
   494 
       
   495         PROGRESSCHUNKSIZE(Integer.class, 2411), // size of progress control chunks
       
   496         PROGRESSSPACESIZE(Integer.class, 2412), // size of progress control spaces
       
   497 
       
   498         TEXTSHADOWOFFSET(Point.class,    3402), // where char shadows are drawn, relative to orig. chars
       
   499 
       
   500         NORMALSIZE(Dimension.class,      3409), // size of dest rect that exactly source
       
   501 
       
   502 
       
   503         SIZINGMARGINS ( Insets.class,    3601), // margins used for 9-grid sizing
       
   504         CONTENTMARGINS(Insets.class,     3602), // margins that define where content can be placed
       
   505         CAPTIONMARGINS(Insets.class,     3603), // margins that define where caption text can be placed
       
   506 
       
   507         BORDERCOLOR(Color.class,         3801), // color of borders for BorderFill
       
   508         FILLCOLOR  (  Color.class,       3802), // color of bg fill
       
   509         TEXTCOLOR  (  Color.class,       3803), // color text is drawn in
       
   510 
       
   511         TEXTSHADOWCOLOR(Color.class,     3818), // color of text shadow
       
   512 
       
   513         BGTYPE(Integer.class,            4001), // basic drawing type for each part
       
   514 
       
   515         TEXTSHADOWTYPE(Integer.class,    4010), // type of shadow to draw with text
       
   516 
       
   517         TRANSITIONDURATIONS(Integer.class, 6000);
       
   518 
       
   519         private final Class<?> type;
       
   520         private final int value;
       
   521 
       
   522         private Prop(Class<?> type, int value) {
       
   523             this.type     = type;
       
   524             this.value    = value;
       
   525         }
       
   526 
       
   527         public int getValue() {
       
   528             return value;
       
   529         }
       
   530 
       
   531         public String toString() {
       
   532             return name()+"["+type.getName()+"] = "+value;
       
   533         }
       
   534     }
       
   535 
       
   536 
       
   537     /**
       
   538      * An enumeration of attribute values for some Props
       
   539      */
       
   540     public static enum TypeEnum {
       
   541         BT_IMAGEFILE (Prop.BGTYPE, "imagefile",  0),
       
   542         BT_BORDERFILL(Prop.BGTYPE, "borderfill", 1),
       
   543 
       
   544         TST_NONE(Prop.TEXTSHADOWTYPE, "none", 0),
       
   545         TST_SINGLE(Prop.TEXTSHADOWTYPE, "single", 1),
       
   546         TST_CONTINUOUS(Prop.TEXTSHADOWTYPE, "continuous", 2);
       
   547 
       
   548 
       
   549         private TypeEnum(Prop prop, String enumName, int value) {
       
   550             this.prop = prop;
       
   551             this.enumName = enumName;
       
   552             this.value = value;
       
   553         }
       
   554 
       
   555         private final Prop prop;
       
   556         private final String enumName;
       
   557         private final int value;
       
   558 
       
   559         public String toString() {
       
   560             return prop+"="+enumName+"="+value;
       
   561         }
       
   562 
       
   563         String getName() {
       
   564             return enumName;
       
   565         }
       
   566 
       
   567 
       
   568         static TypeEnum getTypeEnum(Prop prop, int enumval) {
       
   569             for (TypeEnum e : TypeEnum.values()) {
       
   570                 if (e.prop == prop && e.value == enumval) {
       
   571                     return e;
       
   572                 }
       
   573             }
       
   574             return null;
       
   575         }
       
   576     }
       
   577 }