KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > Box


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: Box.java,v $
11    Revision 1.3 2004/02/07 21:04:50 bobintetley
12    Fixed typo - createVerical should be createVertical
13
14    Revision 1.2 2004/01/26 08:11:00 bobintetley
15    Many bugfixes and addition of SwingSet
16
17    Revision 1.1 2004/01/20 15:52:56 bobintetley
18    Code from an anonymous developer
19
20
21 */

22
23 package swingwtx.swing;
24
25 import swingwt.awt.Component;
26 import swingwt.awt.Container;
27 import swingwt.awt.Dimension;
28
29 /**
30  * @author Submitted by a kind developer who remains anonymous
31  * Fixed up by Rob to subclass JPanel so it can be used as a Swing
32  * container (SwingSet does this)
33  */

34 public class Box extends JPanel {
35     
36     public Box(int axis) {
37         this(null, axis);
38     }
39     
40     public Box(Container target, int axis) {
41         
42         if (target != null) {
43             target.add(this);
44             setLayout(new BoxLayout(target, axis));
45         }
46         else
47             setLayout(new BoxLayout(this, axis));
48     }
49                               
50     public static Box createHorizontalBox() {
51         return new Box(BoxLayout.X_AXIS);
52     }
53     
54     public static Box createVerticalBox() {
55         return new Box(BoxLayout.Y_AXIS);
56     }
57     
58     public static Box createHorizontalBox(Container target) {
59             return new Box(target, BoxLayout.X_AXIS);
60     }
61                                                                                                                         
62     public static Box createVerticalBox(Container target) {
63             return new Box(target, BoxLayout.Y_AXIS);
64     }
65                                                                                                                              
66     public static Component createRigidArea(Dimension d) {
67         return new Filler(d, d, d);
68     }
69                                                                                                                              
70     public static Component createHorizontalStrut(int width) {
71         // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
72
// to date because BoxLayout alignment breaks.
73
return new Filler(new Dimension(width,0), new Dimension(width,0), new Dimension(width, Short.MAX_VALUE));
74     }
75                                                                                                                              
76     public static Component createVerticalStrut(int height) {
77         // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
78
// to date because BoxLayout alignment breaks.
79
return new Filler(new Dimension(0,height), new Dimension(0,height), new Dimension(Short.MAX_VALUE, height));
80     }
81                                                                                                                              
82     public static Component createGlue() {
83         // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
84
// to date because BoxLayout alignment breaks.
85
return new Filler(new Dimension(0,0), new Dimension(0,0), new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
86     }
87                                                                                                                              
88     public static Component createHorizontalGlue() {
89         // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
90
// to date because BoxLayout alignment breaks.
91
return new Filler(new Dimension(0,0), new Dimension(0,0), new Dimension(Short.MAX_VALUE, 0));
92     }
93                                                                                                                              
94     public static Component createVerticalGlue() {
95         // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
96
// to date because BoxLayout alignment breaks.
97
return new Filler(new Dimension(0,0), new Dimension(0,0), new Dimension(0, Short.MAX_VALUE));
98     }
99                                                                                                                              
100     public static class Filler extends JPanel {
101                                                                                                                              
102         public Filler(Dimension min, Dimension pref, Dimension max) {
103             reqMin = min;
104             reqPref = pref;
105             reqMax = max;
106         }
107                                                                                                                              
108         public void changeShape(Dimension min, Dimension pref, Dimension max) {
109             reqMin = min;
110             reqPref = pref;
111             reqMax = max;
112             //invalidate();
113
}
114                                                                                                                              
115         public Dimension getMinimumSize() {
116             return reqMin;
117         }
118                                                                                                                              
119         public Dimension getPreferredSize() {
120             return reqPref;
121         }
122                                                                                                                              
123         public Dimension getMaximumSize() {
124             return reqMax;
125         }
126                                                                                                                              
127         private Dimension reqMin;
128         private Dimension reqPref;
129         private Dimension reqMax;
130     }
131 }
132
Popular Tags