1 package com.sshtools.ui.awt; 2 3 import java.awt.Color ; 4 import java.awt.Component ; 5 import java.awt.Panel ; 6 import java.awt.SystemColor ; 7 8 13 public class ActionBar extends Panel { 14 15 private Color 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 baseBackground) { 45 setBackground(baseBackground == null ? SystemColor.control : baseBackground); 46 this.baseBackground = baseBackground; 47 for (int i = 0; i < getComponentCount(); i++) { 48 Component c = getComponent(i); 49 if (c instanceof ActionButton) { 50 ((ActionButton) c).setBaseBackground(baseBackground); 51 } 52 } 53 } 54 55 public void setBaseForeground(Color baseForeground) { 56 setForeground(baseForeground == null ? SystemColor.controlText : baseForeground); 57 this.baseForeground = baseForeground; 58 for (int i = 0; i < getComponentCount(); i++) { 59 Component c = getComponent(i); 60 if (c instanceof ActionButton) { 61 ((ActionButton) c).setBaseForeground(baseForeground); 62 } 63 } 64 } 65 66 } | Popular Tags |