diff --git a/settings/settings.json b/settings/settings.json new file mode 100644 index 0000000..70af1df --- /dev/null +++ b/settings/settings.json @@ -0,0 +1,4 @@ +{ + "responseAreaFont": "Liberation Mono", + "responseAreaFontSize": "18" +} \ No newline at end of file diff --git a/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java b/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java index c16a3b3..5c99774 100644 --- a/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java +++ b/src/main/java/com/rohitawate/restaurant/dashboard/DashboardController.java @@ -21,6 +21,7 @@ import com.rohitawate.restaurant.models.requests.GETRequest; import com.rohitawate.restaurant.models.responses.RestaurantResponse; import com.rohitawate.restaurant.requestsmanager.GETRequestManager; import com.rohitawate.restaurant.requestsmanager.RequestManager; +import com.rohitawate.restaurant.settings.Settings; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.ComboBox; @@ -60,6 +61,7 @@ public class DashboardController implements Initializable { @Override public void initialize(URL url, ResourceBundle rb) { + applySettings(); responseBox.getChildren().remove(0); httpMethodBox.getItems().addAll(httpMethods); httpMethodBox.setValue("GET"); @@ -114,4 +116,10 @@ public class DashboardController implements Initializable { responseTime.setText(Long.toString(response.getTime()) + " ms"); responseSize.setText(Integer.toString(response.getSize()) + " B"); } + + private void applySettings() { + String responseAreaCSS = "-fx-font-family: " + Settings.responseAreaFont + ";" + + "-fx-font-size: " + Settings.responseAreaFontSize; + responseArea.setStyle(responseAreaCSS); + } } diff --git a/src/main/java/com/rohitawate/restaurant/main/Main.java b/src/main/java/com/rohitawate/restaurant/main/Main.java index 401dbf6..4b8d3f1 100644 --- a/src/main/java/com/rohitawate/restaurant/main/Main.java +++ b/src/main/java/com/rohitawate/restaurant/main/Main.java @@ -15,6 +15,7 @@ */ package com.rohitawate.restaurant.main; +import com.rohitawate.restaurant.settings.SettingsLoader; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -24,6 +25,8 @@ import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception { + SettingsLoader settingsLoader = new SettingsLoader(); + settingsLoader.SettingsLoaderThread.join(); Parent dashboard = FXMLLoader.load(getClass().getResource("/fxml/Dashboard.fxml")); Stage dashboardStage = new Stage(); dashboardStage.setScene(new Scene(dashboard)); diff --git a/src/main/java/com/rohitawate/restaurant/settings/Settings.java b/src/main/java/com/rohitawate/restaurant/settings/Settings.java new file mode 100644 index 0000000..df2e304 --- /dev/null +++ b/src/main/java/com/rohitawate/restaurant/settings/Settings.java @@ -0,0 +1,26 @@ +/* + * Copyright 2018 Rohit Awate. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.rohitawate.restaurant.settings; + +/* + Holds settings from settings.json which are + loaded by SettingsLoader at startup. + */ +public class Settings { + public static String responseAreaFont; + public static int responseAreaFontSize; +} diff --git a/src/main/java/com/rohitawate/restaurant/settings/SettingsLoader.java b/src/main/java/com/rohitawate/restaurant/settings/SettingsLoader.java new file mode 100644 index 0000000..51e163e --- /dev/null +++ b/src/main/java/com/rohitawate/restaurant/settings/SettingsLoader.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 Rohit Awate. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.rohitawate.restaurant.settings; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class SettingsLoader implements Runnable { + public Thread SettingsLoaderThread; + + public SettingsLoader() { + SettingsLoaderThread = new Thread(this, "Settings loader thread"); + SettingsLoaderThread.start(); + } + + @Override + public void run() { + try { + StringBuilder settingsJSON = new StringBuilder(); + File settingsFile = new File("settings/settings.json"); + BufferedReader reader = new BufferedReader(new FileReader(settingsFile)); + + String line; + while ((line = reader.readLine()) != null) { + settingsJSON.append(line).append('\n'); + } + + reader.close(); + + ObjectMapper mapper = new ObjectMapper(); + JsonNode nodes = mapper.readTree(settingsJSON.toString()); + Settings.responseAreaFont = nodes.get("responseAreaFont").toString(); + Settings.responseAreaFontSize = nodes.get("responseAreaFontSize").asInt(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/css/Default.css b/src/main/resources/css/Default.css index 8279e79..cee124e 100644 --- a/src/main/resources/css/Default.css +++ b/src/main/resources/css/Default.css @@ -36,7 +36,7 @@ } #responseArea { - -fx-font-family: 'Liberation Mono'; + -fx-font-family: "Liberation Mono"; -fx-text-fill: #a1a1a1; -fx-background-radius: 0; -fx-background-insets: 0;