setting look and feel automatically

This commit is contained in:
Sven Vogel 2023-07-17 18:22:24 +02:00
parent d8bdad548d
commit 64f0b7d0c8
3 changed files with 35 additions and 2 deletions

View File

@ -40,11 +40,42 @@ public final class Main {
Locales.autodetectDefaultLocale(); Locales.autodetectDefaultLocale();
setPlatformDependingTheme();
// create main instance and show the login screen // create main instance and show the login screen
instance(); instance();
getInstance().showLoginScreen(); getInstance().showLoginScreen();
} }
private static void setPlatformDependingTheme() {
// default look and feel
var laf = UIManager.getCrossPlatformLookAndFeelClassName();
// runtime os
String os = System.getProperty("os.name").toLowerCase();
LOGGER.fine("Detected operating system: " + os);
// set look and feel class name depending on the platform we run on
if (os.contains("win") || os.contains("mac")) {
LOGGER.info("Detected Windows or MacOS based operating system, using system look and feel");
laf = UIManager.getSystemLookAndFeelClassName();
} else if (os.contains("nix") || os.contains("nux") || os.contains("aix") || os.contains("sunos")) {
LOGGER.info("Detected Unix/Linux based operating system, using GTK look and feel");
laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
} else {
LOGGER.warning("Unable to detect operating system: " + os);
}
try {
LOGGER.info("Setting look and feel to class: " + laf);
UIManager.setLookAndFeel(laf);
} catch (ClassNotFoundException | UnsupportedLookAndFeelException e) {
LOGGER.severe("Look and feel class not found: " + e.getMessage());
} catch (InstantiationException | IllegalAccessException e) {
LOGGER.warning("Could not set look and feel: " + e.getMessage());
}
}
/** /**
* Get the main singleton instance of this program * Get the main singleton instance of this program
* @return the singleton instance of this class * @return the singleton instance of this class

View File

@ -8,6 +8,7 @@ import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import static javax.swing.JFileChooser.APPROVE_OPTION; import static javax.swing.JFileChooser.APPROVE_OPTION;
import static me.teridax.jcash.lang.Translator.translate;
/** /**
* Utility class for loading a BMS configuration from a csv file. * Utility class for loading a BMS configuration from a csv file.
@ -17,7 +18,7 @@ public class Loader {
/** /**
* Filter that only allows for files with *.csv extension * Filter that only allows for files with *.csv extension
*/ */
private static final FileNameExtensionFilter FILE_FILTER = new FileNameExtensionFilter("Comma separated value spreadsheet", "csv", "CSV"); private static final FileNameExtensionFilter FILE_FILTER = new FileNameExtensionFilter(translate("Comma separated value spreadsheet"), "csv", "CSV");
private Loader() {} private Loader() {}
@ -35,7 +36,7 @@ public class Loader {
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setAcceptAllFileFilterUsed(false);
if (fileChooser.showDialog(null, Translator.translate("Load database")) == APPROVE_OPTION) { if (fileChooser.showDialog(null, translate("Load database")) == APPROVE_OPTION) {
// parse file content // parse file content
try { try {
return BankingManagementSystem.loadFromCsv(fileChooser.getSelectedFile().toPath()); return BankingManagementSystem.loadFromCsv(fileChooser.getSelectedFile().toPath());

View File

@ -46,3 +46,4 @@ Address,Adresse,Dirección,Adresse,地址
Account,Konto,Cuenta,Compte,账户 Account,Konto,Cuenta,Compte,账户
Closing JCash,JCash wird geschlossen,JCash está cerrado,JCash est fermé,JCash 已关闭 Closing JCash,JCash wird geschlossen,JCash está cerrado,JCash est fermé,JCash 已关闭
you're logged out,Du bist abgemeldet,Ha cerrado la sesión,Tu es déconnecté,您已注销 you're logged out,Du bist abgemeldet,Ha cerrado la sesión,Tu es déconnecté,您已注销
Comma separated value spreadsheet,Tabelle mit kommagetrennten Werten,Planilla de valores separados por comas,Feuille de calcul à valeurs séparées par des virgules,逗号分隔值电子表格
1 en_EN de_DE es_ES fr_FR zh_Hans
46 Account Konto Cuenta Compte 账户
47 Closing JCash JCash wird geschlossen JCash está cerrado JCash est fermé JCash 已关闭
48 you're logged out Du bist abgemeldet Ha cerrado la sesión Tu es déconnecté 您已注销
49 Comma separated value spreadsheet Tabelle mit kommagetrennten Werten Planilla de valores separados por comas Feuille de calcul à valeurs séparées par des virgules 逗号分隔值电子表格