KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > widget > BoxWidget


1 /*
2  * Copyright (c) 1998-2005 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29 package com.caucho.widget;
30
31 import com.caucho.util.L10N;
32
33 import java.io.IOException;
34
35 /**
36  * <a HREF="http://www.xulplanet.com/references/elemref/ref_box.html">XUL reference</a>
37  */

38 public class BoxWidget
39   extends XulWidgetContainer
40 {
41   private static final L10N L = new L10N(BoxWidget.class);
42
43   private Orient _orient = Orient.HORIZONTAL;
44
45   public BoxWidget()
46   {
47   }
48
49   public BoxWidget(String id)
50   {
51     setId(id);
52   }
53
54   public BoxWidget(String id, Orient orient)
55   {
56     setId(id);
57     setOrient(orient);
58   }
59
60   /**
61    * Set the orientation, default is {@link Orient.HORIZONTAL}.
62    */

63   public void setOrient(Orient orient)
64   {
65     _orient = orient;
66   }
67
68   /**
69    * Set the orientation, either "horizontal" or "vertical".
70    */

71   public void setOrient(String orient)
72   {
73     if ("horizontal".equals(orient))
74       setOrient(Orient.HORIZONTAL);
75     else if ("vertical".equals(orient))
76       setOrient(Orient.VERTICAL);
77     else
78       throw new IllegalArgumentException("" + orient);
79   }
80
81   public Orient getOrient()
82   {
83     return _orient;
84   }
85
86   public void init(WidgetInit init)
87     throws WidgetException
88   {
89     super.init(init);
90   }
91
92   public void response(WidgetResponse response)
93     throws WidgetException, IOException
94   {
95     Orient orient = getOrient();
96
97     String id = getId();
98     String cssClass = getCssClass(response);
99
100     WidgetWriter out = response.getWriter();
101
102     out.startElement("div");
103     out.writeAttribute("id", id);
104
105     String orientAttribute = orient == Orient.HORIZONTAL ? "horizontal" : "vertical";
106
107     out.writeAttribute("class", cssClass, orientAttribute);
108
109     super.response(response);
110
111     out.endElement("div");
112   }
113 }
114
Popular Tags