From c2a4ba9d6a3fcd58cebf51104f196778f62ce112 Mon Sep 17 00:00:00 2001 From: C0d3v Date: Thu, 30 Sep 2021 14:13:21 +0200 Subject: [PATCH] Smaller fixes --- QuickLaunch/src/basics/BasicGuiApp.java | 20 ++++----- QuickLaunch/src/guis/MainGui.java | 34 ++++++++++------ QuickLaunch/src/main/KeyChecker.java | 3 +- QuickLaunch/src/main/ModLoader.java | 13 +++--- QuickLaunch/src/mod_calc/Calcmod.java | 49 ++++++++--------------- QuickLaunch/src/update/UpdateChecker.java | 6 +-- 6 files changed, 54 insertions(+), 71 deletions(-) diff --git a/QuickLaunch/src/basics/BasicGuiApp.java b/QuickLaunch/src/basics/BasicGuiApp.java index 26783e8..a58b1b4 100644 --- a/QuickLaunch/src/basics/BasicGuiApp.java +++ b/QuickLaunch/src/basics/BasicGuiApp.java @@ -61,13 +61,10 @@ public class BasicGuiApp extends Application{ mainStage = primaryStage; mainStage.setTitle("QuickLaunch v"+Start.VERSION); mainStage.getIcons().add(new Image(BasicGuiApp.class.getResourceAsStream("/icon.png"))); - mainStage.setOnCloseRequest(new EventHandler() { - - public void handle(WindowEvent event) { - SettingManager.saveSettings(); - System.exit(0); - - } + mainStage.setOnCloseRequest(event -> { + SettingManager.saveSettings(); + System.exit(0); + }); primaryStage.initStyle(StageStyle.TRANSPARENT); @@ -81,12 +78,9 @@ public class BasicGuiApp extends Application{ primaryStage.show(); if(SettingManager.isCheckUptdateOnBoot()){ - new Thread(new Runnable() { - - public void run() { - Updater up = new Updater(); - up.checkForUpdate(); - } + new Thread(() -> { + Updater up = new Updater(); + up.checkForUpdate(); }).start(); } } diff --git a/QuickLaunch/src/guis/MainGui.java b/QuickLaunch/src/guis/MainGui.java index 6a47b10..f1fa3b6 100644 --- a/QuickLaunch/src/guis/MainGui.java +++ b/QuickLaunch/src/guis/MainGui.java @@ -1,7 +1,5 @@ package guis; -import java.io.IOException; - import basics.BasicGuiApp; import basics.BasicMod; import javafx.event.ActionEvent; @@ -19,7 +17,7 @@ public class MainGui extends AnchorPane{ private static Text notificationText; - public static TextField inputField; + public final TextField inputField; public MainGui(){ @@ -46,13 +44,13 @@ public class MainGui extends AnchorPane{ public void handle(KeyEvent event) { String input; if(event.getCode().name().equals("ENTER")){ + //TODO create a layout for suggestions of which maybe 5 can be displayed BasicGuiApp.mainStage.setAlwaysOnTop(false); input = inputField.getText(); inputField.setText(""); if(input.equals("exit")){ System.exit(-1); } - for (BasicMod bm : ModLoader.mods) { bm.checkInput(input); } @@ -79,7 +77,9 @@ public class MainGui extends AnchorPane{ } }); - + + //TODO maybe show this only when notification is present + //TODO Enlarge and collapse window if content is present notificationText = new Text(); notificationText.setLayoutX(0); notificationText.setLayoutY(65); @@ -88,6 +88,8 @@ public class MainGui extends AnchorPane{ notificationText.setStyle("-fx-background-color: rgba(0, 0, 0, 0);" + "-fx-fill: rgb(221,255,0);"); notificationText.setFont(ResourceManager.getFontSmall()); + notificationText.setVisible(false); + notificationText.setManaged(false); this.getChildren().add(inputField); this.getChildren().add(minimize); @@ -97,15 +99,21 @@ public class MainGui extends AnchorPane{ public static void addNotification(String msg,final int sec){ notificationText.setText(msg); - Thread t = new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(sec*1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - notificationText.setText(""); + notificationText.setManaged(true); + notificationText.setVisible(true); + BasicGuiApp.mainScene.getRoot().resize(400,60); + BasicGuiApp.mainScene.getWindow().sizeToScene(); + Thread t = new Thread(() -> { + try { + Thread.sleep(sec*1000); + } catch (InterruptedException e) { + e.printStackTrace(); } + notificationText.setText(""); + notificationText.setVisible(false); + notificationText.setManaged(false); + BasicGuiApp.mainScene.getRoot().resize(400,40); + BasicGuiApp.mainScene.getWindow().sizeToScene(); }); t.start(); } diff --git a/QuickLaunch/src/main/KeyChecker.java b/QuickLaunch/src/main/KeyChecker.java index 44cf84f..d1d04e3 100644 --- a/QuickLaunch/src/main/KeyChecker.java +++ b/QuickLaunch/src/main/KeyChecker.java @@ -33,7 +33,8 @@ public class KeyChecker implements NativeKeyListener{ BasicGuiApp.mainStage.setAlwaysOnTop(true); BasicGuiApp.mainStage.setAlwaysOnTop(false); BasicGuiApp.mainStage.requestFocus(); - MainGui.inputField.requestFocus(); + //MainGui.inputField.requestFocus(); + //TODO BasicGuiApp.mainStage.setIconified(true); BasicGuiApp.mainStage.setIconified(false); } diff --git a/QuickLaunch/src/main/ModLoader.java b/QuickLaunch/src/main/ModLoader.java index 712ef10..ca65331 100644 --- a/QuickLaunch/src/main/ModLoader.java +++ b/QuickLaunch/src/main/ModLoader.java @@ -2,7 +2,6 @@ package main; import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -15,7 +14,7 @@ import manager.SettingManager; import mod_quicklaunch.QuickLaunch; public class ModLoader { - public static ArrayList mods = new ArrayList(); + public static ArrayList mods = new ArrayList<>(); private BufferedReader bfr; public void init() { @@ -30,11 +29,7 @@ public class ModLoader { System.out.println("ModLoader: Ready to install mods"); } this.bfr = new BufferedReader(new FileReader(modfile)); - } - catch (FileNotFoundException e) { - e.printStackTrace(); - } - catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } System.out.println("ModLoader: Exit init"); @@ -49,12 +44,14 @@ public class ModLoader { catch (IOException e1) { e1.printStackTrace(); } + + //TODO move mods maybe to mods folder while (nextMod != null) { try { System.out.println("Trying for "+nextMod+".jar"); File modJar = new File(SettingManager.getJarDirectory()+File.separator+nextMod+".jar"); System.out.println(modJar.exists() ? "Found "+nextMod : "Not found"); - ClassLoader cl = new URLClassLoader(new URL[] {modJar.toURL()}, Thread.currentThread().getContextClassLoader()); + ClassLoader cl = new URLClassLoader(new URL[] {modJar.toURI().toURL()}, Thread.currentThread().getContextClassLoader()); mods.add((BasicMod)cl.loadClass("mod_"+nextMod.toLowerCase()+"."+nextMod).getConstructors()[0].newInstance(new Object[0])); nextMod = bfr.readLine(); } catch (InstantiationException | IOException | SecurityException | InvocationTargetException | IllegalArgumentException | IllegalAccessException e) { diff --git a/QuickLaunch/src/mod_calc/Calcmod.java b/QuickLaunch/src/mod_calc/Calcmod.java index d5a8745..de3fdce 100644 --- a/QuickLaunch/src/mod_calc/Calcmod.java +++ b/QuickLaunch/src/mod_calc/Calcmod.java @@ -53,46 +53,31 @@ public class Calcmod extends BasicMod{ } private boolean isNumber(char check){ - if((check == '1') || - (check == '2') || - (check == '3') || - (check == '4') || - (check == '5') || - (check == '6') || - (check == '7') || - (check == '8') || - (check == '9') || - (check == '0') || - (check == '.')){ - return true; - } - else{ - return false; - } + return (check == '1') || + (check == '2') || + (check == '3') || + (check == '4') || + (check == '5') || + (check == '6') || + (check == '7') || + (check == '8') || + (check == '9') || + (check == '0') || + (check == '.'); } private boolean isOperator(char check){ - if((check == '+') || - (check == '-') || - (check == '*') || - (check == '/')){ - return true; - } - else{ - return false; - } + return (check == '+') || + (check == '-') || + (check == '*') || + (check == '/'); } private boolean isAlternative(char check){ - if((check == ',') || - (check == 'x')){ - return true; - } - else{ - return false; - } + return (check == ',') || + (check == 'x'); } private char changeAlternatives(char check){ diff --git a/QuickLaunch/src/update/UpdateChecker.java b/QuickLaunch/src/update/UpdateChecker.java index b135ce7..3597a2e 100644 --- a/QuickLaunch/src/update/UpdateChecker.java +++ b/QuickLaunch/src/update/UpdateChecker.java @@ -12,8 +12,7 @@ public class UpdateChecker { HashMap serverData = new HashMap<>(); public void requestServerData(){ - try { - Socket socket = new Socket(); + try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), 9999), 2000); DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); @@ -30,9 +29,8 @@ public class UpdateChecker { String[] keyValue = str.split("="); serverData.put(keyValue[0], keyValue[1]); } - socket.close(); } catch (IOException e) { - e.printStackTrace(); + System.err.println("Could not reach update server"); } }