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.awt.event.*;
009: import java.util.*;
010: import java.io.*;
011:
012: import com.javelin.swinglets.*;
013: import com.javelin.swinglets.plaf.*;
014: import com.javelin.swinglets.theme.*;
015:
016: /**
017: * HTMLFrameUI defines a look and feel for default HTML.
018: *
019: *
020: *
021: *
022: * @author Robin Sharp
023: */
024:
025: public class HTMLFrameUI extends HTMLContainerUI implements SFrameUI {
026: public final static String HTML_TIMER = "HTML_TIMER";
027:
028: public final static String HTML_AUTHOR = "HTML_AUTHOR";
029: public final static String HTML_DESCRIPTION = "HTML_DESCRIPTION";
030:
031: public final static String HTML_LINK_COLOR = "HTML_LINK_COLOR";
032: public final static String HTML_ACTIVE_LINK_COLOR = "HTML_ACTIVE_LINK_COLOR";
033: public final static String HTML_BACKGROUND_ICON = "HTML_BACKGROUND_ICON";
034:
035: //public final static String HTML_FRAME = "HTML_FRAME";
036: //public final static String HTML_PARENT = "HTML_PARENT";
037:
038: /**
039: * Render the UI on the PrintWriter.
040: * This outputs the open HTML, HEAD and open BODY tags.
041: */
042: public void updateHeader(PrintWriter out, SComponent c) {
043: if (!c.isVisible())
044: return;
045:
046: SFrame frame = (SFrame) c;
047:
048: out.println("<HTML>");
049: out.print("<HEAD> <!--");
050: out.print(c.getLookAndFeel().getName());
051: out.println(" RENDERER -->");
052: out
053: .println("<META NAME=\"GENERATOR\" CONTENT=\"Javelin Software\">");
054:
055: out.println(" <meta http-equiv=\"Expire\" content=\"now\"> ");
056: out
057: .println(" <meta http-equiv=\"pragma\" content=\"no-cache\"> ");
058:
059: STimer timer = (STimer) frame.getClientProperty(HTML_TIMER);
060: if (timer != null) {
061: out.print("<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"");
062: out.print(timer.getMillis() / 1000);
063: out.print("; URL=");
064: out.print("timer.getLink().getUrl();");
065: out.println("\">");
066: }
067:
068: if (frame.getClientProperty(HTML_DESCRIPTION) != null)
069: out
070: .println("<META NAME=\"Description\" CONTENT=\""
071: + frame.getClientProperty(HTML_DESCRIPTION)
072: + "\">");
073: if (frame.getClientProperty(HTML_AUTHOR) != null)
074: out.println("<META NAME=\"Author\" CONTENT=\""
075: + frame.getClientProperty(HTML_AUTHOR) + "\">");
076: if (frame.getTitle() != null)
077: out.println("<TITLE>" + frame.getTitle() + "</TITLE>");
078:
079: //Add the script into the web page
080: updateScript(out, c);
081:
082: out.println("</HEAD>");
083:
084: if (frame.getMenuBar() != null) {
085: frame.getMenuBar().paintHeader(out);
086: }
087:
088: super .updateHeader(out, c);
089: }
090:
091: /**
092: * Update the container header.
093: */
094: public void updateComponentHeader(PrintWriter out, SComponent c) {
095: if (!c.isVisible())
096: return;
097:
098: SFrame frame = (SFrame) c;
099:
100: out.print("<BODY ");
101:
102: //Set The Style Sheet
103: Object cssClass = c.getClientProperty(CSS_CLASS);
104: if (cssClass != null) {
105: out.print(" class=\"");
106: out.print(cssClass);
107: }
108:
109: //Set the default text color
110: if (frame.getForeground() != null) {
111: out.print(" TEXT=\"#"
112: + SColor.toHexString(frame.getForeground()) + "\"");
113: } else {
114: out.print(" TEXT=\"#"
115: + SColor.toHexString(getTheme()
116: .getSystemTextColor()) + "\"");
117: }
118:
119: //Set the default background
120: if (frame.getBackground() != null) {
121: out.print(" BGCOLOR=\"#"
122: + SColor.toHexString(frame.getBackground()) + "\"");
123: } else {
124: out.print(" BGCOLOR=\"#"
125: + SColor.toHexString(getTheme().getDesktopColor())
126: + "\"");
127: }
128:
129: //Set the link color
130: if (frame.getClientProperty(HTML_LINK_COLOR) != null) {
131: out
132: .print(" LINK=\"#"
133: + SColor
134: .toHexString((SColor) frame
135: .getClientProperty(HTML_LINK_COLOR))
136: + "\"");
137: } else {
138: out.print(" LINK=\"#"
139: + SColor.toHexString(getTheme()
140: .getAcceleratorForeground()) + "\"");
141: }
142:
143: //Set the Active link color
144: if (frame.getClientProperty(HTML_ACTIVE_LINK_COLOR) != null) {
145: out.print(" VLINK=\"#"
146: + SColor.toHexString((SColor) frame
147: .getClientProperty(HTML_ACTIVE_LINK_COLOR))
148: + "\"");
149: } else {
150: out
151: .print(" VLINK=\"#"
152: + SColor
153: .toHexString(getTheme()
154: .getAcceleratorSelectedForeground())
155: + "\"");
156: }
157:
158: if (frame.getClientProperty(HTML_BACKGROUND_ICON) != null) {
159: out.print(" BACKGROUND=\""
160: + ((SIcon) frame
161: .getClientProperty(HTML_BACKGROUND_ICON))
162: .getUrl() + "\"");
163: }
164:
165: updateEvent(out, c);
166:
167: out.println(">");
168: }
169:
170: /**
171: * Render the UI on the Output
172: */
173: public void update(PrintWriter out, SComponent c) {
174: if (!c.isVisible())
175: return;
176:
177: SFrame frame = (SFrame) c;
178:
179: if (frame.getMenuBar() != null) {
180: out
181: .print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100% >");
182:
183: if (frame.getMenuBar().getMenuPlacement() == SConstants.LEFT) {
184: out.print("<TR><TD VALIGN=TOP WIDTH=1% >");
185: frame.getMenuBar().paint(out);
186: out.print("</TD><TD VALIGN=TOP>");
187: super .update(out, c);
188: out.print("</TD></TR>");
189: } else if (frame.getMenuBar().getMenuPlacement() == SConstants.RIGHT) {
190: out.print("<TR><TD VALIGN=TOP WIDTH=1% >");
191: super .update(out, c);
192: out.print("</TD><TD VALIGN=TOP>");
193: frame.getMenuBar().paint(out);
194: out.print("</TD></TR>");
195: } else if (frame.getMenuBar().getMenuPlacement() == SConstants.TOP) {
196: out.print("<TR><TD ALIGN=LEFT>");
197: frame.getMenuBar().paint(out);
198: out.print("</TD></TR><TR><TD ALIGN=LEFT>");
199: super .update(out, c);
200: out.print("</TD></TR>");
201: } else if (frame.getMenuBar().getMenuPlacement() == SConstants.BOTTOM) {
202: out.print("<TR><TD ALIGN=LEFT>");
203: super .update(out, c);
204: out.print("</TD></TR><TR><TD ALIGN=LEFT>");
205: frame.getMenuBar().paint(out);
206: out.print("</TD></TR>");
207: }
208:
209: out.print("</TABLE>");
210: } else {
211: super .update(out, c);
212: }
213:
214: }
215:
216: /**
217: * Render the UI on the PrintWriter on the body.This outputs the close body and
218: * close HTML tags.
219: */
220: public void updateComponentFooter(PrintWriter out, SComponent c) {
221: out.println("</BODY>");
222:
223: out.println("</HTML>");
224: }
225:
226: }
|