gui
This commit is contained in:
parent
050c0233ad
commit
9bfe419ba3
9 changed files with 237 additions and 41 deletions
|
@ -9,8 +9,12 @@ import java.util.ArrayList;
|
|||
public class FetchData {
|
||||
|
||||
private static ArrayList<String> levels = new ArrayList<String>();
|
||||
private static int lock = 0;
|
||||
|
||||
public void getGithubString() throws IOException {
|
||||
|
||||
if(lock == 0) {
|
||||
lock = 1;
|
||||
String link = "https://raw.githubusercontent.com/All-Rated-Extreme-Demon-List/AREDL/main/data/_list.json";
|
||||
|
||||
|
||||
|
@ -31,6 +35,7 @@ public class FetchData {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> allLevels() {
|
||||
return levels;
|
||||
|
|
|
@ -14,6 +14,14 @@ import org.json.JSONObject;
|
|||
public class GuiData {
|
||||
|
||||
private ArrayList<String> localLevels = new ArrayList<String>();
|
||||
private ArrayList<String> completed = new ArrayList<String>();
|
||||
private ArrayList<String> id = new ArrayList<String>();
|
||||
|
||||
|
||||
public void setId(ArrayList<String> id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private int localLength;
|
||||
|
||||
public int getLocalLength() {
|
||||
|
@ -23,6 +31,16 @@ public class GuiData {
|
|||
public ArrayList<String> getLocalLevels() {
|
||||
return localLevels;
|
||||
}
|
||||
|
||||
public ArrayList<String> getCompleted() {
|
||||
return completed;
|
||||
}
|
||||
|
||||
public ArrayList<String> getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void IndexLevelName() throws IOException {
|
||||
|
||||
|
@ -38,6 +56,9 @@ public class GuiData {
|
|||
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("\\", "");
|
||||
|
||||
|
@ -45,7 +66,42 @@ public class GuiData {
|
|||
|
||||
localLevels.add(obj.getString("name"));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void IndexLevelID() 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);
|
||||
|
||||
id.add(obj.getInt("id") + "");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ public class ManageFiles {
|
|||
|
||||
fetch.getGithubString();
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < fetch.allLevels().size(); i++) {
|
||||
|
||||
File file = new File("C:\\ExtremeDemonList\\levels\\" + fetch.allLevels().get(i) + ".json");
|
||||
|
@ -39,14 +41,11 @@ public class ManageFiles {
|
|||
}
|
||||
|
||||
if(missing > 0) {
|
||||
|
||||
gui.show(missinglevels, missing);
|
||||
} else {
|
||||
MainGUI gui = new MainGUI();
|
||||
gui.build();
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> missingLevels() { // missinglevels wird zurückgegeben
|
||||
return missinglevels;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,16 @@ public class CreateFileStructure {
|
|||
public void create() {
|
||||
|
||||
File file = new File("C:\\ExtremeDemonList\\levels");
|
||||
File file2 = new File("C:\\ExtremeDemonList\\completed");
|
||||
|
||||
if(!file.isDirectory()) {
|
||||
System.out.println("nein");
|
||||
file.mkdirs();
|
||||
}
|
||||
|
||||
if(!file2.isDirectory()) {
|
||||
file2.mkdirs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
31
src/gui/Elements.java
Normal file
31
src/gui/Elements.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package gui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Elements {
|
||||
|
||||
private int lock = 0;
|
||||
|
||||
private JPanel panel = new JPanel();
|
||||
|
||||
public JPanel infopanel() {
|
||||
|
||||
if(lock == 0) {
|
||||
lock = 1;
|
||||
|
||||
System.out.println("sdfadsf");
|
||||
|
||||
|
||||
panel.setBackground(Color.LIGHT_GRAY);
|
||||
panel.setLayout(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return panel;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,22 +1,39 @@
|
|||
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.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.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import data.FetchData;
|
||||
import data.GuiData;
|
||||
|
||||
public class MainGUI {
|
||||
|
@ -29,18 +46,29 @@ public class MainGUI {
|
|||
public JScrollPane scroll = new JScrollPane(levelpanel);
|
||||
public JTextField search = new JTextField();
|
||||
public JLabel levelname;
|
||||
public JLabel level = new JLabel("Liste");
|
||||
public JCheckBox filtercompleted = new JCheckBox("Nach geschaft filtern");
|
||||
public Button copyid = new Button("Level ID kopieren");
|
||||
private FetchData fetch = new FetchData();
|
||||
private Elements elements = new Elements();
|
||||
|
||||
|
||||
public void build() throws IOException {
|
||||
|
||||
GuiData data = new GuiData();
|
||||
data.IndexLevelName();
|
||||
data.IndexLevelID();
|
||||
|
||||
main.setSize(900, 700);
|
||||
main.setLayout(null);
|
||||
main.setResizable(false);
|
||||
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
level.setBounds(10, 10, 200, 30);
|
||||
level.setFont(level.getFont().deriveFont(20f));
|
||||
|
||||
filtercompleted.setBounds(720, 15, 200, 30);
|
||||
|
||||
progress.setBounds(200, 300, 500, 30);
|
||||
progress.setStringPainted(true);
|
||||
progress.setMaximum(data.getLocalLength());
|
||||
|
@ -53,6 +81,7 @@ public class MainGUI {
|
|||
levelpanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
||||
levelpanel.setLayout(new GridLayout(data.getLocalLevels().size(), 1));
|
||||
|
||||
copyid.setBounds(10, 50, 100, 30);
|
||||
|
||||
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||||
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
@ -60,27 +89,102 @@ public class MainGUI {
|
|||
scroll.getVerticalScrollBar().setUnitIncrement(16);
|
||||
scroll.setVisible(false);
|
||||
|
||||
elements.infopanel().setBounds(700, 61, 184, 600);
|
||||
elements.infopanel().setVisible(false);
|
||||
|
||||
search.setBounds(1, 1, 700, 60);
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(int i = 0; i < data.getLocalLevels().size(); i++) {
|
||||
final int index = i;
|
||||
progress.setValue(i + 1);
|
||||
|
||||
currentLevel.setText(data.getLocalLevels().get(i));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel contents = new JPanel();
|
||||
contents.setName(data.getLocalLevels().get(i));
|
||||
contents.setPreferredSize(new Dimension(600, 50));
|
||||
contents.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
|
||||
contents.setLayout(null);
|
||||
|
||||
|
||||
|
||||
JButton completed = new JButton("x");
|
||||
completed.setBounds(640, 17, 17, 17);
|
||||
completed.setMargin(new Insets(0,0,0,0));
|
||||
|
||||
JButton uncompleted = new JButton("\u2713");
|
||||
uncompleted.setBounds(640, 17, 17, 17);
|
||||
uncompleted.setMargin(new Insets(0,0,0,0));
|
||||
|
||||
File file = new File("C:\\ExtremeDemonList\\completed\\" + fetch.allLevels().get(i)+ ".json");
|
||||
|
||||
|
||||
|
||||
completed.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
contents.setBackground(Color.decode("#cbffbf"));
|
||||
|
||||
completed.setVisible(false);
|
||||
uncompleted.setVisible(true);
|
||||
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
uncompleted.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
contents.setBackground(Color.WHITE);
|
||||
|
||||
uncompleted.setVisible(false);
|
||||
completed.setVisible(true);
|
||||
|
||||
file.delete();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if(new File("C:\\ExtremeDemonList\\completed\\" + fetch.allLevels().get(i)+ ".json").exists()) {
|
||||
contents.setBackground(Color.decode("#cbffbf"));
|
||||
uncompleted.setVisible(true);
|
||||
completed.setVisible(false);
|
||||
}
|
||||
|
||||
contents.addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
level.setText(data.getLocalLevels().get(index));
|
||||
level.setVerticalAlignment(SwingConstants.CENTER);
|
||||
|
||||
copyid.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
StringSelection stringSelection = new StringSelection(data.getId().get(index));
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(stringSelection, null);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
|
@ -100,10 +204,9 @@ public class MainGUI {
|
|||
|
||||
levelname = new JLabel();
|
||||
levelname.setText(data.getLocalLevels().get(i));
|
||||
levelname.setBounds(10, 10, 300, 30);
|
||||
levelname.setBounds(290, 10, 300, 30);
|
||||
|
||||
search.addKeyListener(new KeyListener() {
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
if(!contents.getName().toLowerCase().contains(search.getText().toLowerCase())) {
|
||||
|
@ -114,35 +217,44 @@ public class MainGUI {
|
|||
levelpanel.add(contents);
|
||||
levelpanel.repaint();
|
||||
levelpanel.revalidate();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
filtercompleted.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
if (!contents.getBackground().equals(Color.decode("#cbffbf"))) {
|
||||
levelpanel.remove(contents);
|
||||
}
|
||||
} else if (e.getStateChange() == ItemEvent.DESELECTED) {
|
||||
levelpanel.add(contents, 0); // Füge das Element am Anfang hinzu
|
||||
}
|
||||
levelpanel.repaint();
|
||||
levelpanel.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
JLabel rank = new JLabel("#" + (i + 1));
|
||||
rank.setBounds(640, 10, 40, 30);
|
||||
rank.setBounds(10, 10, 40, 30);
|
||||
|
||||
contents.add(levelname);
|
||||
contents.add(rank);
|
||||
contents.add(completed);
|
||||
contents.add(uncompleted);
|
||||
levelpanel.add(contents);
|
||||
|
||||
}
|
||||
scroll.setVisible(true);
|
||||
elements.infopanel().setVisible(true);
|
||||
progress.setVisible(false);
|
||||
info.setVisible(false);
|
||||
currentLevel.setVisible(false);
|
||||
|
@ -150,7 +262,9 @@ public class MainGUI {
|
|||
|
||||
});
|
||||
thread.start();
|
||||
|
||||
|
||||
elements.infopanel().add(copyid);
|
||||
elements.infopanel().add(level, SwingConstants.CENTER);
|
||||
|
||||
|
||||
main.add(search);
|
||||
|
@ -158,6 +272,8 @@ public class MainGUI {
|
|||
main.add(info);
|
||||
main.add(scroll);
|
||||
main.add(progress);
|
||||
main.add(filtercompleted);
|
||||
main.add(elements.infopanel());
|
||||
main.setVisible(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ public class MissingLevels {
|
|||
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
scroll.setBounds(1, 60, 383, 201);
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < missinglevels.size(); i++) {
|
||||
area.append(missinglevels.get(i) + "\n");
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package gui;
|
||||
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class SearchEngine {
|
||||
|
||||
MainGUI gui = new MainGUI();
|
||||
|
||||
JTextField searchbar = gui.search;
|
||||
|
||||
public void Filter(String query) {
|
||||
System.out.println(query);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,4 +8,5 @@
|
|||
requires java.desktop;
|
||||
requires json;
|
||||
requires org.apache.commons.io;
|
||||
requires java.datatransfer;
|
||||
}
|
Loading…
Reference in a new issue