1 16 package org.mortbay.html; 17 import java.io.IOException ; 18 import java.io.Writer ; 19 import java.util.Enumeration ; 20 import java.util.Hashtable ; 21 import java.util.Vector ; 22 23 24 38 public class FrameSet extends Page 39 { 40 Frame[][] frames=null; 41 String colSpec=null; 42 String rowSpec=null; 43 int cols; 44 int rows; 45 String border=""; 46 Vector frameNames=null; 47 Hashtable frameMap=null; 48 49 50 54 public FrameSet(String title, String colSpec, String rowSpec) 55 { 56 super(title); 57 58 this.colSpec=colSpec; 59 this.rowSpec=rowSpec; 60 61 cols=1; 62 rows=1; 63 64 int i=-1; 65 while(colSpec != null && (i=colSpec.indexOf(",",i+1))>=0) 66 cols++; 67 68 i=-1; 69 while(rowSpec != null && (i=rowSpec.indexOf(",",i+1))>=0) 70 rows++; 71 72 frames=new Frame[cols][rows]; 73 for(int c=0;c<cols;c++) 74 for(int r=0;r<rows;r++) 75 frames[c][r]=new Frame(); 76 } 77 78 79 public Frame frame(int col, int row) 80 { 81 return frames[col][row]; 82 } 83 84 85 public FrameSet border(boolean threeD, int width, String color) 86 { 87 border=" frameborder=\""+(threeD?"yes":"no")+"\""; 88 if (width>=0) 89 border+=" border=\""+width+"\""; 90 91 if (color!=null) 92 border+=" bordercolor=\""+color+"\""; 93 return this; 94 } 95 96 97 public Enumeration namedFrames() 98 { 99 if (frameNames==null) 100 return new Vector ().elements(); 101 return frameNames.elements(); 102 } 103 104 105 public Frame frame(String name) 106 { 107 if (frameMap==null) 108 return null; 109 return (Frame) frameMap.get(name); 110 } 111 112 113 116 public Frame nameFrame(String name,int col, int row) 117 { 118 if (frameMap==null) 119 { 120 frameMap=new Hashtable (10); 121 frameNames=new Vector (10); 122 } 123 124 Frame frame = frames[col][row]; 125 if (frame==null) 126 frame = frames[col][row] = new Frame(); 127 128 if (frameMap.get(name)==null) 129 frameNames.addElement(name); 130 frameMap.put(name,frame); 131 frame.name(name); 132 133 return frame; 134 } 135 136 137 138 public void write(Writer out) 139 throws IOException 140 { 141 writeHtmlHead(out); 142 143 out.write("<frameset "+border); 144 145 if(colSpec!=null) 146 out.write(" cols=\""+colSpec+"\""); 147 if(rowSpec!=null) 148 out.write(" rows=\""+rowSpec+"\""); 149 out.write(">"); 150 151 for(int r=0;r<rows;r++) 152 for(int c=0;c<cols;c++) 153 frames[c][r].write(out); 154 155 out.write("<noframes>"); 156 writeElements(out); 157 out.write("</noframes>"); 158 159 out.write("</frameset>"); 160 out.write("</html>"); 161 } 162 }; 163 164 165 | Popular Tags |