Skip to content
Snippets Groups Projects
Commit a8f8b745 authored by joalhelk's avatar joalhelk
Browse files

added logout method

parent ceea8a59
No related branches found
No related tags found
No related merge requests found
...@@ -37,4 +37,10 @@ public class User { ...@@ -37,4 +37,10 @@ public class User {
public static String getToken() { public static String getToken() {
return token; return token;
} }
public static void clear() {
User.name = null;
User.email = null;
User.token = null;
}
} }
...@@ -33,6 +33,8 @@ public class WelcomePage implements MouseListener { ...@@ -33,6 +33,8 @@ public class WelcomePage implements MouseListener {
private final JLabel friendsLabel; private final JLabel friendsLabel;
private final JLabel helpLabel; private final JLabel helpLabel;
private final JLabel settingsLabel; private final JLabel settingsLabel;
private final JLabel logoutLabel;
private final JFrame frame;
public WelcomePage(){ public WelcomePage(){
Map<String, String> temperatures = HttpRequests.getNodeData(1); Map<String, String> temperatures = HttpRequests.getNodeData(1);
...@@ -78,7 +80,7 @@ public class WelcomePage implements MouseListener { ...@@ -78,7 +80,7 @@ public class WelcomePage implements MouseListener {
chart.setBounds(15, 10, width - leftPanelWidth - 30, cardPanelHeight - 20); chart.setBounds(15, 10, width - leftPanelWidth - 30, cardPanelHeight - 20);
chartPanel.add(chart); chartPanel.add(chart);
JFrame frame = new JFrame(); frame = new JFrame();
frame.getContentPane().setBackground( new Color(128, 127, 137) ); frame.getContentPane().setBackground( new Color(128, 127, 137) );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null); frame.getContentPane().setLayout(null);
...@@ -149,6 +151,18 @@ public class WelcomePage implements MouseListener { ...@@ -149,6 +151,18 @@ public class WelcomePage implements MouseListener {
settingsLabel.addMouseListener(this); settingsLabel.addMouseListener(this);
settingsLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); settingsLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
leftPanel.add(settingsLabel); leftPanel.add(settingsLabel);
logoutLabel = new JLabel("Logout");
logoutLabel.setVerticalAlignment(SwingConstants.BOTTOM);
logoutLabel.setHorizontalAlignment(SwingConstants.CENTER);
logoutLabel.setBounds(884, 6, 48, 20);
logoutLabel.setForeground(Color.WHITE);
logoutLabel.setFont(new Font("Apple SD Gothic Neo", Font.PLAIN, 16));
logoutLabel.addMouseListener(this);
bottomPanel.setLayout(null);
logoutLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
bottomPanel.add(logoutLabel);
frame.getContentPane().add(cardPanel); frame.getContentPane().add(cardPanel);
frame.getContentPane().add(chartPanel); frame.getContentPane().add(chartPanel);
frame.getContentPane().add(bottomPanel); frame.getContentPane().add(bottomPanel);
...@@ -165,21 +179,13 @@ public class WelcomePage implements MouseListener { ...@@ -165,21 +179,13 @@ public class WelcomePage implements MouseListener {
@Override @Override
public void mouseEntered(MouseEvent arg0) { public void mouseEntered(MouseEvent arg0) {
Object target = arg0.getSource(); Object target = arg0.getSource();
if (target == nodeDataLabel) nodeDataLabel.setForeground(lightgray); ((JComponent) target).setForeground(lightgray);
else if (target == nodeSettingsLabel) nodeSettingsLabel.setForeground(lightgray);
else if (target == friendsLabel) friendsLabel.setForeground(lightgray);
else if (target == helpLabel) helpLabel.setForeground(lightgray);
else if (target == settingsLabel) settingsLabel.setForeground(lightgray);
} }
@Override @Override
public void mouseExited(MouseEvent arg0) { public void mouseExited(MouseEvent arg0) {
Object target = arg0.getSource(); Object target = arg0.getSource();
if (target == nodeDataLabel) nodeDataLabel.setForeground(Color.WHITE); ((JComponent) target).setForeground(Color.WHITE);
else if (target == nodeSettingsLabel) nodeSettingsLabel.setForeground(Color.WHITE);
else if (target == friendsLabel) friendsLabel.setForeground(Color.WHITE);
else if (target == helpLabel) helpLabel.setForeground(Color.WHITE);
else if (target == settingsLabel) settingsLabel.setForeground(Color.WHITE);
} }
@Override @Override
...@@ -190,7 +196,25 @@ public class WelcomePage implements MouseListener { ...@@ -190,7 +196,25 @@ public class WelcomePage implements MouseListener {
@Override @Override
public void mouseReleased(MouseEvent arg0) { public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub if(arg0.getSource() == logoutLabel) {
handleLogout();
}
} }
// Logs the user out and clears user data
// Closes current window and opens loginpage
private void handleLogout() {
String message = "Are you sure you want to logout?";
String title = "Logout?";
int result = JOptionPane.showConfirmDialog(frame, message, title,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(result == JOptionPane.YES_OPTION) {
User.clear();
frame.dispose();
LoginPage login = new LoginPage();
}
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment