Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/mvsteenb/javauitransformer/xmltransformer/util/FontUtil.java


1   package com.mvsteenb.javauitransformer.xmltransformer.util;
2   
3   import java.awt.*;
4   
5   /**
6    * com.mvsteenb.javauitransformer.xmltransformer.util
7    *
8    * <p><b>Description</b></p>
9    *
10   *
11   *
12   * <p><b>Free Software</b></p>
13   *
14   * <p>
15   *   Copyright (C) 2003 Mario Van Steenberghe
16   * </p>
17   *
18   * <p>
19   *   <small>
20   *     This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
21   *     General Public License as published by the Free Software Foundation; either version 2.1 of the License, or
22   *     (at your option) any later version. This library is distributed in the hope that it will be useful,
23   *     but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
24   *     PURPOSE.  See the GNU Lesser General Public License for more details. You should have received a copy of the
25   *     GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc.,
26   *     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
27   *   </small>
28   * </p>
29   *
30   * <p>
31   *   <small>
32   *     Please contact me at mario.vansteenberghe@pandora.be for more information.
33   *   </small>
34   * </p>
35   *
36   * <p><b>Revision History</b></p>
37   *
38   * <p>
39   *   Aug 24, 2003 : mvsteenb : Initial Revision
40   * </p>
41   *
42   */
43  
44  public class FontUtil {
45  
46  
47    /**
48     * Creates font from given string representation. The string should be of format 'font, type, size'
49     *
50     * for example : toFont("helvetica, 0, 14");
51     */
52  
53    public static Font toFont(String fontString) throws InvalidFontStringException {
54  
55      String values [] = new String [3];
56  
57      int i = fontString.indexOf(",");
58      values[0] = fontString.substring(0, i);
59      int i2 = fontString.indexOf(",", i);
60      values[1] = fontString.substring(i, i2);
61      values[2] = fontString.substring(i2);
62  
63      //String values [] = fontString.split(",");
64  
65      if (values.length < 3) {
66        throw new InvalidFontStringException("Could not parse font string : " + fontString + ". Please make sure the font string is of format : 'font, type, string' !");
67      }
68  
69      try {
70        return new Font(values[0].trim(), Integer.parseInt(values[1].trim()), Integer.parseInt(values[2].trim()));
71      }
72      catch (NumberFormatException e) {
73        throw new InvalidFontStringException("Could not parse font string : " + fontString + ". Please make sure the font string is of format : 'font, type, string' : " + e.getMessage() );
74      }
75  
76    }
77  
78  }