001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf.css;
014:
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017: import org.wings.*;
018: import org.wings.event.SInternalFrameEvent;
019: import org.wings.io.Device;
020: import org.wings.io.StringBuilderDevice;
021: import org.wings.plaf.Update.Handler;
022: import org.wings.plaf.css.FrameCG.AddWindowUpdate;
023: import org.wings.plaf.css.FrameCG.RemoveWindowUpdate;
024: import org.wings.plaf.css.script.OnPageRenderedScript;
025: import org.wings.plaf.Update;
026: import org.wings.resource.ResourceManager;
027: import org.wings.session.ScriptManager;
028: import org.wings.util.SStringBuilder;
029:
030: import java.io.IOException;
031: import java.util.HashMap;
032: import java.util.Map;
033:
034: public class InternalFrameCG extends AbstractComponentCG implements
035: org.wings.plaf.InternalFrameCG {
036: private static final long serialVersionUID = 1L;
037: private final static Log log = LogFactory
038: .getLog(InternalFrameCG.class);
039: protected static final String WINDOWICON_CLASSNAME = "WindowIcon";
040: protected static final String BUTTONICON_CLASSNAME = "WindowButton";
041: private SIcon closeIcon;
042: private SIcon deiconifyIcon;
043: private SIcon iconifyIcon;
044: private SIcon maximizeIcon;
045: private SIcon unmaximizeIcon;
046:
047: /**
048: * Initialize properties from config
049: */
050: public InternalFrameCG() {
051: setCloseIcon((SIcon) ResourceManager.getObject(
052: "InternalFrameCG.closeIcon", SIcon.class));
053: setDeiconifyIcon((SIcon) ResourceManager.getObject(
054: "InternalFrameCG.deiconifyIcon", SIcon.class));
055: setIconifyIcon((SIcon) ResourceManager.getObject(
056: "InternalFrameCG.iconifyIcon", SIcon.class));
057: setMaximizeIcon((SIcon) ResourceManager.getObject(
058: "InternalFrameCG.maximizeIcon", SIcon.class));
059: setUnmaximizeIcon((SIcon) ResourceManager.getObject(
060: "InternalFrameCG.unmaximizeIcon", SIcon.class));
061: }
062:
063: protected void writeIcon(Device device, SIcon icon, String cssClass)
064: throws IOException {
065: device.print("<img");
066: if (cssClass != null) {
067: device.print(" class=\"");
068: device.print(cssClass);
069: device.print("\"");
070: }
071: Utils.optAttribute(device, "src", icon.getURL());
072: Utils.optAttribute(device, "width", icon.getIconWidth());
073: Utils.optAttribute(device, "height", icon.getIconHeight());
074: Utils.attribute(device, "alt", icon.getIconTitle());
075: device.print("/>");
076: }
077:
078: protected void writeWindowIcon(Device device, SInternalFrame frame,
079: int event, SIcon icon, String cssClass) throws IOException {
080: Utils.printButtonStart(device, frame, Integer.toString(event),
081: true, frame.getShowAsFormComponent(), cssClass);
082: device.print(">");
083: writeIcon(device, icon, null);
084: Utils.printButtonEnd(device, true);
085: }
086:
087: protected void writeWindowIcon(Device device, SInternalFrame frame,
088: int event, SIcon icon) throws IOException {
089: writeWindowIcon(device, frame, event, icon, null);
090: }
091:
092: public void writeInternal(final Device device, final SComponent _c)
093: throws IOException {
094:
095: SInternalFrame frame = (SInternalFrame) _c;
096:
097: // Optional attribute to identify the internal frame for
098: // SDialog and SOptionPane usage.
099: Map optionalAttributes = new HashMap();
100: optionalAttributes.put("SComponentClass",
101: "org.wings.SInternalFrame");
102:
103: writeDivPrefix(device, frame, optionalAttributes);
104: writeWindowBar(device, frame);
105: // write the actual content
106: if (!frame.isIconified()) {
107: device.print("<div class=\"WindowContent\"");
108: SStringBuilder contentArea = Utils.inlineStyles(frame
109: .getDynamicStyle(SInternalFrame.SELECTOR_CONTENT));
110: Utils.optAttribute(device, "style", contentArea);
111: device.print(">");
112:
113: Utils.renderContainer(device, frame);
114: device.print("</div>");
115: }
116: writeDivSuffix(device, frame);
117: }
118:
119: /**
120: * Convenience method to keep differences between default and msie
121: * implementations small
122: * @param device
123: * @param frame
124: * @throws IOException
125: */
126: protected void writeWindowBar(final Device device,
127: SInternalFrame frame) throws IOException {
128: String text = frame.getTitle();
129: if (text == null)
130: text = "wingS";
131:
132: device.print("<div class=\"WindowBar\" id=\"");
133: device.print(frame.getName());
134: device.print("_titlebar\"");
135:
136: SStringBuilder titleArea = Utils.inlineStyles(frame
137: .getDynamicStyle(SInternalFrame.SELECTOR_TITLE));
138: Utils.optAttribute(device, "style", titleArea);
139: device.print(">");
140:
141: if (frame.isClosable() && closeIcon != null) {
142: writeWindowIcon(device, frame,
143: SInternalFrameEvent.INTERNAL_FRAME_CLOSED,
144: closeIcon, BUTTONICON_CLASSNAME);
145: }
146: if (frame.isMaximized() && unmaximizeIcon != null) {
147: writeWindowIcon(device, frame,
148: SInternalFrameEvent.INTERNAL_FRAME_UNMAXIMIZED,
149: unmaximizeIcon, BUTTONICON_CLASSNAME);
150: }
151: if (frame.isMaximizable() && !frame.isMaximized()
152: && maximizeIcon != null) {
153: writeWindowIcon(device, frame,
154: SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED,
155: maximizeIcon, BUTTONICON_CLASSNAME);
156: }
157: if (frame.isIconified() && deiconifyIcon != null) {
158: writeWindowIcon(device, frame,
159: SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED,
160: deiconifyIcon, BUTTONICON_CLASSNAME);
161: }
162: if (frame.isIconifyable() && !frame.isIconified()
163: && iconifyIcon != null) {
164: writeWindowIcon(device, frame,
165: SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED,
166: iconifyIcon, BUTTONICON_CLASSNAME);
167: }
168:
169: device.print("<div class=\"WindowBar_title\">"); // float right end
170:
171: if (frame.getIcon() != null) {
172: writeIcon(device, frame.getIcon(), WINDOWICON_CLASSNAME);
173: }
174: device.print(text);
175: device.print("</div>");
176:
177: device.print("</div>");
178: }
179:
180: protected String getDragHandle(SComponent component) {
181: return component.getName() + "_titlebar";
182: }
183:
184: public SIcon getCloseIcon() {
185: return closeIcon;
186: }
187:
188: public void setCloseIcon(SIcon closeIcon) {
189: this .closeIcon = closeIcon;
190: }
191:
192: public SIcon getDeiconifyIcon() {
193: return deiconifyIcon;
194: }
195:
196: public void setDeiconifyIcon(SIcon deiconifyIcon) {
197: this .deiconifyIcon = deiconifyIcon;
198: }
199:
200: public SIcon getIconifyIcon() {
201: return iconifyIcon;
202: }
203:
204: public void setIconifyIcon(SIcon iconifyIcon) {
205: this .iconifyIcon = iconifyIcon;
206: }
207:
208: public SIcon getMaximizeIcon() {
209: return maximizeIcon;
210: }
211:
212: public void setMaximizeIcon(SIcon maximizeIcon) {
213: this .maximizeIcon = maximizeIcon;
214: }
215:
216: public SIcon getUnmaximizeIcon() {
217: return unmaximizeIcon;
218: }
219:
220: public void setUnmaximizeIcon(SIcon unmaximizeIcon) {
221: this .unmaximizeIcon = unmaximizeIcon;
222: }
223:
224: /**
225: * {@inheritDoc}
226: */
227: public Update getAddWindowUpdate(SContainer container,
228: SWindow window) {
229: return new AddWindowUpdate(container, window);
230: }
231:
232: protected class AddWindowUpdate extends AbstractUpdate {
233:
234: private SWindow window;
235:
236: public AddWindowUpdate(SContainer container, SWindow window) {
237: super (container);
238: this .window = window;
239: }
240:
241: @Override
242: public int getPriority() {
243: return Integer.MAX_VALUE;
244: }
245:
246: public Handler getHandler() {
247: UpdateHandler handler = new UpdateHandler("addWindow");
248: handler.addParameter(component.getName());
249: handler.addParameter("<div id=\"" + window.getName()
250: + "\"/>");
251: return handler;
252: }
253: }
254:
255: public Update getRemoveWindowUpdate(final SContainer container,
256: final SWindow window) {
257: return new RemoveWindowUpdate(container, window);
258: }
259:
260: protected class RemoveWindowUpdate extends AbstractUpdate {
261:
262: private SWindow window;
263:
264: public RemoveWindowUpdate(final SContainer container,
265: final SWindow window) {
266: super (container);
267: this .window = window;
268: }
269:
270: public Handler getHandler() {
271: UpdateHandler handler = new UpdateHandler("removeWindow");
272: handler.addParameter(window.getName());
273: return handler;
274: }
275: }
276: }
|