source: tmcsimulator/trunk/src/tmcsim/client/cadclientgui/screens/Login.java @ 3

Revision 3, 6.5 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files - cadclientgui

Line 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.Color;
4import java.awt.Dimension;
5import java.awt.Font;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8
9import javax.swing.Box;
10import javax.swing.BoxLayout;
11import javax.swing.JButton;
12import javax.swing.JFrame;
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15import javax.swing.JTextField;
16import javax.swing.SwingConstants;
17
18
19/**
20 * This class contains the view and controller for the Login screen. The view was not built using a GUI builder plug-in
21 * (but may want to consider doing so in the future), and the controller uses listeners to control how the view and data act.
22 *
23 * @author Vincent
24 */
25
26public class Login extends JFrame {
27
28    private Box login;
29    private JTextField userNameField;
30    private JTextField passwordField;
31
32    public Login() {
33        initView();
34    }
35   
36    private ActionListener newEnterActionListener(){
37        return new ActionListener() {
38            public void actionPerformed(ActionEvent e) {
39                setVisible(false);
40                ScreenManager.setUserName(userNameField.getText());
41                ScreenManager.openCADMenu();
42                ScreenManager.openAssignedIncidents();
43                ScreenManager.openUnitStatus();
44                ScreenManager.openPendingIncidents();
45                ScreenManager.openPowerlineUI();
46                if (!passwordField.getText().equals("Dispatcher")) {
47                    ScreenManager.setDispatcherAuthority(false);
48                }
49            }
50        };
51    }
52   
53    private ActionListener newExitActionListener(){
54        return new ActionListener() {
55            public void actionPerformed(ActionEvent e) {
56                System.exit(0);
57            }
58        };
59    }
60   
61    private void initView(){
62        login = new Box(BoxLayout.Y_AXIS);
63        login.setAlignmentX(LEFT_ALIGNMENT);
64        JPanel whiteBackground = new JPanel();
65        whiteBackground.setAlignmentX(LEFT_ALIGNMENT);
66        whiteBackground.setBackground(Color.WHITE);
67        whiteBackground.setMaximumSize(new Dimension(750, 150));
68        whiteBackground.setMinimumSize(new Dimension(750, 150));
69        whiteBackground.setPreferredSize(new Dimension(750, 150));
70        login.add(whiteBackground);
71
72        JPanel blueBackground = new JPanel();
73        blueBackground.setAlignmentX(LEFT_ALIGNMENT);
74        blueBackground.setBackground(new Color(50, 150, 200));
75        blueBackground.setMaximumSize(new Dimension(750, 350));
76        blueBackground.setMinimumSize(new Dimension(750, 350));
77        blueBackground.setPreferredSize(new Dimension(750, 350));
78
79        JLabel title = new JLabel();
80        title.setText("Inform CAD 5.3 Patch 5");
81        title.setHorizontalAlignment(SwingConstants.CENTER);
82        title.setFont(new Font("Arial", Font.PLAIN, 22));
83        title.setForeground(Color.WHITE);
84        title.setMaximumSize(new Dimension(750, 100));
85        title.setMinimumSize(new Dimension(750, 100));
86        title.setPreferredSize(new Dimension(750, 100));
87        blueBackground.add(title);
88
89        Box leftBox = new Box(BoxLayout.Y_AXIS);
90        leftBox.setMaximumSize(new Dimension(350, 50));
91        leftBox.setMinimumSize(new Dimension(350, 50));
92        leftBox.setPreferredSize(new Dimension(350, 50));
93        leftBox.setAlignmentX(LEFT_ALIGNMENT);
94
95        JLabel userNameLabel = new JLabel("User name ");
96        userNameLabel.setForeground(Color.WHITE);
97        userNameField = new JTextField("Enter your name");
98        Box userNameBox = new Box(BoxLayout.X_AXIS);
99        userNameBox.setAlignmentX(LEFT_ALIGNMENT);
100        userNameBox.add(Box.createHorizontalStrut(10));
101        userNameBox.add(userNameLabel);
102        userNameBox.add(userNameField);
103        leftBox.add(userNameBox);
104
105        JLabel passwordLabel = new JLabel("Password  ");
106        passwordLabel.setForeground(Color.WHITE);
107        passwordField = new JTextField("Does not matter");
108        Box passwordBox = new Box(BoxLayout.X_AXIS);
109        passwordBox.setAlignmentX(LEFT_ALIGNMENT);
110        passwordBox.add(Box.createHorizontalStrut(10));
111        passwordBox.add(passwordLabel);
112        passwordBox.add(passwordField);
113        leftBox.add(Box.createVerticalStrut(10));
114        leftBox.add(passwordBox);
115
116        JButton enter = new JButton("Login");
117        enter.addActionListener(newEnterActionListener());
118        JButton newPassword = new JButton("New Password");
119        newPassword.setEnabled(false);
120        JButton exit = new JButton("Exit");
121        exit.addActionListener(newExitActionListener());
122        JButton selectAll = new JButton("Select All");
123        selectAll.setEnabled(false);
124        JButton unselectAll = new JButton("Unselect all");
125        unselectAll.setEnabled(false);
126        Box buttonBox = new Box(BoxLayout.X_AXIS);
127        buttonBox.setAlignmentX(LEFT_ALIGNMENT);
128        buttonBox.add(Box.createHorizontalStrut(75));
129        buttonBox.add(enter);
130        buttonBox.add(Box.createHorizontalStrut(20));
131        buttonBox.add(newPassword);
132        buttonBox.add(Box.createHorizontalStrut(20));
133        buttonBox.add(exit);
134        buttonBox.add(Box.createHorizontalStrut(125));
135        buttonBox.add(selectAll);
136        buttonBox.add(Box.createHorizontalStrut(10));
137        buttonBox.add(unselectAll);
138
139        Box rightBox = new Box(BoxLayout.Y_AXIS);
140        rightBox.setAlignmentX(LEFT_ALIGNMENT);
141        rightBox.setMaximumSize(new Dimension(250, 90));
142        rightBox.setMinimumSize(new Dimension(250, 90));
143        rightBox.setPreferredSize(new Dimension(250, 90));
144        JLabel position = new JLabel("Positions:");
145        position.setPreferredSize(new Dimension(250, 20));
146        position.setMaximumSize(new Dimension(250, 20));
147        position.setMinimumSize(new Dimension(250, 20));
148        position.setBackground(Color.BLACK);
149        position.setHorizontalAlignment(SwingConstants.LEFT);
150        position.setForeground(Color.WHITE);
151        rightBox.add(position);
152        JPanel list = new JPanel();
153        rightBox.add(list);
154
155        Box centerBox = new Box(BoxLayout.X_AXIS);
156        centerBox.setAlignmentX(LEFT_ALIGNMENT);
157        centerBox.add(leftBox);
158        centerBox.add(Box.createHorizontalStrut(75));
159        centerBox.add(rightBox);
160        blueBackground.add(centerBox);
161        blueBackground.add(Box.createVerticalStrut(125));
162        blueBackground.add(buttonBox);
163        login.add(blueBackground);
164
165        getContentPane().add(login);
166        setUndecorated(true);
167        pack();
168        setLocationRelativeTo(null);
169        setDefaultCloseOperation(EXIT_ON_CLOSE);
170        setVisible(true);
171    }
172}
Note: See TracBrowser for help on using the repository browser.