KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > JProgressBar


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: JProgressBar.java,v $
11    Revision 1.17 2004/04/28 08:38:11 bobintetley
12    Hierarchy fixes, code cleanup for base classes, additional javadocs and use of flag to identify JComponent descendants with peers
13
14    Revision 1.16 2004/01/26 08:11:00 bobintetley
15    Many bugfixes and addition of SwingSet
16
17    Revision 1.15 2004/01/16 12:35:27 bobintetley
18    JProgressBar should be smooth
19
20    Revision 1.14 2003/12/16 17:46:17 bobintetley
21    Additional thread safety methods
22
23    Revision 1.13 2003/12/16 14:51:16 bobintetley
24    Fixed hang when a window close event closes itself again
25
26    Revision 1.12 2003/12/16 13:14:33 bobintetley
27    Use of SwingWTUtils.isSWTControlAvailable instead of null test
28
29    Revision 1.11 2003/12/15 18:57:13 bobintetley
30    getValue now thread-safe
31
32    Revision 1.10 2003/12/15 18:54:53 bobintetley
33    Threaded accessor methods to prevent SWT problems
34
35    Revision 1.9 2003/12/15 18:29:57 bobintetley
36    Changed setParent() method to setSwingWTParent() to avoid conflicts with applications
37
38    Revision 1.8 2003/12/15 15:54:25 bobintetley
39    Additional core methods
40
41    Revision 1.7 2003/12/14 09:13:38 bobintetley
42    Added CVS log to source headers
43
44 */

45
46
47 package swingwtx.swing;
48
49 import org.eclipse.swt.widgets.*;
50 import org.eclipse.swt.*;
51
52 public class JProgressBar extends swingwtx.swing.JComponent implements SwingConstants {
53
54     private ProgressBar ppeer = null;
55     private int pMin = 0;
56     private int pMax = 0;
57     private int pValue = 0;
58     
59     public JProgressBar() {}
60     public JProgressBar(int orient) { }
61     public JProgressBar(int min, int max) { pMin = min; pMax = max; }
62     public JProgressBar(int orient, int min, int max) { pMin = min; pMax = max; }
63     
64     public void setMaximum(final int max) {
65         SwingUtilities.invokeAsync(new Runnable JavaDoc() {
66             public void run() {
67                 setMaximumT(max);
68             }
69         });
70     }
71     
72     public void setMinimum(final int min) {
73         SwingUtilities.invokeAsync(new Runnable JavaDoc() {
74             public void run() {
75                 setMinimumT(min);
76             }
77         });
78     }
79     
80     public void setValue(final int value) {
81         pValue = value;
82         SwingUtilities.invokeAsync(new Runnable JavaDoc() {
83             public void run() {
84                 setValueT(value);
85             }
86         });
87     }
88       
89     protected void setMaximumT(int max) { if (!SwingWTUtils.isSWTControlAvailable(ppeer)) pMax = max; else ppeer.setMaximum(max); }
90     protected void setMinimumT(int min) { if (!SwingWTUtils.isSWTControlAvailable(ppeer)) pMin = min; else ppeer.setMinimum(min); }
91     protected void setValueT(int value) { if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setSelection(value); }
92     public int getMaximum() { return pMax; }
93     public int getMinimum() { return pMin; }
94     public int getValue() { return pValue; }
95     public double getPercentComplete() { return ( ((double) (getValue() - getMinimum())) / ((double) (getMaximum() - getMinimum())) * 100); }
96     public void setStringPainted(boolean b) { }
97     public boolean getStringPainted() { return false; }
98     public void setString(String JavaDoc s) {}
99     public String JavaDoc getString() { return ""; }
100     
101     /**
102      * Once a parent component receives an "add" call for a child, this being
103      * the child, this should be called to tell us to instantiate the peer
104      * and load in any cached properties.
105      */

106    public void setSwingWTParent(swingwt.awt.Container parent) throws Exception JavaDoc {
107         descendantHasPeer = true;
108        
109         ppeer = new ProgressBar(parent.getComposite(), SWT.BORDER | SWT.SMOOTH);
110
111         ppeer.setMaximum(pMax);
112         ppeer.setMinimum(pMin);
113         ppeer.setSelection(pValue);
114
115         peer = ppeer;
116         this.parent = parent;
117     }
118     
119 }
120
Popular Tags