From e1ef85d70258333d6bc006d0bb0664032a50d850 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:23:26 +0100 Subject: [PATCH] Edit syncTimeout property, made Config a singleton --- src/main/java/envoy/client/Config.java | 22 +++++++++++++++++-- src/main/java/envoy/client/ui/ChatWindow.java | 5 +++-- .../envoy/client/ui/MessageListRenderer.java | 2 +- src/main/java/envoy/client/ui/Startup.java | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/envoy/client/Config.java b/src/main/java/envoy/client/Config.java index 0da3cf1..c31c972 100644 --- a/src/main/java/envoy/client/Config.java +++ b/src/main/java/envoy/client/Config.java @@ -16,6 +16,16 @@ public class Config { private String server; private int port; private File localDB; + private int syncTimeout; + + private static Config config; + + private Config() {} + + public static Config getInstance() { + if (config == null) config = new Config(); + return config; + } /** * Defaults to the {@code client.properties} file for information. @@ -28,7 +38,8 @@ public class Config { public void load(Properties properties) { if (properties.containsKey("server")) server = properties.getProperty("server"); if (properties.containsKey("port")) port = Integer.parseInt(properties.getProperty("port")); - localDB = new File(properties.getProperty("localDB", ".\\localDB")); + localDB = new File(properties.getProperty("localDB", ".\\localDB")); + syncTimeout = Integer.parseInt(properties.getProperty("syncTimeout", "1000")); } /** @@ -54,13 +65,16 @@ public class Config { localDB = new File(args[++i]); } if (localDB == null) localDB = new File(".\\localDB"); + if (syncTimeout == 0) syncTimeout = 1000; } /** * @return {@code true} if server, port and localDB directory are known. * @since Envoy v0.1-alpha */ - public boolean isInitialized() { return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; } + public boolean isInitialized() { + return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; + } /** * @return the host name of the Envoy server @@ -106,4 +120,8 @@ public class Config { * @since Envoy v0.1-alpha **/ public void setLocalDB(File localDB) { this.localDB = localDB; } + + public int getSyncTimeout() { return syncTimeout; } + + public void setSyncTimeout(int syncTimeout) { this.syncTimeout = syncTimeout; } } diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index c6e8c37..4a36c57 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -25,6 +25,7 @@ import javax.swing.border.EmptyBorder; import envoy.client.Chat; import envoy.client.Client; +import envoy.client.Config; import envoy.client.LocalDB; import envoy.schema.Message; import envoy.schema.Sync; @@ -235,7 +236,7 @@ public class ChatWindow extends JFrame { contentPane.revalidate(); loadUsersAndChats(); - startSyncThread(5000); + startSyncThread(Config.getInstance().getSyncTimeout()); contentPane.revalidate(); } @@ -260,7 +261,7 @@ public class ChatWindow extends JFrame { } /** - * For detailed information see Javadoc of corresponding methods. + * Updates the data model and the ui every x seconds. * * @param timeout the amount of time that passes between two requests sent to * the server diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/MessageListRenderer.java index 7afdec3..9053c6c 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/MessageListRenderer.java @@ -41,7 +41,7 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer 0) { config.load(args); } else {