Reworked JecnaContent, EscapeDialog has a few options, few smaller tweaks
This commit is contained in:
parent
41553eb50e
commit
2b70c3a283
@ -50,11 +50,6 @@ public class Rozvrh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPredmet(String pr, int d, int i)
|
|
||||||
{
|
|
||||||
rozvrh[d][i] = pr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[][] getRozvrh()
|
public String[][] getRozvrh()
|
||||||
{
|
{
|
||||||
return rozvrh;
|
return rozvrh;
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package xyz.thastertyn.Types;
|
package xyz.thastertyn.Types;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
public class Choice {
|
public class Choice {
|
||||||
|
|
||||||
private ArrayList<String> choices;
|
private List<String> choices;
|
||||||
|
|
||||||
public Choice(ArrayList<String> c)
|
public Choice(List<String> c)
|
||||||
{
|
{
|
||||||
this.choices = c;
|
this.choices = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getChoices()
|
public List<String> getChoices()
|
||||||
{
|
{
|
||||||
return choices;
|
return choices;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ public class Predmet {
|
|||||||
|
|
||||||
private ArrayList<Znamka> znamky = new ArrayList<>();
|
private ArrayList<Znamka> znamky = new ArrayList<>();
|
||||||
private String jmenoPredmetu = "";
|
private String jmenoPredmetu = "";
|
||||||
|
private boolean isFinal = false;
|
||||||
|
|
||||||
private int vyslednaZnamka = 0;
|
private int vyslednaZnamka = 0;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ public class Predmet {
|
|||||||
{
|
{
|
||||||
this.jmenoPredmetu = jmenoPredmetu;
|
this.jmenoPredmetu = jmenoPredmetu;
|
||||||
this.vyslednaZnamka = vyslednaZnamka;
|
this.vyslednaZnamka = vyslednaZnamka;
|
||||||
|
isFinal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addZnamka(Znamka novaZnamka)
|
public void addZnamka(Znamka novaZnamka)
|
||||||
@ -50,6 +52,11 @@ public class Predmet {
|
|||||||
return (double) celkem / vahy;
|
return (double) celkem / vahy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFinal()
|
||||||
|
{
|
||||||
|
return isFinal;
|
||||||
|
}
|
||||||
|
|
||||||
public String getJmenoPredmetu()
|
public String getJmenoPredmetu()
|
||||||
{
|
{
|
||||||
return jmenoPredmetu;
|
return jmenoPredmetu;
|
||||||
|
@ -15,12 +15,28 @@ import xyz.thastertyn.UserInterface.UpdateListener;
|
|||||||
*/
|
*/
|
||||||
public abstract class JecnaContent {
|
public abstract class JecnaContent {
|
||||||
|
|
||||||
public abstract Panel getPanel();
|
protected Panel mainPanel;
|
||||||
public abstract void downloadDefault() throws IOException;
|
protected Boolean hasStarted;
|
||||||
protected abstract void download(Choice choice) throws IOException;
|
protected Label borderLabel;
|
||||||
public abstract boolean hasStarted();
|
protected UpdateListener listener;
|
||||||
public abstract Label getLabel();
|
|
||||||
public abstract void showOptions(final WindowBasedTextGUI textGUI) throws IOException;
|
|
||||||
protected abstract void setGUI();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,13 @@ public class OmluvnyList extends JecnaContent{
|
|||||||
private Label borderLabel = new Label("Omluvny L.");
|
private Label borderLabel = new Label("Omluvny L.");
|
||||||
private xyz.thastertyn.Scrape.OmluvnyList omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList();
|
private xyz.thastertyn.Scrape.OmluvnyList omluvnyList = new xyz.thastertyn.Scrape.OmluvnyList();
|
||||||
|
|
||||||
private UpdateListener listener;
|
|
||||||
|
|
||||||
private boolean hasStarted = false;
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
|
public OmluvnyList(UpdateListener listener)
|
||||||
|
{
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadDefault()
|
public void downloadDefault()
|
||||||
{
|
{
|
||||||
@ -76,9 +79,4 @@ public class OmluvnyList extends JecnaContent{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUpdateListener(UpdateListener updateListener) {
|
|
||||||
this.listener = updateListener;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,11 @@ import xyz.thastertyn.Types.Choice;
|
|||||||
import xyz.thastertyn.UserInterface.UpdateListener;
|
import xyz.thastertyn.UserInterface.UpdateListener;
|
||||||
|
|
||||||
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.Scrape.Rozvrh rozvrh = new xyz.thastertyn.Scrape.Rozvrh();
|
private xyz.thastertyn.Scrape.Rozvrh rozvrh = new xyz.thastertyn.Scrape.Rozvrh();
|
||||||
|
|
||||||
private UpdateListener listener;
|
|
||||||
|
|
||||||
private boolean hasStarted = false;
|
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"};
|
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);
|
Table<String> t = new Table<>(labels);
|
||||||
|
|
||||||
|
public Rozvrh(UpdateListener listener)
|
||||||
|
{
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadDefault()
|
public void downloadDefault()
|
||||||
{
|
{
|
||||||
@ -94,9 +97,4 @@ public class Rozvrh extends JecnaContent {
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUpdateListener(UpdateListener updateListener) {
|
|
||||||
this.listener = updateListener;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,13 @@ public class Sdeleni extends JecnaContent {
|
|||||||
|
|
||||||
private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
|
private xyz.thastertyn.Scrape.Sdeleni sdeleni = new xyz.thastertyn.Scrape.Sdeleni();
|
||||||
|
|
||||||
private UpdateListener listener;
|
|
||||||
|
|
||||||
private boolean hasStarted = false;
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
|
public Sdeleni(UpdateListener listener)
|
||||||
|
{
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadDefault()
|
public void downloadDefault()
|
||||||
{
|
{
|
||||||
@ -81,9 +84,4 @@ public class Sdeleni extends JecnaContent {
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUpdateListener(UpdateListener updateListener) {
|
|
||||||
this.listener = updateListener;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,13 +42,22 @@ public class Znamky extends JecnaContent {
|
|||||||
true,
|
true,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
private Panel mainPanel;
|
private Panel mainPanel = new Panel()
|
||||||
|
.setLayoutManager(new GridLayout(3));
|
||||||
private Label borderLabel = new Label("Znamky");
|
private Label borderLabel = new Label("Znamky");
|
||||||
private xyz.thastertyn.Scrape.Znamky znamky;
|
private xyz.thastertyn.Scrape.Znamky znamky;
|
||||||
|
|
||||||
private UpdateListener listener;
|
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
|
@Override
|
||||||
public void downloadDefault() throws IOException
|
public void downloadDefault() throws IOException
|
||||||
@ -63,12 +72,12 @@ public class Znamky extends JecnaContent {
|
|||||||
if(choice != null)
|
if(choice != null)
|
||||||
{
|
{
|
||||||
znamky.downloadZnamky(choice);
|
znamky.downloadZnamky(choice);
|
||||||
|
setGUI();
|
||||||
|
listener.updatePanel();
|
||||||
}else{
|
}else{
|
||||||
znamky.downloadZnamky();
|
znamky.downloadZnamky();
|
||||||
|
setGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
setGUI();
|
|
||||||
listener.updatePanel();
|
|
||||||
|
|
||||||
hasStarted = true;
|
hasStarted = true;
|
||||||
}
|
}
|
||||||
@ -76,8 +85,7 @@ public class Znamky extends JecnaContent {
|
|||||||
@Override
|
@Override
|
||||||
protected void setGUI()
|
protected void setGUI()
|
||||||
{
|
{
|
||||||
mainPanel = new Panel()
|
mainPanel.removeAllComponents();
|
||||||
.setLayoutManager(new GridLayout(3));
|
|
||||||
|
|
||||||
ArrayList<Predmet> subjects = znamky.getPredmety();
|
ArrayList<Predmet> subjects = znamky.getPredmety();
|
||||||
|
|
||||||
@ -126,34 +134,23 @@ public class Znamky extends JecnaContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double prumer = predmet.getVyslednaZnamka();
|
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)));
|
vysl.setTheme(colors.get((int) Math.round(prumer)));
|
||||||
|
|
||||||
jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu()));
|
jmemaPredmetu.addComponent(new Label(predmet.getJmenoPredmetu()));
|
||||||
vysledneZnamky.addComponent(vysl);
|
vysledneZnamky.addComponent(vysl);
|
||||||
}
|
}
|
||||||
mainPanel.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Panel getPanel()
|
|
||||||
{
|
|
||||||
return mainPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasStarted()
|
|
||||||
{
|
|
||||||
return hasStarted;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Label getLabel()
|
|
||||||
{
|
|
||||||
return borderLabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -167,9 +164,4 @@ public class Znamky extends JecnaContent {
|
|||||||
download(c);
|
download(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUpdateListener(UpdateListener updateListener) {
|
|
||||||
this.listener = updateListener;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -3,8 +3,9 @@ package xyz.thastertyn.UserInterface.Dialogs;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.googlecode.lanterna.gui2.Button;
|
import com.googlecode.lanterna.gui2.Button;
|
||||||
|
import com.googlecode.lanterna.gui2.Direction;
|
||||||
import com.googlecode.lanterna.gui2.GridLayout;
|
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.Panel;
|
||||||
import com.googlecode.lanterna.gui2.Window;
|
import com.googlecode.lanterna.gui2.Window;
|
||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
@ -14,41 +15,49 @@ public class EscapeDialog extends DialogWindow {
|
|||||||
|
|
||||||
public EscapeDialog()
|
public EscapeDialog()
|
||||||
{
|
{
|
||||||
super("Choose from below");
|
super("Escape Menu");
|
||||||
|
|
||||||
Panel mainPanel = new Panel()
|
Panel mainPanel = new Panel()
|
||||||
.setLayoutManager(new GridLayout(1)
|
.setLayoutManager(new GridLayout(1)
|
||||||
.setLeftMarginSize(1)
|
.setLeftMarginSize(1)
|
||||||
.setRightMarginSize(1));
|
.setRightMarginSize(1));
|
||||||
|
|
||||||
|
|
||||||
new Panel()
|
new Panel()
|
||||||
.setLayoutManager(
|
.setLayoutManager(
|
||||||
new GridLayout(2).setHorizontalSpacing(1))
|
new LinearLayout(Direction.VERTICAL))
|
||||||
.addComponent(
|
.addComponent(new Button("Return", this::onReturn))
|
||||||
new Button(LocalizedString.OK.toString(), this::onOK)
|
.addComponent(new Button("Logout", this::onLogout))
|
||||||
.setLayoutData(GridLayout.createLayoutData(
|
.addComponent(new Button("Delete stored login", this::onDeleteLogin))
|
||||||
GridLayout.Alignment.CENTER,
|
.addComponent(new Button("Exit", this::onExit))
|
||||||
GridLayout.Alignment.CENTER,
|
.addTo(mainPanel);
|
||||||
true,
|
|
||||||
false)))
|
|
||||||
.addComponent(
|
|
||||||
new Button(LocalizedString.Cancel.toString(), this::onCancel))
|
|
||||||
.addTo(mainPanel);
|
|
||||||
|
|
||||||
|
|
||||||
setHints(Arrays.asList(Window.Hint.CENTERED));
|
setHints(Arrays.asList(Window.Hint.CENTERED));
|
||||||
setComponent(mainPanel);
|
setComponent(mainPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onOK()
|
public void onReturn()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCancel()
|
public void onDeleteLogin()
|
||||||
{
|
{
|
||||||
close();
|
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
|
@Override
|
||||||
|
@ -90,21 +90,13 @@ public class OptionsDialog extends DialogWindow {
|
|||||||
public Choice showDialog(WindowBasedTextGUI textGUI) {
|
public Choice showDialog(WindowBasedTextGUI textGUI) {
|
||||||
super.showDialog(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) ?
|
return (useData) ?
|
||||||
c
|
// User pressed Ok
|
||||||
|
new Choice(boxs.stream()
|
||||||
|
.map(box -> box.getSelectedItem().getValue())
|
||||||
|
.toList())
|
||||||
:
|
:
|
||||||
null; // User pressed Cancel
|
// User pressed Cancel
|
||||||
|
null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,16 @@ import xyz.thastertyn.UserInterface.Content.OmluvnyList;
|
|||||||
import xyz.thastertyn.UserInterface.Content.Rozvrh;
|
import xyz.thastertyn.UserInterface.Content.Rozvrh;
|
||||||
import xyz.thastertyn.UserInterface.Content.Sdeleni;
|
import xyz.thastertyn.UserInterface.Content.Sdeleni;
|
||||||
import xyz.thastertyn.UserInterface.Content.Znamky;
|
import xyz.thastertyn.UserInterface.Content.Znamky;
|
||||||
|
import xyz.thastertyn.UserInterface.Dialogs.EscapeDialog;
|
||||||
|
|
||||||
public class WindowSwitchListener implements WindowListener, UpdateListener {
|
public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||||
private WindowBasedTextGUI textGUI;
|
private WindowBasedTextGUI textGUI;
|
||||||
|
|
||||||
private JecnaContent[] contents = {
|
private JecnaContent[] contents = {
|
||||||
new Rozvrh(),
|
new Rozvrh(this),
|
||||||
new Znamky(),
|
new Znamky(this),
|
||||||
new Sdeleni(),
|
new Sdeleni(this),
|
||||||
new OmluvnyList()
|
new OmluvnyList(this)
|
||||||
};
|
};
|
||||||
|
|
||||||
private Label[] tabs = new Label[contents.length];
|
private Label[] tabs = new Label[contents.length];
|
||||||
@ -53,11 +54,6 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
|||||||
tabsPanel.addComponent(this.tabs[i]);
|
tabsPanel.addComponent(this.tabs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(JecnaContent c : contents)
|
|
||||||
{
|
|
||||||
c.setUpdateListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +82,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
|||||||
|
|
||||||
private void loadPanel()
|
private void loadPanel()
|
||||||
{
|
{
|
||||||
checkIfDownloadedCorrectly();
|
checkIfDownloaded();
|
||||||
|
|
||||||
holderPanel.removeAllComponents();
|
holderPanel.removeAllComponents();
|
||||||
tabsPanel.removeAllComponents();
|
tabsPanel.removeAllComponents();
|
||||||
@ -95,7 +91,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
|||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIfDownloadedCorrectly()
|
private void checkIfDownloaded()
|
||||||
{
|
{
|
||||||
if(!contents[current].hasStarted())
|
if(!contents[current].hasStarted())
|
||||||
{
|
{
|
||||||
@ -167,7 +163,8 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Escape:
|
case Escape:
|
||||||
MessageDialog.showMessageDialog(textGUI, "Options", "Loging out and some other stuff soon", MessageDialogButton.OK);
|
EscapeDialog dialog = new EscapeDialog();
|
||||||
|
dialog.showDialog(textGUI);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user