KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SynthStyle.java 1.23 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 javax.swing.plaf.synth;
8
9 import java.awt.*;
10 import javax.swing.*;
11 import javax.swing.border.Border JavaDoc;
12 import javax.swing.plaf.UIResource JavaDoc;
13 import javax.swing.text.DefaultEditorKit JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16 import sun.swing.plaf.synth.SynthUI;
17
18 /**
19  * <code>SynthStyle</code> is a set of style properties.
20  * Each <code>SynthUI</code> references at least one
21  * <code>SynthStyle</code> that is obtained using a
22  * <code>SynthStyleFactory</code>. You typically don't need to interact with
23  * this class directly, rather you will load a
24  * <a HREF="doc-files/synthFileFormat.html">Synth File Format file</a> into
25  * <code>SynthLookAndFeel</code> that will create a set of SynthStyles.
26  *
27  * @see SynthLookAndFeel
28  * @see SynthStyleFactory
29  *
30  * @version 1.23, 12/19/03
31  * @since 1.5
32  * @author Scott Violet
33  */

34 public abstract class SynthStyle {
35     /**
36      * Contains the default values for certain properties.
37      */

38     private static Map JavaDoc DEFAULT_VALUES;
39
40     /**
41      * Shared SynthGraphics.
42      */

43     private static final SynthGraphicsUtils JavaDoc SYNTH_GRAPHICS =
44                               new SynthGraphicsUtils JavaDoc();
45
46     /**
47      * Adds the default values that we know about to DEFAULT_VALUES.
48      */

49     private static void populateDefaultValues() {
50         Object JavaDoc buttonMap = new UIDefaults.LazyInputMap(new Object JavaDoc[] {
51                           "SPACE", "pressed",
52                  "released SPACE", "released"
53         });
54         DEFAULT_VALUES.put("Button.focusInputMap", buttonMap);
55         DEFAULT_VALUES.put("JCheckBox.focusInputMap", buttonMap);
56         DEFAULT_VALUES.put("JRadioButton.focusInputMap", buttonMap);
57         DEFAULT_VALUES.put("JToggleButton.focusInputMap", buttonMap);
58         DEFAULT_VALUES.put("SynthArrowButton.focusInputMap", buttonMap);
59
60     Object JavaDoc multilineInputMap = new UIDefaults.LazyInputMap(new Object JavaDoc[] {
61                "ctrl C", DefaultEditorKit.copyAction,
62                "ctrl V", DefaultEditorKit.pasteAction,
63                "ctrl X", DefaultEditorKit.cutAction,
64                  "COPY", DefaultEditorKit.copyAction,
65                 "PASTE", DefaultEditorKit.pasteAction,
66                   "CUT", DefaultEditorKit.cutAction,
67                "shift LEFT", DefaultEditorKit.selectionBackwardAction,
68                     "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
69               "shift RIGHT", DefaultEditorKit.selectionForwardAction,
70            "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
71             "ctrl LEFT", DefaultEditorKit.previousWordAction,
72              "ctrl KP_LEFT", DefaultEditorKit.previousWordAction,
73                "ctrl RIGHT", DefaultEditorKit.nextWordAction,
74             "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction,
75           "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
76            "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
77          "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction,
78           "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
79                "ctrl A", DefaultEditorKit.selectAllAction,
80                  "HOME", DefaultEditorKit.beginLineAction,
81                   "END", DefaultEditorKit.endLineAction,
82                "shift HOME", DefaultEditorKit.selectionBeginLineAction,
83                 "shift END", DefaultEditorKit.selectionEndLineAction,
84
85                    "UP", DefaultEditorKit.upAction,
86                 "KP_UP", DefaultEditorKit.upAction,
87                  "DOWN", DefaultEditorKit.downAction,
88               "KP_DOWN", DefaultEditorKit.downAction,
89               "PAGE_UP", DefaultEditorKit.pageUpAction,
90             "PAGE_DOWN", DefaultEditorKit.pageDownAction,
91             "shift PAGE_UP", "selection-page-up",
92               "shift PAGE_DOWN", "selection-page-down",
93            "ctrl shift PAGE_UP", "selection-page-left",
94          "ctrl shift PAGE_DOWN", "selection-page-right",
95              "shift UP", DefaultEditorKit.selectionUpAction,
96               "shift KP_UP", DefaultEditorKit.selectionUpAction,
97                "shift DOWN", DefaultEditorKit.selectionDownAction,
98             "shift KP_DOWN", DefaultEditorKit.selectionDownAction,
99                 "ENTER", DefaultEditorKit.insertBreakAction,
100                        "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
101                            "ctrl H", DefaultEditorKit.deletePrevCharAction,
102                            "DELETE", DefaultEditorKit.deleteNextCharAction,
103                             "RIGHT", DefaultEditorKit.forwardAction,
104                              "LEFT", DefaultEditorKit.backwardAction,
105                          "KP_RIGHT", DefaultEditorKit.forwardAction,
106                           "KP_LEFT", DefaultEditorKit.backwardAction,
107                   "TAB", DefaultEditorKit.insertTabAction,
108           "ctrl BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
109             "ctrl HOME", DefaultEditorKit.beginAction,
110              "ctrl END", DefaultEditorKit.endAction,
111           "ctrl shift HOME", DefaultEditorKit.selectionBeginAction,
112            "ctrl shift END", DefaultEditorKit.selectionEndAction,
113                            "ctrl T", "next-link-action",
114                      "ctrl shift T", "previous-link-action",
115                        "ctrl SPACE", "activate-link-action",
116                    "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
117     });
118         DEFAULT_VALUES.put("EditorPane.focusInputMap", multilineInputMap);
119         DEFAULT_VALUES.put("TextArea.focusInputMap", multilineInputMap);
120         DEFAULT_VALUES.put("TextPane.focusInputMap", multilineInputMap);
121
122     Object JavaDoc fieldInputMap = new UIDefaults.LazyInputMap(new Object JavaDoc[] {
123                "ctrl C", DefaultEditorKit.copyAction,
124                "ctrl V", DefaultEditorKit.pasteAction,
125                "ctrl X", DefaultEditorKit.cutAction,
126                  "COPY", DefaultEditorKit.copyAction,
127                 "PASTE", DefaultEditorKit.pasteAction,
128                   "CUT", DefaultEditorKit.cutAction,
129                "shift LEFT", DefaultEditorKit.selectionBackwardAction,
130                     "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
131               "shift RIGHT", DefaultEditorKit.selectionForwardAction,
132            "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
133             "ctrl LEFT", DefaultEditorKit.previousWordAction,
134              "ctrl KP_LEFT", DefaultEditorKit.previousWordAction,
135                "ctrl RIGHT", DefaultEditorKit.nextWordAction,
136             "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction,
137           "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
138            "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
139          "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction,
140           "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
141                "ctrl A", DefaultEditorKit.selectAllAction,
142                  "HOME", DefaultEditorKit.beginLineAction,
143                   "END", DefaultEditorKit.endLineAction,
144                "shift HOME", DefaultEditorKit.selectionBeginLineAction,
145                 "shift END", DefaultEditorKit.selectionEndLineAction,
146                        "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
147                            "ctrl H", DefaultEditorKit.deletePrevCharAction,
148                            "DELETE", DefaultEditorKit.deleteNextCharAction,
149                             "RIGHT", DefaultEditorKit.forwardAction,
150                              "LEFT", DefaultEditorKit.backwardAction,
151                          "KP_RIGHT", DefaultEditorKit.forwardAction,
152                           "KP_LEFT", DefaultEditorKit.backwardAction,
153                 "ENTER", JTextField.notifyAction,
154           "ctrl BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
155                    "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
156     });
157         DEFAULT_VALUES.put("TextField.focusInputMap", fieldInputMap);
158         DEFAULT_VALUES.put("PasswordField.focusInputMap", fieldInputMap);
159
160
161         DEFAULT_VALUES.put("ComboBox.ancestorInputMap",
162                   new UIDefaults.LazyInputMap(new Object JavaDoc[] {
163              "ESCAPE", "hidePopup",
164             "PAGE_UP", "pageUpPassThrough",
165           "PAGE_DOWN", "pageDownPassThrough",
166                "HOME", "homePassThrough",
167                 "END", "endPassThrough",
168                "DOWN", "selectNext",
169             "KP_DOWN", "selectNext",
170            "alt DOWN", "togglePopup",
171         "alt KP_DOWN", "togglePopup",
172              "alt UP", "togglePopup",
173           "alt KP_UP", "togglePopup",
174               "SPACE", "spacePopup",
175              "ENTER", "enterPressed",
176                  "UP", "selectPrevious",
177               "KP_UP", "selectPrevious"
178                   }));
179
180         DEFAULT_VALUES.put("Desktop.ancestorInputMap",
181            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
182          "ctrl F5", "restore",
183          "ctrl F4", "close",
184          "ctrl F7", "move",
185          "ctrl F8", "resize",
186            "RIGHT", "right",
187         "KP_RIGHT", "right",
188              "shift RIGHT", "shrinkRight",
189           "shift KP_RIGHT", "shrinkRight",
190             "LEFT", "left",
191          "KP_LEFT", "left",
192               "shift LEFT", "shrinkLeft",
193            "shift KP_LEFT", "shrinkLeft",
194               "UP", "up",
195            "KP_UP", "up",
196                 "shift UP", "shrinkUp",
197              "shift KP_UP", "shrinkUp",
198             "DOWN", "down",
199          "KP_DOWN", "down",
200               "shift DOWN", "shrinkDown",
201            "shift KP_DOWN", "shrinkDown",
202           "ESCAPE", "escape",
203          "ctrl F9", "minimize",
204         "ctrl F10", "maximize",
205          "ctrl F6", "selectNextFrame",
206         "ctrl TAB", "selectNextFrame",
207          "ctrl alt F6", "selectNextFrame",
208        "shift ctrl alt F6", "selectPreviousFrame",
209                 "ctrl F12", "navigateNext",
210            "shift ctrl F12", "navigatePrevious"
211                }));
212
213         DEFAULT_VALUES.put("FileChooser.ancestorInputMap",
214            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
215              "ESCAPE", "cancelSelection",
216              "F2", "editFileName",
217              "F5", "refresh",
218              "BACK_SPACE", "Go Up",
219              "ENTER", "approveSelection"
220                }));
221
222         DEFAULT_VALUES.put("FormattedTextField.focusInputMap",
223               new UIDefaults.LazyInputMap(new Object JavaDoc[] {
224                "ctrl C", DefaultEditorKit.copyAction,
225                "ctrl V", DefaultEditorKit.pasteAction,
226                "ctrl X", DefaultEditorKit.cutAction,
227                  "COPY", DefaultEditorKit.copyAction,
228                 "PASTE", DefaultEditorKit.pasteAction,
229                   "CUT", DefaultEditorKit.cutAction,
230                "shift LEFT", DefaultEditorKit.selectionBackwardAction,
231                     "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
232               "shift RIGHT", DefaultEditorKit.selectionForwardAction,
233            "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
234             "ctrl LEFT", DefaultEditorKit.previousWordAction,
235              "ctrl KP_LEFT", DefaultEditorKit.previousWordAction,
236                "ctrl RIGHT", DefaultEditorKit.nextWordAction,
237             "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction,
238           "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
239            "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
240          "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction,
241           "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
242                "ctrl A", DefaultEditorKit.selectAllAction,
243                  "HOME", DefaultEditorKit.beginLineAction,
244                   "END", DefaultEditorKit.endLineAction,
245                "shift HOME", DefaultEditorKit.selectionBeginLineAction,
246                 "shift END", DefaultEditorKit.selectionEndLineAction,
247                        "BACK_SPACE", DefaultEditorKit.deletePrevCharAction,
248                            "ctrl H", DefaultEditorKit.deletePrevCharAction,
249                            "DELETE", DefaultEditorKit.deleteNextCharAction,
250                             "RIGHT", DefaultEditorKit.forwardAction,
251                              "LEFT", DefaultEditorKit.backwardAction,
252                          "KP_RIGHT", DefaultEditorKit.forwardAction,
253                           "KP_LEFT", DefaultEditorKit.backwardAction,
254                 "ENTER", JTextField.notifyAction,
255           "ctrl BACK_SLASH", "unselect",
256                    "control shift O", "toggle-componentOrientation",
257                            "ESCAPE", "reset-field-edit",
258                                "UP", "increment",
259                             "KP_UP", "increment",
260                              "DOWN", "decrement",
261                           "KP_DOWN", "decrement",
262               }));
263
264         DEFAULT_VALUES.put("InternalFrame.windowBindings",
265             new Object JavaDoc[] {
266           "shift ESCAPE", "showSystemMenu",
267         "ctrl SPACE", "showSystemMenu",
268               "ESCAPE", "hideSystemMenu"});
269
270         DEFAULT_VALUES.put("List.focusInputMap",
271            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
272                            "ctrl C", "copy",
273                            "ctrl V", "paste",
274                            "ctrl X", "cut",
275                              "COPY", "copy",
276                             "PASTE", "paste",
277                               "CUT", "cut",
278                        "UP", "selectPreviousRow",
279                     "KP_UP", "selectPreviousRow",
280                  "shift UP", "selectPreviousRowExtendSelection",
281               "shift KP_UP", "selectPreviousRowExtendSelection",
282                     "ctrl shift UP", "selectPreviousRowExtendSelection",
283                  "ctrl shift KP_UP", "selectPreviousRowExtendSelection",
284                           "ctrl UP", "selectPreviousRowChangeLead",
285                        "ctrl KP_UP", "selectPreviousRowChangeLead",
286                      "DOWN", "selectNextRow",
287                   "KP_DOWN", "selectNextRow",
288                "shift DOWN", "selectNextRowExtendSelection",
289             "shift KP_DOWN", "selectNextRowExtendSelection",
290                   "ctrl shift DOWN", "selectNextRowExtendSelection",
291                "ctrl shift KP_DOWN", "selectNextRowExtendSelection",
292                         "ctrl DOWN", "selectNextRowChangeLead",
293                      "ctrl KP_DOWN", "selectNextRowChangeLead",
294                      "LEFT", "selectPreviousColumn",
295                   "KP_LEFT", "selectPreviousColumn",
296                "shift LEFT", "selectPreviousColumnExtendSelection",
297             "shift KP_LEFT", "selectPreviousColumnExtendSelection",
298                   "ctrl shift LEFT", "selectPreviousColumnExtendSelection",
299                "ctrl shift KP_LEFT", "selectPreviousColumnExtendSelection",
300                         "ctrl LEFT", "selectPreviousColumnChangeLead",
301                      "ctrl KP_LEFT", "selectPreviousColumnChangeLead",
302                     "RIGHT", "selectNextColumn",
303                  "KP_RIGHT", "selectNextColumn",
304               "shift RIGHT", "selectNextColumnExtendSelection",
305            "shift KP_RIGHT", "selectNextColumnExtendSelection",
306                  "ctrl shift RIGHT", "selectNextColumnExtendSelection",
307               "ctrl shift KP_RIGHT", "selectNextColumnExtendSelection",
308                        "ctrl RIGHT", "selectNextColumnChangeLead",
309                     "ctrl KP_RIGHT", "selectNextColumnChangeLead",
310                      "HOME", "selectFirstRow",
311                "shift HOME", "selectFirstRowExtendSelection",
312                   "ctrl shift HOME", "selectFirstRowExtendSelection",
313                         "ctrl HOME", "selectFirstRowChangeLead",
314                       "END", "selectLastRow",
315                 "shift END", "selectLastRowExtendSelection",
316                    "ctrl shift END", "selectLastRowExtendSelection",
317                          "ctrl END", "selectLastRowChangeLead",
318                   "PAGE_UP", "scrollUp",
319             "shift PAGE_UP", "scrollUpExtendSelection",
320                "ctrl shift PAGE_UP", "scrollUpExtendSelection",
321                      "ctrl PAGE_UP", "scrollUpChangeLead",
322                 "PAGE_DOWN", "scrollDown",
323           "shift PAGE_DOWN", "scrollDownExtendSelection",
324              "ctrl shift PAGE_DOWN", "scrollDownExtendSelection",
325                    "ctrl PAGE_DOWN", "scrollDownChangeLead",
326                    "ctrl A", "selectAll",
327                "ctrl SLASH", "selectAll",
328           "ctrl BACK_SLASH", "clearSelection",
329                             "SPACE", "addToSelection",
330                        "ctrl SPACE", "toggleAndAnchor",
331                       "shift SPACE", "extendTo",
332                  "ctrl shift SPACE", "moveSelectionTo"
333                }));
334
335         DEFAULT_VALUES.put("List.focusInputMap.RightToLeft",
336            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
337                      "LEFT", "selectNextColumn",
338                   "KP_LEFT", "selectNextColumn",
339                "shift LEFT", "selectNextColumnExtendSelection",
340             "shift KP_LEFT", "selectNextColumnExtendSelection",
341                   "ctrl shift LEFT", "selectNextColumnExtendSelection",
342                "ctrl shift KP_LEFT", "selectNextColumnExtendSelection",
343                         "ctrl LEFT", "selectNextColumnChangeLead",
344                      "ctrl KP_LEFT", "selectNextColumnChangeLead",
345                     "RIGHT", "selectPreviousColumn",
346                  "KP_RIGHT", "selectPreviousColumn",
347               "shift RIGHT", "selectPreviousColumnExtendSelection",
348            "shift KP_RIGHT", "selectPreviousColumnExtendSelection",
349                  "ctrl shift RIGHT", "selectPreviousColumnExtendSelection",
350               "ctrl shift KP_RIGHT", "selectPreviousColumnExtendSelection",
351                        "ctrl RIGHT", "selectPreviousColumnChangeLead",
352                     "ctrl KP_RIGHT", "selectPreviousColumnChangeLead",
353                }));
354
355         DEFAULT_VALUES.put("MenuBar.windowBindings",
356                                 new Object JavaDoc[] { "F10", "takeFocus" });
357
358         DEFAULT_VALUES.put("OptionPane.windowBindings",
359                  new Object JavaDoc[] { "ESCAPE", "close" });
360
361         DEFAULT_VALUES.put("RootPane.defaultButtonWindowKeyBindings",
362                  new Object JavaDoc[] {
363                      "ENTER", "press",
364             "released ENTER", "release",
365                 "ctrl ENTER", "press",
366            "ctrl released ENTER", "release"
367                  });
368
369         DEFAULT_VALUES.put("ScrollBar.anecstorInputMap",
370            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
371                "RIGHT", "positiveUnitIncrement",
372             "KP_RIGHT", "positiveUnitIncrement",
373                 "DOWN", "positiveUnitIncrement",
374              "KP_DOWN", "positiveUnitIncrement",
375            "PAGE_DOWN", "positiveBlockIncrement",
376                 "LEFT", "negativeUnitIncrement",
377              "KP_LEFT", "negativeUnitIncrement",
378                   "UP", "negativeUnitIncrement",
379                "KP_UP", "negativeUnitIncrement",
380              "PAGE_UP", "negativeBlockIncrement",
381                 "HOME", "minScroll",
382                  "END", "maxScroll"
383                }));
384
385         DEFAULT_VALUES.put("ScrollBar.ancestorInputMap.RightToLeft",
386            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
387                "RIGHT", "negativeUnitIncrement",
388             "KP_RIGHT", "negativeUnitIncrement",
389                 "LEFT", "positiveUnitIncrement",
390              "KP_LEFT", "positiveUnitIncrement",
391                }));
392
393         DEFAULT_VALUES.put("ScrollPane.ancestorInputMap",
394            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
395                    "RIGHT", "unitScrollRight",
396                 "KP_RIGHT", "unitScrollRight",
397                     "DOWN", "unitScrollDown",
398                  "KP_DOWN", "unitScrollDown",
399                     "LEFT", "unitScrollLeft",
400                  "KP_LEFT", "unitScrollLeft",
401                       "UP", "unitScrollUp",
402                    "KP_UP", "unitScrollUp",
403                  "PAGE_UP", "scrollUp",
404                "PAGE_DOWN", "scrollDown",
405             "ctrl PAGE_UP", "scrollLeft",
406           "ctrl PAGE_DOWN", "scrollRight",
407                "ctrl HOME", "scrollHome",
408                 "ctrl END", "scrollEnd"
409                }));
410         DEFAULT_VALUES.put("ScrollPane.ancestorInputMap.RightToLeft",
411            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
412             "ctrl PAGE_UP", "scrollRight",
413           "ctrl PAGE_DOWN", "scrollLeft",
414                }));
415
416         DEFAULT_VALUES.put("SplitPane.ancestorInputMap",
417            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
418                 "UP", "negativeIncrement",
419               "DOWN", "positiveIncrement",
420               "LEFT", "negativeIncrement",
421              "RIGHT", "positiveIncrement",
422              "KP_UP", "negativeIncrement",
423            "KP_DOWN", "positiveIncrement",
424            "KP_LEFT", "negativeIncrement",
425           "KP_RIGHT", "positiveIncrement",
426               "HOME", "selectMin",
427                "END", "selectMax",
428                 "F8", "startResize",
429                 "F6", "toggleFocus",
430           "ctrl TAB", "focusOutForward",
431         "ctrl shift TAB", "focusOutBackward"
432                }));
433
434         DEFAULT_VALUES.put("Slider.focusInputMap",
435            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
436                "RIGHT", "positiveUnitIncrement",
437             "KP_RIGHT", "positiveUnitIncrement",
438                 "DOWN", "negativeUnitIncrement",
439              "KP_DOWN", "negativeUnitIncrement",
440            "PAGE_DOWN", "negativeBlockIncrement",
441           "ctrl PAGE_DOWN", "negativeBlockIncrement",
442                 "LEFT", "negativeUnitIncrement",
443              "KP_LEFT", "negativeUnitIncrement",
444                   "UP", "positiveUnitIncrement",
445                "KP_UP", "positiveUnitIncrement",
446              "PAGE_UP", "positiveBlockIncrement",
447                 "ctrl PAGE_UP", "positiveBlockIncrement",
448                 "HOME", "minScroll",
449                  "END", "maxScroll"
450                }));
451
452         DEFAULT_VALUES.put("Slider.focusInputMap.RightToLeft",
453            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
454                "RIGHT", "negativeUnitIncrement",
455             "KP_RIGHT", "negativeUnitIncrement",
456                 "LEFT", "positiveUnitIncrement",
457              "KP_LEFT", "positiveUnitIncrement",
458                }));
459
460         DEFAULT_VALUES.put("TabbedPane.ancestorInputMap",
461            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
462            "ctrl PAGE_DOWN", "navigatePageDown",
463                  "ctrl PAGE_UP", "navigatePageUp",
464                       "ctrl UP", "requestFocus",
465                    "ctrl KP_UP", "requestFocus",
466                }));
467
468         DEFAULT_VALUES.put("TabbedPane.focusInputMap",
469           new UIDefaults.LazyInputMap(new Object JavaDoc[] {
470                  "RIGHT", "navigateRight",
471                   "KP_RIGHT", "navigateRight",
472                       "LEFT", "navigateLeft",
473                    "KP_LEFT", "navigateLeft",
474                         "UP", "navigateUp",
475                      "KP_UP", "navigateUp",
476                       "DOWN", "navigateDown",
477                    "KP_DOWN", "navigateDown",
478                  "ctrl DOWN", "requestFocusForVisibleComponent",
479               "ctrl KP_DOWN", "requestFocusForVisibleComponent",
480               }));
481
482         DEFAULT_VALUES.put("Table.ancestorInputMap",
483            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
484                                "ctrl C", "copy",
485                                "ctrl V", "paste",
486                                "ctrl X", "cut",
487                                  "COPY", "copy",
488                                 "PASTE", "paste",
489                                   "CUT", "cut",
490                         "RIGHT", "selectNextColumn",
491                      "KP_RIGHT", "selectNextColumn",
492                           "shift RIGHT", "selectNextColumnExtendSelection",
493                        "shift KP_RIGHT", "selectNextColumnExtendSelection",
494                      "ctrl shift RIGHT", "selectNextColumnExtendSelection",
495                   "ctrl shift KP_RIGHT", "selectNextColumnExtendSelection",
496                            "ctrl RIGHT", "selectNextColumnChangeLead",
497                         "ctrl KP_RIGHT", "selectNextColumnChangeLead",
498                          "LEFT", "selectPreviousColumn",
499                       "KP_LEFT", "selectPreviousColumn",
500                            "shift LEFT", "selectPreviousColumnExtendSelection",
501                         "shift KP_LEFT", "selectPreviousColumnExtendSelection",
502                       "ctrl shift LEFT", "selectPreviousColumnExtendSelection",
503                    "ctrl shift KP_LEFT", "selectPreviousColumnExtendSelection",
504                             "ctrl LEFT", "selectPreviousColumnChangeLead",
505                          "ctrl KP_LEFT", "selectPreviousColumnChangeLead",
506                          "DOWN", "selectNextRow",
507                       "KP_DOWN", "selectNextRow",
508                            "shift DOWN", "selectNextRowExtendSelection",
509                         "shift KP_DOWN", "selectNextRowExtendSelection",
510                       "ctrl shift DOWN", "selectNextRowExtendSelection",
511                    "ctrl shift KP_DOWN", "selectNextRowExtendSelection",
512                             "ctrl DOWN", "selectNextRowChangeLead",
513                          "ctrl KP_DOWN", "selectNextRowChangeLead",
514                            "UP", "selectPreviousRow",
515                         "KP_UP", "selectPreviousRow",
516                              "shift UP", "selectPreviousRowExtendSelection",
517                           "shift KP_UP", "selectPreviousRowExtendSelection",
518                         "ctrl shift UP", "selectPreviousRowExtendSelection",
519                      "ctrl shift KP_UP", "selectPreviousRowExtendSelection",
520                               "ctrl UP", "selectPreviousRowChangeLead",
521                            "ctrl KP_UP", "selectPreviousRowChangeLead",
522                                  "HOME", "selectFirstColumn",
523                            "shift HOME", "selectFirstColumnExtendSelection",
524                       "ctrl shift HOME", "selectFirstRowExtendSelection",
525                             "ctrl HOME", "selectFirstRow",
526                                   "END", "selectLastColumn",
527                             "shift END", "selectLastColumnExtendSelection",
528                        "ctrl shift END", "selectLastRowExtendSelection",
529                              "ctrl END", "selectLastRow",
530                       "PAGE_UP", "scrollUpChangeSelection",
531                         "shift PAGE_UP", "scrollUpExtendSelection",
532                    "ctrl shift PAGE_UP", "scrollLeftExtendSelection",
533                          "ctrl PAGE_UP", "scrollLeftChangeSelection",
534                     "PAGE_DOWN", "scrollDownChangeSelection",
535               "shift PAGE_DOWN", "scrollDownExtendSelection",
536                  "ctrl shift PAGE_DOWN", "scrollRightExtendSelection",
537                "ctrl PAGE_DOWN", "scrollRightChangeSelection",
538                           "TAB", "selectNextColumnCell",
539                     "shift TAB", "selectPreviousColumnCell",
540                         "ENTER", "selectNextRowCell",
541                   "shift ENTER", "selectPreviousRowCell",
542                        "ctrl A", "selectAll",
543                            "ctrl SLASH", "selectAll",
544                       "ctrl BACK_SLASH", "clearSelection",
545                        "ESCAPE", "cancel",
546                            "F2", "startEditing",
547                                 "SPACE", "addToSelection",
548                            "ctrl SPACE", "toggleAndAnchor",
549                           "shift SPACE", "extendTo",
550                      "ctrl shift SPACE", "moveSelectionTo"
551                }));
552
553         DEFAULT_VALUES.put("Tree.ancestorInputMap",
554            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
555              "ESCAPE", "cancel"
556                }));
557         DEFAULT_VALUES.put("Tree.focusInputMap",
558            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
559                                     "ADD", "expand",
560                                "SUBTRACT", "collapse",
561                                  "ctrl C", "copy",
562                                  "ctrl V", "paste",
563                                  "ctrl X", "cut",
564                                    "COPY", "copy",
565                                   "PASTE", "paste",
566                                     "CUT", "cut",
567                              "UP", "selectPrevious",
568                           "KP_UP", "selectPrevious",
569                        "shift UP", "selectPreviousExtendSelection",
570                     "shift KP_UP", "selectPreviousExtendSelection",
571                           "ctrl shift UP", "selectPreviousExtendSelection",
572                        "ctrl shift KP_UP", "selectPreviousExtendSelection",
573                                 "ctrl UP", "selectPreviousChangeLead",
574                              "ctrl KP_UP", "selectPreviousChangeLead",
575                            "DOWN", "selectNext",
576                         "KP_DOWN", "selectNext",
577                      "shift DOWN", "selectNextExtendSelection",
578                   "shift KP_DOWN", "selectNextExtendSelection",
579                         "ctrl shift DOWN", "selectNextExtendSelection",
580                      "ctrl shift KP_DOWN", "selectNextExtendSelection",
581                               "ctrl DOWN", "selectNextChangeLead",
582                            "ctrl KP_DOWN", "selectNextChangeLead",
583                           "RIGHT", "selectChild",
584                        "KP_RIGHT", "selectChild",
585                            "LEFT", "selectParent",
586                         "KP_LEFT", "selectParent",
587                         "PAGE_UP", "scrollUpChangeSelection",
588                   "shift PAGE_UP", "scrollUpExtendSelection",
589                      "ctrl shift PAGE_UP", "scrollUpExtendSelection",
590                            "ctrl PAGE_UP", "scrollUpChangeLead",
591                       "PAGE_DOWN", "scrollDownChangeSelection",
592                 "shift PAGE_DOWN", "scrollDownExtendSelection",
593                    "ctrl shift PAGE_DOWN", "scrollDownExtendSelection",
594                          "ctrl PAGE_DOWN", "scrollDownChangeLead",
595                            "HOME", "selectFirst",
596                      "shift HOME", "selectFirstExtendSelection",
597                         "ctrl shift HOME", "selectFirstExtendSelection",
598                               "ctrl HOME", "selectFirstChangeLead",
599                             "END", "selectLast",
600                       "shift END", "selectLastExtendSelection",
601                          "ctrl shift END", "selectLastExtendSelection",
602                                "ctrl END", "selectLastChangeLead",
603                              "F2", "startEditing",
604                          "ctrl A", "selectAll",
605                      "ctrl SLASH", "selectAll",
606                 "ctrl BACK_SLASH", "clearSelection",
607                       "ctrl LEFT", "scrollLeft",
608                    "ctrl KP_LEFT", "scrollLeft",
609                      "ctrl RIGHT", "scrollRight",
610                   "ctrl KP_RIGHT", "scrollRight",
611                                   "SPACE", "addToSelection",
612                              "ctrl SPACE", "toggleAndAnchor",
613                             "shift SPACE", "extendTo",
614                        "ctrl shift SPACE", "moveSelectionTo"
615                }));
616         DEFAULT_VALUES.put("Tree.focusInputMap.RightToLeft",
617            new UIDefaults.LazyInputMap(new Object JavaDoc[] {
618                           "RIGHT", "selectParent",
619                        "KP_RIGHT", "selectParent",
620                            "LEFT", "selectChild",
621                         "KP_LEFT", "selectChild",
622                }));
623     }
624
625     /**
626      * Returns the default value for the specified property, or null if there
627      * is no default for the specified value.
628      */

629     private static Object JavaDoc getDefaultValue(Object JavaDoc key) {
630         synchronized(SynthStyle JavaDoc.class) {
631             if (DEFAULT_VALUES == null) {
632                 DEFAULT_VALUES = new HashMap JavaDoc();
633                 populateDefaultValues();
634             }
635             Object JavaDoc value = DEFAULT_VALUES.get(key);
636             if (value instanceof UIDefaults.LazyValue) {
637                 value = ((UIDefaults.LazyValue)value).createValue(null);
638                 DEFAULT_VALUES.put(key, value);
639             }
640             return value;
641         }
642     }
643
644     /**
645      * Constructs a SynthStyle.
646      */

647     public SynthStyle() {
648     }
649
650     /**
651      * Returns the <code>SynthGraphicUtils</code> for the specified context.
652      *
653      * @param context SynthContext identifying requester
654      * @return SynthGraphicsUtils
655      */

656     public SynthGraphicsUtils JavaDoc getGraphicsUtils(SynthContext JavaDoc context) {
657         return SYNTH_GRAPHICS;
658     }
659
660     /**
661      * Returns the color for the specified state. This gives precedence to
662      * foreground and background of the <code>JComponent</code>. If the
663      * <code>Color</code> from the <code>JComponent</code> is not appropriate,
664      * or not used, this will invoke <code>getColorForState</code>. Subclasses
665      * should generally not have to override this, instead override
666      * {@link #getColorForState}.
667      *
668      * @param context SynthContext identifying requester
669      * @param type Type of color being requested.
670      * @return Color
671      */

672     public Color getColor(SynthContext JavaDoc context, ColorType JavaDoc type) {
673         JComponent c = context.getComponent();
674         Region JavaDoc id = context.getRegion();
675         int cs = context.getComponentState();
676         // For the enabled state, prefer the widget's colors
677
if (!id.isSubregion() && cs == SynthConstants.ENABLED) {
678             if (type == ColorType.BACKGROUND) {
679                 return c.getBackground();
680             }
681             else if (type == ColorType.FOREGROUND) {
682                 return c.getForeground();
683             }
684             else if (type == ColorType.TEXT_FOREGROUND) {
685                 // If getForeground returns a non-UIResource it means the
686
// developer has explicitly set the foreground, use it over
687
// that of TEXT_FOREGROUND as that is typically the expected
688
// behavior.
689
Color color = c.getForeground();
690                 if (!(color instanceof UIResource JavaDoc)) {
691                     return color;
692                 }
693             }
694         }
695         // Then use what we've locally defined
696
Color color = getColorForState(context, type);
697         if (color == null) {
698             // No color, fallback to that of the widget.
699
if (type == ColorType.BACKGROUND ||
700                         type == ColorType.TEXT_BACKGROUND) {
701                 return c.getBackground();
702             }
703             else if (type == ColorType.FOREGROUND ||
704                      type == ColorType.TEXT_FOREGROUND) {
705                 return c.getForeground();
706             }
707         }
708         return color;
709     }
710
711     /**
712      * Returns the color for the specified state. This should NOT call any
713      * methods on the <code>JComponent</code>.
714      *
715      * @param context SynthContext identifying requester
716      * @param type Type of color being requested.
717      * @return Color to render with
718      */

719     protected abstract Color getColorForState(SynthContext JavaDoc context,
720                                               ColorType JavaDoc type);
721
722     /**
723      * Returns the Font for the specified state. This redirects to the
724      * <code>JComponent</code> from the <code>context</code> as necessary.
725      * If this does not redirect
726      * to the JComponent {@link #getFontForState} is invoked.
727      *
728      * @param context SynthContext identifying requester
729      * @return Font to render with
730      */

731     public Font getFont(SynthContext JavaDoc context) {
732         JComponent c = context.getComponent();
733         if (context.getComponentState() == SynthConstants.ENABLED) {
734             return c.getFont();
735         }
736         Font cFont = c.getFont();
737         if (cFont != null && !(cFont instanceof UIResource JavaDoc)) {
738             return cFont;
739         }
740         return getFontForState(context);
741     }
742
743     /**
744      * Returns the font for the specified state. This should NOT call any
745      * method on the <code>JComponent</code>.
746      *
747      * @param context SynthContext identifying requester
748      * @return Font to render with
749      */

750     protected abstract Font getFontForState(SynthContext JavaDoc context);
751
752     /**
753      * Returns the Insets that are used to calculate sizing information.
754      *
755      * @param context SynthContext identifying requester
756      * @param insets Insets to place return value in.
757      * @return Sizing Insets.
758      */

759     public Insets getInsets(SynthContext JavaDoc context, Insets insets) {
760         if (insets == null) {
761             insets = new Insets(0, 0, 0, 0);
762         }
763         insets.top = insets.bottom = insets.left = insets.right = 0;
764         return insets;
765     }
766
767     /**
768      * Returns the <code>SynthPainter</code> that will be used for painting.
769      * This may return null.
770      *
771      * @param context SynthContext identifying requester
772      * @return SynthPainter to use
773      */

774     public SynthPainter JavaDoc getPainter(SynthContext JavaDoc context) {
775         return null;
776     }
777
778     /**
779      * Returns true if the region is opaque.
780      *
781      * @param context SynthContext identifying requester
782      * @return true if region is opaque.
783      */

784     public boolean isOpaque(SynthContext JavaDoc context) {
785         return true;
786     }
787
788     /**
789      * Getter for a region specific style property.
790      *
791      * @param context SynthContext identifying requester
792      * @param key Property being requested.
793      * @return Value of the named property
794      */

795     public Object JavaDoc get(SynthContext JavaDoc context, Object JavaDoc key) {
796         return getDefaultValue(key);
797     }
798
799     void installDefaults(SynthContext JavaDoc context, SynthUI ui) {
800         // Special case the Border as this will likely change when the LAF
801
// can have more control over this.
802
if (!context.isSubregion()) {
803             JComponent c = context.getComponent();
804             Border JavaDoc border = c.getBorder();
805
806             if (border == null || border instanceof UIResource JavaDoc) {
807                 c.setBorder(new SynthBorder JavaDoc(ui, getInsets(context, null)));
808             }
809         }
810         installDefaults(context);
811     }
812
813     /**
814      * Installs the necessary state from this Style on the
815      * <code>JComponent</code> from <code>context</code>.
816      *
817      * @param context SynthContext identifying component to install properties
818      * to.
819      */

820     public void installDefaults(SynthContext JavaDoc context) {
821         if (!context.isSubregion()) {
822             JComponent c = context.getComponent();
823             Region JavaDoc region = context.getRegion();
824             Font font = c.getFont();
825
826             if (font == null || (font instanceof UIResource JavaDoc)) {
827                 c.setFont(getFontForState(context));
828             }
829             Color background = c.getBackground();
830             if (background == null || (background instanceof UIResource JavaDoc)) {
831                 c.setBackground(getColorForState(context,
832                                                  ColorType.BACKGROUND));
833             }
834             Color foreground = c.getForeground();
835             if (foreground == null || (foreground instanceof UIResource JavaDoc)) {
836                 c.setForeground(getColorForState(context,
837                          ColorType.FOREGROUND));
838             }
839             LookAndFeel.installProperty(c, "opaque", Boolean.valueOf(isOpaque(context)));
840         }
841     }
842
843     /**
844      * Uninstalls any state that this style installed on
845      * the <code>JComponent</code> from <code>context</code>.
846      * <p>
847      * Styles should NOT depend upon this being called, in certain cases
848      * it may never be called.
849      *
850      * @param context SynthContext identifying component to install properties
851      * to.
852      */

853     public void uninstallDefaults(SynthContext JavaDoc context) {
854         if (!context.isSubregion()) {
855             // NOTE: because getForeground, getBackground and getFont will look
856
// at the parent Container, if we set them to null it may
857
// mean we they return a non-null and non-UIResource value
858
// preventing install from correctly settings its colors/font. For
859
// this reason we do not uninstall the fg/bg/font.
860

861             JComponent c = context.getComponent();
862             Border JavaDoc border = c.getBorder();
863
864             if (border instanceof UIResource JavaDoc) {
865                 c.setBorder(null);
866             }
867         }
868     }
869
870     /**
871      * Convenience method to get a specific style property whose value is
872      * a <code>Number</code>. If the value is a <code>Number</code>,
873      * <code>intValue</code> is returned, otherwise <code>defaultValue</code>
874      * is returned.
875      *
876      * @param context SynthContext identifying requester
877      * @param key Property being requested.
878      * @param defaultValue Value to return if the property has not been
879      * specified, or is not a Number
880      * @return Value of the named property
881      */

882     public int getInt(SynthContext JavaDoc context, Object JavaDoc key, int defaultValue) {
883         Object JavaDoc value = get(context, key);
884
885         if (value instanceof Number JavaDoc) {
886             return ((Number JavaDoc)value).intValue();
887         }
888         return defaultValue;
889     }
890
891     /**
892      * Convenience method to get a specific style property whose value is
893      * an Boolean.
894      *
895      * @param context SynthContext identifying requester
896      * @param key Property being requested.
897      * @param defaultValue Value to return if the property has not been
898      * specified, or is not a Boolean
899      * @return Value of the named property
900      */

901     public boolean getBoolean(SynthContext JavaDoc context, Object JavaDoc key,
902                               boolean defaultValue) {
903         Object JavaDoc value = get(context, key);
904
905         if (value instanceof Boolean JavaDoc) {
906             return ((Boolean JavaDoc)value).booleanValue();
907         }
908         return defaultValue;
909     }
910
911     /**
912      * Convenience method to get a specific style property whose value is
913      * an Icon.
914      *
915      * @param context SynthContext identifying requester
916      * @param key Property being requested.
917      * @return Value of the named property, or null if not specified
918      */

919     public Icon getIcon(SynthContext JavaDoc context, Object JavaDoc key) {
920         Object JavaDoc value = get(context, key);
921
922         if (value instanceof Icon) {
923             return (Icon)value;
924         }
925         return null;
926     }
927
928     /**
929      * Convenience method to get a specific style property whose value is
930      * a String.
931      *
932      * @param context SynthContext identifying requester
933      * @param key Property being requested.
934      * @param defaultValue Value to return if the property has not been
935      * specified, or is not a String
936      * @return Value of the named property
937      */

938     public String JavaDoc getString(SynthContext JavaDoc context, Object JavaDoc key,
939                               String JavaDoc defaultValue) {
940         Object JavaDoc value = get(context, key);
941
942         if (value instanceof String JavaDoc) {
943             return (String JavaDoc)value;
944         }
945         return defaultValue;
946     }
947 }
948
Popular Tags