KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > base > tool > AdaptorConfigurationPanel


1 /*
2  * Created on Jul 19, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.base.tool;
8
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.awt.event.ActionListener JavaDoc;
11
12 import javax.swing.JPanel JavaDoc;
13
14 import javax.swing.AbstractAction JavaDoc;
15 import javax.swing.JLabel JavaDoc;
16 import javax.swing.JCheckBox JavaDoc;
17 import javax.swing.JComboBox JavaDoc;
18 import javax.swing.JOptionPane JavaDoc;
19 import javax.swing.JTextField JavaDoc;
20
21 /**
22  * @author slobodan
23  *
24  * TODO To change the template for this generated type comment go to
25  * Window - Preferences - Java - Code Style - Code Templates
26  */

27 public class AdaptorConfigurationPanel extends JPanel JavaDoc {
28
29     private JLabel JavaDoc headLabel = null;
30     private JLabel JavaDoc authenticationLabel = null;
31     private JComboBox JavaDoc authenticationCombo = null;
32     private JCheckBox JavaDoc httpAdaptor = null;
33     private JLabel JavaDoc httpAdaptorLabel = null;
34     private JTextField JavaDoc httpAdaptorText = null;
35     private JCheckBox JavaDoc rmiAdaptor = null;
36     private JLabel JavaDoc rmiAdaptorLabel = null;
37     private JTextField JavaDoc rmiAdaptorText = null;
38     /**
39      * This is the default constructor
40      */

41     public AdaptorConfigurationPanel() {
42         super();
43         initialize();
44     }
45     /**
46      * This method initializes this
47      *
48      * @return void
49      */

50     private void initialize() {
51         headLabel = new JLabel JavaDoc();
52         authenticationLabel = new JLabel JavaDoc();
53         httpAdaptorLabel = new JLabel JavaDoc();
54         rmiAdaptorLabel = new JLabel JavaDoc();
55         this.setPreferredSize(new java.awt.Dimension JavaDoc(300,150));
56         this.setSize(300, 150);
57         headLabel.setText("");
58         headLabel.setPreferredSize(new java.awt.Dimension JavaDoc(300,25));
59         headLabel.setName("headLabel");
60         authenticationLabel.setText("Adaptor Authentication Level:");
61         authenticationLabel.setName("authenticationLabel");
62         httpAdaptorLabel.setText("Port:");
63         httpAdaptorLabel.setPreferredSize(new java.awt.Dimension JavaDoc(30,16));
64         httpAdaptorLabel.setName("httpAdaptorLabel");
65         rmiAdaptorLabel.setText("Port:");
66         rmiAdaptorLabel.setPreferredSize(new java.awt.Dimension JavaDoc(30,16));
67         this.add(headLabel, null);
68         this.add(authenticationLabel, null);
69         this.add(getAuthenticationCombo(), null);
70         this.add(getHttpAdaptor(), null);
71         this.add(httpAdaptorLabel, null);
72         this.add(getHttpAdaptorText(), null);
73         this.add(getRmiAdaptor(), null);
74         this.add(rmiAdaptorLabel, null);
75         this.add(getRmiAdaptorText(), null);
76     }
77     /**
78      * This method initializes jComboBox
79      *
80      * @return javax.swing.JComboBox
81      */

82     private JComboBox JavaDoc getAuthenticationCombo() {
83         if (authenticationCombo == null) {
84             authenticationCombo = new JComboBox JavaDoc();
85             authenticationCombo.setPreferredSize(new java.awt.Dimension JavaDoc(115,25));
86             authenticationCombo.setName("authenticationCombo");
87             authenticationCombo.addItem("none");
88             authenticationCombo.addItem("basic");
89             authenticationCombo.addItem("digest");
90             authenticationCombo.setSelectedIndex(0);
91         }
92         return authenticationCombo;
93     }
94     /**
95      * This method initializes jCheckBox
96      *
97      * @return javax.swing.JCheckBox
98      */

99     private JCheckBox JavaDoc getHttpAdaptor() {
100         if (httpAdaptor == null) {
101             httpAdaptor = new JCheckBox JavaDoc();
102             httpAdaptor.setName("httpAdaptor");
103             httpAdaptor.setPreferredSize(new java.awt.Dimension JavaDoc(175,21));
104             httpAdaptor.setText("HTTP Adaptor");
105             httpAdaptor.setSelected(true);
106             httpAdaptor.addActionListener(new CustomActionListener());
107         }
108         return httpAdaptor;
109     }
110     /**
111      * This method initializes jTextField
112      *
113      * @return javax.swing.JTextField
114      */

115     private JTextField JavaDoc getHttpAdaptorText() {
116         if (httpAdaptorText == null) {
117             httpAdaptorText = new JTextField JavaDoc();
118             httpAdaptorText.setPreferredSize(new java.awt.Dimension JavaDoc(75,20));
119             httpAdaptorText.setName("httpAdaptorText");
120             httpAdaptorText.setText("9050");
121         }
122         return httpAdaptorText;
123     }
124     /**
125      * This method initializes jCheckBox
126      *
127      * @return javax.swing.JCheckBox
128      */

129     private JCheckBox JavaDoc getRmiAdaptor() {
130         if (rmiAdaptor == null) {
131             rmiAdaptor = new JCheckBox JavaDoc();
132             rmiAdaptor.setName("rmiAdaptor");
133             rmiAdaptor.setPreferredSize(new java.awt.Dimension JavaDoc(175,21));
134             rmiAdaptor.setSelected(true);
135             rmiAdaptor.setText("RMI/JRMP Adaptor");
136             rmiAdaptor.addActionListener(new CustomActionListener());
137         }
138         return rmiAdaptor;
139     }
140     /**
141      * This method initializes jTextField
142      *
143      * @return javax.swing.JTextField
144      */

145     private JTextField JavaDoc getRmiAdaptorText() {
146         if (rmiAdaptorText == null) {
147             rmiAdaptorText = new JTextField JavaDoc();
148             rmiAdaptorText.setName("rmiAdaptorText");
149             rmiAdaptorText.setPreferredSize(new java.awt.Dimension JavaDoc(75,20));
150             rmiAdaptorText.setText("1099");
151         }
152         return rmiAdaptorText;
153     }
154     
155     public void setHttpPort (String JavaDoc port){
156         getHttpAdaptorText().setText(port);
157     }
158     
159     public String JavaDoc getHttpPort (){
160         return getHttpAdaptorText().getText();
161     }
162     
163     public void setRmiPort (String JavaDoc port){
164         getRmiAdaptorText().setText(port);
165     }
166     
167     public String JavaDoc getRmiPort (){
168         return getRmiAdaptorText().getText();
169     }
170     
171     public void setHttpChecked (boolean selected){
172         getHttpAdaptor().setSelected(selected);
173         
174         httpAdaptorLabel.setEnabled(getHttpAdaptor().isSelected());
175         getHttpAdaptorText().setEnabled(getHttpAdaptor().isSelected());
176     }
177     
178     public boolean getHttpChecked (){
179         return getHttpAdaptor().isSelected();
180     }
181     
182     public void setRmiChecked (boolean selected){
183         getRmiAdaptor().setSelected(selected);
184         
185         rmiAdaptorLabel.setEnabled(getRmiAdaptor().isSelected());
186         getRmiAdaptorText().setEnabled(getRmiAdaptor().isSelected());
187     }
188     
189     public boolean getRmiChecked (){
190         return getRmiAdaptor().isSelected();
191     }
192     
193     public void setComboSelection (String JavaDoc select){
194         getAuthenticationCombo().setSelectedItem(select);
195     }
196     
197     public String JavaDoc getComboSelection (){
198         return (String JavaDoc)getAuthenticationCombo().getSelectedItem();
199     }
200     
201     private class CustomAction extends AbstractAction JavaDoc {
202         public void actionPerformed(ActionEvent JavaDoc ae) {
203             String JavaDoc command = ae.getActionCommand();
204             if ("HTTP Adaptor".equals(command)) {
205                 httpAdaptorLabel.setEnabled(getHttpAdaptor().isSelected());
206                 getHttpAdaptorText().setEnabled(getHttpAdaptor().isSelected());
207             } else if ("RMI/JRMP Adaptor".equals(command)) {
208                 rmiAdaptorLabel.setEnabled(getRmiAdaptor().isSelected());
209                 getRmiAdaptorText().setEnabled(getRmiAdaptor().isSelected());
210             }
211         }
212     }
213
214     private class CustomActionListener implements ActionListener JavaDoc {
215
216         protected AbstractAction JavaDoc action;
217
218         public CustomActionListener() {
219             action = new CustomAction();
220         }
221
222         public void actionPerformed(ActionEvent JavaDoc e) {
223             action.actionPerformed(e);
224         }
225     }
226     
227     public boolean checkEntries (){
228         boolean valid = true;
229         if (httpAdaptor.isSelected()){
230             if ("".equals(httpAdaptorText.getText())||httpAdaptorText.getText()==null){
231                 displayErrorMessage("Http Adaptor Port");
232                 valid = false;
233             } else {
234                 try {
235                     int temp = Integer.parseInt(httpAdaptorText.getText());
236                 } catch (NumberFormatException JavaDoc ex){
237                     displayErrorMessage("Http Adaptor Port");
238                     valid = false;
239                 }
240             }
241         }
242         
243         if (rmiAdaptor.isSelected()){
244             if ("".equals(rmiAdaptorText.getText())||rmiAdaptorText.getText()==null){
245                 displayErrorMessage("RMI/JRMP Adaptor Port");
246                 valid = false;
247             } else {
248                 try {
249                     int temp = Integer.parseInt(rmiAdaptorText.getText());
250                 } catch (NumberFormatException JavaDoc ex){
251                     displayErrorMessage("RMI/JRMP Adaptor Port");
252                     valid = false;
253                 }
254             }
255         }
256         return valid;
257     }
258     
259     private void displayErrorMessage(String JavaDoc field){
260         JOptionPane.showMessageDialog(null, "Check '"+field+"' Field Setting!", "Enhydra Configuration Tool - Houston, we have a problem!",
261                 JOptionPane.ERROR_MESSAGE);
262     }
263 }
264
Popular Tags