From cc21e69084905c8a664369d71d9711d27e097f50 Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 8 Mar 2024 19:13:28 +0100 Subject: [PATCH 1/4] huge runtime optimisations --- pom.xml | 2 + src/data/GuiData.java | 161 ++---------------------------------------- src/gui/MainGUI.java | 29 +++----- 3 files changed, 18 insertions(+), 174 deletions(-) diff --git a/pom.xml b/pom.xml index 4b0b0f2..635b6f6 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,8 @@ 17 17 + UTF-8 + UTF-8 diff --git a/src/data/GuiData.java b/src/data/GuiData.java index 6ff3711..5fc9964 100644 --- a/src/data/GuiData.java +++ b/src/data/GuiData.java @@ -21,6 +21,7 @@ public class GuiData { private ArrayList verifier = new ArrayList(); private ArrayList creator = new ArrayList(); private ArrayList ytlink = new ArrayList(); + public ArrayList completed = new ArrayList(); private FetchData data = new FetchData(); @@ -60,7 +61,7 @@ public class GuiData { - public void IndexLevelName() throws IOException { + public void IndexData() throws IOException { FetchData data = new FetchData(); @@ -75,169 +76,22 @@ public class GuiData { for(int i = 0; i < filelengthindex.length; i++) { - - jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); JSONObject obj = new JSONObject(jsonstring); + JSONArray recordsArray = obj.getJSONArray("records"); localLevels.add(obj.getString("name")); - - - - } - - - - } - - public void IndexLevelID() throws IOException { - - - - File filelength = new File("C:\\ExtremeDemonList\\levels"); - File[] filelengthindex = filelength.listFiles(); - - String jsonstring; - - localLength = filelengthindex.length; - - System.out.println(filelengthindex.length); - - for(int i = 0; i < filelengthindex.length; i++) { - - - - jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); - jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); - - JSONObject obj = new JSONObject(jsonstring); - id.add(obj.getInt("id") + ""); - - - - } - - } - - public void IndexVerifiers() throws IOException { - - FetchData data = new FetchData(); - - File filelength = new File("C:\\ExtremeDemonList\\levels"); - File[] filelengthindex = filelength.listFiles(); - - String jsonstring; - - localLength = filelengthindex.length; - - System.out.println(filelengthindex.length); - - for(int i = 0; i < filelengthindex.length; i++) { - - - - jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); - jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); - - JSONObject obj = new JSONObject(jsonstring); - verifier.add(obj.getString("verifier")); - - - - } - - - - } - - public void IndexCreators() throws IOException { - - FetchData data = new FetchData(); - - File filelength = new File("C:\\ExtremeDemonList\\levels"); - File[] filelengthindex = filelength.listFiles(); - - String jsonstring; - - localLength = filelengthindex.length; - - System.out.println(filelengthindex.length); - - for(int i = 0; i < filelengthindex.length; i++) { - - - - jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); - jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); - - JSONObject obj = new JSONObject(jsonstring); - creator.add(obj.getString("author")); + qualification.add(obj.getInt("percentToQualify") + ""); + ytlink.add(obj.getString("verification") + ""); - } - - - - } - - public void IndexQualification() throws IOException { - - FetchData data = new FetchData(); - - File filelength = new File("C:\\ExtremeDemonList\\levels"); - File[] filelengthindex = filelength.listFiles(); - - String jsonstring; - - localLength = filelengthindex.length; - - System.out.println(filelengthindex.length); - - for(int i = 0; i < filelengthindex.length; i++) { - - - - jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); - jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); - - JSONObject obj = new JSONObject(jsonstring); - - qualification.add(obj.getInt("percentToQualify") + ""); - } - } - - public ArrayList IndexYoutubeLink() throws IOException { - FetchData data = new FetchData(); - - File filelength = new File("C:\\ExtremeDemonList\\levels"); - File[] filelengthindex = filelength.listFiles(); - - String jsonstring; - - localLength = filelengthindex.length; - - System.out.println(filelengthindex.length); - - for(int i = 0; i < filelengthindex.length; i++) { - - - - jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); - jsonstring = jsonstring.trim().replace("\n", "").replace("\t", "").replace("\\", ""); - - JSONObject obj = new JSONObject(jsonstring); - - ytlink.add(obj.getString("verification") + ""); - } - - return ytlink; - } + } public static ArrayList allVictors(String levelname) throws IOException { ArrayList completed = new ArrayList<>(); @@ -259,7 +113,4 @@ public class GuiData { return completed; } - - - } diff --git a/src/gui/MainGUI.java b/src/gui/MainGUI.java index 2c27171..69662c4 100644 --- a/src/gui/MainGUI.java +++ b/src/gui/MainGUI.java @@ -2,35 +2,25 @@ package gui; import java.awt.Button; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; -import java.awt.Image; import java.awt.Insets; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; import java.util.ArrayList; -import javax.imageio.ImageIO; import javax.swing.BorderFactory; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -70,6 +60,7 @@ public class MainGUI { public JCheckBox filtercompleted = new JCheckBox("Nach geschafft filtern"); public Button copyid = new Button("Level ID kopieren"); public Button showinfos = new Button("Mehr Infos anzeigen"); + public JButton settings = new JButton("⚙"); GridLayout gridLayout = new GridLayout(3, 1); private String[] showing = {"Alle anzeigen", "Top 3", "Top 50", "Top 150", "Top 200"}; @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -79,12 +70,7 @@ public class MainGUI { public void build() throws IOException { GuiData data = new GuiData(); - data.IndexLevelName(); - data.IndexLevelID(); - data.IndexVerifiers(); - data.IndexCreators(); - data.IndexQualification(); - data.IndexYoutubeLink(); + data.IndexData(); gridLayout.setRows(data.getLocalLevels().size()); @@ -118,6 +104,10 @@ public class MainGUI { qualify.setBounds(10, 170, 164, 30); + settings.setBounds(1, 1, 60, 60); + settings.setFont(settings.getFont().deriveFont(30f)); + settings.setBackground(Color.LIGHT_GRAY); + victor.setBounds(1, 276, 164, 30); records.getVerticalScrollBar().setUnitIncrement(16); @@ -140,7 +130,7 @@ public class MainGUI { verifier.setBounds(10, 110, 164, 30); - search.setBounds(1, 1, 500, 60); + search.setBounds(60, 1, 440, 60); show.setBounds(500, 1, 200, 60); @@ -181,7 +171,7 @@ public class MainGUI { try { file.createNewFile(); } catch (IOException e1) { - // TODO Auto-generated catch block + e1.printStackTrace(); } } @@ -227,7 +217,7 @@ public class MainGUI { try { recordspanel.setLayout(new GridLayout(GuiData.allVictors(fetchData.allLevels().get(index)).size(), 1)); } catch (IOException e1) { - // TODO Auto-generated catch block + e1.printStackTrace(); } recordspanel.setBackground(Color.GRAY); @@ -424,6 +414,7 @@ public class MainGUI { main.add(progress); main.add(filtercompleted); main.add(show); + main.add(settings); main.add(elements.infopanel()); main.setVisible(true); } From d5cc42a29f6336a6da11170d0269b348d58445e8 Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 8 Mar 2024 22:42:54 +0100 Subject: [PATCH 2/4] minor changes --- src/data/GuiData.java | 4 +--- src/gui/MainGUI.java | 9 +++++++-- src/gui/SettingsGui.java | 5 +++++ 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/gui/SettingsGui.java diff --git a/src/data/GuiData.java b/src/data/GuiData.java index 5fc9964..e485b29 100644 --- a/src/data/GuiData.java +++ b/src/data/GuiData.java @@ -71,9 +71,7 @@ public class GuiData { String jsonstring; localLength = filelengthindex.length; - - System.out.println(filelengthindex.length); - + for(int i = 0; i < filelengthindex.length; i++) { jsonstring = FileUtils.readFileToString(new File("C:\\ExtremeDemonList\\levels\\" + data.allLevels().get(i) + ".json"), StandardCharsets.UTF_8); diff --git a/src/gui/MainGUI.java b/src/gui/MainGUI.java index 69662c4..7617561 100644 --- a/src/gui/MainGUI.java +++ b/src/gui/MainGUI.java @@ -67,6 +67,8 @@ public class MainGUI { public JComboBox show = new JComboBox(showing); private FetchData fetch = new FetchData(); private Elements elements = new Elements(); + + private int completedcount = 0; public void build() throws IOException { GuiData data = new GuiData(); @@ -82,7 +84,7 @@ public class MainGUI { level.setBounds(10, 10, 200, 30); level.setFont(level.getFont().deriveFont(15f)); - filtercompleted.setBounds(720, 15, 200, 30); + filtercompleted.setBounds(710, 15, 200, 30); progress.setBounds(200, 300, 500, 30); progress.setStringPainted(true); @@ -191,6 +193,7 @@ public class MainGUI { contents.setBackground(Color.decode("#cbffbf")); uncompleted.setVisible(true); completed.setVisible(false); + completedcount++; } contents.addMouseListener(new MouseListener() { @@ -212,6 +215,7 @@ public class MainGUI { qualify.setText("Qualifikation: " + data.getQualification().get(index) + "%"); level.setVerticalAlignment(SwingConstants.CENTER); + FetchData fetchData = new FetchData(); try { @@ -235,7 +239,6 @@ public class MainGUI { recordspanel.setLayout(new GridLayout(victors.size(), 1)); for(String victor : victors) { - System.out.println(victor); JPanel contents = new JPanel(); contents.setPreferredSize(new Dimension(165, 50)); contents.setLayout(null); @@ -284,6 +287,8 @@ public class MainGUI { rank.setBounds(10, 10, 40, 30); rank.setName(i + ""); + filtercompleted.setText("nach Geschafft filtern (" + completedcount + ")"); + show.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { diff --git a/src/gui/SettingsGui.java b/src/gui/SettingsGui.java new file mode 100644 index 0000000..aba6a12 --- /dev/null +++ b/src/gui/SettingsGui.java @@ -0,0 +1,5 @@ +package gui; + +public class SettingsGui { + +} From a953d838a4085a62143c7d39802b411b5499bc5c Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:57:14 +0100 Subject: [PATCH 3/4] Update maven.yml --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5f558db..6e1df36 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,7 +1,7 @@ on: push: branches: - - main + - release pull_request: branches: - main From c8dabd9c7b8241b18dee9f181cb5dce6c9e1999f Mon Sep 17 00:00:00 2001 From: potzplitz <127513690+potzplitz@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:59:41 +0100 Subject: [PATCH 4/4] added settings --- src/gui/MainGUI.java | 16 ++++++++++--- src/gui/SettingsGui.java | 17 ++++++++++++++ src/settingsfunctions/DeleteDatabase.java | 28 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/settingsfunctions/DeleteDatabase.java diff --git a/src/gui/MainGUI.java b/src/gui/MainGUI.java index 7617561..de9b6f3 100644 --- a/src/gui/MainGUI.java +++ b/src/gui/MainGUI.java @@ -231,8 +231,7 @@ public class MainGUI { recordspanel.removeAll(); try { - // Instanz der FetchData-Klasse erstellen - ArrayList victors = GuiData.allVictors(fetchData.allLevels().get(index)); // Methode allVictors aufrufen + ArrayList victors = GuiData.allVictors(fetchData.allLevels().get(index)); victorcount.setText("Anzahl Victors: " + victors.size()); @@ -374,7 +373,7 @@ public class MainGUI { scroll.revalidate(); } } else if (e.getStateChange() == ItemEvent.DESELECTED) { - levelpanel.add(contents, 0); // Füge das Element am Anfang hinzu + levelpanel.add(contents, 0); } levelpanel.repaint(); levelpanel.revalidate(); @@ -397,6 +396,17 @@ public class MainGUI { } }); thread.start(); + + settings.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + SettingsGui gui = new SettingsGui(); + gui.showSettings(); + + } + + }); elements.infopanel().add(copyid); elements.infopanel().add(level, SwingConstants.CENTER); diff --git a/src/gui/SettingsGui.java b/src/gui/SettingsGui.java index aba6a12..f54a521 100644 --- a/src/gui/SettingsGui.java +++ b/src/gui/SettingsGui.java @@ -1,5 +1,22 @@ package gui; +import java.awt.Button; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JFrame; + +import settingsfunctions.DeleteDatabase; + public class SettingsGui { + + public void showSettings() { + JFrame settings = new JFrame("Einstellungen"); + settings.setLayout(null); + settings.setResizable(false); + settings.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + settings.setSize(500, 500); + settings.setVisible(true); + } } diff --git a/src/settingsfunctions/DeleteDatabase.java b/src/settingsfunctions/DeleteDatabase.java new file mode 100644 index 0000000..b66b008 --- /dev/null +++ b/src/settingsfunctions/DeleteDatabase.java @@ -0,0 +1,28 @@ +package settingsfunctions; + +import java.io.File; + +public class DeleteDatabase { + + private void deleter(String database) { + File filelength = new File("C:\\ExtremeDemonList\\" + database); + File[] filelengthindex = filelength.listFiles(); + for(File file : filelengthindex) { + file.delete(); + } + } + + public void deleteCompleted() { + deleter("completed"); + } + + public void deleteUncompleted() { + deleter("levels"); + } + + public void deleteAll() { + deleteCompleted(); + deleteUncompleted(); + } + +}