Replaced a non-modular json library library with a modular one. Bach is able to build application a custom image and worldclock executable.

This commit is contained in:
Carl Dea
2021-03-23 20:46:05 -04:00
parent 490e94a441
commit ab6cdcbf8e
9 changed files with 199 additions and 179 deletions

View File

@@ -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;

22
pom.xml
View File

@@ -15,16 +15,30 @@
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>com.jsoniter</groupId>
<artifactId>jsoniter</artifactId>
<version>0.9.23</version>
<scope>compile</scope>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.1</version>
</dependency>
</dependencies>
<build>

View File

@@ -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<Any> 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<Map<String, Object>> locationArray = objectMapper.readValue(actual, List.class);
for (Map<String, Object> 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.");

View File

@@ -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<Location> locationList = locationsListView.getItems().stream().collect(Collectors.toList());
String arrayJson = JsonStream.serialize(locationList);
fileWriter.write(arrayJson);
ObjectMapper objectMapper = new ObjectMapper();
List<Location> locationList = locationsListView.getItems();
objectMapper.writeValue(fileWriter, locationList);
System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");

View File

@@ -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 +
'}';

View File

@@ -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);
}

View File

@@ -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));

View File

@@ -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;
}

View File

@@ -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 {