001: /*--
002:
003: Copyright (C) 2002 Anthony Eden.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: me@anthonyeden.com.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Anthony Eden (me@anthonyeden.com).
027:
028: In addition, I request (but do not require) that you include in the
029: end-user documentation provided with the redistribution and/or in the
030: software itself an acknowledgement equivalent to the following:
031: "This product includes software developed by
032: Anthony Eden (http://www.anthonyeden.com/)."
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
038: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
039: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
040: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
041: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
042: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
043: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
044: POSSIBILITY OF SUCH DAMAGE.
045:
046: For more information on OBE, please see <http://obe.sourceforge.net/>.
047:
048: */
049:
050: package org.obe.client;
051:
052: import java.awt.Insets;
053: import java.awt.BorderLayout;
054: import java.awt.GridBagLayout;
055: import java.awt.GridBagConstraints;
056: import java.awt.event.ActionEvent;
057: import java.awt.event.ActionListener;
058:
059: import javax.swing.JLabel;
060: import javax.swing.JPanel;
061: import javax.swing.JDialog;
062: import javax.swing.JButton;
063: import javax.swing.JTextField;
064:
065: /** Dialog for connecting to an XmlRpc server.
066:
067: @author Anthony Eden
068: */
069:
070: public class XmlRpcConnectDialog extends JDialog {
071:
072: /** Construct a new XmlRpcConnectDialog.
073:
074: @param host The host name
075: @param port The port number
076: */
077:
078: public XmlRpcConnectDialog(String host, int port) {
079: init();
080:
081: hostField.setText(host);
082: portField.setText(Integer.toString(port));
083: }
084:
085: /** Show the dialog as a modal dialog.
086:
087: @return The result code
088: */
089:
090: public int showDialog() {
091: setModal(true);
092: setVisible(true);
093: return result;
094: }
095:
096: /** Get the host specified in the dialog.
097:
098: @return The host
099: */
100:
101: public String getHost() {
102: return hostField.getText();
103: }
104:
105: /** Get the post specified in the dialog.
106:
107: @return The port
108: */
109:
110: public int getPort() {
111: return Integer.parseInt(portField.getText());
112: }
113:
114: /** Return true if the port is editable. The default is true.
115:
116: @return True if the port is editable
117: */
118:
119: public boolean isPortEditable() {
120: return portField.isEditable();
121: }
122:
123: /** Set the port editable state.
124:
125: @param portEditable The new state
126: */
127:
128: public void setPortEditable(boolean portEditable) {
129: portField.setEditable(portEditable);
130: }
131:
132: /** Method invoked when a user clicks on the "Connect" button. */
133:
134: public void connect() {
135: result = APPROVE_OPTION;
136: dispose();
137: }
138:
139: /** Method invoked when a user clicks on the "Cancel" button. */
140:
141: public void cancel() {
142: result = CANCEL_OPTION;
143: dispose();
144: }
145:
146: /** Initialize the dialog's UI. */
147:
148: private void init() {
149: getContentPane().setLayout(new BorderLayout());
150: getContentPane().add(createInputPanel(), BorderLayout.CENTER);
151: getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
152:
153: setTitle("Connect to Host");
154: setResizable(false);
155:
156: getRootPane().setDefaultButton(connectButton);
157:
158: pack();
159: }
160:
161: /** Create the input panel which contains the host and port fields.
162:
163: @return The panel
164: */
165:
166: private JPanel createInputPanel() {
167: JPanel panel = new JPanel();
168:
169: GridBagLayout gbl = new GridBagLayout();
170: GridBagConstraints gbc = new GridBagConstraints();
171: panel.setLayout(gbl);
172:
173: gbc.insets = new Insets(1, 1, 1, 1);
174: gbc.anchor = GridBagConstraints.WEST;
175: gbc.fill = GridBagConstraints.HORIZONTAL;
176:
177: hostLabel = new JLabel("Host");
178: gbc.weightx = 0;
179: gbc.gridwidth = 1;
180: gbl.setConstraints(hostLabel, gbc);
181: panel.add(hostLabel);
182:
183: hostField = new JTextField();
184: hostField.setColumns(32);
185: gbc.weightx = 1;
186: gbc.gridwidth = GridBagConstraints.REMAINDER;
187: gbl.setConstraints(hostField, gbc);
188: panel.add(hostField);
189:
190: portLabel = new JLabel("Port");
191: gbc.weightx = 0;
192: gbc.gridwidth = 1;
193: gbl.setConstraints(portLabel, gbc);
194: panel.add(portLabel);
195:
196: portField = new JTextField();
197: portField.setColumns(8);
198: gbc.weightx = 1;
199: gbc.gridwidth = GridBagConstraints.REMAINDER;
200: gbl.setConstraints(portField, gbc);
201: panel.add(portField);
202:
203: return panel;
204: }
205:
206: /** Create the button panel which contains "Connect" and "Cancel" buttons.
207:
208: @return The panel
209: */
210:
211: private JPanel createButtonPanel() {
212: JPanel panel = new JPanel();
213:
214: connectButton = new JButton("Connect");
215: connectButton.addActionListener(new ActionListener() {
216: public void actionPerformed(ActionEvent evt) {
217: connect();
218: }
219: });
220: panel.add(connectButton);
221:
222: cancelButton = new JButton("Cancel");
223: cancelButton.addActionListener(new ActionListener() {
224: public void actionPerformed(ActionEvent evt) {
225: cancel();
226: }
227: });
228: panel.add(cancelButton);
229:
230: return panel;
231: }
232:
233: /** Return value when the user approves the connection. */
234: public static final int APPROVE_OPTION = 1;
235:
236: /** Return value when the user cancels the connection. */
237: public static final int CANCEL_OPTION = 2;
238:
239: private int result = CANCEL_OPTION;
240:
241: private JLabel hostLabel;
242: private JTextField hostField;
243: private JLabel portLabel;
244: private JTextField portField;
245: private JButton connectButton;
246: private JButton cancelButton;
247:
248: }
|