LoginDialog and source target
Source target changed to 1.8 to allow a few things
This commit is contained in:
1 parent
a66d67676f
commit
4464cd2840
24 files changed
+178
-12
No files matched your search
@@ -9,10 +9,7 @@ import xyz.thastertyn.Window.MainWindow;
|
||||
*/
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
//System.out.println("Hello World!");
|
||||
|
||||
//Login l = new Login();
|
||||
//l.login(Credentials.user, Credentials.pass);
|
||||
System.out.println("Hello World!");
|
||||
|
||||
MainWindow window = new MainWindow();
|
||||
window.run();
|
||||
|
||||
@@ -43,6 +43,25 @@ public class Login {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void saveCredentials(String user, String pass)
|
||||
{
|
||||
File credentials = null;
|
||||
|
||||
if(System.getProperty("os.name").equals("Linux"))
|
||||
{
|
||||
credentials = new File("~/.local/share/jecnak/credentials.json");
|
||||
|
||||
}else if(System.getProperty("os.name").contains("Windows"))
|
||||
{
|
||||
credentials = new File(System.getenv("APPDATA\\jecnak\\"));
|
||||
}
|
||||
|
||||
if(!credentials.exists())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getJSESSIONID()
|
||||
{
|
||||
return Jsessionid;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package xyz.thastertyn.Window;
|
||||
|
||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
|
||||
public class Login {
|
||||
|
||||
String user = "";
|
||||
String pass = "";
|
||||
|
||||
xyz.thastertyn.Jecna.Login login = new xyz.thastertyn.Jecna.Login();
|
||||
|
||||
LoginDialog dialog = new LoginDialog("Login", "Enter your username and password");
|
||||
|
||||
public void showDialog(WindowBasedTextGUI textGUI)
|
||||
{
|
||||
String[] input = dialog.showDialog(textGUI);
|
||||
|
||||
user = input[0];
|
||||
pass = input[1];
|
||||
|
||||
login();
|
||||
}
|
||||
|
||||
private void login()
|
||||
{
|
||||
login.login(user, pass);
|
||||
|
||||
user = null;
|
||||
pass = null;
|
||||
}
|
||||
|
||||
public String getJsessionId()
|
||||
{
|
||||
return login.getJSESSIONID();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
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};
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||
|
||||
import com.googlecode.lanterna.TextColor;
|
||||
import com.googlecode.lanterna.gui2.BasicWindow;
|
||||
import com.googlecode.lanterna.gui2.Borders;
|
||||
import com.googlecode.lanterna.gui2.DefaultWindowManager;
|
||||
import com.googlecode.lanterna.gui2.Direction;
|
||||
import com.googlecode.lanterna.gui2.EmptySpace;
|
||||
@@ -49,16 +50,17 @@ public class MainWindow {
|
||||
final Panel content = new Panel();
|
||||
mainPanel.addComponent(content);
|
||||
|
||||
Login l = new Login();
|
||||
l.login(Credentials.user, Credentials.pass);
|
||||
Rozvrh r = new Rozvrh();
|
||||
r.download(l.getJSESSIONID());
|
||||
xyz.thastertyn.Window.Login login = new xyz.thastertyn.Window.Login();
|
||||
|
||||
/*Rozvrh r = new Rozvrh();
|
||||
r.download(login.getJsessionId());
|
||||
|
||||
content.addComponent(r.getPanel());
|
||||
|
||||
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);
|
||||
/*KeyStroke k = terminal.readInput();
|
||||
if(k.equals(KeyStroke.fromString("<up>")))
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user