jTracer  1.03
Stack trace visualization tool
TraceTools.java
Go to the documentation of this file.
1 
7 package org.libcsdbg.jtracer;
8 
9 import java.beans.PropertyChangeEvent;
10 import java.beans.PropertyChangeListener;
11 
12 import java.awt.event.ActionListener;
13 import java.awt.Insets;
14 import java.awt.Component;
15 
16 import javax.swing.JToolBar;
17 
23 public class TraceTools extends JToolBar implements PropertyChangeListener
24 {
26  private static final long serialVersionUID = 0x00;
27 
29  private ActionListener handler = null;
30 
31 
37  TraceTools(ActionListener owner)
38  {
39  super();
40  handler = owner;
41  Registry conf = Registry.getCurrent();
42 
43  /*
44  * Setting a new border removes the float handle. To properly set the border
45  * get the current (probably matte) border and set its properties
46  */
47  setName((String) conf.get("generic", "name") + " tools");
48  setRollover(false);
49 
50  add(createTool("Start"));
51  add(createTool("Stop"));
52  add(createTool("Restart"));
53  addSeparator();
54 
55  add(createTool("Select previous"));
56  add(createTool("Select next"));
57  add(createTool("Close"));
58  addSeparator();
59 
60  add(createTool("Cascade"));
61  add(createTool("Minimize all"));
62  add(createTool("Restore all"));
63  add(createTool("Close all"));
64  addSeparator();
65 
66  add(createTool("Find"));
67  add(createTool("Preferences"));
68  }
69 
70 
78  private Button createTool(String cmd)
79  {
80  String nm = cmd.toLowerCase().replace(' ', '_') + "24.png";
81  Button retval = new Button(nm, cmd, handler);
82  retval.setMargin(new Insets(2, 2, 2, 2));
83  return retval;
84  }
85 
86 
98  private void renderTool(Component c, int index, String key, Object val)
99  {
100  Boolean how = (Boolean) val;
101 
102  if (key.equals("isServing"))
103  switch (index) {
104  case 0:
105  c.setEnabled(!how);
106  break;
107 
108  case 1:
109  case 2:
110  c.setEnabled(how);
111  }
112 
113  else if (key.equals("hasClients"))
114  if (index >= 4 && index <= 13)
115  c.setEnabled(how);
116  }
117 
118 
124  public void propertyChange(PropertyChangeEvent event)
125  {
126  try {
127  String key = event.getPropertyName();
128  Object val = event.getNewValue();
129 
130  for (int i = getComponentCount() - 1; i >= 0; i--) {
131  Component c = getComponent(i);
132  if (c instanceof Button)
133  renderTool(c, i, key, val);
134  }
135  }
136 
137  catch (Throwable t) {
138  Registry.debug(t);
139  }
140  }
141 }
142 
Multitype button with configurable styles and behaviour.
Definition: Button.java:20
Object get(String section, String key)
Get an entry.
Definition: Registry.java:151
Configuration registry.
Definition: Registry.java:41
Session frame toolbar equipped with a dynamic UI updating mechanism.
Definition: TraceTools.java:23
ActionListener handler
Event handler.
Definition: TraceTools.java:29
void renderTool(Component c, int index, String key, Object val)
Update the UI state of a single tool.
Definition: TraceTools.java:98
Button createTool(String cmd)
Create a toolbar button.
Definition: TraceTools.java:78
void propertyChange(PropertyChangeEvent event)
Handler for events fired when UI properties change.
static final long serialVersionUID
Class version.
Definition: TraceTools.java:26