Skip to content

Commit b96663d

Browse files
authored
Merge pull request #1 from jrt345/release-v1.1.0
Release v1.1.0
2 parents e83fd7f + bf17053 commit b96663d

File tree

11 files changed

+232
-100
lines changed

11 files changed

+232
-100
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--Version-1.0.0-->
1+
<!--Version-1.1.0-->
22

33
# BookJar
44

@@ -55,9 +55,8 @@ by selected a different option among the three radio buttons right of the text f
5555

5656
## Requirements to edit source code:
5757

58-
1. Have [Java 16.0.1](https://jdk.java.net/) to run the source code.
59-
2. Have the [JavaFX 16 SDK](https://gluonhq.com/products/javafx/) installed.
60-
3. Have [SceneBuilder](https://gluonhq.com/products/scene-builder/) installed to easily edit .fxml files (optional, but highly recommended).
58+
1. Have [Java 17](https://jdk.java.net/) to run the source code.
59+
2. Have [SceneBuilder](https://gluonhq.com/products/scene-builder/) installed to easily edit .fxml files.
6160

6261
***
6362

pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.example</groupId>
88
<artifactId>BookJar</artifactId>
9-
<version>1.0</version>
9+
<version>1.1.0</version>
1010
<name>BookJar</name>
1111

1212
<properties>
@@ -18,12 +18,12 @@
1818
<dependency>
1919
<groupId>org.openjfx</groupId>
2020
<artifactId>javafx-controls</artifactId>
21-
<version>16</version>
21+
<version>17.0.2</version>
2222
</dependency>
2323
<dependency>
2424
<groupId>org.openjfx</groupId>
2525
<artifactId>javafx-fxml</artifactId>
26-
<version>16</version>
26+
<version>17.0.2</version>
2727
</dependency>
2828

2929
<dependency>
@@ -75,14 +75,15 @@
7575
<plugin>
7676
<groupId>org.apache.maven.plugins</groupId>
7777
<artifactId>maven-shade-plugin</artifactId>
78-
<version>3.2.4</version>
78+
<version>3.3.0</version>
7979
<executions>
8080
<execution>
8181
<goals>
8282
<goal>shade</goal>
8383
</goals>
8484
<configuration>
8585
<shadedArtifactAttached>true</shadedArtifactAttached>
86+
<createDependencyReducedPom>false</createDependencyReducedPom>
8687
<transformers>
8788
<transformer implementation=
8889
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

src/main/java/main/LoadBookJar.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javafx.scene.Scene;
66
import javafx.scene.image.Image;
77
import javafx.stage.Stage;
8+
import main.utils.UpdateManager;
89
import main.utils.readwrite.ReadWriteFile;
910

1011
import java.io.FileOutputStream;
@@ -41,6 +42,10 @@ public void start(Stage stage) throws Exception {
4142
stage.show();
4243
LoadBookJar.stage = stage;
4344

45+
if (UpdateManager.isUpdateAvailable()) {
46+
UpdateManager.showUpdateDialog();
47+
}
48+
4449
stage.setOnCloseRequest(e -> {
4550
try {
4651
ReadWriteFile.saveData();

src/main/java/main/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main;
22

33
public class Main {
4-
public static void main(String[] args){
4+
public static void main(String[] args) {
55
LoadBookJar.main(args);
66
}
77
}

src/main/java/main/controllers/Controller.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javafx.stage.WindowEvent;
2020
import main.LoadBookJar;
2121
import main.utils.Book;
22+
import main.utils.UpdateManager;
2223
import main.utils.readwrite.ReadWriteFile;
2324

2425
import java.io.IOException;
@@ -483,6 +484,13 @@ private void searchBooksTable(KeyEvent keyEvent) {
483484
}
484485
}
485486

487+
@FXML
488+
private void checkForUpdate(ActionEvent event) {
489+
if (UpdateManager.isUpdateAvailable()) {
490+
UpdateManager.showUpdateDialog();
491+
}
492+
}
493+
486494
@Override
487495
public void initialize(URL url, ResourceBundle resourceBundle) {
488496
indexColumn.setCellValueFactory(new PropertyValueFactory<>("Index"));
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package main.utils;
2+
3+
import javafx.geometry.Pos;
4+
import javafx.scene.control.Alert;
5+
import javafx.scene.control.Hyperlink;
6+
import javafx.scene.control.Label;
7+
import javafx.scene.image.Image;
8+
import javafx.scene.layout.FlowPane;
9+
import javafx.scene.layout.VBox;
10+
import javafx.stage.Stage;
11+
import main.Main;
12+
13+
import java.io.BufferedReader;
14+
import java.io.IOException;
15+
import java.io.InputStreamReader;
16+
import java.net.URL;
17+
import java.net.URLConnection;
18+
import java.util.Objects;
19+
20+
public class UpdateManager {
21+
22+
public static final String CURRENT_VERSION = "1.1.0";
23+
24+
public static String getLatestVersion() {
25+
try {
26+
URL latestVersion = new URL("https://raw.githubusercontent.com/jrt345/BookJar/master/README.md");
27+
URLConnection gitHub = latestVersion.openConnection();
28+
BufferedReader in = new BufferedReader(new InputStreamReader(gitHub.getInputStream()));
29+
30+
String stringCurrentVersion = in.readLine();
31+
in.close();
32+
33+
return stringCurrentVersion.replaceAll("<", "")
34+
.replaceAll("!", "")
35+
.replaceAll("-", "")
36+
.replaceAll("Version", "")
37+
.replaceAll(">", "")
38+
.replaceAll("\\s", "");
39+
} catch (IOException e) {
40+
return "0.0.0";
41+
}
42+
}
43+
44+
45+
public static boolean isUpdateAvailable() {
46+
try {
47+
String stringLatestVersion = getLatestVersion();
48+
49+
String[] currentVersionsStringArray = CURRENT_VERSION.split("\\.");
50+
String[] latestVersionsStringArray = stringLatestVersion.split("\\.");
51+
52+
int[] currentVersionsIntArray = new int[3];
53+
int[] latestVersionsIntArray = new int[3];
54+
55+
for (int i = 0;i < 3;i++){
56+
currentVersionsIntArray[i] = Integer.parseInt(currentVersionsStringArray[i]);
57+
latestVersionsIntArray[i] = Integer.parseInt(latestVersionsStringArray[i]);
58+
}
59+
60+
if (currentVersionsIntArray[0] < latestVersionsIntArray[0]){
61+
return true;
62+
} else if (currentVersionsIntArray[1] < latestVersionsIntArray[1]) {
63+
return true;
64+
} else {
65+
return currentVersionsIntArray[2] < latestVersionsIntArray[2];
66+
}
67+
} catch (Exception e) {
68+
return false;
69+
}
70+
}
71+
72+
public static void showUpdateDialog() {
73+
Alert alert = new Alert(Alert.AlertType.INFORMATION);
74+
alert.setTitle("BookJar");
75+
((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(new Image(Objects.requireNonNull(Main.class.getResourceAsStream("/main/images/bookJarLogo-200x.png"))));
76+
alert.setHeaderText("Update available!");
77+
78+
VBox primaryVbox = new VBox();
79+
VBox vboxPt1 = new VBox();
80+
VBox vboxPt2 = new VBox();
81+
82+
Label introLabel = new Label("A new version of BookJar has been released! Version: " + getLatestVersion());
83+
84+
Label label = new Label(" is available at ");
85+
Hyperlink repoLink = new Hyperlink("github.com/jrt345/BookJar.");
86+
87+
FlowPane flowPane = new FlowPane(label, repoLink);
88+
flowPane.setAlignment(Pos.CENTER);
89+
90+
vboxPt1.getChildren().addAll(introLabel, flowPane);
91+
vboxPt1.setAlignment(Pos.CENTER);
92+
93+
Label downloadLabel = new Label("You can download version: " + getLatestVersion() + " here: ");
94+
Hyperlink downloadLink = new Hyperlink("https://github.com/jrt345/BookJar/releases/latest");
95+
96+
vboxPt2.getChildren().addAll(downloadLabel, downloadLink);
97+
vboxPt2.setAlignment(Pos.CENTER);
98+
99+
primaryVbox.getChildren().addAll(vboxPt1, new Label(), vboxPt2);
100+
primaryVbox.setAlignment(Pos.CENTER);
101+
102+
repoLink.setOnAction( (evt) -> {
103+
alert.close();
104+
Runtime rt = Runtime.getRuntime();
105+
String url = "https://github.com/jrt345/BookJar";
106+
try {
107+
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
108+
} catch (IOException e) {
109+
e.printStackTrace();
110+
}
111+
} );
112+
113+
downloadLink.setOnAction( (evt) -> {
114+
alert.close();
115+
Runtime rt = Runtime.getRuntime();
116+
String url = "https://github.com/jrt345/BookJar/releases/latest";
117+
try {
118+
rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
119+
} catch (IOException e) {
120+
e.printStackTrace();
121+
}
122+
} );
123+
124+
alert.getDialogPane().contentProperty().set(primaryVbox);
125+
alert.showAndWait();
126+
}
127+
}
128+

src/main/resources/main/aboutBox.fxml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,34 @@
99
<?import javafx.scene.image.ImageView?>
1010
<?import javafx.scene.layout.*?>
1111
<?import javafx.scene.text.Font?>
12-
<AnchorPane prefHeight="400.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.controllers.AboutBoxController">
12+
<AnchorPane prefHeight="400.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.controllers.AboutBoxController">
1313
<children>
1414
<BorderPane prefHeight="400.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
1515
<top>
1616
<AnchorPane prefHeight="75.0" prefWidth="500.0" BorderPane.alignment="CENTER">
1717
<children>
18-
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="185.0" layoutY="9.0" text="BookJar" textAlignment="CENTER" AnchorPane.bottomAnchor="8.5" AnchorPane.leftAnchor="185.0" AnchorPane.rightAnchor="126.0" AnchorPane.topAnchor="8.5">
19-
<font>
20-
<Font name="Trebuchet MS Bold" size="50.0" />
21-
</font>
22-
</Label>
23-
<ImageView fitHeight="58.0" fitWidth="58.0" layoutX="127.0" layoutY="9.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="8.5" AnchorPane.leftAnchor="127.0" AnchorPane.rightAnchor="315.0" AnchorPane.topAnchor="8.5">
24-
<image>
25-
<Image url="@images/bookJarLogo-200x.png" />
26-
</image>
27-
</ImageView>
18+
<HBox alignment="CENTER" layoutX="127.0" layoutY="8.5" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
19+
<children>
20+
<ImageView fitHeight="58.0" fitWidth="58.0" pickOnBounds="true" preserveRatio="true">
21+
<image>
22+
<Image url="@images/bookJarLogo-200x.png" />
23+
</image>
24+
</ImageView>
25+
<Label alignment="CENTER" contentDisplay="CENTER" text="BookJar" textAlignment="CENTER">
26+
<font>
27+
<Font name="Trebuchet MS Bold" size="50.0" />
28+
</font>
29+
</Label>
30+
</children>
31+
</HBox>
2832
</children>
2933
</AnchorPane>
3034
</top>
3135
<center>
3236
<AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
3337
<children>
3438
<Separator layoutX="199.0" layoutY="4.0" prefWidth="200.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="0.0" />
35-
<TextArea editable="false" focusTraversable="false" layoutX="50.0" layoutY="23.0" prefHeight="240.0" prefWidth="400.0" text="BookJar&#10;Version 1.0.0&#10;&#10;Build with:&#10;Java 16, OpenJDK.&#10;JavaFX 16, Gluon.&#10;&#10;Copyright © 2021 jrt345. All rights reserved.&#10;&#10;BookJar is licensed under the MIT License:&#10;&#10;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:&#10;&#10;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#10;&#10;THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." wrapText="true" />
39+
<TextArea editable="false" focusTraversable="false" layoutX="50.0" layoutY="23.0" prefHeight="240.0" prefWidth="400.0" text="BookJar&#10;Version 1.1.0&#10;&#10;Build with:&#10;Java 17, OpenJDK.&#10;JavaFX 17, Gluon.&#10;&#10;Copyright © 2021-2022 jrt345. All rights reserved.&#10;&#10;BookJar is licensed under the MIT License:&#10;&#10;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:&#10;&#10;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#10;&#10;THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." wrapText="true" />
3640
</children>
3741
</AnchorPane>
3842
</center>

0 commit comments

Comments
 (0)