1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Component ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.Vector ; 27 import javax.swing.JScrollPane ; 28 import javax.swing.JSplitPane ; 29 import org.objectweb.jac.aspects.gui.*; 30 import org.objectweb.jac.util.ExtArrays; 31 32 public class SwingPanelView extends AbstractCompositeView 33 implements PanelView 34 { 35 36 int geometry; 37 int subPanesCount; 38 boolean[] scrollings; 39 40 Vector subPanes = new Vector (); 41 Vector splitters = new Vector (); 42 Map splitterLocations; 43 Map paneContainers; 44 45 public SwingPanelView(ViewFactory factory, 46 int subPanesCount, int geometry, 47 Map paneContainers, 48 boolean[] scrollings, Map splitterLocations) { 49 this.factory = factory; 50 this.geometry = geometry; 51 this.subPanesCount = subPanesCount; 52 this.scrollings = scrollings; 53 this.paneContainers = paneContainers; 54 this.splitterLocations=splitterLocations; 55 setLayout(new BorderLayout ()); 56 construct(); 57 } 58 59 protected void construct() 60 { 61 splitters.clear(); 62 subPanes.clear(); 63 removeAll(); 64 Vector subScrollPanes = new Vector (); 65 for(int i=0;i<subPanesCount;i++) { 66 CompositeView subPane; 67 if (paneContainers.containsKey(Integer.toString(i))) { 68 subPane = factory.createCompositeView( 69 "subpane["+i+"]",(String )paneContainers.get(Integer.toString(i)), 70 new Object [] {}, 71 context); 72 } else { 73 subPane = 74 factory.createCompositeView("subpane["+i+"]","SingleSlotContainer", 75 ExtArrays.emptyObjectArray, 76 context); 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 if (subPanesCount == 1) { 91 add((Component )subScrollPanes.get(0)); 92 } else if (subPanesCount == 2) { 93 JSplitPane splitPane = new JSplitPane ( 95 geometry==Constants.HORIZONTAL? 96 JSplitPane.VERTICAL_SPLIT:JSplitPane.HORIZONTAL_SPLIT, 97 (Component )subScrollPanes.get(0), (Component )subScrollPanes.get(1)); 98 splitPane.setOneTouchExpandable(true); 99 splitters.add(splitPane); 100 add(splitPane); 101 } else if (subPanesCount == 4) { 102 JSplitPane subSplitPane1 = new JSplitPane ( 104 geometry==Constants.HORIZONTAL? 105 JSplitPane.HORIZONTAL_SPLIT:JSplitPane.VERTICAL_SPLIT, 106 (Component )subScrollPanes.get(0), (Component )subScrollPanes.get(1)); 107 subSplitPane1.setOneTouchExpandable(true); 108 JSplitPane subSplitPane2 = new JSplitPane ( 109 geometry==Constants.HORIZONTAL? 110 JSplitPane.HORIZONTAL_SPLIT:JSplitPane.VERTICAL_SPLIT, 111 (Component )subScrollPanes.get(2), (Component )subScrollPanes.get(3)); 112 subSplitPane2.setOneTouchExpandable(true); 113 JSplitPane splitPane = new JSplitPane ( 115 geometry==Constants.HORIZONTAL? 116 JSplitPane.VERTICAL_SPLIT:JSplitPane.HORIZONTAL_SPLIT, 117 subSplitPane1, subSplitPane2); 118 splitPane.setOneTouchExpandable(true); 119 splitters.add(splitPane); 120 splitters.add(subSplitPane1); 121 splitters.add(subSplitPane2); 122 add(splitPane); 123 } else if (subPanesCount == 3) { 124 JSplitPane subSplitPane = new JSplitPane ( 126 geometry<Constants.VERTICAL? 127 JSplitPane.HORIZONTAL_SPLIT:JSplitPane.VERTICAL_SPLIT, 128 (Component )subScrollPanes.get(0), (Component )subScrollPanes.get(1)); 129 subSplitPane.setOneTouchExpandable(true); 130 int type; 132 int splitType; 133 if (geometry<Constants.VERTICAL) { 134 type = geometry - Constants.HORIZONTAL; 135 splitType = JSplitPane.VERTICAL_SPLIT; 136 } else { 137 type = geometry - Constants.VERTICAL; 138 splitType = JSplitPane.HORIZONTAL_SPLIT; 139 } 140 JSplitPane splitPane = new JSplitPane ( 141 splitType, 142 type==1 ? subSplitPane : (Component )subScrollPanes.get(2), 143 type==1 ? (Component )subScrollPanes.get(2) : subSplitPane); 144 splitPane.setOneTouchExpandable(true); 145 splitters.add(splitPane); 146 splitters.add(subSplitPane); 147 add(splitPane); 148 } 149 } 150 151 public void setSplitterLocation(int splitterId, float location) { 152 JSplitPane splitter = (JSplitPane )splitters.get(splitterId); 153 splitter.setDividerLocation((double)location); 154 } 155 156 162 163 public void addView(View component, Object extraInfo) { 164 int i; 165 try { 166 i = new Integer ((String )extraInfo).intValue(); 167 } catch (NumberFormatException e) { 168 switch (geometry) { 169 case CustomizedGUI.HORIZONTAL: 170 if (extraInfo.equals(PanelView.UPPER) || 171 extraInfo.equals(PanelView.UPPER_LEFT)) 172 i = 0; 173 else if (extraInfo.equals(PanelView.LOWER) || 174 extraInfo.equals(PanelView.LOWER_LEFT)) 175 i = 1; 176 else if (extraInfo.equals(PanelView.UPPER_RIGHT)) 177 i = 2; 178 else if (extraInfo.equals(PanelView.LOWER_RIGHT)) 179 i = 3; 180 else 181 throw new RuntimeException ("Unknown position: "+extraInfo); 182 break; 183 case CustomizedGUI.VERTICAL: 184 if (extraInfo.equals(PanelView.LEFT) || 185 extraInfo.equals(PanelView.UPPER_LEFT)) 186 i = 0; 187 else if (extraInfo.equals(PanelView.RIGHT) || 188 extraInfo.equals(PanelView.UPPER_RIGHT)) 189 i = 1; 190 else if (extraInfo.equals(PanelView.LOWER_LEFT)) 191 i = 2; 192 else if (extraInfo.equals(PanelView.LOWER_RIGHT)) 193 i = 3; 194 else 195 throw new RuntimeException ("Unknown position: "+extraInfo); 196 break; 197 case CustomizedGUI.VERTICAL_RIGHT: 198 if (extraInfo.equals(PanelView.LEFT)) 199 i = 2; 200 else if (extraInfo.equals(PanelView.UPPER_RIGHT)) 201 i = 0; 202 else if (extraInfo.equals(PanelView.LOWER_RIGHT)) 203 i = 1; 204 else 205 throw new RuntimeException ("Unknown position: "+extraInfo); 206 break; 207 case CustomizedGUI.VERTICAL_LEFT: 208 if (extraInfo.equals(PanelView.RIGHT)) 209 i = 2; 210 else if (extraInfo.equals(PanelView.UPPER_LEFT)) 211 i = 0; 212 else if (extraInfo.equals(PanelView.LOWER_LEFT)) 213 i = 1; 214 else 215 throw new RuntimeException ("Unknown position: "+extraInfo); 216 break; 217 case CustomizedGUI.HORIZONTAL_DOWN: 218 if (extraInfo.equals(PanelView.UPPER)) 219 i = 2; 220 else if (extraInfo.equals(PanelView.LOWER_LEFT)) 221 i = 0; 222 else if (extraInfo.equals(PanelView.LOWER_RIGHT)) 223 i = 1; 224 else 225 throw new RuntimeException ("Unknown position: "+extraInfo); 226 break; 227 case CustomizedGUI.HORIZONTAL_UP: 228 if (extraInfo.equals(PanelView.LOWER)) 229 i = 2; 230 else if (extraInfo.equals(PanelView.UPPER_LEFT)) 231 i = 0; 232 else if (extraInfo.equals(PanelView.UPPER_RIGHT)) 233 i = 1; 234 else 235 throw new RuntimeException ("Unknown position: "+extraInfo); 236 break; 237 default: 238 throw new RuntimeException ("Invalid geometry: "+geometry); 239 } 240 } 241 CompositeView subPane=(CompositeView)subPanes.get(i); 242 subPane.addView(component,null); 243 component.setParentView(this); 244 } 245 246 public Collection getViews() { 247 return subPanes; } 249 250 public View getView(Object id) { 251 return (View)subPanes.get(Integer.parseInt((String )id)); 252 } 253 254 public void close(boolean validate) { 255 Iterator it = subPanes.iterator(); 256 while(it.hasNext()) { 257 View sp = (View)it.next(); 258 sp.close(validate); 259 } 260 } 261 262 public void removeAllViews() { 263 } 265 } 266 | Popular Tags |