KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ungoverned > oscar > installer > PropertyPanel


1 /*
2  * Oscar - An implementation of the OSGi framework.
3  * Copyright (c) 2004, Richard S. Hall
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of the ungoverned.org nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Contact: Richard S. Hall (heavy@ungoverned.org)
33  * Contributor(s):
34  *
35 **/

36 package org.ungoverned.oscar.installer;
37
38 import java.awt.GridBagConstraints JavaDoc;
39 import java.awt.GridBagLayout JavaDoc;
40 import java.awt.Insets JavaDoc;
41 import java.util.*;
42
43 import javax.swing.JComponent JavaDoc;
44 import javax.swing.JLabel JavaDoc;
45 import javax.swing.JPanel JavaDoc;
46
47 public class PropertyPanel extends JPanel JavaDoc
48 {
49     private List m_propList = null;
50     private Map m_propToCompMap = null;
51
52     public PropertyPanel(List paramList)
53     {
54         super();
55         m_propList = paramList;
56         m_propToCompMap = new HashMap();
57         layoutComponents();
58     }
59
60     public void setEnabled(boolean b)
61     {
62         for (int i = 0; i < m_propList.size(); i++)
63         {
64             Property prop = (Property) m_propList.get(i);
65             JComponent JavaDoc comp = (JComponent JavaDoc) m_propToCompMap.get(prop.getName());
66             comp.setEnabled(b);
67         }
68     }
69
70     public List getProperties()
71     {
72         return m_propList;
73     }
74
75     protected void layoutComponents()
76     {
77         // Create the field panel for entering query variables.
78
GridBagLayout JavaDoc grid = new GridBagLayout JavaDoc();
79         GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
80         gbc.insets = new Insets JavaDoc(2, 2, 2, 2);
81         setLayout(grid);
82
83         for (int i = 0; i < m_propList.size(); i++)
84         {
85             Property prop = (Property) m_propList.get(i);
86             JLabel JavaDoc label = null;
87             JComponent JavaDoc component = null;
88
89             // Add label.
90
gbc.gridx = 0;
91             gbc.gridy = i;
92             gbc.gridheight = 1;
93             gbc.gridwidth = 1;
94             gbc.anchor = GridBagConstraints.EAST;
95             grid.setConstraints(label = new JLabel JavaDoc(prop.getName()), gbc);
96             add(label);
97
98             gbc.gridx = 1;
99             gbc.gridy = i;
100             gbc.gridheight = 1;
101             gbc.gridwidth = 3;
102             gbc.anchor = GridBagConstraints.WEST;
103             grid.setConstraints(component = prop.getEditor(), gbc);
104             add(component);
105
106             m_propToCompMap.put(prop.getName(), component);
107         }
108     }
109 }
Popular Tags