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