/*--
Copyright (C) 2002 Anthony Eden.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the disclaimer that follows
these conditions in the documentation and/or other materials
provided with the distribution.
3. The names "OBE" and "Open Business Engine" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
me@anthonyeden.com.
4. Products derived from this software may not be called "OBE" or
"Open Business Engine", nor may "OBE" or "Open Business Engine"
appear in their name, without prior written permission from
Anthony Eden (me@anthonyeden.com).
In addition, I request (but do not require) that you include in the
end-user documentation provided with the redistribution and/or in the
software itself an acknowledgement equivalent to the following:
"This product includes software developed by
Anthony Eden (http://www.anthonyeden.com/)."
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
For more information on OBE, please see <http://obe.sourceforge.net/>.
*/
package org.obe.client;
import java.awt.Insets;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JTextField;
/** Dialog for connecting to an XmlRpc server.
@author Anthony Eden
*/
public class XmlRpcConnectDialog extends JDialog{
/** Construct a new XmlRpcConnectDialog.
@param host The host name
@param port The port number
*/
public XmlRpcConnectDialog(String host, int port){
init();
hostField.setText(host);
portField.setText(Integer.toString(port));
}
/** Show the dialog as a modal dialog.
@return The result code
*/
public int showDialog(){
setModal(true);
setVisible(true);
return result;
}
/** Get the host specified in the dialog.
@return The host
*/
public String getHost(){
return hostField.getText();
}
/** Get the post specified in the dialog.
@return The port
*/
public int getPort(){
return Integer.parseInt(portField.getText());
}
/** Return true if the port is editable. The default is true.
@return True if the port is editable
*/
public boolean isPortEditable(){
return portField.isEditable();
}
/** Set the port editable state.
@param portEditable The new state
*/
public void setPortEditable(boolean portEditable){
portField.setEditable(portEditable);
}
/** Method invoked when a user clicks on the "Connect" button. */
public void connect(){
result = APPROVE_OPTION;
dispose();
}
/** Method invoked when a user clicks on the "Cancel" button. */
public void cancel(){
result = CANCEL_OPTION;
dispose();
}
/** Initialize the dialog's UI. */
private void init(){
getContentPane().setLayout(new BorderLayout());
getContentPane().add(createInputPanel(), BorderLayout.CENTER);
getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
setTitle("Connect to Host");
setResizable(false);
getRootPane().setDefaultButton(connectButton);
pack();
}
/** Create the input panel which contains the host and port fields.
@return The panel
*/
private JPanel createInputPanel(){
JPanel panel = new JPanel();
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
panel.setLayout(gbl);
gbc.insets = new Insets(1, 1, 1, 1);
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
hostLabel = new JLabel("Host");
gbc.weightx = 0;
gbc.gridwidth = 1;
gbl.setConstraints(hostLabel, gbc);
panel.add(hostLabel);
hostField = new JTextField();
hostField.setColumns(32);
gbc.weightx = 1;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints(hostField, gbc);
panel.add(hostField);
portLabel = new JLabel("Port");
gbc.weightx = 0;
gbc.gridwidth = 1;
gbl.setConstraints(portLabel, gbc);
panel.add(portLabel);
portField = new JTextField();
portField.setColumns(8);
gbc.weightx = 1;
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints(portField, gbc);
panel.add(portField);
return panel;
}
/** Create the button panel which contains "Connect" and "Cancel" buttons.
@return The panel
*/
private JPanel createButtonPanel(){
JPanel panel = new JPanel();
connectButton = new JButton("Connect");
connectButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
connect();
}
});
panel.add(connectButton);
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
cancel();
}
});
panel.add(cancelButton);
return panel;
}
/** Return value when the user approves the connection. */
public static final int APPROVE_OPTION = 1;
/** Return value when the user cancels the connection. */
public static final int CANCEL_OPTION = 2;
private int result = CANCEL_OPTION;
private JLabel hostLabel;
private JTextField hostField;
private JLabel portLabel;
private JTextField portField;
private JButton connectButton;
private JButton cancelButton;
}
|