KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: InternalFrameCG.java,v 1.23 2005/06/07 12:55:59 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
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19 import org.wings.*;
20 import org.wings.event.SInternalFrameEvent;
21 import org.wings.io.Device;
22 import org.wings.plaf.CGManager;
23 import org.wings.session.SessionManager;
24
25 import java.io.IOException JavaDoc;
26
27 public class InternalFrameCG extends AbstractComponentCG implements
28         org.wings.plaf.InternalFrameCG {
29     private final static transient Log log = LogFactory.getLog(InternalFrameCG.class);
30     protected static final String JavaDoc WINDOWICON_CLASSNAME = "WindowIcon";
31     protected static final String JavaDoc BUTTONICON_CLASSNAME = "WindowButton";
32     private SIcon closeIcon;
33     private SIcon deiconifyIcon;
34     private SIcon iconifyIcon;
35     private SIcon maximizeIcon;
36     private SIcon unmaximizeIcon;
37
38     /**
39      * Initialize properties from config
40      */

41     public InternalFrameCG() {
42         final CGManager manager = SessionManager.getSession().getCGManager();
43
44         setCloseIcon((SIcon) manager.getObject("InternalFrameCG.closeIcon", SIcon.class));
45         setDeiconifyIcon((SIcon) manager.getObject("InternalFrameCG.deiconifyIcon", SIcon.class));
46         setIconifyIcon((SIcon) manager.getObject("InternalFrameCG.iconifyIcon", SIcon.class));
47         setMaximizeIcon((SIcon) manager.getObject("InternalFrameCG.maximizeIcon", SIcon.class));
48         setUnmaximizeIcon((SIcon) manager.getObject("InternalFrameCG.unmaximizeIcon", SIcon.class));
49     }
50
51     public void installCG(SComponent component) {
52         super.installCG(component);
53     }
54
55     protected void writeIcon(Device device, SIcon icon, String JavaDoc cssClass) throws IOException JavaDoc {
56         device.print("<img");
57         if (cssClass != null) {
58             device.print(" class=\"");
59             device.print(cssClass);
60             device.print("\"");
61         }
62         Utils.optAttribute(device, "src", icon.getURL());
63         Utils.optAttribute(device, "width", icon.getIconWidth());
64         Utils.optAttribute(device, "height", icon.getIconHeight());
65         device.print(" alt=\"");
66         device.print(icon.getIconTitle());
67         device.print("\"/>");
68     }
69
70     protected void writeWindowIcon(Device device, SInternalFrame frame,
71             int event, SIcon icon, String JavaDoc cssClass) throws IOException JavaDoc {
72         boolean showAsFormComponent = frame.getShowAsFormComponent();
73
74         // RequestURL addr = frame.getRequestURL();
75
// addr.addParameter(Utils.event(frame), event);
76

77         // we don't need this to be buttons
78
// if (showAsFormComponent) {
79
// device.print("<button");
80
// if (cssClass != null) {
81
// device.print(" class=\"");
82
// device.print(cssClass);
83
// device.print("\"");
84
// }
85
// device.print(" name=\"").print(Utils.event(frame)).print(
86
// "\" value=\"").print(event).print("\">");
87
// } else {
88
device.print("<a");
89             if (cssClass != null) {
90                 device.print(" class=\"");
91                 device.print(cssClass);
92                 device.print("\"");
93             }
94             device.print(" HREF=\"").print(
95                     frame.getRequestURL().addParameter(
96                             Utils.event(frame) + "=" + event).toString())
97                     .print("\">");
98 // }
99
writeIcon(device, icon, null);
100
101 // if (showAsFormComponent) {
102
// device.print("</button>");
103
// } else {
104
device.print("</a>");
105 // }
106
}
107
108
109     public void writeContent(final Device device, final SComponent _c)
110             throws IOException JavaDoc {
111         final SInternalFrame component = (SInternalFrame) _c;
112
113         SInternalFrame frame = component;
114
115         writeWindowBar(device, frame);
116
117         // write the actual content
118
if (!frame.isIconified()) {
119             device.print("<div class=\"WindowContent\">");
120             Utils.renderContainer(device, frame);
121             device.print("</div>");
122         }
123     }
124
125     /**
126      * Convenience method to keep differences between default and msie
127      * implementations small
128      * @param device
129      * @param frame
130      * @throws IOException
131      */

132     protected void writeWindowBar(final Device device, SInternalFrame frame) throws IOException JavaDoc {
133         String JavaDoc text = frame.getTitle();
134         if (text == null)
135             text = "wingS";
136         device.print("<div class=\"WindowBar\">");
137         if (frame.isIconified()) {
138             // frame is rendered in taskbar
139
if (frame.getIcon() != null) {
140                 writeIcon(device, frame.getIcon(), WINDOWICON_CLASSNAME);
141             }
142             if (deiconifyIcon != null) {
143                 device.print(text);
144                 writeWindowIcon(device, frame,
145                         SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED, deiconifyIcon, "DeiconifyButton");
146             } else {
147                 device.print("<a HREF=\"").print(
148                         frame.getRequestURL().addParameter(
149                                 Utils.event(frame) + "=" + SInternalFrameEvent.INTERNAL_FRAME_DEICONIFIED).toString())
150                         .print("\">");
151                 device.print(text);
152                 device.print("</a>");
153             }
154         } else {
155             // frame is rendered in desktopPane
156
// these following icons will be floated to the right by the style sheet...
157
if (frame.isClosable() && closeIcon != null) {
158                 writeWindowIcon(device, frame,
159                         SInternalFrameEvent.INTERNAL_FRAME_CLOSED, closeIcon, BUTTONICON_CLASSNAME);
160             }
161             if (frame.isIconifyable() && iconifyIcon != null) {
162                 writeWindowIcon(device, frame,
163                         SInternalFrameEvent.INTERNAL_FRAME_ICONIFIED, iconifyIcon, BUTTONICON_CLASSNAME);
164             }
165             if (frame.isMaximizable() && !frame.isMaximized() && maximizeIcon != null) {
166                 writeWindowIcon(device, frame,
167                         SInternalFrameEvent.INTERNAL_FRAME_MAXIMIZED, maximizeIcon, BUTTONICON_CLASSNAME);
168             }
169             device.print("<div class=\"WindowBar_title\">");
170             // float right end
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     private String JavaDoc getIconWidth(SIcon icon) {
181         if (icon.getIconWidth() == -1)
182             return "0%";
183         else
184             return "" + icon.getIconWidth();
185     }
186
187
188     public SIcon getCloseIcon() {
189         return closeIcon;
190     }
191
192     public void setCloseIcon(SIcon closeIcon) {
193         this.closeIcon = closeIcon;
194     }
195
196     public SIcon getDeiconifyIcon() {
197         return deiconifyIcon;
198     }
199
200     public void setDeiconifyIcon(SIcon deiconifyIcon) {
201         this.deiconifyIcon = deiconifyIcon;
202     }
203
204     public SIcon getIconifyIcon() {
205         return iconifyIcon;
206     }
207
208     public void setIconifyIcon(SIcon iconifyIcon) {
209         this.iconifyIcon = iconifyIcon;
210     }
211
212     public SIcon getMaximizeIcon() {
213         return maximizeIcon;
214     }
215
216     public void setMaximizeIcon(SIcon maximizeIcon) {
217         this.maximizeIcon = maximizeIcon;
218     }
219
220     public SIcon getUnmaximizeIcon() {
221         return unmaximizeIcon;
222     }
223
224     public void setUnmaximizeIcon(SIcon unmaximizeIcon) {
225         this.unmaximizeIcon = unmaximizeIcon;
226     }
227
228 }
229
Popular Tags