KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > DialogBox


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.dialog;
14
15 import info.magnolia.cms.gui.misc.CssConstants;
16
17 import java.io.IOException JavaDoc;
18 import java.io.Writer JavaDoc;
19
20 import org.apache.commons.lang.StringUtils;
21
22
23 /**
24  * @author Vinzenz Wyser
25  * @version 2.0
26  */

27 public class DialogBox extends DialogControlImpl {
28
29     public static final int BOXTYPE_2COLS = 0;
30
31     public static final int BOXTYPE_1COL = 1;
32
33     private int boxType = BOXTYPE_2COLS;
34
35     /**
36      * Empty constructor should only be used by DialogFactory.
37      */

38     protected DialogBox() {
39     }
40
41     public void setBoxType(int i) {
42         this.boxType = i;
43     }
44
45     public int getBoxType() {
46         String JavaDoc configBoxType = this.getConfigValue("boxType"); //$NON-NLS-1$
47
if (configBoxType.equals("1Col")) { //$NON-NLS-1$
48
return BOXTYPE_1COL;
49         }
50         return this.boxType;
51
52     }
53
54     public void drawHtmlPre(Writer JavaDoc out) throws IOException JavaDoc {
55         if (this.getConfigValue("lineSemi", "false").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
56
out.write(new DialogLine().getHtml(1, 1));
57         }
58         else if (this.getConfigValue("line", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
59
out.write(new DialogLine().getHtml());
60         }
61         out.write("<tr>"); //$NON-NLS-1$
62
if (this.getBoxType() == BOXTYPE_2COLS) {
63             out.write("<td width=\"1%\" class=\"" + CssConstants.CSSCLASS_BOXLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
64
// write the label
65
out.write(this.getMessage(this.getLabel()));
66             if (this.isRequired()) {
67                 out.write("(*)");
68             }
69             if (StringUtils.isNotEmpty(this.getConfigValue("labelDescription"))) { //$NON-NLS-1$
70
String JavaDoc desc = this.getConfigValue("labelDescription"); //$NON-NLS-1$
71
desc = this.getMessage(desc);
72                 out.write("<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + desc + "</div>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
73
}
74             out.write("</td>"); //$NON-NLS-1$
75
String JavaDoc cssClass = CssConstants.CSSCLASS_BOXINPUT;
76             if (this.getClass().getName().indexOf("DialogStatic") != -1 //$NON-NLS-1$
77
|| this.getClass().getName().indexOf("DialogButton") != -1) { //$NON-NLS-1$
78
cssClass = CssConstants.CSSCLASS_BOXLABEL;
79             }
80             out.write("<td width=\"100%\" class=\"" + cssClass + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
81
}
82         else {
83             out.write("<td width=\"100%\" colspan=\"2\" class=\"" + CssConstants.CSSCLASS_BOXLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
84
if (StringUtils.isNotEmpty(this.getLabel())) {
85                 out.write("<div class=\"" //$NON-NLS-1$
86
+ CssConstants.CSSCLASS_BOXLABEL
87                     + "\">" //$NON-NLS-1$
88
+ this.getMessage(this.getLabel())
89                     + "</div>"); //$NON-NLS-1$
90
}
91             if (StringUtils.isNotEmpty(this.getConfigValue("labelDescription"))) { //$NON-NLS-1$
92
String JavaDoc desc = this.getConfigValue("labelDescription"); //$NON-NLS-1$
93
out.write("<div class=\"" //$NON-NLS-1$
94
+ CssConstants.CSSCLASS_DESCRIPTION
95                     + "\">" //$NON-NLS-1$
96
+ this.getMessage(desc)
97                     + "</div>"); //$NON-NLS-1$
98
}
99         }
100     }
101
102     public void drawHtmlPost(Writer JavaDoc out) throws IOException JavaDoc {
103         out.write(this.getHtmlDescription());
104         out.write("</td></tr>"); //$NON-NLS-1$
105
}
106
107     public String JavaDoc getHtmlDescription() {
108
109         // use div to force a new line
110
if (StringUtils.isNotEmpty(this.getDescription())) {
111             String JavaDoc desc = this.getDescription();
112             desc = this.getMessage(desc);
113             return "<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + desc + "</div>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
114
}
115
116         return StringUtils.EMPTY;
117     }
118
119 }
Popular Tags