forked from External/mage
Moved /src and /resources to maven stardard /src/main/java and /src/main/resources. Hope it's ok, if not I'll revert.
This commit is contained in:
parent
b45cc23d72
commit
f775f7c511
155 changed files with 0 additions and 9 deletions
249
Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java
Normal file
249
Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. 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 following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS 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 BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS 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.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ConnectDialog.java
|
||||
*
|
||||
* Created on 20-Jan-2010, 9:37:07 PM
|
||||
*/
|
||||
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JOptionPane;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ConnectDialog extends MageDialog {
|
||||
|
||||
private final static Logger logger = Logging.getLogger(ConnectDialog.class.getName());
|
||||
|
||||
/** Creates new form ConnectDialog */
|
||||
public ConnectDialog() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
this.txtServer.setText(MageFrame.getPreferences().get("serverAddress", Config.serverName));
|
||||
this.txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
||||
this.txtUserName.setText(MageFrame.getPreferences().get("userName", ""));
|
||||
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get("autoConnect", "false")));
|
||||
this.setModal(true);
|
||||
this.setLocation(50, 50);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
txtServer = new javax.swing.JTextField();
|
||||
lblServer = new javax.swing.JLabel();
|
||||
lblPort = new javax.swing.JLabel();
|
||||
txtPort = new javax.swing.JTextField();
|
||||
txtUserName = new javax.swing.JTextField();
|
||||
lblUserName = new javax.swing.JLabel();
|
||||
btnConnect = new javax.swing.JButton();
|
||||
btnCancel = new javax.swing.JButton();
|
||||
chkAutoConnect = new javax.swing.JCheckBox();
|
||||
|
||||
setTitle("Connect");
|
||||
setNormalBounds(new java.awt.Rectangle(100, 100, 410, 307));
|
||||
|
||||
lblServer.setLabelFor(txtServer);
|
||||
lblServer.setText("Server:");
|
||||
|
||||
lblPort.setLabelFor(txtPort);
|
||||
lblPort.setText("Port:");
|
||||
|
||||
txtPort.addKeyListener(new java.awt.event.KeyAdapter() {
|
||||
public void keyTyped(java.awt.event.KeyEvent evt) {
|
||||
ConnectDialog.this.keyTyped(evt);
|
||||
}
|
||||
});
|
||||
|
||||
lblUserName.setLabelFor(txtUserName);
|
||||
lblUserName.setText("User Name:");
|
||||
|
||||
btnConnect.setText("Connect");
|
||||
btnConnect.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnConnectActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnCancel.setText("Cancel");
|
||||
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnCancelActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
chkAutoConnect.setText("Automatically connect to this server next time");
|
||||
chkAutoConnect.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
chkAutoConnectActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(btnConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblPort)
|
||||
.addComponent(lblServer)
|
||||
.addComponent(lblUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(131, 131, 131))
|
||||
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
|
||||
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblServer)
|
||||
.addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblPort))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lblUserName))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(chkAutoConnect)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnCancel)
|
||||
.addComponent(btnConnect))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
this.setVisible(false);
|
||||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
|
||||
|
||||
if (txtUserName.getText().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a user name");
|
||||
return;
|
||||
}
|
||||
if (txtServer.getText().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a server address");
|
||||
return;
|
||||
}
|
||||
if (txtPort.getText().isEmpty()) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Please provide a port number");
|
||||
return;
|
||||
}
|
||||
if (Integer.valueOf(txtPort.getText()) < 1 || Integer.valueOf(txtPort.getText()) > 65535 ) {
|
||||
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
|
||||
txtPort.setText(MageFrame.getPreferences().get("serverPort", Integer.toString(Config.port)));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
if (MageFrame.connect(txtUserName.getText(), txtServer.getText(), Integer.valueOf(txtPort.getText()))) {
|
||||
MageFrame.getPreferences().put("serverAddress", txtServer.getText());
|
||||
MageFrame.getPreferences().put("serverPort", txtPort.getText());
|
||||
MageFrame.getPreferences().put("userName", txtUserName.getText());
|
||||
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||
this.setVisible(false);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(rootPane, "Unable to connect to server");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_btnConnectActionPerformed
|
||||
|
||||
private void keyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyTyped
|
||||
char c = evt.getKeyChar();
|
||||
if (!Character.isDigit(c))
|
||||
evt.consume();
|
||||
}//GEN-LAST:event_keyTyped
|
||||
|
||||
private void chkAutoConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAutoConnectActionPerformed
|
||||
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_chkAutoConnectActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnConnect;
|
||||
private javax.swing.JCheckBox chkAutoConnect;
|
||||
private javax.swing.JLabel lblPort;
|
||||
private javax.swing.JLabel lblServer;
|
||||
private javax.swing.JLabel lblUserName;
|
||||
private javax.swing.JTextField txtPort;
|
||||
private javax.swing.JTextField txtServer;
|
||||
private javax.swing.JTextField txtUserName;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue