01: // FormFrame.java
02: // $Id: FormPanel.java,v 1.3 2000/08/16 21:37:49 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.forms;
07:
08: import java.awt.Component;
09: import java.awt.Container;
10: import java.awt.Dimension;
11: import java.awt.Graphics;
12: import java.awt.GridBagConstraints;
13: import java.awt.GridBagLayout;
14: import java.awt.Insets;
15: import java.awt.Label;
16: import java.awt.Panel;
17:
18: public class FormPanel extends Panel {
19: /**
20: * Our associated form manager.
21: */
22: FormManager manager = null;
23: /**
24: * Our layout manager.
25: */
26: GridBagLayout gb = null;
27: /**
28: * Field's title constraints.
29: */
30: GridBagConstraints ct = null;
31: /**
32: * Field's editor constraints.
33: */
34: GridBagConstraints cv = null;
35:
36: /**
37: * Add a field editor.
38: * @param title The title for the field.
39: * @param editor Its editor component.
40: */
41:
42: protected void addField(String title, Component editor) {
43: Label label = new Label(title, Label.LEFT);
44: gb.setConstraints(label, ct);
45: add(label);
46: gb.setConstraints(editor, cv);
47: add(editor);
48: }
49:
50: /**
51: * Some insets for the form panel.
52: */
53:
54: public Insets insets() {
55: return new Insets(5, 5, 5, 5);
56: }
57:
58: /**
59: * Darw a rectangle around the form panel.
60: */
61:
62: public void paint(Graphics g) {
63: Dimension d = size();
64: g.drawRect(1, 1, d.width - 3, d.height - 3);
65: }
66:
67: /**
68: * Create a new form panel for the given form manager.
69: */
70:
71: FormPanel(FormManager manager) {
72: super ();
73: // Create our layout manager:
74: gb = new GridBagLayout();
75: setLayout(gb);
76: // Create the title constraints:
77: ct = new GridBagConstraints();
78: ct.gridx = GridBagConstraints.RELATIVE;
79: ct.anchor = GridBagConstraints.EAST;
80: ct.weighty = 1.0;
81: // Create the value constraints:
82: cv = new GridBagConstraints();
83: cv.gridx = GridBagConstraints.RELATIVE;
84: cv.gridwidth = GridBagConstraints.REMAINDER;
85: cv.fill = GridBagConstraints.HORIZONTAL;
86: cv.anchor = GridBagConstraints.WEST;
87: cv.weightx = 1.0;
88: cv.weighty = 1.0;
89: }
90:
91: }
|