1 18 19 package org.objectweb.jac.aspects.gui; 20 21 import java.lang.ref.WeakReference ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Vector ; 25 import org.apache.log4j.Logger; 26 import org.objectweb.jac.util.Strings; 27 28 42 43 public class DisplayContext implements EditorContainer { 44 static Logger logger = Logger.getLogger("gui.context"); 45 static Logger loggerEdit = Logger.getLogger("gui.editor"); 46 47 CustomizedDisplay display; 48 CustomizedView customizedView; 49 WeakReference window; 51 Vector editors = new Vector (); 52 boolean showButtons = false; 53 54 60 public DisplayContext(CustomizedDisplay display, 61 CustomizedView customizedView) { 62 this.display = display; 63 this.customizedView = customizedView; 64 } 65 66 72 73 public DisplayContext(CustomizedDisplay display, 74 Object window) { 75 this.display = display; 76 this.window = new WeakReference (window); 77 } 78 79 86 87 public CustomizedDisplay getDisplay() { 88 return display; 89 } 90 91 98 99 public CustomizedView getCustomizedView() { 100 return customizedView; 101 } 102 103 107 108 public void setCustomizedView(CustomizedView customizedView) { 109 this.customizedView = customizedView; 110 } 111 112 116 117 public void setWindow(Object window) { 118 this.window = new WeakReference (window); 119 } 120 121 125 126 public Object getWindow() { 127 if (customizedView!=null) 128 return customizedView; 129 else 130 return window==null ? null : window.get(); 131 } 132 133 135 public void addEditor(Object editor) { 136 editors.add(editor); 137 logger.debug("addEditor "+editor+" -> size="+editors.size()); 138 } 139 public void removeEditor(Object editor) { 140 editors.remove(editor); 141 logger.debug("removeEditor "+editor+" -> size="+editors.size()); 142 } 143 public List getEditors() { 144 return (List )editors.clone(); 145 } 146 147 public boolean hasEnabledEditor() { 148 Iterator it = editors.iterator(); 149 while (it.hasNext()) { 150 Object view = it.next(); 151 if (view instanceof FieldEditor && 152 ((FieldEditor)view).isEnabled()) { 153 loggerEdit.debug("Found enabled editor "+view+ 154 "("+((FieldEditor)view).getField()+")"); 155 return true; 156 } 157 } 158 return false; 159 } 160 161 public void setShowButtons(boolean value) { 162 this.showButtons = value; 163 } 164 public boolean showButtons() { 165 return showButtons; 166 } 167 168 170 public String toString() { 171 return "{display="+display+ 172 ",customized="+customizedView+ 173 ",window="+Strings.hex(window==null ? null : window.get())+"}"; 174 } 175 } 176 177 | Popular Tags |