diff --git a/src/main/java/xyz/thastertyn/App.java b/src/main/java/xyz/thastertyn/App.java index a7ec750..e0f106e 100644 --- a/src/main/java/xyz/thastertyn/App.java +++ b/src/main/java/xyz/thastertyn/App.java @@ -1,6 +1,10 @@ package xyz.thastertyn; -import xyz.thastertyn.Display.MainWindow; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.plaf.FontUIResource; + +import xyz.thastertyn.UserInterface.MainWindow; /** * Hello world! diff --git a/src/main/java/xyz/thastertyn/Display/Content/Jidelna.java b/src/main/java/xyz/thastertyn/Display/Content/Jidelna.java deleted file mode 100644 index 7b4156b..0000000 --- a/src/main/java/xyz/thastertyn/Display/Content/Jidelna.java +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.thastertyn.Display.Content; - -public class Jidelna { - -} diff --git a/src/main/java/xyz/thastertyn/Display/Content/Znamky.java b/src/main/java/xyz/thastertyn/Display/Content/Znamky.java deleted file mode 100644 index 82420b1..0000000 --- a/src/main/java/xyz/thastertyn/Display/Content/Znamky.java +++ /dev/null @@ -1,168 +0,0 @@ -package xyz.thastertyn.Display.Content; - -import java.io.IOException; -import java.util.ArrayList; - -import com.googlecode.lanterna.TextColor; -import com.googlecode.lanterna.graphics.SimpleTheme; -import com.googlecode.lanterna.gui2.Direction; -import com.googlecode.lanterna.gui2.GridLayout; -import com.googlecode.lanterna.gui2.Label; -import com.googlecode.lanterna.gui2.LinearLayout; -import com.googlecode.lanterna.gui2.Panel; -import com.googlecode.lanterna.gui2.WindowBasedTextGUI; - -import xyz.thastertyn.Display.Dialogs.OptionsDialog; -import xyz.thastertyn.Tuples.Pair; - -public class Znamky extends JecnaContent { - - private Panel mainPanel = new Panel() - .setLayoutManager(new GridLayout(3)); - - private Label borderLabel = new Label("Znamky"); - private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky(); - - private boolean hasStarted = false; - - @Override - public void download() - { - try{ - znamky.downloadZnamky(); - - Panel predmetyPanel = new Panel() - .setLayoutManager(new LinearLayout(Direction.VERTICAL)) - .setLayoutData(GridLayout.createLayoutData( - GridLayout.Alignment.BEGINNING, - GridLayout.Alignment.BEGINNING, - false, - false)); - - Panel znamkyPanel = new Panel() - .setLayoutManager(new LinearLayout(Direction.VERTICAL)) - .setLayoutData(GridLayout.createLayoutData( - GridLayout.Alignment.BEGINNING, - GridLayout.Alignment.BEGINNING, - false, - false)); - - Panel vyslednaZnamkaPanel = new Panel(). - setLayoutManager(new LinearLayout(Direction.VERTICAL)) - .setLayoutData(GridLayout.createLayoutData( - GridLayout.Alignment.END, - GridLayout.Alignment.BEGINNING, - true, - false)); - - ArrayList>,Double>>> grades = znamky.getGrades(); - - TextColor.RGB vyborny = new TextColor.RGB(85,212,0); - TextColor.RGB chvalitebny = new TextColor.RGB(196,224,80); - TextColor.RGB dobry = new TextColor.RGB(255,213,42); - TextColor.RGB dostatecny = new TextColor.RGB(255,102,0); - TextColor.RGB nedostatecny = new TextColor.RGB(255,48,48); - - for(Pair>,Double>> predmet : grades) - { - - Panel jednotliveZnamky = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); - - if(predmet.getValue1().getValue0().isEmpty()) - { - jednotliveZnamky.addComponent(new Label("")); - } - - for(Pair znamka : predmet.getValue1().getValue0()) - { - Label znamkaLabel = new Label(znamka.getValue0() + ""); - switch(znamka.getValue0()) - { - case -1: - znamkaLabel.setText("N"); - znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.WHITE, TextColor.ANSI.BLACK)); - break; - case 1: - znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, vyborny)); - break; - case 2: - znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, chvalitebny)); - break; - case 3: - znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dobry)); - break; - case 4: - znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dostatecny)); - break; - case 5: - znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny)); - break; - } - - jednotliveZnamky.addComponent(znamkaLabel); - } - - double prumer = predmet.getValue1().getValue1(); - - Label vysl = new Label(String.format("%.2f", prumer)); - - if(prumer >= 1 && prumer < 1.5) - { - vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, vyborny)); - }else if(prumer >= 1.5 && prumer < 2.5) - { - vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, chvalitebny)); - - }else if(prumer >= 2.5 && prumer < 3.5) - { - vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dobry)); - - }else if(prumer >= 3.5 && prumer < 4.5) - { - vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, dostatecny)); - }else if(prumer >= 4.5) - { - vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny)); - } - - znamkyPanel.addComponent(jednotliveZnamky); - predmetyPanel.addComponent(new Label(predmet.getValue0())); - vyslednaZnamkaPanel.addComponent(vysl); - } - - mainPanel.addComponent(predmetyPanel); - mainPanel.addComponent(znamkyPanel); - mainPanel.addComponent(vyslednaZnamkaPanel); - - hasStarted = true; - }catch(IOException e) - { - mainPanel.addComponent(new Label("An error has occured")); - } - } - - @Override - public Panel getPanel() - { - return mainPanel; - } - - @Override - public boolean hasStarted() - { - return hasStarted; - } - - @Override - public Label getLabel() - { - return borderLabel; - } - - @Override - public void showOptions(WindowBasedTextGUI textGUI) { - OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1()); - - d.showDialog(textGUI); - } -} diff --git a/src/main/java/xyz/thastertyn/Display/Dialogs/CredentialsInput.java b/src/main/java/xyz/thastertyn/Login/CredentialsInput.java similarity index 99% rename from src/main/java/xyz/thastertyn/Display/Dialogs/CredentialsInput.java rename to src/main/java/xyz/thastertyn/Login/CredentialsInput.java index d7837fc..6b7a078 100644 --- a/src/main/java/xyz/thastertyn/Display/Dialogs/CredentialsInput.java +++ b/src/main/java/xyz/thastertyn/Login/CredentialsInput.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display.Dialogs; +package xyz.thastertyn.Login; import java.util.Arrays; diff --git a/src/main/java/xyz/thastertyn/Scrape/Login.java b/src/main/java/xyz/thastertyn/Login/Login.java similarity index 98% rename from src/main/java/xyz/thastertyn/Scrape/Login.java rename to src/main/java/xyz/thastertyn/Login/Login.java index f3b5b91..b281ecf 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Login.java +++ b/src/main/java/xyz/thastertyn/Login/Login.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Scrape; +package xyz.thastertyn.Login; import java.io.IOException; import java.net.UnknownHostException; @@ -11,6 +11,8 @@ import org.jsoup.Jsoup; import org.jsoup.Connection.Method; import org.jsoup.nodes.Document; +import xyz.thastertyn.Scrape.Downloader; + public class Login { private String Jsessionid = null; diff --git a/src/main/java/xyz/thastertyn/Display/LoginController.java b/src/main/java/xyz/thastertyn/Login/LoginController.java similarity index 95% rename from src/main/java/xyz/thastertyn/Display/LoginController.java rename to src/main/java/xyz/thastertyn/Login/LoginController.java index 375f972..5440b5e 100644 --- a/src/main/java/xyz/thastertyn/Display/LoginController.java +++ b/src/main/java/xyz/thastertyn/Login/LoginController.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display; +package xyz.thastertyn.Login; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -15,14 +15,13 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; -import xyz.thastertyn.Display.Dialogs.CredentialsInput; import xyz.thastertyn.Tuples.Triplet; public class LoginController { private WindowBasedTextGUI textGUI; - private xyz.thastertyn.Display.Dialogs.CredentialsInput dialog; - private xyz.thastertyn.Scrape.Login login = new xyz.thastertyn.Scrape.Login(); + private xyz.thastertyn.Login.CredentialsInput dialog; + private xyz.thastertyn.Login.Login login = new xyz.thastertyn.Login.Login(); public LoginController(WindowBasedTextGUI textGUI) { diff --git a/src/main/java/xyz/thastertyn/Scrape/BaseJecnaParser.java b/src/main/java/xyz/thastertyn/Scrape/BaseJecnaParser.java deleted file mode 100644 index 8c89ef4..0000000 --- a/src/main/java/xyz/thastertyn/Scrape/BaseJecnaParser.java +++ /dev/null @@ -1,9 +0,0 @@ -package xyz.thastertyn.Scrape; - -import xyz.thastertyn.Types.BaseType; - -public abstract class BaseJecnaParser { - - public abstract void download(); - public abstract BaseType getData(); -} diff --git a/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java b/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java index 04ae7b9..d038091 100644 --- a/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java @@ -16,11 +16,11 @@ public class OmluvnyList { public void downloadOmluvnyList() throws UnknownHostException, IOException { - Document doc = Downloader.download("https://www.spsejecna.cz/absence/student").get(); + Document omluvnyListDokumentHTML = Downloader.download("https://www.spsejecna.cz/absence/student").get(); - Elements omluv = doc.select("table.absence-list").select("tr"); + Elements omluvneListy = omluvnyListDokumentHTML.select("table.absence-list").select("tr"); - for(Element e : omluv) + for(Element e : omluvneListy) { String date = e.child(0).text(); String text = e.child(1).text(); diff --git a/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java b/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java index 7f3d63f..f7e5711 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java @@ -2,9 +2,11 @@ package xyz.thastertyn.Scrape; import java.io.IOException; import java.net.UnknownHostException; +import java.util.Arrays; import java.util.HashSet; import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; import org.jsoup.select.Elements; /** @@ -13,8 +15,40 @@ import org.jsoup.select.Elements; public class Rozvrh { private String[][] rozvrh = new String[5][10]; - int pos = 0; + + /** + * Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy + * se kterou da pracovat + * @param Jsessionid ze stranek + * @throws UnknownHostException kdyz neni pripojeni k internetu + * @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom + */ + public void downloadRozvrh() throws UnknownHostException, IOException + { + Document rozvrhDokumentHTML = Downloader.download("https://www.spsejecna.cz/timetable/class").get(); + Elements[] radkyRozvrhuHTML = rozvrhDokumentHTML + .select("table.timetable") + .select("tr") + .stream() + .map(Element::children) + .toArray(Elements[]::new); + + for(int i = 1; i < 6; i++) + { + for(int j = 1; j < 11; j++) + { + String predmet = radkyRozvrhuHTML[i].get(j).select("span.subject").text(); + + // Predmety jako CEL jsou trikrat, staci ale jen jednou + String[] split = predmet.split(" "); + HashSet set = new HashSet<>(Arrays.asList(split)); + String pr = String.join("/", set); + + rozvrh[i-1][j-1] = pr; + } + } + } public void setPredmet(String pr, int d, int i) { @@ -42,61 +76,4 @@ public class Rozvrh { return s; } - - /** - * Stahne rozvrh z www.spsejecna.cz a dale ho zpracuje do formy - * se kterou da pracovat - * @param Jsessionid ze stranek - * @throws UnknownHostException kdyz neni pripojeni k internetu - * @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom - */ - public void downloadRozvrh() throws UnknownHostException, IOException - { - Document rozvrhDoc = Downloader.download("https://www.spsejecna.cz" + "/timetable/class").get(); - - Elements rozvrhTable = rozvrhDoc.select("table.timetable").select("tr"); - Elements[] rozvrhDny = new Elements[rozvrhTable.size()]; - - for(int i = 0; i < rozvrhTable.size(); i++) - { - rozvrhDny[i] = rozvrhTable.get(i).children(); - } - - for(int i = 1; i < 6; i++) - { - for(int j = 1; j < 11; j++) - { - String predmet = rozvrhDny[i].get(j).select("span.subject").text().replaceAll(" ", "/"); - - // Predmety jako CEL jsou trikrat, staci ale jen jednou - HashSet set = new HashSet<>(); - String[] split = predmet.split("/"); - - for(String s : split) - { - set.add(s); - } - - String pr = ""; - - if(set.size() > 1) - { - for(String s : set) - { - pr += s + "/"; - } - pr = pr.substring(0, pr.length() - 1); - }else{ - for(String s : set) { pr = s; break; } - } - - if(pr.isBlank()) - { - pr = "-"; - } - - rozvrh[i-1][j-1] = pr; - } - } - } } diff --git a/src/main/java/xyz/thastertyn/Scrape/Znamky.java b/src/main/java/xyz/thastertyn/Scrape/Znamky.java index 20b3ba5..8f91f30 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Znamky.java +++ b/src/main/java/xyz/thastertyn/Scrape/Znamky.java @@ -3,7 +3,6 @@ package xyz.thastertyn.Scrape; import java.io.IOException; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jsoup.nodes.Document; @@ -13,133 +12,90 @@ import org.jsoup.select.Elements; import xyz.thastertyn.Tuples.Pair; import xyz.thastertyn.Types.Option; import xyz.thastertyn.Types.Options; +import xyz.thastertyn.Types.Predmet; +import xyz.thastertyn.Types.Znamka; public class Znamky { private boolean wasDownloaded; // schoolYear, schoolYearId - private ArrayList>,Double>>> grades = new ArrayList<>(); + private ArrayList predmety = new ArrayList<>(); - // Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti + // int znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti private Options schoolYearOptions = new Options("Skolni R."); private Options schoolHalfYearOptions = new Options("Pololeti"); public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException { //String url = String.format("https://www.spsejecna.cz/score/student?schoolYearId=%d&schoolYearHalfId=%d", schoolYearId, schoolYearHalfId); - Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student").get(); + Document znamkyDokumentHTML = Downloader.download("https://www.spsejecna.cz/score/student").get(); - Elements rows = znamkyDoc.select("table.score").select("tr"); + // Predmety ulozene v + Elements[] radkyPredmetuHTML = znamkyDokumentHTML + .select("table.score") + .select("tr") + .stream() + .map(Element::children) + .toArray(Elements[]::new); - Elements[] rows_split = new Elements[rows.size()]; + int subjectIndex = 0; - for (int i = 0; i < rows.size(); i++) + for(int i = 1; i < radkyPredmetuHTML.length; i++) { - rows_split[i] = rows.get(i).children(); - } + String plnyNazevPredmetu = radkyPredmetuHTML[i].get(0).text(); - int subj = 0; + String jmenoPredmetu = Pattern + .compile("\\((.*?)\\)") + .matcher(plnyNazevPredmetu) + .results() + .findFirst() + .map(m -> m.group(1)) + .orElse(plnyNazevPredmetu); - for(int i = 1; i < rows_split.length; i++) - { - String predmetFull = rows_split[i].get(0).text(); + predmety.add(new Predmet(jmenoPredmetu)); - Matcher matcher = Pattern.compile("\\((.*)\\)").matcher(predmetFull); - - String predmet = matcher.find() ? matcher.group(1) : predmetFull; - addSubject(predmet); - - for(Element znamkaElement : rows_split[i].get(1).select("a.score")) + for(Element znamkaElement : radkyPredmetuHTML[i].get(1).select("a.score")) { - if(znamkaElement == null) - { - break; - } - - String zn = znamkaElement.select("span.value").text(); int znamka; - if(zn.toLowerCase().equals("n") || zn.toLowerCase().equals("u")) - { - znamka = -1; - }else{ - znamka = Integer.parseInt(znamkaElement.select("span.value").text()); - } + boolean jeMala = false; + + String textZnamky = znamkaElement.select("span.value").text(); + + znamka = textZnamky.matches("\\d") ? + Integer.parseInt(textZnamky) : + -1; // Nejspis se jedna o N (Nehodnocen) // Mala znamka se bude pocitat jako polovicni vaha - if(znamkaElement.hasClass("scoreSmall")) - { - addGrade(subj, predmet, znamka, 0.5); - }else{ - addGrade(subj, predmet, znamka, 1); - } + jeMala = znamkaElement.hasClass("scoreSmall"); + + predmety.get(subjectIndex).addZnamka(new Znamka(znamka, jeMala, textZnamky)); } - grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0())); - subj++; + subjectIndex++; } - Element optionsPanel = znamkyDoc.selectFirst("form.listConfigure"); + Element optionsPanel = znamkyDokumentHTML.selectFirst("form.listConfigure"); - Elements schoolYear = optionsPanel.select("select[id=schoolYearId]").select("option"); - Elements schoolYearId = optionsPanel.select("select[id=schoolYearHalfId]").select("option"); + Elements skolniRoky = optionsPanel.select("select[id=schoolYearId]").select("option"); + Elements pololeti = optionsPanel.select("select[id=schoolYearHalfId]").select("option"); - for(Element e : schoolYear) + for(Element e : skolniRoky) { - this.schoolYearOptions.addOption(new Option(e.text(), e.attr("value"))); + schoolYearOptions.addOption(new Option(e.text(), e.attr("value"))); } - for(Element e : schoolYearId) + for(Element e : pololeti) { - this.schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value"))); + schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value"))); } wasDownloaded = true; } - - private void addGrade(int index, String subject, int grade, double weight) - { - Pair znamka = new Pair<>(grade, weight); - - grades.get(index).getValue1().getValue0().add(znamka); - } - - private void addSubject(String subject) - { - Pair>, Double> p = new Pair<>(new ArrayList>(), 0.0); - - grades.add(new Pair<>(subject, p)); - } - - private double getAverage(ArrayList> a) - { - try{ - double divident = 0; - double divisor = 0; - for(Pair p : a) - { - if(p.getValue0() == -1) - { - continue; - } - - divident += p.getValue0() * p.getValue1(); - divisor += p.getValue1(); - } - - double prumer = (double) divident / divisor; - return (double) Math.round(prumer * 100) / 100; - - }catch(ArithmeticException e) - { - return 0; - } - } - - public ArrayList>,Double>>> getGrades() + public ArrayList getPredmety() { - return grades; + return predmety; } public Pair getOptions() @@ -150,17 +106,8 @@ public class Znamky { @Override public String toString() { - if(wasDownloaded) - { - String s = ""; - - for(Pair>,Double>> p : grades) - { - s += p.getValue0() + " | " + p.getValue1().getValue0().toString() + " { " + p.getValue1().getValue1() + " } "; - } - return s; - }else{ - return "Nothing was downloaded"; - } + return (wasDownloaded) ? + "All up and ready for use" : + "Nothing downloaded yet"; } } \ No newline at end of file diff --git a/src/main/java/xyz/thastertyn/Types/BaseType.java b/src/main/java/xyz/thastertyn/Types/BaseType.java deleted file mode 100644 index 26a87fe..0000000 --- a/src/main/java/xyz/thastertyn/Types/BaseType.java +++ /dev/null @@ -1,5 +0,0 @@ -package xyz.thastertyn.Types; - -public abstract class BaseType { - -} diff --git a/src/main/java/xyz/thastertyn/Types/Predmet.java b/src/main/java/xyz/thastertyn/Types/Predmet.java new file mode 100644 index 0000000..7b75b16 --- /dev/null +++ b/src/main/java/xyz/thastertyn/Types/Predmet.java @@ -0,0 +1,56 @@ +package xyz.thastertyn.Types; + +import java.util.ArrayList; + +public class Predmet { + + private ArrayList znamky = new ArrayList<>(); + private String jmenoPredmetu = ""; + + private int vyslednaZnamka = 0; + + public Predmet(String jmenoPredmetu) + { + this.jmenoPredmetu = jmenoPredmetu; + } + + public void addZnamka(Znamka novaZnamka) + { + znamky.add(novaZnamka); + } + + public double getPrumer() + { + if(vyslednaZnamka != 0) + { + return vyslednaZnamka; + } + + if(znamky.isEmpty()) + { + return 0; + } + + int celkem = znamky + .stream() + .mapToInt((z) -> z.getZnamka() * z.getVaha()) + .sum(); + + int vahy = znamky + .stream() + .mapToInt((z) -> z.getVaha()) + .sum(); + + return (double) celkem / vahy; + } + + public String getJmenoPredmetu() + { + return jmenoPredmetu; + } + + public ArrayList getZnamky() + { + return znamky; + } +} diff --git a/src/main/java/xyz/thastertyn/Types/Znamka.java b/src/main/java/xyz/thastertyn/Types/Znamka.java index a92955f..eb83aaa 100644 --- a/src/main/java/xyz/thastertyn/Types/Znamka.java +++ b/src/main/java/xyz/thastertyn/Types/Znamka.java @@ -3,17 +3,28 @@ package xyz.thastertyn.Types; public class Znamka { private int znamka; - private boolean malaZnamka; - private String text; - private String datum; + private String znamkaJakoText; + private int vaha; - - public Znamka(int znamka, boolean malaZnamka, String text, String datum) + public Znamka(int znamka, boolean malaZnamka, String znamkaJakoText/*, String text, String datum*/) { this.znamka = znamka; - this.malaZnamka = malaZnamka; - this.datum = datum; - this.text = text; + this.vaha = (malaZnamka) ? 1 : 2; + this.znamkaJakoText = znamkaJakoText; } -} + public int getZnamka() + { + return znamka; + } + + public int getVaha() + { + return vaha; + } + + public String getText() + { + return znamkaJakoText; + } +} \ No newline at end of file diff --git a/src/main/java/xyz/thastertyn/Display/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java similarity index 92% rename from src/main/java/xyz/thastertyn/Display/Content/JecnaContent.java rename to src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java index ab6b109..ee84643 100644 --- a/src/main/java/xyz/thastertyn/Display/Content/JecnaContent.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display.Content; +package xyz.thastertyn.UserInterface.Content; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.dialogs.MessageDialog; diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Jidelna.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Jidelna.java new file mode 100644 index 0000000..ba7755f --- /dev/null +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Jidelna.java @@ -0,0 +1,5 @@ +package xyz.thastertyn.UserInterface.Content; + +public class Jidelna { + +} diff --git a/src/main/java/xyz/thastertyn/Display/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java similarity index 96% rename from src/main/java/xyz/thastertyn/Display/Content/OmluvnyList.java rename to src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java index 52f9de3..55489ac 100644 --- a/src/main/java/xyz/thastertyn/Display/Content/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display.Content; +package xyz.thastertyn.UserInterface.Content; import java.io.IOException; import java.net.UnknownHostException; diff --git a/src/main/java/xyz/thastertyn/Display/Content/Rozvrh.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java similarity index 97% rename from src/main/java/xyz/thastertyn/Display/Content/Rozvrh.java rename to src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java index 91c1406..27b6a7d 100644 --- a/src/main/java/xyz/thastertyn/Display/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display.Content; +package xyz.thastertyn.UserInterface.Content; import java.io.IOException; import java.net.UnknownHostException; diff --git a/src/main/java/xyz/thastertyn/Display/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java similarity index 96% rename from src/main/java/xyz/thastertyn/Display/Content/Sdeleni.java rename to src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java index 039a57e..ea6bbe0 100644 --- a/src/main/java/xyz/thastertyn/Display/Content/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display.Content; +package xyz.thastertyn.UserInterface.Content; import java.io.IOException; diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java new file mode 100644 index 0000000..6cab6fc --- /dev/null +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java @@ -0,0 +1,144 @@ +package xyz.thastertyn.UserInterface.Content; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +import com.googlecode.lanterna.TextColor; +import com.googlecode.lanterna.TextColor.ANSI; +import com.googlecode.lanterna.graphics.SimpleTheme; +import com.googlecode.lanterna.gui2.Direction; +import com.googlecode.lanterna.gui2.GridLayout; +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.LayoutData; +import com.googlecode.lanterna.gui2.LinearLayout; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; + +import xyz.thastertyn.Types.Predmet; +import xyz.thastertyn.Types.Znamka; +import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog; + +public class Znamky extends JecnaContent { + + private final TextColor.RGB VYBORNY = new TextColor.RGB(85,212,0); + private final TextColor.RGB CHVALITEBNY = new TextColor.RGB(196,224,80); + private final TextColor.RGB DOBRY = new TextColor.RGB(255,213,42); + private final TextColor.RGB DOSTATECNY = new TextColor.RGB(255,102,0); + private final TextColor.RGB NEDOSTATECNY = new TextColor.RGB(255,48,48); + private final TextColor.RGB NEHODNOCEN = new TextColor.RGB(0,0,0); + + private final LayoutData ALIGN_LEFT = GridLayout.createLayoutData( + GridLayout.Alignment.BEGINNING, + GridLayout.Alignment.BEGINNING, + false, + false); + + private final LayoutData ALIGN_RIGHT = GridLayout.createLayoutData( + GridLayout.Alignment.END, + GridLayout.Alignment.BEGINNING, + true, + false); + + private Panel mainPanel = new Panel() + .setLayoutManager(new GridLayout(3)); + + private Label borderLabel = new Label("Znamky"); + private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky(); + + private boolean hasStarted = false; + + @Override + public void download() + { + try{ + znamky.downloadZnamky(); + + ArrayList predmety = znamky.getPredmety(); + + HashMap barvy = new HashMap<>(); + barvy.put(1, new SimpleTheme(ANSI.BLACK, VYBORNY)); + barvy.put(2, new SimpleTheme(ANSI.BLACK, CHVALITEBNY)); + barvy.put(3, new SimpleTheme(ANSI.BLACK, DOBRY)); + barvy.put(4, new SimpleTheme(ANSI.BLACK, DOSTATECNY)); + barvy.put(5, new SimpleTheme(ANSI.BLACK, NEDOSTATECNY)); + barvy.put(-1, new SimpleTheme(ANSI.WHITE, NEHODNOCEN)); + + // Sloupec pro jmena predmetu + Panel jmemaPredmetu = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(ALIGN_LEFT) + .addTo(mainPanel); + + // Sloupec pro znamky z predmetu + Panel znamky = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(ALIGN_LEFT) + .addTo(mainPanel); + + // Sloupec pro vyslednou znamku + Panel vysledneZnamky = new Panel() + .setLayoutManager(new LinearLayout(Direction.VERTICAL)) + .setLayoutData(ALIGN_RIGHT) + .addTo(mainPanel); + + for(Predmet predmet : predmety) + { + Panel jednotliveZnamky = new Panel() + .setLayoutManager(new LinearLayout(Direction.HORIZONTAL)) + .addTo(znamky); + + if(predmet.getZnamky().isEmpty()) + { + jednotliveZnamky.addComponent(new Label("")); + } + + for(Znamka znamka : predmet.getZnamky()) + { + Label znamkaLabel = new Label(znamka.getText()); + znamkaLabel.setTheme(barvy.get(znamka.getZnamka())); + jednotliveZnamky.addComponent(znamkaLabel); + } + + double prumer = predmet.getPrumer(); + + Label vysl = new Label(String.format("%.2f", prumer)); + + vysl.setTheme(barvy.get((int) Math.round(prumer))); + + jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu())); + vysledneZnamky.addComponent(vysl); + } + + hasStarted = true; + }catch(IOException e) + { + mainPanel.addComponent(new Label("An error has occured")); + } + } + + @Override + public Panel getPanel() + { + return mainPanel; + } + + @Override + public boolean hasStarted() + { + return hasStarted; + } + + @Override + public Label getLabel() + { + return borderLabel; + } + + @Override + public void showOptions(WindowBasedTextGUI textGUI) { + OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1()); + + d.showDialog(textGUI); + } +} \ No newline at end of file diff --git a/src/main/java/xyz/thastertyn/Display/Dialogs/OptionsDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java similarity index 97% rename from src/main/java/xyz/thastertyn/Display/Dialogs/OptionsDialog.java rename to src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java index 62a09b5..6cce016 100644 --- a/src/main/java/xyz/thastertyn/Display/Dialogs/OptionsDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display.Dialogs; +package xyz.thastertyn.UserInterface.Dialogs; import java.util.Arrays; diff --git a/src/main/java/xyz/thastertyn/Display/MainWindow.java b/src/main/java/xyz/thastertyn/UserInterface/MainWindow.java similarity index 95% rename from src/main/java/xyz/thastertyn/Display/MainWindow.java rename to src/main/java/xyz/thastertyn/UserInterface/MainWindow.java index 371cc3e..6778ccd 100644 --- a/src/main/java/xyz/thastertyn/Display/MainWindow.java +++ b/src/main/java/xyz/thastertyn/UserInterface/MainWindow.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display; +package xyz.thastertyn.UserInterface; import java.io.IOException; import java.util.Arrays; @@ -18,6 +18,8 @@ import com.googlecode.lanterna.screen.TerminalScreen; import com.googlecode.lanterna.terminal.DefaultTerminalFactory; import com.googlecode.lanterna.terminal.Terminal; +import xyz.thastertyn.Login.LoginController; + public class MainWindow { private Terminal terminal; diff --git a/src/main/java/xyz/thastertyn/Display/WindowSwitchListener.java b/src/main/java/xyz/thastertyn/UserInterface/WindowSwitchListener.java similarity index 91% rename from src/main/java/xyz/thastertyn/Display/WindowSwitchListener.java rename to src/main/java/xyz/thastertyn/UserInterface/WindowSwitchListener.java index 9a33eee..e708513 100644 --- a/src/main/java/xyz/thastertyn/Display/WindowSwitchListener.java +++ b/src/main/java/xyz/thastertyn/UserInterface/WindowSwitchListener.java @@ -1,4 +1,4 @@ -package xyz.thastertyn.Display; +package xyz.thastertyn.UserInterface; import java.util.concurrent.atomic.AtomicBoolean; @@ -17,11 +17,11 @@ import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyType; -import xyz.thastertyn.Display.Content.JecnaContent; -import xyz.thastertyn.Display.Content.OmluvnyList; -import xyz.thastertyn.Display.Content.Rozvrh; -import xyz.thastertyn.Display.Content.Sdeleni; -import xyz.thastertyn.Display.Content.Znamky; +import xyz.thastertyn.UserInterface.Content.JecnaContent; +import xyz.thastertyn.UserInterface.Content.OmluvnyList; +import xyz.thastertyn.UserInterface.Content.Rozvrh; +import xyz.thastertyn.UserInterface.Content.Sdeleni; +import xyz.thastertyn.UserInterface.Content.Znamky; public class WindowSwitchListener implements WindowListener {