01: package com.opensymphony.workflow.designer.swing.status;
02:
03: import java.awt.*;
04: import javax.swing.*;
05: import javax.swing.border.Border;
06:
07: /**
08: * @author Hani Suleiman (hani@formicary.net)
09: * Date: Dec 24, 2003
10: * Time: 3:27:25 PM
11: */
12: public class StatusBar extends JPanel {
13: private Border border;
14:
15: public StatusBar() {
16: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
17: setRequestFocusEnabled(false);
18: setFocusable(false);
19: border = BorderFactory.createEmptyBorder(1, 4, 1, 4);
20: }
21:
22: protected void addImpl(Component comp, Object constraints, int index) {
23: super .addImpl(comp, constraints, index);
24: if (comp instanceof DisplayItem) {
25: DisplayItem item = (DisplayItem) comp;
26: item.setBorder(border);
27: }
28: }
29:
30: public DisplayItem getItemByName(String name) {
31: Component[] components = getComponents();
32: for (int i = 0; i < components.length; i++) {
33: Component c = components[i];
34: if (c instanceof DisplayItem) {
35: DisplayItem item = (DisplayItem) c;
36: if (name.equals(item.getItemName()))
37: return item;
38: }
39: }
40: return null;
41: }
42:
43: public void setItemVisible(String string, boolean bool) {
44: DisplayItem item = getItemByName(string);
45: if (item != null)
46: item.setVisible(bool);
47: validate();
48: repaint();
49: }
50:
51: public int getHeight() {
52: Component[] components = getComponents();
53: int height = 0;
54: for (int i = 0; i < components.length; i++) {
55: Component c = components[i];
56: if (c instanceof DisplayItem) {
57: int itemHeight = c.getPreferredSize().height;
58: if (itemHeight > height)
59: height = itemHeight;
60: }
61: }
62: return height + 5;
63: }
64:
65: public Dimension getPreferredSize() {
66: return new Dimension(0, getHeight());
67: }
68:
69: public void removeNotify() {
70: super .removeNotify();
71: removeAll();
72: }
73:
74: public static void main(String[] args) throws InterruptedException {
75: JFrame frame = new JFrame();
76: frame.getContentPane().setLayout(new BorderLayout());
77: StatusBar bar = new StatusBar();
78: StatusDisplay progress = new StatusDisplay();
79: bar.add(progress);
80: bar.add(Box.createHorizontalGlue());
81: bar.add(new MemoryDisplay());
82: frame.setSize(800, 600);
83: frame.setLocation(100, 100);
84: frame.getContentPane().add(bar, BorderLayout.SOUTH);
85: frame.show();
86: Thread.sleep(1000);
87: progress.setIndeterminate(true);
88: progress.setProgressStatus("blahblah");
89: Thread.sleep(2000);
90: progress.setStatus("This is a status");
91: Thread.sleep(1000);
92: progress.setIndeterminate(false);
93: for (int i = 0; i < 100; i++) {
94: Thread.sleep(20L);
95: progress.setProgress(i);
96: }
97: }
98: }
|