Tabs, rozvrh + znamky tabs
This commit is contained in:
parent
4464cd2840
commit
3a37456337
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Launch Current File",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "${file}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Launch App",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "xyz.thastertyn.App",
|
||||||
|
"projectName": "jecnak-tui"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package xyz.thastertyn;
|
package xyz.thastertyn;
|
||||||
|
|
||||||
import xyz.thastertyn.Jecna.*;
|
|
||||||
import xyz.thastertyn.Window.MainWindow;
|
import xyz.thastertyn.Window.MainWindow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,49 +19,7 @@ public class App {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#region Jidelna
|
|
||||||
|
|
||||||
//#region JSESSIONID
|
|
||||||
Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/")
|
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.method(Method.HEAD)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
String jidelnaJSESSIONID = jidelna.cookie("JSESSIONID");
|
|
||||||
String XSRF_TOKEN = jidelna.cookie("XSRF-TOKEN");
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
//#region CSRF
|
|
||||||
String csrf = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/login.jsp")
|
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.cookie("XSRF-TOKEN", XSRF_TOKEN)
|
|
||||||
.cookie("JSESSIONID", jidelnaJSESSIONID)
|
|
||||||
.get()
|
|
||||||
.select("input[name=_csrf]")
|
|
||||||
.attr("value");
|
|
||||||
|
|
||||||
|
|
||||||
if(!XSRF_TOKEN.equals(csrf))
|
|
||||||
{
|
|
||||||
throw new SecurityException("CSRF tokens do not match, something is up");
|
|
||||||
}
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
//#region Login
|
|
||||||
Connection.Response jidelnaLogin = Jsoup.connect("https://objednavky.jidelnasokolska.cz/j_spring_security_check")
|
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
.cookie("XSRF-TOKEN", XSRF_TOKEN)
|
|
||||||
.cookie("JSESSIONID", jidelnaJSESSIONID)
|
|
||||||
.data("j_username", Credentials.user)
|
|
||||||
.data("j_password", Credentials.pass)
|
|
||||||
.data("terminal", "false")
|
|
||||||
.data("type", "web")
|
|
||||||
.data("_csrf", XSRF_TOKEN)
|
|
||||||
.data("targetUrl", "/faces/secured/main.jsp?terminal=false&status=true&printer=false&keyboard=false")
|
|
||||||
.method(Method.POST)
|
|
||||||
.execute();
|
|
||||||
//#endregion
|
|
||||||
|
|
||||||
Document obedy = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/secured/month.jsp?terminal=false&keyboard=&printer=")
|
Document obedy = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/secured/month.jsp?terminal=false&keyboard=&printer=")
|
||||||
.header("Connection", "keep-alive")
|
.header("Connection", "keep-alive")
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package xyz.thastertyn;
|
|
||||||
|
|
||||||
import org.jsoup.Jsoup;
|
|
||||||
|
|
||||||
public class Connection {
|
|
||||||
|
|
||||||
private static final org.jsoup.Connection CONNECTION = Jsoup.connect("")
|
|
||||||
.header("Connection", "keep-alive")
|
|
||||||
.cookie("role", "student");
|
|
||||||
|
|
||||||
public static org.jsoup.Connection getConnection()
|
|
||||||
{
|
|
||||||
return CONNECTION;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package xyz.thastertyn;
|
|
||||||
|
|
||||||
public class Download {
|
|
||||||
|
|
||||||
}
|
|
@ -3,9 +3,9 @@ package xyz.thastertyn.Jecna;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
import xyz.thastertyn.Connection;
|
|
||||||
import xyz.thastertyn.Tuple.Pair;
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
public class Dochazka {
|
public class Dochazka {
|
||||||
@ -18,9 +18,10 @@ public class Dochazka {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// absence-list
|
// absence-list
|
||||||
absenceDoc = Connection.getConnection()
|
absenceDoc = Jsoup.connect("https://www.spsejecna.cz" + "/absence/passing-student")
|
||||||
.cookie("JSESSIOND", JSESSIOND)
|
.cookie("JSESSIOND", JSESSIOND)
|
||||||
.url("https://www.spsejecna.cz" + "/absence/passing-student")
|
.cookie("role", "student")
|
||||||
|
.header("Connection", "keep-alive")
|
||||||
.get();
|
.get();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
5
src/main/java/xyz/thastertyn/Jecna/Jidelna.java
Normal file
5
src/main/java/xyz/thastertyn/Jecna/Jidelna.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package xyz.thastertyn.Jecna;
|
||||||
|
|
||||||
|
public class Jidelna {
|
||||||
|
|
||||||
|
}
|
@ -4,9 +4,12 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import javax.security.auth.login.CredentialException;
|
||||||
|
|
||||||
import org.jsoup.Connection;
|
import org.jsoup.Connection;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.Connection.Method;
|
import org.jsoup.Connection.Method;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
|
||||||
public class Login {
|
public class Login {
|
||||||
|
|
||||||
@ -23,7 +26,7 @@ public class Login {
|
|||||||
* <li> {@code false} neexistuje, nebo jsou prazdne </li>
|
* <li> {@code false} neexistuje, nebo jsou prazdne </li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public boolean getCredentials()
|
public boolean checkForCredentials()
|
||||||
{
|
{
|
||||||
File credentials = null;
|
File credentials = null;
|
||||||
|
|
||||||
@ -67,9 +70,8 @@ public class Login {
|
|||||||
return Jsessionid;
|
return Jsessionid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte login(String user, String pass)
|
public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
//#region JSESSIONID
|
//#region JSESSIONID
|
||||||
Connection.Response response = Jsoup.connect("https://www.spsejecna.cz")
|
Connection.Response response = Jsoup.connect("https://www.spsejecna.cz")
|
||||||
.header("Connection", "keep-alive")
|
.header("Connection", "keep-alive")
|
||||||
@ -89,7 +91,7 @@ public class Login {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Login
|
//#region Login
|
||||||
Connection.Response login = Jsoup.connect("https://www.spsejecna.cz/user/login")
|
Jsoup.connect("https://www.spsejecna.cz/user/login")
|
||||||
.method(Connection.Method.POST)
|
.method(Connection.Method.POST)
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
//.header("Content-Length", "71") Adds 10 seconds to total request time
|
//.header("Content-Length", "71") Adds 10 seconds to total request time
|
||||||
@ -105,17 +107,63 @@ public class Login {
|
|||||||
.execute();
|
.execute();
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
Document test = Jsoup.connect("https://www.spsejecna.cz/score/student")
|
||||||
|
.header("Connection", "keep-alive")
|
||||||
|
.cookie("JSESSIONID", Jsessionid)
|
||||||
|
.cookie("role", "student")
|
||||||
|
.get();
|
||||||
|
|
||||||
|
if(test.toString().contains("Pro pokračování se přihlaste do systému"))
|
||||||
|
{
|
||||||
|
throw new CredentialException("Incorrect username or password");
|
||||||
|
}
|
||||||
|
|
||||||
start = System.currentTimeMillis() / 1000L;
|
start = System.currentTimeMillis() / 1000L;
|
||||||
lastCheck = start;
|
lastCheck = start;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
public void loginJidelna() throws UnknownHostException, IOException
|
||||||
} catch(UnknownHostException e)
|
{
|
||||||
{
|
//#region JSESSIONID
|
||||||
// Not connected to internet
|
Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/")
|
||||||
return 127;
|
.header("Connection", "keep-alive")
|
||||||
} catch(IOException e)
|
.method(Method.HEAD)
|
||||||
{
|
.execute();
|
||||||
return 126;
|
|
||||||
}
|
String jidelnaJSESSIONID = jidelna.cookie("JSESSIONID");
|
||||||
|
String XSRF_TOKEN = jidelna.cookie("XSRF-TOKEN");
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region CSRF
|
||||||
|
String csrf = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/login.jsp")
|
||||||
|
.header("Connection", "keep-alive")
|
||||||
|
.cookie("XSRF-TOKEN", XSRF_TOKEN)
|
||||||
|
.cookie("JSESSIONID", jidelnaJSESSIONID)
|
||||||
|
.get()
|
||||||
|
.select("input[name=_csrf]")
|
||||||
|
.attr("value");
|
||||||
|
|
||||||
|
|
||||||
|
if(!XSRF_TOKEN.equals(csrf))
|
||||||
|
{
|
||||||
|
throw new SecurityException("CSRF tokens do not match, something is up");
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region Login
|
||||||
|
Connection.Response jidelnaLogin = Jsoup.connect("https://objednavky.jidelnasokolska.cz/j_spring_security_check")
|
||||||
|
.header("Connection", "keep-alive")
|
||||||
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
.cookie("XSRF-TOKEN", XSRF_TOKEN)
|
||||||
|
.cookie("JSESSIONID", jidelnaJSESSIONID)
|
||||||
|
.data("j_username", Credentials.user)
|
||||||
|
.data("j_password", Credentials.pass)
|
||||||
|
.data("terminal", "false")
|
||||||
|
.data("type", "web")
|
||||||
|
.data("_csrf", XSRF_TOKEN)
|
||||||
|
.data("targetUrl", "/faces/secured/main.jsp?terminal=false&status=true&printer=false&keyboard=false")
|
||||||
|
.method(Method.POST)
|
||||||
|
.execute();
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
package xyz.thastertyn.Jecna;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.regex.Matcher;
|
||||||
import java.util.Map;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
@ -15,17 +16,20 @@ public class Znamky {
|
|||||||
|
|
||||||
private boolean wasDownloaded;
|
private boolean wasDownloaded;
|
||||||
|
|
||||||
// key (String) reprezentuje predmet, value (arraylist) znamky a pair znamku s jeji vahou
|
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
||||||
private HashMap<String, ArrayList<Pair<Integer, Double>>> grades = new HashMap<>();
|
|
||||||
|
|
||||||
public void addGrade(String subject, int grade, double weight)
|
public void addGrade(int index, String subject, int grade, double weight)
|
||||||
{
|
{
|
||||||
grades.get(subject).add(new Pair<Integer,Double>(grade, weight));
|
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
|
||||||
|
|
||||||
|
grades.get(index).getValue1().getValue0().add(znamka);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSubject(String subject)
|
public void addSubject(String subject)
|
||||||
{
|
{
|
||||||
grades.put(subject, new ArrayList<Pair<Integer, Double>>());
|
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
|
||||||
|
|
||||||
|
grades.add(new Pair<>(subject, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getAverage(ArrayList<Pair<Integer, Double>> a)
|
private double getAverage(ArrayList<Pair<Integer, Double>> a)
|
||||||
@ -39,7 +43,8 @@ public class Znamky {
|
|||||||
divisor += p.getValue1();
|
divisor += p.getValue1();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (double) divident / divisor;
|
double prumer = (double) divident / divisor;
|
||||||
|
return (double) Math.round(prumer * 100) / 100;
|
||||||
|
|
||||||
}catch(ArithmeticException e)
|
}catch(ArithmeticException e)
|
||||||
{
|
{
|
||||||
@ -47,17 +52,10 @@ public class Znamky {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte downloadZnamky(final String Jsessionid)
|
public void downloadZnamky(final String Jsessionid) throws UnknownHostException, IOException
|
||||||
{
|
{
|
||||||
wasDownloaded = true;
|
wasDownloaded = true;
|
||||||
Document znamkyDoc = null;
|
Document znamkyDoc = Downloader.download("https://www.spsejecna.cz" + "/score/student", Jsessionid).get();
|
||||||
|
|
||||||
try {
|
|
||||||
znamkyDoc = Downloader.download("https://www.spsejecna.cz" + "/score/student", Jsessionid).get();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
Elements rows = znamkyDoc.select("table.score").select("tr");
|
Elements rows = znamkyDoc.select("table.score").select("tr");
|
||||||
|
|
||||||
@ -68,25 +66,43 @@ public class Znamky {
|
|||||||
rows_split[i] = rows.get(i).children();
|
rows_split[i] = rows.get(i).children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int subj = 0;
|
||||||
|
|
||||||
for(int i = 1; i < rows_split.length; i++)
|
for(int i = 1; i < rows_split.length; i++)
|
||||||
{
|
{
|
||||||
String predmet = rows_split[i].get(0).text();
|
String predmetFull = rows_split[i].get(0).text();
|
||||||
|
|
||||||
|
Matcher matcher = Pattern.compile("\\((.*)\\)").matcher(predmetFull);
|
||||||
|
|
||||||
|
String predmet = matcher.find() ? matcher.group(1) : predmetFull;
|
||||||
addSubject(predmet);
|
addSubject(predmet);
|
||||||
|
|
||||||
for(Element e : rows_split[i].get(1).select("a.score"))
|
for(Element znamkaElement : rows_split[i].get(1).select("a.score"))
|
||||||
{
|
{
|
||||||
int znamka = Integer.parseInt(e.select("span.value").text());
|
if(znamkaElement == null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int znamka = Integer.parseInt(znamkaElement.select("span.value").text());
|
||||||
|
|
||||||
// Mala znamka se bude pocitat jako polovicni vaha
|
// Mala znamka se bude pocitat jako polovicni vaha
|
||||||
if(e.hasClass("scoreSmall"))
|
if(znamkaElement.hasClass("scoreSmall"))
|
||||||
{
|
{
|
||||||
addGrade(predmet, znamka, 0.5);
|
addGrade(subj, predmet, znamka, 0.5);
|
||||||
}else{
|
}else{
|
||||||
addGrade(predmet, znamka, 1);
|
addGrade(subj, predmet, znamka, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0()));
|
||||||
|
subj++;
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades()
|
||||||
|
{
|
||||||
|
return grades;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -96,11 +112,9 @@ public class Znamky {
|
|||||||
{
|
{
|
||||||
String s = "";
|
String s = "";
|
||||||
|
|
||||||
for(Map.Entry<String, ArrayList<Pair<Integer, Double>>> entry : grades.entrySet())
|
for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> p : grades)
|
||||||
{
|
{
|
||||||
double prumer = getAverage(entry.getValue());
|
s += p.getValue0() + " | " + p.getValue1().getValue0().toString() + " { " + p.getValue1().getValue1() + " } ";
|
||||||
double p = (double) Math.round(prumer * 100) / 100;
|
|
||||||
s += entry.getKey() + " | " + entry.getValue().toString() + " { " + p + " }\n";
|
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}else{
|
}else{
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package xyz.thastertyn;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Predmet {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package xyz.thastertyn;
|
|
||||||
|
|
||||||
public class RozvrhDownload {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,29 @@
|
|||||||
|
package xyz.thastertyn.Window.Content;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper to include all classes that deal with content in some way
|
||||||
|
*/
|
||||||
|
public class JecnaContent {
|
||||||
|
|
||||||
|
public Panel getPanel()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void download(String s)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasStarted()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
5
src/main/java/xyz/thastertyn/Window/Content/Jidelna.java
Normal file
5
src/main/java/xyz/thastertyn/Window/Content/Jidelna.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package xyz.thastertyn.Window.Content;
|
||||||
|
|
||||||
|
public class Jidelna {
|
||||||
|
|
||||||
|
}
|
70
src/main/java/xyz/thastertyn/Window/Content/Rozvrh.java
Normal file
70
src/main/java/xyz/thastertyn/Window/Content/Rozvrh.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package xyz.thastertyn.Window.Content;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.table.Table;
|
||||||
|
|
||||||
|
public class Rozvrh extends JecnaContent {
|
||||||
|
|
||||||
|
private Panel rozvrhPanel = new Panel();
|
||||||
|
|
||||||
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
|
private xyz.thastertyn.Jecna.Rozvrh rozvrh = new xyz.thastertyn.Jecna.Rozvrh();
|
||||||
|
|
||||||
|
//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", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."};
|
||||||
|
|
||||||
|
String[] days = {"PO", "UT", "ST", "CT", "PA"};
|
||||||
|
|
||||||
|
Table<String> t = new Table<>(labels);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(String Jsessionid)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
rozvrh.downloadRozvrh(Jsessionid);
|
||||||
|
|
||||||
|
String[][] r = rozvrh.getRozvrh();
|
||||||
|
|
||||||
|
String[] s = new String[labels.length];
|
||||||
|
|
||||||
|
for(int i = 0; i < r.length; i++)
|
||||||
|
{
|
||||||
|
s[0] = days[i];
|
||||||
|
for(int j = 1; j < r[i].length; j++) { s[j] = r[i][j]; }
|
||||||
|
|
||||||
|
t.getTableModel().addRow(s);
|
||||||
|
}
|
||||||
|
rozvrhPanel.addComponent(t);
|
||||||
|
hasStarted = true;
|
||||||
|
}catch(UnknownHostException e)
|
||||||
|
{
|
||||||
|
rozvrhPanel.addComponent(new Label("A connection error occurred"));
|
||||||
|
}catch(IOException e)
|
||||||
|
{
|
||||||
|
rozvrhPanel.addComponent(new Label("An error occurred"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStarted()
|
||||||
|
{
|
||||||
|
return hasStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Panel getPanel()
|
||||||
|
{
|
||||||
|
return rozvrhPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLabel()
|
||||||
|
{
|
||||||
|
return "Rozvrh";
|
||||||
|
}
|
||||||
|
}
|
127
src/main/java/xyz/thastertyn/Window/Content/Znamky.java
Normal file
127
src/main/java/xyz/thastertyn/Window/Content/Znamky.java
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
package xyz.thastertyn.Window.Content;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.TextColor;
|
||||||
|
import com.googlecode.lanterna.graphics.SimpleTheme;
|
||||||
|
import com.googlecode.lanterna.gui2.Direction;
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
|
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
|
public class Znamky extends JecnaContent {
|
||||||
|
|
||||||
|
private Panel znamkyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
||||||
|
|
||||||
|
private xyz.thastertyn.Jecna.Znamky znamky = new xyz.thastertyn.Jecna.Znamky();
|
||||||
|
|
||||||
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(String JsessionId)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
znamky.downloadZnamky(JsessionId);
|
||||||
|
|
||||||
|
Panel predmetyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL));
|
||||||
|
Panel znamkyP = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL));
|
||||||
|
Panel vyslPanel = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL));
|
||||||
|
|
||||||
|
ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = znamky.getGrades();
|
||||||
|
|
||||||
|
for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> predmet : grades)
|
||||||
|
{
|
||||||
|
predmetyPanel.addComponent(new Label(predmet.getValue0()));
|
||||||
|
|
||||||
|
Panel znamkyZPredmetu = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
||||||
|
|
||||||
|
if(predmet.getValue1().getValue0().isEmpty())
|
||||||
|
{
|
||||||
|
znamkyZPredmetu.addComponent(new Label(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Pair<Integer, Double> znamka : predmet.getValue1().getValue0())
|
||||||
|
{
|
||||||
|
// TODO pridat predmet.getValue0() ktery premeni znamky na jmeno predmetu jako funkci (not a bug, its a feature)
|
||||||
|
Label znamkaLabel = new Label(znamka.getValue0() + "");
|
||||||
|
switch(znamka.getValue0())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.BLUE));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.YELLOW));
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.MAGENTA));
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
znamkaLabel.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.RED));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
znamkyZPredmetu.addComponent(znamkaLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
znamkyP.addComponent(znamkyZPredmetu);
|
||||||
|
|
||||||
|
double prumer = predmet.getValue1().getValue1();
|
||||||
|
|
||||||
|
Label vysl = new Label("" + prumer);
|
||||||
|
|
||||||
|
if(prumer >= 1 && prumer < 1.5)
|
||||||
|
{
|
||||||
|
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.GREEN));
|
||||||
|
}else if(prumer >= 1.5 && prumer < 2.5)
|
||||||
|
{
|
||||||
|
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.BLUE));
|
||||||
|
|
||||||
|
}else if(prumer >= 2.5 && prumer < 3.5)
|
||||||
|
{
|
||||||
|
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.YELLOW));
|
||||||
|
|
||||||
|
}else if(prumer >= 3.5 && prumer < 4.5)
|
||||||
|
{
|
||||||
|
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.MAGENTA));
|
||||||
|
}else if(prumer >= 4.5)
|
||||||
|
{
|
||||||
|
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, TextColor.ANSI.RED));
|
||||||
|
}
|
||||||
|
|
||||||
|
vyslPanel.addComponent(vysl);
|
||||||
|
}
|
||||||
|
|
||||||
|
znamkyPanel.addComponent(predmetyPanel);
|
||||||
|
znamkyPanel.addComponent(znamkyP);
|
||||||
|
znamkyPanel.addComponent(vyslPanel);
|
||||||
|
|
||||||
|
hasStarted = true;
|
||||||
|
}catch(IOException e)
|
||||||
|
{
|
||||||
|
znamkyPanel.addComponent(new Label("An error has occured"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Panel getPanel()
|
||||||
|
{
|
||||||
|
return znamkyPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStarted()
|
||||||
|
{
|
||||||
|
return hasStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLabel()
|
||||||
|
{
|
||||||
|
return "Znamky";
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +1,164 @@
|
|||||||
package xyz.thastertyn.Window;
|
package xyz.thastertyn.Window;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.security.auth.login.CredentialException;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.TerminalSize;
|
||||||
|
import com.googlecode.lanterna.gui2.Button;
|
||||||
|
import com.googlecode.lanterna.gui2.EmptySpace;
|
||||||
|
import com.googlecode.lanterna.gui2.GridLayout;
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
|
import com.googlecode.lanterna.gui2.LocalizedString;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.TextBox;
|
||||||
|
import com.googlecode.lanterna.gui2.Window;
|
||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import com.googlecode.lanterna.gui2.GridLayout.Alignment;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
|
||||||
|
|
||||||
public class Login {
|
public class Login extends DialogWindow {
|
||||||
|
|
||||||
String user = "";
|
|
||||||
String pass = "";
|
|
||||||
|
|
||||||
xyz.thastertyn.Jecna.Login login = new xyz.thastertyn.Jecna.Login();
|
private TextBox username;
|
||||||
|
private TextBox password;
|
||||||
|
private String user;
|
||||||
|
private String pass;
|
||||||
|
|
||||||
LoginDialog dialog = new LoginDialog("Login", "Enter your username and password");
|
private xyz.thastertyn.Jecna.Login login = new xyz.thastertyn.Jecna.Login();
|
||||||
|
|
||||||
public void showDialog(WindowBasedTextGUI textGUI)
|
Login()
|
||||||
{
|
{
|
||||||
String[] input = dialog.showDialog(textGUI);
|
super("Login");
|
||||||
|
this.user = null;
|
||||||
|
this.pass = null;
|
||||||
|
this.username = new TextBox();
|
||||||
|
this.password = new TextBox().setMask('*');
|
||||||
|
|
||||||
user = input[0];
|
Panel buttonPanel = new Panel();
|
||||||
pass = input[1];
|
buttonPanel
|
||||||
|
.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));
|
||||||
|
|
||||||
login();
|
Panel mainPanel = new Panel()
|
||||||
|
.setLayoutManager(new GridLayout(1)
|
||||||
|
.setLeftMarginSize(1)
|
||||||
|
.setRightMarginSize(1));
|
||||||
|
|
||||||
|
mainPanel.addComponent(new Label("Enter your username and password"));
|
||||||
|
|
||||||
|
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
|
||||||
|
|
||||||
|
Panel userPanel = new Panel()
|
||||||
|
.setLayoutManager(new GridLayout(3))
|
||||||
|
.setLayoutData(
|
||||||
|
GridLayout.createLayoutData(
|
||||||
|
GridLayout.Alignment.FILL,
|
||||||
|
Alignment.CENTER,
|
||||||
|
true,
|
||||||
|
false));
|
||||||
|
|
||||||
|
this.username.setLayoutData(
|
||||||
|
GridLayout.createLayoutData(
|
||||||
|
GridLayout.Alignment.FILL,
|
||||||
|
GridLayout.Alignment.CENTER,
|
||||||
|
true,
|
||||||
|
false));
|
||||||
|
|
||||||
|
userPanel.addComponent(new Label("Username: "))
|
||||||
|
.addComponent(username)
|
||||||
|
.addTo(mainPanel);
|
||||||
|
|
||||||
|
this.password
|
||||||
|
.setLayoutData(
|
||||||
|
GridLayout.createLayoutData(GridLayout.Alignment.FILL,
|
||||||
|
GridLayout.Alignment.CENTER,
|
||||||
|
true,
|
||||||
|
false))
|
||||||
|
.addTo(mainPanel);
|
||||||
|
|
||||||
|
Panel passPanel = new Panel()
|
||||||
|
.setLayoutManager(new GridLayout(3))
|
||||||
|
.setLayoutData(GridLayout.createLayoutData(
|
||||||
|
GridLayout.Alignment.FILL,
|
||||||
|
Alignment.CENTER,
|
||||||
|
true,
|
||||||
|
false));
|
||||||
|
|
||||||
|
passPanel.addComponent(new Label("Password: "))
|
||||||
|
.addComponent(password)
|
||||||
|
.addTo(mainPanel);
|
||||||
|
|
||||||
|
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
|
||||||
|
|
||||||
|
buttonPanel.setLayoutData(
|
||||||
|
GridLayout.createLayoutData(
|
||||||
|
Alignment.END,
|
||||||
|
Alignment.CENTER,
|
||||||
|
false, false))
|
||||||
|
.addTo(mainPanel);
|
||||||
|
|
||||||
|
setHints(Arrays.asList(Window.Hint.CENTERED));
|
||||||
|
setComponent(mainPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void login()
|
public void onOK()
|
||||||
{
|
{
|
||||||
login.login(user, pass);
|
this.user = username.getText();
|
||||||
|
this.pass = password.getText();
|
||||||
|
|
||||||
user = null;
|
if (user.isEmpty() || pass.isEmpty())
|
||||||
pass = null;
|
{
|
||||||
|
MessageDialog.showMessageDialog(getTextGUI(), getTitle(), "Username and password cannot be blank",
|
||||||
|
MessageDialogButton.OK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
login.loginJecna(user, pass);
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
MessageDialog.showMessageDialog(getTextGUI(), "No Internet connection",
|
||||||
|
"There seems to be no internet connection, reverting to cached data", MessageDialogButton.OK);
|
||||||
|
return;
|
||||||
|
} catch (CredentialException e)
|
||||||
|
{
|
||||||
|
MessageDialog.showMessageDialog(getTextGUI(), "Incorrect username or password",
|
||||||
|
"The username or password you entered is incorrect", MessageDialogButton.OK);
|
||||||
|
return;
|
||||||
|
} catch (IOException e)
|
||||||
|
{
|
||||||
|
MessageDialog.showMessageDialog(getTextGUI(), "There was an error", "Maybe try again and it will go away",
|
||||||
|
MessageDialogButton.OK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJsessionId()
|
public String getJessionId() {
|
||||||
{
|
|
||||||
return login.getJSESSIONID();
|
return login.getJSESSIONID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onCancel() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] showDialog(WindowBasedTextGUI textGUI) {
|
||||||
|
super.showDialog(textGUI);
|
||||||
|
return new String[] { user, pass };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
package xyz.thastertyn.Window;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.TerminalSize;
|
|
||||||
import com.googlecode.lanterna.gui2.Button;
|
|
||||||
import com.googlecode.lanterna.gui2.EmptySpace;
|
|
||||||
import com.googlecode.lanterna.gui2.GridLayout;
|
|
||||||
import com.googlecode.lanterna.gui2.Label;
|
|
||||||
import com.googlecode.lanterna.gui2.LocalizedString;
|
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
|
||||||
import com.googlecode.lanterna.gui2.TextBox;
|
|
||||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
|
||||||
import com.googlecode.lanterna.gui2.GridLayout.Alignment;
|
|
||||||
import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
|
|
||||||
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
|
|
||||||
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
|
|
||||||
|
|
||||||
public class LoginDialog extends DialogWindow {
|
|
||||||
|
|
||||||
private TextBox username;
|
|
||||||
private TextBox password;
|
|
||||||
private String user;
|
|
||||||
private String pass;
|
|
||||||
|
|
||||||
LoginDialog(
|
|
||||||
String title,
|
|
||||||
String description
|
|
||||||
)
|
|
||||||
{
|
|
||||||
super(title);
|
|
||||||
this.user = null;
|
|
||||||
this.pass = null;
|
|
||||||
this.username = new TextBox();
|
|
||||||
this.password = new TextBox().setMask('*');
|
|
||||||
|
|
||||||
Panel buttonPanel = new Panel();
|
|
||||||
buttonPanel.setLayoutManager((new GridLayout(2).setHorizontalSpacing(1)));
|
|
||||||
buttonPanel
|
|
||||||
.addComponent((new Button(LocalizedString.OK.toString(), this::onOK)
|
|
||||||
.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.CENTER, GridLayout.Alignment.CENTER, true, false))));
|
|
||||||
buttonPanel.addComponent(new Button(LocalizedString.Cancel.toString(), this::onCancel));
|
|
||||||
|
|
||||||
Panel mainPanel = new Panel();
|
|
||||||
mainPanel.setLayoutManager(new GridLayout(1).setLeftMarginSize(1).setRightMarginSize(1));
|
|
||||||
|
|
||||||
if(description != null)
|
|
||||||
{
|
|
||||||
mainPanel.addComponent(new Label(description));
|
|
||||||
}
|
|
||||||
|
|
||||||
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
|
|
||||||
|
|
||||||
Panel userPanel = new Panel()
|
|
||||||
.setLayoutManager(new GridLayout(3))
|
|
||||||
.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, Alignment.CENTER, true, false));
|
|
||||||
|
|
||||||
this.username.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false));
|
|
||||||
|
|
||||||
userPanel.addComponent(new Label("Username: "))
|
|
||||||
.addComponent(username)
|
|
||||||
.addTo(mainPanel);
|
|
||||||
|
|
||||||
this.password.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, GridLayout.Alignment.CENTER, true, false))
|
|
||||||
.addTo(mainPanel);
|
|
||||||
|
|
||||||
Panel passPanel = new Panel()
|
|
||||||
.setLayoutManager(new GridLayout(3))
|
|
||||||
.setLayoutData(GridLayout.createLayoutData(GridLayout.Alignment.FILL, Alignment.CENTER, true, false));
|
|
||||||
|
|
||||||
passPanel.addComponent(new Label("Password: "))
|
|
||||||
.addComponent(password)
|
|
||||||
.addTo(mainPanel);
|
|
||||||
|
|
||||||
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
|
|
||||||
|
|
||||||
buttonPanel.setLayoutData(
|
|
||||||
GridLayout.createLayoutData(
|
|
||||||
Alignment.END,
|
|
||||||
Alignment.CENTER,
|
|
||||||
false, false))
|
|
||||||
.addTo(mainPanel);
|
|
||||||
|
|
||||||
setComponent(mainPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onOK()
|
|
||||||
{
|
|
||||||
if(username.getText().isEmpty() || password.getText().isEmpty())
|
|
||||||
{
|
|
||||||
MessageDialog.showMessageDialog(getTextGUI(), getTitle(), "Username and password cannot be blank", MessageDialogButton.OK);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.user = username.getText();
|
|
||||||
this.pass = password.getText();
|
|
||||||
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onCancel()
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] showDialog(WindowBasedTextGUI textGUI)
|
|
||||||
{
|
|
||||||
user = null;
|
|
||||||
pass = null;
|
|
||||||
super.showDialog(textGUI);
|
|
||||||
return new String[] {user, pass};
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,13 +2,12 @@ package xyz.thastertyn.Window;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import com.googlecode.lanterna.TextColor;
|
import com.googlecode.lanterna.TextColor;
|
||||||
import com.googlecode.lanterna.gui2.BasicWindow;
|
import com.googlecode.lanterna.gui2.BasicWindow;
|
||||||
import com.googlecode.lanterna.gui2.Borders;
|
|
||||||
import com.googlecode.lanterna.gui2.DefaultWindowManager;
|
import com.googlecode.lanterna.gui2.DefaultWindowManager;
|
||||||
import com.googlecode.lanterna.gui2.Direction;
|
import com.googlecode.lanterna.gui2.Direction;
|
||||||
import com.googlecode.lanterna.gui2.EmptySpace;
|
import com.googlecode.lanterna.gui2.EmptySpace;
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||||
import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
|
import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
@ -19,58 +18,53 @@ import com.googlecode.lanterna.screen.TerminalScreen;
|
|||||||
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
|
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
|
||||||
import com.googlecode.lanterna.terminal.Terminal;
|
import com.googlecode.lanterna.terminal.Terminal;
|
||||||
|
|
||||||
import xyz.thastertyn.Jecna.Credentials;
|
|
||||||
import xyz.thastertyn.Jecna.Login;
|
|
||||||
|
|
||||||
public class MainWindow {
|
public class MainWindow {
|
||||||
|
|
||||||
Login l = new Login();
|
|
||||||
|
|
||||||
|
private Terminal terminal;
|
||||||
|
private Screen screen;
|
||||||
|
private Window window;
|
||||||
|
private MultiWindowTextGUI textGUI;
|
||||||
|
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Terminal terminal = null;
|
|
||||||
try {
|
try {
|
||||||
|
//#region init
|
||||||
// Setup terminal and screen layers
|
// Setup terminal and screen layers
|
||||||
terminal = new DefaultTerminalFactory().createTerminal();
|
terminal = new DefaultTerminalFactory().createTerminal();
|
||||||
|
|
||||||
Screen screen = new TerminalScreen(terminal);
|
screen = new TerminalScreen(terminal);
|
||||||
screen.startScreen();
|
screen.startScreen();
|
||||||
|
|
||||||
|
// Create window to hold the panel
|
||||||
|
window = new BasicWindow();
|
||||||
|
window.setHints(Arrays.asList(Window.Hint.CENTERED));
|
||||||
|
|
||||||
|
// Create gui and start gui
|
||||||
|
textGUI = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLACK_BRIGHT));
|
||||||
|
//#endregion
|
||||||
|
|
||||||
// Create panel to hold components
|
// Create panel to hold components
|
||||||
final Panel mainPanel = new Panel();
|
final Panel mainPanel = new Panel();
|
||||||
mainPanel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
mainPanel.setLayoutManager(new LinearLayout(Direction.VERTICAL));
|
||||||
|
|
||||||
// Create window to hold the panel
|
|
||||||
BasicWindow window = new BasicWindow();
|
|
||||||
window.setComponent(mainPanel);
|
window.setComponent(mainPanel);
|
||||||
window.setHints(Arrays.asList(Window.Hint.CENTERED));
|
|
||||||
|
|
||||||
mainPanel.addComponent(new Separator(Direction.VERTICAL).setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill)));
|
mainPanel.addComponent(new Separator(Direction.VERTICAL).setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill)));
|
||||||
|
|
||||||
final Panel content = new Panel();
|
Panel content = new Panel();
|
||||||
mainPanel.addComponent(content);
|
content.addTo(mainPanel);
|
||||||
|
|
||||||
xyz.thastertyn.Window.Login login = new xyz.thastertyn.Window.Login();
|
Login login = new Login();
|
||||||
|
login.showDialog(textGUI);
|
||||||
|
|
||||||
/*Rozvrh r = new Rozvrh();
|
window.addWindowListener(new WindowSwitchListener(content, login.getJessionId()));
|
||||||
r.download(login.getJsessionId());
|
|
||||||
|
textGUI.addWindowAndWait(window);
|
||||||
content.addComponent(r.getPanel());*/
|
|
||||||
|
|
||||||
// Create gui and start gui
|
|
||||||
final MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLACK_BRIGHT));
|
|
||||||
|
|
||||||
login.showDialog(gui);
|
} catch (IOException e) {
|
||||||
/*KeyStroke k = terminal.readInput();
|
e.printStackTrace();
|
||||||
if(k.equals(KeyStroke.fromString("<up>")))
|
}
|
||||||
{
|
|
||||||
window.close();
|
|
||||||
}*/
|
|
||||||
gui.addWindowAndWait(window);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package xyz.thastertyn.Window;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.TerminalSize;
|
|
||||||
import com.googlecode.lanterna.TextColor;
|
|
||||||
import com.googlecode.lanterna.graphics.SimpleTheme;
|
|
||||||
import com.googlecode.lanterna.gui2.Direction;
|
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
|
||||||
import com.googlecode.lanterna.gui2.Separator;
|
|
||||||
import com.googlecode.lanterna.gui2.TextGUIGraphics;
|
|
||||||
import com.googlecode.lanterna.gui2.table.Table;
|
|
||||||
import com.googlecode.lanterna.gui2.table.TableCellRenderer;
|
|
||||||
|
|
||||||
public class Rozvrh {
|
|
||||||
|
|
||||||
private Panel rozvrhPanel = new Panel();
|
|
||||||
|
|
||||||
private xyz.thastertyn.Jecna.Rozvrh rozvrh = new xyz.thastertyn.Jecna.Rozvrh();
|
|
||||||
|
|
||||||
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"};
|
|
||||||
|
|
||||||
String[] days = {"PO", "UT", "ST", "CT", "PA"};
|
|
||||||
|
|
||||||
Table<String> t = new Table<>(labels);
|
|
||||||
|
|
||||||
public byte download(String Jsessionid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
rozvrh.downloadRozvrh(Jsessionid);
|
|
||||||
|
|
||||||
String[][] r = rozvrh.getRozvrh();
|
|
||||||
|
|
||||||
String[] s = new String[labels.length];
|
|
||||||
|
|
||||||
for(int i = 0; i < r.length; i++)
|
|
||||||
{
|
|
||||||
s[0] = days[i];
|
|
||||||
for(int j = 1; j < r[i].length; j++) { s[j] = r[i][j]; }
|
|
||||||
|
|
||||||
t.getTableModel().addRow(s);
|
|
||||||
}
|
|
||||||
t.addTo(rozvrhPanel);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}catch(UnknownHostException e)
|
|
||||||
{
|
|
||||||
return 127;
|
|
||||||
}catch(IOException e)
|
|
||||||
{
|
|
||||||
return 126;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Panel getPanel()
|
|
||||||
{
|
|
||||||
return rozvrhPanel;
|
|
||||||
}
|
|
||||||
}
|
|
123
src/main/java/xyz/thastertyn/Window/WindowSwitchListener.java
Normal file
123
src/main/java/xyz/thastertyn/Window/WindowSwitchListener.java
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
package xyz.thastertyn.Window;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.TerminalPosition;
|
||||||
|
import com.googlecode.lanterna.TerminalSize;
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.Window;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowListener;
|
||||||
|
import com.googlecode.lanterna.input.KeyStroke;
|
||||||
|
import com.googlecode.lanterna.input.KeyType;
|
||||||
|
|
||||||
|
import xyz.thastertyn.Window.Content.JecnaContent;
|
||||||
|
import xyz.thastertyn.Window.Content.Rozvrh;
|
||||||
|
import xyz.thastertyn.Window.Content.Znamky;
|
||||||
|
|
||||||
|
public class WindowSwitchListener implements WindowListener {
|
||||||
|
|
||||||
|
WindowBasedTextGUI gui;
|
||||||
|
|
||||||
|
private JecnaContent[] contents = {new Rozvrh(), new Znamky()};
|
||||||
|
|
||||||
|
private String JsessionId;
|
||||||
|
|
||||||
|
Panel panel;
|
||||||
|
Label label;
|
||||||
|
|
||||||
|
int current = 0;
|
||||||
|
|
||||||
|
public WindowSwitchListener(Panel holder, String JsessionId)
|
||||||
|
{
|
||||||
|
panel = holder;
|
||||||
|
this.JsessionId = JsessionId;
|
||||||
|
this.label = label;
|
||||||
|
defaultPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void defaultPanel()
|
||||||
|
{
|
||||||
|
contents[0].download(JsessionId);
|
||||||
|
panel.removeAllComponents();
|
||||||
|
panel.addComponent(contents[0].getPanel());
|
||||||
|
//label.setText(contents[0].getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void next()
|
||||||
|
{
|
||||||
|
if(current + 1 == contents.length)
|
||||||
|
{
|
||||||
|
current = 0;
|
||||||
|
}else{
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!contents[current].hasStarted())
|
||||||
|
{
|
||||||
|
contents[current].download(JsessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
panel.removeAllComponents();
|
||||||
|
panel.addComponent(contents[current].getPanel());
|
||||||
|
|
||||||
|
//label.setText(contents[current].getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void previous()
|
||||||
|
{
|
||||||
|
if(current - 1 == -1)
|
||||||
|
{
|
||||||
|
current = contents.length - 1;
|
||||||
|
}else{
|
||||||
|
current--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!contents[current].hasStarted())
|
||||||
|
{
|
||||||
|
contents[current].download(JsessionId);
|
||||||
|
}
|
||||||
|
panel.removeAllComponents();
|
||||||
|
panel.addComponent(contents[current].getPanel());
|
||||||
|
|
||||||
|
//label.setText(contents[current].getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInput(Window basePane, KeyStroke keyStroke, AtomicBoolean deliverEvent) {
|
||||||
|
KeyType type = keyStroke.getKeyType();
|
||||||
|
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case Tab:
|
||||||
|
if(!keyStroke.isShiftDown())
|
||||||
|
{
|
||||||
|
next();
|
||||||
|
}else{
|
||||||
|
previous();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResized(Window window, TerminalSize oldSize, TerminalSize newSize) {
|
||||||
|
window.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/xyz/thastertyn/Jecna/Jidelna.class
Normal file
BIN
target/classes/xyz/thastertyn/Jecna/Jidelna.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/xyz/thastertyn/Window/Content/JecnaContent.class
Normal file
BIN
target/classes/xyz/thastertyn/Window/Content/JecnaContent.class
Normal file
Binary file not shown.
BIN
target/classes/xyz/thastertyn/Window/Content/Jidelna.class
Normal file
BIN
target/classes/xyz/thastertyn/Window/Content/Jidelna.class
Normal file
Binary file not shown.
BIN
target/classes/xyz/thastertyn/Window/Content/Rozvrh.class
Normal file
BIN
target/classes/xyz/thastertyn/Window/Content/Rozvrh.class
Normal file
Binary file not shown.
BIN
target/classes/xyz/thastertyn/Window/Content/Znamky.class
Normal file
BIN
target/classes/xyz/thastertyn/Window/Content/Znamky.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/xyz/thastertyn/Window/WindowSwitchListener.class
Normal file
BIN
target/classes/xyz/thastertyn/Window/WindowSwitchListener.class
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user