mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
async connect button
This commit is contained in:
parent
c522db40da
commit
0ca71ad174
@ -23,8 +23,6 @@ public class Connection extends SubForm {
|
|||||||
public CheckBox cbx_autodetect;
|
public CheckBox cbx_autodetect;
|
||||||
public TextField txtfield_hotelversion;
|
public TextField txtfield_hotelversion;
|
||||||
|
|
||||||
private boolean isBusy = false;
|
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
inpPort.getEditor().textProperty().addListener(observable -> {
|
inpPort.getEditor().textProperty().addListener(observable -> {
|
||||||
updateInputUI();
|
updateInputUI();
|
||||||
@ -77,6 +75,7 @@ public class Connection extends SubForm {
|
|||||||
public void onParentSet(){
|
public void onParentSet(){
|
||||||
getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(() -> {
|
getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(() -> {
|
||||||
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
|
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
|
||||||
|
Platform.runLater(() -> {
|
||||||
if (newState == HConnection.State.NOT_CONNECTED) {
|
if (newState == HConnection.State.NOT_CONNECTED) {
|
||||||
updateInputUI();
|
updateInputUI();
|
||||||
lblState.setText("Not connected");
|
lblState.setText("Not connected");
|
||||||
@ -97,19 +96,24 @@ public class Connection extends SubForm {
|
|||||||
if (newState == HConnection.State.WAITING_FOR_CLIENT) {
|
if (newState == HConnection.State.WAITING_FOR_CLIENT) {
|
||||||
lblState.setText("Waiting for connection");
|
lblState.setText("Waiting for connection");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void btnConnect_clicked(ActionEvent actionEvent) {
|
public void btnConnect_clicked(ActionEvent actionEvent) {
|
||||||
if (!isBusy) {
|
if (getHConnection().getState() == HConnection.State.NOT_CONNECTED) {
|
||||||
isBusy = true;
|
|
||||||
|
btnConnect.setDisable(true);
|
||||||
|
new Thread(() -> {
|
||||||
if (cbx_autodetect.isSelected()) {
|
if (cbx_autodetect.isSelected()) {
|
||||||
getHConnection().prepare();
|
getHConnection().prepare();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getHConnection().prepare(inpHost.getEditor().getText(), Integer.parseInt(inpPort.getEditor().getText()));
|
getHConnection().prepare(inpHost.getEditor().getText(), Integer.parseInt(inpPort.getEditor().getText()));
|
||||||
}
|
}
|
||||||
|
Platform.runLater(() -> btnConnect.setDisable(false));
|
||||||
|
|
||||||
if (HConnection.DEBUG) System.out.println("connecting");
|
if (HConnection.DEBUG) System.out.println("connecting");
|
||||||
|
|
||||||
@ -120,10 +124,11 @@ public class Connection extends SubForm {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
}).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getHConnection().abort();
|
getHConnection().abort();
|
||||||
isBusy = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user