1 22 23 package org.gjt.sp.jedit; 24 25 import java.util.*; 26 import org.gjt.sp.util.Log; 27 28 70 public class EditBus 71 { 72 79 public static void addToBus(EBComponent comp) 80 { 81 synchronized(components) 82 { 83 components.add(comp); 84 copyComponents = null; 85 } 86 } 88 93 public static void removeFromBus(EBComponent comp) 94 { 95 synchronized(components) 96 { 97 components.remove(comp); 98 copyComponents = null; 99 } 100 } 102 106 public static EBComponent[] getComponents() 107 { 108 synchronized(components) 109 { 110 if (copyComponents == null) 111 { 112 copyComponents = (EBComponent[])components.toArray( 113 new EBComponent[components.size()]); 114 } 115 return copyComponents; 116 } 117 } 119 124 public static void send(EBMessage message) 125 { 126 Log.log(Log.DEBUG,EditBus.class,message.toString()); 127 128 EBComponent[] comps = getComponents(); 131 132 for(int i = 0; i < comps.length; i++) 133 { 134 try 135 { 136 EBComponent comp = comps[i]; 137 if(Debug.EB_TIMER) 138 { 139 long start = System.currentTimeMillis(); 140 comp.handleMessage(message); 141 long time = (System.currentTimeMillis() - start); 142 if(time != 0) 143 { 144 Log.log(Log.DEBUG,EditBus.class,comp + ": " + time + " ms"); 145 } 146 } 147 else 148 comps[i].handleMessage(message); 149 } 150 catch(Throwable t) 151 { 152 Log.log(Log.ERROR,EditBus.class,"Exception" 153 + " while sending message on EditBus:"); 154 Log.log(Log.ERROR,EditBus.class,t); 155 } 156 } 157 } 159 private static ArrayList components = new ArrayList(); 161 private static EBComponent[] copyComponents; 162 163 private EditBus() {} 165 } 167 | Popular Tags |