Changeset 532 in tmcsimulator for trunk/src/tmcsim
- Timestamp:
- 11/27/2019 07:56:32 AM (6 years ago)
- Location:
- trunk/src/tmcsim
- Files:
-
- 3 edited
-
application.properties (modified) (1 diff)
-
client/CADClient.java (modified) (7 diffs)
-
client/cadclientgui/screens/Login.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/application.properties
r523 r532 1 # Tue, 12 Nov 2019 08:57:23 -08001 #Wed, 27 Nov 2019 09:34:13 -0800 2 2 3 Application.revision=5 223 Application.revision=531 4 4 5 Application.buildnumber=19 85 Application.buildnumber=199 -
trunk/src/tmcsim/client/CADClient.java
r525 r532 9 9 import java.awt.event.WindowEvent; 10 10 import java.awt.event.WindowListener; 11 import java.awt.image.BufferedImage; 12 import java.io.File; 11 13 import java.io.FileInputStream; 12 14 import java.io.FileOutputStream; … … 19 21 import java.util.logging.Level; 20 22 import java.util.logging.Logger; 23 import javax.imageio.ImageIO; 24 import javax.swing.ImageIcon; 21 25 import javax.swing.JDialog; 22 26 … … 88 92 "CADRmiPort"), CLIENT_CAD_POS("CADPosition"), CLIENT_USER_ID( 89 93 "CADUserID"), KEYBOARD_TYPE("KeyboardType"), DISPLAY_TYPE( 90 "DisplayType") ;94 "DisplayType"), STUDENT_NAMES_FILE("StudentNamesFile"); 91 95 92 96 public String name; … … 182 186 // This ensures they all have access to each other and the data model 183 187 theClientGUI.screen = new ScreenManager(theCoorInt); 184 theClientGUI.login = new Login( );188 theClientGUI.login = new Login(cadClientProp.getProperty(PROPERTIES.STUDENT_NAMES_FILE.name).trim()); 185 189 theClientGUI.client = this; 186 190 … … 345 349 // CAD Simulator's connection information. 346 350 if (cadClientProp.getProperty(PROPERTIES.CAD_SIM_HOST.name) == null 347 || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null) { 351 || cadClientProp.getProperty(PROPERTIES.CAD_SIM_PORT.name) == null 352 || cadClientProp.getProperty(PROPERTIES.STUDENT_NAMES_FILE.name) == null) { 348 353 cadClientLogger.logp(Level.SEVERE, "SimulationManager", 349 354 "Constructor", "Null value in properties file."); … … 522 527 private JDialog createSplashScreen() 523 528 { 524 final int dialogSize = 300; // desired width and height of dialog529 final int dialogSize = 268; // desired width and height of dialog 525 530 // create the dialog 526 531 JDialog dlg = new JDialog(null,"VisiCAD loading",Dialog.ModalityType.MODELESS); … … 534 539 // Add the msg to the center of the dialog 535 540 dlg.add(dlgMsg,BorderLayout.CENTER); 541 // Add TriTech banner to top of screen 542 try { 543 BufferedImage myPicture = ImageIO.read(new File("images/CADMenuImages/Tritech.png")); 544 JLabel picLabel = new JLabel(new ImageIcon(myPicture)); 545 dlg.add(picLabel, BorderLayout.NORTH); 546 } catch (IOException ex) { 547 Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); 548 } 536 549 // Set how big we want the dialog to be 537 550 dlg.setSize(dialogSize, dialogSize); -
trunk/src/tmcsim/client/cadclientgui/screens/Login.java
r289 r532 1 1 package tmcsim.client.cadclientgui.screens; 2 2 3 import java.awt.BorderLayout; 3 4 import java.awt.Color; 4 5 import static java.awt.Component.LEFT_ALIGNMENT; … … 9 10 import java.awt.event.KeyEvent; 10 11 import java.awt.event.KeyListener; 12 import java.awt.image.BufferedImage; 13 import java.io.File; 14 import java.io.FileInputStream; 15 import java.io.FileNotFoundException; 16 import java.io.IOException; 17 import java.util.ArrayList; 18 import java.util.Arrays; 19 import java.util.List; 20 import java.util.Scanner; 21 import java.util.Vector; 22 import java.util.logging.Level; 23 import java.util.logging.Logger; 24 import javax.imageio.ImageIO; 11 25 import javax.swing.Box; 12 26 import javax.swing.BoxLayout; 27 import javax.swing.ImageIcon; 13 28 import javax.swing.JButton; 29 import javax.swing.JComboBox; 14 30 import javax.swing.JFrame; 15 31 import javax.swing.JLabel; … … 26 42 * @author Vincent 27 43 */ 28 public class Login extends JFrame implements KeyListener44 public class Login extends JFrame 29 45 { 30 46 private Box login; 31 private J TextField userNameField;47 private JComboBox<String> userNameCombo; 32 48 private JTextField passwordField; 33 49 public static String kNamePrompt = "Enter your name"; 34 35 public Login() 36 { 50 /** a list of student names that will be displayed on the login screen */ 51 private Vector<String> students; 52 53 public Login(String studentNamesFile) 54 { 55 readNamesFile(studentNamesFile); 37 56 initView(); 38 57 } 39 58 59 /** 60 * A list of student names is read from a file. The intent is to allow the 61 * system operators to customize the login display for each training session 62 * with the names of participants in that training. 63 * @param studentNamesFile the full path to a text file of student names 64 * @author jdalbey ticket #206 65 */ 66 private void readNamesFile(String studentNamesFile) 67 { 68 FileInputStream fis = null; 69 try { 70 // Prepare an input stream from the names file 71 fis = new FileInputStream(studentNamesFile); 72 // Scan the names into a string 73 Scanner s = new Scanner(fis).useDelimiter("\\A"); 74 String out = s.next(); 75 // split string into an array 76 String[] results = out.split("\\n"); 77 // Initialize the student name list 78 students = new Vector(); 79 // Make sure to truncate names before putting in list 80 for (String name: results) 81 { 82 String truncName = name.trim(); 83 // Limit name length so it fits in the combo box 84 if (truncName.length() > 26) 85 { 86 truncName = truncName.substring(0,25); 87 } 88 // Add the validated name to the list of students 89 students.add(truncName); 90 } 91 // Append the default name 92 students.add("Anonymous Trainee"); 93 } catch (FileNotFoundException ex) { 94 Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); 95 } finally { 96 try { 97 fis.close(); 98 } catch (IOException ex) { 99 Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); 100 } 101 } 102 } 40 103 private ActionListener newEnterActionListener() 41 104 { … … 45 108 { 46 109 setVisible(false); 47 // Check if user provided a username JD 48 String userEntry = userNameField.getText(); 49 if (userEntry.equals(kNamePrompt)) 50 { 51 ScreenManager.setUserName("Anonymous Trainee"); 52 } 53 else 54 { 55 ScreenManager.setUserName(userEntry); 56 } 110 // Extract the selected student name from the combo box 111 String userEntry = (String) userNameCombo.getSelectedItem(); 112 ScreenManager.setUserName(userEntry); 57 113 ScreenManager.openCADMenu(); 58 114 ScreenManager.openAssignedIncidents(); … … 60 116 ScreenManager.openPendingIncidents(); 61 117 ScreenManager.openPowerlineUI(); 118 // a secret password allows special permission 62 119 if (!passwordField.getText().equals("Dispatcher")) 63 120 { … … 81 138 private void initView() 82 139 { 140 // create a combo box containing the student names 141 userNameCombo = new JComboBox<String>(students); 142 // Create a scrollbar after ten names 143 userNameCombo.setMaximumRowCount(10); 144 userNameCombo.setForeground(Color.BLUE); 145 userNameCombo.setFont(new Font("Arial", Font.BOLD, 14)); 146 83 147 login = new Box(BoxLayout.Y_AXIS); 84 148 login.setAlignmentX(LEFT_ALIGNMENT); 85 149 JPanel whiteBackground = new JPanel(); 150 whiteBackground.setLayout(new BorderLayout()); 86 151 whiteBackground.setAlignmentX(LEFT_ALIGNMENT); 87 152 whiteBackground.setBackground(Color.WHITE); … … 89 154 whiteBackground.setMinimumSize(new Dimension(750, 150)); 90 155 whiteBackground.setPreferredSize(new Dimension(750, 150)); 156 // Add TriTech banner to top of screen (ticket #205) 157 try { 158 BufferedImage myPicture = ImageIO.read(new File("images/TritechLoginBanner.png")); 159 JLabel picLabel = new JLabel(new ImageIcon(myPicture)); 160 whiteBackground.add(picLabel, BorderLayout.CENTER); 161 } catch (IOException ex) { 162 Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); 163 } 91 164 login.add(whiteBackground); 92 165 … … 134 207 JLabel userNameLabel = new JLabel("User name "); 135 208 userNameLabel.setForeground(Color.WHITE); 136 userNameField = new JTextField(kNamePrompt);137 userNameField.addKeyListener(this);138 userNameField.setForeground(Color.GRAY);139 209 Box userNameBox = new Box(BoxLayout.X_AXIS); 140 210 userNameBox.setAlignmentX(LEFT_ALIGNMENT); 141 211 userNameBox.add(Box.createHorizontalStrut(10)); 142 212 userNameBox.add(userNameLabel); 143 userNameBox.add(userName Field);213 userNameBox.add(userNameCombo); 144 214 leftBox.add(userNameBox); 145 215 … … 212 282 setVisible(true); 213 283 } 214 215 /** 216 * This keylistener removes the prompt displayed in the username text box 217 * the first time the user presses a key. Fixes #96 218 * @author jdalbey 219 * @param evt 220 */ 221 public void keyPressed(KeyEvent evt) 222 { 223 // See if the text in the box is the initial prompt 224 // If so, the user hasn't typed anything yet, this is the 1st keypress 225 // Even the shift key will be caught here. 226 if (userNameField.getText().equals(kNamePrompt)) 227 { 228 userNameField.setText(""); 229 // Change the text color from gray to black 230 userNameField.setForeground(Color.BLACK); 231 } 232 } 233 234 public void keyReleased(KeyEvent e) {} 235 public void keyTyped(KeyEvent e) {} 284 285 /** Local main for unit testing */ 286 public static void main(String[] args) 287 { 288 new Login("config/student_names.txt"); 289 } 290 236 291 }
Note: See TracChangeset
for help on using the changeset viewer.
