jTracer  1.03
Stack trace visualization tool
TraceBar.java
Go to the documentation of this file.
1 
7 package org.libcsdbg.jtracer;
8 
9 import java.util.Hashtable;
10 import java.util.Calendar;
11 
12 import java.awt.Font;
13 import java.awt.Color;
14 import java.awt.Insets;
15 import java.awt.GridBagLayout;
16 import java.awt.GridBagConstraints;
17 
18 import javax.swing.JPanel;
19 import javax.swing.JLabel;
20 import javax.swing.BorderFactory;
21 import javax.swing.border.EtchedBorder;
22 
28 public class TraceBar extends JPanel
29 {
31  private static final long serialVersionUID = 0x00;
32 
34  private Hashtable<String, JLabel> fields = null;
35 
36 
40  TraceBar()
41  {
42  super();
43  fields = new Hashtable<String, JLabel>();
44  GridBagLayout lm = new GridBagLayout();
45  GridBagConstraints c = new GridBagConstraints();
46  setLayout(lm);
47 
48  JPanel field = createField("message");
49  c.gridx = c.gridy = 0;
50  c.weightx = 1;
51  c.insets = new Insets(0, 0, 0, 0);
52  c.fill = GridBagConstraints.HORIZONTAL;
53  lm.setConstraints(field, c);
54  add(field);
55 
56  field = createField("timestamp");
57  c.gridx++;
58  c.weightx = 0;
59  c.fill = GridBagConstraints.NONE;
60  lm.setConstraints(field, c);
61  add(field);
62 
63  field = createField("address");
64  c.gridx++;
65  lm.setConstraints(field, c);
66  add(field);
67  }
68 
69 
77  public void setField(String nm, String text)
78  {
79  fields.get(nm).setText(text);
80  }
81 
82 
88  public void setMessage(String msg)
89  {
90  fields.get("message").setText(msg);
91  }
92 
93 
101  public void setTimestamp(Long microtm)
102  {
103  JLabel field = fields.get("timestamp");
104 
105  Calendar c = Calendar.getInstance();
106  c.setTimeInMillis(microtm / 1000);
107 
108  int d1 = c.get(Calendar.DATE);
109  int d2 = c.get(Calendar.MONTH) + 1;
110  int d3 = c.get(Calendar.YEAR);
111 
112  String text = "";
113  text += ((d1 < 10) ? "0" : "") + d1 + "/";
114  text += ((d2 < 10) ? "0" : "") + d2 + "/" + d3 + " ";
115 
116  int h1 = c.get(Calendar.HOUR);
117  int h2 = c.get(Calendar.MINUTE);
118  int h3 = c.get(Calendar.SECOND);
119 
120  text += ((h1 < 10) ? "0" : "") + h1 + ":";
121  text += ((h2 < 10) ? "0" : "") + h2 + ":";
122  text += ((h3 < 10) ? "0" : "") + h3;
123 
124  field.setText(text);
125  }
126 
127 
135  public void setAddress(String addr, int port)
136  {
137  fields.get("address").setText(addr + ":" + port);
138  }
139 
140 
144  public void clear()
145  {
146  fields.get("message").setText("n/a");
147  fields.get("timestamp").setText("n/a");
148  fields.get("address").setText("n/a");
149  }
150 
151 
159  private JPanel createField(String nm)
160  {
161  GridBagLayout lm = new GridBagLayout();
162  GridBagConstraints c = new GridBagConstraints();
163  JPanel retval = new JPanel(lm);
164 
165  Registry conf = Registry.getCurrent();
166  retval.setBackground((Color) conf.get("statusbar", "bgcolor"));
167  retval.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
168 
169  JLabel field = new JLabel("n/a");
170  field.setFont((Font) conf.get("statusbar", "font"));
171  field.setForeground((Color) conf.get("statusbar", "fgcolor"));
172 
173  if (nm.equals("message")) {
174  c.weightx = 1;
175  c.anchor = GridBagConstraints.EAST;
176  }
177 
178  c.insets = new Insets(1, 8, 1, 8);
179  lm.setConstraints(field, c);
180  retval.add(field);
181 
182  fields.put(nm, field);
183  return retval;
184  }
185 }
186 
static final long serialVersionUID
Class version.
Definition: TraceBar.java:31
Object get(String section, String key)
Get an entry.
Definition: Registry.java:151
void setField(String nm, String text)
Set the text of any field.
Definition: TraceBar.java:77
Configuration registry.
Definition: Registry.java:41
JPanel createField(String nm)
Create one of the fields.
Definition: TraceBar.java:159
void setAddress(String addr, int port)
Set the address field.
Definition: TraceBar.java:135
void setTimestamp(Long microtm)
Set the trace timestamp field.
Definition: TraceBar.java:101
void setMessage(String msg)
Set the message field.
Definition: TraceBar.java:88
void clear()
Clear all fields (set them to their default value)
Definition: TraceBar.java:144
A bar for various trace details (exception message, timestamp e.t.c) with multiple indicators and con...
Definition: TraceBar.java:28
Hashtable< String, JLabel > fields
Indicator list.
Definition: TraceBar.java:34