KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > ejb > jndi > config > gui > JndiConfigGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/jndi/config/gui/JndiConfigGui.java,v 1.4 2004/02/13 02:40:53 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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 implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.ejb.jndi.config.gui;
20
21 import javax.swing.*;
22 import javax.swing.border.*;
23 import java.awt.event.*;
24 import javax.naming.InitialContext JavaDoc;
25 import java.awt.*;
26 import java.util.*;
27
28 import org.apache.jmeter.gui.ModelSupported;
29 import org.apache.jmeter.gui.NamePanel;
30 import org.apache.jmeter.gui.VerticalLayout;
31 import org.apache.jmeter.config.gui.ArgumentsPanel;
32 import org.apache.jmeter.config.Arguments;
33 import org.apache.jmeter.util.JMeterUtils;
34 import org.apache.jmeter.ejb.jndi.config.JndiConfig;
35 import org.apache.log4j.Category;
36
37 /**
38  * Provides the gui interface to configure JNDI sampling
39  * @author Khor Soon Hin
40  * @version $Revision: 1.4 $ Last updated: $Date: 2004/02/13 02:40:53 $
41  * Created 2001 Dec 17
42  */

43 public class JndiConfigGui extends JPanel implements ModelSupported,
44     KeyListener
45 {
46   private static Category catClass = Category.getInstance(
47     JndiConfigGui.class.getName());
48
49   protected JTextField[] jndi_fields = new JTextField[JndiConfig.JNDI_PROPS.length];
50
51   protected NamePanel namePanel;
52   protected boolean displayName;
53   protected JndiConfig model;
54
55   public JndiConfigGui()
56   {
57     displayName = true;
58   }
59
60   public JndiConfigGui(boolean displayName)
61   {
62     this.displayName = displayName;
63   }
64
65   public void setModel(Object JavaDoc model)
66   {
67     this.model = (JndiConfig)model;
68     init();
69   }
70
71   public void updateGui()
72   {
73     for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++)
74     {
75       jndi_fields[i].setText(model.getValue(i));
76     }
77   }
78
79   protected void init()
80   {
81     for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++)
82     {
83       jndi_fields[i] = new JTextField(20);
84     }
85     if(displayName)
86     {
87       this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT,
88     VerticalLayout.TOP));
89       // main panel
90
JPanel mainPanel = new JPanel();
91       Border margin = new EmptyBorder(10, 10, 5, 10);
92       mainPanel.setBorder(margin);
93       mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
94
95       mainPanel.add(makeTitlePanel());
96
97       // jndi properties
98
JPanel urlJNDIPanel = new JPanel();
99       urlJNDIPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
100       urlJNDIPanel.setBorder(BorderFactory.createTitledBorder(
101     JMeterUtils.getResString("jndi_url_jndi_props")));
102
103       for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++)
104       {
105         urlJNDIPanel.add(getPanel(i));
106       }
107
108       mainPanel.add(urlJNDIPanel);
109       this.add(mainPanel);
110     }
111     else
112     {
113       this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
114
115       // url and driver class
116
JPanel urlJNDIPanel = new JPanel();
117       urlJNDIPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
118       urlJNDIPanel.setBorder(BorderFactory.createTitledBorder(
119     JMeterUtils.getResString("jndi_url_jndi_props")));
120
121       for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++)
122       {
123         urlJNDIPanel.add(getPanel(i));
124       }
125
126       this.add(urlJNDIPanel);
127     }
128   }
129
130   protected JPanel getPanel(int i)
131   {
132     catClass.info("Start : getPanel1");
133     if(catClass.isDebugEnabled())
134     {
135       catClass.debug("getPanel1 : Panel no. - " + i);
136       catClass.debug("getPanel1 : Panel name - " + JndiConfig.JNDI_PROPS[i]);
137       catClass.debug("getPanel1 : Panel value - " + model.getValue(i));
138     }
139     JPanel panel = new JPanel();
140     panel.add(new JLabel(JndiConfig.JNDI_PROPS[i]));
141     jndi_fields[i].setText(model.getValue(i));
142     jndi_fields[i].setName(JndiConfig.JNDI_PROPS[i]);
143     jndi_fields[i].addKeyListener(this);
144     panel.add(jndi_fields[i]);
145     catClass.info("End : getPanel1");
146     return panel;
147   }
148
149   public void keyPressed(KeyEvent e)
150   {
151   }
152
153   public void keyTyped(KeyEvent e)
154   {
155   }
156
157   public void keyReleased(KeyEvent e)
158   {
159     String JavaDoc name = e.getComponent().getName();
160     int i = 0;
161     while(i < JndiConfig.JNDI_PROPS.length)
162     {
163       if(name.equals(JndiConfig.JNDI_PROPS[i]))
164       {
165         break;
166       }
167       i++;
168     }
169     if(i < JndiConfig.JNDI_PROPS.length)
170     {
171       model.setValue(i, jndi_fields[i].getText());
172     }
173   }
174 }
175
Popular Tags