View Javadoc

1   /*
2    * @(#)$Id: Formatter.java 741 2009-08-15 09:40:16Z kurmannu $
3    *
4    * Author   : Ueli Kurmann, igesture@uelikurmann.ch
5    *                  
6    *
7    * Purpose    : 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date       Who     Reason
14   *
15   * 23.08.2009 ukurmann  Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
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   * This is a simple two column form builder.
39   * 
40   * @author Ueli Kurmann
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  }