Reworked JecnaContent, EscapeDialog has a few options, few smaller tweaks

This commit is contained in:
Thastertyn 2023-04-28 20:11:23 +02:00
parent 41553eb50e
commit 2b70c3a283
11 changed files with 116 additions and 114 deletions

View File

@ -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;

View File

@ -1,17 +1,17 @@
package xyz.thastertyn.Types;
import java.util.ArrayList;
import java.util.List;
public class Choice {
private ArrayList<String> choices;
private List<String> choices;
public Choice(ArrayList<String> c)
public Choice(List<String> c)
{
this.choices = c;
}
public ArrayList<String> getChoices()
public List<String> getChoices()
{
return choices;
}

View File

@ -6,6 +6,7 @@ public class Predmet {
private ArrayList<Znamka> 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;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<String> 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;
}
}

View File

@ -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;
}
}

View File

@ -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<Predmet> 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;
}
}

View File

@ -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

View File

@ -90,21 +90,13 @@ public class OptionsDialog extends DialogWindow {
public Choice showDialog(WindowBasedTextGUI textGUI) {
super.showDialog(textGUI);
Choice c;
ArrayList<String> s = new ArrayList<>();
for(ComboBox<Option> b : boxs)
{
s.add(b.getSelectedItem().getValue());
}
c = new Choice(s);
return (useData) ?
c
// User pressed Ok
new Choice(boxs.stream()
.map(box -> box.getSelectedItem().getValue())
.toList())
:
null; // User pressed Cancel
// User pressed Cancel
null;
}
}

View File

@ -23,15 +23,16 @@ import xyz.thastertyn.UserInterface.Content.OmluvnyList;
import xyz.thastertyn.UserInterface.Content.Rozvrh;
import xyz.thastertyn.UserInterface.Content.Sdeleni;
import xyz.thastertyn.UserInterface.Content.Znamky;
import xyz.thastertyn.UserInterface.Dialogs.EscapeDialog;
public class WindowSwitchListener implements WindowListener, UpdateListener {
private WindowBasedTextGUI textGUI;
private JecnaContent[] contents = {
new Rozvrh(),
new Znamky(),
new Sdeleni(),
new OmluvnyList()
new Rozvrh(this),
new Znamky(this),
new Sdeleni(this),
new OmluvnyList(this)
};
private Label[] tabs = new Label[contents.length];
@ -53,11 +54,6 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
tabsPanel.addComponent(this.tabs[i]);
}
for(JecnaContent c : contents)
{
c.setUpdateListener(this);
}
next();
}
@ -86,7 +82,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
private void loadPanel()
{
checkIfDownloadedCorrectly();
checkIfDownloaded();
holderPanel.removeAllComponents();
tabsPanel.removeAllComponents();
@ -95,7 +91,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
updateLabels();
}
private void checkIfDownloadedCorrectly()
private void checkIfDownloaded()
{
if(!contents[current].hasStarted())
{
@ -167,7 +163,8 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
}
break;
case Escape:
MessageDialog.showMessageDialog(textGUI, "Options", "Loging out and some other stuff soon", MessageDialogButton.OK);
EscapeDialog dialog = new EscapeDialog();
dialog.showDialog(textGUI);
break;
default:
break;