KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > Region


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

7 package javax.swing.plaf.synth;
8
9 import javax.swing.*;
10 import java.util.*;
11
12 /**
13  * A distinct rendering area of a Swing component. A component may
14  * support one or more regions. Specific component regions are defined
15  * by the typesafe enumeration in this class.
16  * <p>
17  * Regions are typically used as a way to identify the <code>Component</code>s
18  * and areas a particular style is to apply to. Synth's file format allows you
19  * to bind styles based on the name of a <code>Region</code>.
20  * The name is derived from the field name of the constant:
21  * <ol>
22  * <li>Map all characters to lowercase.
23  * <li>Map the first character to uppercase.
24  * <li>Map the first character after underscores to uppercase.
25  * <li>Remove all underscores.
26  * </ol>
27  * For example, to identify the <code>SPLIT_PANE</code>
28  * <code>Region</code> you would use <code>SplitPane</code>.
29  * The following shows a custom <code>SynthStyleFactory</code>
30  * that returns a specific style for split panes:
31  * <pre>
32  * public SynthStyle getStyle(JComponent c, Region id) {
33  * if (id == Region.SPLIT_PANE) {
34  * return splitPaneStyle;
35  * }
36  * ...
37  * }
38  * </pre>
39  * The following <a HREF="doc-files/synthFileFormat.html">xml</a>
40  * accomplishes the same thing:
41  * <pre>
42  * &lt;style id="splitPaneStyle">
43  * ...
44  * &lt;/style>
45  * &lt;bind style="splitPaneStyle" type="region" key="SplitPane"/>
46  * </pre>
47  *
48  * @version 1.30, 02/19/04
49  * @since 1.5
50  * @author Scott Violet
51  */

52 public class Region {
53     private static final Map uiToRegionMap = new HashMap();
54     private static final Map lowerCaseNameMap = new HashMap();
55
56     /**
57      * ArrowButton's are special types of buttons that also render a
58      * directional indicator, typically an arrow. ArrowButtons are used by
59      * composite components, for example ScrollBar's contain ArrowButtons.
60      * To bind a style to this <code>Region</code> use the name
61      * <code>ArrowButton</code>.
62      */

63     public static final Region JavaDoc ARROW_BUTTON = new Region JavaDoc("ArrowButton",
64                                                          "ArrowButtonUI");
65
66     /**
67      * Button region. To bind a style to this <code>Region</code> use the name
68      * <code>Button</code>.
69      */

70     public static final Region JavaDoc BUTTON = new Region JavaDoc("Button",
71                                                    "ButtonUI");
72
73     /**
74      * CheckBox region. To bind a style to this <code>Region</code> use the name
75      * <code>CheckBox</code>.
76      */

77     public static final Region JavaDoc CHECK_BOX = new Region JavaDoc("CheckBox",
78                                                    "CheckBoxUI");
79
80     /**
81      * CheckBoxMenuItem region. To bind a style to this <code>Region</code> use
82      * the name <code>CheckBoxMenuItem</code>.
83      */

84     public static final Region JavaDoc CHECK_BOX_MENU_ITEM = new Region JavaDoc(
85                                      "CheckBoxMenuItem", "CheckBoxMenuItemUI");
86
87     /**
88      * ColorChooser region. To bind a style to this <code>Region</code> use
89      * the name <code>ColorChooser</code>.
90      */

91     public static final Region JavaDoc COLOR_CHOOSER = new Region JavaDoc(
92                                      "ColorChooser", "ColorChooserUI");
93
94     /**
95      * ComboBox region. To bind a style to this <code>Region</code> use
96      * the name <code>ComboBox</code>.
97      */

98     public static final Region JavaDoc COMBO_BOX = new Region JavaDoc(
99                                      "ComboBox", "ComboBoxUI");
100
101     /**
102      * DesktopPane region. To bind a style to this <code>Region</code> use
103      * the name <code>DesktopPane</code>.
104      */

105     public static final Region JavaDoc DESKTOP_PANE = new Region JavaDoc("DesktopPane",
106                                                          "DesktopPaneUI");
107     /**
108      * DesktopIcon region. To bind a style to this <code>Region</code> use
109      * the name <code>DesktopIcon</code>.
110      */

111     public static final Region JavaDoc DESKTOP_ICON = new Region JavaDoc("DesktopIcon",
112                                                          "DesktopIconUI");
113
114     /**
115      * EditorPane region. To bind a style to this <code>Region</code> use
116      * the name <code>EditorPane</code>.
117      */

118     public static final Region JavaDoc EDITOR_PANE = new Region JavaDoc("EditorPane",
119                                                         "EditorPaneUI");
120
121     /**
122      * FileChooser region. To bind a style to this <code>Region</code> use
123      * the name <code>FileChooser</code>.
124      */

125     public static final Region JavaDoc FILE_CHOOSER = new Region JavaDoc("FileChooser",
126                                                          "FileChooserUI");
127
128     /**
129      * FormattedTextField region. To bind a style to this <code>Region</code> use
130      * the name <code>FormattedTextField</code>.
131      */

132     public static final Region JavaDoc FORMATTED_TEXT_FIELD = new Region JavaDoc(
133                             "FormattedTextField", "FormattedTextFieldUI");
134
135     /**
136      * InternalFrame region. To bind a style to this <code>Region</code> use
137      * the name <code>InternalFrame</code>.
138      */

139     public static final Region JavaDoc INTERNAL_FRAME = new Region JavaDoc("InternalFrame",
140                                                            "InternalFrameUI");
141     /**
142      * TitlePane of an InternalFrame. The TitlePane typically
143      * shows a menu, title, widgets to manipulate the internal frame.
144      * To bind a style to this <code>Region</code> use the name
145      * <code>InternalFrameTitlePane</code>.
146      */

147     public static final Region JavaDoc INTERNAL_FRAME_TITLE_PANE =
148                          new Region JavaDoc("InternalFrameTitlePane",
149                                     "InternalFrameTitlePaneUI");
150
151     /**
152      * Label region. To bind a style to this <code>Region</code> use the name
153      * <code>Label</code>.
154      */

155     public static final Region JavaDoc LABEL = new Region JavaDoc("Label", "LabelUI");
156
157     /**
158      * List region. To bind a style to this <code>Region</code> use the name
159      * <code>List</code>.
160      */

161     public static final Region JavaDoc LIST = new Region JavaDoc("List", "ListUI");
162
163     /**
164      * Menu region. To bind a style to this <code>Region</code> use the name
165      * <code>Menu</code>.
166      */

167     public static final Region JavaDoc MENU = new Region JavaDoc("Menu", "MenuUI");
168
169     /**
170      * MenuBar region. To bind a style to this <code>Region</code> use the name
171      * <code>MenuBar</code>.
172      */

173     public static final Region JavaDoc MENU_BAR = new Region JavaDoc("MenuBar", "MenuBarUI");
174
175     /**
176      * MenuItem region. To bind a style to this <code>Region</code> use the name
177      * <code>MenuItem</code>.
178      */

179     public static final Region JavaDoc MENU_ITEM = new Region JavaDoc("MenuItem","MenuItemUI");
180
181     /**
182      * Accelerator region of a MenuItem. To bind a style to this
183      * <code>Region</code> use the name <code>MenuItemAccelerator</code>.
184      */

185     public static final Region JavaDoc MENU_ITEM_ACCELERATOR = new Region JavaDoc(
186                                          "MenuItemAccelerator");
187
188     /**
189      * OptionPane region. To bind a style to this <code>Region</code> use
190      * the name <code>OptionPane</code>.
191      */

192     public static final Region JavaDoc OPTION_PANE = new Region JavaDoc("OptionPane",
193                                                         "OptionPaneUI");
194
195     /**
196      * Panel region. To bind a style to this <code>Region</code> use the name
197      * <code>Panel</code>.
198      */

199     public static final Region JavaDoc PANEL = new Region JavaDoc("Panel", "PanelUI");
200
201     /**
202      * PasswordField region. To bind a style to this <code>Region</code> use
203      * the name <code>PasswordField</code>.
204      */

205     public static final Region JavaDoc PASSWORD_FIELD = new Region JavaDoc("PasswordField",
206                                                            "PasswordFieldUI");
207
208     /**
209      * PopupMenu region. To bind a style to this <code>Region</code> use
210      * the name <code>PopupMenu</code>.
211      */

212     public static final Region JavaDoc POPUP_MENU = new Region JavaDoc("PopupMenu",
213                                                        "PopupMenuUI");
214
215     /**
216      * PopupMenuSeparator region. To bind a style to this <code>Region</code>
217      * use the name <code>PopupMenuSeparator</code>.
218      */

219     public static final Region JavaDoc POPUP_MENU_SEPARATOR = new Region JavaDoc(
220                            "PopupMenuSeparator", "PopupMenuSeparatorUI");
221
222     /**
223      * ProgressBar region. To bind a style to this <code>Region</code>
224      * use the name <code>ProgressBar</code>.
225      */

226     public static final Region JavaDoc PROGRESS_BAR = new Region JavaDoc("ProgressBar",
227                                                          "ProgressBarUI");
228
229     /**
230      * RadioButton region. To bind a style to this <code>Region</code>
231      * use the name <code>RadioButton</code>.
232      */

233     public static final Region JavaDoc RADIO_BUTTON = new Region JavaDoc(
234                                "RadioButton", "RadioButtonUI");
235
236     /**
237      * RegionButtonMenuItem region. To bind a style to this <code>Region</code>
238      * use the name <code>RadioButtonMenuItem</code>.
239      */

240     public static final Region JavaDoc RADIO_BUTTON_MENU_ITEM = new Region JavaDoc(
241                                "RadioButtonMenuItem", "RadioButtonMenuItemUI");
242
243     /**
244      * RootPane region. To bind a style to this <code>Region</code> use
245      * the name <code>RootPane</code>.
246      */

247     public static final Region JavaDoc ROOT_PANE = new Region JavaDoc("RootPane",
248                                                       "RootPaneUI");
249
250     /**
251      * ScrollBar region. To bind a style to this <code>Region</code> use
252      * the name <code>ScrollBar</code>.
253      */

254     public static final Region JavaDoc SCROLL_BAR = new Region JavaDoc("ScrollBar",
255                                                        "ScrollBarUI");
256     /**
257      * Track of the ScrollBar. To bind a style to this <code>Region</code> use
258      * the name <code>ScrollBarTrack</code>.
259      */

260     public static final Region JavaDoc SCROLL_BAR_TRACK = new Region JavaDoc("ScrollBarTrack");
261     /**
262      * Thumb of the ScrollBar. The thumb is the region of the ScrollBar
263      * that gives a graphical depiction of what percentage of the View is
264      * currently visible. To bind a style to this <code>Region</code> use
265      * the name <code>ScrollBarThumb</code>.
266      */

267     public static final Region JavaDoc SCROLL_BAR_THUMB = new Region JavaDoc("ScrollBarThumb");
268
269     /**
270      * ScrollPane region. To bind a style to this <code>Region</code> use
271      * the name <code>ScrollPane</code>.
272      */

273     public static final Region JavaDoc SCROLL_PANE = new Region JavaDoc("ScrollPane",
274                                                         "ScrollPaneUI");
275
276     /**
277      * Separator region. To bind a style to this <code>Region</code> use
278      * the name <code>Separator</code>.
279      */

280     public static final Region JavaDoc SEPARATOR = new Region JavaDoc("Separator",
281                                                       "SeparatorUI");
282
283     /**
284      * Slider region. To bind a style to this <code>Region</code> use
285      * the name <code>Slider</code>.
286      */

287     public static final Region JavaDoc SLIDER = new Region JavaDoc("Slider", "SliderUI");
288     /**
289      * Track of the Slider. To bind a style to this <code>Region</code> use
290      * the name <code>SliderTrack</code>.
291      */

292     public static final Region JavaDoc SLIDER_TRACK = new Region JavaDoc("SliderTrack");
293     /**
294      * Thumb of the Slider. The thumb of the Slider identifies the current
295      * value. To bind a style to this <code>Region</code> use the name
296      * <code>SliderThumb</code>.
297      */

298     public static final Region JavaDoc SLIDER_THUMB = new Region JavaDoc("SliderThumb");
299
300     /**
301      * Spinner region. To bind a style to this <code>Region</code> use the name
302      * <code>Spinner</code>.
303      */

304     public static final Region JavaDoc SPINNER = new Region JavaDoc("Spinner", "SpinnerUI");
305
306     /**
307      * SplitPane region. To bind a style to this <code>Region</code> use the name
308      * <code>SplitPane</code>.
309      */

310     public static final Region JavaDoc SPLIT_PANE = new Region JavaDoc("SplitPane",
311                                                       "SplitPaneUI");
312
313     /**
314      * Divider of the SplitPane. To bind a style to this <code>Region</code>
315      * use the name <code>SplitPaneDivider</code>.
316      */

317     public static final Region JavaDoc SPLIT_PANE_DIVIDER = new Region JavaDoc(
318                                         "SplitPaneDivider");
319
320     /**
321      * TabbedPane region. To bind a style to this <code>Region</code> use
322      * the name <code>TabbedPane</code>.
323      */

324     public static final Region JavaDoc TABBED_PANE = new Region JavaDoc("TabbedPane",
325                                                         "TabbedPaneUI");
326     /**
327      * Region of a TabbedPane for one tab. To bind a style to this
328      * <code>Region</code> use the name <code>TabbedPaneTab</code>.
329      */

330     public static final Region JavaDoc TABBED_PANE_TAB = new Region JavaDoc("TabbedPaneTab");
331     /**
332      * Region of a TabbedPane containing the tabs. To bind a style to this
333      * <code>Region</code> use the name <code>TabbedPaneTabArea</code>.
334      */

335     public static final Region JavaDoc TABBED_PANE_TAB_AREA =
336                                  new Region JavaDoc("TabbedPaneTabArea");
337     /**
338      * Region of a TabbedPane containing the content. To bind a style to this
339      * <code>Region</code> use the name <code>TabbedPaneContent</code>.
340      */

341     public static final Region JavaDoc TABBED_PANE_CONTENT =
342                                  new Region JavaDoc("TabbedPaneContent");
343
344     /**
345      * Table region. To bind a style to this <code>Region</code> use
346      * the name <code>Table</code>.
347      */

348     public static final Region JavaDoc TABLE = new Region JavaDoc("Table", "TableUI");
349
350     /**
351      * TableHeader region. To bind a style to this <code>Region</code> use
352      * the name <code>TableHeader</code>.
353      */

354     public static final Region JavaDoc TABLE_HEADER = new Region JavaDoc("TableHeader",
355                                                          "TableHeaderUI");
356     /**
357      * TextArea region. To bind a style to this <code>Region</code> use
358      * the name <code>TextArea</code>.
359      */

360     public static final Region JavaDoc TEXT_AREA = new Region JavaDoc("TextArea",
361                                                       "TextAreaUI");
362
363     /**
364      * TextField region. To bind a style to this <code>Region</code> use
365      * the name <code>TextField</code>.
366      */

367     public static final Region JavaDoc TEXT_FIELD = new Region JavaDoc("TextField",
368                                                        "TextFieldUI");
369
370     /**
371      * TextPane region. To bind a style to this <code>Region</code> use
372      * the name <code>TextPane</code>.
373      */

374     public static final Region JavaDoc TEXT_PANE = new Region JavaDoc("TextPane",
375                                                       "TextPaneUI");
376
377     /**
378      * ToggleButton region. To bind a style to this <code>Region</code> use
379      * the name <code>ToggleButton</code>.
380      */

381     public static final Region JavaDoc TOGGLE_BUTTON = new Region JavaDoc("ToggleButton",
382                                                           "ToggleButtonUI");
383
384     /**
385      * ToolBar region. To bind a style to this <code>Region</code> use
386      * the name <code>ToolBar</code>.
387      */

388     public static final Region JavaDoc TOOL_BAR = new Region JavaDoc("ToolBar", "ToolBarUI");
389     /**
390      * Region of the ToolBar containing the content. To bind a style to this
391      * <code>Region</code> use the name <code>ToolBarContent</code>.
392      */

393     public static final Region JavaDoc TOOL_BAR_CONTENT = new Region JavaDoc("ToolBarContent");
394     /**
395      * Region for the Window containing the ToolBar. To bind a style to this
396      * <code>Region</code> use the name <code>ToolBarDragWindow</code>.
397      */

398     public static final Region JavaDoc TOOL_BAR_DRAG_WINDOW = new Region JavaDoc(
399                                         "ToolBarDragWindow", null, false);
400
401     /**
402      * ToolTip region. To bind a style to this <code>Region</code> use
403      * the name <code>ToolTip</code>.
404      */

405     public static final Region JavaDoc TOOL_TIP = new Region JavaDoc("ToolTip", "ToolTipUI");
406
407     /**
408      * ToolBar separator region. To bind a style to this <code>Region</code> use
409      * the name <code>ToolBarSeparator</code>.
410      */

411     public static final Region JavaDoc TOOL_BAR_SEPARATOR = new Region JavaDoc(
412                           "ToolBarSeparator", "ToolBarSeparatorUI");
413
414     /**
415      * Tree region. To bind a style to this <code>Region</code> use the name
416      * <code>Tree</code>.
417      */

418     public static final Region JavaDoc TREE = new Region JavaDoc("Tree", "TreeUI");
419     /**
420      * Region of the Tree for one cell. To bind a style to this
421      * <code>Region</code> use the name <code>TreeCell</code>.
422      */

423     public static final Region JavaDoc TREE_CELL = new Region JavaDoc("TreeCell");
424
425     /**
426      * Viewport region. To bind a style to this <code>Region</code> use
427      * the name <code>Viewport</code>.
428      */

429     public static final Region JavaDoc VIEWPORT = new Region JavaDoc("Viewport", "ViewportUI");
430
431
432     private String JavaDoc name;
433     private boolean subregion;
434
435
436     static Region JavaDoc getRegion(JComponent c) {
437         return (Region JavaDoc)uiToRegionMap.get(c.getUIClassID());
438     }
439
440     static void registerUIs(UIDefaults table) {
441         Iterator uis = uiToRegionMap.keySet().iterator();
442
443         while (uis.hasNext()) {
444             Object JavaDoc key = uis.next();
445
446             table.put(key, "javax.swing.plaf.synth.SynthLookAndFeel");
447         }
448     }
449
450
451     Region(String JavaDoc name) {
452         this(name, null, true);
453     }
454
455     Region(String JavaDoc name, String JavaDoc ui) {
456         this(name, ui, false);
457     }
458
459     /**
460      * Creates a Region with the specified name. This should only be
461      * used if you are creating your own <code>JComponent</code> subclass
462      * with a custom <code>ComponentUI</code> class.
463      *
464      * @param name Name of the region
465      * @param ui String that will be returned from
466      * <code>component.getUIClassID</code>. This will be null
467      * if this is a subregion.
468      * @param subregion Whether or not this is a subregion.
469      */

470     protected Region(String JavaDoc name, String JavaDoc ui, boolean subregion) {
471         if (name == null) {
472             throw new NullPointerException JavaDoc("You must specify a non-null name");
473         }
474         this.name = name;
475         if (ui != null) {
476             uiToRegionMap.put(ui, this);
477         }
478         this.subregion = subregion;
479     }
480
481     /**
482      * Returns true if the Region is a subregion of a Component, otherwise
483      * false. For example, <code>Region.BUTTON</code> corresponds do a
484      * <code>Component</code> so that <code>Region.BUTTON.isSubregion()</code>
485      * returns false.
486      *
487      * @return true if the Region is a subregion of a Component.
488      */

489     public boolean isSubregion() {
490         return subregion;
491     }
492
493     /**
494      * Returns the name of the region.
495      *
496      * @return name of the Region.
497      */

498     public String JavaDoc getName() {
499         return name;
500     }
501
502     /**
503      * Returns the name, in lowercase.
504      */

505     String JavaDoc getLowerCaseName() {
506         synchronized(lowerCaseNameMap) {
507             String JavaDoc lowerCaseName = (String JavaDoc)lowerCaseNameMap.get(this);
508             if (lowerCaseName == null) {
509                 lowerCaseName = getName().toLowerCase();
510                 lowerCaseNameMap.put(this, lowerCaseName);
511             }
512             return lowerCaseName;
513         }
514     }
515
516     /**
517      * Returns the name of the Region.
518      *
519      * @return name of the Region.
520      */

521     public String JavaDoc toString() {
522         return name;
523     }
524 }
525
Popular Tags