1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import java.util.Arrays ; 22 import java.util.Collection ; 23 import java.util.Hashtable ; 24 import java.util.Iterator ; 25 import javax.swing.JComponent ; 26 import javax.swing.JDesktopPane ; 27 import javax.swing.JInternalFrame ; 28 import org.apache.log4j.Logger; 29 import org.objectweb.jac.aspects.gui.Border; 30 import org.objectweb.jac.aspects.gui.CompositeView; 31 import org.objectweb.jac.aspects.gui.DisplayContext; 32 import org.objectweb.jac.aspects.gui.Length; 33 import org.objectweb.jac.aspects.gui.View; 34 import org.objectweb.jac.aspects.gui.ViewFactory; 35 import org.objectweb.jac.aspects.gui.ViewIdentity; 36 import org.objectweb.jac.core.rtti.FieldItem; 37 import org.objectweb.jac.core.rtti.MethodItem; 38 39 43 44 public class DesktopView extends JDesktopPane implements CompositeView { 45 static Logger logger = Logger.getLogger("gui.swing"); 46 47 Hashtable views = new Hashtable (); 48 49 DisplayContext context; 50 Length width; 51 Length height; 52 ViewFactory factory; 53 Object [] parameters; 54 String type; 55 String label; 56 57 public DesktopView() { 58 } 59 60 public void addHorizontalStrut(int width) {} 61 public void addVerticalStrut(int height) {} 62 63 String style; 65 66 public void setStyle(String style) { 67 this.style = style; 68 } 69 70 public String getStyle() { 71 return style; 72 } 73 74 Border viewBorder; 75 76 80 public Border getViewBorder() { 81 return viewBorder; 82 } 83 84 88 public void setViewBorder(Border v) { 89 this.viewBorder = v; 90 } 91 92 String description; 93 94 98 public String getDescription() { 99 return description; 100 } 101 102 106 public void setDescription(String v) { 107 this.description = v; 108 } 109 110 View parentView; 111 112 116 public View getParentView() { 117 return parentView; 118 } 119 120 124 public void setParentView(View v) { 125 this.parentView = v; 126 } 127 128 public View getRootView() { 129 if (parentView==null) 130 return this; 131 return parentView.getRootView(); 132 } 133 134 public boolean isDescendantOf(View ancestor) { 135 if (this==ancestor) 136 return true; 137 else if (parentView==null) 138 return false; 139 else 140 return parentView.isDescendantOf(ancestor); 141 } 142 143 MethodItem message; 144 145 149 public MethodItem getMessage() { 150 return message; 151 } 152 153 157 public void setMessage(MethodItem v) { 158 this.message = v; 159 } 160 161 162 164 public void addView(View view, Object extraInfos) { 165 logger.debug("Adding view in desktop"); 166 JInternalFrame frame=new JInternalFrame (); 167 frame.getContentPane().add((JComponent )view); 168 frame.setVisible(true); frame.setTitle((String )extraInfos); 170 frame.setResizable(true); 171 frame.setClosable(true); 172 frame.setIconifiable(true); 173 frame.setMaximizable(true); 174 add(frame); 175 try { 176 frame.setSelected(true); 177 } catch (java.beans.PropertyVetoException e) { 178 } 179 views.put(extraInfos,view); 180 frame.pack(); 181 frame.show(); 182 } 183 184 public void addView(View view) { 185 addView(view,view.getLabel()); 186 } 187 188 public void removeView(View component, boolean validate) { 189 for (int i=0; i<getComponentCount(); i++) { 190 JInternalFrame frame = (JInternalFrame )getComponent(i); 191 if (frame.getContentPane().getComponent(0).equals(component)) { 192 component.close(validate); 193 remove(frame); 194 } 195 } 196 } 197 198 public View getView(Object id) { 199 return (View)views.get(id); 200 } 201 202 public Collection getViews() { 203 return views.values(); 204 } 205 206 public void removeAllViews(boolean validate) { 207 Iterator i = views.values().iterator(); 208 while (i.hasNext()) { 209 ((View)i.next()).close(validate); 210 } 211 removeAll(); 212 } 213 214 public boolean containsView(String viewType, Object [] parameters) { 215 Iterator it = getViews().iterator(); 216 while (it.hasNext()) { 217 View view = (View)it.next(); 218 if (view.equalsView(viewType,parameters)) 219 return true; 220 } 221 return false; 222 } 223 224 226 public void setContext(DisplayContext context) { 227 this.context = context; 228 } 229 230 public DisplayContext getContext() { 231 return context; 232 } 233 234 public void setLabel(String label) { 235 this.label = label; 236 } 237 238 public String getLabel() { 239 return label; 240 } 241 242 243 public void setSize(Length width, Length height) { 244 this.width = width; 245 this.height = height; 246 SwingUtils.setSize(this,width,height); 247 } 248 249 public void close(boolean validate) { 250 closed = true; 251 } 252 253 boolean closed = false; 254 255 public boolean isClosed() { 256 return closed; 257 } 258 259 public ViewFactory getFactory() { 260 return factory; 261 } 262 263 public void setFactory(ViewFactory factory) { 264 this.factory = factory; 265 } 266 267 public void setType(String type) { 268 this.type = type; 269 } 270 271 public String getType() { 272 return type; 273 } 274 275 public void setParameters(Object [] parameters) { 276 this.parameters = parameters; 277 } 278 279 public Object [] getParameters() { 280 return parameters; 281 } 282 283 public boolean equalsView(ViewIdentity view) { 284 return 285 ( ( type!=null && 286 type.equals(view.getType()) ) 287 || (type==null && view.getType()==null ) ) 288 && ( ( parameters!=null && 289 Arrays.equals(parameters,view.getParameters()) ) 290 || (parameters==null && view.getParameters()==null) ); 291 } 292 293 public boolean equalsView(String type, Object [] parameters) { 294 return this.type.equals(type) 295 && Arrays.equals(this.parameters,parameters); 296 } 297 298 public void setFocus(FieldItem field, Object option) { 299 } 300 301 public String toString() { 302 return getClass().getName()+"@"+Integer.toString(hashCode()); 303 } 304 305 } 306 | Popular Tags |