7 package org.libcsdbg.jtracer;
9 import java.util.Hashtable;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ActionListener;
14 import java.awt.Color;
15 import java.awt.Insets;
16 import java.awt.GridBagLayout;
17 import java.awt.GridBagConstraints;
18 import java.awt.EventQueue;
20 import javax.swing.JPanel;
21 import javax.swing.JLabel;
22 import javax.swing.Timer;
23 import javax.swing.SwingUtilities;
24 import javax.swing.BorderFactory;
25 import javax.swing.border.EtchedBorder;
32 public class StatusBar extends JPanel implements ActionListener
44 private Hashtable<String, JLabel>
fields = null;
55 fields =
new Hashtable<String, JLabel>();
56 GridBagLayout lm =
new GridBagLayout();
57 GridBagConstraints c =
new GridBagConstraints();
61 c.gridx = c.gridy = 0;
63 c.insets =
new Insets(0, 0, 0, 0);
64 c.fill = GridBagConstraints.HORIZONTAL;
65 lm.setConstraints(field, c);
71 c.fill = GridBagConstraints.NONE;
72 lm.setConstraints(field, c);
77 lm.setConstraints(field, c);
82 lm.setConstraints(field, c);
87 lm.setConstraints(field, c);
103 public void setMessage(
final String msg,
final boolean normal)
106 if (EventQueue.isDispatchThread()) {
107 JLabel field = fields.get(
"status");
110 Registry conf = Registry.getCurrent();
112 field.setForeground((Color) conf.get(
"statusbar",
"fgcolor-error"));
113 field.setIcon(conf.loadIcon(
"stat_err.png"));
116 field.setForeground((Color) conf.get(
"statusbar",
"fgcolor"));
117 field.setIcon(conf.loadIcon(
"stat_ok.png"));
136 SwingUtilities.invokeLater(
new Worker());
139 catch (Throwable t) {
154 JLabel field = fields.get(nm +
"Count");
156 String text = cnt +
" " + nm;
161 Registry conf = Registry.getCurrent();
164 bg = (Color) conf.
get(
"statusbar",
"bgcolor-counter-active");
166 bg = (Color) conf.get(
"statusbar",
"bgcolor");
168 field.getParent().setBackground(bg);
192 if (EventQueue.isDispatchThread()) {
193 Registry conf = Registry.getCurrent();
194 Color bg = (Color) conf.
get(
"statusbar",
"bgcolor-uptime-active");
195 fields.get(
"uptime").getParent().setBackground(bg);
197 timer =
new Timer(1000,
this);
198 timer.setActionCommand(
"Uptime timer");
199 timer.setCoalesce(
false);
217 SwingUtilities.invokeLater(
new Worker());
220 catch (Throwable t) {
247 if (EventQueue.isDispatchThread()) {
251 Registry conf = Registry.getCurrent();
252 JLabel field = fields.get(
"uptime");
253 field.getParent().setBackground((Color) conf.get(
"statusbar",
"bgcolor"));
256 field.setForeground((Color) conf.
get(
"statusbar",
"fgcolor-error"));
279 SwingUtilities.invokeLater(
new Worker());
282 catch (Throwable t) {
299 GridBagLayout lm =
new GridBagLayout();
300 GridBagConstraints c =
new GridBagConstraints();
301 JPanel retval =
new JPanel(lm);
303 Registry conf = Registry.getCurrent();
304 retval.setBackground((Color) conf.
get(
"statusbar",
"bgcolor"));
305 retval.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
307 JLabel field =
new JLabel(text);
308 field.setFont((Font) conf.
get(
"statusbar",
"font"));
309 field.setForeground((Color) conf.
get(
"statusbar",
"fgcolor"));
311 if (tag.equals(
"status")) {
312 field.setIcon(conf.loadIcon(
"stat_ok.png"));
313 field.setIconTextGap(6);
315 c.anchor = GridBagConstraints.EAST;
318 c.insets =
new Insets(1, 8, 1, 8);
319 lm.setConstraints(field, c);
322 fields.put(tag, field);
333 long hours = now / 3600;
336 long minutes = now / 60;
337 long seconds = now % 60;
339 String tm =
"Uptime ";
340 tm += ((hours < 10) ?
"0" :
"") + hours +
":";
341 tm += ((minutes < 10) ?
"0" :
"") + minutes +
":";
342 tm += ((seconds < 10) ?
"0" :
"") + seconds;
344 fields.get(
"uptime").setText(tm);
360 catch (Throwable t) {
void stopUptimeTimer()
Stop and reset the server uptime timer.
Object get(String section, String key)
Get an entry.
void setIndicators(int sessions, int traces)
Set both the counter indicators.
void stopUptimeTimer(final boolean reset, final boolean normal)
Stop and reset the server uptime timer.
Application statusbar with multiple indicators and configurable styles.
void startUptimeTimer()
Start the server uptime timer.
void setIndicator(String nm, int cnt)
Set one of the counter indicators.
long uptime
Server uptime (seconds)
static final long serialVersionUID
Class version.
Hashtable< String, JLabel > fields
Indicator list.
void setMessage(final String msg, final boolean normal)
Set the status message.
void renderUptime()
Update the server uptime field.
JPanel createField(String tag, String text)
Create one of the fields.
void actionPerformed(ActionEvent event)
Handler for events fired from the server uptime timer.