KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > Panel


1 /*
2   Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>,
3                           Renaud Pawlak <renaud@aopsys.com>
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

18
19 package org.objectweb.jac.aspects.gui.web;
20
21
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Vector JavaDoc;
29 import org.objectweb.jac.aspects.gui.*;
30 import org.objectweb.jac.util.ExtArrays;
31
32 public class Panel extends AbstractCompositeView
33     implements PanelView, HTMLViewer
34 {
35    
36     int geometry;
37     int subPanesCount;
38     boolean[] scrollings;
39
40     Vector JavaDoc subPanes = new Vector JavaDoc();
41     Map JavaDoc splitterLocations;
42     Map JavaDoc paneContainers;
43
44     public Panel(ViewFactory factory,
45                  int subPanesCount, int geometry,
46                  Map JavaDoc paneContainers,
47                  boolean[] scrollings, Map JavaDoc splitterLocations) {
48         this.factory = factory;
49         this.geometry = geometry;
50         this.subPanesCount = subPanesCount;
51         this.scrollings = scrollings;
52         this.paneContainers = paneContainers;
53         this.splitterLocations=splitterLocations;
54         construct();
55     }
56
57     protected void construct()
58     {
59         subPanes.clear();
60         components.clear();
61         Vector JavaDoc subScrollPanes = new Vector JavaDoc();
62         for(int i=0;i<subPanesCount;i++) {
63             CompositeView subPane;
64             if (paneContainers.containsKey(Integer.toString(i))) {
65                 subPane = factory.createCompositeView(
66                     "subpane["+i+"]",(String JavaDoc)paneContainers.get(Integer.toString(i)),
67                     new Object JavaDoc[] {},
68                     context);
69             } else {
70                 subPane =
71                     factory.createCompositeView("subpane["+i+"]","SingleSlotContainer",
72                                                 ExtArrays.emptyObjectArray,
73                                                 context);
74             }
75             subPanes.add(subPane);
76             add(subPane);
77             /*
78               JScrollPane subScrollPane = null;
79               if( scrollings[i] == true ) {
80               subScrollPane = new JScrollPane((Component)subPane);
81               }
82               subPanes.add( subPane );
83               if( subScrollPane == null ) {
84               subScrollPanes.add(subPane);
85               } else {
86               subScrollPanes.add(subScrollPane);
87               }
88             */

89         }
90     }
91
92     public void setSplitterLocation(int splitId, float location) {
93         if (splitterLocations==null)
94             splitterLocations = new Hashtable JavaDoc();
95         splitterLocations.put(new Integer JavaDoc(splitId),new Float JavaDoc(location));
96     }
97
98     /**
99      * Returns a splitter's loctation as a percentage between 0 and 100.
100      */

101     protected float getSplitterLocation(int splitId) {
102         if (splitterLocations==null) {
103             return 50;
104         } else {
105             Float JavaDoc value = (Float JavaDoc)splitterLocations.get(new Integer JavaDoc(splitId));
106             if (value!=null)
107                 return value.floatValue()*100;
108             else
109                 return 50;
110         }
111     }
112
113     /**
114      * Adds a view.
115      *
116      * @param component the view to add
117      * @param extraInfo the panel ID
118      */

119
120     public void addView(View component, Object JavaDoc extraInfo) {
121         int i=new Integer JavaDoc((String JavaDoc)extraInfo).intValue();
122         CompositeView subPane=(CompositeView)subPanes.get(i);
123         subPane.addView(component);
124     }
125
126     public Collection JavaDoc getViews() {
127         return subPanes;
128     }
129
130     public View getView(Object JavaDoc id) {
131         return (View)subPanes.get(Integer.parseInt((String JavaDoc)id));
132     }
133
134     public void close(boolean validate) {
135         Iterator JavaDoc it = subPanes.iterator();
136         while(it.hasNext()) {
137             View sp = (View)it.next();
138             sp.close(validate);
139         }
140     }
141
142     public void removeAllViews() {
143         //
144
}
145
146     // HTMLViewer interface
147

148     public void genHTML(PrintWriter JavaDoc out) throws IOException JavaDoc {
149         switch(subPanesCount) {
150             case 1:
151                 out.println("<div class=\""+getClass().getName()+"\" id=\""+label+"\">");
152                 //out.println("<div>");
153
((HTMLViewer)components.get(0)).genHTML(out);
154                 out.println("</div>");
155                 break;
156             case 2:
157                 if (geometry==Constants.HORIZONTAL) {
158                     out.println("<table style=\"width:100%;height:100%\">"+
159                                 "<tr class=\"up\" style=\"height:"+
160                                 (100-getSplitterLocation(0))+"%\"><td>");
161                     ((HTMLViewer)components.get(0)).genHTML(out);
162                     out.println("</td></tr>");
163                     out.println("<tr class=\"down\" height=\""+
164                                 getSplitterLocation(0)+"%\"><td>");
165                     ((HTMLViewer)components.get(1)).genHTML(out);
166                     out.println("</td></tr></table>");
167                 } else {
168                     out.println("<table style=\"width:100%;height:100%\">"+
169                                 "<tr><td class=\"left\" width=\""+
170                                 getSplitterLocation(0)+"%\">");
171                     ((HTMLViewer)components.get(0)).genHTML(out);
172                     out.println("</td>");
173                     out.println("<td class=\"right\" width=\""+
174                                 (100-getSplitterLocation(0))+"%\">");
175                     ((HTMLViewer)components.get(1)).genHTML(out);
176                     out.println("</td></tr></table");
177                 }
178                 break;
179             case 3:
180                 if (geometry<Constants.VERTICAL) {
181                     if (geometry==Constants.HORIZONTAL_UP) {
182                         out.println("<div class=\"upper\" style=\"bottom:"+
183                                     (100-getSplitterLocation(0))+"%\">");
184                         out.println("<div class=\"left\" style=\"right:"+
185                                     (100-getSplitterLocation(1))+"%\">");
186                         ((HTMLViewer)components.get(0)).genHTML(out);
187                         out.println("</div>");
188                         out.println("<div class=\"right\" style=\"left:"+
189                                     getSplitterLocation(1)+"%\">");
190                         ((HTMLViewer)components.get(1)).genHTML(out);
191                         out.println("</div>");
192                         out.println("</div>");
193                         out.println("<div class=\"lower\" style=\"top:"+
194                                     getSplitterLocation(0)+"%\">");
195                         ((HTMLViewer)components.get(2)).genHTML(out);
196                         out.println("</div>");
197                     } else {
198                         out.println("<div class=\"upper\" style=\"bottom:"+
199                                     (100-getSplitterLocation(0))+"%\">");
200                         ((HTMLViewer)components.get(2)).genHTML(out);
201                         out.println("</div>");
202                         out.println("<div class=\"lower\" style=\"top:"+
203                                     getSplitterLocation(0)+"%\">");
204                         out.println("<div class=\"left\" style=\"right:"+
205                                     (100-getSplitterLocation(1))+"%\">");
206                         ((HTMLViewer)components.get(0)).genHTML(out);
207                         out.println("</div>");
208                         out.println("<div class=\"right\" style=\"left:"+
209                                     getSplitterLocation(1)+"%\">");
210                         ((HTMLViewer)components.get(1)).genHTML(out);
211                         out.println("</div>");
212                         out.println("</div>");
213                     }
214                 } else {
215                     if (geometry==Constants.VERTICAL_LEFT) {
216                         out.println("<div class=\"left\" style=\"right:"+
217                                     (100-getSplitterLocation(0))+"%\">");
218                         out.println("<div class=\"upper\" style=\"bottom:"+
219                                     (100-getSplitterLocation(1))+"%\">");
220                         ((HTMLViewer)components.get(0)).genHTML(out);
221                         out.println("</div>");
222                         out.println("<div class=\"lower\" style=\"top:"+
223                                     getSplitterLocation(1)+"%\">");
224                         ((HTMLViewer)components.get(1)).genHTML(out);
225                         out.println("</div>");
226                         out.println("</div>");
227                         out.println("<div class=\"right\" style=\"left:"+
228                                     getSplitterLocation(0)+"%\">");
229                         ((HTMLViewer)components.get(2)).genHTML(out);
230                         out.println("</div>");
231                     } else {
232                         out.println("<div class=\"left\" style=\"right:"+
233                                     (100-getSplitterLocation(0))+"%\">");
234                         ((HTMLViewer)components.get(2)).genHTML(out);
235                         out.println("</div>");
236                         out.println("<div class=\"right\" style=\"left:"+
237                                     getSplitterLocation(0)+"%\">");
238                         out.println("<div class=\"upper\" style=\"bottom:"+
239                                     (100-getSplitterLocation(1))+"%\">");
240                         ((HTMLViewer)components.get(0)).genHTML(out);
241                         out.println("</div>");
242                         out.println("<div class=\"lower\" style=\"top:"+
243                                     getSplitterLocation(1)+"%\">");
244                         ((HTMLViewer)components.get(1)).genHTML(out);
245                         out.println("</div>");
246                         out.println("</div>");
247                     }
248                 }
249                 break;
250             case 4:
251                 if (geometry==Constants.VERTICAL) {
252                     out.println("<div class=\"left\" style=\"right:"+
253                                 (100-getSplitterLocation(0))+"%\">");
254                     out.println("<div class=\"upper\" style=\"bottom:"+
255                                 (100-getSplitterLocation(1))+"%\">");
256                     ((HTMLViewer)components.get(0)).genHTML(out);
257                     out.println("</div>");
258                     out.println("<div class=\"lower\" style=\"top:"+
259                                 getSplitterLocation(1)+"%\">");
260                     ((HTMLViewer)components.get(1)).genHTML(out);
261                     out.println("</div>");
262                     out.println("</div>");
263                     out.println("<div class=\"right\" style=\"left:"+
264                                 getSplitterLocation(0)+"%\">");
265                     out.println("<div class=\"upper\" style=\"bottom:"+
266                                 (100-getSplitterLocation(2))+"%\">");
267                     ((HTMLViewer)components.get(2)).genHTML(out);
268                     out.println("</div>");
269                     out.println("<div class=\"lower\" style=\"top:"+
270                                 getSplitterLocation(2)+"%\">");
271                     ((HTMLViewer)components.get(3)).genHTML(out);
272                     out.println("</div>");
273                     out.println("</div>");
274                 } else {
275                     out.println("<div class=\"upper\" style=\"bottom:"+
276                                 (100-getSplitterLocation(0))+"%\">");
277                     out.println("<div class=\"left\" style=\"right:"+
278                                 (100-getSplitterLocation(1))+"%\">");
279                     ((HTMLViewer)components.get(0)).genHTML(out);
280                     out.println("</div>");
281                     out.println("<div class=\"right\" style=\"left:"+
282                                 getSplitterLocation(1)+"%\">");
283                     ((HTMLViewer)components.get(1)).genHTML(out);
284                     out.println("</div>");
285                     out.println("</div>");
286                     out.println("<div class=\"lower\" style=\"top:"+
287                                 getSplitterLocation(0)+"%\">");
288                     out.println("<div class=\"left\" style=\"right:"+
289                                 (100-getSplitterLocation(2))+"%\">");
290                     ((HTMLViewer)components.get(2)).genHTML(out);
291                     out.println("</div>");
292                     out.println("<div class=\"right\" style=\"left:"+
293                                 getSplitterLocation(2)+"%\">");
294                     ((HTMLViewer)components.get(3)).genHTML(out);
295                     out.println("</div>");
296                     out.println("</div>");
297                 }
298                 break;
299         }
300     }
301 }
302
Popular Tags