diff --git a/src/main/java/xyz/thastertyn/Types/Choice.java b/src/main/java/xyz/thastertyn/Types/Choice.java index d6c1116..1c51a31 100644 --- a/src/main/java/xyz/thastertyn/Types/Choice.java +++ b/src/main/java/xyz/thastertyn/Types/Choice.java @@ -1,14 +1,14 @@ package xyz.thastertyn.Types; import java.util.ArrayList; -import java.util.Arrays; public class Choice { private ArrayList choices; - public Choice(String... choices) + + public Choice(ArrayList c) { - this.choices.addAll(Arrays.asList(choices)); + this.choices = c; } public ArrayList getChoices() diff --git a/src/main/java/xyz/thastertyn/Types/Option.java b/src/main/java/xyz/thastertyn/Types/Option.java index 3b369d4..c5296df 100644 --- a/src/main/java/xyz/thastertyn/Types/Option.java +++ b/src/main/java/xyz/thastertyn/Types/Option.java @@ -22,6 +22,6 @@ public class Option { } @Override public String toString() { - return text; + return value; } } diff --git a/src/main/java/xyz/thastertyn/Types/Predmet.java b/src/main/java/xyz/thastertyn/Types/Predmet.java index 7b75b16..2f6cc27 100644 --- a/src/main/java/xyz/thastertyn/Types/Predmet.java +++ b/src/main/java/xyz/thastertyn/Types/Predmet.java @@ -14,12 +14,18 @@ public class Predmet { this.jmenoPredmetu = jmenoPredmetu; } + public Predmet(String jmenoPredmetu, int vyslednaZnamka) + { + this.jmenoPredmetu = jmenoPredmetu; + this.vyslednaZnamka = vyslednaZnamka; + } + public void addZnamka(Znamka novaZnamka) { znamky.add(novaZnamka); } - public double getPrumer() + public double getVyslednaZnamka() { if(vyslednaZnamka != 0) { diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java index 24e7420..9e7e60f 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java @@ -1,11 +1,14 @@ package xyz.thastertyn.UserInterface.Content; +import java.io.IOException; + +import com.googlecode.lanterna.gui2.Label; +import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import xyz.thastertyn.Types.Choice; +import xyz.thastertyn.UserInterface.UpdateListener; -import com.googlecode.lanterna.gui2.Panel; -import com.googlecode.lanterna.gui2.Label; /** * Wrapper to include all classes that deal with content in some way @@ -13,10 +16,11 @@ import com.googlecode.lanterna.gui2.Label; public abstract class JecnaContent { public abstract Panel getPanel(); - public abstract void downloadDefault(); - protected abstract void download(Choice choice); + 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); + public abstract void showOptions(final WindowBasedTextGUI textGUI) throws IOException; protected abstract void setGUI(); + public abstract void setUpdateListener(UpdateListener updateListener); } diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java index d02348a..9d7de68 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java @@ -10,6 +10,7 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import xyz.thastertyn.Tuples.Pair; import xyz.thastertyn.Types.Choice; +import xyz.thastertyn.UserInterface.UpdateListener; public class OmluvnyList extends JecnaContent{ @@ -17,6 +18,8 @@ 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; @Override @@ -73,4 +76,9 @@ 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 8b8244b..1b76f23 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java @@ -9,6 +9,7 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.table.Table; import xyz.thastertyn.Types.Choice; +import xyz.thastertyn.UserInterface.UpdateListener; public class Rozvrh extends JecnaContent { @@ -16,6 +17,8 @@ public class Rozvrh extends JecnaContent { 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"}; @@ -91,4 +94,9 @@ 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 36a95e3..cdb8794 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java @@ -11,6 +11,7 @@ import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import xyz.thastertyn.Types.Choice; +import xyz.thastertyn.UserInterface.UpdateListener; public class Sdeleni extends JecnaContent { @@ -19,6 +20,8 @@ public class Sdeleni extends JecnaContent { private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni(); + private UpdateListener listener; + private boolean hasStarted = false; @Override @@ -78,4 +81,9 @@ 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 74911d5..e185940 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java @@ -18,6 +18,7 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import xyz.thastertyn.Types.Choice; import xyz.thastertyn.Types.Predmet; import xyz.thastertyn.Types.Znamka; +import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog; public class Znamky extends JecnaContent { @@ -41,52 +42,52 @@ public class Znamky extends JecnaContent { true, false); - private Panel mainPanel = new Panel() - .setLayoutManager(new GridLayout(3)); - + private Panel mainPanel; private Label borderLabel = new Label("Znamky"); - private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky(); + private xyz.thastertyn.Scrape.Znamky znamky; + + private UpdateListener listener; private boolean hasStarted = false; @Override - public void downloadDefault() + public void downloadDefault() throws IOException { download(null); } @Override - protected void download(Choice choice) + protected void download(Choice choice) throws IOException { - try{ - if(choice != null) - { - znamky.downloadZnamky(choice); - }else{ - znamky.downloadZnamky(); - } - - setGUI(); - - hasStarted = true; - }catch(IOException e) + znamky = new xyz.thastertyn.Scrape.Znamky(); + if(choice != null) { - mainPanel.addComponent(new Label("An error has occured")); + znamky.downloadZnamky(choice); + }else{ + znamky.downloadZnamky(); } + + setGUI(); + listener.updatePanel(); + + hasStarted = true; } @Override protected void setGUI() { - ArrayList predmety = znamky.getPredmety(); + mainPanel = new Panel() + .setLayoutManager(new GridLayout(3)); + + ArrayList subjects = 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)); + HashMap colors = new HashMap<>(); + colors.put(1, new SimpleTheme(ANSI.BLACK, VYBORNY)); + colors.put(2, new SimpleTheme(ANSI.BLACK, CHVALITEBNY)); + colors.put(3, new SimpleTheme(ANSI.BLACK, DOBRY)); + colors.put(4, new SimpleTheme(ANSI.BLACK, DOSTATECNY)); + colors.put(5, new SimpleTheme(ANSI.BLACK, NEDOSTATECNY)); + colors.put(-1, new SimpleTheme(ANSI.WHITE, NEHODNOCEN)); // Sloupec pro jmena predmetu Panel jmemaPredmetu = new Panel() @@ -106,7 +107,7 @@ public class Znamky extends JecnaContent { .setLayoutData(ALIGN_RIGHT) .addTo(mainPanel); - for(Predmet predmet : predmety) + for(Predmet predmet : subjects) { Panel jednotliveZnamky = new Panel() .setLayoutManager(new LinearLayout(Direction.HORIZONTAL)) @@ -120,19 +121,20 @@ public class Znamky extends JecnaContent { for(Znamka znamka : predmet.getZnamky()) { Label znamkaLabel = new Label(znamka.getText()); - znamkaLabel.setTheme(barvy.get(znamka.getZnamka())); + znamkaLabel.setTheme(colors.get(znamka.getZnamka())); jednotliveZnamky.addComponent(znamkaLabel); } - double prumer = predmet.getPrumer(); + double prumer = predmet.getVyslednaZnamka(); Label vysl = new Label(String.format("%.2f", prumer)); - vysl.setTheme(barvy.get((int) Math.round(prumer))); + vysl.setTheme(colors.get((int) Math.round(prumer))); jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu())); vysledneZnamky.addComponent(vysl); } + mainPanel.invalidate(); } @@ -155,7 +157,7 @@ public class Znamky extends JecnaContent { } @Override - public void showOptions(WindowBasedTextGUI textGUI) { + public void showOptions(WindowBasedTextGUI textGUI) throws IOException { OptionsDialog d = new OptionsDialog(znamky.getOptions().getValue0(), znamky.getOptions().getValue1()); Choice c = d.showDialog(textGUI); @@ -165,4 +167,9 @@ 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 new file mode 100644 index 0000000..25a38b7 --- /dev/null +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java @@ -0,0 +1,59 @@ +package xyz.thastertyn.UserInterface.Dialogs; + +import java.util.Arrays; + +import com.googlecode.lanterna.gui2.Button; +import com.googlecode.lanterna.gui2.GridLayout; +import com.googlecode.lanterna.gui2.LocalizedString; +import com.googlecode.lanterna.gui2.Panel; +import com.googlecode.lanterna.gui2.Window; +import com.googlecode.lanterna.gui2.WindowBasedTextGUI; +import com.googlecode.lanterna.gui2.dialogs.DialogWindow; + +public class EscapeDialog extends DialogWindow { + + public EscapeDialog() + { + super("Choose from below"); + + 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); + + + setHints(Arrays.asList(Window.Hint.CENTERED)); + setComponent(mainPanel); + } + + public void onOK() + { + close(); + } + + public void onCancel() + { + close(); + } + + @Override + public Object showDialog(WindowBasedTextGUI textGUI) { + super.showDialog(textGUI); + return null; + } +} diff --git a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java index bda89cc..486f7ea 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java @@ -90,11 +90,20 @@ public class OptionsDialog extends DialogWindow { public Choice showDialog(WindowBasedTextGUI textGUI) { super.showDialog(textGUI); + Choice c; + + ArrayList s = new ArrayList<>(); + + for(ComboBox