diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml deleted file mode 100644 index c0e01ca..0000000 --- a/.idea/sqldialects.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index deab1b6..71a317d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [LICENSE](LICENSE) -# [Versiohistoria](CHANGELOG.md) +# [Versiohistoria](src/main/resources/CHANGELOG.md) # Kuvaus Pienen kotiateriapalvelun käyttöön rakennettu ohjelma sisältäen seuraavat ominaisuudet diff --git a/pom.xml b/pom.xml index 17c948d..9a6b0e8 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,11 @@ 3.53.1.0 compile + + one.jpro.platform + jpro-mdfx + 0.6.2 + diff --git a/src/main/java/fi/lpam/App.java b/src/main/java/fi/lpam/App.java index f562bb6..ea5880b 100644 --- a/src/main/java/fi/lpam/App.java +++ b/src/main/java/fi/lpam/App.java @@ -4,9 +4,11 @@ import fi.lpam.gui.Asiakashallinta; import fi.lpam.gui.Kierroshallinta; import fi.lpam.gui.KuljetusRaportit; import fi.lpam.gui.KuljetusListat; +import fi.lpam.gui.elementit.MuutosIlmoitus; import javafx.application.Application; import javafx.geometry.Side; import javafx.scene.Scene; +import javafx.scene.control.Alert; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.image.Image; @@ -63,5 +65,7 @@ public class App extends Application { primaryStage.setMaximized(true); primaryStage.show(); primaryStage.getIcons().add(new Image(Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream("kuljetusruokalaatikko.jpg")))); + + if (!Main.properties.getProperty("version").equals(Main.properties.getProperty("viimeisinVersio"))) new MuutosIlmoitus(); } } \ No newline at end of file diff --git a/src/main/java/fi/lpam/Main.java b/src/main/java/fi/lpam/Main.java index 82c080a..6278def 100644 --- a/src/main/java/fi/lpam/Main.java +++ b/src/main/java/fi/lpam/Main.java @@ -1,12 +1,17 @@ package fi.lpam; -import java.io.IOException; +import org.apache.commons.lang3.SystemUtils; + +import java.io.*; +import java.nio.file.Path; import java.util.Properties; public class Main { public static boolean dev; public static Properties properties; + public static final File asetustiedosto = Path.of(SystemUtils.getUserHome().getAbsolutePath(), "OneDrive", "Kuljetusruokasovellus", "asetukset.properties").toFile(); + static void main(String[] args) { //noinspection RedundantIfStatement if (args.length > 0) { @@ -16,14 +21,25 @@ public class Main { } try { - properties = new Properties(); - properties.load(Main.class.getClassLoader().getResourceAsStream("app.properties")); + Properties defaults = new Properties(); + defaults.load(Main.class.getClassLoader().getResourceAsStream("defaults.properties")); + properties = new Properties(defaults); + properties.load(new FileInputStream(asetustiedosto)); } catch (IOException e) { //noinspection CallToPrintStackTrace e.printStackTrace(); } + System.out.println(properties.getProperty("version")); + System.out.println(properties.getProperty("viimeisinVersio")); + App.main(); + + try (OutputStream os = new FileOutputStream(asetustiedosto)) { + properties.store(os, ""); + } catch (IOException e) { + throw new RuntimeException(e); + } } } \ No newline at end of file diff --git a/src/main/java/fi/lpam/dataluokat/Asetukset.java b/src/main/java/fi/lpam/dataluokat/Asetukset.java new file mode 100644 index 0000000..e5b0f96 --- /dev/null +++ b/src/main/java/fi/lpam/dataluokat/Asetukset.java @@ -0,0 +1,29 @@ +package fi.lpam.dataluokat; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class Asetukset extends Properties { + private static Asetukset asetukset; + + private Asetukset() { + super(); + asetukset = this; + System.out.println("Luotu asetukset"); + try (InputStream is = new FileInputStream("defaults.properties")) { + asetukset.load(is); + asetukset.forEach((k, v) -> { + System.out.println(k + ": " + v); + }); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public Properties get() { + if (asetukset == null) {new Properties();} + return asetukset; + } +} diff --git a/src/main/java/fi/lpam/dataluokat/Tietokanta.java b/src/main/java/fi/lpam/dataluokat/Tietokanta.java index 8603e3b..d41f4ed 100644 --- a/src/main/java/fi/lpam/dataluokat/Tietokanta.java +++ b/src/main/java/fi/lpam/dataluokat/Tietokanta.java @@ -6,23 +6,23 @@ import fi.lpam.Main; import org.apache.commons.lang3.SystemUtils; import java.io.*; +import java.nio.file.Path; import java.sql.*; import java.util.Objects; public class Tietokanta { private static String osoite; - private static String dbPath = SystemUtils.getUserHome().getAbsolutePath() + "\\OneDrive\\Kuljetusruokasovellus\\tietokanta.db"; + private static File tietokantatiedosto = Path.of(SystemUtils.getUserHome().getAbsolutePath(), "OneDrive", "Kuljetusruokasovellus", "tietokanta.db").toFile(); public Tietokanta(boolean dev) { - if (dev) dbPath = "testikanta.db"; - File file = new File(dbPath); + if (dev) tietokantatiedosto = new File("testikanta.db"); try { - boolean _ = file.getParentFile().mkdirs(); - boolean _ = file.createNewFile(); + boolean _ = tietokantatiedosto.getParentFile().mkdirs(); + boolean _ = tietokantatiedosto.createNewFile(); } catch (Exception _) {} - osoite = "jdbc:sqlite:" + file.getAbsolutePath(); + osoite = "jdbc:sqlite:" + tietokantatiedosto.getAbsolutePath(); try (Connection conn = haeYhteys()) { diff --git a/src/main/java/fi/lpam/gui/elementit/MuutosIlmoitus.java b/src/main/java/fi/lpam/gui/elementit/MuutosIlmoitus.java new file mode 100644 index 0000000..d1f5b82 --- /dev/null +++ b/src/main/java/fi/lpam/gui/elementit/MuutosIlmoitus.java @@ -0,0 +1,55 @@ +package fi.lpam.gui.elementit; + +import fi.lpam.Main; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.layout.*; +import javafx.scene.paint.Color; +import javafx.stage.Stage; +import one.jpro.platform.mdfx.MarkdownView; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Objects; + +public class MuutosIlmoitus extends Stage { + public MuutosIlmoitus() { + super(); + VBox root = new VBox(); + root.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT))); + root.setPadding(TabPohja.oletusInsets); + root.setStyle(TabPohja.oletusStyle); + root.setAlignment(Pos.CENTER); + root.setSpacing(10); + + String md; + try (InputStreamReader isr = new InputStreamReader(Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream("CHANGELOG.md")))) { + md = isr.readAllAsString(); + int toinenMerkintä = md.indexOf("# ", 1); + int kolmasMerkintä = md.indexOf("# ", toinenMerkintä + 1); + int endIndex = md.indexOf("# ", kolmasMerkintä + 1); + md = md.substring(0, endIndex); + } + catch (IOException e) { + e.printStackTrace(); + md = "# Virhe versiolokin haussa"; + } + + MarkdownView markdownView = new MarkdownView(md); + root.getChildren().add(markdownView); + + Button ok = new Button("OK"); + ok.setFont(TabPohja.buttonFont); + ok.setOnAction(e -> this.close()); + root.getChildren().add(ok); + + Scene scene = new Scene(root); + this.setScene(scene); + this.setTitle("Uusi versio, katso muutokset alta!"); + this.setResizable(false); + this.show(); + + Main.properties.setProperty("viimeisinVersio", Main.properties.getProperty("version")); + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 58b192b..30d36ec 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -8,6 +8,7 @@ module fi.lpam.ruokamanageri { requires java.desktop; requires org.apache.pdfbox; requires org.apache.commons.lang3; + requires one.jpro.platform.mdfx; opens fi.lpam.dataluokat to javafx.base; exports fi.lpam; diff --git a/CHANGELOG.md b/src/main/resources/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to src/main/resources/CHANGELOG.md diff --git a/src/main/resources/app.properties b/src/main/resources/app.properties deleted file mode 100644 index e5683df..0000000 --- a/src/main/resources/app.properties +++ /dev/null @@ -1 +0,0 @@ -version=${project.version} \ No newline at end of file diff --git a/src/main/resources/defaults.properties b/src/main/resources/defaults.properties new file mode 100644 index 0000000..b73f2ce --- /dev/null +++ b/src/main/resources/defaults.properties @@ -0,0 +1,2 @@ +version=${project.version} +viimeisinVersio=0.0.0 \ No newline at end of file