KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)BlueprintEngineParser.java 1.12 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
8 package com.sun.java.swing.plaf.gtk;
9
10 import java.io.IOException JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.awt.Font JavaDoc;
13 import java.awt.Insets JavaDoc;
14 import java.awt.Color JavaDoc;
15 import javax.swing.plaf.synth.SynthConstants JavaDoc;
16
17 /**
18  * A parser for the "blueprint" engine sections in GTK rc theme files.
19  *
20  * @author Shannon Hickey
21  * @version 1.12 12/19/03
22  */

23 class BlueprintEngineParser extends GTKEngineParser {
24
25     private static final int SYM_IMAGE = GTKScanner.TOKEN_LAST + 1;
26     private static final int SYM_FUNCTION = SYM_IMAGE + 1;
27     private static final int SYM_FILE = SYM_FUNCTION + 1;
28     private static final int SYM_STRETCH = SYM_FILE + 1;
29     private static final int SYM_RECOLORABLE = SYM_STRETCH + 1;
30     private static final int SYM_BORDER = SYM_RECOLORABLE + 1;
31     private static final int SYM_DETAIL = SYM_BORDER + 1;
32     private static final int SYM_STATE = SYM_DETAIL + 1;
33     private static final int SYM_SHADOW = SYM_STATE + 1;
34     private static final int SYM_GAP_SIDE = SYM_SHADOW + 1;
35     private static final int SYM_GAP_FILE = SYM_GAP_SIDE + 1;
36     private static final int SYM_GAP_BORDER = SYM_GAP_FILE + 1;
37     private static final int SYM_GAP_START_FILE = SYM_GAP_BORDER + 1;
38     private static final int SYM_GAP_START_BORDER = SYM_GAP_START_FILE + 1;
39     private static final int SYM_GAP_END_FILE = SYM_GAP_START_BORDER + 1;
40     private static final int SYM_GAP_END_BORDER = SYM_GAP_END_FILE + 1;
41     private static final int SYM_OVERLAY_FILE = SYM_GAP_END_BORDER + 1;
42     private static final int SYM_OVERLAY_BORDER = SYM_OVERLAY_FILE + 1;
43     private static final int SYM_OVERLAY_STRETCH = SYM_OVERLAY_BORDER + 1;
44     private static final int SYM_ARROW_DIRECTION = SYM_OVERLAY_STRETCH + 1;
45     private static final int SYM_ORIENTATION = SYM_ARROW_DIRECTION + 1;
46     private static final int SYM_PARENT_TYPE = SYM_ORIENTATION + 1;
47     private static final int SYM_COLORIZE_COLOR = SYM_PARENT_TYPE + 1;
48     private static final int SYM_ICON_COLORIZE = SYM_COLORIZE_COLOR + 1;
49     private static final int SYM_ICON_COLORIZE_ANCESTOR_TYPE = SYM_ICON_COLORIZE + 1;
50     private static final int SYM_USE_AS_BKG_MASK = SYM_ICON_COLORIZE_ANCESTOR_TYPE + 1;
51     private static final int SYM_OVERLAY_RECOLORABLE = SYM_USE_AS_BKG_MASK + 1;
52     private static final int SYM_OVERLAY_COLORIZE_COLOR = SYM_OVERLAY_RECOLORABLE + 1;
53
54     // SYM_D_HLINE and SYM_D_STEPPER are assumed to begin and end the function symbols.
55
// When adding new symbols, only function symbols should be added between them.
56
private static final int SYM_D_HLINE = SYM_OVERLAY_COLORIZE_COLOR + 1;
57     private static final int SYM_D_VLINE = SYM_D_HLINE + 1;
58     private static final int SYM_D_SHADOW = SYM_D_VLINE + 1;
59     private static final int SYM_D_POLYGON = SYM_D_SHADOW + 1;
60     private static final int SYM_D_ARROW = SYM_D_POLYGON + 1;
61     private static final int SYM_D_DIAMOND = SYM_D_ARROW + 1;
62     private static final int SYM_D_OVAL = SYM_D_DIAMOND + 1;
63     private static final int SYM_D_STRING = SYM_D_OVAL + 1;
64     private static final int SYM_D_BOX = SYM_D_STRING + 1;
65     private static final int SYM_D_FLAT_BOX = SYM_D_BOX + 1;
66     private static final int SYM_D_CHECK = SYM_D_FLAT_BOX + 1;
67     private static final int SYM_D_OPTION = SYM_D_CHECK + 1;
68     private static final int SYM_D_CROSS = SYM_D_OPTION + 1;
69     private static final int SYM_D_RAMP = SYM_D_CROSS + 1;
70     private static final int SYM_D_TAB = SYM_D_RAMP + 1;
71     private static final int SYM_D_SHADOW_GAP = SYM_D_TAB + 1;
72     private static final int SYM_D_BOX_GAP = SYM_D_SHADOW_GAP + 1;
73     private static final int SYM_D_EXTENSION = SYM_D_BOX_GAP + 1;
74     private static final int SYM_D_FOCUS = SYM_D_EXTENSION + 1;
75     private static final int SYM_D_SLIDER = SYM_D_FOCUS + 1;
76     private static final int SYM_D_ENTRY = SYM_D_SLIDER + 1;
77     private static final int SYM_D_HANDLE = SYM_D_ENTRY + 1;
78     private static final int SYM_D_LAYOUT = SYM_D_HANDLE + 1;
79     private static final int SYM_D_BACKGROUND = SYM_D_LAYOUT + 1;
80     private static final int SYM_D_STEPPER = SYM_D_BACKGROUND + 1;
81     // end function symbols
82

83     private static final int SYM_TRUE = SYM_D_STEPPER + 1;
84     private static final int SYM_FALSE = SYM_TRUE + 1;
85     private static final int SYM_TOP = SYM_FALSE + 1;
86     private static final int SYM_UP = SYM_TOP + 1;
87     private static final int SYM_BOTTOM = SYM_UP + 1;
88     private static final int SYM_DOWN = SYM_BOTTOM + 1;
89     private static final int SYM_LEFT = SYM_DOWN + 1;
90     private static final int SYM_RIGHT = SYM_LEFT + 1;
91     private static final int SYM_NORMAL = SYM_RIGHT + 1;
92     private static final int SYM_ACTIVE = SYM_NORMAL + 1;
93     private static final int SYM_PRELIGHT = SYM_ACTIVE + 1;
94     private static final int SYM_SELECTED = SYM_PRELIGHT + 1;
95     private static final int SYM_INSENSITIVE = SYM_SELECTED + 1;
96     private static final int SYM_NONE = SYM_INSENSITIVE + 1;
97     private static final int SYM_IN = SYM_NONE + 1;
98     private static final int SYM_OUT = SYM_IN + 1;
99     private static final int SYM_ETCHED_IN = SYM_OUT + 1;
100     private static final int SYM_ETCHED_OUT = SYM_ETCHED_IN + 1;
101     private static final int SYM_HORIZONTAL = SYM_ETCHED_OUT + 1;
102     private static final int SYM_VERTICAL = SYM_HORIZONTAL + 1;
103
104     private static final int[] symbolVals = {
105         SYM_IMAGE, SYM_FUNCTION, SYM_FILE, SYM_STRETCH, SYM_RECOLORABLE,
106         SYM_BORDER, SYM_DETAIL, SYM_STATE, SYM_SHADOW, SYM_GAP_SIDE,
107         SYM_GAP_FILE, SYM_GAP_BORDER, SYM_GAP_START_FILE, SYM_GAP_START_BORDER,
108         SYM_GAP_END_FILE, SYM_GAP_END_BORDER, SYM_OVERLAY_FILE, SYM_OVERLAY_BORDER,
109         SYM_OVERLAY_STRETCH, SYM_ARROW_DIRECTION, SYM_ORIENTATION,
110         SYM_PARENT_TYPE, SYM_COLORIZE_COLOR, SYM_ICON_COLORIZE,
111         SYM_ICON_COLORIZE_ANCESTOR_TYPE, SYM_USE_AS_BKG_MASK,
112         SYM_OVERLAY_RECOLORABLE, SYM_OVERLAY_COLORIZE_COLOR, SYM_D_HLINE,
113         SYM_D_VLINE, SYM_D_SHADOW, SYM_D_POLYGON, SYM_D_ARROW, SYM_D_DIAMOND,
114         SYM_D_OVAL, SYM_D_STRING, SYM_D_BOX, SYM_D_FLAT_BOX, SYM_D_CHECK,
115         SYM_D_OPTION, SYM_D_CROSS, SYM_D_RAMP, SYM_D_TAB, SYM_D_SHADOW_GAP,
116         SYM_D_BOX_GAP, SYM_D_EXTENSION, SYM_D_FOCUS, SYM_D_SLIDER, SYM_D_ENTRY,
117         SYM_D_HANDLE, SYM_D_LAYOUT, SYM_D_BACKGROUND,
118         SYM_D_STEPPER, SYM_TRUE, SYM_FALSE, SYM_TOP, SYM_UP,
119         SYM_BOTTOM, SYM_DOWN, SYM_LEFT, SYM_RIGHT, SYM_NORMAL, SYM_ACTIVE,
120         SYM_PRELIGHT, SYM_SELECTED, SYM_INSENSITIVE, SYM_NONE, SYM_IN, SYM_OUT,
121         SYM_ETCHED_IN, SYM_ETCHED_OUT, SYM_HORIZONTAL, SYM_VERTICAL
122     };
123
124     private static final String JavaDoc[] symbolNames = {
125         "image", // SYM_IMAGE
126
"function", // SYM_FUNCTION
127
"file", // SYM_FILE
128
"stretch", // SYM_STRETCH
129
"recolorable", // SYM_RECOLORABLE
130
"border", // SYM_BORDER
131
"detail", // SYM_DETAIL
132
"state", // SYM_STATE
133
"shadow", // SYM_SHADOW
134
"gap_side", // SYM_GAP_SIDE
135
"gap_file", // SYM_GAP_FILE
136
"gap_border", // SYM_GAP_BORDER
137
"gap_start_file", // SYM_GAP_START_FILE
138
"gap_start_border", // SYM_GAP_START_BORDER
139
"gap_end_file", // SYM_GAP_END_FILE
140
"gap_end_border", // SYM_GAP_END_BORDER
141
"overlay_file", // SYM_OVERLAY_FILE
142
"overlay_border", // SYM_OVERLAY_BORDER
143
"overlay_stretch", // SYM_OVERLAY_STRETCH
144
"arrow_direction", // SYM_ARROW_DIRECTION
145
"orientation", // SYM_ORIENTATION
146
"parent_type", // SYM_PARENT_TYPE
147
"colorize_color", // SYM_COLORIZE_COLOR
148
"icon_colorize", // SYM_ICON_COLORIZE
149
"icon_colorize_ancestor_type", // SYM_ICON_COLORIZE_ANCESTOR_TYPE
150
"use_as_bkg_mask", // SYM_USE_AS_BKG_MASK
151
"overlay_recolorable", // SYM_OVERLAY_RECOLORABLE
152
"overlay_colorize_color", // SYM_OVERLAY_COLORIZE_COLOR
153

154         "HLINE", // SYM_D_HLINE
155
"VLINE", // SYM_D_VLINE
156
"SHADOW", // SYM_D_SHADOW
157
"POLYGON", // SYM_D_POLYGON
158
"ARROW", // SYM_D_ARROW
159
"DIAMOND", // SYM_D_DIAMOND
160
"OVAL", // SYM_D_OVAL
161
"STRING", // SYM_D_STRING
162
"BOX", // SYM_D_BOX
163
"FLAT_BOX", // SYM_D_FLAT_BOX
164
"CHECK", // SYM_D_CHECK
165
"OPTION", // SYM_D_OPTION
166
"CROSS", // SYM_D_CROSS
167
"RAMP", // SYM_D_RAMP
168
"TAB", // SYM_D_TAB
169
"SHADOW_GAP", // SYM_D_SHADOW_GAP
170
"BOX_GAP", // SYM_D_BOX_GAP
171
"EXTENSION", // SYM_D_EXTENSION
172
"FOCUS", // SYM_D_FOCUS
173
"SLIDER", // SYM_D_SLIDER
174
"ENTRY", // SYM_D_ENTRY
175
"HANDLE", // SYM_D_HANDLE
176
"LAYOUT", // SYM_D_LAYOUT
177
"BACKGROUND", // SYM_D_BACKGROUND
178
"STEPPER", // SYM_D_STEPPER
179

180         "TRUE", // SYM_TRUE
181
"FALSE", // SYM_FALSE
182

183         "TOP", // SYM_TOP
184
"UP", // SYM_UP
185
"BOTTOM", // SYM_BOTTOM
186
"DOWN", // SYM_DOWN
187
"LEFT", // SYM_LEFT
188
"RIGHT", // SYM_RIGHT
189

190         "NORMAL", // SYM_NORMAL
191
"ACTIVE", // SYM_ACTIVE
192
"PRELIGHT", // SYM_PRELIGHT
193
"SELECTED", // SYM_SELECTED
194
"INSENSITIVE", // SYM_INSENSITIVE
195

196         "NONE", // SYM_NONE
197
"IN", // SYM_IN
198
"OUT", // SYM_OUT
199
"ETCHED_IN", // SYM_ETCHED_IN
200
"ETCHED_OUT", // SYM_ETCHED_OUT
201
"HORIZONTAL", // SYM_HORIZONTAL
202
"VERTICAL" // SYM_VERTICAL
203
};
204
205     private static class BlueprintEngineInfo extends GTKParser.EngineInfo {
206
207         ArrayList JavaDoc pInfos = new ArrayList JavaDoc();
208         boolean iconColorize = false;
209         ArrayList JavaDoc iconAncestorTypes = null;
210         Color JavaDoc colorizeColor = null;
211
212         GTKStyle constructGTKStyle(GTKStyle.GTKStateInfo[] infoArray,
213                                    CircularIdentityList props,
214                                    Font JavaDoc font,
215                                    int xThickness,
216                                    int yThickness,
217                                    GTKStyle.GTKStockIconInfo[] stockArray) {
218
219             BlueprintStyle.Info[] pInfoArray = null;
220             if (pInfos.size() != 0) {
221                 pInfoArray = new BlueprintStyle.Info[pInfos.size()];
222                 pInfoArray = (BlueprintStyle.Info[])pInfos.toArray(pInfoArray);
223             }
224
225             String JavaDoc[] ancestorArray = null;
226             if (iconAncestorTypes != null && iconAncestorTypes.size() != 0) {
227                 ancestorArray = new String JavaDoc[iconAncestorTypes.size()];
228                 ancestorArray = (String JavaDoc[])iconAncestorTypes.toArray(ancestorArray);
229             }
230
231             return new BlueprintStyle(infoArray,
232                                    props,
233                                    font,
234                                    xThickness,
235                                    yThickness,
236                                    stockArray,
237                                    pInfoArray,
238                                    iconColorize,
239                                    ancestorArray,
240                                    colorizeColor);
241         }
242     }
243
244     private GTKScanner scanner;
245     private GTKParser parser;
246     private BlueprintEngineInfo engineInfo;
247
248     private void registerSymbolsIfNecessary() {
249         if (scanner.containsSymbol(symbolNames[0])) {
250             return;
251         }
252
253         for (int i = 0; i < symbolNames.length; i++) {
254             scanner.addSymbol(symbolNames[i], symbolVals[i]);
255         }
256     }
257
258     int parse(GTKScanner scanner,
259               GTKParser parser,
260               GTKParser.EngineInfo[] retVal) throws IOException JavaDoc {
261
262         this.scanner = scanner;
263         this.parser = parser;
264
265         if (retVal[0] == null) {
266             engineInfo = new BlueprintEngineInfo();
267         } else {
268             engineInfo = (BlueprintEngineInfo)retVal[0];
269         }
270
271         int oldScope = scanner.setScope(uniqueScopeID);
272         registerSymbolsIfNecessary();
273
274         BlueprintStyle.Info info[] = new BlueprintStyle.Info[1];
275
276         int token;
277
278         token = scanner.peekNextToken();
279         while (token != GTKScanner.TOKEN_RIGHT_CURLY) {
280             
281             info[0] = null;
282             
283             switch(token) {
284                 case SYM_IMAGE:
285                     token = parseImage(info);
286                     break;
287                 case SYM_COLORIZE_COLOR:
288                     Color JavaDoc[] col = new Color JavaDoc[1];
289                     token = parseColorizeColor(col);
290                     if (token == GTKScanner.TOKEN_NONE) {
291                         engineInfo.colorizeColor = col[0];
292                     }
293                     break;
294                 case SYM_ICON_COLORIZE:
295                     token = parseIconColorize(engineInfo);
296                     break;
297                 case SYM_ICON_COLORIZE_ANCESTOR_TYPE:
298                     // consume token
299
scanner.getToken();
300
301                     if (engineInfo.iconAncestorTypes == null) {
302                         engineInfo.iconAncestorTypes = new ArrayList JavaDoc();
303                     }
304
305                     token = parseStringList(engineInfo.iconAncestorTypes);
306                     break;
307                 default:
308                     scanner.getToken();
309                     token = GTKScanner.TOKEN_RIGHT_CURLY;
310                     break;
311             }
312
313             if (token != GTKScanner.TOKEN_NONE) {
314                 return token;
315             }
316
317             if (info[0] != null) {
318                 engineInfo.pInfos.add(info[0]);
319             }
320
321             token = scanner.peekNextToken();
322         }
323
324         scanner.getToken();
325
326         retVal[0] = engineInfo;
327
328         scanner.setScope(oldScope);
329         return GTKScanner.TOKEN_NONE;
330     }
331
332     private int parseImage(BlueprintStyle.Info[] retVal) throws IOException JavaDoc {
333         int token;
334
335         token = scanner.getToken();
336         if (token != SYM_IMAGE) {
337             return SYM_IMAGE;
338         }
339
340         token = scanner.getToken();
341         if (token != GTKScanner.TOKEN_LEFT_CURLY) {
342             return GTKScanner.TOKEN_LEFT_CURLY;
343         }
344
345         BlueprintStyle.Info info = new BlueprintStyle.Info();
346
347         // to hold the return value from parseFile
348
String JavaDoc[] fileName = new String JavaDoc[1];
349         
350         // to hold the return value from parseStretch
351
// and parseRecolorable
352
boolean[] bool = new boolean[1];
353         
354         // to hold the return value from parseBorder
355
Insets JavaDoc[] insets = new Insets JavaDoc[1];
356
357         // to hold the return value from parseColorizeColor
358
Color JavaDoc[] col = new Color JavaDoc[1];
359
360         token = scanner.peekNextToken();
361         while (token != GTKScanner.TOKEN_RIGHT_CURLY) {
362             switch(token) {
363                 case SYM_FUNCTION:
364                     token = parseFunction(info);
365                     break;
366                 case SYM_RECOLORABLE:
367                     token = parseRecolorable(bool);
368                     if (token == GTKScanner.TOKEN_NONE) {
369                         info.recolorable = bool[0];
370                     }
371                     break;
372                 case SYM_OVERLAY_RECOLORABLE:
373                     token = parseRecolorable(bool);
374                     if (token == GTKScanner.TOKEN_NONE) {
375                         info.overlayRecolorable = bool[0];
376                     }
377                     break;
378                 case SYM_DETAIL:
379                     token = parseDetail(info);
380                     break;
381                 case SYM_STATE:
382                     token = parseState(info);
383                     break;
384                 case SYM_SHADOW:
385                     token = parseShadow(info);
386                     break;
387                 case SYM_GAP_SIDE:
388                     token = parseGapSide(info);
389                     break;
390                 case SYM_ARROW_DIRECTION:
391                     token = parseArrowDirection(info);
392                     break;
393                 case SYM_ORIENTATION:
394                     token = parseOrientation(info);
395                     break;
396                 case SYM_FILE:
397                     token = parseFile(fileName);
398                     if (token == GTKScanner.TOKEN_NONE) {
399                         info.image = fileName[0];
400                     }
401                     break;
402                 case SYM_BORDER:
403                     token = parseBorder(insets);
404                     if (token == GTKScanner.TOKEN_NONE) {
405                         info.fileInsets = insets[0];
406                     }
407                     break;
408                 case SYM_STRETCH:
409                     token = parseStretch(bool);
410                     if (token == GTKScanner.TOKEN_NONE) {
411                         info.stretch = bool[0];
412                     }
413                     break;
414                 case SYM_GAP_FILE:
415                     token = parseFile(fileName);
416                     if (token == GTKScanner.TOKEN_NONE) {
417                         info.gapImage = fileName[0];
418                     }
419                     break;
420                 case SYM_GAP_BORDER:
421                     token = parseBorder(insets);
422                     if (token == GTKScanner.TOKEN_NONE) {
423                         info.gapInsets = insets[0];
424                     }
425                     break;
426                 case SYM_GAP_START_FILE:
427                     token = parseFile(fileName);
428                     if (token == GTKScanner.TOKEN_NONE) {
429                         info.gapStartImage = fileName[0];
430                     }
431                     break;
432                 case SYM_GAP_START_BORDER:
433                     token = parseBorder(insets);
434                     if (token == GTKScanner.TOKEN_NONE) {
435                         info.gapStartInsets = insets[0];
436                     }
437                     break;
438                 case SYM_GAP_END_FILE:
439                     token = parseFile(fileName);
440                     if (token == GTKScanner.TOKEN_NONE) {
441                         info.gapEndImage = fileName[0];
442                     }
443                     break;
444                 case SYM_GAP_END_BORDER:
445                     token = parseBorder(insets);
446                     if (token == GTKScanner.TOKEN_NONE) {
447                         info.gapEndInsets = insets[0];
448                     }
449                     break;
450                 case SYM_OVERLAY_FILE:
451                     token = parseFile(fileName);
452                     if (token == GTKScanner.TOKEN_NONE) {
453                         info.overlayImage = fileName[0];
454                     }
455                     break;
456                 case SYM_OVERLAY_BORDER:
457                     token = parseBorder(insets);
458                     if (token == GTKScanner.TOKEN_NONE) {
459                         info.overlayInsets = insets[0];
460                     }
461                     break;
462                 case SYM_OVERLAY_STRETCH:
463                     token = parseStretch(bool);
464                     if (token == GTKScanner.TOKEN_NONE) {
465                         info.overlayStretch = bool[0];
466                     }
467                     break;
468                 case SYM_PARENT_TYPE:
469                     // consume token
470
scanner.getToken();
471
472                     if (info.parentTypeList == null) {
473                         info.parentTypeList = new ArrayList JavaDoc();
474                     }
475
476                     token = parseStringList(info.parentTypeList);
477                     break;
478                 case SYM_COLORIZE_COLOR:
479                     token = parseColorizeColor(col);
480                     if (token == GTKScanner.TOKEN_NONE) {
481                         info.colorizeColor = col[0];
482                     }
483                     break;
484                 case SYM_OVERLAY_COLORIZE_COLOR:
485                     token = parseColorizeColor(col);
486                     if (token == GTKScanner.TOKEN_NONE) {
487                         info.overlayColorizeColor = col[0];
488                     }
489                     break;
490                 case SYM_USE_AS_BKG_MASK:
491                     token = parseUseAsBkgMask(info);
492                     break;
493                 default:
494                     scanner.getToken();
495                     token = GTKScanner.TOKEN_RIGHT_CURLY;
496                     break;
497             }
498
499             if (token != GTKScanner.TOKEN_NONE) {
500                 return token;
501             }
502
503             token = scanner.peekNextToken();
504         }
505
506         token = scanner.getToken();
507         if (token != GTKScanner.TOKEN_RIGHT_CURLY) {
508             return GTKScanner.TOKEN_RIGHT_CURLY;
509         }
510
511         // PENDING(shannonh) - may want to do some validation of the
512
// info before we return it
513

514         retVal[0] = info;
515         return GTKScanner.TOKEN_NONE;
516     }
517
518     private int parseFunction(BlueprintStyle.Info info) throws IOException JavaDoc {
519         int token;
520
521         token = scanner.getToken();
522         if (token != SYM_FUNCTION) {
523             return SYM_FUNCTION;
524         }
525
526         token = scanner.getToken();
527         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
528             return GTKScanner.TOKEN_EQUAL_SIGN;
529         }
530
531         token = scanner.getToken();
532         if (token >= SYM_D_HLINE && token <= SYM_D_STEPPER) {
533             info.setFunction(symbolNames[token - SYM_IMAGE]);
534         }
535         
536         // PENDING(shannonh) - should we complain if not a valid function?
537

538         return GTKScanner.TOKEN_NONE;
539     }
540
541     private int parseRecolorable(boolean[] retVal) throws IOException JavaDoc {
542         int token;
543         
544         scanner.getToken();
545         
546         token = scanner.getToken();
547         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
548             return GTKScanner.TOKEN_EQUAL_SIGN;
549         }
550         
551         token = scanner.getToken();
552         if (token == SYM_TRUE) {
553             retVal[0] = true;
554         } else if (token == SYM_FALSE) {
555             retVal[0] = false;
556         } else {
557             return SYM_TRUE;
558         }
559         
560         return GTKScanner.TOKEN_NONE;
561     }
562     
563     private int parseDetail(BlueprintStyle.Info info) throws IOException JavaDoc {
564         int token;
565         
566         token = scanner.getToken();
567         if (token != SYM_DETAIL) {
568             return SYM_DETAIL;
569         }
570         
571         token = scanner.getToken();
572         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
573             return GTKScanner.TOKEN_EQUAL_SIGN;
574         }
575         
576         token = scanner.getToken();
577         if (token != GTKScanner.TOKEN_STRING) {
578             return GTKScanner.TOKEN_STRING;
579         }
580
581         info.setDetail(scanner.currValue.stringVal);
582
583         return GTKScanner.TOKEN_NONE;
584     }
585
586     private int parseState(BlueprintStyle.Info info) throws IOException JavaDoc {
587         int token;
588         
589         token = scanner.getToken();
590         if (token != SYM_STATE) {
591             return SYM_STATE;
592         }
593         
594         token = scanner.getToken();
595         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
596             return GTKScanner.TOKEN_EQUAL_SIGN;
597         }
598         
599         token = scanner.getToken();
600         switch(token) {
601             case SYM_NORMAL:
602                 info.componentState = SynthConstants.ENABLED;
603                 break;
604             case SYM_ACTIVE:
605                 info.componentState = SynthConstants.PRESSED;
606                 break;
607             case SYM_PRELIGHT:
608                 info.componentState = SynthConstants.MOUSE_OVER;
609                 break;
610             case SYM_SELECTED:
611                 info.componentState = SynthConstants.SELECTED;
612                 break;
613             case SYM_INSENSITIVE:
614                 info.componentState = SynthConstants.DISABLED;
615                 break;
616             default:
617                 return SYM_NORMAL;
618         }
619
620         return GTKScanner.TOKEN_NONE;
621     }
622
623     private int parseShadow(BlueprintStyle.Info info) throws IOException JavaDoc {
624         int token;
625         
626         token = scanner.getToken();
627         if (token != SYM_SHADOW) {
628             return SYM_SHADOW;
629         }
630         
631         token = scanner.getToken();
632         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
633             return GTKScanner.TOKEN_EQUAL_SIGN;
634         }
635         
636         token = scanner.getToken();
637         switch(token) {
638             case SYM_NONE:
639                 info.shadow = GTKConstants.SHADOW_NONE;
640                 break;
641             case SYM_IN:
642                 info.shadow = GTKConstants.SHADOW_IN;
643                 break;
644             case SYM_OUT:
645                 info.shadow = GTKConstants.SHADOW_OUT;
646                 break;
647             case SYM_ETCHED_IN:
648                 info.shadow = GTKConstants.SHADOW_ETCHED_IN;
649                 break;
650             case SYM_ETCHED_OUT:
651                 info.shadow = GTKConstants.SHADOW_ETCHED_OUT;
652                 break;
653             default:
654                 return SYM_NONE;
655         }
656
657         return GTKScanner.TOKEN_NONE;
658     }
659
660     private int parseGapSide(BlueprintStyle.Info info) throws IOException JavaDoc {
661         int token;
662         
663         token = scanner.getToken();
664         if (token != SYM_GAP_SIDE) {
665             return SYM_GAP_SIDE;
666         }
667         
668         token = scanner.getToken();
669         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
670             return GTKScanner.TOKEN_EQUAL_SIGN;
671         }
672         
673         token = scanner.getToken();
674         switch(token) {
675             case SYM_TOP:
676                 info.gapSide = GTKConstants.TOP;
677                 break;
678             case SYM_BOTTOM:
679                 info.gapSide = GTKConstants.BOTTOM;
680                 break;
681             case SYM_LEFT:
682                 info.gapSide = GTKConstants.LEFT;
683                 break;
684             case SYM_RIGHT:
685                 info.gapSide = GTKConstants.RIGHT;
686                 break;
687             default:
688                 return SYM_TOP;
689         }
690
691         return GTKScanner.TOKEN_NONE;
692     }
693
694     private int parseArrowDirection(BlueprintStyle.Info info) throws IOException JavaDoc {
695         int token;
696         
697         token = scanner.getToken();
698         if (token != SYM_ARROW_DIRECTION) {
699             return SYM_ARROW_DIRECTION;
700         }
701         
702         token = scanner.getToken();
703         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
704             return GTKScanner.TOKEN_EQUAL_SIGN;
705         }
706         
707         token = scanner.getToken();
708         switch(token) {
709             case SYM_UP:
710                 info.arrowDirection = GTKConstants.ARROW_UP;
711                 break;
712             case SYM_DOWN:
713                 info.arrowDirection = GTKConstants.ARROW_DOWN;
714                 break;
715             case SYM_LEFT:
716                 info.arrowDirection = GTKConstants.ARROW_LEFT;
717                 break;
718             case SYM_RIGHT:
719                 info.arrowDirection = GTKConstants.ARROW_RIGHT;
720                 break;
721             default:
722                 return SYM_UP;
723         }
724
725         return GTKScanner.TOKEN_NONE;
726     }
727     
728     private int parseOrientation(BlueprintStyle.Info info) throws IOException JavaDoc {
729         int token;
730         
731         token = scanner.getToken();
732         if (token != SYM_ORIENTATION) {
733             return SYM_ORIENTATION;
734         }
735         
736         token = scanner.getToken();
737         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
738             return GTKScanner.TOKEN_EQUAL_SIGN;
739         }
740         
741         token = scanner.getToken();
742         switch(token) {
743             case SYM_HORIZONTAL:
744                 info.orientation = GTKConstants.HORIZONTAL;
745                 break;
746             case SYM_VERTICAL:
747                 info.orientation = GTKConstants.VERTICAL;
748                 break;
749             default:
750                 return SYM_HORIZONTAL;
751         }
752         
753         return GTKScanner.TOKEN_NONE;
754     }
755
756     private int parseFile(String JavaDoc[] retVal) throws IOException JavaDoc {
757         int token;
758
759         token = scanner.getToken();
760         
761         token = scanner.getToken();
762         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
763             return GTKScanner.TOKEN_EQUAL_SIGN;
764         }
765         
766         token = scanner.getToken();
767         if (token != GTKScanner.TOKEN_STRING) {
768             return GTKScanner.TOKEN_STRING;
769         }
770
771         retVal[0] = parser.resolvePixmapPath(scanner.currValue.stringVal);
772
773         return GTKScanner.TOKEN_NONE;
774     }
775
776     private int parseStretch(boolean[] retVal) throws IOException JavaDoc {
777         int token;
778         
779         token = scanner.getToken();
780         
781         token = scanner.getToken();
782         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
783             return GTKScanner.TOKEN_EQUAL_SIGN;
784         }
785         
786         token = scanner.getToken();
787         switch(token) {
788             case SYM_TRUE:
789                 retVal[0] = true;
790                 break;
791             case SYM_FALSE:
792                 retVal[0] = false;
793                 break;
794             default:
795                 return SYM_TRUE;
796         }
797         
798         return GTKScanner.TOKEN_NONE;
799     }
800
801     private int parseBorder(Insets JavaDoc[] retVal) throws IOException JavaDoc {
802         int left = 0;
803         int right = 0;
804         int top = 0;
805         int bottom = 0;
806         
807         scanner.getToken();
808         
809         if (scanner.getToken() != GTKScanner.TOKEN_EQUAL_SIGN) {
810             return GTKScanner.TOKEN_EQUAL_SIGN;
811         }
812         
813         if (scanner.getToken() != GTKScanner.TOKEN_LEFT_CURLY) {
814             return GTKScanner.TOKEN_LEFT_CURLY;
815         }
816         
817         if (scanner.getToken() != GTKScanner.TOKEN_INT) {
818             return GTKScanner.TOKEN_INT;
819         }
820         
821         left = (int)scanner.currValue.longVal;
822         
823         if (scanner.getToken() != GTKScanner.TOKEN_COMMA) {
824             return GTKScanner.TOKEN_COMMA;
825         }
826         
827         if (scanner.getToken() != GTKScanner.TOKEN_INT) {
828             return GTKScanner.TOKEN_INT;
829         }
830         
831         right = (int)scanner.currValue.longVal;
832         
833         if (scanner.getToken() != GTKScanner.TOKEN_COMMA) {
834             return GTKScanner.TOKEN_COMMA;
835         }
836         
837         if (scanner.getToken() != GTKScanner.TOKEN_INT) {
838             return GTKScanner.TOKEN_INT;
839         }
840         
841         top = (int)scanner.currValue.longVal;
842         
843         if (scanner.getToken() != GTKScanner.TOKEN_COMMA) {
844             return GTKScanner.TOKEN_COMMA;
845         }
846         
847         if (scanner.getToken() != GTKScanner.TOKEN_INT) {
848             return GTKScanner.TOKEN_INT;
849         }
850         
851         bottom = (int)scanner.currValue.longVal;
852         
853         if (scanner.getToken() != GTKScanner.TOKEN_RIGHT_CURLY) {
854             return GTKScanner.TOKEN_RIGHT_CURLY;
855         }
856
857         retVal[0] = new Insets JavaDoc(top, left, bottom, right);
858
859         return GTKScanner.TOKEN_NONE;
860     }
861
862     private int parseColorizeColor(Color JavaDoc[] retVal) throws IOException JavaDoc {
863         int token;
864
865         scanner.getToken();
866         
867         token = scanner.getToken();
868         if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
869             return GTKScanner.TOKEN_EQUAL_SIGN;
870         }
871         
872         token = scanner.getToken();
873
874         switch(token) {
875             case GTKScanner.TOKEN_LEFT_CURLY:
876                 int red;
877                 int green;
878                 int blue;
879                 int alpha = 255;
880
881                 token = scanner.getToken();
882                 if (token == GTKScanner.TOKEN_INT) {
883                     red = intColorVal(scanner.currValue.longVal);
884                 } else if (token == GTKScanner.TOKEN_FLOAT) {
885                     red = intColorVal(scanner.currValue.doubleVal);
886                 } else {
887                     return GTKScanner.TOKEN_FLOAT;
888                 }
889                 
890                 token = scanner.getToken();
891                 if (token != GTKScanner.TOKEN_COMMA) {
892                     return GTKScanner.TOKEN_COMMA;
893                 }
894
895                 token = scanner.getToken();
896                 if (token == GTKScanner.TOKEN_INT) {
897                     green = intColorVal(scanner.currValue.longVal);
898                 } else if (token == GTKScanner.TOKEN_FLOAT) {
899                     green = intColorVal(scanner.currValue.doubleVal);
900                 } else {
901                     return GTKScanner.TOKEN_FLOAT;
902                 }
903
904                 token = scanner.getToken();
905                 if (token != GTKScanner.TOKEN_COMMA) {
906                     return GTKScanner.TOKEN_COMMA;
907                 }
908
909                 token = scanner.getToken();
910                 if (token == GTKScanner.TOKEN_INT) {
911                     blue = intColorVal(scanner.currValue.longVal);
912                 } else if (token == GTKScanner.TOKEN_FLOAT) {
913                     blue = intColorVal(scanner.currValue.doubleVal);
914                 } else {
915                     return GTKScanner.TOKEN_FLOAT;
916                 }
917
918                 token = scanner.getToken();
919                 if (token == GTKScanner.TOKEN_COMMA) {
920                     token = scanner.getToken();
921                     if (token == GTKScanner.TOKEN_INT) {
922                         alpha = intColorVal(scanner.currValue.longVal);
923                     } else if (token == GTKScanner.TOKEN_FLOAT) {
924                         alpha = intColorVal(scanner.currValue.doubleVal);
925                     } else {
926                         return GTKScanner.TOKEN_FLOAT;
927                     }
928                     
929                     token = scanner.getToken();
930                 }
931
932                 if (token != GTKScanner.TOKEN_RIGHT_CURLY) {
933                     return GTKScanner.TOKEN_RIGHT_CURLY;
934                 }
935
936                 retVal[0] = new Color JavaDoc(red, green, blue, alpha);
937
938                 break;
939             case GTKScanner.TOKEN_STRING:
940                 Color JavaDoc color = parseColorString(scanner.currValue.stringVal);
941
942                 if (color == null) {
943                     scanner.printMessage("Invalid color constant '" +
944                                               scanner.currValue.stringVal
945                                               + "'", false);
946                     return GTKScanner.TOKEN_STRING;
947                 }
948
949                 retVal[0] = color;
950
951                 break;
952             default:
953                 return GTKScanner.TOKEN_STRING;
954         }
955         
956         return GTKScanner.TOKEN_NONE;
957     }
958
959     private static Color JavaDoc parseColorString(String JavaDoc str) {
960         if (str.charAt(0) == '#') {
961             str = str.substring(1);
962
963             int i = str.length();
964
965             if (i < 3 || i > 12 || (i % 3) != 0) {
966                 return null;
967             }
968
969             i /= 3;
970
971             int r;
972             int g;
973             int b;
974
975             try {
976                 r = Integer.parseInt(str.substring(0, i), 16);
977                 g = Integer.parseInt(str.substring(i, i * 2), 16);
978                 b = Integer.parseInt(str.substring(i * 2, i * 3), 16);
979             } catch (NumberFormatException JavaDoc nfe) {
980                 return null;
981             }
982
983             if (i == 4) {
984                 return new Color JavaDoc(r / 65535.0f, g / 65535.0f, b / 65535.0f);
985             } else if (i == 1) {
986                 return new Color JavaDoc(r / 15.0f, g / 15.0f, b / 15.0f);
987             } else if (i == 2) {
988                 return new Color JavaDoc(r, g, b);
989             } else {
990                 return new Color JavaDoc(r / 4095.0f, g / 4095.0f, b / 4095.0f);
991             }
992         } else {
993             return XColors.lookupColor(str);
994         }
995     }
996
997     private static int intColorVal(long col) {
998         int color = (int)Math.max(Math.min(col, 255), 0);
999         return color;
1000    }
1001
1002    private static int intColorVal(double col) {
1003        float color = (float)Math.max(Math.min(col, 1.0f), 0.0f);
1004        return (int)(color * 255);
1005    }
1006
1007    private int parseIconColorize(BlueprintEngineInfo engineInfo) throws IOException JavaDoc {
1008        int token;
1009
1010        token = scanner.getToken();
1011        if (token != SYM_ICON_COLORIZE) {
1012            return SYM_ICON_COLORIZE;
1013        }
1014
1015        token = scanner.getToken();
1016        if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
1017            return GTKScanner.TOKEN_EQUAL_SIGN;
1018        }
1019
1020        token = scanner.getToken();
1021        if (token == SYM_TRUE) {
1022            engineInfo.iconColorize = true;
1023        } else if (token == SYM_FALSE) {
1024            engineInfo.iconColorize = false;
1025        } else {
1026            return SYM_TRUE;
1027        }
1028
1029        return GTKScanner.TOKEN_NONE;
1030    }
1031
1032    /**
1033     * Helper method for parsing string list assignments such as the following:
1034     * = {"FOO", "BAR", "SJH"}
1035     * The scanner is expected to start returning tokens at the equal sign when
1036     * this method is invoked. It will parse the strings in the list into the
1037     * given <code>ArrayList</code> parameter.
1038     *
1039     * NOTE: The <code>Strings</code> that are added to the
1040     * <code>ArrayList</code> will have been <code>intern()</code>ed
1041     * first.
1042     *
1043     * @return <code>GTKScanner.TOKEN_NONE</code> if the parse was successful,
1044     * otherwise the token that was expected but not received.
1045     */

1046    private int parseStringList(ArrayList JavaDoc list) throws IOException JavaDoc {
1047        int token;
1048
1049        token = scanner.getToken();
1050        if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
1051            return GTKScanner.TOKEN_EQUAL_SIGN;
1052        }
1053
1054        token = scanner.getToken();
1055        if (token != GTKScanner.TOKEN_LEFT_CURLY) {
1056            return GTKScanner.TOKEN_LEFT_CURLY;
1057        }
1058        
1059        token = scanner.getToken();
1060        while (token == GTKScanner.TOKEN_STRING) {
1061            list.add(scanner.currValue.stringVal.intern());
1062            
1063            token = scanner.getToken();
1064            
1065            if (token == GTKScanner.TOKEN_RIGHT_CURLY) {
1066                continue;
1067            }
1068            
1069            if (token != GTKScanner.TOKEN_COMMA) {
1070                return GTKScanner.TOKEN_COMMA;
1071            }
1072            
1073            token = scanner.getToken();
1074        }
1075        
1076        if (token != GTKScanner.TOKEN_RIGHT_CURLY) {
1077            return GTKScanner.TOKEN_RIGHT_CURLY;
1078        }
1079        
1080        return GTKScanner.TOKEN_NONE;
1081    }
1082
1083    private int parseUseAsBkgMask(BlueprintStyle.Info info) throws IOException JavaDoc {
1084        int token;
1085
1086        token = scanner.getToken();
1087        if (token != SYM_USE_AS_BKG_MASK) {
1088            return SYM_USE_AS_BKG_MASK;
1089        }
1090
1091        token = scanner.getToken();
1092        if (token != GTKScanner.TOKEN_EQUAL_SIGN) {
1093            return GTKScanner.TOKEN_EQUAL_SIGN;
1094        }
1095
1096        token = scanner.getToken();
1097        switch(token) {
1098            case SYM_TRUE:
1099                info.useAsBkgMask = true;
1100                break;
1101            case SYM_FALSE:
1102                info.useAsBkgMask = false;
1103                break;
1104            default:
1105                return SYM_TRUE;
1106        }
1107        
1108        return GTKScanner.TOKEN_NONE;
1109    }
1110
1111}
1112
Popular Tags