KickJava   Java API By Example, From Geeks To Geeks.

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


1 package rero.gui.windows;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import javax.swing.event.*;
6 import text.*;
7
8 import rero.client.*;
9 import rero.client.notify.*; // lag checking mechanism is part of the notify list implementation (it piggy backs off of it)
10

11 import javax.swing.border.*;
12
13 import rero.gui.*;
14 import rero.gui.background.*;
15 import java.util.*;
16
17 import rero.config.*;
18
19 public class WindowStatusBar extends BackgroundToolBar implements IRCAwareComponent, ChangeListener, ClientStateListener
20 {
21    protected LabelDisplay contents;
22    protected HashMap event;
23    protected StatusWindow parent;
24    protected Capabilities capabilities;
25    protected long lastRehash;
26
27    public void installCapabilities(Capabilities c)
28    {
29        capabilities = c;
30
31        Lag temp = (Lag)capabilities.getDataStructure("lag");
32        temp.addChangeListener(this);
33    }
34
35    public void stateChanged(ChangeEvent ev)
36    {
37        rehash();
38        repaint();
39    }
40
41    public WindowStatusBar(StatusWindow _parent)
42    {
43       contents = new LabelDisplay();
44
45       setFloatable(false);
46
47       setLayout(new BorderLayout());
48       add(contents, BorderLayout.CENTER);
49
50       event = new HashMap();
51
52       parent = _parent;
53
54       setOpaque(false);
55
56       setBorder(BorderFactory.createEmptyBorder(0, TextSource.UNIVERSAL_TWEAK, 0, TextSource.UNIVERSAL_TWEAK));
57 // setBorder(null);
58

59       rehashValues();
60
61       ClientState.getClientState().addClientStateListener("ui.sbarlines", this);
62       ClientState.getClientState().addClientStateListener("ui.showsbar", this);
63       ClientState.getClientState().addClientStateListener("ui.font", this);
64    }
65
66    public Dimension getPreferredSize()
67    {
68       if (contents.getTotalLines() == 0)
69       {
70          return new Dimension(Integer.MAX_VALUE, 1);
71       }
72       return super.getPreferredSize();
73    }
74
75    public void rehashValues()
76    {
77       if (ClientState.getClientState().isOption("ui.showsbar", true))
78       {
79          int lines = ClientState.getClientState().getInteger("ui.sbarlines", ClientDefaults.ui_sbarlines);
80          contents.setNumberOfLines(lines);
81       }
82       else
83       {
84          contents.setNumberOfLines(0);
85       }
86    }
87
88    public void propertyChanged(String JavaDoc var, String JavaDoc parms)
89    {
90       if (var.equals("statusbar"))
91       {
92          repaint();
93       }
94       else
95       {
96          SwingUtilities.invokeLater(new Runnable JavaDoc()
97          {
98             public void run()
99             {
100                rehashValues();
101                rehash();
102                revalidate();
103                repaint();
104             }
105          });
106       }
107    }
108
109    public void rehash()
110    {
111       if (capabilities == null)
112          return;
113
114       event.put("$query", parent.getQuery());
115       event.put("$window", parent.getName());
116
117       for (int x = 0; x < contents.getTotalLines(); x++)
118       {
119          event.put("$line", ""+x);
120
121          String JavaDoc lhs = capabilities.getOutputCapabilities().parseSet(event, "SBAR_LEFT");
122          String JavaDoc rhs = capabilities.getOutputCapabilities().parseSet(event, "SBAR_RIGHT");
123
124          if (lhs == null) { lhs = ""; }
125          if (rhs == null) { rhs = ""; }
126
127          contents.setLine(lhs, rhs, x);
128       }
129
130       lastRehash = System.currentTimeMillis();
131    }
132
133    public void paint(Graphics g)
134    {
135       if ((System.currentTimeMillis() - lastRehash) > 10000)
136       {
137          rehash(); // force a rehash every 10 seconds regardless...
138
}
139
140       super.paint(g);
141    }
142
143 /* protected void finalize()
144    {
145      System.out.println("Finalizing Window Status Bar");
146    } */

147 }
148
Popular Tags