KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > gui > windows > StatusWindow


1 package rero.gui.windows;
2
3 import rero.gui.*;
4 import rero.gui.input.*;
5 import rero.gui.background.*;
6 import javax.swing.*;
7 import java.awt.*;
8 import java.awt.event.*;
9
10 import rero.client.*;
11 import java.util.HashMap JavaDoc;
12 import rero.util.ClientUtils;
13
14 import rero.gui.toolkit.OrientedToolBar;
15 import rero.ircfw.*;
16
17 import rero.bridges.menu.*;
18
19 import text.*;
20 import rero.config.*;
21
22 public class StatusWindow extends BackgroundPanel implements IRCAwareComponent, Comparable JavaDoc
23 {
24    public static final String JavaDoc STATUS_NAME = "%STATUS%"; // a constant representing the name of the status window as far as jIRCii goes...
25

26    protected WrappedDisplay display;
27    protected InputField input;
28    protected WindowStatusBar statusbar;
29
30    protected JToggleButton button; // for the switchbar homez.
31
protected ImageIcon icon; // jEAH bABY
32

33    protected ClientWindow frame;
34    protected String JavaDoc query = "";
35
36    protected Capabilities capabilities;
37
38    protected Color defaultForegroundColor;
39
40    protected MenuBridge menuManager;
41
42    public void cleanup()
43    {
44       if (display != null)
45         display.clear();
46    }
47
48    public void touch()
49    {
50       statusbar.rehash();
51       statusbar.repaint();
52    }
53
54    protected void maybeShowPopup(MouseEvent ev, String JavaDoc desc)
55    {
56       if (ev.isPopupTrigger())
57       {
58          JPopupMenu menu = getPopupMenu(desc, ClientUtils.getEventHashMap(getName(), getName()));
59
60          if (menu != null)
61          {
62             menu.show((JComponent)ev.getComponent(), ev.getX(), ev.getY());
63             ev.consume();
64          }
65       }
66    }
67
68    public void installCapabilities(Capabilities c)
69    {
70       capabilities = c;
71       statusbar.installCapabilities(c);
72
73       menuManager = (MenuBridge)c.getDataStructure("menuBridge");
74
75       input.addMouseListener(new MouseAdapter()
76       {
77           public void mousePressed(MouseEvent ev)
78           {
79              maybeShowPopup(ev, "input");
80           }
81
82           public void mouseReleased(MouseEvent ev)
83           {
84              maybeShowPopup(ev, "input");
85           }
86
87           public void mouseClicked(MouseEvent ev)
88           {
89              maybeShowPopup(ev, "input");
90           }
91       });
92
93       MouseAdapter normal = new MouseAdapter()
94       {
95           public void mousePressed(MouseEvent ev)
96           {
97              maybeShowPopup(ev, getWindowType());
98           }
99
100           public void mouseReleased(MouseEvent ev)
101           {
102              maybeShowPopup(ev, getWindowType());
103           }
104
105           public void mouseClicked(MouseEvent ev)
106           {
107              maybeShowPopup(ev, getWindowType());
108           }
109       };
110
111       display.addMouseListener(normal);
112    }
113
114    public JPopupMenu getPopupMenu(String JavaDoc name, HashMap JavaDoc event)
115    {
116       return menuManager.getPopupMenu(name, event);
117    }
118
119    public InputField getInput()
120    {
121       return input;
122    }
123
124    public WrappedDisplay getDisplay()
125    {
126       return display;
127    }
128
129    public WindowStatusBar getStatusBar()
130    {
131       return statusbar;
132    }
133
134    public void flag()
135    {
136       if (!getWindow().isSelected() && SwitchBarOptions.isHilightOn())
137       {
138           getButton().setForeground(SwitchBarOptions.getHighlightColor());
139       }
140    }
141
142    public void unflag()
143    {
144       if (SwitchBarOptions.isHilightOn())
145       {
146          getButton().setForeground(defaultForegroundColor);
147          getButton().repaint();
148       }
149    }
150
151
152    public void init(ClientWindow _frame)
153    {
154       frame = _frame;
155       frame.addWindowListener(new ClientWindowStuff());
156
157       setLayout(new BorderLayout());
158
159       display = new WrappedDisplay();
160       input = new InputField();
161       statusbar = new WindowStatusBar(this);
162
163       add(display, BorderLayout.CENTER);
164
165       JPanel space = new JPanel();
166       space.setLayout(new BorderLayout());
167
168       space.add(statusbar, BorderLayout.NORTH);
169       space.add(input, BorderLayout.SOUTH);
170
171       space.setOpaque(false);
172
173       add(space, BorderLayout.SOUTH);
174
175       frame.setContentPane(this);
176
177       setTitle(getName());
178       frame.setIcon(getImageIcon());
179    }
180
181    public String JavaDoc getQuery()
182    {
183       return query;
184    }
185
186    public void setQuery(String JavaDoc q)
187    {
188       query = q;
189       statusbar.stateChanged(null); // I know that the statusbar doesn't do anything with the 'state' variable
190
}
191
192    public void setTitle(String JavaDoc title)
193    {
194       if (title != null && title.equals("%STATUS%"))
195       {
196          title = "Status";
197       }
198
199       frame.setTitle(title);
200    }
201
202    public ClientWindow getWindow()
203    {
204       return frame;
205    }
206
207    public String JavaDoc getTitle()
208    {
209       return frame.getTitle();
210    }
211
212    public void setName(String JavaDoc name)
213    {
214       getButton().setText(getName());
215       getButton().repaint();
216       setTitle(getName());
217       touch();
218    }
219
220    public String JavaDoc getName()
221    {
222       return "%STATUS%";
223    }
224
225    public ImageIcon getImageIcon()
226    {
227       if (icon == null)
228       {
229          icon = new ImageIcon(ClientState.getClientState().getResource("status.gif"));
230       }
231
232       return icon;
233    }
234
235    public JToggleButton getButton()
236    {
237       if (button == null)
238       {
239          if (getName().equals("%STATUS%"))
240          {
241             button = new JToggleButton("Status", getImageIcon());
242          }
243          else
244          {
245             button = new JToggleButton(getName(), getImageIcon());
246          }
247
248          button.setHorizontalAlignment(JToggleButton.LEFT);
249          button.setMargin(new Insets(0, 0, 0, 5));
250          button.setFocusPainted(false);
251
252          button.setPreferredSize(new Dimension(OrientedToolBar.BUTTON_FIXED_WIDTH, button.getPreferredSize().height));
253
254          button.setSelected(false);
255
256          defaultForegroundColor = button.getForeground();
257
258          button.addMouseListener(new MouseAdapter()
259          {
260              public void mousePressed(MouseEvent ev)
261              {
262                  // Shift+Click closes windows
263
int onmask = KeyEvent.SHIFT_DOWN_MASK | KeyEvent.BUTTON1_DOWN_MASK;
264                  if ((ev.getModifiersEx() & onmask) == onmask)
265                  {
266                      String JavaDoc text = ((JToggleButton) ev.getSource()).getText();
267                      IRCSession session = capabilities.getGlobalCapabilities().getSessionManager().getActiveSession();
268                      session.getWindow(text).getWindow().closeWindow();
269                  } else {
270                      maybeShowPopup(ev, "switchbar");
271                  }
272              }
273
274              public void mouseReleased(MouseEvent ev)
275              {
276                 maybeShowPopup(ev, "switchbar");
277              }
278
279              public void mouseClicked(MouseEvent ev)
280              {
281                 maybeShowPopup(ev, "switchbar");
282              }
283          });
284       }
285
286       return button;
287    }
288
289    protected class ClientWindowStuff implements ClientWindowListener
290    {
291       public void onActive(ClientWindowEvent ev)
292       {
293          unflag();
294       }
295       public void onOpen(ClientWindowEvent ev) { }
296       public void onInactive(ClientWindowEvent ev) { }
297       public void onMinimize(ClientWindowEvent ev) { }
298       public void onClose(ClientWindowEvent ev)
299       {
300          cleanup();
301       }
302    }
303
304    public String JavaDoc getWindowType()
305    {
306       return "Status";
307    }
308
309    public int compareTo(Object JavaDoc o)
310    {
311       StatusWindow temp = (StatusWindow)o;
312
313       if (compareWindowType() == temp.compareWindowType())
314       {
315          return this.getName().toUpperCase().compareTo(((StatusWindow)o).getName().toUpperCase());
316       }
317
318       return compareWindowType() - temp.compareWindowType();
319    }
320
321    public int compareWindowType()
322    {
323       return 1;
324    }
325
326    public boolean isLegalWindow()
327    {
328       return true;
329    }
330
331 /* protected void finalize()
332    {
333       System.out.println("Finalizing " + getWindowType() + ", " + getName());
334    } */

335 }
336
Popular Tags