mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
remember last connection
This commit is contained in:
parent
44e343499c
commit
1066f6f3d2
@ -117,7 +117,7 @@ public class HConnection {
|
|||||||
|
|
||||||
private static volatile ConnectionInfoOverrider connectionInfoOverrider;
|
private static volatile ConnectionInfoOverrider connectionInfoOverrider;
|
||||||
public static volatile boolean DECRYPTPACKETS = true;
|
public static volatile boolean DECRYPTPACKETS = true;
|
||||||
public static volatile boolean DEBUG = true;
|
public static volatile boolean DEBUG = false;
|
||||||
private static final HostReplacer hostsReplacer = HostReplacerFactory.get();
|
private static final HostReplacer hostsReplacer = HostReplacerFactory.get();
|
||||||
|
|
||||||
private volatile boolean hostRedirected = false;
|
private volatile boolean hostRedirected = false;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package gearth.ui.connection;
|
package gearth.ui.connection;
|
||||||
|
|
||||||
|
import gearth.misc.Cacher;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import gearth.protocol.HConnection;
|
import gearth.protocol.HConnection;
|
||||||
import gearth.ui.SubForm;
|
import gearth.ui.SubForm;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -14,6 +16,11 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class ConnectionController extends SubForm {
|
public class ConnectionController extends SubForm {
|
||||||
|
|
||||||
|
private final String CONNECTION_INFO_CACHE_KEY = "last_connection_settings";
|
||||||
|
private final String AUTODETECT_CACHE = "auto_detect";
|
||||||
|
private final String HOST_CACHE = "host";
|
||||||
|
private final String PORT_CACHE = "port";
|
||||||
|
|
||||||
public ComboBox<String> inpPort;
|
public ComboBox<String> inpPort;
|
||||||
public ComboBox<String> inpHost;
|
public ComboBox<String> inpHost;
|
||||||
public Button btnConnect;
|
public Button btnConnect;
|
||||||
@ -23,7 +30,21 @@ public class ConnectionController extends SubForm {
|
|||||||
public CheckBox cbx_autodetect;
|
public CheckBox cbx_autodetect;
|
||||||
public TextField txtfield_hotelversion;
|
public TextField txtfield_hotelversion;
|
||||||
|
|
||||||
|
private final Object lock = new Object();
|
||||||
|
private volatile int fullyInitialized = 0;
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
Object object;
|
||||||
|
String hostRemember = null;
|
||||||
|
String portRemember = null;
|
||||||
|
if ((object = Cacher.get(CONNECTION_INFO_CACHE_KEY)) != null) {
|
||||||
|
JSONObject connectionSettings = (JSONObject) object;
|
||||||
|
boolean autoDetect = connectionSettings.getBoolean(AUTODETECT_CACHE);
|
||||||
|
hostRemember = connectionSettings.getString(HOST_CACHE);
|
||||||
|
portRemember = connectionSettings.getInt(PORT_CACHE) + "";
|
||||||
|
cbx_autodetect.setSelected(autoDetect);
|
||||||
|
}
|
||||||
|
|
||||||
inpPort.getEditor().textProperty().addListener(observable -> {
|
inpPort.getEditor().textProperty().addListener(observable -> {
|
||||||
updateInputUI();
|
updateInputUI();
|
||||||
});
|
});
|
||||||
@ -47,17 +68,33 @@ public class ConnectionController extends SubForm {
|
|||||||
List<String> portsSorted = new ArrayList<>(ports);
|
List<String> portsSorted = new ArrayList<>(ports);
|
||||||
portsSorted.sort(String::compareTo);
|
portsSorted.sort(String::compareTo);
|
||||||
|
|
||||||
|
int hostSelectIndex = 0;
|
||||||
|
int portSelectIndex = 0;
|
||||||
|
if (hostRemember != null) {
|
||||||
|
hostSelectIndex = hostsSorted.indexOf(hostRemember);
|
||||||
|
portSelectIndex = portsSorted.indexOf(portRemember);
|
||||||
|
hostSelectIndex = Math.max(hostSelectIndex, 0);
|
||||||
|
portSelectIndex = Math.max(portSelectIndex, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inpPort.getItems().addAll(portsSorted);
|
inpPort.getItems().addAll(portsSorted);
|
||||||
inpHost.getItems().addAll(hostsSorted);
|
inpHost.getItems().addAll(hostsSorted);
|
||||||
|
|
||||||
inpPort.getSelectionModel().selectFirst();
|
inpPort.getSelectionModel().select(portSelectIndex);
|
||||||
inpHost.getSelectionModel().selectFirst();
|
inpHost.getSelectionModel().select(hostSelectIndex);
|
||||||
|
|
||||||
|
synchronized (lock) {
|
||||||
|
fullyInitialized++;
|
||||||
|
if (fullyInitialized == 2) {
|
||||||
|
Platform.runLater(this::updateInputUI);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateInputUI() {
|
private void updateInputUI() {
|
||||||
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
|
txtfield_hotelversion.setText(getHConnection().getHotelVersion());
|
||||||
|
|
||||||
System.out.println(getHConnection().getState());
|
|
||||||
btnConnect.setDisable(getHConnection().getState() == HConnection.State.PREPARING || getHConnection().getState() == HConnection.State.ABORTING);
|
btnConnect.setDisable(getHConnection().getState() == HConnection.State.PREPARING || getHConnection().getState() == HConnection.State.ABORTING);
|
||||||
if (!cbx_autodetect.isSelected() && !btnConnect.isDisable()) {
|
if (!cbx_autodetect.isSelected() && !btnConnect.isDisable()) {
|
||||||
try {
|
try {
|
||||||
@ -74,6 +111,13 @@ public class ConnectionController extends SubForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onParentSet(){
|
public void onParentSet(){
|
||||||
|
synchronized (lock) {
|
||||||
|
fullyInitialized++;
|
||||||
|
if (fullyInitialized == 2) {
|
||||||
|
Platform.runLater(this::updateInputUI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(() -> {
|
getHConnection().getStateObservable().addListener((oldState, newState) -> Platform.runLater(() -> {
|
||||||
updateInputUI();
|
updateInputUI();
|
||||||
if (newState == HConnection.State.NOT_CONNECTED) {
|
if (newState == HConnection.State.NOT_CONNECTED) {
|
||||||
@ -95,6 +139,14 @@ public class ConnectionController extends SubForm {
|
|||||||
lblState.setText("Waiting for connection");
|
lblState.setText("Waiting for connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newState == HConnection.State.CONNECTED) {
|
||||||
|
JSONObject connectionSettings = new JSONObject();
|
||||||
|
connectionSettings.put(AUTODETECT_CACHE, cbx_autodetect.isSelected());
|
||||||
|
connectionSettings.put(HOST_CACHE, inpHost.getEditor().getText());
|
||||||
|
connectionSettings.put(PORT_CACHE, Integer.parseInt(inpPort.getEditor().getText()));
|
||||||
|
|
||||||
|
Cacher.put(CONNECTION_INFO_CACHE_KEY, connectionSettings);
|
||||||
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -118,6 +170,7 @@ public class ConnectionController extends SubForm {
|
|||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getHConnection().abort();
|
getHConnection().abort();
|
||||||
|
Loading…
Reference in New Issue
Block a user