|
| 1 | +package org.cyberpwn.react; |
| 2 | + |
| 3 | +import java.awt.BorderLayout; |
| 4 | +import java.awt.Color; |
| 5 | +import java.awt.FlowLayout; |
| 6 | +import java.awt.Font; |
| 7 | +import java.awt.Toolkit; |
| 8 | +import java.awt.event.MouseAdapter; |
| 9 | +import java.awt.event.MouseEvent; |
| 10 | +import javax.swing.JButton; |
| 11 | +import javax.swing.JDialog; |
| 12 | +import javax.swing.JLabel; |
| 13 | +import javax.swing.JPanel; |
| 14 | +import javax.swing.JTextPane; |
| 15 | +import javax.swing.SpringLayout; |
| 16 | +import javax.swing.border.EmptyBorder; |
| 17 | +import org.cyberpwn.react.network.NetworkedServer; |
| 18 | + |
| 19 | +public class ConnectionFailure extends JDialog |
| 20 | +{ |
| 21 | + private static final long serialVersionUID = 1L; |
| 22 | + private final JPanel contentPanel = new JPanel(); |
| 23 | + |
| 24 | + public static void failed(NetworkedServer ns) |
| 25 | + { |
| 26 | + try |
| 27 | + { |
| 28 | + ConnectionFailure dialog = new ConnectionFailure(ns); |
| 29 | + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
| 30 | + dialog.setVisible(true); |
| 31 | + } |
| 32 | + catch(Exception e) |
| 33 | + { |
| 34 | + e.printStackTrace(); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Create the dialog. |
| 40 | + */ |
| 41 | + public ConnectionFailure(final NetworkedServer ns) |
| 42 | + { |
| 43 | + setTitle("Problem Connecting to " + ns.getName()); |
| 44 | + setResizable(false); |
| 45 | + ReactClient.getInstance().lockConnection(ns); |
| 46 | + setType(Type.POPUP); |
| 47 | + setAlwaysOnTop(true); |
| 48 | + setIconImage(Toolkit.getDefaultToolkit().getImage(ConnectionFailure.class.getResource("/org/cyberpwn/react/ui/server-mini-red.png"))); |
| 49 | + setBounds(100, 100, 394, 296); |
| 50 | + getContentPane().setLayout(new BorderLayout()); |
| 51 | + contentPanel.setBackground(Color.WHITE); |
| 52 | + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); |
| 53 | + getContentPane().add(contentPanel, BorderLayout.CENTER); |
| 54 | + SpringLayout sl_contentPanel = new SpringLayout(); |
| 55 | + contentPanel.setLayout(sl_contentPanel); |
| 56 | + |
| 57 | + JLabel lblFailedToConnect = new JLabel("Failed to Connect"); |
| 58 | + lblFailedToConnect.setFont(new Font("Segoe UI Light", Font.PLAIN, 24)); |
| 59 | + sl_contentPanel.putConstraint(SpringLayout.NORTH, lblFailedToConnect, 10, SpringLayout.NORTH, contentPanel); |
| 60 | + sl_contentPanel.putConstraint(SpringLayout.WEST, lblFailedToConnect, 10, SpringLayout.WEST, contentPanel); |
| 61 | + contentPanel.add(lblFailedToConnect); |
| 62 | + |
| 63 | + JLabel lblLocalhost = new JLabel(ns.getUsername() + "@" + ns.getAddress() + ":" + ns.getPort()); |
| 64 | + sl_contentPanel.putConstraint(SpringLayout.NORTH, lblLocalhost, 6, SpringLayout.SOUTH, lblFailedToConnect); |
| 65 | + sl_contentPanel.putConstraint(SpringLayout.WEST, lblLocalhost, 0, SpringLayout.WEST, lblFailedToConnect); |
| 66 | + lblLocalhost.setFont(new Font("Segoe UI Light", Font.PLAIN, 18)); |
| 67 | + contentPanel.add(lblLocalhost); |
| 68 | + |
| 69 | + JTextPane txtpnSdfsdfsdf = new JTextPane(); |
| 70 | + txtpnSdfsdfsdf.setForeground(Color.GRAY); |
| 71 | + sl_contentPanel.putConstraint(SpringLayout.NORTH, txtpnSdfsdfsdf, 6, SpringLayout.SOUTH, lblLocalhost); |
| 72 | + sl_contentPanel.putConstraint(SpringLayout.WEST, txtpnSdfsdfsdf, 10, SpringLayout.WEST, contentPanel); |
| 73 | + sl_contentPanel.putConstraint(SpringLayout.SOUTH, txtpnSdfsdfsdf, -5, SpringLayout.SOUTH, contentPanel); |
| 74 | + sl_contentPanel.putConstraint(SpringLayout.EAST, txtpnSdfsdfsdf, -15, SpringLayout.EAST, contentPanel); |
| 75 | + txtpnSdfsdfsdf.setEditable(false); |
| 76 | + txtpnSdfsdfsdf.setFont(new Font("Segoe UI Light", Font.PLAIN, 15)); |
| 77 | + txtpnSdfsdfsdf.setText("Please ensure that your username, password, address and port are correct. Also make sure that the react remote server is running & you are connected to the internet. You also may want to check documentation for other debugging procedures."); |
| 78 | + contentPanel.add(txtpnSdfsdfsdf); |
| 79 | + { |
| 80 | + JPanel buttonPane = new JPanel(); |
| 81 | + buttonPane.setBackground(Color.WHITE); |
| 82 | + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
| 83 | + getContentPane().add(buttonPane, BorderLayout.SOUTH); |
| 84 | + |
| 85 | + JButton buttonEdit = new JButton("Edit"); |
| 86 | + buttonEdit.setFont(new Font("Segoe UI Light", Font.PLAIN, 14)); |
| 87 | + buttonEdit.addMouseListener(new MouseAdapter() |
| 88 | + { |
| 89 | + @Override |
| 90 | + public void mouseReleased(MouseEvent e) |
| 91 | + { |
| 92 | + setVisible(false); |
| 93 | + dispose(); |
| 94 | + ReactClient.getInstance().editConnection(ns); |
| 95 | + } |
| 96 | + }); |
| 97 | + buttonPane.add(buttonEdit); |
| 98 | + |
| 99 | + JButton btnRetry = new JButton("Retry"); |
| 100 | + btnRetry.setFont(new Font("Segoe UI Light", Font.PLAIN, 14)); |
| 101 | + btnRetry.addMouseListener(new MouseAdapter() |
| 102 | + { |
| 103 | + @Override |
| 104 | + public void mouseReleased(MouseEvent e) |
| 105 | + { |
| 106 | + setVisible(false); |
| 107 | + dispose(); |
| 108 | + ReactClient.getInstance().releaseConnection(ns); |
| 109 | + } |
| 110 | + }); |
| 111 | + buttonPane.add(btnRetry); |
| 112 | + |
| 113 | + JButton cancelButton = new JButton("Cancel"); |
| 114 | + cancelButton.setFont(new Font("Segoe UI Light", Font.PLAIN, 14)); |
| 115 | + cancelButton.setActionCommand("Cancel"); |
| 116 | + buttonPane.add(cancelButton); |
| 117 | + cancelButton.addMouseListener(new MouseAdapter() |
| 118 | + { |
| 119 | + @Override |
| 120 | + public void mouseReleased(MouseEvent e) |
| 121 | + { |
| 122 | + setVisible(false); |
| 123 | + dispose(); |
| 124 | + ReactClient.getInstance().deleteConnection(ns); |
| 125 | + } |
| 126 | + }); |
| 127 | + |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments