1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import java.awt.Component ; 22 import java.awt.Dimension ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.Vector ; 26 import javax.swing.Box ; 27 import org.objectweb.jac.aspects.gui.CommitException; 28 import org.objectweb.jac.aspects.gui.CompositeView; 29 import org.objectweb.jac.aspects.gui.DisplayContext; 30 import org.objectweb.jac.aspects.gui.View; 31 32 public class AbstractCompositeView extends AbstractView 33 implements CompositeView { 34 35 public AbstractCompositeView() { 36 } 37 38 public void setContext(DisplayContext context) { 39 super.setContext(context); 40 for (int i=0; i<getComponentCount(); i++) { 42 Component component = getComponent(i); 43 if (component instanceof View) { 44 ((View)component).setContext(context); 45 } 46 } 47 } 48 49 public void addView(View view, Object extraInfo) { 50 view.setContext(context); 51 add((Component )view); 52 view.setParentView(this); 53 validate(); 54 } 55 56 public void addView(View view) { 57 addView(view,null); 58 } 59 60 public void addHorizontalStrut(int width) { 61 add(Box.createRigidArea(new Dimension (width,1))); 62 } 63 64 public void addVerticalStrut(int height) { 65 add(Box.createRigidArea(new Dimension (1,height))); 66 } 67 68 public Collection getViews() { 69 Object [] components = getComponents(); 70 Vector views = new Vector (); 71 for (int i=0; i<components.length; i++) { 74 if (components[i] instanceof View) { 75 views.add(components[i]); 76 } 77 } 78 return views; 79 } 80 81 public View getView(Object id) { 82 if (id instanceof String ) 83 return (View)getComponent(Integer.parseInt((String )id)); 84 else if (id instanceof Integer ) 85 return (View)getComponent(((Integer )id).intValue()); 86 else 87 throw new RuntimeException ("getView(): bad id "+id); 88 } 89 90 public boolean containsView(String viewType, Object [] parameters) { 91 Iterator it = getViews().iterator(); 92 while (it.hasNext()) { 93 View view = (View)it.next(); 94 if (view.equalsView(viewType,parameters)) 95 return true; 96 } 97 return false; 98 } 99 100 public void removeView(View component, boolean validate) 101 { 102 component.close(validate); 103 remove((Component )component); 104 validate(); 105 } 106 107 public void removeAllViews(boolean validate) { 108 close(validate); 109 removeAll(); 110 } 111 112 public void close(boolean validate) { 113 super.close(validate); 114 Iterator i = getViews().iterator(); 115 while (i.hasNext()) { 116 Object view = i.next(); 117 if (view instanceof View) { 118 try { 119 ((View)view).close(validate); 120 } catch (CommitException e) { 121 throw e; 122 } catch (Exception e) { 123 loggerClose.error("AbstractCompositeView.close: failed to close "+view,e); 124 } 125 } 126 } 127 } 128 } 129 130 | Popular Tags |