01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.template;
14:
15: import org.wings.SFont;
16: import org.wings.SConstants;
17:
18: import java.util.StringTokenizer;
19:
20: /**
21: * Provides util methods for {@link org.wings.STemplateLayout} related implementation.
22: *
23: * @author <a href="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
24: */
25: public class TemplateUtil {
26:
27: private TemplateUtil() {
28: }
29:
30: /**
31: * Parses a font description in the format of <code>Arial,B,14</code>.
32: * @param value A free text representation of a font in the format of <code>Arial,B,14</code>.
33: * @return according SFont instance. Defaults to plain 12.
34: */
35: public static SFont parseFont(String value) {
36: StringTokenizer s = new StringTokenizer(value, ",");
37: String fontName = s.nextToken();
38: String tmpFontType = s.nextToken().toUpperCase().trim();
39: int fontType = SFont.PLAIN;
40: if (tmpFontType.startsWith("B"))
41: fontType = SFont.BOLD;
42: else if (tmpFontType.startsWith("I"))
43: fontType = SFont.ITALIC;
44:
45: int fontSize = 12;
46: try {
47: fontSize = Integer.parseInt(s.nextToken());
48: } catch (Exception e) {
49: }
50:
51: return new SFont(fontName, fontType, fontSize);
52: }
53:
54: /**
55: * Parses a free text string representation for alignments and returns
56: * the according value.
57: * @param alignmentValue A String like "Top" or "Center"
58: * @return Alignment constant value or {@link SConstants#NO_ALIGN}
59: */
60: public static int parseAlignment(String alignmentValue) {
61: if ("TOP".equalsIgnoreCase(alignmentValue))
62: return SConstants.TOP_ALIGN;
63: else if ("CENTER".equalsIgnoreCase(alignmentValue)
64: || "MIDDLE".equalsIgnoreCase(alignmentValue))
65: return SConstants.CENTER_ALIGN;
66: else if ("BOTTOM".equalsIgnoreCase(alignmentValue))
67: return SConstants.BOTTOM_ALIGN;
68: else if ("LEFT".equalsIgnoreCase(alignmentValue))
69: return SConstants.LEFT_ALIGN;
70: else if ("RIGHT".equalsIgnoreCase(alignmentValue))
71: return SConstants.RIGHT_ALIGN;
72: else
73: return SConstants.NO_ALIGN;
74: }
75:
76: }
|