KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > client > AbstractTabularOptionDialog


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.client;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.awt.GridBagConstraints JavaDoc;
25 import java.awt.GridBagLayout JavaDoc;
26
27 import javax.swing.Box JavaDoc;
28 import javax.swing.JFrame JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31
32 /**
33  * Creates a dialog which displays a table of labeled components to the user.
34  *
35  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
36  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:23 $
37  * @since 4.1
38  */

39 public abstract class AbstractTabularOptionDialog
40     extends AbstractOptionDialog
41 {
42     /*---------------------------------------------------------------
43      * Constructors
44      *-------------------------------------------------------------*/

45     /**
46      * Creates a new AbstractTabularOptionDialog.
47      *
48      * @param frame Frame which owns the dialog.
49      * @param title Title for the dialog.
50      * @param buttons List of buttons to display.
51      */

52     protected AbstractTabularOptionDialog( JFrame JavaDoc frame, String JavaDoc title, int buttons )
53     {
54         super( frame, title, buttons );
55     }
56     
57     /*---------------------------------------------------------------
58      * AbstractOptionDialog Methods
59      *-------------------------------------------------------------*/

60     /**
61      * Returns the main panel which makes up the guts of the dialog.
62      * This implementaton builds a table of labeled components using
63      * arrays returned by getMainPanelLabels() and getMainPanelComponents();
64      *
65      * @return The main panel.
66      */

67     protected JPanel JavaDoc getMainPanel()
68     {
69         String JavaDoc[] labels = getMainPanelLabels();
70         Component JavaDoc[] components = getMainPanelComponents();
71         
72         JPanel JavaDoc panel = new JPanel JavaDoc();
73         
74         GridBagLayout JavaDoc gbl = new GridBagLayout JavaDoc();
75         GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
76         panel.setLayout( gbl );
77         
78         for ( int i = 0; i < labels.length; i++ )
79         {
80             addRow( panel, labels[i], components[i], gbl, gbc );
81         }
82         
83         return panel;
84     }
85     
86     /*---------------------------------------------------------------
87      * Methods
88      *-------------------------------------------------------------*/

89     /**
90      * Returns an array of labels to use for the components returned from
91      * getMainPanelComponents().
92      *
93      * @returns An array of labels.
94      */

95     protected abstract String JavaDoc[] getMainPanelLabels();
96     
97     /**
98      * Returns an array of components to show in the main panel of the dialog.
99      *
100      * @returns An array of components.
101      */

102     protected abstract Component JavaDoc[] getMainPanelComponents();
103     
104     /**
105      * Adds a row to the panel consisting of a label and component, separated by
106      * a 5 pixel spacer and followed by a 5 pixel high row between this and the
107      * next row.
108      *
109      * @param panel Panel to which the row will be added.
110      * @param label Text of the label for the component.
111      * @param component Component which makes up the row.
112      * @param gbl GridBagLayout which must have been set as the layour of the
113      * panel.
114      * @param gbc GridBagConstraints to use when laying out the row.
115      */

116     private void addRow( JPanel JavaDoc panel,
117                          String JavaDoc label,
118                          Component JavaDoc component,
119                          GridBagLayout JavaDoc gbl,
120                          GridBagConstraints JavaDoc gbc )
121     {
122         JLabel JavaDoc jLabel = new JLabel JavaDoc( label );
123         gbc.gridwidth = 1;
124         gbc.anchor = GridBagConstraints.EAST;
125         gbl.setConstraints( jLabel, gbc );
126         panel.add( jLabel );
127         
128         // Add a 5 pixel high spacer
129
Component JavaDoc spacer = Box.createRigidArea( new Dimension JavaDoc( 5, 5 ) );
130         gbc.gridwidth = GridBagConstraints.RELATIVE;
131         gbc.anchor = GridBagConstraints.WEST;
132         gbl.setConstraints( spacer, gbc );
133         panel.add( spacer );
134         
135         gbc.gridwidth = GridBagConstraints.REMAINDER;
136         gbc.anchor = GridBagConstraints.WEST;
137         gbl.setConstraints( component, gbc );
138         panel.add( component );
139         
140         // Add a 5 pixel high spacer
141
spacer = Box.createRigidArea( new Dimension JavaDoc( 5, 5 ) );
142         gbc.gridwidth = GridBagConstraints.REMAINDER;
143         gbc.anchor = GridBagConstraints.WEST;
144         gbl.setConstraints( spacer, gbc );
145         panel.add( spacer );
146     }
147 }
148
149
Popular Tags