KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > IconTextCompound


1 /*
2  * $Id: IconTextCompound.java,v 1.18 2005/05/27 09:40:10 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css;
15
16 import org.wings.SComponent;
17 import org.wings.SConstants;
18 import org.wings.SDimension;
19 import org.wings.io.Device;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import java.io.IOException JavaDoc;
24
25 /**
26  * @author hengels
27  * @version $Revision: 1.18 $
28  */

29 public abstract class IconTextCompound {
30     private final static transient Log log = LogFactory.getLog(IconTextCompound.class);
31     
32     public void writeCompound(Device device, SComponent component, int horizontal, int vertical) throws IOException JavaDoc {
33         if (horizontal == SConstants.NO_ALIGN)
34             horizontal = SConstants.RIGHT;
35         if (vertical == SConstants.NO_ALIGN)
36             vertical = SConstants.CENTER;
37         boolean order = vertical == SConstants.TOP || (vertical == SConstants.CENTER && horizontal == SConstants.LEFT);
38
39
40         device.print("<table class=\"SLayout\"");
41         SDimension prefSize = component.getPreferredSize();
42         if (prefSize != null && (prefSize.getWidth() != null || prefSize.getHeight() != null)) {
43             device.print(" style=\"width:100%;height:100%\"");
44         }
45         device.print(">");
46
47         if (vertical == SConstants.TOP && horizontal == SConstants.LEFT ||
48                 vertical == SConstants.BOTTOM && horizontal == SConstants.RIGHT) {
49             device.print("<tr><td align=\"left\" valign=\"top\" class=\"SLayout\">");
50             first(device, order);
51             device.print("</td><td class=\"SLayout\"></td></tr><tr><td class=\"SLayout\"></td><td align=\"right\" valign=\"bottom\" class=\"SLayout\">");
52             last(device, order);
53             device.print("</td></tr>");
54         } else if (vertical == SConstants.TOP && horizontal == SConstants.RIGHT ||
55                 vertical == SConstants.BOTTOM && horizontal == SConstants.LEFT) {
56             device.print("<tr><td class=\"SLayout\"></td><td align=\"right\" valign=\"top\" class=\"SLayout\">");
57             first(device, order);
58             device.print("</td></tr><tr><td align=\"left\" valign=\"bottom\" class=\"SLayout\">");
59             last(device, order);
60             device.print("</td><td class=\"SLayout\"></td></tr>");
61         } else if (vertical == SConstants.TOP && horizontal == SConstants.CENTER ||
62                 vertical == SConstants.BOTTOM && horizontal == SConstants.CENTER) {
63             device.print("<tr><td align=\"center\" valign=\"top\" class=\"SLayout\">");
64             first(device, order);
65             device.print("</td></tr><tr><td align=\"center\" valign=\"bottom\" class=\"SLayout\">");
66             last(device, order);
67             device.print("</td></tr>");
68         } else if (vertical == SConstants.CENTER && horizontal == SConstants.LEFT ||
69                 vertical == SConstants.CENTER && horizontal == SConstants.RIGHT) {
70             device.print("<tr><td align=\"left\" class=\"SLayout\">");
71             first(device, order);
72             device.print("</td><td align=\"right\" class=\"SLayout\">");
73             last(device, order);
74             device.print("</td></tr>");
75         } else {
76             log.warn("horizontal = " + horizontal);
77             log.warn("vertical = " + vertical);
78         }
79         device.print("</table>");
80     }
81
82     private void first(Device d, boolean order) throws IOException JavaDoc {
83         if (order)
84             text(d);
85         else
86             icon(d);
87     }
88
89     private void last(Device d, boolean order) throws IOException JavaDoc {
90         if (!order)
91             text(d);
92         else
93             icon(d);
94     }
95
96     protected abstract void text(Device d) throws IOException JavaDoc;
97
98     protected abstract void icon(Device d) throws IOException JavaDoc;
99 }
100
Popular Tags