1 // stolen from XPath Explorer (http://www.xpathexplorer.com)
2
3 package net.sourceforge.pmd.cpd;
4
5 import javax.swing.JLabel;
6 import javax.swing.SwingConstants;
7 import java.awt.Component;
8 import java.awt.Container;
9 import java.awt.GridBagConstraints;
10 import java.awt.GridBagLayout;
11 import java.awt.Insets;
12
13 public class GridBagHelper {
14
15 GridBagLayout gridbag;
16 Container container;
17 GridBagConstraints c;
18 int x = 0;
19 int y = 0;
20 int labelAlignment = SwingConstants.RIGHT;
21 double[] weights;
22
23 public GridBagHelper(Container container, double[] weights) {
24 this.container = container;
25 this.weights = weights;
26
27 gridbag = new GridBagLayout();
28 container.setLayout(gridbag);
29
30 c = new GridBagConstraints();
31 c.insets = new Insets(2, 2, 2, 2);
32 c.anchor = GridBagConstraints.EAST;
33 c.fill = GridBagConstraints.HORIZONTAL;
34 }
35
36 public void add(Component component) {
37 add(component, 1);
38 }
39
40 public void add(Component component, int width) {
41 c.gridx = x;
42 c.gridy = y;
43 c.weightx = weights[x];
44 c.gridwidth = width;
45 gridbag.setConstraints(component, c);
46 container.add(component);
47 x += width;
48 }
49
50 public void nextRow() {
51 y++;
52 x = 0;
53 }
54
55 public void addLabel(String label) {
56 add(new JLabel(label, labelAlignment));
57 }
58
59 }
60
This page was automatically generated by Maven