KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25
26 import javax.swing.JOptionPane JavaDoc;
27 import javax.swing.JTextField JavaDoc;
28
29 /**
30  *
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:23 $
33  * @since 4.1
34  */

35 class ConnectDialog
36     extends AbstractTabularOptionDialog
37 {
38     private JTextField JavaDoc m_urlField;
39     private URL JavaDoc m_url;
40     
41     /*---------------------------------------------------------------
42      * Constructors
43      *-------------------------------------------------------------*/

44     /**
45      * Creates a new ConnectDialog.
46      *
47      * @param frame Frame which owns the dialog.
48      */

49     ConnectDialog( InstrumentClientFrame frame )
50     {
51         super( frame, "Connect to Remote Instrument Manager",
52             AbstractOptionDialog.BUTTON_OK | AbstractOptionDialog.BUTTON_CANCEL );
53     }
54     
55     /*---------------------------------------------------------------
56      * AbstractOptionDialog Methods
57      *-------------------------------------------------------------*/

58     /**
59      * Returns the message to show at the top of the dialog.
60      *
61      * @return The text of the message.
62      */

63     protected String JavaDoc getMessage()
64     {
65         return "Please enter the url of the InstrumentManager to connect to.";
66     }
67     
68     /**
69      * Goes through and validates the fields in the dialog.
70      *
71      * @return True if the fields were Ok.
72      */

73     protected boolean validateFields()
74     {
75         // Check the URL.
76
URL JavaDoc url;
77         try
78         {
79             url = new URL JavaDoc( m_urlField.getText().trim() );
80         }
81         catch ( MalformedURLException JavaDoc e )
82         {
83             JOptionPane.showMessageDialog( this, "Please enter a valid url: " + e.getMessage(),
84                 "Invalid URL", JOptionPane.ERROR_MESSAGE );
85             return false;
86         }
87         m_url = url;
88         
89         return true;
90     }
91     
92     /*---------------------------------------------------------------
93      * AbstractTabularOptionDialog Methods
94      *-------------------------------------------------------------*/

95     /**
96      * Returns an array of labels to use for the components returned from
97      * getMainPanelComponents().
98      *
99      * @returns An array of labels.
100      */

101     protected String JavaDoc[] getMainPanelLabels()
102     {
103         return new String JavaDoc[]
104         {
105             "URL:"
106         };
107     }
108     
109     /**
110      * Returns an array of components to show in the main panel of the dialog.
111      *
112      * @returns An array of components.
113      */

114     protected Component JavaDoc[] getMainPanelComponents()
115     {
116         m_urlField = new JTextField JavaDoc();
117         m_urlField.setColumns( 30 );
118         
119         return new Component JavaDoc[]
120         {
121             m_urlField
122         };
123     }
124         
125     /*---------------------------------------------------------------
126      * Methods
127      *-------------------------------------------------------------*/

128     /**
129      * Sets the initial URL to be shown in the URL TextField.
130      *
131      * @param url The initial URL.
132      */

133     void setURL( URL JavaDoc url )
134     {
135         m_url = url;
136         m_urlField.setText( url.toExternalForm() );
137     }
138     
139     /**
140      * Returns the URL set in the dialog.
141      *
142      * @return The URL.
143      */

144     URL JavaDoc getURL()
145     {
146         return m_url;
147     }
148 }
149
150
Popular Tags