1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.accessibility.awb.view;
25 
26 import java.awt.Color;
27 import java.awt.Dimension;
28 import java.awt.Font;
29 import java.awt.GridBagLayout;
30 import java.awt.GridBagConstraints;
31 import javax.swing.JComponent;
32 import javax.swing.JLabel;
33 
34 
35 /** This class is a convenience class for views to use the GridBagLayout.
36 */
37 class ViewGridLayout
38 {
ViewGridLayout(JComponent aComponent)39     public ViewGridLayout (JComponent aComponent)
40     {
41         maComponent = aComponent;
42         maComponent.setLayout (new GridBagLayout());
43         maComponent.setMinimumSize (new Dimension (300,30));
44         maComponent.setMaximumSize (new Dimension (300,1000));
45         mnCurrentLine = 0;
46     }
47 
AddLabeledEntry(String sTitle)48     public JLabel AddLabeledEntry (String sTitle)
49     {
50         return (JLabel)AddLabeledComponent (sTitle, new JLabel (""));
51     }
52 
AddLabeledString(String sTitle)53     public JLabel AddLabeledString (String sTitle)
54     {
55         JLabel aLabel = AddLabeledEntry (sTitle);
56         aLabel.setBackground (new Color(220,220,220));
57         aLabel.setOpaque (true);
58         return aLabel;
59     }
60 
AddLabeledComponent(String sTitle, JComponent aComponent)61     public JComponent AddLabeledComponent (String sTitle, JComponent aComponent)
62     {
63         GridBagConstraints constraints = new GridBagConstraints ();
64         constraints.gridx = 0;
65         constraints.anchor = GridBagConstraints.WEST;
66         constraints.fill = GridBagConstraints.NONE;
67         constraints.gridy = mnCurrentLine;
68 
69         JLabel aLabel = new JLabel(sTitle);
70         aLabel.setFont (saFont);
71         maComponent.add (aLabel, constraints);
72         constraints.gridx = 1;
73         constraints.weightx = 1;
74         constraints.fill = GridBagConstraints.NONE;
75         aComponent.setFont (saFont);
76         maComponent.add (aComponent, constraints);
77 
78         mnCurrentLine += 1;
79 
80         return aComponent;
81     }
82 
AddComponent(JComponent aComponent)83     public JComponent AddComponent (JComponent aComponent)
84     {
85         GridBagConstraints constraints = new GridBagConstraints ();
86         constraints.gridx = 0;
87         constraints.gridwidth = 2;
88         constraints.weightx = 1;
89         constraints.anchor = GridBagConstraints.WEST;
90         constraints.fill = GridBagConstraints.HORIZONTAL;
91         constraints.gridy = mnCurrentLine;
92 
93         maComponent.add (aComponent, constraints);
94 
95         mnCurrentLine += 1;
96 
97         return aComponent;
98     }
99 
GetFont()100     static public Font GetFont ()
101     {
102         return saFont;
103     }
104 
105     static private Font saFont;
106     private int mnCurrentLine;
107     private JComponent maComponent;
108 
109     static
110     {
111         saFont = new Font ("Dialog", Font.PLAIN, 11);
112     }
113 }
114