Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/client/cadclientgui/screens/Login.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 59, 7.7 KB checked in by jdalbey, 9 years ago (diff)

Merge CAD Client updates for multiple incident view windows.

RevLine 
1package tmcsim.client.cadclientgui.screens;
2
3import java.awt.Color;
4import static java.awt.Component.LEFT_ALIGNMENT;
5import java.awt.Dimension;
6import java.awt.Font;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
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 * This class contains the view and controller for the Login screen. The view
20 * was not built using a GUI builder plug-in (but may want to consider doing so
21 * in the future), and the controller uses listeners to control how the view and
22 * data act.
23 *
24 * @author Vincent
25 */
26public class Login extends JFrame
27{
28    private Box login;
29    private JTextField userNameField;
30    private JTextField passwordField;
31    public static String kNamePrompt = "Enter your name";
32
33    public Login()
34    {
35        initView();
36    }
37
38    private ActionListener newEnterActionListener()
39    {
40        return new ActionListener()
41        {
42            public void actionPerformed(ActionEvent e)
43            {
44                setVisible(false);
45                // Check if user provided a username JD
46                String userEntry = userNameField.getText();
47                if (userEntry.equals(kNamePrompt))
48                {
49                    ScreenManager.setUserName("Anonymous Trainee");
50                }
51                else
52                {
53                    ScreenManager.setUserName(userEntry);
54                }
55                ScreenManager.openCADMenu();
56                ScreenManager.openAssignedIncidents();
57                ScreenManager.openUnitStatus();
58                ScreenManager.openPendingIncidents();
59                ScreenManager.openPowerlineUI();
60                if (!passwordField.getText().equals("Dispatcher"))
61                {
62                    ScreenManager.setDispatcherAuthority(false);
63                }
64            }
65        };
66    }
67
68    private ActionListener newExitActionListener()
69    {
70        return new ActionListener()
71        {
72            public void actionPerformed(ActionEvent e)
73            {
74                System.exit(0);
75            }
76        };
77    }
78
79    private void initView()
80    {
81        login = new Box(BoxLayout.Y_AXIS);
82        login.setAlignmentX(LEFT_ALIGNMENT);
83        JPanel whiteBackground = new JPanel();
84        whiteBackground.setAlignmentX(LEFT_ALIGNMENT);
85        whiteBackground.setBackground(Color.WHITE);
86        whiteBackground.setMaximumSize(new Dimension(750, 150));
87        whiteBackground.setMinimumSize(new Dimension(750, 150));
88        whiteBackground.setPreferredSize(new Dimension(750, 150));
89        login.add(whiteBackground);
90
91        JPanel blueBackground = new JPanel();
92        blueBackground.setAlignmentX(LEFT_ALIGNMENT);
93        blueBackground.setBackground(new Color(50, 150, 200));
94        blueBackground.setMaximumSize(new Dimension(750, 350));
95        blueBackground.setMinimumSize(new Dimension(750, 350));
96        blueBackground.setPreferredSize(new Dimension(750, 350));
97
98        JLabel title = new JLabel();
99        // Check if we are running from a jar to put message from manifest into title
100        Package clientpkg = Login.class.getPackage();
101        String builddate = clientpkg.getImplementationVersion();
102        String version = "";
103        if (builddate != null)
104        {
105            version = "          (build " + builddate + ")";
106        }
107        else // We're running from a dev environment
108        {
109            version = "           00-00-00 00:00";
110        }
111
112        title.setText("Inform CAD 5.3 Patch 5 ");
113        title.setHorizontalAlignment(SwingConstants.CENTER);
114        title.setFont(new Font("Arial", Font.PLAIN, 22));
115        title.setForeground(Color.WHITE);
116        title.setMaximumSize(new Dimension(750, 100));
117        title.setMinimumSize(new Dimension(750, 100));
118        title.setPreferredSize(new Dimension(750, 100));
119        blueBackground.add(title);
120
121        JLabel builddateLabel = new JLabel(version);
122        builddateLabel.setForeground(Color.WHITE);
123        builddateLabel.setHorizontalAlignment(SwingConstants.CENTER);
124        blueBackground.add(builddateLabel);
125
126        Box leftBox = new Box(BoxLayout.Y_AXIS);
127        leftBox.setMaximumSize(new Dimension(350, 50));
128        leftBox.setMinimumSize(new Dimension(350, 50));
129        leftBox.setPreferredSize(new Dimension(350, 50));
130        leftBox.setAlignmentX(LEFT_ALIGNMENT);
131
132        JLabel userNameLabel = new JLabel("User name ");
133        userNameLabel.setForeground(Color.WHITE);
134        userNameField = new JTextField(kNamePrompt);
135        Box userNameBox = new Box(BoxLayout.X_AXIS);
136        userNameBox.setAlignmentX(LEFT_ALIGNMENT);
137        userNameBox.add(Box.createHorizontalStrut(10));
138        userNameBox.add(userNameLabel);
139        userNameBox.add(userNameField);
140        leftBox.add(userNameBox);
141
142        JLabel passwordLabel = new JLabel("Password  ");
143        passwordLabel.setForeground(Color.WHITE);
144        passwordField = new JTextField("Not required");
145        Box passwordBox = new Box(BoxLayout.X_AXIS);
146        passwordBox.setAlignmentX(LEFT_ALIGNMENT);
147        passwordBox.add(Box.createHorizontalStrut(10));
148        passwordBox.add(passwordLabel);
149        passwordBox.add(passwordField);
150        leftBox.add(Box.createVerticalStrut(10));
151        leftBox.add(passwordBox);
152
153        JButton enter = new JButton("Login");
154        enter.addActionListener(newEnterActionListener());
155        JButton newPassword = new JButton("New Password");
156        newPassword.setEnabled(false);
157        JButton exit = new JButton("Exit");
158        exit.addActionListener(newExitActionListener());
159        JButton selectAll = new JButton("Select All");
160        selectAll.setEnabled(false);
161        JButton unselectAll = new JButton("Unselect all");
162        unselectAll.setEnabled(false);
163        Box buttonBox = new Box(BoxLayout.X_AXIS);
164        buttonBox.setAlignmentX(LEFT_ALIGNMENT);
165        buttonBox.add(Box.createHorizontalStrut(75));
166        buttonBox.add(enter);
167        buttonBox.add(Box.createHorizontalStrut(20));
168        buttonBox.add(newPassword);
169        buttonBox.add(Box.createHorizontalStrut(20));
170        buttonBox.add(exit);
171        buttonBox.add(Box.createHorizontalStrut(125));
172        buttonBox.add(selectAll);
173        buttonBox.add(Box.createHorizontalStrut(10));
174        buttonBox.add(unselectAll);
175
176        Box rightBox = new Box(BoxLayout.Y_AXIS);
177        rightBox.setAlignmentX(LEFT_ALIGNMENT);
178        rightBox.setMaximumSize(new Dimension(250, 90));
179        rightBox.setMinimumSize(new Dimension(250, 90));
180        rightBox.setPreferredSize(new Dimension(250, 90));
181        JLabel position = new JLabel("Positions:");
182        position.setPreferredSize(new Dimension(250, 20));
183        position.setMaximumSize(new Dimension(250, 20));
184        position.setMinimumSize(new Dimension(250, 20));
185        position.setBackground(Color.BLACK);
186        position.setHorizontalAlignment(SwingConstants.LEFT);
187        position.setForeground(Color.WHITE);
188        rightBox.add(position);
189        JPanel list = new JPanel();
190        rightBox.add(list);
191
192        Box centerBox = new Box(BoxLayout.X_AXIS);
193        centerBox.setAlignmentX(LEFT_ALIGNMENT);
194        centerBox.add(leftBox);
195        centerBox.add(Box.createHorizontalStrut(75));
196        centerBox.add(rightBox);
197        blueBackground.add(centerBox);
198        blueBackground.add(Box.createVerticalStrut(125));
199        blueBackground.add(buttonBox);
200        login.add(blueBackground);
201
202        getContentPane().add(login);
203        setUndecorated(true);
204        pack();
205        setLocationRelativeTo(null);
206        setDefaultCloseOperation(EXIT_ON_CLOSE);
207        setVisible(true);
208    }
209}
Note: See TracBrowser for help on using the repository browser.