added fundamental css files, theoretically added css support

This commit is contained in:
delvh 2020-05-09 10:57:30 +02:00
parent d8e006f051
commit 067cbbdcf8
6 changed files with 114 additions and 36 deletions

View File

@ -27,8 +27,8 @@ import envoy.util.SerializationUtils;
public class Settings {
// Actual settings accessible by the rest of the application
private Map<String, SettingsItem<?>> items;
private Map<String, Theme> themes;
private Map<String, SettingsItem<?>> items;
private Map<String, Theme> themes;
/**
* Settings are stored in this file.
@ -46,8 +46,8 @@ public class Settings {
private static Settings settings = new Settings();
/**
* The way to instantiate the settings.
* Is set to private to deny other instances of that object.
* The way to instantiate the settings. Is set to private to deny other
* instances of that object.
*
* @since Envoy Client v0.2-alpha
*/
@ -69,12 +69,10 @@ public class Settings {
}
// Load standard themes not defined in the themes file
themes.put("dark",
new Theme("dark", Color.black, Color.darkGray, Color.white, new Color(165, 60, 232), Color.white, Color.orange, Color.blue,
Color.white, Color.white));
themes.put("light",
new Theme("light", new Color(235, 235, 235), Color.white, Color.white, Color.darkGray, Color.black, Color.orange, Color.darkGray,
Color.black, Color.black));
themes.put("dark", new Theme("dark", Color.black, Color.darkGray, Color.white, new Color(165, 60, 232),
Color.white, Color.orange, Color.blue, Color.white, Color.white));
themes.put("light", new Theme("light", new Color(235, 235, 235), Color.white, Color.white, Color.darkGray,
Color.black, Color.orange, Color.darkGray, Color.black, Color.black));
}
/**
@ -83,7 +81,9 @@ public class Settings {
* @return the instance of Settings
* @since Envoy Client v0.2-alpha
*/
public static Settings getInstance() { return settings; }
public static Settings getInstance() {
return settings;
}
/**
* Updates the preferences when the save button is clicked.
@ -101,9 +101,12 @@ public class Settings {
}
private void supplementDefaults() {
items.putIfAbsent("enterToSend", new SettingsItem<>(true, "Enter to send", "Sends a message by pressing the enter key."));
items.putIfAbsent("onCloseMode", new SettingsItem<>(true, "Hide on close", "Hides the chat window when it is closed."));
items.putIfAbsent("currentTheme", new SettingsItem<>("dark", "Current Theme Name", "The name of the currently selected theme."));
items.putIfAbsent("enterToSend",
new SettingsItem<>(true, "Enter to send", "Sends a message by pressing the enter key."));
items.putIfAbsent("onCloseMode",
new SettingsItem<>(true, "Hide on close", "Hides the chat window when it is closed."));
items.putIfAbsent("currentTheme",
new SettingsItem<>("dark", "Current Theme Name", "The name of the currently selected theme."));
}
/**
@ -112,19 +115,25 @@ public class Settings {
* @param theme the {@link Theme} to add
* @since Envoy Client v0.2-alpha
*/
public void addNewThemeToMap(Theme theme) { getThemes().put(theme.getThemeName(), theme); }
public void addNewThemeToMap(Theme theme) {
getThemes().put(theme.getThemeName(), theme);
}
/**
* @return the name of the currently active {@link Theme}
* @since Envoy Client v0.2-alpha
*/
public String getCurrentThemeName() { return (String) items.get("currentTheme").get(); }
public String getCurrentThemeName() {
return (String) items.get("currentTheme").get();
}
/**
* @return the currently active {@link Theme}
* @since Envoy Client v0.1-beta
*/
public Theme getCurrentTheme() { return getTheme(getCurrentThemeName()); }
public Theme getCurrentTheme() {
return getTheme(getCurrentThemeName());
}
/**
* Sets the name of the current {@link Theme}.
@ -132,7 +141,18 @@ public class Settings {
* @param themeName the name to set
* @since Envoy Client v0.2-alpha
*/
public void setCurrentTheme(String themeName) { ((SettingsItem<String>) items.get("currentTheme")).set(themeName); }
public void setCurrentTheme(String themeName) {
((SettingsItem<String>) items.get("currentTheme")).set(themeName);
}
/**
* @return whether the current {@link Theme} is one of the default themes.
* Currently checks for dark and light theme.
* @since Envoy Client v0.1-beta
*/
public boolean isUsingDefaultTheme() {
return getCurrentThemeName().equals("dark") || getCurrentThemeName().equals("light");
}
/**
* @return {@code true}, if pressing the {@code Enter} key suffices to send a
@ -140,7 +160,9 @@ public class Settings {
* {@code Control} key.
* @since Envoy Client v0.2-alpha
*/
public Boolean isEnterToSend() { return (Boolean) items.get("enterToSend").get(); }
public Boolean isEnterToSend() {
return (Boolean) items.get("enterToSend").get();
}
/**
* Changes the keystrokes performed by the user to send a message.
@ -150,13 +172,17 @@ public class Settings {
* conjunction with the {@code Control} key.
* @since Envoy Client v0.2-alpha
*/
public void setEnterToSend(boolean enterToSend) { ((SettingsItem<Boolean>) items.get("enterToSend")).set(enterToSend); }
public void setEnterToSend(boolean enterToSend) {
((SettingsItem<Boolean>) items.get("enterToSend")).set(enterToSend);
}
/**
* @return the current on close mode.
* @since Envoy Client v0.3-alpha
*/
public Boolean getCurrentOnCloseMode() { return (Boolean) items.get("onCloseMode").get(); }
public Boolean getCurrentOnCloseMode() {
return (Boolean) items.get("onCloseMode").get();
}
/**
* Sets the current on close mode.
@ -164,23 +190,31 @@ public class Settings {
* @param currentOnCloseMode the on close mode that should be set.
* @since Envoy Client v0.3-alpha
*/
public void setCurrentOnCloseMode(boolean currentOnCloseMode) { ((SettingsItem<Boolean>) items.get("onCloseMode")).set(currentOnCloseMode); }
public void setCurrentOnCloseMode(boolean currentOnCloseMode) {
((SettingsItem<Boolean>) items.get("onCloseMode")).set(currentOnCloseMode);
}
/**
* @return the items
*/
public Map<String, SettingsItem<?>> getItems() { return items; }
public Map<String, SettingsItem<?>> getItems() {
return items;
}
/**
* @param items the items to set
*/
public void setItems(Map<String, SettingsItem<?>> items) { this.items = items; }
public void setItems(Map<String, SettingsItem<?>> items) {
this.items = items;
}
/**
* @return a {@code Map<String, Theme>} of all themes with their names as keys
* @since Envoy Client v0.2-alpha
*/
public Map<String, Theme> getThemes() { return themes; }
public Map<String, Theme> getThemes() {
return themes;
}
/**
* Sets the {@code Map<String, Theme>} of all themes with their names as keys
@ -188,12 +222,16 @@ public class Settings {
* @param themes the theme map to set
* @since Envoy Client v0.2-alpha
*/
public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
public void setThemes(Map<String, Theme> themes) {
this.themes = themes;
}
/**
* @param themeName the name of the {@link Theme} to get
* @return the {@link Theme} with the specified name
* @since Envoy Client v0.3-alpha
*/
public Theme getTheme(String themeName) { return themes.get(themeName); }
public Theme getTheme(String themeName) {
return themes.get(themeName);
}
}

View File

@ -3,6 +3,7 @@ package envoy.client.ui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -44,11 +45,14 @@ public final class Startup extends Application {
private FXMLLoader loader = new FXMLLoader();
private Stage stage;
private Scene previousScene;
private Scene previousScene;
private final String[] CSSPaths = { "file://./src/main/resources/fxml/themes/base.css",
"file://./src/main/resources/fxml/themes/" + (settings.isUsingDefaultTheme() ? settings.getCurrentThemeName() : "custom") + ".css" };
private static final ClientConfig config = ClientConfig.getInstance();
private static final Logger logger = EnvoyLog.getLogger(Startup.class);
private static final Settings settings = Settings.getInstance();
private static final ClientConfig config = ClientConfig.getInstance();
private static final Logger logger = EnvoyLog.getLogger(Startup.class);
/**
* {@inheritDoc}
@ -150,7 +154,8 @@ public final class Startup extends Application {
* @param fxmlLocation the location of the fxml file
* @param layout the layout to use
* @param savePrevious if true, the previous stage will be stored in this
* instance of Startup, else the variable storing it will be
* instance of Startup, else the variable storing it will
* be
* set to null
* @since Envoy Client v0.1-beta
*/
@ -160,13 +165,17 @@ public final class Startup extends Application {
// Clearing the loader so that a new Scene can be initialised
loader = new FXMLLoader();
var rootNode = loader.<T>load(getClass().getResourceAsStream(fxmlLocation));
var chatScene = new Scene(rootNode);
previousScene = (savePrevious) ? stage.getScene() : null;
stage.setScene(chatScene);
var scene = new Scene(rootNode);
previousScene = savePrevious ? stage.getScene() : null;
// Setting the visual appearance
scene.getStylesheets().addAll(CSSPaths);
System.out.println(Paths.get(".").toAbsolutePath().normalize().toString());
stage.setScene(scene);
stage.show();
// return loader.getController();
} catch (IOException e) {
new Alert(AlertType.ERROR, "The screen could not be updated due to reasons. (...bad programming...)");
System.err.println("input: FXMLLocation: " + fxmlLocation + ", CSS paths: " + CSSPaths);
e.printStackTrace();
logger.severe("Something happened (while loading the new scene from " + fxmlLocation + ")");
}
@ -175,7 +184,7 @@ public final class Startup extends Application {
/**
* Changes the visual scene back to the saved value. The currently active scene
* can be saved.
* can be saved, but must not be.
*
* @param storeCurrent the old scene to store, if wanted. Can be null
* @since Envoy Client v0.1-beta
@ -185,7 +194,7 @@ public final class Startup extends Application {
if (previousScene == null) throw new IllegalStateException("Someone tried restoring a null scene. (Something happened)");
else {
// switching previous and current
var temp = (storeCurrent) ? stage.getScene() : null;
var temp = storeCurrent ? stage.getScene() : null;
stage.setScene(previousScene);
previousScene = temp;
stage.show();
@ -224,4 +233,23 @@ public final class Startup extends Application {
if (loader.getController() == null) throw new NullPointerException("Cannot deliver current controller as its undefined (duh!)");
else return loader.getController();
}
/**
* @return the CSSPaths
* @since Envoy Client v0.1-beta
*/
public String[] getCSSPaths() { return CSSPaths; }
/**
* Changes the currently displayed theme
*
* @since Envoy Client v0.1-beta
*/
public void changeTheme() {
// the base.css file should never be changed during runtime
CSSPaths[1] = "file://.fxml/themes/" + (settings.isUsingDefaultTheme() ? settings.getCurrentThemeName() : "custom") + ".css";
var styleSheets = stage.getScene().getStylesheets();
styleSheets.remove(styleSheets.size() - 1);
styleSheets.add(CSSPaths[1]);
}
}

View File

@ -0,0 +1,5 @@
.root{
-fx-font: 200pt "Serif";
--background=#00FF00;
background: var(--background);
}

View File

@ -0,0 +1,7 @@
.root{
--background=#000000;
background: var(--background);
}
.button{
color: rgb(105,0,153);
}

View File