1 19 20 package org.openide.explorer; 21 22 import org.openide.util.lookup.AbstractLookup; 23 import org.openide.util.lookup.InstanceContent; 24 import org.openide.windows.TopComponent; 25 import org.openide.nodes.Node; 26 import java.util.Set ; 27 import org.openide.util.actions.SystemAction; 28 import java.awt.event.ActionEvent ; 29 import javax.swing.Action ; 30 import java.beans.PropertyChangeListener ; 31 import java.beans.PropertyChangeEvent ; 32 import org.openide.windows.WindowManager; 33 import javax.swing.JFrame ; 34 import java.awt.Frame ; 35 import org.openide.windows.Workspace; 36 import org.openide.util.NotImplementedException; 37 import java.awt.Image ; 38 import java.beans.PropertyChangeSupport ; 39 import org.openide.util.Lookup; 40 import java.util.ArrayList ; 41 42 45 public abstract class ActionsInfraHid { 46 47 private ActionsInfraHid() {} 48 49 public static final UsefulThings UT; 50 static { 51 String tm = System.getProperty("org.openide.TopManager"); 52 if (tm != null) throw new IllegalStateException ("TopManager was initialized already: " + tm); 53 String lookup = System.getProperty("org.openide.util.Lookup"); 54 if (lookup != null && !lookup.equals(UsefulLookup.class.getName())) throw new IllegalStateException ("Already had a Lookup installed: " + lookup); 55 System.setProperty("org.openide.util.Lookup", UsefulLookup.class.getName()); 56 UT = new UsefulThings(); 57 Lookup l = Lookup.getDefault(); 58 if (!(l instanceof UsefulLookup)) throw new IllegalStateException (Lookup.getDefault().toString()); 59 if (l.lookup(TopComponent.Registry.class) == null) throw new IllegalStateException ("no TC.R"); 60 } 63 public static void main(String [] args) { 64 System.err.println("ActionsInfraHid OK."); 65 } 66 67 69 public static final class UsefulLookup extends AbstractLookup { 70 public UsefulLookup() { 71 super(getContent()); 72 } 73 private static AbstractLookup.Content getContent() { 74 InstanceContent c = new InstanceContent(); 75 c.add(UT); 76 c.add(ActionsInfraHid.class.getClassLoader()); 77 78 return c; 79 } 80 } 81 82 84 public static final class UsefulThings implements TopComponent.Registry, org.openide.util.ContextGlobalProvider { 85 private TopComponent activated; 87 88 private InstanceContent ic = new InstanceContent (); 89 90 private Lookup lookup = new AbstractLookup (ic); 91 92 private final PropertyChangeSupport pcs = new PropertyChangeSupport (this); 93 94 public void addPropertyChangeListener(PropertyChangeListener l) { 95 pcs.addPropertyChangeListener(l); 96 } 97 98 public void removePropertyChangeListener(PropertyChangeListener l) { 99 pcs.removePropertyChangeListener(l); 100 } 101 102 private void firePropertyChange(String p, Object o, Object n) { 103 pcs.firePropertyChange(p, o, n); 104 } 105 106 107 public TopComponent getActivated() { 108 return activated; 109 } 110 111 public void setActivated(TopComponent nue) { 112 TopComponent old = activated; 113 activated = nue; 114 firePropertyChange(PROP_ACTIVATED, old, nue); 115 updateLookup (); 116 } 117 118 private Node[] activatedNodes = new Node[0]; 119 private Node[] currentNodes = null; 120 121 public Node[] getActivatedNodes() { 122 return activatedNodes; 123 } 124 125 public Node[] getCurrentNodes() { 126 return currentNodes; 127 } 128 129 public void setCurrentNodes(Node[] nue) { 130 if (nue != null) { 131 Node[] old = activatedNodes; 132 activatedNodes = nue; 133 firePropertyChange(PROP_ACTIVATED_NODES, old, nue); 134 } 135 Node[] old = currentNodes; 136 currentNodes = nue; 137 firePropertyChange(PROP_CURRENT_NODES, old, nue); 138 updateLookup (); 139 } 140 141 private Set opened = null; 142 143 public Set getOpened() { 144 return opened; 145 } 146 147 public void setOpened(Set nue) { 148 Set old = opened; 149 opened = nue; 150 firePropertyChange(PROP_OPENED, old, nue); 151 } 152 153 private void updateLookup () { 154 ArrayList items = new ArrayList (); 155 if (currentNodes != null) { 156 for (int i = 0; i < currentNodes.length; i++) { 157 items.add (new IPair (currentNodes[i])); 158 } 159 } else { 160 items.add (IPair.NULL_NODES); 161 } 162 if (activated != null) { 163 items.add (new IPair (activated.getActionMap ())); 164 } 165 ic.setPairs (items); 166 } 167 168 public Lookup createGlobalContext() { 172 return lookup; 173 } 174 } 175 176 178 public static final class WaitPCL implements PropertyChangeListener { 179 180 public int gotit = 0; 181 182 private final String prop; 183 public WaitPCL(String p) { 184 prop = p; 185 } 186 public synchronized void propertyChange(PropertyChangeEvent evt) { 187 if (prop == null || prop.equals(evt.getPropertyName())) { 188 gotit++; 189 notifyAll(); 190 } 191 } 192 public boolean changed() { 193 return changed(1500); 194 } 195 public synchronized boolean changed(int timeout) { 196 if (gotit > 0) { 197 return true; 198 } 199 try { 200 wait(timeout); 201 } catch (InterruptedException ie) { 202 ie.printStackTrace(); 203 } 204 return gotit > 0; 205 } 206 } 207 208 public static void doGC() { 210 doGC(10); 211 } 212 public static void doGC(int count) { 213 ArrayList l = new ArrayList (count); 214 while (count-- > 0) { 215 System.gc(); 216 System.runFinalization(); 217 l.add(new byte[1000]); 218 } 219 } 220 221 private static final class IPair extends AbstractLookup.Pair { 222 private Object obj; 223 224 public static final IPair NULL_NODES = new IPair ( 225 new org.openide.nodes.AbstractNode (org.openide.nodes.Children.LEAF) 226 ); 227 228 public IPair (Object obj) { 229 this.obj = obj; 230 } 231 232 protected boolean creatorOf(Object obj) { 233 return this.obj == obj; 234 } 235 236 public String getDisplayName() { 237 return obj.toString (); 238 } 239 240 public String getId() { 241 if (this == NULL_NODES) { 242 return "none"; } 244 return obj.toString (); 245 } 246 247 public Object getInstance() { 248 if (this == NULL_NODES) { 249 return null; 250 } 251 return obj; 252 } 253 254 public Class getType() { 255 return obj.getClass(); 256 } 257 258 protected boolean instanceOf(Class c) { 259 return c.isInstance(obj); 260 } 261 262 } } 264 | Popular Tags |