KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > gui > UICapabilities


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.*; // for the WindowDataListener
9

10 public class UICapabilities
11 {
12    protected IRCSession clientSession;
13    protected WindowDataListener listeners = null; // we're only going to have one listener and that is the collapsed
14
protected BuiltInLogger logger = null;
15                                                       // listener for the scripts.
16
public UICapabilities(IRCSession _session)
17    {
18       clientSession = _session;
19       logger = new BuiltInLogger(_session);
20    }
21
22    public void logMessage(String JavaDoc window, String JavaDoc text)
23    {
24       if (logger.isEnabled())
25         logger.logMessage(window, text);
26    }
27
28    public void setQuery(String JavaDoc query)
29    {
30       clientSession.getStatusWindow().setQuery(query);
31    }
32
33    public String JavaDoc getQuery()
34    {
35       return clientSession.getActiveWindow().getQuery();
36    }
37
38    public boolean isActive(String JavaDoc title)
39    {
40       return (clientSession.getStatusWindow().getQuery().toLowerCase().equals(title.toLowerCase()) || clientSession.isWindow(title));
41    }
42
43    public boolean isWindow(String JavaDoc title)
44    {
45       return clientSession.isWindow(title);
46    }
47
48    /** checks the listeners to make sure text is approved by on window events, also makes sure text is not null */
49    protected boolean shouldContinue(String JavaDoc window, String JavaDoc text)
50    {
51       return (text != null && (listeners == null || listeners.shouldContinue(window, text)));
52    }
53
54    /** prints text to the active window, if no window is active text is printed to the status window */
55    public void printActive(String JavaDoc 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    /** prints text to all open windows for the current server. By all I mean *all* open windows. Window buttons are not flagged. */
68    public void printAll(String JavaDoc 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 // printStatus(text);
84
}
85
86    /** prints text directly to the status window. */
87    public void printStatus(String JavaDoc 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    /** prints text to the specified window. If the window doesn't exist the text goes to the status window, simple enough */
100    public void printNormal(String JavaDoc window, String JavaDoc 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    /** prints a message to the window for each target (if it exists), if there is no window for any of the targets output
114       goes to the status window, if any of the targets are handled in the status window the text is echo'd at most once to
115       the status window */

116    public void printToTargets(Set targets, String JavaDoc text, boolean alwaysStatus)
117    {
118       boolean echoToStatus = false;
119       boolean echoHasOccured = false;
120
121       Iterator i = targets.iterator();
122
123       String JavaDoc query = getQuery();
124
125       while (i.hasNext())
126       {
127          String JavaDoc target = (String JavaDoc)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    /** prints a chunk of text to the specified window, a special case used for /names formatting */
149    public void printChunk(String JavaDoc window, String JavaDoc normal, String JavaDoc 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 JavaDoc window, String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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       // Tells the window that something important hath happened. Update its state.
241
clientSession.getActiveWindow().touch();
242    }
243
244    public void notifyWindow(String JavaDoc window)
245    {
246       // Tells the window that something important hath happened. Update its state.
247
clientSession.getWindow(window).touch();
248    }
249
250    public void renameWindow(String JavaDoc old, String JavaDoc 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 JavaDoc 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