Skip to content

Commit b325a65

Browse files
committed
Connection fixes
1 parent 5339fea commit b325a65

File tree

7 files changed

+208
-30
lines changed

7 files changed

+208
-30
lines changed

src/org/cyberpwn/react/AboutReact.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.awt.Font;
44
import java.awt.Window.Type;
5-
65
import javax.swing.ImageIcon;
76
import javax.swing.JFrame;
87
import javax.swing.JLabel;
@@ -11,6 +10,7 @@
1110
public class AboutReact
1211
{
1312
private JFrame frame;
13+
private String version = "2.3";
1414

1515
public AboutReact()
1616
{
@@ -45,5 +45,11 @@ private void initialize()
4545
springLayout.putConstraint(SpringLayout.WEST, lblNewLabel, 143, SpringLayout.WEST, frame.getContentPane());
4646
springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel, -6, SpringLayout.NORTH, lblReactClient);
4747
frame.getContentPane().add(lblNewLabel);
48+
49+
JLabel labelVersion = new JLabel("Version " + version);
50+
springLayout.putConstraint(SpringLayout.NORTH, labelVersion, 24, SpringLayout.NORTH, lblReactClient);
51+
springLayout.putConstraint(SpringLayout.WEST, labelVersion, 6, SpringLayout.EAST, lblReactClient);
52+
labelVersion.setFont(new Font("Segoe UI Light", Font.PLAIN, 18));
53+
frame.getContentPane().add(labelVersion);
4854
}
4955
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
}

src/org/cyberpwn/react/EditConnection.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66
import java.awt.Toolkit;
77
import java.awt.event.MouseAdapter;
88
import java.awt.event.MouseEvent;
9-
109
import javax.swing.JButton;
1110
import javax.swing.JDialog;
1211
import javax.swing.JLabel;
1312
import javax.swing.JPanel;
1413
import javax.swing.JPasswordField;
1514
import javax.swing.JTextField;
1615
import javax.swing.border.EmptyBorder;
17-
1816
import org.cyberpwn.react.network.NetworkedServer;
1917
import org.cyberpwn.react.ui.PortJTextField;
20-
2118
import net.miginfocom.swing.MigLayout;
2219

2320
public class EditConnection extends JDialog
@@ -37,7 +34,7 @@ public static void editConnection(NetworkedServer ns)
3734
EditConnection dialog = new EditConnection(ns);
3835
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
3936
dialog.setVisible(true);
40-
}
37+
}
4138

4239
catch(Exception e)
4340
{
@@ -123,14 +120,15 @@ public EditConnection(final NetworkedServer ns)
123120
getContentPane().add(buttonPane, BorderLayout.SOUTH);
124121
{
125122
JButton okButton = new JButton("Edit Connection");
126-
okButton.addMouseListener(new MouseAdapter()
123+
okButton.addMouseListener(new MouseAdapter()
127124
{
128125
@Override
129126
public void mouseReleased(MouseEvent e)
130127
{
131128
editServer(txtFancyServer.getText(), txtLocalhost.getText(), Integer.valueOf(textField_1.getText()), txtCyberpwn.getText(), txtReactisawesome.getText(), ns);
132129
setVisible(false);
133130
dispose();
131+
ReactClient.getInstance().releaseConnection(ns);
134132
}
135133
});
136134
okButton.setActionCommand("OK");
@@ -140,9 +138,10 @@ public void mouseReleased(MouseEvent e)
140138

141139
{
142140
JButton cancelButton = new JButton("Cancel");
143-
cancelButton.addMouseListener(new MouseAdapter() {
141+
cancelButton.addMouseListener(new MouseAdapter()
142+
{
144143
@Override
145-
public void mouseReleased(MouseEvent e)
144+
public void mouseReleased(MouseEvent e)
146145
{
147146
setVisible(false);
148147
dispose();

src/org/cyberpwn/react/ReactClient.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.awt.event.MouseAdapter;
1010
import java.awt.event.MouseEvent;
1111
import java.io.IOException;
12-
1312
import javax.swing.ImageIcon;
1413
import javax.swing.JFrame;
1514
import javax.swing.JLabel;
@@ -22,15 +21,14 @@
2221
import javax.swing.UIManager;
2322
import javax.swing.border.BevelBorder;
2423
import javax.swing.border.SoftBevelBorder;
25-
2624
import org.apache.commons.lang3.StringUtils;
2725
import org.cyberpwn.react.network.Network;
2826
import org.cyberpwn.react.network.NetworkScheduler;
2927
import org.cyberpwn.react.network.NetworkedServer;
3028
import org.cyberpwn.react.ui.AbstractTabRenderer;
3129
import org.cyberpwn.react.ui.JXTabbedPane;
3230
import org.cyberpwn.react.ui.ServerTab;
33-
31+
import org.cyberpwn.react.util.GList;
3432
import net.miginfocom.swing.MigLayout;
3533

3634
public class ReactClient
@@ -40,6 +38,7 @@ public class ReactClient
4038
private JFrame frmReactClient;
4139
private static ReactClient instance;
4240
public JXTabbedPane tabbedPane;
41+
private GList<NetworkedServer> locks;
4342

4443
public static void main(String[] args)
4544
{
@@ -66,14 +65,15 @@ public ReactClient()
6665
}
6766
}
6867

69-
this.network = new Network();
68+
network = new Network();
7069
initialize();
7170
ns = new NetworkScheduler(network.getServers(), 50);
7271
ns.start();
7372
}
7473

7574
private void initialize()
7675
{
76+
locks = new GList<NetworkedServer>();
7777
JMenuBar menuBar = new JMenuBar();
7878
JMenu mnReact = new JMenu("React");
7979
JMenuItem mntmAbout = new JMenuItem("About");
@@ -235,6 +235,7 @@ public void validateConnectionAdd(String name, String address, int port, String
235235

236236
public void deleteConnection(NetworkedServer ns)
237237
{
238+
releaseConnection(ns);
238239
network.deleteServer(ns);
239240
try
240241
{
@@ -248,12 +249,12 @@ public void deleteConnection(NetworkedServer ns)
248249

249250
restart();
250251
}
251-
252+
252253
public void editConnection(NetworkedServer ns)
253254
{
254255
EditConnection.editConnection(ns);
255256
}
256-
257+
257258
public void validateConnectionEdit(String name, String address, int port, String username, String password, NetworkedServer ns)
258259
{
259260
network.rename(name, ns);
@@ -265,12 +266,31 @@ public void validateConnectionEdit(String name, String address, int port, String
265266
try
266267
{
267268
network.save();
268-
}
269+
}
269270

270271
catch(IOException e)
271272
{
272273
e.printStackTrace();
273274
}
274275
restart();
275276
}
277+
278+
public boolean isLocked(NetworkedServer ns)
279+
{
280+
return locks.contains(ns);
281+
}
282+
283+
public void lockConnection(NetworkedServer ns2)
284+
{
285+
if(!locks.contains(ns2))
286+
{
287+
locks.add(ns2);
288+
}
289+
}
290+
291+
public void releaseConnection(NetworkedServer ns2)
292+
{
293+
locks.remove(ns2);
294+
ns2.reset();
295+
}
276296
}

0 commit comments

Comments
 (0)