8
8
import java .awt .*;
9
9
import java .awt .event .MouseAdapter ;
10
10
import java .awt .event .MouseEvent ;
11
+ import java .util .ArrayList ;
11
12
12
13
public class AddConnection extends JDialog {
13
14
private static final long serialVersionUID = 801014377635942783L ;
14
- private final JPanel contentPanel = new JPanel () ;
15
+ private final JLabel lblExists ;
15
16
private final JTextField txtLocalhost ;
16
17
private final JTextField textField_1 ;
17
18
private final JTextField txtCyberpwn ;
@@ -23,6 +24,7 @@ public AddConnection() {
23
24
setTitle ("Add a Connection" );
24
25
setBounds (100 , 100 , 450 , 397 );
25
26
getContentPane ().setLayout (new BorderLayout ());
27
+ JPanel contentPanel = new JPanel ();
26
28
contentPanel .setBorder (new EmptyBorder (5 , 5 , 5 , 5 ));
27
29
28
30
getContentPane ().add (contentPanel , BorderLayout .CENTER );
@@ -88,6 +90,13 @@ public AddConnection() {
88
90
89
91
contentPanel .add (txtReactisawesome , "cell 0 7,growx" );
90
92
}
93
+ {
94
+ lblExists = new JLabel ("Server name already exists" );
95
+ lblExists .setFont (new Font ("Segoe UI Light" , Font .PLAIN , 18 ));
96
+ lblExists .setForeground (Color .RED );
97
+ lblExists .setVisible (false );
98
+ contentPanel .add (lblExists , "cell 0 8" );
99
+ }
91
100
{
92
101
JPanel buttonPane = new JPanel ();
93
102
buttonPane .setLayout (new FlowLayout (FlowLayout .RIGHT ));
@@ -98,10 +107,8 @@ public AddConnection() {
98
107
okButton .addMouseListener (new MouseAdapter () {
99
108
@ Override
100
109
public void mouseReleased (MouseEvent e ) {
101
- if (SwingUtilities .isLeftMouseButton (e )) {
110
+ if (SwingUtilities .isLeftMouseButton (e )) {
102
111
addServer (txtFancyServer .getText (), txtLocalhost .getText (), Integer .parseInt (textField_1 .getText ()), txtCyberpwn .getText (), txtReactisawesome .getText ());
103
- setVisible (false );
104
- dispose ();
105
112
}
106
113
}
107
114
});
@@ -115,7 +122,7 @@ public void mouseReleased(MouseEvent e) {
115
122
cancelButton .addMouseListener (new MouseAdapter () {
116
123
@ Override
117
124
public void mouseReleased (MouseEvent e ) {
118
- if (SwingUtilities .isLeftMouseButton (e )) {
125
+ if (SwingUtilities .isLeftMouseButton (e )) {
119
126
setVisible (false );
120
127
dispose ();
121
128
}
@@ -138,6 +145,14 @@ public static void addConnection() {
138
145
}
139
146
140
147
public void addServer (String name , String address , int port , String username , String password ) {
141
- ReactClient .getInstance ().validateConnectionAdd (name , address , port , username , password );
148
+ ArrayList <String > networkedServerNames = new ArrayList <>();
149
+ ReactClient .getInstance ().getNetwork ().getServers ().forEach ((networkedServer -> networkedServerNames .add (networkedServer .getName ())));
150
+ if (networkedServerNames .contains (name )) {
151
+ lblExists .setVisible (true );
152
+ } else {
153
+ ReactClient .getInstance ().validateConnectionAdd (name , address , port , username , password );
154
+ setVisible (false );
155
+ dispose ();
156
+ }
142
157
}
143
158
}
0 commit comments