From 9dc2c7d9d076ead5c155c4e789e2e7ee9d52a508 Mon Sep 17 00:00:00 2001 From: genuineparts Date: Mon, 9 Jun 2025 15:45:29 +0200 Subject: [PATCH] Get titles from DB --- src/main/java/be/jaud/Main.java | 95 ++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/src/main/java/be/jaud/Main.java b/src/main/java/be/jaud/Main.java index 94fc433..6afbf52 100644 --- a/src/main/java/be/jaud/Main.java +++ b/src/main/java/be/jaud/Main.java @@ -107,85 +107,96 @@ public class Main { } } - private static String createOutput(String user){ + private static String createOutput(String user) { + List title = new ArrayList<>(); + try { + ResultSet rsu = MariaDB.load_user(user); + if (rsu != null) { + while (rsu.next()) { + title.add(rsu.getString("title")); + } + } + rsu.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } JSONObject dat = new JSONObject(); Date updatetime = new Date(time); - dat.put("interval",conf.getInt("refreshTime")*1000); + dat.put("interval", conf.getInt("refreshTime") * 1000); JSONArray display = new JSONArray(); JSONObject monitor1 = new JSONObject(); - monitor1.put("label","Zug"); + monitor1.put("label", "Zug"); JSONArray layout = new JSONArray(); JSONObject text1 = new JSONObject(); - text1.put("type","text"); - text1.put("x",120); - text1.put("y",120); - text1.put("text","Abfahrten"); - text1.put("font",2); - text1.put("color",conf.getString("textcolormain")); - text1.put("background",conf.getString("bgcolormain")); + text1.put("type", "text"); + text1.put("x", 120); + text1.put("y", 120); + text1.put("text", "Abfahrten"); + text1.put("font", 2); + text1.put("color", conf.getString("textcolormain")); + text1.put("background", conf.getString("bgcolormain")); JSONObject text2 = new JSONObject(); - text2.put("type","text"); - text2.put("x",120); - text2.put("y",170); + text2.put("type", "text"); + text2.put("x", 120); + text2.put("y", 170); text2.put("text", dateFormat.format(updatetime)); - text2.put("color",conf.getString("textcolorupdate")); - text2.put("font",2); - text2.put("background",conf.getString("bgcolormain")); + text2.put("color", conf.getString("textcolorupdate")); + text2.put("font", 2); + text2.put("background", conf.getString("bgcolormain")); JSONObject text3 = new JSONObject(); - text3.put("type","text"); - text3.put("x",120); - text3.put("y",210); - text3.put("text", "Ver. "+version); - text3.put("color",conf.getString("textcolorupdate")); - text3.put("font",2); - text3.put("background",conf.getString("bgcolormain")); + text3.put("type", "text"); + text3.put("x", 120); + text3.put("y", 210); + text3.put("text", "Ver. " + version); + text3.put("color", conf.getString("textcolorupdate")); + text3.put("font", 2); + text3.put("background", conf.getString("bgcolormain")); layout.put(text3); layout.put(text2); layout.put(text1); - monitor1.put("data",layout); - monitor1.put("labelColor",conf.getString("textcolormain")); - monitor1.put("color",conf.getString("textcolormain")); - monitor1.put("background",conf.getString("bgcolormain")); + monitor1.put("data", layout); + monitor1.put("labelColor", conf.getString("textcolormain")); + monitor1.put("color", conf.getString("textcolormain")); + monitor1.put("background", conf.getString("bgcolormain")); display.put(monitor1); JSONObject monitor2 = new JSONObject(); - monitor2.put("label",conf.getString("monitors.monitor1.Title")); - monitor2.put("labelColor",conf.getString("labelcolor")); - monitor2.put("fullDraw",true); + monitor2.put("label", title.get(0)); + monitor2.put("labelColor", conf.getString("labelcolor")); + monitor2.put("fullDraw", true); int zug1 = udata.get(user).get("1"); makeLabel(monitor2, zug1); display.put(monitor2); JSONObject monitor3 = new JSONObject(); - monitor3.put("label",conf.getString("monitors.monitor2.Title")); - monitor3.put("labelColor",conf.getString("labelcolor")); - monitor3.put("fullDraw",true); + monitor3.put("label", title.get(1)); + monitor3.put("labelColor", conf.getString("labelcolor")); + monitor3.put("fullDraw", true); int zug2 = udata.get(user).get("2"); makeLabel(monitor3, zug2); display.put(monitor3); JSONObject monitor4 = new JSONObject(); - monitor4.put("label",conf.getString("monitors.monitor3.Title")); - monitor4.put("labelColor",conf.getString("labelcolor")); - monitor4.put("fullDraw",true); + monitor4.put("label", title.get(2)); + monitor4.put("labelColor", conf.getString("labelcolor")); + monitor4.put("fullDraw", true); int zug3 = udata.get(user).get("3"); makeLabel(monitor4, zug3); display.put(monitor4); JSONObject monitor5 = new JSONObject(); - monitor5.put("label",conf.getString("monitors.monitor4.Title")); - monitor5.put("labelColor",conf.getString("labelcolor")); - monitor5.put("fullDraw",true); + monitor5.put("label", title.get(3)); + monitor5.put("labelColor", conf.getString("labelcolor")); + monitor5.put("fullDraw", true); int zug4 = udata.get(user).get("4"); makeLabel(monitor5, zug4); display.put(monitor5); - dat.put("displays",display); - System.out.println(display); + dat.put("displays", display); return dat.toString(); } - private static void makeLabel(JSONObject Monitor, int zeit){ + private static void makeLabel(JSONObject Monitor, int zeit){ if(zeit != 0){ Monitor.put("color",conf.getString("textcolordelay")); Monitor.put("background",conf.getString("bgcolordelay"));