01: // (c) copyright 2006 by eXXcellent solutions, Ulm. Author: bschmid
02:
03: package org.wings.plaf.css;
04:
05: import org.wings.SComponent;
06: import org.wings.border.SBorder;
07: import org.wings.io.Device;
08: import org.wings.plaf.css.Utils;
09: import org.wings.util.SStringBuilder;
10:
11: import java.io.IOException;
12: import java.awt.*;
13:
14: /**
15: * This class collect various rendering workaround methods needed to fix issues with the Microsoft Internet Explorer.
16: * It is primarily kept as separate utility class for <b>documentational and reference</b> purpose!
17: * <p>
18: * The methods call here should extensively document what they do and why to be maintainable.
19: *
20: * @author Benjamin Schmid <B.Schmid@exxcellent.de>
21: */
22: public final class PaddingVoodoo {
23: private PaddingVoodoo() {
24: }
25:
26: //
27: // MSIE TABLE Padding Voodooo section --------------------------------------------------------------------------------------
28: //
29:
30: /**
31: * @param component The component to inspect
32: * @return <code>true</code> if the componentn has any padding insets requiring workaround
33: */
34: public static boolean hasPaddingInsets(final SComponent component) {
35: if (component == null || component.getBorder() == null)
36: return false;
37: final Insets insets = component.getBorder().getInsets();
38: return insets != null
39: && (insets.top > 0 || insets.left > 0
40: || insets.right > 0 || insets.bottom > 0);
41: }
42:
43: /**
44: * Utility method to add selected border's insets to the <code>targetInsets</code>.
45: * @param border border containing insets
46: * @param targetInsets Target inset to modify
47: * @param firstRow if <code>true</code>, add top to top
48: * @param firstCol if <code>true</code>, add left to left
49: * @param lastCol if <code>true</code>, add right to right
50: * @param lastRow if <code>true</code>, add bottom to bottom
51: */
52: public static void doBorderPaddingsWorkaround(final SBorder border,
53: final Insets targetInsets, boolean firstRow,
54: boolean firstCol, boolean lastCol, boolean lastRow) {
55: if (border != null && border.getInsets() != null) {
56: final Insets paddingInset = border.getInsets();
57: if (firstRow)
58: targetInsets.top += paddingInset.top;
59: if (firstCol)
60: targetInsets.left += paddingInset.left;
61: if (lastCol)
62: targetInsets.right += paddingInset.right;
63: if (lastRow)
64: targetInsets.bottom += paddingInset.bottom;
65: }
66: }
67:
68: /**
69: * MSIE does not support PADDING on table elements.
70: * For borders we re-render their insets (which are paddings) on the inner TD elements.
71: * <p>
72: * Call this method after <code><TD</code> and before <code>></code>
73: * @param d target device
74: * @param component source component
75: */
76: public static void doSimpleTablePaddingWorkaround(final Device d,
77: final SComponent component) throws IOException {
78: if (component == null)
79: return;
80: if (component.getBorder() != null
81: && Utils.hasInsets(component.getBorder().getInsets())) {
82: final SStringBuilder stringBuilder = new SStringBuilder();
83: Utils.createInlineStylesForInsets(stringBuilder, component
84: .getBorder().getInsets());
85: Utils.optAttribute(d, "style", stringBuilder);
86: }
87: }
88:
89: //
90: // MSIE ????????????????? section --------------------------------------------------------------------------------------
91: //
92:
93: }
|