jTracer  1.03
Stack trace visualization tool
ToolBar.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 ToolBar extends JToolBar implements PropertyChangeListener
24 {
26  private static final long serialVersionUID = 0x00;
27 
29  private ActionListener handler = null;
30 
31 
37  ToolBar(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
Button createTool(String cmd)
Create a toolbar button.
Definition: ToolBar.java:78
void propertyChange(PropertyChangeEvent event)
Handler for events fired when UI properties change.
Definition: ToolBar.java:124
Configuration registry.
Definition: Registry.java:41
static final long serialVersionUID
Class version.
Definition: ToolBar.java:26
ActionListener handler
Event handler.
Definition: ToolBar.java:29
Main application toolbar equipped with a dynamic UI updating mechanism.
Definition: ToolBar.java:23
void renderTool(Component c, int index, String key, Object val)
Update the UI state of a single tool.
Definition: ToolBar.java:98