Skip to content

Commit

Permalink
v2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed Jun 16, 2016
1 parent 5432d95 commit ef8d8e1
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 45 deletions.
Binary file added release/ReactClient-2.1.exe
Binary file not shown.
Binary file added release/ReactClient-2.1.jar
Binary file not shown.
161 changes: 161 additions & 0 deletions src/org/cyberpwn/react/EditConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package org.cyberpwn.react;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import org.cyberpwn.react.network.NetworkedServer;
import org.cyberpwn.react.ui.PortJTextField;

import net.miginfocom.swing.MigLayout;

public class EditConnection extends JDialog
{
private static final long serialVersionUID = 801014377635942783L;
private final JPanel contentPanel = new JPanel();
private JTextField txtLocalhost;
private JTextField textField_1;
private JTextField txtCyberpwn;
private JTextField txtReactisawesome;
private JTextField txtFancyServer;

public static void editConnection(NetworkedServer ns)
{
try
{
EditConnection dialog = new EditConnection(ns);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
}

catch(Exception e)
{
e.printStackTrace();
}
}

public EditConnection(final NetworkedServer ns)
{
setIconImage(Toolkit.getDefaultToolkit().getImage(EditConnection.class.getResource("/org/cyberpwn/react/ui/server-low.png")));
setTitle("Add a Connection");
setBounds(100, 100, 450, 397);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));

getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(new MigLayout("", "[grow][grow]", "[][][][][][][][]"));
{
JLabel lblName = new JLabel("Name");
lblName.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
contentPanel.add(lblName, "cell 0 0");
}
{
txtFancyServer = new JTextField();
txtFancyServer.setText(ns.getName());
txtFancyServer.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
txtFancyServer.setColumns(10);
contentPanel.add(txtFancyServer, "cell 0 1,growx");
}
{
JLabel lblAddress = new JLabel("Address");
lblAddress.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
contentPanel.add(lblAddress, "cell 0 2");
}
{
JLabel lblPort = new JLabel("Port");
lblPort.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
contentPanel.add(lblPort, "cell 1 2");
}
{
txtLocalhost = new JTextField();
txtLocalhost.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
txtLocalhost.setText(ns.getAddress());
contentPanel.add(txtLocalhost, "cell 0 3,growx");
txtLocalhost.setColumns(10);
}
{
textField_1 = new PortJTextField();
textField_1.setText(ns.getPort().toString());
textField_1.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
textField_1.setColumns(10);
contentPanel.add(textField_1, "cell 1 3,alignx left");
}
{
JLabel lblUsername = new JLabel("Username");
lblUsername.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
contentPanel.add(lblUsername, "cell 0 4");
}
{
txtCyberpwn = new JTextField();
txtCyberpwn.setText(ns.getUsername());
txtCyberpwn.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
txtCyberpwn.setColumns(10);
contentPanel.add(txtCyberpwn, "cell 0 5,growx");
}
{
JLabel lblPassword = new JLabel("Password");
lblPassword.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
contentPanel.add(lblPassword, "cell 0 6");
}
{
txtReactisawesome = new JPasswordField();
txtReactisawesome.setText(ns.getPassword());
txtReactisawesome.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
txtReactisawesome.setColumns(10);

contentPanel.add(txtReactisawesome, "cell 0 7,growx");
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));

getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("Edit Connection");
okButton.addMouseListener(new MouseAdapter()
{
@Override
public void mouseReleased(MouseEvent e)
{
editServer(txtFancyServer.getText(), txtLocalhost.getText(), Integer.valueOf(textField_1.getText()), txtCyberpwn.getText(), txtReactisawesome.getText(), ns);
setVisible(false);
dispose();
}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}

{
JButton cancelButton = new JButton("Cancel");
cancelButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e)
{
setVisible(false);
dispose();
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}

public void editServer(String name, String address, int port, String username, String password, NetworkedServer ns)
{
ReactClient.getInstance().validateConnectionEdit(name, address, port, username, password, ns);
}
}
25 changes: 25 additions & 0 deletions src/org/cyberpwn/react/ReactClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,29 @@ public void deleteConnection(NetworkedServer ns)

restart();
}

public void editConnection(NetworkedServer ns)
{
EditConnection.editConnection(ns);
}

public void validateConnectionEdit(String name, String address, int port, String username, String password, NetworkedServer ns)
{
network.rename(name, ns);
ns.setPort(port);
ns.setAddress(address);
ns.setPassword(password);
ns.setUsername(username);

try
{
network.save();
}

catch(IOException e)
{
e.printStackTrace();
}
restart();
}
}
17 changes: 17 additions & 0 deletions src/org/cyberpwn/react/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ public void fromJson(JSONObject network)
}
}

public void rename(String newName, NetworkedServer ns)
{
servers.remove(ns.getName());
servers.put(newName, ns);
ns.setName(newName);

try
{
save();
}

catch(IOException e)
{
e.printStackTrace();
}
}

public JSONObject toJson()
{
JSONObject js = new JSONObject();
Expand Down
1 change: 1 addition & 0 deletions src/org/cyberpwn/react/network/NetworkedServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void run()
{
sample = getData();
tab.push(sample);

}
}
});
Expand Down
17 changes: 2 additions & 15 deletions src/org/cyberpwn/react/network/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import org.cyberpwn.react.util.GMap;
import org.cyberpwn.react.util.JSONObject;
Expand Down Expand Up @@ -63,19 +60,9 @@ public void run()
callback.run(data, false);
}

catch(UnknownHostException e)
catch(Exception e)
{
e.printStackTrace();
}

catch(SocketTimeoutException e)
{
e.printStackTrace();
}

catch(IOException e)
{
e.printStackTrace();

}
}
}
17 changes: 2 additions & 15 deletions src/org/cyberpwn/react/network/RequestBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import org.cyberpwn.react.util.GMap;
import org.cyberpwn.react.util.JSONObject;
Expand Down Expand Up @@ -63,19 +60,9 @@ public void run()
callback.run(data, false);
}

catch(UnknownHostException e)
catch(Exception e)
{
e.printStackTrace();
}

catch(SocketTimeoutException e)
{
e.printStackTrace();
}

catch(IOException e)
{
e.printStackTrace();

}
}
}
Loading

0 comments on commit ef8d8e1

Please sign in to comment.