Skip to content

Commit e60d273

Browse files
authored
Merge pull request #8 from Prem0707/GSoC18
created a new window for user authentication options
2 parents 05f86af + 76887b2 commit e60d273

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package gov.doe.jgi.boost.ui;
2+
3+
import javax.swing.GroupLayout;
4+
import javax.swing.JButton;
5+
import javax.swing.JFrame;
6+
import javax.swing.JLabel;
7+
import javax.swing.JPasswordField;
8+
import javax.swing.JTextField;
9+
import javax.swing.SwingConstants;
10+
11+
public class JWTAuthenticationFrame {
12+
13+
public JWTAuthenticationFrame(){
14+
JFrame frame = new JFrame("JWTAuthentication");
15+
frame.setSize(300, 150);
16+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
17+
placeComponents(frame);
18+
frame.setVisible(true);
19+
}
20+
21+
private static void placeComponents(JFrame jFrame) {
22+
23+
GroupLayout layout = new GroupLayout(jFrame.getContentPane());
24+
jFrame.getContentPane().setLayout(layout);
25+
26+
layout.setAutoCreateGaps(true);
27+
layout.setAutoCreateContainerGaps(true);
28+
29+
JLabel jWTTokenText = new JLabel("Please peovide your JWT Token:");
30+
JTextField tokenText = new JTextField(25);
31+
JButton submitButton = new JButton("Submit");
32+
JButton cancelButton = new JButton("Cancel");
33+
34+
layout.setHorizontalGroup(layout.createSequentialGroup()
35+
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
36+
.addComponent(jWTTokenText)
37+
.addComponent(cancelButton))
38+
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING))
39+
.addComponent(tokenText)
40+
.addComponent(submitButton)
41+
);
42+
43+
// we would like the buttons to be always the same size
44+
layout.linkSize(SwingConstants.HORIZONTAL, cancelButton, submitButton);
45+
46+
layout.setVerticalGroup(layout.createSequentialGroup()
47+
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
48+
.addComponent(jWTTokenText)
49+
.addComponent(tokenText))
50+
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
51+
.addComponent(cancelButton)
52+
.addComponent(submitButton))
53+
);
54+
55+
jFrame.pack();
56+
jFrame.setLocationRelativeTo(null);
57+
jFrame.setResizable(true);
58+
}
59+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package gov.doe.jgi.boost.ui;
2+
3+
import javax.swing.GroupLayout;
4+
import javax.swing.JFrame;
5+
import javax.swing.JLabel;
6+
import javax.swing.JRadioButton;
7+
8+
9+
public class UserAuthentication {
10+
11+
12+
public UserAuthentication() {
13+
14+
JFrame jFrame= new JFrame();
15+
jFrame.setTitle("Prepare for Synthesis");
16+
jFrame.setResizable(false);
17+
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18+
placeComponents(jFrame);
19+
jFrame.setSize(400, 200);
20+
21+
// Setting the frame visibility to true
22+
jFrame.setVisible(true);
23+
}
24+
25+
26+
private void placeComponents(JFrame jFrame) {
27+
28+
GroupLayout layout = new GroupLayout(jFrame.getContentPane());
29+
jFrame.getContentPane().setLayout(layout);
30+
31+
layout.setAutoCreateGaps(true);
32+
layout.setAutoCreateContainerGaps(true);
33+
34+
JLabel headingText = new JLabel("Please choose one of the given way to Authenticate your Account:");
35+
JRadioButton buttonLogin = new JRadioButton("Login");
36+
JRadioButton buttonJWT = new JRadioButton("Provide your JWT");
37+
JRadioButton buttonSignUp = new JRadioButton("Sign Up");
38+
39+
layout.setHorizontalGroup(
40+
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
41+
.addComponent(headingText)
42+
.addComponent(buttonLogin)
43+
.addComponent(buttonJWT)
44+
.addComponent(buttonSignUp)
45+
);
46+
47+
layout.setVerticalGroup(
48+
layout.createSequentialGroup()
49+
.addComponent(headingText)
50+
.addComponent(buttonLogin)
51+
.addComponent(buttonJWT)
52+
.addComponent(buttonSignUp)
53+
);
54+
55+
jFrame.pack();
56+
jFrame.setLocationRelativeTo(null);
57+
}
58+
}

src/test/java/gov/doe/jgi/boost/client/DemoClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gov.doe.jgi.boost.enums.FileFormat;
1111
import gov.doe.jgi.boost.enums.Strategy;
1212
import gov.doe.jgi.boost.enums.Vendor;
13+
import gov.doe.jgi.boost.ui.UserAuthentication;
1314

1415
/**
1516
* The DemoClient exemplifies how to invoke each functionality
@@ -35,6 +36,7 @@ public static void main(String[] args)
3536
BOOSTClient client = new BOOSTClient(LoginCredentials.mJWT);
3637
// -- alternative 2: provider you BOOST username and password
3738
//BOOSTClient client = new BOOSTClient(LoginCredentials.mUserName, LoginCredentials.mPassword);
39+
new UserAuthentication();
3840

3941
// get the predefined hosts
4042
JSONObject jsonPredefinedHosts = client.getPredefinedHosts();

0 commit comments

Comments
 (0)