01: /*
02: * Created on 29-Feb-2004
03: */
04: package uk.org.ponder.swingutil;
05:
06: import java.awt.Component;
07: import java.awt.FlowLayout;
08: import java.awt.Font;
09: import java.awt.LayoutManager;
10: import javax.swing.Box;
11: import javax.swing.JLabel;
12: import javax.swing.JPanel;
13:
14: import uk.org.ponder.util.AssertionException;
15:
16: /**
17: * The class
18: *
19: * @author Bosmon
20: */
21: public class LayoutSpec {
22: int strutheight;
23: int strutwidth = 5;
24: LayoutManager exemplar;
25: private Component strut;
26: private Font defaultfont;
27:
28: public LayoutSpec(int strutheight, LayoutManager exemplar,
29: Font defaultfont) {
30: this .strutheight = strutheight;
31: this .exemplar = exemplar;
32: this .defaultfont = defaultfont;
33: }
34:
35: public JLabel getLabel(String label) {
36: JLabel togo = new JLabel(label);
37: togo.setFont(defaultfont);
38: return togo;
39: }
40:
41: public JPanel getPanel() {
42: JPanel togo = new JPanel(getLayout());
43: togo.setFont(defaultfont);
44: togo.add(getStrut());
45: return togo;
46: }
47:
48: public Component getStrut() {
49: return Box.createVerticalStrut(strutheight);
50: }
51:
52: public LayoutManager getLayout() {
53: LayoutManager togo = null;
54: if (exemplar instanceof FlowLayout) {
55: FlowLayout exflow = (FlowLayout) exemplar;
56: togo = new FlowLayout(exflow.getAlignment(), exflow
57: .getHgap(), exflow.getVgap());
58: } else {
59: throw new AssertionException("Unrecognised layout manager "
60: + exemplar);
61: }
62: return togo;
63: }
64:
65: public int getHeight() {
66: return strutheight;
67: }
68:
69: public Font getFont() {
70: return defaultfont;
71: }
72:
73: /**
74: * @return
75: */
76: public Component getHStrut() {
77: return Box.createHorizontalStrut(strutwidth);
78: }
79: }
|