KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: DialogCG.java,v 1.15 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.wings.*;
18 import org.wings.event.SInternalFrameEvent;
19 import org.wings.io.Device;
20 import org.wings.plaf.CGManager;
21 import org.wings.session.SessionManager;
22
23 import java.io.IOException JavaDoc;
24
25 public class DialogCG extends org.wings.plaf.css.FormCG implements
26         org.wings.plaf.DialogCG {
27
28 //--- byte array converted template snippets.
29

30 //--- properties of this plaf.
31
private SIcon closeIcon;
32
33     /**
34      * Initialize properties from config
35      */

36     public DialogCG() {
37         final CGManager manager = SessionManager.getSession().getCGManager();
38         setCloseIcon((SIcon) manager.getObject("DialogCG.closeIcon", SIcon.class));
39     }
40
41     private void writeIcon(Device device, SIcon icon) throws IOException JavaDoc {
42         device.print("<img");
43         Utils.optAttribute(device, "src", icon.getURL());
44         Utils.optAttribute(device, "width", icon.getIconWidth());
45         Utils.optAttribute(device, "height", icon.getIconHeight());
46         device.print(" alt=\"");
47         device.print(icon.getIconTitle());
48         device.print("\"/>");
49     }
50
51     private void writeWindowIcon(Device device, SDialog dialog,
52                                  int event, SIcon icon) throws IOException JavaDoc {
53         boolean showAsFormComponent = dialog.getShowAsFormComponent();
54
55         RequestURL addr = dialog.getRequestURL();
56         addr.addParameter(Utils.event(dialog), event);
57
58         device.print("<th");
59         Utils.optAttribute(device, "width", getIconWidth(icon));
60         device.print(">");
61
62         // this really doesn't need to be shown as a form component
63
// if (showAsFormComponent)
64
// device.print("<button name=\"")
65
// .print(Utils.event(dialog))
66
// .print("\" value=\"")
67
// .print(event)
68
// .print("\">");
69
// else
70
device.print("<a HREF=\"")
71                     .print(dialog.getRequestURL()
72                     .addParameter(Utils.event(dialog) + "=" + event).toString())
73                     .print("\">");
74
75         writeIcon(device, icon);
76
77 // if (showAsFormComponent)
78
// device.print("</button>");
79
// else
80
device.print("</a>");
81
82         device.print("</th>");
83     }
84
85     private String JavaDoc getIconWidth(SIcon icon) {
86         if (icon.getIconWidth() == -1)
87             return "0%";
88         else
89             return "" + icon.getIconWidth();
90     }
91
92     public void write(final Device device, final SComponent component)
93             throws IOException JavaDoc {
94         SDialog dialog = (SDialog) component;
95         device.print("<table border=\"0\" width=\"100%\" height=\"100%\" class=\"SLayout\"><tr><td align=\"center\" valign=\"middle\" class=\"SLayout\">");
96         super.writeContent(device, dialog);
97         device.print("</td></tr></table>\n");
98     }
99
100     protected void renderContainer(Device device, SForm component) throws IOException JavaDoc {
101         super.write(device, component);
102     }
103
104     protected void writeContent(final Device device, final SComponent component) throws IOException JavaDoc {
105         final SDialog dialog = (SDialog) component;
106
107         String JavaDoc text = dialog.getTitle();
108         int columns = 0;
109         if (text == null)
110             text = "Dialog";
111
112         device.print("<table class=\"SLayout\"");
113         Utils.printCSSInlineFullSize(device, component.getPreferredSize());
114         device.print(">\n<tr>");
115
116         // left icon
117
if (dialog.getIcon() != null) {
118             SIcon icon = dialog.getIcon();
119             device.print("<th class=\"SLayout\"");
120             Utils.optAttribute(device, "width", getIconWidth(icon));
121             device.print(">");
122             writeIcon(device, icon);
123             device.print("</th>");
124             ++columns;
125         }
126
127         device.print("<th col=\"title\" class=\"SLayout\">&nbsp;");
128         Utils.write(device, text);
129         device.print("</th>");
130         ++columns;
131
132         if (dialog.isClosable() && closeIcon != null) {
133             writeWindowIcon(device, dialog,
134                     SInternalFrameEvent.INTERNAL_FRAME_CLOSED, closeIcon);
135             ++columns;
136         }
137         device.print("</tr>");
138
139         // write the actual content
140
device.print("<tr><td class=\"SLayout\" colspan=\"");
141         device.print(String.valueOf(columns));
142         device.print("\">");
143         Utils.renderContainer(device, dialog);
144         device.print("</td></tr>");
145         device.print("</table>\n");
146     }
147
148     public SIcon getCloseIcon() {
149         return closeIcon;
150     }
151
152     public void setCloseIcon(SIcon closeIcon) {
153         this.closeIcon = closeIcon;
154     }
155 }
156
Popular Tags