001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.plaf.html;
006:
007: import java.awt.*;
008: import java.util.*;
009: import java.io.*;
010:
011: import javax.servlet.*;
012:
013: import com.javelin.swinglets.*;
014: import com.javelin.swinglets.plaf.*;
015: import com.javelin.swinglets.theme.*;
016:
017: /**
018: * HTMLSplitPaneUI defines a look and feel for default HTML.
019: *
020: * @author Robin Sharp
021: */
022:
023: public class HTMLSplitPaneUI extends HTMLContainerUI {
024: /**
025: * Render the UI on the PrintWriter
026: */
027: public void update(PrintWriter out, SComponent c) {
028: SContainer parent = c.getTopLevelAncestor();
029: paintSplitPane(out, c);
030: }
031:
032: /**
033: * Paint the split pane as a table.
034: */
035: public void paintSplitPane(PrintWriter out, SComponent c) {
036: if (!c.isVisible())
037: return;
038:
039: SSplitPane splitPane = (SSplitPane) c;
040:
041: out.print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0");
042:
043: if (splitPane.getSize() != null) {
044: if (splitPane.getSize().width > 0) {
045: out.print(" WIDTH=");
046: out.print(splitPane.getSize().width);
047: } else if (splitPane.getSize().width < 0) {
048: out.print(" WIDTH=");
049: out.print(1 - splitPane.getSize().width);
050: out.print("%");
051: }
052:
053: if (splitPane.getSize().height > 0) {
054: out.print(" HEIGHT=");
055: out.print(splitPane.getSize().height);
056: } else if (splitPane.getSize().height < 0) {
057: out.print(" HEIGHT=");
058: out.print(1 - splitPane.getSize().height);
059: out.print("%");
060: }
061: }
062:
063: if (!splitPane.isOpaque()) {
064: //Dont do anything
065: } else if (splitPane.getBackground() != null) {
066: out.print(" BGCOLOR=\"#"
067: + SColor.toHexString(splitPane.getBackground())
068: + "\"");
069: } else {
070: out.print(" BGCOLOR=\"#"
071: + SColor.toHexString(getTheme()
072: .getWindowBackground()) + "\"");
073: }
074:
075: out.println(" >");
076:
077: //Get the divider
078: if (theme == null || theme != getTheme()) {
079: theme = getTheme();
080:
081: horizontalDivider = theme.getIcon(STheme.HORIZONTAL_DIV);
082: verticalDivider = theme.getIcon(STheme.VERTICAL_DIV);
083: point = theme.getIcon(STheme.BACKGROUND_ICON);
084:
085: horizontalDivider
086: .setLookAndFeel(splitPane.getLookAndFeel());
087: verticalDivider.setLookAndFeel(splitPane.getLookAndFeel());
088: point.setLookAndFeel(splitPane.getLookAndFeel());
089: }
090:
091: if (splitPane.getOrientation() == SSplitPane.HORIZONTAL_SPLIT) {
092: out.print("<TR>");
093:
094: //TOP COMPONENT
095: out.print("<TD ");
096:
097: HTMLUtility.updateHorizontalAlignment(out, splitPane
098: .getTopComponent(), SConstants.CENTER);
099:
100: HTMLUtility.updateVerticalAlignment(out, splitPane
101: .getTopComponent(), SConstants.TOP);
102:
103: if (splitPane.getTopComponent() != null
104: && splitPane.getTopComponent().isOpaque()
105: && splitPane.getTopComponent().getBackground() != null) {
106: out.print(" BGCOLOR=\"#"
107: + SColor.toHexString(splitPane
108: .getTopComponent().getBackground())
109: + "\"");
110: }
111:
112: //Proportional width and height
113: out.print(" HEIGHT=\"");
114: out.print((splitPane.getDividerLocation() * 100)
115: - (splitPane.getDividerSize() == 0 ? 0 : 1));
116: out.print("%\" >");
117:
118: if (splitPane.getTopComponent() != null) {
119: splitPane.getTopComponent().paint(out);
120: }
121:
122: out.println("</TD>");
123:
124: //HORIZONTAL LINE
125: if (splitPane.getDividerSize() > 0) {
126: out.println("</TR><TR><TD HEIGHT=");
127: out.print(splitPane.getDividerSize());
128: out.print(" BACKGROUND=\"");
129: out.print(horizontalDivider.getUrl());
130: out.print("\">");
131: point.setSize(-100, splitPane.getDividerSize());
132: point.paint(out);
133: out.println("</TD>");
134: }
135:
136: out.print("</TR><TR>");
137:
138: //BOTTOM COMPONENT
139: out.print("<TD");
140:
141: HTMLUtility.updateHorizontalAlignment(out, splitPane
142: .getBottomComponent(), SConstants.CENTER);
143:
144: HTMLUtility.updateVerticalAlignment(out, splitPane
145: .getBottomComponent(), SConstants.TOP);
146:
147: if (splitPane.getBottomComponent() != null
148: && splitPane.getBottomComponent().isOpaque()
149: && splitPane.getBottomComponent().getBackground() != null) {
150: out.print(" BGCOLOR=\"#"
151: + SColor.toHexString(splitPane
152: .getBottomComponent().getBackground())
153: + "\"");
154: }
155:
156: //Proportional width and height
157: out.print(" HEIGHT=\"");
158: out.print((1 - splitPane.getDividerLocation()) * 100);
159: out.print("%\" >");
160:
161: if (splitPane.getBottomComponent() != null) {
162: splitPane.getBottomComponent().paint(out);
163: }
164: out.print("</TD></TR>");
165: } else {
166: out.print("<TR>");
167:
168: //LEFT COMPONENT
169: out.print("<TD ");
170:
171: HTMLUtility.updateHorizontalAlignment(out, splitPane
172: .getLeftComponent(), SConstants.LEFT);
173:
174: HTMLUtility.updateVerticalAlignment(out, splitPane
175: .getLeftComponent(), SConstants.TOP);
176:
177: if (splitPane.getLeftComponent() != null
178: && splitPane.getLeftComponent().isOpaque()
179: && splitPane.getLeftComponent().getBackground() != null) {
180: out.print(" BGCOLOR=\"#"
181: + SColor.toHexString(splitPane
182: .getLeftComponent().getBackground())
183: + "\"");
184: }
185:
186: //Proportional width and height
187: out.print(" WIDTH=\"");
188: out.print((splitPane.getDividerLocation() * 100)
189: - (splitPane.getDividerSize() == 0 ? 0 : 1));
190: out.print("%\" >");
191:
192: if (splitPane.getLeftComponent() != null) {
193: splitPane.getLeftComponent().paint(out);
194: }
195:
196: out.println("</TD>");
197:
198: //VERTICAL LINE
199: if (splitPane.getDividerSize() > 0) {
200: out.print("<TD WIDTH=");
201: out.print(splitPane.getDividerSize());
202: out.print(" BACKGROUND=\"");
203: out.print(verticalDivider.getUrl());
204: out.print("\" >");
205: point.setSize(splitPane.getDividerSize(), -100);
206: point.paint(out);
207:
208: out.print("</TD>");
209: }
210:
211: //RIGHT COMPONENT
212: out.print("<TD ");
213:
214: HTMLUtility.updateHorizontalAlignment(out, splitPane
215: .getRightComponent(), SConstants.LEFT);
216:
217: HTMLUtility.updateVerticalAlignment(out, splitPane
218: .getRightComponent(), SConstants.TOP);
219:
220: if (splitPane.getRightComponent() != null
221: && splitPane.getRightComponent().isOpaque()
222: && splitPane.getRightComponent().getBackground() != null) {
223: out.print(" BGCOLOR=\"#"
224: + SColor.toHexString(splitPane
225: .getRightComponent().getBackground())
226: + "\"");
227: }
228:
229: //Proportional width and height
230: out.print(" WIDTH=\"");
231: out
232: .print((int) ((1 - splitPane.getDividerLocation()) * 100));
233: out.print("%\" >");
234:
235: if (splitPane.getRightComponent() != null) {
236: splitPane.getRightComponent().paint(out);
237: }
238:
239: out.print("</TD>");
240:
241: out.println("</TR>");
242: }
243:
244: out.println("</TABLE>");
245: }
246:
247: protected String getDividerString(SSplitPane split) {
248: if (split.getDividerLocation() > 1.0) {
249: return "" + ((int) split.getDividerLocation()) + ",*";
250: }
251:
252: return "" + ((int) (split.getDividerLocation() * 100)) + "%,*%";
253: }
254:
255: protected STheme theme;
256: protected SIcon horizontalDivider;
257: protected SIcon verticalDivider;
258: protected SIcon point;
259:
260: }
|