KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > ActionBar


1 package com.sshtools.ui.awt;
2
3 import java.awt.Color JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.awt.Panel JavaDoc;
6 import java.awt.SystemColor JavaDoc;
7
8 /**
9  * A toolbar implementation that creates buttons from a set of {@link Action}.
10  *
11  * @author $Autho$
12  */

13 public class ActionBar extends Panel JavaDoc {
14
15     private Color JavaDoc baseBackground, baseForeground;
16
17     public ActionBar() {
18         super();
19         Separator separator = new Separator(Separator.HORIZONTAL);
20         setLayout(new ToolLayout(separator));
21         setBackground(SystemColor.control);
22         setForeground(SystemColor.controlText);
23         add(separator);
24     }
25     
26     public void add(ActionButton button) {
27         if (baseBackground != null) {
28             button.setBaseBackground(baseBackground);
29         }
30         if (baseForeground != null) {
31             button.setBaseForeground(baseForeground);
32         }
33         super.add(button);
34     }
35
36     public void addAction(Action action) {
37         add(new ActionButton(action));
38     }
39
40     public void addSeparator() {
41         add(new Separator(Separator.VERTICAL));
42     }
43
44     public void setBaseBackground(Color JavaDoc baseBackground) {
45         setBackground(baseBackground == null ? SystemColor.control : baseBackground);
46         this.baseBackground = baseBackground;
47         for (int i = 0; i < getComponentCount(); i++) {
48             Component JavaDoc c = getComponent(i);
49             if (c instanceof ActionButton) {
50                 ((ActionButton) c).setBaseBackground(baseBackground);
51             }
52         }
53     }
54
55     public void setBaseForeground(Color JavaDoc baseForeground) {
56         setForeground(baseForeground == null ? SystemColor.controlText : baseForeground);
57         this.baseForeground = baseForeground;
58         for (int i = 0; i < getComponentCount(); i++) {
59             Component JavaDoc c = getComponent(i);
60             if (c instanceof ActionButton) {
61                 ((ActionButton) c).setBaseForeground(baseForeground);
62             }
63         }
64     }
65
66 }
Popular Tags