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 com.javelin.swinglets.*;
012: import com.javelin.swinglets.plaf.*;
013: import com.javelin.swinglets.theme.*;
014:
015: /**
016: * HTMLInternalFrameUI defines a look and feel for default HTML.
017: *
018: * @author Robin Sharp
019: */
020:
021: public class HTMLInternalFrameUI extends HTMLContainerUI {
022: /**
023: * Render the UI on the PrintWriter
024: */
025: public void updateComponentHeader(PrintWriter out, SComponent c) {
026: if (!c.isVisible())
027: return;
028:
029: SInternalFrame internalFrame = (SInternalFrame) c;
030:
031: if (theme == null
032: || theme != internalFrame.getSwingletManager()
033: .getTheme()) {
034: theme = internalFrame.getSwingletManager().getTheme();
035: icon = theme.getIcon(STheme.FRAME_ICON);
036: desktop = theme.getIcon(STheme.FRAME_DESKTOP);
037: desktop.setToolTipText(internalFrame.getTitle());
038: //desktop.setSize( 32, 32 );
039: min = theme.getIcon(STheme.FRAME_MIN);
040: min.setToolTipText("Minimize");
041: max = theme.getIcon(STheme.FRAME_MAX);
042: max.setToolTipText("Maximize");
043: restore = theme.getIcon(STheme.FRAME_RESTORE);
044: restore.setToolTipText("Restore");
045: close = theme.getIcon(STheme.FRAME_CLOSE);
046: close.setToolTipText("Close");
047: bar = theme.getIcon(STheme.FRAME_BAR);
048:
049: point = theme.getIcon(STheme.BACKGROUND_ICON);
050: point.setSize(-100, 20);
051:
052: icon.setLookAndFeel(internalFrame.getLookAndFeel());
053: desktop.setLookAndFeel(internalFrame.getLookAndFeel());
054: min.setLookAndFeel(internalFrame.getLookAndFeel());
055: max.setLookAndFeel(internalFrame.getLookAndFeel());
056: restore.setLookAndFeel(internalFrame.getLookAndFeel());
057: close.setLookAndFeel(internalFrame.getLookAndFeel());
058: point.setLookAndFeel(internalFrame.getLookAndFeel());
059:
060: }
061:
062: if (!internalFrame.isIconized()) {
063: updateOpenedComponentHeader(out, internalFrame);
064: }
065: }
066:
067: protected void updateOpenedComponentHeader(PrintWriter out,
068: SInternalFrame internalFrame) {
069: out.print("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0");
070:
071: if (internalFrame.isMaximized()) {
072: out.print(" WIDTH=\"100%\" HEIGHT=\"100%\" ");
073: } else if (internalFrame.getSize() != null) {
074: if (internalFrame.getSize().width > 0) {
075: out.print(" WIDTH=\"");
076: out.print(internalFrame.getSize().width);
077: out.print("\"");
078: } else if (internalFrame.getSize().width < 0) {
079: out.print(" WIDTH=\"");
080: out.print((0 - internalFrame.getSize().width));
081: out.print("%\"");
082: }
083:
084: if (internalFrame.getSize().height > 0) {
085: out.print(" HEIGHT=\"");
086: out.print(internalFrame.getSize().height);
087: out.print("\"");
088: } else if (internalFrame.getSize().width < 0) {
089: out.print(" HEIGHT=\"");
090: out.print((0 - internalFrame.getSize().height));
091: out.print("%\"");
092: }
093: } else {
094: out.print(" WIDTH=\"1\" HEIGHT=\"1\" ");
095: }
096:
097: out.println(" >");
098:
099: //HEADER
100: out.print("<TR><TD>");
101:
102: out
103: .print("<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\" ");
104: out.print(" BGCOLOR=\"#");
105: out.print(SColor.toHexString(theme.getWindowTitleBackground()));
106: out.print("\" >");
107:
108: out.print("<TR>");
109:
110: out.println("<TD>");
111: icon.paint(out);
112: out.println("</TD>");
113:
114: out.print("<TD NOWRAP>");
115:
116: HTMLUtility.updateText(out, internalFrame.getTitle(), theme
117: .getWindowTitleFont(),
118: theme.getWindowTitleForeground(), internalFrame
119: .getHorizontalAlignment());
120:
121: out.println("</TD>");
122:
123: //Paint drag area
124: out.print("<TD HEIGHT=\"1\" WIDTH=\"100%\" BACKGROUND=\"");
125: out.print(bar.getUrl());
126: out.print("\" > ");
127: //point.paint( out );
128: out.println("</TD>");
129:
130: if (internalFrame.isIconizable()) {
131: out.print("<TD >");
132: updateIcon(out, internalFrame, min);
133: out.print("</TD>");
134: }
135:
136: if (internalFrame.isMaximizable()) {
137: out.print("<TD>");
138: if (internalFrame.isMaximized()) {
139: updateIcon(out, internalFrame, restore);
140: } else {
141: updateIcon(out, internalFrame, max);
142: }
143: out.print("</TD>");
144: }
145:
146: if (internalFrame.isCloseable()) {
147: out.print("<TD>");
148:
149: updateIcon(out, internalFrame, close);
150: out.print("</TD>");
151: }
152:
153: out.print("</TR>");
154: out.println("</TABLE>");
155:
156: out.print("</TD></TR>");
157:
158: //Render the contents of the Frame
159: out.print("<TR><TD");
160:
161: if (internalFrame.getBackground() != null) {
162: out.print(" BGCOLOR=\"#"
163: + SColor.toHexString(internalFrame.getBackground())
164: + "\"");
165: } else {
166: out.print(" BGCOLOR=\"#"
167: + SColor.toHexString(getTheme()
168: .getWindowBackground()) + "\"");
169: }
170:
171: out.print(" >");
172: }
173:
174: public void update(PrintWriter out, SComponent c) {
175: if (!c.isVisible())
176: return;
177:
178: SInternalFrame internalFrame = (SInternalFrame) c;
179:
180: if (internalFrame.isIconized()) {
181: updateClosed(out, internalFrame);
182: } else {
183: updateOpened(out, internalFrame);
184: }
185: }
186:
187: protected void updateClosed(PrintWriter out,
188: SInternalFrame internalFrame) {
189: out.print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 >");
190: out.print("<TR><TD>");
191: updateIcon(out, internalFrame, desktop);
192: out.print("</TD></TR><TR><TD>");
193:
194: HTMLUtility.updateText(out,
195: internalFrame.getDesktopTitle() != null ? internalFrame
196: .getDesktopTitle() : internalFrame.getTitle(),
197: theme.getControlTextFont(),
198: theme.getControlTextColor(), internalFrame
199: .getHorizontalAlignment());
200:
201: out.println("</TD></TR></TABLE>");
202:
203: }
204:
205: protected void updateOpened(PrintWriter out,
206: SInternalFrame internalFrame) {
207: updateContents(out, internalFrame);
208: }
209:
210: /**
211: * Render the UI on the PrintWriter
212: */
213: public void updateComponentFooter(PrintWriter out, SComponent c) {
214: if (!c.isVisible())
215: return;
216:
217: SInternalFrame internalFrame = (SInternalFrame) c;
218:
219: if (!internalFrame.isIconized()) {
220: updateOpenedContainerFooter(out, internalFrame);
221: }
222: }
223:
224: /**
225: * Render the UI on the PrintWriter
226: */
227: public void updateOpenedContainerFooter(PrintWriter out,
228: SInternalFrame internalFrame) {
229: out.println("</TD></TR></TABLE>");
230: }
231:
232: public void updateIcon(PrintWriter out,
233: SInternalFrame internalFrame, SIcon icon) {
234: out.print("<A HREF=\"");
235: out.print(internalFrame.getComponentUrl());
236: out.print("&_BUTTON=");
237: if (icon == min)
238: out.print(STheme.FRAME_MIN);
239: else if (icon == max)
240: out.print(STheme.FRAME_MAX);
241: else if (icon == close)
242: out.print(STheme.FRAME_CLOSE);
243: else if (icon == restore)
244: out.print(STheme.FRAME_RESTORE);
245: else if (icon == desktop)
246: out.print(STheme.FRAME_DESKTOP);
247: out.println("\" >");
248:
249: icon.paint(out);
250:
251: out.println("</A>");
252: }
253:
254: protected void updateContents(PrintWriter out,
255: SInternalFrame internalFrame) {
256: super .update(out, internalFrame);
257: }
258:
259: protected STheme theme;
260: protected SIcon icon;
261: protected SIcon desktop;
262: protected SIcon min;
263: protected SIcon max;
264: protected SIcon close;
265: protected SIcon bar;
266: protected SIcon restore;
267: protected SIcon point;
268:
269: protected StringBuffer linkBuffer;
270: }
|