1 package rero.gui; 2 3 import rero.gui.windows.*; 4 import rero.ircfw.*; 5 6 import java.util.*; 7 8 import rero.gui.script.*; 10 public class UICapabilities 11 { 12 protected IRCSession clientSession; 13 protected WindowDataListener listeners = null; protected BuiltInLogger logger = null; 15 public UICapabilities(IRCSession _session) 17 { 18 clientSession = _session; 19 logger = new BuiltInLogger(_session); 20 } 21 22 public void logMessage(String window, String text) 23 { 24 if (logger.isEnabled()) 25 logger.logMessage(window, text); 26 } 27 28 public void setQuery(String query) 29 { 30 clientSession.getStatusWindow().setQuery(query); 31 } 32 33 public String getQuery() 34 { 35 return clientSession.getActiveWindow().getQuery(); 36 } 37 38 public boolean isActive(String title) 39 { 40 return (clientSession.getStatusWindow().getQuery().toLowerCase().equals(title.toLowerCase()) || clientSession.isWindow(title)); 41 } 42 43 public boolean isWindow(String title) 44 { 45 return clientSession.isWindow(title); 46 } 47 48 49 protected boolean shouldContinue(String window, String text) 50 { 51 return (text != null && (listeners == null || listeners.shouldContinue(window, text))); 52 } 53 54 55 public void printActive(String text) 56 { 57 if (shouldContinue(clientSession.getActiveWindow().getQuery(), text)) 58 { 59 clientSession.getActiveWindow().flag(); 60 clientSession.getActiveWindow().getDisplay().addText(text); 61 62 if (logger.isEnabled()) 63 logger.logMessage(clientSession.getActiveWindow().getName(), text); 64 } 65 } 66 67 68 public void printAll(String text) 69 { 70 Iterator i = clientSession.getAllWindows().iterator(); 71 while (i.hasNext()) 72 { 73 StatusWindow temp = (StatusWindow)i.next(); 74 if (temp.isLegalWindow() && shouldContinue(temp.getQuery(), text)) 75 { 76 temp.getDisplay().addText(text); 77 78 if (logger.isEnabled()) 79 logger.logMessage(temp.getName(), text); 80 } 81 } 82 83 } 85 86 87 public void printStatus(String text) 88 { 89 if (shouldContinue(clientSession.getStatusWindow().getQuery(), text) && clientSession.getStatusWindow().getDisplay() != null) 90 { 91 clientSession.getStatusWindow().flag(); 92 clientSession.getStatusWindow().getDisplay().addText(text); 93 94 if (logger.isEnabled()) 95 logger.logMessage(StatusWindow.STATUS_NAME, text); 96 } 97 } 98 99 100 public void printNormal(String window, String text) 101 { 102 if (shouldContinue(window, text)) 103 { 104 StatusWindow temp = clientSession.getWindow(window); 105 temp.flag(); 106 temp.getDisplay().addText(text); 107 108 if (logger.isEnabled()) 109 logger.logMessage(temp.getName(), text); 110 } 111 } 112 113 116 public void printToTargets(Set targets, String text, boolean alwaysStatus) 117 { 118 boolean echoToStatus = false; 119 boolean echoHasOccured = false; 120 121 Iterator i = targets.iterator(); 122 123 String query = getQuery(); 124 125 while (i.hasNext()) 126 { 127 String target = (String )i.next(); 128 if (clientSession.isWindow(target)) 129 { 130 printNormal(target, text); 131 echoHasOccured = true; 132 133 if (target.equals(query)) 134 alwaysStatus = false; 135 } 136 else 137 { 138 echoToStatus = true; 139 } 140 } 141 142 if (echoToStatus || !echoHasOccured || alwaysStatus) 143 { 144 printStatus(text); 145 } 146 } 147 148 149 public void printChunk(String window, String normal, String chunks[], double percentage) 150 { 151 if (shouldContinue(window, normal)) 152 { 153 clientSession.getWindow(window).getDisplay().addTextTable(normal, chunks, percentage); 154 155 if (logger.isEnabled()) 156 logger.logMessage(clientSession.getWindow(window).getName(), normal); 157 } 158 } 159 160 public void printRaw(String window, String text) 161 { 162 StatusWindow temp = clientSession.getWindow(window); 163 164 if (window != null) 165 { 166 temp.flag(); 167 temp.getDisplay().addText(text); 168 169 if (logger.isEnabled()) 170 logger.logMessage(temp.getName(), text); 171 } 172 } 173 174 public void clearScreen(String window) 175 { 176 if (window == null || window.length() == 0) 177 { 178 clientSession.getActiveWindow().getDisplay().clear(); 179 } 180 else if ("%ALL%".equals(window)) 181 { 182 clientSession.getStatusWindow().getDisplay().clear(); 183 clientSession.getStatusWindow().unflag(); 184 185 Iterator i = clientSession.getAllWindows().iterator(); 186 while (i.hasNext()) 187 { 188 StatusWindow swindow = (StatusWindow)i.next(); 189 190 if (swindow.isLegalWindow()) 191 { 192 swindow.getDisplay().clear(); 193 swindow.unflag(); 194 } 195 } 196 } 197 else 198 { 199 clientSession.getWindow(window).getDisplay().clear(); 200 clientSession.getWindow(window).unflag(); 201 } 202 } 203 204 public void openQueryWindow(String nickname, boolean selected) 205 { 206 if (! clientSession.isWindow(nickname)) 207 { 208 QueryWindow temp = clientSession.createQueryWindow(nickname, selected); 209 } 210 } 211 212 public void closeWindow(String window) 213 { 214 if (clientSession.isWindow(window)) 215 { 216 clientSession.getWindow(window).getWindow().closeWindow(); 217 } 218 } 219 220 public void openListWindow() 221 { 222 clientSession.createListWindow(); 223 } 224 225 public void openDCCWindow() 226 { 227 clientSession.createDCCWindow(); 228 } 229 230 public void openChannelWindow(Channel channel) 231 { 232 if (! clientSession.isWindow(channel.getName())) 233 { 234 ChannelWindow temp = clientSession.createChannelWindow(channel); 235 } 236 } 237 238 public void notifyActiveWindow() 239 { 240 clientSession.getActiveWindow().touch(); 242 } 243 244 public void notifyWindow(String window) 245 { 246 clientSession.getWindow(window).touch(); 248 } 249 250 public void renameWindow(String old, String newtitle) 251 { 252 clientSession.renameWindow(old, newtitle); 253 } 254 255 public void setListener(WindowDataListener l) 256 { 257 listeners = l; 258 } 259 260 public void showSearchDialog(String window) 261 { 262 StatusWindow temp = clientSession.getWindow(window); 263 264 if (temp.isLegalWindow()) 265 { 266 if (window.equals("%STATUS%")) { window = "Status"; } 267 268 temp.getDisplay().showSearchDialog("Search " + window); 269 } 270 } 271 } 272 | Popular Tags |