From 2b70c3a2837dea3965b6d6f1c3892cb96055d761 Mon Sep 17 00:00:00 2001 From: Thastertyn Date: Fri, 28 Apr 2023 20:11:23 +0200 Subject: [PATCH] Reworked JecnaContent, EscapeDialog has a few options, few smaller tweaks --- .../java/xyz/thastertyn/Scrape/Rozvrh.java | 5 -- .../java/xyz/thastertyn/Types/Choice.java | 8 +-- .../java/xyz/thastertyn/Types/Predmet.java | 7 +++ .../UserInterface/Content/JecnaContent.java | 30 +++++++--- .../UserInterface/Content/OmluvnyList.java | 12 ++-- .../UserInterface/Content/Rozvrh.java | 14 ++--- .../UserInterface/Content/Sdeleni.java | 12 ++-- .../UserInterface/Content/Znamky.java | 58 ++++++++----------- .../UserInterface/Dialogs/EscapeDialog.java | 43 ++++++++------ .../UserInterface/Dialogs/OptionsDialog.java | 20 ++----- .../UserInterface/WindowSwitchListener.java | 21 +++---- 11 files changed, 116 insertions(+), 114 deletions(-) diff --git a/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java b/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java index f7e5711..1ea1a0e 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java @@ -50,11 +50,6 @@ public class Rozvrh { } } - public void setPredmet(String pr, int d, int i) - { - rozvrh[d][i] = pr; - } - public String[][] getRozvrh() { return rozvrh; diff --git a/src/main/java/xyz/thastertyn/Types/Choice.java b/src/main/java/xyz/thastertyn/Types/Choice.java index 1c51a31..8135705 100644 --- a/src/main/java/xyz/thastertyn/Types/Choice.java +++ b/src/main/java/xyz/thastertyn/Types/Choice.java @@ -1,17 +1,17 @@ package xyz.thastertyn.Types; -import java.util.ArrayList; +import java.util.List; public class Choice { - private ArrayList choices; + private List choices; - public Choice(ArrayList c) + public Choice(List c) { this.choices = c; } - public ArrayList getChoices() + public List getChoices() { return choices; } diff --git a/src/main/java/xyz/thastertyn/Types/Predmet.java b/src/main/java/xyz/thastertyn/Types/Predmet.java index 2f6cc27..ae5f365 100644 --- a/src/main/java/xyz/thastertyn/Types/Predmet.java +++ b/src/main/java/xyz/thastertyn/Types/Predmet.java @@ -6,6 +6,7 @@ public class Predmet { private ArrayList znamky = new ArrayList<>(); private String jmenoPredmetu = ""; + private boolean isFinal = false; private int vyslednaZnamka = 0; @@ -18,6 +19,7 @@ public class Predmet { { this.jmenoPredmetu = jmenoPredmetu; this.vyslednaZnamka = vyslednaZnamka; + isFinal = true; } public void addZnamka(Znamka novaZnamka) @@ -50,6 +52,11 @@ public class Predmet { return (double) celkem / vahy; } + public boolean isFinal() + { + return isFinal; + } + public String getJmenoPredmetu() { return jmenoPredmetu; diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java index 9e7e60f..d66bd45 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java @@ -15,12 +15,28 @@ import xyz.thastertyn.UserInterface.UpdateListener; */ public abstract class JecnaContent { - public abstract Panel getPanel(); - public abstract void downloadDefault() throws IOException; - protected abstract void download(Choice choice) throws IOException; - public abstract boolean hasStarted(); - public abstract Label getLabel(); - public abstract void showOptions(final WindowBasedTextGUI textGUI) throws IOException; + protected Panel mainPanel; + protected Boolean hasStarted; + protected Label borderLabel; + protected UpdateListener listener; + protected abstract void setGUI(); - public abstract void setUpdateListener(UpdateListener updateListener); + protected abstract void download(Choice choice) throws IOException; + public abstract void showOptions(final WindowBasedTextGUI textGUI) throws IOException; + public abstract void downloadDefault() throws IOException; + + public Panel getPanel() + { + return mainPanel; + } + + public boolean hasStarted() + { + return hasStarted.booleanValue(); + } + + public Label getLabel() + { + return borderLabel; + } } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java index 9d7de68..1dd6913 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java @@ -18,10 +18,13 @@ public class OmluvnyList extends JecnaContent{ private Label borderLabel = new Label("Omluvny L."); private xyz.thastertyn.Scrape.OmluvnyList omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList(); - private UpdateListener listener; - private boolean hasStarted = false; + public OmluvnyList(UpdateListener listener) + { + this.listener = listener; + } + @Override public void downloadDefault() { @@ -76,9 +79,4 @@ public class OmluvnyList extends JecnaContent{ // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); } - - @Override - public void setUpdateListener(UpdateListener updateListener) { - this.listener = updateListener; - } } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java index 1b76f23..a8e8200 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java @@ -12,13 +12,11 @@ import xyz.thastertyn.Types.Choice; import xyz.thastertyn.UserInterface.UpdateListener; public class Rozvrh extends JecnaContent { - + private Panel rozvrhPanel = new Panel(); private Label borderLabel = new Label("Rozvrh"); private xyz.thastertyn.Scrape.Rozvrh rozvrh = new xyz.thastertyn.Scrape.Rozvrh(); - private UpdateListener listener; - private boolean hasStarted = false; private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"}; @@ -28,6 +26,11 @@ public class Rozvrh extends JecnaContent { Table t = new Table<>(labels); + public Rozvrh(UpdateListener listener) + { + this.listener = listener; + } + @Override public void downloadDefault() { @@ -94,9 +97,4 @@ public class Rozvrh extends JecnaContent { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); } - - @Override - public void setUpdateListener(UpdateListener updateListener) { - this.listener = updateListener; - } } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java index cdb8794..2098720 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java @@ -20,10 +20,13 @@ public class Sdeleni extends JecnaContent { private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni(); - private UpdateListener listener; - private boolean hasStarted = false; + public Sdeleni(UpdateListener listener) + { + this.listener = listener; + } + @Override public void downloadDefault() { @@ -81,9 +84,4 @@ public class Sdeleni extends JecnaContent { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); } - - @Override - public void setUpdateListener(UpdateListener updateListener) { - this.listener = updateListener; - } } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java index e185940..8dc0d14 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java @@ -42,13 +42,22 @@ public class Znamky extends JecnaContent { true, false); - private Panel mainPanel; + private Panel mainPanel = new Panel() + .setLayoutManager(new GridLayout(3)); private Label borderLabel = new Label("Znamky"); private xyz.thastertyn.Scrape.Znamky znamky; private UpdateListener listener; - private boolean hasStarted = false; + private Boolean hasStarted = Boolean.valueOf(false); + + public Znamky(UpdateListener listener) + { + super.mainPanel = this.mainPanel; + super.hasStarted = this.hasStarted; + super.borderLabel = this.borderLabel; + this.listener = listener; + } @Override public void downloadDefault() throws IOException @@ -63,12 +72,12 @@ public class Znamky extends JecnaContent { if(choice != null) { znamky.downloadZnamky(choice); + setGUI(); + listener.updatePanel(); }else{ znamky.downloadZnamky(); + setGUI(); } - - setGUI(); - listener.updatePanel(); hasStarted = true; } @@ -76,8 +85,7 @@ public class Znamky extends JecnaContent { @Override protected void setGUI() { - mainPanel = new Panel() - .setLayoutManager(new GridLayout(3)); + mainPanel.removeAllComponents(); ArrayList subjects = znamky.getPredmety(); @@ -126,34 +134,23 @@ public class Znamky extends JecnaContent { } double prumer = predmet.getVyslednaZnamka(); + String pr; - Label vysl = new Label(String.format("%.2f", prumer)); + if(predmet.isFinal()) + { + int i = (int) prumer; + pr = i + ""; + }else{ + pr = String.format("%.2f", prumer); + } + + Label vysl = new Label(pr); vysl.setTheme(colors.get((int) Math.round(prumer))); jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu())); vysledneZnamky.addComponent(vysl); } - mainPanel.invalidate(); - } - - - @Override - public Panel getPanel() - { - return mainPanel; - } - - @Override - public boolean hasStarted() - { - return hasStarted; - } - - @Override - public Label getLabel() - { - return borderLabel; } @Override @@ -167,9 +164,4 @@ public class Znamky extends JecnaContent { download(c); } } - - @Override - public void setUpdateListener(UpdateListener updateListener) { - this.listener = updateListener; - } } \ No newline at end of file diff --git a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java index 25a38b7..0466e43 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java @@ -3,8 +3,9 @@ package xyz.thastertyn.UserInterface.Dialogs; import java.util.Arrays; import com.googlecode.lanterna.gui2.Button; +import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.GridLayout; -import com.googlecode.lanterna.gui2.LocalizedString; +import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; @@ -14,41 +15,49 @@ public class EscapeDialog extends DialogWindow { public EscapeDialog() { - super("Choose from below"); + super("Escape Menu"); Panel mainPanel = new Panel() .setLayoutManager(new GridLayout(1) .setLeftMarginSize(1) .setRightMarginSize(1)); - new Panel() .setLayoutManager( - new GridLayout(2).setHorizontalSpacing(1)) - .addComponent( - new Button(LocalizedString.OK.toString(), this::onOK) - .setLayoutData(GridLayout.createLayoutData( - GridLayout.Alignment.CENTER, - GridLayout.Alignment.CENTER, - true, - false))) - .addComponent( - new Button(LocalizedString.Cancel.toString(), this::onCancel)) - .addTo(mainPanel); - + new LinearLayout(Direction.VERTICAL)) + .addComponent(new Button("Return", this::onReturn)) + .addComponent(new Button("Logout", this::onLogout)) + .addComponent(new Button("Delete stored login", this::onDeleteLogin)) + .addComponent(new Button("Exit", this::onExit)) + .addTo(mainPanel); setHints(Arrays.asList(Window.Hint.CENTERED)); setComponent(mainPanel); } - public void onOK() + public void onReturn() { close(); } - public void onCancel() + public void onDeleteLogin() { close(); + + // Call login manager to delete login + } + + public void onLogout() + { + close(); + + // Go back to square one and start logging in again + } + + public void onExit() + { + close(); + System.exit(0); } @Override diff --git a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java index 486f7ea..5488743 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java @@ -90,21 +90,13 @@ public class OptionsDialog extends DialogWindow { public Choice showDialog(WindowBasedTextGUI textGUI) { super.showDialog(textGUI); - Choice c; - - ArrayList s = new ArrayList<>(); - - for(ComboBox