KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > swing > status > StatusBar


1 package com.opensymphony.workflow.designer.swing.status;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import javax.swing.border.Border JavaDoc;
6
7 /**
8  * @author Hani Suleiman (hani@formicary.net)
9  * Date: Dec 24, 2003
10  * Time: 3:27:25 PM
11  */

12 public class StatusBar extends JPanel
13 {
14   private Border JavaDoc border;
15
16   public StatusBar()
17   {
18     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
19     setRequestFocusEnabled(false);
20     setFocusable(false);
21     border = BorderFactory.createEmptyBorder(1, 4, 1, 4);
22   }
23
24   protected void addImpl(Component comp, Object JavaDoc constraints, int index)
25   {
26     super.addImpl(comp, constraints, index);
27     if(comp instanceof DisplayItem)
28     {
29       DisplayItem item = (DisplayItem)comp;
30       item.setBorder(border);
31     }
32   }
33
34   public DisplayItem getItemByName(String JavaDoc name)
35   {
36     Component[] components = getComponents();
37     for(int i = 0; i < components.length; i++)
38     {
39       Component c = components[i];
40       if(c instanceof DisplayItem)
41       {
42         DisplayItem item = (DisplayItem)c;
43         if(name.equals(item.getItemName()))
44           return item;
45       }
46     }
47     return null;
48   }
49
50   public void setItemVisible(String JavaDoc string, boolean bool)
51   {
52     DisplayItem item = getItemByName(string);
53     if(item != null)
54       item.setVisible(bool);
55     validate();
56     repaint();
57   }
58
59   public int getHeight()
60   {
61     Component[] components = getComponents();
62     int height = 0;
63     for(int i = 0; i < components.length; i++)
64     {
65       Component c = components[i];
66       if(c instanceof DisplayItem)
67       {
68         int itemHeight = c.getPreferredSize().height;
69         if(itemHeight > height) height = itemHeight;
70       }
71     }
72     return height + 5;
73   }
74
75   public Dimension getPreferredSize()
76   {
77     return new Dimension(0, getHeight());
78   }
79
80   public void removeNotify()
81   {
82     super.removeNotify();
83     removeAll();
84   }
85
86   public static void main(String JavaDoc[] args) throws InterruptedException JavaDoc
87   {
88     JFrame frame = new JFrame();
89     frame.getContentPane().setLayout(new BorderLayout());
90     StatusBar bar = new StatusBar();
91     StatusDisplay progress = new StatusDisplay();
92     bar.add(progress);
93     bar.add(Box.createHorizontalGlue());
94     bar.add(new MemoryDisplay());
95     frame.setSize(800, 600);
96     frame.setLocation(100, 100);
97     frame.getContentPane().add(bar, BorderLayout.SOUTH);
98     frame.show();
99     Thread.sleep(1000);
100     progress.setIndeterminate(true);
101     progress.setProgressStatus("blahblah");
102     Thread.sleep(2000);
103     progress.setStatus("This is a status");
104     Thread.sleep(1000);
105     progress.setIndeterminate(false);
106     for(int i=0;i<100;i++)
107     {
108       Thread.sleep(20L);
109       progress.setProgress(i);
110     }
111   }
112 }
113
Popular Tags