82 lines
2.4 KiB
Java
82 lines
2.4 KiB
Java
package envoy.client.ui;
|
|
|
|
import java.awt.EventQueue;
|
|
import java.io.IOException;
|
|
import java.util.Properties;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
import envoy.client.Client;
|
|
import envoy.client.Config;
|
|
import envoy.client.LocalDB;
|
|
import envoy.exception.EnvoyException;
|
|
|
|
/**
|
|
* Starts the Envoy client and prompts the user to enter their name.
|
|
*
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>Startup.java</strong><br>
|
|
* Created: <strong>12 Oct 2019</strong><br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @author Maximilian Käfer
|
|
* @since Envoy v0.1-alpha
|
|
*/
|
|
public class Startup {
|
|
|
|
private static final Logger logger = Logger.getLogger(Startup.class.getSimpleName());
|
|
|
|
public static void main(String[] args) {
|
|
logger.setLevel(Level.ALL);
|
|
|
|
Config config = Config.getInstance();
|
|
|
|
// Load the configuration from client.properties first
|
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
try {
|
|
Properties configProperties = new Properties();
|
|
configProperties.load(loader.getResourceAsStream("client.properties"));
|
|
config.load(configProperties);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// Override configuration values with command line arguments
|
|
if (args.length > 0) config.load(args);
|
|
|
|
if (!config.isInitialized()) {
|
|
logger.severe("Server or port are not defined. Exiting...");
|
|
JOptionPane.showMessageDialog(null, "Error loading configuration values.", "Configuration error", JOptionPane.ERROR_MESSAGE);
|
|
System.exit(1);
|
|
}
|
|
|
|
String userName = JOptionPane.showInputDialog("Please enter your username");
|
|
if (userName == null || userName.isEmpty()) {
|
|
logger.severe("User name is not set or empty. Exiting...");
|
|
System.exit(1);
|
|
}
|
|
Client client = new Client(config, userName);
|
|
LocalDB localDB = new LocalDB(client.getSender());
|
|
try {
|
|
localDB.initializeDBFile(config.getLocalDB());
|
|
} catch (EnvoyException e) {
|
|
e.printStackTrace();
|
|
JOptionPane.showMessageDialog(null,
|
|
"Error while loading local database: " + e.toString() + "\nChats will not be stored locally.",
|
|
"Local DB error",
|
|
JOptionPane.WARNING_MESSAGE);
|
|
}
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
try {
|
|
ChatWindow chatWindow = new ChatWindow(client, localDB);
|
|
new StatusTrayIcon(chatWindow).show();
|
|
chatWindow.setVisible(true);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
});
|
|
}
|
|
} |