001 /* 002 Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>, 003 Renaud Pawlak <renaud@aopsys.com> 004 005 This program is free software; you can redistribute it and/or modify 006 it under the terms of the GNU Lesser General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This program is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 GNU Lesser General Public License for more details. 014 015 You should have received a copy of the GNU Lesser General Public License 016 along with this program; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 018 019 package org.objectweb.jac.aspects.gui.web; 020 021 022 import java.io.IOException; 023 import java.io.PrintWriter; 024 import java.util.Collection; 025 import java.util.Hashtable; 026 import java.util.Iterator; 027 import java.util.Map; 028 import java.util.Vector; 029 import org.objectweb.jac.aspects.gui.*; 030 import org.objectweb.jac.util.ExtArrays; 031 032 public class Panel extends AbstractCompositeView 033 implements PanelView, HTMLViewer 034 { 035 036 int geometry; 037 int subPanesCount; 038 boolean[] scrollings; 039 040 Vector subPanes = new Vector(); 041 Map splitterLocations; 042 Map paneContainers; 043 044 public Panel(ViewFactory factory, 045 int subPanesCount, int geometry, 046 Map paneContainers, 047 boolean[] scrollings, Map splitterLocations) { 048 this.factory = factory; 049 this.geometry = geometry; 050 this.subPanesCount = subPanesCount; 051 this.scrollings = scrollings; 052 this.paneContainers = paneContainers; 053 this.splitterLocations=splitterLocations; 054 construct(); 055 } 056 057 protected void construct() 058 { 059 subPanes.clear(); 060 components.clear(); 061 Vector subScrollPanes = new Vector(); 062 for(int i=0;i<subPanesCount;i++) { 063 CompositeView subPane; 064 if (paneContainers.containsKey(Integer.toString(i))) { 065 subPane = factory.createCompositeView( 066 "subpane["+i+"]",(String)paneContainers.get(Integer.toString(i)), 067 new Object[] {}, 068 context); 069 } else { 070 subPane = 071 factory.createCompositeView("subpane["+i+"]","SingleSlotContainer", 072 ExtArrays.emptyObjectArray, 073 context); 074 } 075 subPanes.add(subPane); 076 add(subPane); 077 /* 078 JScrollPane subScrollPane = null; 079 if( scrollings[i] == true ) { 080 subScrollPane = new JScrollPane((Component)subPane); 081 } 082 subPanes.add( subPane ); 083 if( subScrollPane == null ) { 084 subScrollPanes.add(subPane); 085 } else { 086 subScrollPanes.add(subScrollPane); 087 } 088 */ 089 } 090 } 091 092 public void setSplitterLocation(int splitId, float location) { 093 if (splitterLocations==null) 094 splitterLocations = new Hashtable(); 095 splitterLocations.put(new Integer(splitId),new Float(location)); 096 } 097 098 /** 099 * 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 value = (Float)splitterLocations.get(new Integer(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 extraInfo) { 121 int i=new Integer((String)extraInfo).intValue(); 122 CompositeView subPane=(CompositeView)subPanes.get(i); 123 subPane.addView(component); 124 } 125 126 public Collection getViews() { 127 return subPanes; 128 } 129 130 public View getView(Object id) { 131 return (View)subPanes.get(Integer.parseInt((String)id)); 132 } 133 134 public void close(boolean validate) { 135 Iterator 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 out) throws IOException { 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 }