1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.ximtec.igesture.tool.util;
27
28 import java.awt.Color;
29 import java.awt.GridBagConstraints;
30 import java.awt.GridBagLayout;
31
32 import javax.swing.JComponent;
33 import javax.swing.JPanel;
34
35 import org.sigtec.graphix.GridBagLayouter;
36
37
38
39
40
41
42
43 public class FormBuilder {
44
45 public static final int LEFT = 1;
46 public static final int RIGHT = 2;
47
48 private int line;
49 private JPanel panel;
50
51 public FormBuilder() {
52 panel = new JPanel();
53 panel.setOpaque(true);
54 panel.setBackground(Color.WHITE);
55 panel.setLayout(new GridBagLayout());
56 line = 1;
57 }
58
59 public void nextLine() {
60 line++;
61 }
62
63 public void addLeft(JComponent component) {
64 addComponent(component, LEFT, 0.0);
65 }
66
67 public void addRight(JComponent component) {
68 addComponent(component, RIGHT, 1.0);
69 }
70
71 private void addComponent(JComponent component, int position, double weight) {
72
73 GridBagLayouter.addComponent(panel, component, position, line, 1, 1, 5, 5, 5, 5, weight, 0,
74 GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL);
75 }
76
77 public JPanel getPanel() {
78 return panel;
79 }
80
81 }