KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > plaf > CompiereTheme


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.plaf;
15
16 import java.awt.Color JavaDoc;
17 import java.awt.Font JavaDoc;
18 import java.awt.SystemColor JavaDoc;
19 import java.io.FileInputStream JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import javax.swing.plaf.ColorUIResource JavaDoc;
24 import javax.swing.plaf.FontUIResource JavaDoc;
25 import javax.swing.plaf.metal.MetalTheme JavaDoc;
26
27 import org.compiere.util.Ini;
28
29 import sun.awt.AppContext;
30
31 /**
32  * Compiere User definable Theme (if used in Metal L&F).
33  * In other Environments, it provides UI extensions (e.g. Error Color)
34  *
35  * @author Jorg Janke
36  * @version $Id: CompiereTheme.java,v 1.11 2003/09/27 11:08:53 jjanke Exp $
37  */

38 public class CompiereTheme extends MetalTheme JavaDoc
39 {
40     /**
41      * Constructor - nop
42      */

43     public CompiereTheme()
44     {
45     } // CompiereTheme
46

47     /**
48      * Return Theme Name
49      * @return Theme Name
50      */

51     public String JavaDoc getName()
52     {
53         return NAME;
54     } // getName
55

56     public static final String JavaDoc NAME = "Compiere Theme";
57
58     /** Blue 51,51,102 */
59     protected static ColorUIResource JavaDoc primary0 = new ColorUIResource JavaDoc(51, 51, 102);
60     /** Blue 102, 102, 153 */
61     protected static ColorUIResource JavaDoc primary1;
62     /** Blue 153, 153, 204 */
63     protected static ColorUIResource JavaDoc primary2;
64     /** Blue 204, 204, 255 */
65     protected static ColorUIResource JavaDoc primary3;
66
67     /** Black */
68     protected final ColorUIResource JavaDoc secondary0 = new ColorUIResource JavaDoc(0, 0, 0);
69     /** Gray 102, 102, 102 */
70     protected static ColorUIResource JavaDoc secondary1;
71     /** Gray 153, 153, 153 */
72     protected static ColorUIResource JavaDoc secondary2;
73     /** Gray 204, 204, 204 */
74     protected static ColorUIResource JavaDoc secondary3;
75     /** White */
76     protected final ColorUIResource JavaDoc secondary4 = new ColorUIResource JavaDoc(255, 255, 255);
77
78     /** Black */
79     protected static ColorUIResource JavaDoc black;
80     /** White */
81     protected static ColorUIResource JavaDoc white;
82
83     /** Background for mandatory fields */
84     protected static ColorUIResource JavaDoc mandatory;
85     /** Background for fields in error */
86     protected static ColorUIResource JavaDoc error;
87     /** Background for inactive fields */
88     protected static ColorUIResource JavaDoc inactive;
89     /** Background for info fields */
90     protected static ColorUIResource JavaDoc info;
91
92     /** Foreground Text OK */
93     protected static ColorUIResource JavaDoc txt_ok;
94     /** Foreground Text Error */
95     protected static ColorUIResource JavaDoc txt_error;
96
97     /** Control font */
98     protected static FontUIResource JavaDoc controlFont;
99     /** System font */
100     protected static FontUIResource JavaDoc systemFont;
101     /** User font */
102     protected static FontUIResource JavaDoc userFont;
103     /** Small font */
104     protected static FontUIResource JavaDoc smallFont;
105     /** Window Title font */
106     protected static FontUIResource JavaDoc windowFont;
107     /** Menu font */
108     protected static FontUIResource JavaDoc menuFont;
109
110     /** Default Font */
111     public static final String JavaDoc FONT_DEFAULT = "Dialog";
112     /** Default Font Size */
113     public static final int FONT_SIZE = 12;
114
115     /**
116      * Set Defaults
117      */

118     private static void setDefault ()
119     {
120         /** Blue 102, 102, 153 */
121         primary1 = new ColorUIResource JavaDoc(102, 102, 153);
122         /** Blue 153, 153, 204 */
123         primary2 = new ColorUIResource JavaDoc(153, 153, 204);
124         /** Blue 204, 204, 255 */
125         primary3 = new ColorUIResource JavaDoc(204, 204, 255);
126         /** Gray 102, 102, 102 */
127         secondary1 = new ColorUIResource JavaDoc(102, 102, 102);
128         /** Gray 153, 153, 153 */
129         secondary2 = new ColorUIResource JavaDoc(153, 153, 153);
130         /** Gray 204, 204, 204 */
131         secondary3 = new ColorUIResource JavaDoc(204, 204, 204);
132
133         /** Black */
134         black = new ColorUIResource JavaDoc(Color.black);
135         /** White */
136         white = new ColorUIResource JavaDoc(Color.white);
137
138         /** Background for mandatory fields */
139         mandatory = new ColorUIResource JavaDoc(224, 224, 255); // blue-isch
140
/** Background for fields in error */
141         error = new ColorUIResource JavaDoc(255, 204, 204); // red-isch
142
/** Background for inactive fields */
143         inactive = new ColorUIResource JavaDoc(234, 234, 234); // light gray
144
/** Background for info fields */
145         info = new ColorUIResource JavaDoc(253, 237, 207); // light yellow
146

147         /** Foreground Text OK */
148         txt_ok = new ColorUIResource JavaDoc(51, 51, 102); // dark blue
149
/** Foreground Text Error */
150         txt_error = new ColorUIResource JavaDoc(204, 0, 0); // dark red
151

152         /** Control font */
153         controlFont = null;
154         _getControlTextFont();
155         /** System font */
156         systemFont = null;
157         _getSystemTextFont();
158         /** User font */
159         userFont = null;
160         _getUserTextFont();
161         /** Small font */
162         smallFont = null;
163         _getSubTextFont();
164         /** Window Title font */
165         windowFont = null;
166         _getWindowTitleFont();
167         /** Menu font */
168         menuFont = null;
169         _getMenuTextFont();
170     } // setDefault
171

172     /**
173      * Static Init
174      */

175     static
176     {
177         setDefault();
178     }
179
180     /**
181      * Set Theme to current Metal Theme and copy it
182      */

183     public static void setTheme ()
184     {
185         AppContext context = AppContext.getAppContext();
186         MetalTheme JavaDoc copyFrom = (MetalTheme JavaDoc)context.get("currentMetalTheme");
187         setTheme (copyFrom);
188     } // setTheme
189

190     /**
191      * Set Theme to current Metal Theme and copy it
192      * @param copyFrom
193      */

194     public static void setTheme (MetalTheme JavaDoc copyFrom)
195     {
196         if (copyFrom == null || copyFrom instanceof CompiereTheme)
197             return;
198         // May not be correct, if Themes overwrites default methods
199
primary1 = copyFrom.getPrimaryControlDarkShadow();
200         primary2 = copyFrom.getPrimaryControlShadow();
201         primary3 = copyFrom.getPrimaryControl();
202         secondary1 = copyFrom.getControlDarkShadow();
203         secondary2 = copyFrom.getControlShadow();
204         secondary3 = copyFrom.getControl();
205         CompierePanelUI.setDefaultBackground(new CompiereColor(secondary3, true));
206         white = copyFrom.getPrimaryControlHighlight();
207         black = copyFrom.getPrimaryControlInfo();
208         //
209
controlFont = copyFrom.getControlTextFont();
210         systemFont = copyFrom.getSystemTextFont();
211         userFont = copyFrom.getUserTextFont();
212         smallFont = copyFrom.getSubTextFont();
213         menuFont = copyFrom.getMenuTextFont();
214         windowFont = copyFrom.getWindowTitleFont();
215     } // setTheme
216

217
218     /*************************************************************************/
219
220     /**
221      * Get Primary 1 (blue in default Metal Theme)
222      * @return color
223      */

224     public ColorUIResource JavaDoc getPrimary1()
225     {
226         return ColorBlind.getDichromatColorUIResource(primary1);
227     }
228     public ColorUIResource JavaDoc getPrimary2()
229     {
230         return ColorBlind.getDichromatColorUIResource(primary2);
231     }
232     public ColorUIResource JavaDoc getPrimary3()
233     {
234         return ColorBlind.getDichromatColorUIResource(primary3);
235     }
236
237     /**
238      * Get Seconary 1 (gray in default Metal Theme)
239      * @return color
240      */

241     public ColorUIResource JavaDoc getSecondary0()
242     {
243         return ColorBlind.getDichromatColorUIResource(secondary0);
244     }
245     public ColorUIResource JavaDoc getSecondary1()
246     {
247         return ColorBlind.getDichromatColorUIResource(secondary1);
248     }
249     public ColorUIResource JavaDoc getSecondary2()
250     {
251         return ColorBlind.getDichromatColorUIResource(secondary2);
252     }
253     public ColorUIResource JavaDoc getSecondary3()
254     {
255         return ColorBlind.getDichromatColorUIResource(secondary3);
256     }
257     public ColorUIResource JavaDoc getSecondary4()
258     {
259         return ColorBlind.getDichromatColorUIResource(secondary4);
260     }
261
262     public ColorUIResource JavaDoc getBlack()
263     {
264         return ColorBlind.getDichromatColorUIResource(black);
265     }
266     public ColorUIResource JavaDoc getWhite()
267     {
268         return ColorBlind.getDichromatColorUIResource(white);
269     }
270
271     /**
272      * Control Font (plain)
273      * @return font
274      */

275     private static FontUIResource JavaDoc _getControlTextFont()
276     {
277         if (controlFont == null)
278         {
279             try
280             {
281                 controlFont = new FontUIResource JavaDoc(Font.getFont("swing.plaf.metal.controlFont",
282                     new Font JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
283             }
284             catch (Exception JavaDoc e)
285             {
286                 controlFont = new FontUIResource JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
287             }
288         }
289         return controlFont;
290     }
291     public FontUIResource JavaDoc getControlTextFont() {return _getControlTextFont();}
292
293     /**
294      * System Font
295      * @return font
296      */

297     private static FontUIResource JavaDoc _getSystemTextFont()
298     {
299         if (systemFont == null)
300         {
301             try
302             {
303                 systemFont = new FontUIResource JavaDoc(Font.getFont("swing.plaf.metal.systemFont",
304                     new Font JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
305             }
306             catch (Exception JavaDoc e)
307             {
308                 systemFont = new FontUIResource JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
309             }
310         }
311         return systemFont;
312     }
313     public FontUIResource JavaDoc getSystemTextFont() {return _getSystemTextFont();}
314
315     /**
316      * User Font
317      * @return font
318      */

319     private static FontUIResource JavaDoc _getUserTextFont()
320     {
321         if (userFont == null)
322         {
323             try
324             {
325                 userFont = new FontUIResource JavaDoc(Font.getFont("swing.plaf.metal.userFont",
326                     new Font JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
327             }
328             catch (Exception JavaDoc e)
329             {
330                 userFont = new FontUIResource JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
331             }
332         }
333         return userFont;
334     }
335     public FontUIResource JavaDoc getUserTextFont() {return _getUserTextFont();}
336
337     /**
338      * Menu
339      * @return font
340      */

341     private static FontUIResource JavaDoc _getMenuTextFont()
342     {
343         if (menuFont == null)
344         {
345             try
346             {
347                 menuFont = new FontUIResource JavaDoc(Font.getFont("swing.plaf.metal.menuFont",
348                     new Font JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
349             }
350             catch (Exception JavaDoc e)
351             {
352                 menuFont = new FontUIResource JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
353             }
354         }
355         return menuFont;
356     }
357     public FontUIResource JavaDoc getMenuTextFont() {return _getMenuTextFont();}
358
359     /**
360      * Window Title
361      * @return font
362      */

363     private static FontUIResource JavaDoc _getWindowTitleFont()
364     {
365         if (windowFont == null)
366         {
367             try
368             {
369                 windowFont = new FontUIResource JavaDoc(Font.getFont("swing.plaf.metal.windowFont",
370                     new Font JavaDoc(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2)));
371             }
372             catch (Exception JavaDoc e)
373             {
374                 windowFont = new FontUIResource JavaDoc(FONT_DEFAULT, Font.BOLD, FONT_SIZE+2);
375             }
376         }
377         return windowFont;
378     }
379     public FontUIResource JavaDoc getWindowTitleFont() {return _getWindowTitleFont();}
380
381     /**
382      * Sub Text
383      * @return font
384      */

385     private static FontUIResource JavaDoc _getSubTextFont()
386     {
387         if (smallFont == null)
388         {
389             try
390             {
391                 smallFont = new FontUIResource JavaDoc(Font.getFont("swing.plaf.metal.smallFont",
392                     new Font JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2)));
393             }
394             catch (Exception JavaDoc e)
395             {
396                 smallFont = new FontUIResource JavaDoc(FONT_DEFAULT, Font.PLAIN, FONT_SIZE-2);
397             }
398         }
399         return smallFont;
400     }
401     public FontUIResource JavaDoc getSubTextFont() {return _getSubTextFont();}
402
403     /*************************************************************************/
404
405     /**
406      * Store information as property file
407      * @param fileName
408      */

409     public static void save (String JavaDoc fileName)
410     {
411         Properties JavaDoc p = new Properties JavaDoc();
412         save (p);
413         //
414
try
415         {
416             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc (fileName);
417             p.store(fos, NAME);
418             fos.close();
419         }
420         catch (Exception JavaDoc e)
421         {
422             System.err.println("CompiereTheme.store - " + e.getMessage());
423         }
424     } // store
425

426     /**
427      * Load Data
428      * @param fileName
429      */

430     public static void load (String JavaDoc fileName)
431     {
432         Properties JavaDoc p = new Properties JavaDoc();
433         try
434         {
435             FileInputStream JavaDoc fis = new FileInputStream JavaDoc (fileName);
436             p.load(fis);
437             fis.close();
438         }
439         catch (Exception JavaDoc e)
440         {
441             System.err.println("CompiereTheme.load - " + e.getMessage());
442             return;
443         }
444         load (p);
445     } // load
446

447     // Static property info
448

449     private static final String JavaDoc P_Primary1 = "#ColorPrimary1";
450     private static final String JavaDoc P_Primary2 = "#ColorPrimary2";
451     private static final String JavaDoc P_Primary3 = "#ColorPrimary3";
452     private static final String JavaDoc P_Secondary1 = "#ColorSecondary1";
453     private static final String JavaDoc P_Secondary2 = "#ColorSecondary2";
454     private static final String JavaDoc P_Secondary3 = "#ColorSecondary3";
455     private static final String JavaDoc P_Black = "#ColorBlack";
456     private static final String JavaDoc P_White = "#ColorWhite";
457     private static final String JavaDoc P_Error = "#ColorError";
458     private static final String JavaDoc P_Info = "#ColorInfo";
459     private static final String JavaDoc P_Mandatory = "#ColorMandatory";
460     private static final String JavaDoc P_Inactive = "#ColorInactive";
461     private static final String JavaDoc P_Txt_OK = "#ColorTextOK";
462     private static final String JavaDoc P_Txt_Error = "#ColorTextError";
463     //
464
private static final String JavaDoc P_Control = "#FontControl";
465     private static final String JavaDoc P_System = "#FontSystem";
466     private static final String JavaDoc P_User = "#FontUser";
467     private static final String JavaDoc P_Small = "#FontSmall";
468     private static final String JavaDoc P_Window = "#FontWindow";
469     private static final String JavaDoc P_Menu = "#FontMenu";
470     //
471
protected static final String JavaDoc P_CompiereColor = "#CompiereColor";
472
473     /**
474      * Save information in Properties
475      * @param p
476      */

477     public static void save (Properties JavaDoc p)
478     {
479         p.setProperty(P_Primary1, getColorAsString(primary1));
480         p.setProperty(P_Primary2, getColorAsString(primary2));
481         p.setProperty(P_Primary3, getColorAsString(primary3));
482         p.setProperty(P_Secondary1, getColorAsString(secondary1));
483         p.setProperty(P_Secondary2, getColorAsString(secondary2));
484         p.setProperty(P_Secondary3, getColorAsString(secondary3));
485         p.setProperty(P_Error, getColorAsString(error));
486         p.setProperty(P_Info, getColorAsString(info));
487         p.setProperty(P_Mandatory, getColorAsString(mandatory));
488         p.setProperty(P_Inactive, getColorAsString(inactive));
489         p.setProperty(P_White, getColorAsString(white));
490         p.setProperty(P_Black, getColorAsString(black));
491         p.setProperty(P_Txt_OK, getColorAsString(txt_ok));
492         p.setProperty(P_Txt_Error, getColorAsString(txt_error));
493         //
494
p.setProperty(P_Control, ((Font JavaDoc)controlFont).toString());
495         p.setProperty(P_System, ((Font JavaDoc)systemFont).toString());
496         p.setProperty(P_User, ((Font JavaDoc)userFont).toString());
497         p.setProperty(P_Small, ((Font JavaDoc)smallFont).toString());
498         p.setProperty(P_Window, ((Font JavaDoc)windowFont).toString());
499         p.setProperty(P_Menu, ((Font JavaDoc)menuFont).toString());
500         //
501
p.setProperty(P_CompiereColor, CompiereColor.getDefaultBackground().toString());
502     } // save
503

504     /**
505      * Parses Color into String representation.
506      * Required as SystemColors and Alpha Colors have different formats
507      * @param c Color
508      * @return [r=102,g=102,b=153,a=255]
509      * @see #parseColor
510      */

511     public static String JavaDoc getColorAsString (Color JavaDoc c)
512     {
513         if (c == null)
514             c = SystemColor.control;
515         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("[r=").append(c.getRed())
516             .append(",g=").append(c.getGreen())
517             .append(",b=").append(c.getBlue())
518             .append(",a=").append(c.getAlpha())
519             .append("]");
520     // System.out.println(sb.toString());
521
return sb.toString();
522     } // getColorAsString
523

524     /**
525      * Load Properties from Ini
526      */

527     public static void load ()
528     {
529         load (Ini.getProperties());
530     } // load
531

532     /**
533      * Load information from properties
534      * @param p Properties
535      */

536     public static void load (Properties JavaDoc p)
537     {
538         primary1 = parseColor (p.getProperty(P_Primary1), primary1);
539         primary2 = parseColor (p.getProperty(P_Primary2), primary2);
540         primary3 = parseColor (p.getProperty(P_Primary3), primary3);
541         secondary1 = parseColor (p.getProperty(P_Secondary1), secondary1);
542         secondary2 = parseColor (p.getProperty(P_Secondary2), secondary2);
543         secondary3 = parseColor (p.getProperty(P_Secondary3), secondary3);
544         error = parseColor(p.getProperty(P_Error), error);
545         info = parseColor(p.getProperty(P_Info), info);
546         mandatory = parseColor(p.getProperty(P_Mandatory), mandatory);
547         inactive = parseColor(p.getProperty(P_Inactive), inactive);
548         white = parseColor(p.getProperty(P_White), white);
549         black = parseColor(p.getProperty(P_Black), black);
550         txt_ok = parseColor(p.getProperty(P_Txt_OK), txt_ok);
551         txt_error = parseColor(p.getProperty(P_Txt_Error), txt_error);
552         //
553
controlFont = parseFont(p.getProperty(P_Control), controlFont);
554         systemFont = parseFont(p.getProperty(P_System), systemFont);
555         userFont = parseFont(p.getProperty(P_User), userFont);
556         smallFont = parseFont(p.getProperty(P_Small), smallFont);
557         windowFont = parseFont(p.getProperty(P_Window), windowFont);
558         menuFont = parseFont(p.getProperty(P_Menu), menuFont);
559         //
560
CompiereColor.setDefaultBackground(CompiereColor.parse(p.getProperty(P_CompiereColor)));
561     } // load
562

563     /**
564      * Reset Info in Properties
565      * @param p Properties
566      */

567     public static void reset (Properties JavaDoc p)
568     {
569         p.remove (P_Primary1);
570         p.remove (P_Primary2);
571         p.remove (P_Primary3);
572         p.remove (P_Secondary1);
573         p.remove (P_Secondary2);
574         p.remove (P_Secondary3);
575         p.remove (P_Error);
576         p.remove (P_Info);
577         p.remove (P_Mandatory);
578         p.remove (P_Inactive);
579         p.remove (P_White);
580         p.remove (P_Black);
581         p.remove (P_Txt_OK);
582         p.remove (P_Txt_Error);
583         //
584
p.remove (P_Control);
585         p.remove (P_System);
586         p.remove (P_User);
587         p.remove (P_Small);
588         p.remove (P_Window);
589         p.remove (P_Menu);
590         // CompiereColor
591
p.remove(P_CompiereColor);
592
593         // Initialize
594
p.setProperty(Ini.P_UI_LOOK, CompiereLookAndFeel.NAME);
595         p.setProperty(Ini.P_UI_THEME, NAME);
596         //
597
setDefault();
598
599         // Background
600
// CompiereColor cc = new CompiereColor(SystemColor.control); // flat Windows 212-208-200
601
// CompiereColor cc = new CompiereColor(secondary3); // flat Metal 204-204-204
602
CompiereColor cc = new CompiereColor(secondary3, false);
603         CompiereColor.setDefaultBackground (cc);
604         //
605
save(p); // save properties
606
} // reset
607

608     /**
609      * Parse Color.
610      * <p>
611      * Color - [r=102,g=102,b=153,a=0]
612      *
613      * @param information string information to be parsed
614      * @param stdColor color used if info cannot parsed
615      * @return color
616      * @see #getColorAsString
617      */

618     protected static ColorUIResource JavaDoc parseColor (String JavaDoc information, ColorUIResource JavaDoc stdColor)
619     {
620         if (information == null || information.length() == 0)
621             return stdColor;
622     // System.out.print("ParseColor=" + info);
623
try
624         {
625             int r = Integer.parseInt(information.substring(information.indexOf("r=")+2, information.indexOf(",g=")));
626             int g = Integer.parseInt(information.substring(information.indexOf("g=")+2, information.indexOf(",b=")));
627             int b = 0;
628             int a = 255;
629             if (information.indexOf("a=") == -1)
630                 b = Integer.parseInt(information.substring(information.indexOf("b=")+2, information.indexOf("]")));
631             else
632             {
633                 b = Integer.parseInt(information.substring(information.indexOf("b=")+2, information.indexOf(",a=")));
634                 a = Integer.parseInt(information.substring(information.indexOf("a=")+2, information.indexOf("]")));
635             }
636             ColorUIResource JavaDoc retValue = new ColorUIResource JavaDoc(new Color JavaDoc(r, g, b, a));
637         // System.out.println(" - " + retValue.toString());
638
return retValue;
639         }
640         catch (Exception JavaDoc e)
641         {
642             System.err.println("ParseColor=" + information + " - cannot parse - " + e.toString());
643         }
644         return stdColor;
645     } // parseColor
646

647     /**
648      * Parse Font
649      * <p>
650      * javax.swing.plaf.FontUIResource[family=dialog.bold,name=Dialog,style=bold,size=12]
651      *
652      * @param information string information to be parsed
653      * @param stdFont font used if info cannot be parsed
654      * @return font
655      */

656     private static FontUIResource JavaDoc parseFont(String JavaDoc information, FontUIResource JavaDoc stdFont)
657     {
658         if (information == null)
659             return stdFont;
660     // System.out.print("ParseFont=" + info);
661
try
662         {
663             String JavaDoc name = information.substring(information.indexOf("name=")+5, information.indexOf(",style="));
664             String JavaDoc s = information.substring(information.indexOf("style=")+6, information.indexOf(",size="));
665             int style = Font.PLAIN;
666             if (s.equals("bold"))
667                 style = Font.BOLD;
668             else if (s.equals("italic"))
669                 style = Font.ITALIC;
670             else if (s.equals("bolditalic"))
671                 style = Font.BOLD | Font.ITALIC;
672             int size = Integer.parseInt(information.substring(information.indexOf(",size=")+6, information.lastIndexOf("]")));
673             FontUIResource JavaDoc retValue = new FontUIResource JavaDoc(name,style,size);
674         // System.out.println(" - " + retValue.toString());
675
return retValue;
676         }
677         catch (Exception JavaDoc e)
678         {
679             System.err.println("ParseFont=" + information + " - cannot parse - " + e.toString());
680         }
681         return stdFont;
682     } // parseFont
683

684 } // CompiereTheme
685
Popular Tags