|
| 1 | +package org.cyberpwn.react; |
| 2 | + |
| 3 | +import java.awt.BorderLayout; |
| 4 | +import java.awt.FlowLayout; |
| 5 | +import java.awt.Font; |
| 6 | +import java.awt.Toolkit; |
| 7 | +import java.awt.event.MouseAdapter; |
| 8 | +import java.awt.event.MouseEvent; |
| 9 | + |
| 10 | +import javax.swing.JButton; |
| 11 | +import javax.swing.JDialog; |
| 12 | +import javax.swing.JLabel; |
| 13 | +import javax.swing.JPanel; |
| 14 | +import javax.swing.JPasswordField; |
| 15 | +import javax.swing.JTextField; |
| 16 | +import javax.swing.border.EmptyBorder; |
| 17 | + |
| 18 | +import org.cyberpwn.react.network.NetworkedServer; |
| 19 | +import org.cyberpwn.react.ui.PortJTextField; |
| 20 | + |
| 21 | +import net.miginfocom.swing.MigLayout; |
| 22 | + |
| 23 | +public class EditConnection extends JDialog |
| 24 | +{ |
| 25 | + private static final long serialVersionUID = 801014377635942783L; |
| 26 | + private final JPanel contentPanel = new JPanel(); |
| 27 | + private JTextField txtLocalhost; |
| 28 | + private JTextField textField_1; |
| 29 | + private JTextField txtCyberpwn; |
| 30 | + private JTextField txtReactisawesome; |
| 31 | + private JTextField txtFancyServer; |
| 32 | + |
| 33 | + public static void editConnection(NetworkedServer ns) |
| 34 | + { |
| 35 | + try |
| 36 | + { |
| 37 | + EditConnection dialog = new EditConnection(ns); |
| 38 | + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
| 39 | + dialog.setVisible(true); |
| 40 | + } |
| 41 | + |
| 42 | + catch(Exception e) |
| 43 | + { |
| 44 | + e.printStackTrace(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + public EditConnection(final NetworkedServer ns) |
| 49 | + { |
| 50 | + setIconImage(Toolkit.getDefaultToolkit().getImage(EditConnection.class.getResource("/org/cyberpwn/react/ui/server-low.png"))); |
| 51 | + setTitle("Add a Connection"); |
| 52 | + setBounds(100, 100, 450, 397); |
| 53 | + getContentPane().setLayout(new BorderLayout()); |
| 54 | + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
| 55 | + |
| 56 | + getContentPane().add(contentPanel, BorderLayout.CENTER); |
| 57 | + contentPanel.setLayout(new MigLayout("", "[grow][grow]", "[][][][][][][][]")); |
| 58 | + { |
| 59 | + JLabel lblName = new JLabel("Name"); |
| 60 | + lblName.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 61 | + contentPanel.add(lblName, "cell 0 0"); |
| 62 | + } |
| 63 | + { |
| 64 | + txtFancyServer = new JTextField(); |
| 65 | + txtFancyServer.setText(ns.getName()); |
| 66 | + txtFancyServer.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 67 | + txtFancyServer.setColumns(10); |
| 68 | + contentPanel.add(txtFancyServer, "cell 0 1,growx"); |
| 69 | + } |
| 70 | + { |
| 71 | + JLabel lblAddress = new JLabel("Address"); |
| 72 | + lblAddress.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 73 | + contentPanel.add(lblAddress, "cell 0 2"); |
| 74 | + } |
| 75 | + { |
| 76 | + JLabel lblPort = new JLabel("Port"); |
| 77 | + lblPort.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 78 | + contentPanel.add(lblPort, "cell 1 2"); |
| 79 | + } |
| 80 | + { |
| 81 | + txtLocalhost = new JTextField(); |
| 82 | + txtLocalhost.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 83 | + txtLocalhost.setText(ns.getAddress()); |
| 84 | + contentPanel.add(txtLocalhost, "cell 0 3,growx"); |
| 85 | + txtLocalhost.setColumns(10); |
| 86 | + } |
| 87 | + { |
| 88 | + textField_1 = new PortJTextField(); |
| 89 | + textField_1.setText(ns.getPort().toString()); |
| 90 | + textField_1.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 91 | + textField_1.setColumns(10); |
| 92 | + contentPanel.add(textField_1, "cell 1 3,alignx left"); |
| 93 | + } |
| 94 | + { |
| 95 | + JLabel lblUsername = new JLabel("Username"); |
| 96 | + lblUsername.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 97 | + contentPanel.add(lblUsername, "cell 0 4"); |
| 98 | + } |
| 99 | + { |
| 100 | + txtCyberpwn = new JTextField(); |
| 101 | + txtCyberpwn.setText(ns.getUsername()); |
| 102 | + txtCyberpwn.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 103 | + txtCyberpwn.setColumns(10); |
| 104 | + contentPanel.add(txtCyberpwn, "cell 0 5,growx"); |
| 105 | + } |
| 106 | + { |
| 107 | + JLabel lblPassword = new JLabel("Password"); |
| 108 | + lblPassword.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 109 | + contentPanel.add(lblPassword, "cell 0 6"); |
| 110 | + } |
| 111 | + { |
| 112 | + txtReactisawesome = new JPasswordField(); |
| 113 | + txtReactisawesome.setText(ns.getPassword()); |
| 114 | + txtReactisawesome.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 115 | + txtReactisawesome.setColumns(10); |
| 116 | + |
| 117 | + contentPanel.add(txtReactisawesome, "cell 0 7,growx"); |
| 118 | + } |
| 119 | + { |
| 120 | + JPanel buttonPane = new JPanel(); |
| 121 | + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
| 122 | + |
| 123 | + getContentPane().add(buttonPane, BorderLayout.SOUTH); |
| 124 | + { |
| 125 | + JButton okButton = new JButton("Edit Connection"); |
| 126 | + okButton.addMouseListener(new MouseAdapter() |
| 127 | + { |
| 128 | + @Override |
| 129 | + public void mouseReleased(MouseEvent e) |
| 130 | + { |
| 131 | + editServer(txtFancyServer.getText(), txtLocalhost.getText(), Integer.valueOf(textField_1.getText()), txtCyberpwn.getText(), txtReactisawesome.getText(), ns); |
| 132 | + setVisible(false); |
| 133 | + dispose(); |
| 134 | + } |
| 135 | + }); |
| 136 | + okButton.setActionCommand("OK"); |
| 137 | + buttonPane.add(okButton); |
| 138 | + getRootPane().setDefaultButton(okButton); |
| 139 | + } |
| 140 | + |
| 141 | + { |
| 142 | + JButton cancelButton = new JButton("Cancel"); |
| 143 | + cancelButton.addMouseListener(new MouseAdapter() { |
| 144 | + @Override |
| 145 | + public void mouseReleased(MouseEvent e) |
| 146 | + { |
| 147 | + setVisible(false); |
| 148 | + dispose(); |
| 149 | + } |
| 150 | + }); |
| 151 | + cancelButton.setActionCommand("Cancel"); |
| 152 | + buttonPane.add(cancelButton); |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + public void editServer(String name, String address, int port, String username, String password, NetworkedServer ns) |
| 158 | + { |
| 159 | + ReactClient.getInstance().validateConnectionEdit(name, address, port, username, password, ns); |
| 160 | + } |
| 161 | +} |
0 commit comments