mensi organizace, misto tuplu bude novy typ

This commit is contained in:
Thastertyn 2023-04-07 11:03:54 +02:00
parent 5e5e6f26da
commit 7b7c00b866
26 changed files with 189 additions and 93 deletions

View File

@ -1,6 +1,6 @@
package xyz.thastertyn; package xyz.thastertyn;
import xyz.thastertyn.ContentDisplay.MainWindow; import xyz.thastertyn.Display.MainWindow;
/** /**
* Hello world! * Hello world!

View File

@ -1,5 +0,0 @@
package xyz.thastertyn.ContentDisplay.Content;
public class Jidelna {
}

View File

@ -1,6 +1,7 @@
package xyz.thastertyn.ContentDisplay.Content; package xyz.thastertyn.Display.Content;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
@ -13,6 +14,5 @@ public abstract class JecnaContent {
public abstract void download(); public abstract void download();
public abstract boolean hasStarted(); public abstract boolean hasStarted();
public abstract Label getLabel(); public abstract Label getLabel();
public abstract void specify(final int y, final int hy); public abstract void showOptions(final WindowBasedTextGUI textGUI);
public abstract void getOptions(final WindowBasedTextGUI textGUI);
} }

View File

@ -0,0 +1,5 @@
package xyz.thastertyn.Display.Content;
public class Jidelna {
}

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay.Content; package xyz.thastertyn.Display.Content;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -14,7 +14,7 @@ public class OmluvnyList extends JecnaContent{
private Panel omluvnyPanel = new Panel(); private Panel omluvnyPanel = new Panel();
private Label borderLabel = new Label("Omluvny L."); private Label borderLabel = new Label("Omluvny L.");
private xyz.thastertyn.JecnaParse.OmluvnyList omluvnyList = new xyz.thastertyn.JecnaParse.OmluvnyList(); private xyz.thastertyn.Scrape.OmluvnyList omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList();
private boolean hasStarted = false; private boolean hasStarted = false;
@ -55,13 +55,7 @@ public class OmluvnyList extends JecnaContent{
} }
@Override @Override
public void specify(int y, int hy) { public void showOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'specify'");
}
@Override
public void getOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
} }

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay.Content; package xyz.thastertyn.Display.Content;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -6,13 +6,14 @@ import java.net.UnknownHostException;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import com.googlecode.lanterna.gui2.table.Table; import com.googlecode.lanterna.gui2.table.Table;
public class Rozvrh extends JecnaContent { public class Rozvrh extends JecnaContent {
private Panel rozvrhPanel = new Panel(); private Panel rozvrhPanel = new Panel();
private Label borderLabel = new Label("Rozvrh"); private Label borderLabel = new Label("Rozvrh");
private xyz.thastertyn.JecnaParse.Rozvrh rozvrh = new xyz.thastertyn.JecnaParse.Rozvrh(); private xyz.thastertyn.Scrape.Rozvrh rozvrh = new xyz.thastertyn.Scrape.Rozvrh();
private boolean hasStarted = false; private boolean hasStarted = false;
@ -73,13 +74,7 @@ public class Rozvrh extends JecnaContent {
} }
@Override @Override
public void specify(int y, int hy) { public void showOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'specify'");
}
@Override
public void getOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
} }

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay.Content; package xyz.thastertyn.Display.Content;
import java.io.IOException; import java.io.IOException;
@ -9,13 +9,14 @@ import com.googlecode.lanterna.gui2.GridLayout;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
public class Sdeleni extends JecnaContent { public class Sdeleni extends JecnaContent {
private Panel sdeleniPanel = new Panel(); private Panel sdeleniPanel = new Panel();
private Label borderLabel = new Label("Sdeleni R."); private Label borderLabel = new Label("Sdeleni R.");
private xyz.thastertyn.JecnaParse.Sdeleni sdeleni = new xyz.thastertyn.JecnaParse.Sdeleni(); private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
private boolean hasStarted = false; private boolean hasStarted = false;
@ -65,13 +66,7 @@ public class Sdeleni extends JecnaContent {
} }
@Override @Override
public void specify(int y, int hy) { public void showOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'specify'");
}
@Override
public void getOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
} }

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay.Content; package xyz.thastertyn.Display.Content;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -11,7 +11,9 @@ import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.LinearLayout;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import xyz.thastertyn.Display.Dialogs.OptionsDialog;
import xyz.thastertyn.Tuples.Pair; import xyz.thastertyn.Tuples.Pair;
public class Znamky extends JecnaContent { public class Znamky extends JecnaContent {
@ -20,7 +22,7 @@ public class Znamky extends JecnaContent {
.setLayoutManager(new GridLayout(3)); .setLayoutManager(new GridLayout(3));
private Label borderLabel = new Label("Znamky"); private Label borderLabel = new Label("Znamky");
private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky(); private xyz.thastertyn.Scrape.Znamky znamky = new xyz.thastertyn.Scrape.Znamky();
private boolean hasStarted = false; private boolean hasStarted = false;
@ -159,14 +161,9 @@ public class Znamky extends JecnaContent {
} }
@Override @Override
public void specify(int y, int hy) { public void showOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub OptionsDialog d = new OptionsDialog(znamky.getOptions());
throw new UnsupportedOperationException("Unimplemented method 'specify'");
}
@Override d.showDialog(textGUI);
public void getOptions(WindowBasedTextGUI textGUI) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
} }
} }

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay; package xyz.thastertyn.Display.Dialogs;
import java.util.Arrays; import java.util.Arrays;
@ -29,7 +29,7 @@ public class CredentialsInput extends DialogWindow {
private CheckBox remember; private CheckBox remember;
CredentialsInput() public CredentialsInput()
{ {
super("Login"); super("Login");
this.user = null; this.user = null;

View File

@ -0,0 +1,74 @@
package xyz.thastertyn.Display.Dialogs;
import java.util.ArrayList;
import java.util.Arrays;
import com.googlecode.lanterna.gui2.Button;
import com.googlecode.lanterna.gui2.ComboBox;
import com.googlecode.lanterna.gui2.EmptySpace;
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;
import xyz.thastertyn.Tuples.Pair;
public class OptionsDialog extends DialogWindow {
private int option0 = 0;
private int option1 = 0;
public OptionsDialog(Pair<ArrayList<String>, ArrayList<String>> options)
{
super("Choose from below");
Panel mainPanel = new Panel()
.setLayoutManager(new GridLayout(1)
.setLeftMarginSize(1)
.setRightMarginSize(1));
new Panel().setLayoutManager(new GridLayout(3))
.addComponent(new ComboBox<>(options.getValue0(), options.getValue0().size() - 1))
.addComponent(new EmptySpace())
.addComponent(new ComboBox<>(options.getValue1(), options.getValue1().size() - 1))
.addTo(mainPanel);
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 String showDialog(WindowBasedTextGUI textGUI) {
super.showDialog(textGUI);
return "";
}
}

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay; package xyz.thastertyn.Display;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -14,13 +14,14 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
import xyz.thastertyn.Display.Dialogs.CredentialsInput;
import xyz.thastertyn.Tuples.Triplet; import xyz.thastertyn.Tuples.Triplet;
public class LoginController { public class LoginController {
private WindowBasedTextGUI textGUI; private WindowBasedTextGUI textGUI;
private xyz.thastertyn.ContentDisplay.CredentialsInput dialog; private xyz.thastertyn.Display.Dialogs.CredentialsInput dialog;
private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login(); private xyz.thastertyn.Scrape.Login login = new xyz.thastertyn.Scrape.Login();
public LoginController(WindowBasedTextGUI textGUI) public LoginController(WindowBasedTextGUI textGUI)
{ {

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay; package xyz.thastertyn.Display;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.ContentDisplay; package xyz.thastertyn.Display;
import java.util.concurrent.atomic.AtomicBoolean; 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.KeyStroke;
import com.googlecode.lanterna.input.KeyType; import com.googlecode.lanterna.input.KeyType;
import xyz.thastertyn.ContentDisplay.Content.JecnaContent; import xyz.thastertyn.Display.Content.JecnaContent;
import xyz.thastertyn.ContentDisplay.Content.OmluvnyList; import xyz.thastertyn.Display.Content.OmluvnyList;
import xyz.thastertyn.ContentDisplay.Content.Rozvrh; import xyz.thastertyn.Display.Content.Rozvrh;
import xyz.thastertyn.ContentDisplay.Content.Sdeleni; import xyz.thastertyn.Display.Content.Sdeleni;
import xyz.thastertyn.ContentDisplay.Content.Znamky; import xyz.thastertyn.Display.Content.Znamky;
public class WindowSwitchListener implements WindowListener { public class WindowSwitchListener implements WindowListener {
@ -115,7 +115,7 @@ public class WindowSwitchListener implements WindowListener {
case Character: case Character:
if(keyStroke.getCharacter() == ' ') if(keyStroke.getCharacter() == ' ')
{ {
MessageDialog.showMessageDialog(textGUI, "Space pressed", "Good job", MessageDialogButton.OK); contents[current].showOptions(textGUI);
} }
break; break;
case Escape: case Escape:

View File

@ -1,5 +0,0 @@
package xyz.thastertyn.JecnaParse;
public class JecnaParser {
}

View File

@ -1,5 +0,0 @@
package xyz.thastertyn.JecnaParse;
public class Jidelna {
}

View File

@ -0,0 +1,9 @@
package xyz.thastertyn.Scrape;
import xyz.thastertyn.Types.BaseType;
public abstract class BaseJecnaParser {
public abstract void download();
public abstract BaseType getData();
}

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.JecnaParse; package xyz.thastertyn.Scrape;
import org.jsoup.Connection; import org.jsoup.Connection;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;

View File

@ -0,0 +1,5 @@
package xyz.thastertyn.Scrape;
public class Jidelna {
}

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.JecnaParse; package xyz.thastertyn.Scrape;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.JecnaParse; package xyz.thastertyn.Scrape;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.JecnaParse; package xyz.thastertyn.Scrape;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.JecnaParse; package xyz.thastertyn.Scrape;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.JecnaParse; package xyz.thastertyn.Scrape;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
@ -11,15 +11,18 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import xyz.thastertyn.Tuples.Pair; import xyz.thastertyn.Tuples.Pair;
import xyz.thastertyn.Tuples.Triplet;
public class Znamky { public class Znamky {
private boolean wasDownloaded; private boolean wasDownloaded;
// schoolYear, schoolYearId
private ArrayList<Triplet<String, ArrayList<Pair<Integer, Double>>, Double>> test = new ArrayList<>();
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>(); private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti // Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
private Pair<ArrayList<String>, ArrayList<String>> options = new Pair<>(); private Pair<ArrayList<Pair<String, String>>, ArrayList<Pair<String, String>>> options = new Pair<>(new ArrayList<Pair<String, String>>(), new ArrayList<Pair<String, String>>());
public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
{ {
@ -80,26 +83,17 @@ public class Znamky {
Elements schoolYear = optionsPanel.select("select[id=schoolYearId]").select("option"); Elements schoolYear = optionsPanel.select("select[id=schoolYearId]").select("option");
Elements schoolYearId = optionsPanel.select("select[id=schoolYearHalfId]").select("option"); Elements schoolYearId = optionsPanel.select("select[id=schoolYearHalfId]").select("option");
/* for(Element e : schoolYear)
Elements roky = znamkyDoc.select("select[name=schoolYearId]");
Elements pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]");
for(Element e : roky)
{ {
boolean jeCelyRok = false; options.getValue0().add(e.attr("value"));
if(pololetiSelect.size() == 2)
{
jeCelyRok = true;
} }
int rok = Integer.parseInt(e.attr("value")); for(Element e : schoolYearId)
{
options.add(new Pair<Integer, Boolean>(rok, jeCelyRok)); options.getValue1().add(new Pair<>(e.attr("value", e.text()));
}*/ }
wasDownloaded = true; wasDownloaded = true;
} }
private void addGrade(int index, String subject, int grade, double weight) private void addGrade(int index, String subject, int grade, double weight)
@ -147,6 +141,11 @@ public class Znamky {
return grades; return grades;
} }
public Pair<ArrayList<String>, ArrayList<String>> getOptions()
{
return options;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -0,0 +1,5 @@
package xyz.thastertyn.Types;
public abstract class BaseType {
}

View File

@ -0,0 +1,13 @@
package xyz.thastertyn.Types;
public class OmluvnyList {
private String datum;
private String popis;
public OmluvnyList(String datum, String popis)
{
this.datum = datum;
this.popis = popis;
}
}

View File

@ -0,0 +1,19 @@
package xyz.thastertyn.Types;
public class Znamka {
private int znamka;
private boolean malaZnamka;
private String text;
private String datum;
public Znamka(int znamka, boolean malaZnamka, String text, String datum)
{
this.znamka = znamka;
this.malaZnamka = malaZnamka;
this.datum = datum;
this.text = text;
}
}