01: // (c) copyright 2006 by eXXcellent solutions, Ulm. Author: bschmid
02:
03: package org.wings.plaf.css;
04:
05: import org.wings.io.Device;
06: import org.wings.SComponent;
07: import org.wings.border.*;
08: import org.wings.style.*;
09:
10: import java.io.IOException;
11:
12: /** This is not a 'real' CG class but a class collection rendering code for variois borders. */
13: public class TitleBorderCG extends BorderCG {
14:
15: public void writeComponentBorderPrefix(final Device device,
16: final SComponent component) throws IOException {
17: if (component != null
18: && component.getBorder() instanceof STitledBorder) {
19: STitledBorder titledBorder = (STitledBorder) component
20: .getBorder();
21: device.print("<fieldset ");
22: Utils.optAttribute(device, "id", component.getName()); /* Gives the Fieldset an id to get update working */
23:
24: if (titledBorder.getBorder() != null
25: && titledBorder.getBorder().getAttributes() != null) {
26: Utils.optAttribute(device, "style", titledBorder
27: .getBorder().getAttributes().toString());
28: }
29:
30: device.print("><legend ");
31: switch (titledBorder.getTitleJustification()) {
32: case STitledBorder.DEFAULT_JUSTIFICATION:
33: break;
34: case STitledBorder.LEFT:
35: break;
36: case STitledBorder.CENTER:
37: device.print(" align=\"center\" ");
38: break;
39: case STitledBorder.RIGHT:
40: device.print(" align=\"right\" ");
41: break;
42: }
43:
44: Utils.optAttribute(device, "style",
45: getLegendAttributes(titledBorder)); /* Write Legend Specifiec styles */
46: device.print(">");
47: Utils.quote(device, ((STitledBorder) component.getBorder())
48: .getTitle(), false, false, false);
49: device.print("</legend>");
50: }
51: }
52:
53: public void writeComponentBorderSufix(final Device device,
54: final SComponent component) throws IOException {
55: if (component != null
56: && component.getBorder() instanceof STitledBorder) {
57: device.print("</fieldset>");
58: }
59: }
60:
61: /**
62: * getLegendAttributes
63: * generates css Atrivbutes for the Legend Property
64: *
65: * @param border with the Toitled Border Info
66: **/
67:
68: private static CSSAttributeSet getLegendAttributes(
69: STitledBorder border) {
70: CSSAttributeSet attributes = new CSSAttributeSet();
71:
72: // switch (border.getTitleJustification()) { /* Position of the Text */
73: // case STitledBorder.DEFAULT_JUSTIFICATION:
74: // break;
75: // case STitledBorder.LEFT:
76: // break;
77: // case STitledBorder.CENTER:
78: // attributes.put(CSSProperty.TEXT_ALIGN,"center");
79: // break;
80: // case STitledBorder.RIGHT:
81: // attributes.put(CSSProperty.TEXT_ALIGN, "right");
82: // break;
83: // }
84: if (border.getTitleFont() != null) { /* Do we have some font information */
85: attributes.putAll(CSSStyleSheet.getAttributes(border
86: .getTitleFont()));
87: }
88:
89: if (border.getTitleColor() != null) { /* Are there any color requests */
90: attributes.put(CSSProperty.COLOR, CSSStyleSheet
91: .getAttribute(border.getTitleColor()));
92: }
93:
94: return attributes;
95: }
96: }
|