From ab6cdcbf8e69f101a2214405daf3918ee317027d Mon Sep 17 00:00:00 2001 From: Carl Dea Date: Tue, 23 Mar 2021 20:46:05 -0400 Subject: [PATCH] Replaced a non-modular json library library with a modular one. Bach is able to build application a custom image and worldclock executable. --- .bach/bach.info/module-info.java | 6 + pom.xml | 22 +- src/main/java/com/carlfx/worldclock/App.java | 38 ++- .../worldclock/ConfigLocationsController.java | 10 +- .../java/com/carlfx/worldclock/Location.java | 22 +- .../com/carlfx/worldclock/USLocation.java | 5 +- .../worldclock/WorldClockController.java | 3 + src/main/java/module-info.java | 8 +- .../carlfx/worldclock/config-locations.css | 264 +++++++++--------- 9 files changed, 199 insertions(+), 179 deletions(-) diff --git a/.bach/bach.info/module-info.java b/.bach/bach.info/module-info.java index e9eae85..b6f7e33 100644 --- a/.bach/bach.info/module-info.java +++ b/.bach/bach.info/module-info.java @@ -1,5 +1,6 @@ import com.github.sormuras.bach.ProjectInfo; import com.github.sormuras.bach.ProjectInfo.Externals; +import com.github.sormuras.bach.ProjectInfo.External; import com.github.sormuras.bach.ProjectInfo.Externals.Name; import com.github.sormuras.bach.ProjectInfo.Tools; import com.github.sormuras.bach.ProjectInfo.Tweak; @@ -13,6 +14,11 @@ import com.github.sormuras.bach.ProjectInfo.Tweak; tool = "jlink", option = "--launcher", value = "worldclock=worldclock/com.carlfx.worldclock.Launcher") + }, + lookupExternal = { + @External(module = "com.fasterxml.jackson.core", via = "com.fasterxml.jackson.core:jackson-core:2.12.1"), + @External(module = "com.fasterxml.jackson.annotation", via = "com.fasterxml.jackson.core:jackson-annotations:2.12.1"), + @External(module = "com.fasterxml.jackson.databind", via = "com.fasterxml.jackson.core:jackson-databind:2.12.1") }) module bach.info { requires com.github.sormuras.bach; diff --git a/pom.xml b/pom.xml index fe47b18..ca336b2 100644 --- a/pom.xml +++ b/pom.xml @@ -15,16 +15,30 @@ javafx-controls ${javafx.version} + + org.openjfx + javafx-web + ${javafx.version} + org.openjfx javafx-fxml ${javafx.version} - com.jsoniter - jsoniter - 0.9.23 - compile + com.fasterxml.jackson.core + jackson-core + 2.12.1 + + + com.fasterxml.jackson.core + jackson-annotations + 2.12.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.12.1 diff --git a/src/main/java/com/carlfx/worldclock/App.java b/src/main/java/com/carlfx/worldclock/App.java index 2f350c0..4c985db 100644 --- a/src/main/java/com/carlfx/worldclock/App.java +++ b/src/main/java/com/carlfx/worldclock/App.java @@ -1,7 +1,6 @@ package com.carlfx.worldclock; -import com.jsoniter.JsonIterator; -import com.jsoniter.any.Any; +import com.fasterxml.jackson.databind.ObjectMapper; import javafx.animation.*; import javafx.application.Application; import javafx.application.Platform; @@ -107,28 +106,25 @@ public class App extends Application { "locations.json")); if (locationsJson.exists()) { try { - String actual = Files.readString(locationsJson.toPath()); if (!"".equals(actual)) { - List locationList = JsonIterator.deserialize(actual).asList(); - locationList.stream().map(any -> { - Location location = null; - String timezone = any.get("timezone").toString(); - String city = any.get("city").toString(); - String countryCode = any.get("countryCode").toString(); - String state = any.get("state") != null ? any.get("state").toString() : ""; - if ("US".equalsIgnoreCase(countryCode)) { - location = new USLocation(timezone, city, state); - } else { - location = new Location(timezone, city, countryCode); + ObjectMapper objectMapper = new ObjectMapper(); + List> locationArray = objectMapper.readValue(actual, List.class); + for (Map map:locationArray) { + try { + Location location = null; + + if (map.containsKey("state")) { + location = objectMapper.convertValue(map, USLocation.class); + } else { + location = objectMapper.convertValue(map, Location.class); + } + locations.add(location); + + } catch (Throwable th) { + th.printStackTrace(); } - String latitude = any.get("latitude") != null ? any.get("latitude").toString() : ""; - String longitude = any.get("latitude") != null ? any.get("longitude").toString() : ""; - if (!"".equals(latitude) && !"".equals(longitude)) { - location.setLatLong(latitude, longitude); - } - return location; - }).forEach(location -> locations.add(location)); + } } System.out.println("Successfully read from file."); diff --git a/src/main/java/com/carlfx/worldclock/ConfigLocationsController.java b/src/main/java/com/carlfx/worldclock/ConfigLocationsController.java index b2e583a..f972627 100644 --- a/src/main/java/com/carlfx/worldclock/ConfigLocationsController.java +++ b/src/main/java/com/carlfx/worldclock/ConfigLocationsController.java @@ -1,6 +1,6 @@ package com.carlfx.worldclock; -import com.jsoniter.output.JsonStream; +import com.fasterxml.jackson.databind.ObjectMapper; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; @@ -14,7 +14,6 @@ import java.io.FileWriter; import java.io.IOException; import java.util.Iterator; import java.util.List; -import java.util.stream.Collectors; public class ConfigLocationsController { @FXML @@ -146,10 +145,9 @@ public class ConfigLocationsController { File.separatorChar, "locations.json")); try (FileWriter fileWriter = new FileWriter(locationsJson)){ - List locationList = locationsListView.getItems().stream().collect(Collectors.toList()); - String arrayJson = JsonStream.serialize(locationList); - fileWriter.write(arrayJson); - + ObjectMapper objectMapper = new ObjectMapper(); + List locationList = locationsListView.getItems(); + objectMapper.writeValue(fileWriter, locationList); System.out.println("Successfully wrote to the file."); } catch (IOException e) { System.out.println("An error occurred."); diff --git a/src/main/java/com/carlfx/worldclock/Location.java b/src/main/java/com/carlfx/worldclock/Location.java index 5e21dec..0588fe7 100644 --- a/src/main/java/com/carlfx/worldclock/Location.java +++ b/src/main/java/com/carlfx/worldclock/Location.java @@ -1,9 +1,9 @@ package com.carlfx.worldclock; -import javafx.scene.image.Image; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.Arrays; - +@JsonIgnoreProperties(ignoreUnknown = true) public class Location { private String clockTime; private String timezone; @@ -11,7 +11,7 @@ public class Location { private String country; private String countryCode; private double[] latLong = null; - private Image weatherImage; + public String weatherImageUrl; private float temperature; private TEMP_STD tempType; /* @@ -50,7 +50,7 @@ public class Location { CELSIUS, FAHRENHEIT } - + public Location(){} public Location(String timezone, String city, String countryCode) { this.timezone = timezone; this.city = city; @@ -125,9 +125,7 @@ public class Location { } public void setLatLong(double[] latLong) { - if (latLong == null || latLong.length != 2) { - throw new IllegalArgumentException("Latitude and Longitude is a two element array of type double."); - } + this.latLong = latLong; } public void setLatLong(String lat, String lon) { @@ -151,12 +149,12 @@ public class Location { return this.latLong[1]; } - public Image getWeatherImage() { - return weatherImage; + public String getWeatherImageUrl() { + return weatherImageUrl; } - public void setWeatherImage(Image weatherImage) { - this.weatherImage = weatherImage; + public void setWeatherImageUrl(String weatherImageUrl) { + this.weatherImageUrl = weatherImageUrl; } public float getTemperature() { @@ -184,7 +182,7 @@ public class Location { ", country='" + country + '\'' + ", countryCode='" + countryCode + '\'' + ", latLong=" + Arrays.toString(latLong) + - ", weatherImage=" + weatherImage + + ", weatherImageUrl=" + weatherImageUrl + ", temperature=" + temperature + ", tempType=" + tempType + '}'; diff --git a/src/main/java/com/carlfx/worldclock/USLocation.java b/src/main/java/com/carlfx/worldclock/USLocation.java index 4939f9e..f5d34b9 100644 --- a/src/main/java/com/carlfx/worldclock/USLocation.java +++ b/src/main/java/com/carlfx/worldclock/USLocation.java @@ -1,9 +1,12 @@ package com.carlfx.worldclock; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) public class USLocation extends Location { private String state = ""; private String zip; - + public USLocation(){} public USLocation(String timezone, String city, String stateCode) { this(timezone, city, stateCode, 0, TEMP_STD.CELSIUS); } diff --git a/src/main/java/com/carlfx/worldclock/WorldClockController.java b/src/main/java/com/carlfx/worldclock/WorldClockController.java index 2188e72..9e4a542 100644 --- a/src/main/java/com/carlfx/worldclock/WorldClockController.java +++ b/src/main/java/com/carlfx/worldclock/WorldClockController.java @@ -102,6 +102,9 @@ public class WorldClockController { if (gmtOffset.indexOf("GMT") > -1) { gmtOffset = gmtOffset.substring(3); } + if ("".equals(gmtOffset.trim())) { + System.out.println("gmtOffset: " + gmtOffset); + } gmtOffset = "GMT%+d".formatted(Integer.parseInt(gmtOffset)); Calendar newCalendar = Calendar.getInstance(TimeZone.getTimeZone(gmtOffset)); diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index d541d3f..e6ff56e 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,8 +1,10 @@ module worldclock { requires javafx.controls; requires javafx.fxml; - requires jsoniter; - - opens com.carlfx.worldclock to jsoniter, javafx.fxml; + requires javafx.web; + requires com.fasterxml.jackson.core; + requires com.fasterxml.jackson.databind; + requires com.fasterxml.jackson.annotation; + opens com.carlfx.worldclock to com.fasterxml.jackson.core, com.fasterxml.jackson.databind, com.fasterxml.jackson.annotation, javafx.fxml; exports com.carlfx.worldclock; } \ No newline at end of file diff --git a/src/main/resources/com/carlfx/worldclock/config-locations.css b/src/main/resources/com/carlfx/worldclock/config-locations.css index bd3fb98..f56abd6 100644 --- a/src/main/resources/com/carlfx/worldclock/config-locations.css +++ b/src/main/resources/com/carlfx/worldclock/config-locations.css @@ -1,21 +1,21 @@ .label-text { - -fx-font-family: "Roboto Medium"; - -fx-font-weight: 100; - -fx-font-size: 12; - -fx-font-style: normal; - -fx-fill: "#2fdae0ce"; - -fx-stroke: "#2fdae0ce"; - -fx-stroke-width: 0; + -fx-font-family: "Roboto Medium"; + -fx-font-weight: 100; + -fx-font-size: 12; + -fx-font-style: normal; + -fx-fill: "#2fdae0ce"; + -fx-stroke: "#2fdae0ce"; + -fx-stroke-width: 0; } .header-label-text { - -fx-font-family: "Roboto Medium"; - -fx-font-weight: 100; - -fx-font-size: 14; - -fx-font-style: bold; - -fx-fill: "#ffffffee"; - -fx-stroke: "#2fdae0ce"; - -fx-stroke-width: 0; + -fx-font-family: "Roboto Medium"; + -fx-font-weight: 100; + -fx-font-size: 14; + -fx-font-style: normal; + -fx-fill: "#ffffffee"; + -fx-stroke: "#2fdae0ce"; + -fx-stroke-width: 0; } .error-overlay { @@ -43,19 +43,19 @@ -fx-text-fill: white; } -// Background color of List View -.list-view { - -fx-font-family: "Roboto Regular"; - -fx-background-color: "#40404050"; - -fx-font-size: 12; - -fx-text-fill: white; -} + /*Background color of List View*/ + .list-view { + -fx-font-family: "Roboto Regular"; + -fx-background-color: "#40404050"; + -fx-font-size: 12; + -fx-text-fill: white; + } -// Background of the text field item in display -.list-view .list-cell .cell.indexed-cell.list-cell { - -fx-background-color: "#40404050"; - -fx-text-fill: #2fdae0ce; -} + /*Background of the text field item in display*/ + .list-view .list-cell .cell.indexed-cell.list-cell { + -fx-background-color: "#40404050"; + -fx-text-fill: #2fdae0ce; + } /* .list-view .list-cell:filled:selected:focused, .list-cell:filled:selected { -fx-background-color: linear-gradient(#2fdae0ce 0%, #2fdae0dd 25%, #2fdae0ee 75%, #2fdae0ff 100%); @@ -72,135 +72,135 @@ -fx-text-fill: white; } -// Background color of combo box -.combo-box { - -fx-font-family: "Roboto Regular"; - -fx-background-color: "#40404050"; - -fx-font-size: 12; - -fx-text-fill: white; -} + /*Background color of combo box*/ + .combo-box { + -fx-font-family: "Roboto Regular"; + -fx-background-color: "#40404050"; + -fx-font-size: 12; + -fx-text-fill: white; + } -// Background of the text field item in display -.combo-box .list-cell, .combo-box .text-input { - -fx-text-fill: white; -} + /*Background of the text field item in display*/ + .combo-box .list-cell, .combo-box .text-input { + -fx-text-fill: white; + } -// background of the list view area of popup -.combo-box .combo-box-popup .list-view { - -fx-background-color: "#00000050"; - -fx-border-color: "#2fdae0ce"; - -fx-background-insets: 0 0 0 0; - -fx-border-style: solid; - -fx-border-width: 1; -} + /*background of the list view area of popup*/ + .combo-box .combo-box-popup .list-view { + -fx-background-color: "#00000050"; + -fx-border-color: "#2fdae0ce"; + -fx-background-insets: 0 0 0 0; + -fx-border-style: solid; + -fx-border-width: 1; + } -// normal list item -.combo-box .combo-box-popup .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell, -.list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell { - -fx-font-family: "Roboto Regular"; - -fx-background-color: "#101010ee"; - -fx-font-size: 12; - -fx-text-fill: white; -} + /*normal list item*/ + .combo-box .combo-box-popup .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell, + .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell { + -fx-font-family: "Roboto Regular"; + -fx-background-color: "#101010ee"; + -fx-font-size: 12; + -fx-text-fill: white; + } -// selected list item -.combo-box .combo-box-popup .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:selected, -.list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:selected { - -fx-background-color: "#2fdae0ce"; - -fx-text-fill: white; -} + /*selected list item*/ + .combo-box .combo-box-popup .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:selected, + .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:selected { + -fx-background-color: "#2fdae0ce"; + -fx-text-fill: white; + } -// hover over list item -.combo-box .combo-box-popup .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:hover, -.list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:hover { - /*-fx-background-color: "#2fdae0bb";*/ - -fx-text-fill: "#2fdae0ff"; + /*hover over list item*/ + .combo-box .combo-box-popup .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:hover, + .list-view .virtual-flow .clipped-container .sheet .cell.indexed-cell.list-cell:hover { + /*-fx-background-color: "#2fdae0bb";*/ + -fx-text-fill: "#2fdae0ff"; - -fx-background-color: "#00000050"; - -fx-border-color: "#2fdae0ff"; - -fx-background-insets: 0 0 0 0; - -fx-border-style: solid; - -fx-border-width: 1; -} + -fx-background-color: "#00000050"; + -fx-border-color: "#2fdae0ff"; + -fx-background-insets: 0 0 0 0; + -fx-border-style: solid; + -fx-border-width: 1; + } -// track display -.combo-box-popup .list-view .scroll-bar:vertical .track, -.list-view .scroll-bar:vertical .track { - -fx-max-width: 10px; - -fx-background-color: "#2fdae0ce", black; - -fx-background-insets: 0 0 0 0, 1 1 1 1; - -fx-color: "#2fdae0ce"; - -fx-border-color: transparent; - // -fx-border-width: 1px; -} + /*track display*/ + .combo-box-popup .list-view .scroll-bar:vertical .track, + .list-view .scroll-bar:vertical .track { + -fx-max-width: 10px; + -fx-background-color: "#2fdae0ce", black; + -fx-background-insets: 0 0 0 0, 1 1 1 1; + -fx-color: "#2fdae0ce"; + -fx-border-color: transparent; + /*-fx-border-width: 1px;*/ + } -// normal thumb display -.combo-box-popup .list-view .scroll-bar:vertical .thumb, -.list-view .scroll-bar:vertical .thumb { - -fx-max-width: 8px; - -fx-background-color: "#2fdae0ce"; - -fx-background-insets: 0 0 0 0; -} + /*normal thumb display*/ + .combo-box-popup .list-view .scroll-bar:vertical .thumb, + .list-view .scroll-bar:vertical .thumb { + -fx-max-width: 8px; + -fx-background-color: "#2fdae0ce"; + -fx-background-insets: 0 0 0 0; + } .combo-box-popup .list-view .scroll-bar:vertical .thumb:hover, .list-view .scroll-bar:vertical .thumb:hover { -fx-background-color: "#2fdae0"; } -// normal increment and decrement buttons -.combo-box-popup .list-view .scroll-bar:vertical .increment-button, -.list-view .scroll-bar:vertical .increment-button, -.combo-box-popup .list-view .scroll-bar:vertical .decrement-button, -.list-view .scroll-bar:vertical .decrement-button { - -fx-background-color: "#2fdae0ce", black; - -fx-color: "#2fdae0ce"; - -fx-background-insets: 0 0 0 0, 1 1 1 1; -} + /*normal increment and decrement buttons*/ + .combo-box-popup .list-view .scroll-bar:vertical .increment-button, + .list-view .scroll-bar:vertical .increment-button, + .combo-box-popup .list-view .scroll-bar:vertical .decrement-button, + .list-view .scroll-bar:vertical .decrement-button { + -fx-background-color: "#2fdae0ce", black; + -fx-color: "#2fdae0ce"; + -fx-background-insets: 0 0 0 0, 1 1 1 1; + } -// normal increment and decrement arrow -.combo-box-popup .list-view .scroll-bar:vertical .increment-button .increment-arrow, -.list-view .scroll-bar:vertical .increment-button .increment-arrow, -.combo-box-popup .list-view .scroll-bar:vertical .decrement-button .decrement-arrow, -.list-view .scroll-bar:vertical .decrement-button .decrement-arrow { - -fx-background-color: "#2fdae0ce" ; - -fx-background-insets: 0 0 0 0; - -fx-color: "#2fdae0ce"; -} -// normal increment and decrement arrow -.combo-box-popup .list-view .scroll-bar:vertical .increment-button .increment-arrow:hover, -.list-view .scroll-bar:vertical .increment-button .increment-arrow:hover, -.combo-box-popup .list-view .scroll-bar:vertical .decrement-button .decrement-arrow:hover, -.list-view .scroll-bar:vertical .decrement-button .decrement-arrow:hover { - -fx-background-color: "#2fdae0"; - -fx-color: "#2fdae0"; -} + /*normal increment and decrement arrow*/ + .combo-box-popup .list-view .scroll-bar:vertical .increment-button .increment-arrow, + .list-view .scroll-bar:vertical .increment-button .increment-arrow, + .combo-box-popup .list-view .scroll-bar:vertical .decrement-button .decrement-arrow, + .list-view .scroll-bar:vertical .decrement-button .decrement-arrow { + -fx-background-color: "#2fdae0ce" ; + -fx-background-insets: 0 0 0 0; + -fx-color: "#2fdae0ce"; + } + /*normal increment and decrement arrow*/ + .combo-box-popup .list-view .scroll-bar:vertical .increment-button .increment-arrow:hover, + .list-view .scroll-bar:vertical .increment-button .increment-arrow:hover, + .combo-box-popup .list-view .scroll-bar:vertical .decrement-button .decrement-arrow:hover, + .list-view .scroll-bar:vertical .decrement-button .decrement-arrow:hover { + -fx-background-color: "#2fdae0"; + -fx-color: "#2fdae0"; + } .save-location-button { - -fx-font-family: "Roboto Medium"; - -fx-font-weight: 100; - -fx-font-size: 12; - -fx-font-style: normal; - -fx-text-fill: "#2fdae0ce"; + -fx-font-family: "Roboto Medium"; + -fx-font-weight: 100; + -fx-font-size: 12; + -fx-font-style: normal; + -fx-text-fill: "#2fdae0ce"; - -fx-background-color: "#2fdae0ce", black; - -fx-background-insets: 0 0 0 0, 1 1 1 1; - -fx-border-color: "#2fdae0ce"; - -fx-border-width: 1px; + -fx-background-color: "#2fdae0ce", black; + -fx-background-insets: 0 0 0 0, 1 1 1 1; + -fx-border-color: "#2fdae0ce"; + -fx-border-width: 1px; } .save-location-button:hover { - -fx-text-fill: "#ffffffff"; + -fx-text-fill: "#ffffffff"; - -fx-background-color: "#2fdae0", black, "#2fdae0"; - -fx-background-insets: 0 0 0 0, 1 1 1 1, 3 3 3 3; - -fx-border-color: "#2fdae0ce"; - -fx-border-width: 1px; + -fx-background-color: "#2fdae0", black, "#2fdae0"; + -fx-background-insets: 0 0 0 0, 1 1 1 1, 3 3 3 3; + -fx-border-color: "#2fdae0ce"; + -fx-border-width: 1px; } .save-location-button:armed { - -fx-text-fill: "#202020"; - -fx-background-color: "#2fdae0", black, "#2fdae0"; - -fx-background-insets: 0 0 0 0, 1 1 1 1, 4 2 2 4; - -fx-border-color: "#2fdae0ce"; - -fx-border-width: 1px; + -fx-text-fill: "#202020"; + -fx-background-color: "#2fdae0", black, "#2fdae0"; + -fx-background-insets: 0 0 0 0, 1 1 1 1, 4 2 2 4; + -fx-border-color: "#2fdae0ce"; + -fx-border-width: 1px; } .add-location-button {